#icurrytheteam
1 messages · Page 1 of 1 (latest)
We don't have any pre-configured UI components for this currently. You'd need to use this endpoint to get the Customer's existing PMs: https://stripe.com/docs/api/payment_methods/customer_list
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
So could I just check if there exists a default saved payment and if there is, then just charge that? Otherwise, I would return the clientSecret of the payment intent so that they may enter their information?
We would automatically attempt to charge the default (https://stripe.com/docs/api/customers/object#customer_object-invoice_settings-default_payment_method) PM on the Customer object, unless you specifically set default_payment_method when creating the Subscription
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
May I read this for a second?
Sure
Ok, so what happens if no saved payment methods exist and I try to process a subscription? Will it throw an error?
What do you mean by 'process a subscription'?
Yeah, but what exactly does that mean? Make the API call to create the Subscription?
Yes
It'll likely be in an incomplete state until you confirm the Payment Intent on the initial Invoice
customer="{{CUSTOMER ID}}",
items=[{"price": "{{PRICE ID}}"}],
transfer_data={'destination': '{{ACCOUNT ID}}'},
expand=['latest_invoice.payment_intent'],
application_fee_percent=30,
)```
I just tested the above code and I was thrown an InvalidRequest error.
It says the customer has no attached payment methods, I see.
You should pass payment_behaviour: 'default_incomplete': https://stripe.com/docs/api/subscriptions/create#create_subscription-payment_behavior
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Let me take a look.
I see and if I pass the clientSecret to the client-side and fill out the form with the payment details, would that complete the transaction?
Yep! Once you call confirmPayment we'd attempt payment with the details collected and carry out 3DS/auth if required
I'd also pass this parameter when creating your subscription: https://stripe.com/docs/api/subscriptions/create#create_subscription-payment_settings-save_default_payment_method
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Will set the payment details you collect as the default for the subscription automatically, so that recurring payment aren't interrupted
Ok, so it saves the payment details for the subscription. I'm understanding that correctly?
it automatically saves the PaymentMethod used for that first payment to the Customer object involved, and sets the ID of that PaymentMethod to be the default that we charge for recurring payments on that Subscription
Exactly what I need it to do.
As for the case when the user has already saved their payment method, I can just create the subscription "normally" right? I think this would work because subscriptions automatically charge the default payment method should it already be there.
no, you should make sure to pass explicitly the payment method you want it to use
what's the context exactly where you'd be creating a subscription like that? is the customer present on your website at the time you create the subscription or not?
yes
I want my subscription flow to cover two case: one where the user has not entered their payment information and another where they have.
So for example, if a user would like to subscribe and they have already saved a default payment method, then I would want to charge that payment method
probably the best way to do that then is create the subscription in the same way, but on the frontend instead of using an instance of Elements to collect cards details, pass the ID of their existing PaymentMethod via https://stripe.com/docs/js/payment_intents/confirm_card_payment#stripe_confirm_card_payment-existing ; which will charge that card for the first invoice of that new subscription and also make it the default for that subscription if you used the save_default_payment_method option when creating the subscription
I'll be accepting transactions using cards and bank accounts. Is there something like this but that'll handle both?
should just work, but you'll need to call the correct frontend function for the given payment method from the reference at https://stripe.com/docs/js/payment_intents/payment_method
Oh, so could I just check the payment method so the frontend knows which function to call?
yes
Alright, so to sum up, I can create the subscription on the backend the same way and on the frontend, I would just check to see what function to call, then call that.
Did this make sense?
If so, then I think I'm done here.
yep sounds good