Skip to content

Commit

Permalink
Merge pull request #5 from SwiichyCode/idempotency
Browse files Browse the repository at this point in the history
update
  • Loading branch information
SwiichyCode authored Jan 31, 2024
2 parents a51e71a + f8863bd commit 3d154cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/app/api/webhooks/checkout/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ export async function POST(req: Request) {
// throw new Error("Webhook is already processing");
// }

// const idempotency_key = await CheckoutService.getIdempotencyKey({
// sessionId: session.id,
// });
const idempotency_key = await CheckoutService.getIdempotencyKey({
sessionId: session.id,
});

// if (idempotency_key) {
// throw new Error("Idempotency key is already defined");
// }
if (idempotency_key.idempotencyKey) {
throw new Error("Idempotency key is already defined");
}

// Fix case if not a physical product
if (customerDetails?.name && customerDetails?.address) {
Expand Down
7 changes: 7 additions & 0 deletions src/app/shop/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getServerAuthSession } from "@/server/auth";
import { ProductList } from "@/modules/Shop/components/ProductList";
import { ContextOptimisticWrapper } from "@/modules/Shop/components/ContextOptimisticWrapper";
import { transformCartData } from "@/modules/Shop/utils/transformCartData";
import CheckoutService from "@/modules/Shop/services/checkout.service";

export default async function ShopPage() {
const session = await getServerAuthSession();
Expand All @@ -18,6 +19,12 @@ export default async function ShopPage() {
: [];

const currentCart = transformCartData(cart[0]?.cartItems ?? []);
const a = await CheckoutService.getIdempotencyKey({
sessionId:
"cs_test_a1OsywgEvXdjsMLZYUtND6M1rIoj2jN5G0baG2Ob753GbHL9TWviA9KDS6",
});

console.log(a);

return (
<>
Expand Down

0 comments on commit 3d154cf

Please sign in to comment.