chore: remove onPaymentIntentSucceeded in stripe
This commit is contained in:
parent
6c1a4685cd
commit
95bd256bc7
@ -499,12 +499,6 @@ export class StripeProvider implements PaymentProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (eventType.startsWith('payment_intent.')) {
|
|
||||||
// Handle payment intent events
|
|
||||||
if (eventType === 'payment_intent.succeeded') {
|
|
||||||
const paymentIntent = event.data.object as Stripe.PaymentIntent;
|
|
||||||
await this.onPaymentIntentSucceeded(paymentIntent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('handle webhook event error:', error);
|
console.error('handle webhook event error:', error);
|
||||||
@ -851,55 +845,6 @@ export class StripeProvider implements PaymentProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle payment intent succeeded event
|
|
||||||
* @param paymentIntent Stripe payment intent
|
|
||||||
*/
|
|
||||||
private async onPaymentIntentSucceeded(
|
|
||||||
paymentIntent: Stripe.PaymentIntent
|
|
||||||
): Promise<void> {
|
|
||||||
console.log(`>> Handle payment intent succeeded: ${paymentIntent.id}`);
|
|
||||||
|
|
||||||
// Get metadata from payment intent
|
|
||||||
const { packageId, userId, credits } = paymentIntent.metadata;
|
|
||||||
|
|
||||||
if (!packageId || !userId || !credits) {
|
|
||||||
console.warn(
|
|
||||||
`<< Missing metadata for payment intent ${paymentIntent.id}: packageId=${packageId}, userId=${userId}, credits=${credits}`
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Get credit package to get expiration info
|
|
||||||
const creditPackage = getCreditPackageById(packageId);
|
|
||||||
if (!creditPackage) {
|
|
||||||
console.warn(`<< Credit package ${packageId} not found`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add credits to user account using existing addCredits method
|
|
||||||
await addCredits({
|
|
||||||
userId,
|
|
||||||
amount: Number.parseInt(credits),
|
|
||||||
type: CREDIT_TRANSACTION_TYPE.PURCHASE,
|
|
||||||
description: `Credit package purchase: ${packageId} - ${credits} credits for $${paymentIntent.amount / 100}`,
|
|
||||||
paymentId: paymentIntent.id,
|
|
||||||
expireDays: creditPackage.expireDays,
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
`<< Successfully processed payment intent ${paymentIntent.id}: Added ${credits} credits to user ${userId}${creditPackage.expireDays ? ` (expires in ${creditPackage.expireDays} days)` : ' (no expiration)'}`
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(
|
|
||||||
`<< Error processing payment intent ${paymentIntent.id}:`,
|
|
||||||
error
|
|
||||||
);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map Stripe subscription interval to our own interval types
|
* Map Stripe subscription interval to our own interval types
|
||||||
* @param subscription Stripe subscription
|
* @param subscription Stripe subscription
|
||||||
|
Loading…
Reference in New Issue
Block a user