#pinho

1 messages · Page 1 of 1 (latest)

ancient gustBOT
forest tide
#

Hi there

#

Can you share the request ID?

graceful willow
#

POST /v1/payment_intents/pi_3NDs8hCENMAgnvaD0P7WAy5N/confirm

#

pi_3NDs8hCENMAgnvaD0P7WAy5N

forest tide
#

That works

#

Let me take a look

graceful willow
#

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)

forest tide
#

Can you show me your code for how you are calling confirmPayment?

graceful willow
#

Yes, absolutely, here's the workflow:

#
  1. 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');`

#
  1. 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];

}`

#
  1. 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);
}

},`

forest tide
#

Thanks, that all looks fine to me. Let me take a deeper look

graceful willow
#

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.

forest tide
#

Ah okay no the issue is that you are specifying payment_method_types: card

graceful willow
forest tide
#

So you either need to remove that

#

Or not use automatic_payment_methods server-side

graceful willow
#

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

forest tide
#

Looking

#

Oh it failed 3DS

#

So that is a separate issue

graceful willow
#

It's a card problem?

forest tide
#

Overall yes. It looks like you are testing in live mode here?

graceful willow
#

Yeah, basically yes.

forest tide
graceful willow
#

But wait, I'm testing but actually paying.

forest tide
#

But yeah, at this point it isn't an integration problem. The integration worked fine just 3DS failed

graceful willow
#

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 ?

minor vortex
#

👋 hopping in here

#

3DS was attempted, but the payment still failed/was denied by the issuer

graceful willow
#

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.

minor vortex
#

I would strongly suggest NOT testing this in livemode

graceful willow
#

It's ok, we are actually issuing orders.