#nerder-subscription-setupintent

1 messages ยท Page 1 of 1 (latest)

torn sierraBOT
buoyant oyster
#

Hello ๐Ÿ‘‹
Do you have an example request ID I can look at?

opal plover
#

this is my code

#
    const stripeSub: Stripe.Subscription = await this.stripe.subscriptions.create(
      {
        customer: customerId,
        items: [
          {
            price: priceId,
          },
        ],
        cancel_at_period_end: isOneOff,
        application_fee_percent: gym.transactionFee.percent,
        trial_period_days: trialDays,
        payment_behavior: 'default_incomplete',
        expand: ['latest_invoice.payment_intent', 'pending_setup_intent'],
      },
      {
        stripeAccount: gym.accountId.value,
      },
    );

    let clientSecret = ((stripeSub.latest_invoice as Stripe.Invoice).payment_intent as Stripe.PaymentIntent)
      ?.client_secret;

    // https://stripe.com/docs/billing/subscriptions/overview#non-payment
    if (clientSecret === undefined) {
      clientSecret = (stripeSub.pending_setup_intent as Stripe.SetupIntent).client_secret;
    }

    if (clientSecret === undefined) {
      throw new Error(`Could not extract client secret from subscription ${stripeSub.id}`);
    }
    return ClientSecret.of(clientSecret);
#

basically, i was taking into consideration that a subscription might not have a latest_invoice so I was looking for the client_secret inside the pending_setup_intent that i was previously expanding

buoyant oyster
#

Oh I wonder if it has something to do with the customer having a default payment method already
Can you try with a fresh customer object?

opal plover
#

ok, let me try real quick

buoyant oyster
#

๐Ÿ‘

opal plover
#

actually now is worse

#

the payment method is not saved

buoyant oyster
#

Interesting, can you run a quick test without setting the payment_behavior?

opal plover
#

in 30min, i'm stuck with a call rn

#

sorry

buoyant oyster
#

NP!

torn sierraBOT
mossy thistle
#

I can confirm that pending_setup_intent is only present if the Customer/Subscription doesn't already have a properly set up PaymentMethod object