#ashish_76275
1 messages · Page 1 of 1 (latest)
I don't understand the question. Can you rephrase and try again?
- Customer is active on subscription.
- Customer cards get denied in future, hence subscriptioin status changes to "unpaid"
- Now I want to add new payment method to customer, make it default, and pay for the current invoice with provided invoice ID and any future payments.
@ivory sentinel
Okay, and how did you collect the card in the first place?
By using PaymentElement react component
const CheckoutForm = ({ setPaymentSuccess }) => {
const stripe = useStripe();
const elements = useElements();
const [paymentError, setPaymentError] = useState();
const handleSubmit = async (event) => {
// We don't want to let default form submission happen here,
// which would refresh the page.
event.preventDefault();
setPaymentError();
if (!stripe || !elements) {
// Stripe.js hasn't yet loaded.
// Make sure to disable form submission until Stripe.js has loaded.
return;
}
const result = await stripe.confirmPayment({
//`Elements` instance that was used to create the Payment Element
elements,
confirmParams: {
return_url: window.location.origin + "/pay",
},
redirect: "if_required",
});
if (result.error) {
// Show error to your customer (for example, payment details incomplete)
console.log(result.error.message);
setPaymentError(result.error.message);
} else {
setPaymentSuccess(true);
// Your customer will be redirected to your `return_url`. For some payment
// methods like iDEAL, your customer will be redirected to an intermediate
// site first to authorize the payment, then redirected to the `return_url`.
}
};
return (
<form onSubmit={handleSubmit}>
<PaymentElement />
<button disabled={!stripe}>Submit</button>
{paymentError && <div className="payment-error">{paymentError}</div>}
</form>
);
};
<Elements stripe={stripePromise} options={{ clientSecret: clientSecret }}>
<CheckoutForm setPaymentSuccess={setPaymentSuccess} />
</Elements>
I got the clientSecret when I created the subscription.
So you would do that again with the existing Subscription and the Customer that needs a new Payment Method
Yes
I mean create new subscription ?
or is there way to just update the payment method by generating new clienSecret for that exisiting subscription ?
Can you please elborate please like how to generate new clientSecret for existing subscriptin ?
A Payment Intent gets generated by the Subscription's Invoice, so you would just use the client secret from that one to keep the existing subscription.
So if I use the payment intent from invoice that was generated by subscription, it will also add it to default for future payments ?