#gullible_best-practices

1 messages ยท Page 1 of 1 (latest)

remote domeBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1319408513268711456

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

rough pantherBOT
agile saddle
#

For additional context, I have UIs built for adding, removing and setting a payment method as a default using StripeJS + Custom Elements. I also have a UI built that allows the user to provide billing information including address. This all works. My next step is to start a subscription based on the users selected subscription. Something like this:

  async doSubscriptionCreate(varCustomerId, varPaymentMethodId, varPriceId) {
    try {
      const response = await this.stripe.subscriptions.create({
        customer: varCustomerId,
        default_payment_method: varPaymentMethodId,
        items: [{
          price: varPriceId,
          quantity: 1
        }],
        trial_settings: {
          end_behavior: {
            missing_payment_method: 'pause'
          }
        },
        trial_from_plan: true
      })

      console.log(response)

      return response
    } catch (error) {
      return new Error(error)
    }
  }

I want to ensure that the trial period is added but it seems like the only way to do that is to create a payment link but I do not want to use Stripe's UIs for handling payments.

uncut idol
agile saddle
#

Okay, so I do not need to worry about creating the payment link which gives me the ability to add the trial period there? I should be able to add trial_period_days to the code I provided above and be good?

uncut idol
#

Sorry, I don't understand the question, as I thought you said you weren't using any of our UIs so I'm not sure how Payment Links are relevant here.

Yes, you can add either of those parameters, and remove trial_from_plan so those don't conflict, and it should do what you're describing. Let me know if that isn't what you see in your testing.

agile saddle
#

I have not tested yet because I wanted to ensure this was going to work and what I wanted first. Once I test this and assume it works, are there webhooks I can set up for when a subscription changes statuses?

uncut idol
agile saddle
#

Awesome, thank you, I appreciate it. How long will this chat stay open just in case I have more questions?

uncut idol
#

Probably about 20 minutes, but you're welcome to open a new thread if I close this one and additional questions come up.

agile saddle
#

Actually, I do have another question. Because this is a subscription and I do plan to collect payment information during user sign up (I know, the vast majority of companies do not do this today), when the subscription is created there will already be a default payment method set in the users account. From my understanding, once their trial period has ended, the payment method will automatically be charged. Is this accurate? I do not need to worry about payment intents and stuff like that or creating check sessions or anything?

uncut idol
#

Correct. If there is already a Payment Method specified to be used as the default, then that will be charged.

That can either be specified in the default_payment_method field on the Subscription object, which will take precedence but only apply for that specific Subscription, or in the invoice_settings.default_payment_method field on the Customer object, which will be used for all of the Customer's Subscriptions that don't have their own default payment method set at the Subscription level.

agile saddle
#

Excellent, that is what I thought. Thank you.

#

Time to forge on to see if I cannot get this to work as intended. Thank you again!