#Gadbit-setupintents
1 messages · Page 1 of 1 (latest)
Hello! Yes, if customer is set on the Setup Intent then it will automatically be attached to the Customer if the setup was successful (https://stripe.com/docs/api/setup_intents/object?event_types-payment_intent.payment_failed#setup_intent_object-customer)
So, if a customer has a trialing subscription, will that payment method be charged when the trial period expires without setting that payment method as default?
Assuming that customer doesn't have another payment method attached.
No, you'd still need to set it as the default (either on the Customer at invoice_settings.default_payment_method on the Subscription at default_payment_method). Just because a PM is attached to a customer doesn't mean we consider it the default (even if the customer only has a single one attached).
I also want to flag - if you set payment_settings.save_default_payment_method: on_subscription this should automatically set the saved payment method to be the default on the Subscription (https://stripe.com/docs/api/subscriptions/create?event_types-payment_intent.payment_failed#create_subscription-payment_settings-save_default_payment_method)
Oh, OK. So, i have a problem. In my app, when a customer subscribes for the first time, the subscription is created with "trial_from_plan: true". However, when the subscription is created, the payment method is not required due to $0 amount invoice, so, any payment method is attached.
I have to create a setup intent first, in order to check if the payment method (card) is a valid one.
In this way, when the setup intent is confirmed (because the card is a valid one), that payment method is attached to the customer and i would expect when the trial period expires, charge that customer's payment method.
So, if the setup intent is created first, the subscription doesn't exist, so how can i set the default_payment_method for the subsciption?
You shouldn't be creating a separate Setup Intent to collect payment details if you know that you're going to be creating a Subscription immediately after. What you should do instead is create the Subscription with payment_behavior: default_incomplete and check pending_setup_intent to grab a Payment Intent you can use to collect payment method details (https://stripe.com/docs/api/subscriptions/object?event_types-payment_intent.payment_failed#subscription_object-pending_setup_intent)
I was doing like that. However, i noticed when a "trial_from_plan: true" subscription is created, the invoice is paid immediatly and the subscription status is trialing automatically without collecting the payment method.
Yes, the Subscription will still be created and Invoice is paid immediately because it's for $0
So, how can i associate a payment method to that subscription?
In advance, an apology, but that is the part that is not clear to me.
Just for adding more details, i'm not using checkout, it's a custom integration where i'm using a Card Field on the client side (mobile app) and when the user clicks on Subscribe button, a "trial_from_plan: true" subscription is created if it's the first time for that customer, otherwise a normal subscription (without trial) is created. Everything works well for normal subscription, since it is default_incomplete, so i return a client secret to the client side to confirm the payment intent and the CardField's payment method is associated to the subscription.
However, in "trial_from_plan: true" subscription, i can't return a client secret to the client side to confirm the payment/setup intent for attaching it to the customer or associate it to the subscription, since the invoice already has been paid.
And latestInvoice.paymentIntent is null
Let me lay this all out:
- Create a Subscription w/
payment_behavior: default_incompleteandpayment_settings.save_default_payment_method: on_subscription. Also be sure to expandpending_setup_intentin your creation request. - Even with
trial_from_plan: trueset on the Subscription, you should still seepending_setup_intentset on the Subscription. You can use the client secret from that Setup Intent to collect payment details
They key is here is that you need to check pending_setup_intent on the Subscription (https://stripe.com/docs/api/subscriptions/object?event_types-payment_intent.payment_failed#subscription_object-pending_setup_intent), since as you mentioned - trialing subs have a $0 invoice and won't generate a Payment Intent
OK. So, when i return the pending_setup_intent.clientSecret to the client side, i need to confirmSetupIntent, right?
Yup!
Once the setup intent is confirmed, i don't need to do anything else, right?
if it's confirmed successfully that's correct
I see.
So, it's possible that the customer enters an invalid card and their subscription is still trialing.
That is, the customer can avoid the subscription screen once he has realized that his card is not valid and exit the process.
Yes it's possible