#jojilede
1 messages ยท Page 1 of 1 (latest)
Hello ๐
Unless you set the PaymentMethod as a default payment method on customer (customer.invoice_settings.default_payment_method), no that payment method will not get automatically charged.
I see. Will it work if they checkout as guest?
No it will not unfortunately.
I see, what about a subscription checkout?
That should work I believe
Thanks! just to clarify for the subscriptionSchedule to work we need to set the customer.invoice_settings.default_payment_method set so they will be charged and that is on top of when we create them a stripe account?
not sure what you mean by
that is on top of when we create them a stripe account?
sorry
but yes, in order for a subscription schedule to charge the payment method it needs to be set as default
stripe customer
so before a checkout we need to create a stripe customer for them and make that payment a default to charge them the subscriptionSchedule?
Yup
Let me see if we have any docs on this
This should help you create a subscription
https://stripe.com/docs/billing/subscriptions/build-subscriptions
and then you can add a schedule to the existing subscription
https://stripe.com/docs/billing/subscriptions/subscription-schedules/use-cases#existing-subscription
gotcha
what is the subscription here? is it the same as the stripe.checkout.sessions.create where mode is subscription?
yes
if they checkout using that method can we add subscriptionSchedule to that to delay the next payment?
Let's take a step back
What is your end goal? I understand you want to build a subscription integration. Can you expand a bit more on your usecase and explain why you need to use SubscriptionSchedule?
sure.
We are a property rental app that offers long term rental, we want to charge the customer the initial monthly payment when they book a property, scenario:
Date of Booking: Jan 10, 2023
Check-in: Feb 1 , 2023
Check-out: April 30, 2023
Monthly Rate: 1000 USD
We want to charge the renter on Jan 10 and that represents the payment for feb 1-28, so the next phase of payment to be charged will be on March 1, 2023 and April 1, 2023.
Ah okay I see.
thinking.. It might not fit in with subscription models that we support by default
https://stripe.com/docs/billing/subscriptions/designing-integration#subscription-models
If this is only one-time then instead of using SubscriptionSchedule you could,
1/ Collect one-time charge on Jan 10. 2023 for the $xxxx amount
2/ Start a subscription with trial (from Jan 10th to March 1)
https://stripe.com/docs/billing/subscriptions/designing-integration#subscription-models
3/ When the trial expires, the next month's amount would be charged
In above, you don't really need to use a subscription schedule
then can the customer be a guest if I use that? so they wont know about the trial process?
and can it be done in just 1 session?
Unfortunately, for subscriptions a customer is required.
Yes
You can specify trial information when you create a checkout session by setting
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-subscription_data-trial_end OR
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-subscription_data-trial_period_days
I see:
const session = await stripe.checkout.sessions.create({
line_items: [
{
price: 'price_1MMwbTDTISXyBnp6h3pajLFc',//req.body.init_price_id,
quantity: 1,
},
],
mode: 'payment',
success_url: `${req.headers.origin}/?success=true`,
cancel_url: `${req.headers.origin}/?canceled=true`,
automatic_tax: {enabled: true},
metadata: {
price_id: 'price_1MMwbTDTISXyBnp6jxGjMEQt'
},
payment_method_types: ['card', ],
});
that is how my current checkout lookslike
so my code will look like this now right:
const initialPaymentsession = await stripe.checkout.sessions.create({
line_items: [
{
price: 'price_1MMwbTDTISXyBnp6h3pajLFc',//req.body.init_price_id,
quantity: 1,
},
],
mode: 'payment',
automatic_tax: {enabled: true},
metadata: {
subscription_price_id: 'price_1MMwbTDTISXyBnp6jxGjMEQt'
},
payment_method_types: ['card', ],
});
const subscriptionSession = await stripe.checkout.sessions.create({
line_items: [
{
price: 'price_1MMwbTDTISXyBnp6h3pajLFc',//req.body.init_price_id,
quantity: 1,
},
],
mode: 'subscription',
success_url: `${req.headers.origin}/?success=true`,
cancel_url: `${req.headers.origin}/?canceled=true`,
automatic_tax: {enabled: true},
metadata: {
subscription_price_id: 'price_1MMwbTDTISXyBnp6jxGjMEQt'
},
payment_method_types: ['card', ],
subscription_data: {
trial_end: '0000'//Feb 28, 2023
}
});
is that correct? ๐
sorry give me 30s to clenaup
because I am charging 1 time and subscription? Sorry I got lost.
๐ trial_end timestamp needs an actual value
You can use trial_period_days instead. It would be easier to specify total days compared to calculating a timestamp
that depends on your usecase. I'm not sure I clearly understand your integration yet ๐ Specifically the part about "guest" customer and one-time payments
ah
the one time payment is the payment on the booking date.
the problem with the trial is we can't charge the customer upfront ๐
ah gotcha. In that case, you can add that price as a line item when creating a checkout session for a subscription too
I see, I'm sorry to ask this , may I know from you how will that code above should look like?
modify Checkout Session creation for a subscription to:
{
price: 'price_1MMwbTDTISXyBnp6h3pajLFc',//req.body.init_price_id,
quantity: 1,
},
{
price: ONE-TIME-PRICE-ID-HERE,
quantity: 1
}
],```
and the mode is ?
subscription
i see ๐
Hi sorry
one more, how will the second one not be charged again next billing cycle?
Hi ๐
Yes that is how the API was designed to handle both scenarios. If the second price is not a recurring price, it will only be charged the first time
Thank you! ๐ will it also charge the one time even if there is a trial?
The answer to my dumb question is yes I just tried it LOL
Yeah we make our Test mode pretty robust so developers can answer their own questions pretty easy ๐
It helps build confidence in your integration that you can just try all of this stuff with your own code