nextjs-subscription-payments icon indicating copy to clipboard operation
nextjs-subscription-payments copied to clipboard

How to set up free trial payment option?

Open Akshath-Nagulapally opened this issue 1 year ago • 4 comments

Hi, In the db autofill I see a free trial option for any user who is "trialing". This is a very important feature for my app in specific. It is not detailed in the readme.md file how to set up a free trial for any customer before they start using the product so I was wondering how it is meant to be set up?

Akshath-Nagulapally avatar Mar 28 '24 09:03 Akshath-Nagulapally

bump. i think there is lack of coherence between the stripe docs and the template atm. from my understanding you can't set up trial_period_days in Stripe anymore, and the functions in the starter use these values to calculate calculateTrialEndUnixTimestamp. can anyone help to clarify?

szymonhernik avatar Apr 08 '24 11:04 szymonhernik

oh I see. Though that could be true, I tried setting up the stripe trial period and it did work and reflect in the DB. How recent was this change to stripe as I tried doing this 3 days after started this thread.

Akshath-Nagulapally avatar Apr 08 '24 16:04 Akshath-Nagulapally

oh I see. Though that could be true, I tried setting up the stripe trial period and it did work and reflect in the DB. How recent was this change to stripe as I tried doing this 3 days after started this thread.

are you saying it works now? was it a missing stripe event or code base?

fullstackwebdev avatar Apr 17 '24 05:04 fullstackwebdev

Here is a step by step guide for you. Hope it helps.

TO DO to add trial

  • [ ] in admin.ts change TRIAL_PERIOD_DAYS to number of days
    • push changes
  • [ ] on price update (in Stripe) this should update the price with that value
    • you can test it by adding new price or editting an existing one
    • listen to webhooks for price.updated event
    • to check if the trial_period_days on price has been updated console.log prices -> it should return trial_period_days: 7 (or any other number you set up)
  • [ ] now you will work with the stripe/server.ts file. when creating stripe checkout session you will want to make sure the console.log that is already there (Trial end: ...) will console log correct UnixTimestamp (result of calculateTrialEndUnixTimestamp called later when setting params on recurring payment)
    • it should return something like 'Trial end: 1714042027' when you click Subscribe on the price you added or edited before and in the stripe checkout page it should give you some info on the left about the trial being set up, for example "Tryout Basic: 7 days for free. Next 5,00 eur per month"

szymonhernik avatar Apr 17 '24 10:04 szymonhernik