#MYoussef - Checkout Session
1 messages ยท Page 1 of 1 (latest)
this is mean that he has 2 separate subscription and he can cancel one of this subscription or disable auto-renewal at any time.
So do you want them to be able to cancel 1 of the subscriptions and keep the other? or do they need to keep all items? Might be better to have subscriptions for 1 item, 2 items, 3 items etc
Could you provide a link to the docs you referenced?
the subscriptions will be separate and the customer can cancel or stop auto-renewal for any one of the subscriptions at any time
@hard knot are the multiple line items for the same product?
With the same billing period
yes, item 1 and 2
Customer = "cus_L8E153vH4CURUb",
LineItems = new List<SessionLineItemOptions>
{
new SessionLineItemOptions
{
Price = "plan_L7zdkSlJ4irdes",
// For metered billing, do not pass quantity
Quantity = 1,
},
new SessionLineItemOptions
{
Price = "plan_L7zdkSlJ4irdes",
// For metered billing, do not pass quantity
Quantity = 1,
},
new SessionLineItemOptions
{
Price = "price_1KSgvKGjZDiWw2Ml7sxZoF6u",
Quantity = 1,
},
},
So in this case wouldn't you just adjust the quantity rather than add another line item?
yes, because if make quantity 2 then i can not deal with 2 items as separate subscriptions (because the customer should be able to cancel one of these item or renew one and keep the other one for one year only)
๐ I'm just hopping in since @empty echo has to head out - if you want to create separate Subscriptions for a customer you cannot do so in the same Checkout Session. You'd have to create the first subscription through checkout, and then create the second one through the Create Subscription API.
Alternatively, you could use Checkout in setup mode just to collect payment details and then create both Subscriptions through the API
which one do you recommend? and if I used the setup mode solution, how to redirect the customer to pay for the items because i want to collect the payment like what happened in checkout session
It's really up to you - with the setup mode solution you'd create your subscriptions server-side with the Payment Method that is generated from the Checkout Session
after creating subscriptions with the Payment Method that is generated from the Checkout Session, how to redirect the customer to pay for these subscriptions as in checkout session ?
You wouldn't be redirecting to go through a Checkout Session again - you'd create the Subscriptions server-side and only take the customer through additional actions if they were needed. Theoretically, after going through the setup flow your customer wouldn't need to do any additional authentication or anything since it was already provided, so you should be able to just create your subscription
is this mean that, i should create checkout session in setup mode then in success function i should create the subscriptions using API with the payment method from setup mode, after that this subscription will be paid automatically from from customer payment method ?
Yup! That would be the idea
You'd want to make sure that before creating the Subscriptions you set the saved Payment Method to invoice_settings.default_payment_method on the customer so it's automatically used when you create the Subscriptions
should i create a webhook in this case to make sure the subscription is paid ?
That's up to you and how your integration works - using webhooks would work if you want to listen for the invoice.paid event to confirm that the subscription's first invoice was paid.
what if i have one time payment item with the subscriptions that i created, how apply the payment for it if i used setup mode ?
because customer cart, can contains subscription and one time payment items
When you create the Subscriptions you'd use add_invoice_items (https://stripe.com/docs/api/subscriptions/create#create_subscription-add_invoice_items) which will add these one-time items to the Subscription's first invoice. When you create the subscription payment for the first invoice will automatically be attempted with the default payment method, so you don't need to worry aboutt his
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
i do not want to allow the customer to use the service before make sure that the invoice is paid, so in my case while using the setup mode then creating the subscription how much time will take to be paid? to inform a customer with message that he can use the service after 1 hour for example
hey there, just stepping in for @glacial frost who had to step away. What do you mean by this:
how much time will take to be paid?
This depends on your integration. For a new subscription without a trial, the first payment would be collected immediately if you used a previously saved payment method.
But if you intend to create the subscription immediately, you should not use a separate setup intent/ setup mode checkout, and instead save the payment method during the first invoice payment
(whether via checkout or a custom integration)
so if i created a subscription with a previously saved payment method then i will received that the invoice is paid or not in the response of create subscription ?
?
Hey there sorry I was going to share some example output from this but my test app is currently freezing, just a sec
take your time, i appreciate
So, yea, if the payment method is already set up the payment will succeed immediately assuming you use a payment_behavior other than default_incomplete -- but this is exactly what you should use to set up a subscription and collect payment method during the first payment
When you create the subscription in either case, you can use expansion to have the response include the full latest invoice & associated payment intent:
https://stripe.com/docs/api/expanding_objects
expand: ['latest_invoice.payment_intent']
In the case of a successful payment, this invoice would be paid, in the case of a new sub you need to collect payment for with default_incomplete you'd use the client_secret rom the payment intent to collect payment details in the client-side app.
This is what we discuss in the guide here:
https://stripe.com/docs/billing/subscriptions/build-subscription
The guide uses the default_incomplete flow to collect payment details during the first payment: 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.