#pinho
1 messages · Page 1 of 1 (latest)
POST /v1/payment_intents/pi_3NDs8hCENMAgnvaD0P7WAy5N/confirm
pi_3NDs8hCENMAgnvaD0P7WAy5N
Before this error, I received a console error, something like "The Stripe elements must be submitted before confirming the payment".
Which I solved by doing elements.submit() (javascript)
Can you show me your code for how you are calling confirmPayment?
Yes, absolutely, here's the workflow:
- I start by initializing the Stripe (JS)
`const publicKey = StripePayment.getPublicKey();
stripe = Stripe(publicKey);
const options =
{
mode: 'payment',
currency: 'eur',
amount: Checkout.getGrandTotal() * 100,
locale: 'pt',
paymentMethodTypes: ['card'],
fonts: [{ cssSrc: 'https://fonts.googleapis.com/css?family=Poppins:400,500' }],
appearance:
{
theme: 'stripe',
variables:
{
fontFamily: 'Poppins, sans-serif',
fontWeightNormal: 500,
fontSizeBase: '14px',
fontSizeSm: '14px',
}
},
};
// stripeElements = global var
stripeElements = stripe.elements(options);
const paymentElement = stripeElements.create('payment');
paymentElement.mount('#stripe-payment-element');`
- When the user decides to press the Pay button:
I create the Payment Intent, through PHP
`public function createPaymentIntent(int|float $amount): array
{
$result = $this->stripe->paymentIntents->create(
[
'amount' => $amount * 100,
'currency' => 'eur',
'automatic_payment_methods' => ['enabled' => true],
]);
return [$result->id, $result->client_secret];
}`
- Finally, I tell Stripe to confirm the payment:
`pay: async function(storeId, orderId, clientSecret)
{
const elements = stripeElements;
elements.submit();
// https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements&html-or-react=html#web-submit-payment
const { error } = await stripe.confirmPayment(
{
elements,
clientSecret,
confirmParams:
{
return_url: Helper.getBaseUrl() + `app/cart/${storeId}/checkout/finish/${orderId}`,
},
});
if (error)
{
alert('Error: ' + error.message);
}
},`
Thanks, that all looks fine to me. Let me take a deeper look
I'm using this approach https://stripe.com/docs/payments/accept-a-payment-deferred which yesterday was recommended by one of your colleagues
oh wait
maybe I should be doing const {error: submitError} = await elements.submit();
instead of just elements.submit()
Nevermind, just tested, and same error shows up.
Ah okay no the issue is that you are specifying payment_method_types: card
hmm, but I didn't want to show all of that cards
ahh, ok, let me see
I removed the automatic_payment_methods and didn't work
pi_3NDsPxCENMAgnvaD1wP8hCju
It's a card problem?
Overall yes. It looks like you are testing in live mode here?
Yeah, basically yes.
You should be testing in test mode and you can use one of our 3DS test cards to ensure you are handling it correctly: https://stripe.com/docs/testing#regulatory-cards
But wait, I'm testing but actually paying.
But yeah, at this point it isn't an integration problem. The integration worked fine just 3DS failed
hi
can you check this pi_3NDsZmCENMAgnvaD1Fj6wC9R
for me?
Payment declined
Tell the customer to try a different payment method, or they can contact their issuing bank for more information. Learn more about declines.
May 31, 2023, 6:12 PM
Can you tell me it's because of the 3DS ?
👋 hopping in here
3DS was attempted, but the payment still failed/was denied by the issuer
Ok thanks, it's not a code related problem, but a card related problem. What's odd about it is that sometimes it works, sometimes it doesn't. It's a mastercard.
I just tried with VISA and there was no problem.
I would strongly suggest NOT testing this in livemode
We have a ton of test cards (https://stripe.com/docs/testing) so you can test all these different scenarios
It's ok, we are actually issuing orders.