Nick: fix auto charge failing when payment is through Link
This commit is contained in:
@@ -7,7 +7,7 @@ async function getCustomerDefaultPaymentMethod(customerId: string) {
|
||||
const paymentMethods = await stripe.customers.listPaymentMethods(customerId, {
|
||||
limit: 3,
|
||||
});
|
||||
return paymentMethods.data[0]?.id;
|
||||
return paymentMethods.data[0] ?? null;
|
||||
}
|
||||
|
||||
type ReturnStatus = "succeeded" | "requires_action" | "failed";
|
||||
@@ -16,13 +16,18 @@ export async function createPaymentIntent(
|
||||
customer_id: string
|
||||
): Promise<{ return_status: ReturnStatus; charge_id: string }> {
|
||||
try {
|
||||
const defaultPaymentMethod = await getCustomerDefaultPaymentMethod(customer_id);
|
||||
if (!defaultPaymentMethod) {
|
||||
Logger.error(`No default payment method found for customer: ${customer_id}`);
|
||||
return { return_status: "failed", charge_id: "" };
|
||||
}
|
||||
const paymentIntent = await stripe.paymentIntents.create({
|
||||
amount: 1100,
|
||||
currency: "usd",
|
||||
customer: customer_id,
|
||||
description: "Firecrawl: Auto re-charge of 1000 credits",
|
||||
payment_method_types: ["card"],
|
||||
payment_method: await getCustomerDefaultPaymentMethod(customer_id),
|
||||
payment_method_types: [defaultPaymentMethod?.type ?? "card"],
|
||||
payment_method: defaultPaymentMethod?.id,
|
||||
off_session: true,
|
||||
confirm: true,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user