Skip to content

Commit

Permalink
fix(Stripe): set expiry date for payment intent cards
Browse files Browse the repository at this point in the history
  • Loading branch information
Betree committed Dec 12, 2024
1 parent 574b65d commit 3a428f0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface) {
await queryInterface.sequelize.query(`
UPDATE "PaymentMethods"
SET
"expiryDate" = to_date((data ->> 'expYear')::varchar || '-' || (data ->> 'expMonth')::varchar, 'YYYY-MM') + INTERVAL '1 month' - INTERVAL '1 ms',
"data" = JSONB_SET(data, '{expiryDateSetFrom20241212132217Migration}', 'true'::jsonb)
WHERE "expiryDate" IS NULL
AND data ->> 'expYear' IS NOT NULL
AND data ->> 'expMonth' IS NOT NULL
AND "deletedAt" IS NULL
`);
},

async down(queryInterface) {
await queryInterface.sequelize.query(`
UPDATE "PaymentMethods"
SET
"expiryDate" = NULL,
"data" = data - 'expiryDateSetFrom20241212132217Migration'
WHERE data -> 'expiryDateSetFrom20241212132217Migration' IS NOT NULL
AND "deletedAt" IS NULL
`);
},
};
8 changes: 7 additions & 1 deletion server/paymentProviders/stripe/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,14 +492,19 @@ export async function createPaymentMethod(
const paymentIntentCharge: Stripe.Charge = (originPaymentIntent as any)?.charges?.data?.[0];
const paymentMethodChargeDetails = paymentIntentCharge?.payment_method_details;

const paymentMethodData = {
const paymentMethodData: Record<string, unknown> = {
stripePaymentMethodId: stripePaymentMethod.id,
stripeAccount,
...mapStripePaymentMethodExtraData(stripePaymentMethod, paymentMethodChargeDetails),
...extraData,
};

const paymentMethodName = formatPaymentMethodName(stripePaymentMethod, paymentMethodChargeDetails);
let expiryDate;
if (paymentMethodData.expYear && paymentMethodData.expMonth) {
const { expYear, expMonth } = paymentMethodData;
expiryDate = moment.utc(`${expYear}-${expMonth}`, 'YYYY-MM').endOf('month');
}

return await PaymentMethod.create(
{
Expand All @@ -515,6 +520,7 @@ export async function createPaymentMethod(
(stripePaymentMethod.type !== 'bancontact' && originPaymentIntent?.setup_future_usage === 'off_session'),
confirmedAt: new Date(),
data: paymentMethodData,
expiryDate,
},
createOptions,
);
Expand Down

0 comments on commit 3a428f0

Please sign in to comment.