#jojilede

1 messages ยท Page 1 of 1 (latest)

warm acornBOT
arctic hare
#

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.

vestal blaze
#

I see. Will it work if they checkout as guest?

arctic hare
#

No it will not unfortunately.

vestal blaze
#

I see, what about a subscription checkout?

arctic hare
#

That should work I believe

vestal blaze
#

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?

arctic hare
#

not sure what you mean by

that is on top of when we create them a stripe account?

vestal blaze
#

sorry

arctic hare
#

but yes, in order for a subscription schedule to charge the payment method it needs to be set as default

vestal blaze
#

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?

arctic hare
#

Yup

#

Let me see if we have any docs on this

vestal blaze
#

gotcha

#

what is the subscription here? is it the same as the stripe.checkout.sessions.create where mode is subscription?

arctic hare
#

yes

vestal blaze
#

if they checkout using that method can we add subscriptionSchedule to that to delay the next payment?

arctic hare
#

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?

vestal blaze
#

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.

arctic hare
#

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

vestal blaze
#

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?

arctic hare
#

Unfortunately, for subscriptions a customer is required.

vestal blaze
#

it's ok

#

can it be done in just 1 session?

#

like they can only checkout once?

vestal blaze
#

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? ๐Ÿ˜“

arctic hare
#

mode is still payment

#

and why do you have two sessions?

vestal blaze
#

sorry give me 30s to clenaup

vestal blaze
arctic hare
#

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

vestal blaze
#

ah I see!

#

and how many sessions should I create?

arctic hare
#

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

vestal blaze
#

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 ๐Ÿ˜„

arctic hare
#

ah gotcha. In that case, you can add that price as a line item when creating a checkout session for a subscription too

vestal blaze
#

I see, I'm sorry to ask this , may I know from you how will that code above should look like?

arctic hare
#

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
    }  
  ],```
vestal blaze
#

and the mode is ?

arctic hare
#

subscription

vestal blaze
#

i see ๐Ÿ˜„

vestal blaze
#

Hi sorry

#

one more, how will the second one not be charged again next billing cycle?

rare parrot
#

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

vestal blaze
#

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

rare parrot
#

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

vestal blaze
#

thank you so much. Can I ask one more question? how do I test the subscription cycle? like can I jump to a specific date in stripe dashboard?

#

I just found it on the subscription, the 'Simulation clock'

#

haha

rare parrot
#

For that you would use a Test Clock to allow you to advance time

#

Bingo

vestal blaze
#

yeah this is really so cool.

#

thank you , I think I can move on from here!