#krut4rth
1 messages · Page 1 of 1 (latest)
some disclaimer i had removed LinkAuthenticationElement from the checkout form
What's the PaymentIntent ID?
I don't see any request to confrim this PaymentIntent. Did you call stripe.confirmPayment when the "Pay now" button is clicked?
Yes i have stripe.confirmPayment in place, here is my code
Do you see any error in your browser console log?
no there are no errors
Do you see errors when you click the "Pay now" button?
No errors after clicking pay now button
OK, then you might want to put some logs in your app and see what prevents stripe.confirmPayment() from getting called.
ok, doing that
actually when i click pay now, i'm redirected. 1. I'm redirected to wrong path, not the return_url. 2. as redirection occurs the logs go away
Do you call e.preventDefault(); in your button handler?
yes, I have provided the code above as well.
Then it shouldn't redirect. Can you save your code, recompile and run again?
I did that, again the same issue as before.
That's very strange.
Can you check out the sample code from github https://github.com/stripe-samples/accept-a-payment/tree/main/custom-payment-flow/client/react-cra and start from there?
i don't know what to look out for in the repo you sent. I'm simply following this doc: https://stripe.com/docs/payments/quickstart?lang=node
Why the e.preventDefault is not working.
i did some changes, removed the form, and directly calling handleSubmit from the button, the payment is going through, it also redirects to return url but the params are still there in the url. like this: http://localhost:3000/?payment_intent=pi_3NgKh4KEOuJhOPhD0IpFJFZp&payment_intent_client_secret=pi_3NgKh4KEOuJhOPhD0IpFJFZp_secret_OYxPpiLwbraVT8DQm47Wdqk6u&redirect_status=succeeded
My new code is as follow:
import { useEffect, useState } from 'react';
import {
PaymentElement,
useStripe,
useElements
} from '@stripe/react-stripe-js';
export default function CheckoutForm() {
const stripe = useStripe();
const elements = useElements();
const [message, setMessage] = useState(null);
const [isProcessing, setIsProcessing] = useState(false);
useEffect(() => {
if (!stripe) {
return;
}
const clientSecret = new URLSearchParams(window.location.search).get(
'payment_intent_client_secret'
);
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]);
const handleSubmit = async () => {
if (!stripe || !elements) {
return;
}
setIsProcessing(true);
const { error } = await stripe.confirmPayment({
elements,
confirmParams: {
return_url: 'http://localhost:3000'
}
});
if (error) {
setMessage(error.message);
}
setIsProcessing(false);
};
return (
<>
<PaymentElement id="payment-element" />
<button
onClick={handleSubmit}
disabled={isProcessing || !stripe || !elements}
id="submit"
>
<span id="button-text">{isProcessing ? 'Processing ... ' : 'Pay'}</span>
</button>
{message && <div id="payment-message">{message}</div>}
</>
);
}
👋 Taking over this thread, catching up now
From https://dashboard.stripe.com/test/payments/pi_3NgKh4KEOuJhOPhD0IpFJFZp, the payment has been succeeded
What is the issue you're facing here?