Skip to content

Commit

Permalink
Merge pull request #44 from amirfakhrullah/hotfix/unique-stripe-id
Browse files Browse the repository at this point in the history
add unique
  • Loading branch information
amirfakhrullah authored Apr 16, 2023
2 parents 9c46222 + 07071df commit cf0dcdf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
3 changes: 1 addition & 2 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ model Order {
orderItems OrderItem[]
createdAt DateTime @default(now())
updatedAt DateTime?
stripePaymentIntentId String?
stripePaymentIntentId String? @unique
stripePaymentClientSecret String?
@@unique([stripePaymentIntentId, stripePaymentClientSecret])
@@index([userId])
}

Expand Down
4 changes: 1 addition & 3 deletions src/pages/api/webhooks/stripe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export default async function handler(

const eventObj = event.data.object as Stripe.PaymentIntent;
const stripePaymentIntentId = eventObj.id;
const stripePaymentIntentClientSecret = eventObj.client_secret;

let status: Status | undefined;

Expand All @@ -57,11 +56,10 @@ export default async function handler(
break;
}

if (stripePaymentIntentId && stripePaymentIntentClientSecret && status) {
if (stripePaymentIntentId && status) {
await db.order.update({
where: {
stripePaymentIntentId,
stripePaymentClientSecret: stripePaymentIntentClientSecret,
},
data: {
status,
Expand Down

1 comment on commit cf0dcdf

@vercel
Copy link

@vercel vercel bot commented on cf0dcdf Apr 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ecommerce-next13beta – ./

ecommerce-next13beta-git-main-bigboii-dev.vercel.app
ecommerce-next13beta-bigboii-dev.vercel.app
checks.amrf.me

Please sign in to comment.