fix(stripe): invalid cql query for gift processing (#78)

This commit is contained in:
Hampus 2026-02-10 13:40:53 +01:00 committed by GitHub
parent 37f676084c
commit d0c20e268d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 4 deletions

View File

@ -560,10 +560,15 @@ export const GiftCodesByCreator = defineTable<GiftCodeByCreatorRow, 'created_by_
primaryKey: ['created_by_user_id', 'code'],
});
export const GiftCodesByPaymentIntent = defineTable<GiftCodeByPaymentIntentRow, 'stripe_payment_intent_id'>({
export const GiftCodesByPaymentIntent = defineTable<
GiftCodeByPaymentIntentRow,
'stripe_payment_intent_id' | 'code',
'stripe_payment_intent_id'
>({
name: 'gift_codes_by_payment_intent',
columns: GIFT_CODE_BY_PAYMENT_INTENT_COLUMNS,
primaryKey: ['stripe_payment_intent_id'],
primaryKey: ['stripe_payment_intent_id', 'code'],
partitionKey: ['stripe_payment_intent_id'],
});
export const GiftCodesByRedeemer = defineTable<GiftCodeByRedeemerRow, 'redeemed_by_user_id' | 'code'>({

View File

@ -154,6 +154,21 @@ export class StripeGiftService {
Logger.debug({checkoutSessionId, code: payment.giftCode}, 'Gift code already exists for checkout session');
return;
}
if (paymentIntentId) {
const existingGift = await this.userRepository.findGiftCodeByPaymentIntent(paymentIntentId);
if (existingGift) {
await this.userRepository.linkGiftCodeToCheckoutSession(existingGift.code, checkoutSessionId);
await this.userRepository.updatePayment({
...payment.toRow(),
gift_code: existingGift.code,
});
Logger.warn(
{checkoutSessionId, paymentIntentId, code: existingGift.code},
'Recovered existing gift code for checkout session',
);
return;
}
}
const code = await this.generateUniqueGiftCode();
let visionarySequenceNumber: number | null = null;

View File

@ -114,10 +114,14 @@ export class StripeWebhookService {
return;
}
if (payment.status !== 'pending') {
const recoverGiftWithoutCode = payment.isGift && payment.status === 'completed' && !payment.giftCode;
if (payment.status !== 'pending' && !recoverGiftWithoutCode) {
Logger.debug({sessionId: session.id, status: payment.status}, 'Payment already processed');
return;
}
if (recoverGiftWithoutCode) {
Logger.warn({sessionId: session.id}, 'Recovering gift checkout with missing gift code');
}
const productInfo = this.productRegistry.getProduct(payment.priceId!);
if (!productInfo) {
@ -140,7 +144,7 @@ export class StripeWebhookService {
amount_cents: session.amount_total || 0,
currency: session.currency || 'usd',
status: 'completed',
completed_at: new Date(),
completed_at: payment.completedAt ?? new Date(),
});
const customerId = extractId(session.customer);