#mattddean

1 messages · Page 1 of 1 (latest)

vale baneBOT
jovial walrus
#

Hey there

#

I assume you are talking about Subscriptions with a trial here, correct?

lilac coral
#

No trial

jovial walrus
#

Hmm in that case there shouldn't be a SetupIntent

#

Do you mean PaymentIntent?

lilac coral
#

Sorry, yes

jovial walrus
#

Gotcha, in that case, if a successful payment is not made within 23 hours the Subscription will expire

lilac coral
#

Ah, that might be where my problem is. I'm finalizing the subscription's first invoice before returning the payment intent's client secret to the client in order to get a payment intent from a subscription created via a subscription schedule.

jovial walrus
#

Ah yep

lilac coral
#

Will the subscription still expire if I've already finalized its first invoice?

jovial walrus
#

Nope

#

You want to use payment_behavior: default_incomplete

lilac coral
#

I'm doing that, but I'm also calling stripe.invoices.finalizeInvoice to get the payment intent's client secret. Is there another way to get the payment intent's client secret from a subscription created via a schedule?

jovial walrus
#

Ah yeah that is all fine

#

You can use the finalize endpoint

#

To expedite that 1 hour period

lilac coral
#

But you're saying that calling that finalize endpoint will cause the subscription to not expire after 23 hours if the first invoice is not paid?

jovial walrus
#

No sorry

#

I thought you meant would finalizing without successful payment expire it

#

Once the Invoice is finalized, the Subscription will expire after 23 hours if there isn't a successful payment

lilac coral
#

Maybe I've set something up wrong then, because the subscription's first invoice looks like it's going to try to charge the customer again

#

And the subscription's 'status' property is 'past_due' more than 23 hours after the first invoice was finalized

jovial walrus
#

This is with collection_method: charge_automatically?

#

When the Subscription was created, was it in a status of incomplete?

#

Maybe I am mis-remembering how this works with Subscription Schedules vs. Subscriptions. Let me double check

lilac coral
#

The code looks like this

        const stripeSubscriptionSchedule = await stripe.subscriptionSchedules.create({
          customer: stripeCustomer.id,
          start_date: 'now',
          end_behavior: 'cancel', // cancel subscription after the number of months the user has specified
          phases: [
            {
              items: [
                {
                  price_data: {
                    currency: currencyCode,
                    product: 'redacted',
                    recurring: {
                      interval: 'month',
                      interval_count: 1, // "once a month"
                    },
                    unit_amount: amountCents,
                    tax_behavior: 'exclusive',
                  },
                  quantity: 1,
                },
              ],
              iterations: requestBody.data.subscription.numMonths,
            },
          ],
          expand: ['subscription'],
        })

#
const stripeSubscription = stripeSubscriptionSchedule.subscription
        if (!stripeSubscription) throw new Error('Stripe did not create subscription')
        if (typeof stripeSubscription !== 'object') throw new Error('Stripe did not expand subscription')
        const stripeLatestInvoiceId = stripeSubscription.latest_invoice
        if (typeof stripeLatestInvoiceId !== 'string') throw new Error('Stripe expanded latest_invoice')

        // Update the subscription with some properties the API doesn't seem to let us set on the underlying subscription when creating a subscription schedule.
        // Note: successful invoice payment doesn't seem to set the customer's default payment method, and this is good, because Recharge is capable of falling
        // back to the stripe customer's default payment method if the recharge customer's default payment method fails. If we were to set the default
        // payment method on the stripe customer in the diaper fund service, that default payment method could be used by Recharge to pay for a HB subscription.
        await stripe.subscriptions.update(stripeSubscription.id, {
          payment_behavior: 'default_incomplete',
          payment_settings: { save_default_payment_method: 'on_subscription' },
        })
#

Maybe things are weird because I'm updating the subscription's payment behavior after it's been created? I didn't see a way to set that property when creating the schedule.

#

I didn't set collection_method, but looking at the subscription object via REST, I think it was set to charge_automatically by default.

#

One idea I have is to create the subscription first with these properties I'm trying to update on it and then create a schedule for it with from_subscription

jovial walrus
#

Yep so I'm incorrect above, sorry.

#

With Subscription Schedules the Sub doesn't start in incomplete

#

So it won't expire

#

If you do want this behavior then you would do as you noted and add on a Schedule after creating the Subscription itself

lilac coral
#

Okay I'll try that! Thank you so much for your help!! I guess then I don't need to call the finalizeInvoice endpoint either since creating a subscription directly won't be subject to the one hour thing?

jovial walrus
#

Correct