#localpath-manualpm
1 messages · Page 1 of 1 (latest)
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.
- localpath, 1 day ago, 11 messages
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
- rendering the Express Checkout Element
- user chooses Google Pay (as example)
- onConfirm is called
await stripe.createPaymentMethod()- submit details and
pm_idto backend to create sub, returning a client secret to confirm on client
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)
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?
Attaching the PM to the customer would happen automatically if createPaymentMethod wasn't being called manually
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 
Sure thing!
localpath-manualpm
@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?
Can you log subscription.id ?
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',
yep, that's correct!
Do I try to expand that response to get the underlying secret?
Yep, that's expandable