fix: paypal save event type and payment (#11181)

* fix-paypal-save

* change type to use appId instead

* Remove duplicated code
This commit is contained in:
alannnc
2023-09-14 00:29:03 -07:00
committed by GitHub
parent dfde17111c
commit aab0d6b18a
2 changed files with 11 additions and 11 deletions
+3 -3
View File
@@ -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<string, string | number>), capture: result.body.id }
{ ...(payment?.data as Record<string, string | number>), capture: result.id }
) as unknown as Prisma.InputJsonValue,
},
});
@@ -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();
}
}