-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/ticket-profile-view-todos
- Loading branch information
Showing
23 changed files
with
718 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { createClerkClient } from '@clerk/backend'; | ||
import { auth } from '@clerk/nextjs/server'; | ||
import { NextResponse } from 'next/server'; | ||
// import Pusher from 'pusher' | ||
|
||
// const pusher = new Pusher({ | ||
// appId: process.env.PUSHER_APP_ID, | ||
// key: process.env.NEXT_PUBLIC_PUSHER_APP_KEY, | ||
// secret: process.env.PUSHER_APP_SECRET, | ||
// cluster: "eu", | ||
// useTLS: true | ||
// }); | ||
|
||
|
||
export async function POST(request: Request) { | ||
const body = await request.json() | ||
console.log(body) | ||
|
||
const clerkClient = createClerkClient({ secretKey: process.env.CLERK_SECRET_KEY }); | ||
const {userId} = await auth(); | ||
|
||
if(!userId){ | ||
return Response.json({error: "User is not signed in."}, { status: 401 }); | ||
} | ||
|
||
const requestingUser = await clerkClient.users.getUser(userId); | ||
if(!requestingUser.publicMetadata.admin){ | ||
return Response.json({error: "User is does not have permissions."}, { status: 401 }); | ||
} | ||
|
||
const checkoutUrl = process.env.LAMBDA_CHECKOUT_COMPLETE_INPERSON | ||
|
||
const checkoutResponse = await fetch(checkoutUrl, { | ||
method: 'POSt', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(body) | ||
}) | ||
if(!checkoutResponse.ok) { | ||
const checkoutData = await checkoutResponse.json() | ||
return NextResponse.json({...checkoutData, generated_at: new Date().toISOString() }, {status: checkoutResponse.status}) | ||
} | ||
const checkoutData = await checkoutResponse.json() | ||
const ticket_number = checkoutData.ticket_number | ||
// const ticket_number = 2212652493 //! This should be returned | ||
// console.log("checkoutData",checkoutData) | ||
return NextResponse.json({ ticket_number: ticket_number, generated_at: new Date().toISOString() }) | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,47 @@ | ||
import { NextResponse} from 'next/server' | ||
import Pusher from 'pusher' | ||
|
||
const pusher = new Pusher({ | ||
appId: process.env.PUSHER_APP_ID, | ||
key: process.env.NEXT_PUBLIC_PUSHER_APP_KEY, | ||
secret: process.env.PUSHER_APP_SECRET, | ||
cluster: "eu", | ||
useTLS: true | ||
}); | ||
|
||
|
||
export async function POST(request: Request) { | ||
console.log(request) | ||
return NextResponse.json({ generated_at: new Date().toISOString() }) | ||
const body = await request.json() | ||
const eventName = body.eventName | ||
const payload = JSON.parse(body.payload) | ||
console.log(eventName) | ||
console.log(payload) | ||
// console.log(JSON.stringify(JSON.stringify(payload))) | ||
|
||
if(eventName == 'TestMessage') { | ||
return NextResponse.json({ generated_at: new Date().toISOString() }) | ||
} else { | ||
// console.log("request:", request) | ||
// console.log("body:",body) | ||
// console.log("payload:",payload, payload.products.map((product) => product.category)) | ||
const channel = "card-payments" | ||
|
||
const tills = payload.products.map((product) => product?.sku) as string[] | ||
const notification = { | ||
amount: payload.amount, | ||
created: payload.created, | ||
timestamp: payload.timestamp, | ||
payment_ref: payload.payments.map((payment) => payment.attributes.referenceNumber).join(' , '), | ||
purchaseUuid: payload.purchaseUuid, | ||
tills: tills | ||
// products: payload.products.map((product) => { return { name: product.sku , till: product?.category?.name?.toLowerCase()?.replaceAll(" ", ""), Uuid: product['productUuid'] }} ) as string[], | ||
} | ||
console.log("notification:",notification) | ||
|
||
tills.forEach(till => { | ||
pusher.trigger(channel, till, notification); | ||
}) | ||
pusher.trigger(channel, "all", notification); | ||
return NextResponse.json({ generated_at: new Date().toISOString() }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.