#sendre
1 messages · Page 1 of 1 (latest)
hi! this isn't directly natively supported but there's a few approaches.
If you create a subscription like that, it should return pending_setup_intent, and that can be passed to the frontend for collecting card details too. https://stripe.com/docs/billing/subscriptions/overview#using-setupintents
Yes, our backend now pass the pending_setup_intent.client_secret to the frontend when using trial, but we get the exception as seen in this image..
It's iOS using flutter.
This is the code for init and presenting the paymentsheet
await Stripe.instance.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
// Main params
merchantDisplayName: (await PackageInfo.fromPlatform()).appName,
style: ThemeMode.light,
appearance: stripeTheme,
// Customer keys
customerId: response.customerId,
paymentIntentClientSecret: response.paymentIntentClientSecret,
customerEphemeralKeySecret: response.customerEphemeralKeySecret,
),
);
await Stripe.instance.presentPaymentSheet();
you have to use setupIntentClientSecret not paymentIntentClientSecret
because you're using a SetupIntent. But yes, I'm aware that quite complicates the frontend through having to branch or use different views
Thanks, will try that now. Is setupIntentClientSecret only when using trials and paymentIntentClientSecret for regular use? It has worked fine with paymentIntentClientSecret until now.
I would say so yes. If there's a trial, then as you say, the invoice is paid immediately, and no payment is required. So invoice.payment_intent is null. But a SetupIntent can be used to collect the payment details instead without charging them
unfortunately our products don't handle this use case terribly well, we optimised for "start a trial without a card, and add the card at some point during it", so it takes a bit of custom work to handle payment data at the start of the trial, but can be done
Your suggestion worked. Thanks for the help!
Is it possible to require a card to start the trial? Or should this be handled through e.g. webhooks on our end?
so in that case it becomes a bit more complicated
as I said this isn't natively supported. What you'd have to do is
- create your own SetupIntent(instead of creating the subscription and using the one from it's pending_setup_intent)
- collect card details to confirm that SetupIntent on the frontend, same as above
- when handling the success of that, set the card from the SetupIntent as the
default_payment_methodfor the customer, and create the trial subscription on the backend - (nothing else to do on the frontend at this point)
Ok, thanks for the help!