| 7 | const stripe = new Stripe(env.STRIPE_SECRET_KEY ?? ""); |
| 8 | |
| 9 | export async function createStripePaymentIntent({ |
| 10 | amount, |
| 11 | stripeCustomerId, |
| 12 | paymentMethodId, |
| 13 | returnUrl, |
| 14 | invoiceId, |
| 15 | }: { |
| 16 | amount: number; |
| 17 | stripeCustomerId: string; |
| 18 | paymentMethodId: string; |
| 19 | returnUrl: string; |
| 20 | invoiceId: string; |
| 21 | }) { |
| 22 | return stripe.paymentIntents.create({ |
| 23 | amount, |
| 24 | currency: "usd", |
| 25 | automatic_payment_methods: { enabled: true }, |
| 26 | customer: stripeCustomerId, |
| 27 | payment_method: paymentMethodId, |
| 28 | return_url: returnUrl, |
| 29 | off_session: true, |
| 30 | confirm: true, |
| 31 | metadata: { |
| 32 | invoiceId, // Used to track status using webhooks |
| 33 | }, |
| 34 | }); |
| 35 | } |
| 36 | export const createSetupIntent = async (stripeCustomerId: string) => |
| 37 | stripe.setupIntents.create({ |
| 38 | customer: stripeCustomerId, |