#MYoussef - Checkout Session

1 messages ยท Page 1 of 1 (latest)

empty echo
shut mauve
#

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

empty echo
#

Could you provide a link to the docs you referenced?

hard knot
empty echo
#

@hard knot are the multiple line items for the same product?

#

With the same billing period

hard knot
#

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,
},

              },
empty echo
#

So in this case wouldn't you just adjust the quantity rather than add another line item?

hard knot
#

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)

glacial frost
#

๐Ÿ‘‹ 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

hard knot
#

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

glacial frost
#

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

hard knot
#

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 ?

glacial frost
#

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

hard knot
#

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 ?

glacial frost
#

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

hard knot
#

should i create a webhook in this case to make sure the subscription is paid ?

glacial frost
#

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.

hard knot
#

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

glacial frost
#

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

hard knot
late iris
#

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)

hard knot
hard knot
#

?

late iris
#

Hey there sorry I was going to share some example output from this but my test app is currently freezing, just a sec

hard knot
#

take your time, i appreciate

late iris
#

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.