From aab0d6b18a52c1a1f5de84f1d01bcf2989cf86ba Mon Sep 17 00:00:00 2001 From: alannnc Date: Thu, 14 Sep 2023 00:29:03 -0700 Subject: [PATCH] fix: paypal save event type and payment (#11181) * fix-paypal-save * change type to use appId instead * Remove duplicated code --- packages/app-store/paypal/lib/Paypal.ts | 6 +++--- .../routers/viewer/eventTypes/update.handler.ts | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/app-store/paypal/lib/Paypal.ts b/packages/app-store/paypal/lib/Paypal.ts index b136299500..ec85ece623 100644 --- a/packages/app-store/paypal/lib/Paypal.ts +++ b/packages/app-store/paypal/lib/Paypal.ts @@ -53,7 +53,7 @@ class Paypal { const { access_token, expires_in } = await response.json(); this.accessToken = access_token; this.expiresAt = Date.now() + expires_in; - } else { + } else if (response?.status) { console.error(`Request failed with status ${response.status}`); } } catch (error) { @@ -127,7 +127,7 @@ class Paypal { }); if (captureResult.ok) { const result = await captureResult.json(); - if (result.body.status === "COMPLETED") { + if (result?.status === "COMPLETED") { // Get payment reference id const payment = await prisma.payment.findFirst({ @@ -153,7 +153,7 @@ class Paypal { success: true, data: Object.assign( {}, - { ...(payment?.data as Record), capture: result.body.id } + { ...(payment?.data as Record), capture: result.id } ) as unknown as Prisma.InputJsonValue, }, }); diff --git a/packages/trpc/server/routers/viewer/eventTypes/update.handler.ts b/packages/trpc/server/routers/viewer/eventTypes/update.handler.ts index 84bd5d76e5..953b2bffe7 100644 --- a/packages/trpc/server/routers/viewer/eventTypes/update.handler.ts +++ b/packages/trpc/server/routers/viewer/eventTypes/update.handler.ts @@ -246,17 +246,17 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => { const paymentCredential = await ctx.prisma.credential.findFirst({ where: { userId: ctx.user.id, - type: { - equals: "stripe_payment", + appId: { + equals: "stripe", }, }, select: { - type: true, + appId: true, key: true, }, }); - if (paymentCredential?.type === "stripe_payment") { + if (paymentCredential?.appId === "stripe") { const { default_currency } = stripeDataSchema.parse(paymentCredential.key); data.currency = default_currency; } @@ -267,16 +267,16 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => { const paymentCredential = await ctx.prisma.credential.findFirst({ where: { userId: ctx.user.id, - type: { - equals: "paypal_payment", + appId: { + equals: "paypal", }, }, select: { - type: true, + appId: true, key: true, }, }); - if (paymentCredential?.type === "paypal_payment" && input.metadata?.apps?.paypal?.currency) { + if (paymentCredential?.appId === "paypal" && input.metadata?.apps?.paypal?.currency) { data.currency = input.metadata?.apps?.paypal?.currency.toLowerCase(); } }