#thiago-spindola_api
1 messages ¡ Page 1 of 1 (latest)
đ 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/1237056709768249444
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
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.
- thiago-spindola_subscription-promo-code, 6 days ago, 4 messages
Hello
When you create a Subscription with a trial you will get a SetupIntent via the pending_setup_intent property: https://docs.stripe.com/api/subscriptions/object#subscription_object-pending_setup_intent
Good, thx
So on Sub creation you should expand pending_setup_intent and then using the setup_intent.client_secret to render Payment Element
Your other option here is to use the deferred-intent flow: https://docs.stripe.com/payments/accept-a-payment-deferred?platform=web&type=subscription
I'm tried this, but i'm having a error message: Invalid value for stripe.retrievePaymentIntent intent secret: value should be a PaymentIntent client secret. You specified: a SetupIntent client secret.
Why are you using stripe.retrievePaymentIntent?
i'm using this code:
export const CheckoutForm: React.FC<StripeCheckoutProps> = ({ clientSecret }) => {
const stripe = useStripe();
const elements = useElements();
const [message, setMessage] = useState<null | string | undefined>(null);
const [isLoading, setIsLoading] = useState(false);
useEffect(() => {
if (!stripe) {
return;
}
// const clientSecret = new URLSearchParams(window.location.search).get('payment_intent_client_secret');
console.log('clientSecret', clientSecret);
if (!clientSecret) {
return;
}
stripe.retrievePaymentIntent(clientSecret).then(({ paymentIntent }) => {
switch (paymentIntent!.status) {
case 'succeeded':
setMessage('Payment succeeded!');
break;
case 'processing':
setMessage('Your payment is processing.');
break;
case 'requires_payment_method':
setMessage('Your payment was not successful, please try again.');
break;
default:
setMessage('Something went wrong.');
break;
}
});
}, [stripe]);
and passing this value: seti_1P8R58DrhWjWTprTajuYzUba_secret_PyNqH5hMPJ1KBvE8uDzD0BGPk8Tp71y
Seems like you are missing a bunch of tihngs from that code -- you don't confirm the SetupIntent? But regardless, in this case you would do stripe.retrieveSetupIntent(): https://docs.stripe.com/js/setup_intents/retrieve_setup_intent
Can you explain confirm the SetupIntent?
That is how you collect the PaymentMethod. Notice in the docs that you call const {error} = await stripe.confirmPayment({ //`Elements` instance that was used to create the Payment Element elements, confirmParams: { return_url: "https://example.com/order/123/complete", } });
That would be to actually complete the payment
But here you don't have a payment, you just want to collect the PaymentMethod so that you use it in the future to charge the Subscription after the trial ends
So you do stripe.confirmSetup() there
Instead of stripe.confirmPayment()
Then you would check the status of the SetupIntent after that
Like you were doing above
In this case, do I have the same result? Will I be able to collect payment details?
Yes -- I'm telling you the way to collect payment method details.
You do that by confirming the SetupIntent
That will create a PaymentMethod and attach it to the Customer
Then you set it as the default to be charged in the future
Ok, thank's man