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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user