#maddockst-paymentsheet-payment

1 messages · Page 1 of 1 (latest)

lilac topaz
#

hello

#

to clarify something before I answer your actual question

#

are you using a SetupIntent? or a PaymentIntent?

a PaymentIntent is what takes a payment

#

a SetupIntent only saves a card for future use

severe nymph
#

SetupIntent

#
const ephemeralKey = await stripe.ephemeralKeys.create({ customer: customerId }, { apiVersion: API_VERSION });
const setupIntent = await stripe.setupIntents.create({ customer: customerId }, { apiVersion: API_VERSION });

return http.buildResponse(201, {
    setupIntentClientSecret: setupIntent.client_secret,
    ephemeralKeySecret: ephemeralKey.secret,
});
lilac topaz
#

ok but just to clarify

When using setup intents + PaymentSheet (setupIntent.client_secret and ephemeralKey.secret), if a user cancels the payment
You said that but you are aware there won't be a "payment" even if the user successfully proceeds through the PaymentSheet, right? Just making sure we're aligned on that part

severe nymph
#

Yes, I planned to setup the subscription after the payment method. This is to handle two situations:

  • Customer is setting up a subscription with no discount code
  • Customer is setting up a subscription with a 100% off discount code (e.g 1 month free)

So, I believe in both situations (with my approach) a payment method will be created and then payments will be taken when the time is right

#

My flow is going to be:

Create customer -> Create setupIntent + ephermalSecret for customer -> Setup payment method -> Create Subscription

lilac topaz
#

got it, in that case, you can re-use the same SetupIntent ID and same EphemeralKey client secret

severe nymph
#

Ok thanks. And, are these values something I should be holding onto temporarily in the client (while on the page for example) or storing in a database and re-using any time that customer comes back to use the PaymentSheet?

lilac topaz
#

client secrets should only be temporarily, you can log the SetupIntent ID in your database. So for the session the user is on your page, you can retain those IDs

severe nymph
#

Ok perfect. So just to be sure, setupIntent ID I can store and re-use, but the ephemeral I can hold onto if while on a page and generate a new one when they come back?

#

Or, instead of storing it could I just get it from the Stripe API using the customerId?

#

Which every you think is the best approach (if the latter is feasible)

lilac topaz
#

but the ephemeral I can hold onto if while on a page and generate a new one when they come back?
correct, if the user closes or comes back to your app later, you generate a new EphemeralKey secret