#localpath-manualpm

1 messages · Page 1 of 1 (latest)

gritty tokenBOT
#

Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

sudden solstice
#
const options: StripeElementsOptions = useMemo(
    () => ({
      // Customize Appearance https://stripe.com/docs/js/elements_object/create
      amount: amountInCents,
      appearance: {
        variables: {
          borderRadius: '6px',
        },
      },
      currency: 'usd',
      mode: isRecurringFrequency ? 'subscription' : 'payment',
      paymentMethodCreation: 'manual',
    }),
    [amountInCents, isRecurringFrequency]
  );
#
const subscription = await this.stripeInstance.subscriptions.create({
      customer: customerId,
      items: [{ price: price.id }],
      ...(startDateInSeconds && {
        billing_cycle_anchor: startDateInSeconds,
      }),
      metadata: {
        destination: nonprofitStripeId,
      },
      proration_behavior: 'none',
      ...(cancelAt && {
        cancel_at: cancelAt,
      }),
      default_payment_method: processorPaymentMethodId,
      expand: ['latest_invoice.payment_intent'],
      payment_behavior: 'default_incomplete',
      payment_settings: { save_default_payment_method: 'on_subscription' },
    });
#

I'm essentially doing this

  1. rendering the Express Checkout Element
  2. user chooses Google Pay (as example)
  3. onConfirm is called
  4. await stripe.createPaymentMethod()
  5. submit details and pm_id to backend to create sub, returning a client secret to confirm on client
radiant cove
#

Ah, I think what's happening here is you've created the PaymentMethod but did not then attach that PM to the customer prior to creating the Subscription (step 5)

sudden solstice
#

Ahh ok so its not so much like the Payment Intent where you can add setup_future_useage I was thinking the subscription Api would do that automatically

#

So basically just make an Api call to attach this payment method to the customer right before I do the sub call huh?

radiant cove
#

Attaching the PM to the customer would happen automatically if createPaymentMethod wasn't being called manually

sudden solstice
#

Ah dang yea that breaks my flow unfortunately bc I need to persist a record for the PM before getting to the subscribe or payment intent portion but that makes perferct sense. Super helpful!

#

Yep that works as expected. THanks for the help and knowledge galactic_brain

radiant cove
#

Sure thing!

gritty tokenBOT
#

localpath-manualpm

sudden solstice
#

@radiant cove one QQ. It seems when I try to expand the subscription response to be able to access the client secret to confirm on front end it returns null

#
const subscription = await this.stripeInstance.subscriptions.create({
      customer: customerId,
      items: [{ price: price.id }],
      ...(startDateInSeconds && {
        billing_cycle_anchor: startDateInSeconds,
      }),
      metadata: {
        destination: nonprofitStripeId,
      },
      proration_behavior: 'none',
      ...(cancelAt && {
        cancel_at: cancelAt,
      }),
      default_payment_method: processorPaymentMethodId,
      expand: ['latest_invoice.payment_intent'],
      payment_behavior: 'default_incomplete',
      payment_settings: { save_default_payment_method: 'on_subscription' },
    });

    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    /** @ts-ignore */
    const paymentIntent = subscription?.latest_invoice?.payment_intent;

    console.log(subscription.latest_invoice);
#

latest_invoice is null. Is that bc we're starting it in the future? if thats the case how do we get a client secret to confirm the subscription?

radiant cove
#

Can you log subscription.id ?

sudden solstice
#

yep

#

sub_1OeQqkEd62mULYc9lLLU3YEY

#

I see a setup intent in the response. I suppose i just need to confirm with that right? since we're using a future billing anchor to start the first charge at some distant date right?

#

pending_setup_intent: 'seti_1OeQqkEd62mULYc9kwSx9WgN',

radiant cove
#

yep, that's correct!

sudden solstice
#

Do I try to expand that response to get the underlying secret?

radiant cove
#

Yep, that's expandable