#jojilede

1 messages ยท Page 1 of 1 (latest)

elfin micaBOT
broken plume
#

does adding interval like this works?:

    trial_period_days: 31,
    interval: 4,
    interval_unit: 'month'
  }
carmine arrow
#

Taking a look now

#

Can you be more specific about what you're trying to do? I'm not sure what "set the checkout.session subscription below in 4 months" means.

broken plume
#

I want to just simply add a limit to the subscription to 4 cycle ๐Ÿ˜„

#

just to give a background:

carmine arrow
#

" 4 cycle " what does this mean?

broken plume
#

this is a long term property rental, and the use case above is I want to charge the user the initial payment(the ONE-TIME PRICE ID above) and the subscription that will end on their checkout date.

sample use case:

  • Booking Date: now
  • Check-in: Jan 15, 2023
  • Check-out: June 14, 2023

we will charge the customer "now" for the cycle of Jan 15-Feb 14 and limit the subscription cycle to the remaining 4months (Feb - June)

carmine arrow
broken plume
#

Oh I see.

carmine arrow
#

So yeah, I think if you set the trial period to the number of days between the time of payment and the time of check-in, then they will not be charged for the Subscription, but you will have their payment details to charge when the subscription's trial is over.

Let me test on my end to make sure. I'll circle back to you in a few minutes

broken plume
#

but that is already fixed on that code

#

what i need now is how to limit the subscription to the sample 4months.

carmine arrow
#

Do you mean you want to cancel it at the 4 month mark?

broken plume
#

yes ๐Ÿ˜„

carmine arrow
broken plume
#

ah

#

so I will attach this to the webhook?

#

haha! That's exactly what I'm lookng for. Thank you so much!

#

Btw, may I know how will my code looks like now?

  line_items: [
    {
      price: 'price_XXX',//ONE-TIME PRICE ID
      quantity: 1,
    },
    {
      price: 'price_XXX',//SUBSCRIPTION PRICE ID
      quantity: 1,
    },
  ],
  mode: 'subscription',
  success_url: `${req.headers.origin}/?success=true`,
  cancel_url: `${req.headers.origin}/?canceled=true`,
  automatic_tax: {enabled: true},
  payment_method_types: ['card'],
  subscription_data: {
    trial_period_days: 31,
    interval: 4,
    interval_unit: 'month'
  }
});

is that ok?
then on webhook I can just add:

case '[EVENT_NAME_FOR_SUBSCRIPTION_STARTED]':
   stripe.subscriptions.update(event.object.subscription.id, {cancel_at_period_end: true});
broken plume
carmine arrow
#

That looks right to me. Now it will create the Subscription and (upon creation) the webhook will fire. Your server receives the webhook and then makes another API call to set cancel_at_period_end: true

#

Looks good to me

broken plume
#

Well I can just log it also from the webhook but it seems I still have to create it that's why I asked haha

#

or can I just do on the webhook:

case '[EVENT_NAME_FOR_SUBSCRIPTION_STARTED]':
   stripe.subscriptions.update(event.object.subscription.id, {cancel_at: [FUTURE_DATE]});
carmine arrow
#

I think it should be event.data.object.id

broken plume
#

yeah, thanks ๐Ÿ˜„