#BRData

1 messages · Page 1 of 1 (latest)

cunning raftBOT
cedar stone
#

Hello

grim kayak
#

Hi Bismarck

cedar stone
#

What do you mean by "went through successfully"?

grim kayak
#

So I have this code that comes in the quick setup with Stripe inside the handleSubmit function

#

const { error } = await stripe.confirmPayment({
elements,
redirect: "if_required",
confirmParams: {
// Make sure to change this to your payment completion page
return_url: windowLocation,
receipt_email: emailAddress,
},
});

    if (error.type === "card_error" || error.type === "validation_error") {
        showMessage(error.message);
    } else {
        showMessage("An unexpected error occurred.");
    }
#

And I noticed that its checking the error.type and the if else statement only contains an error check - what is a way for me to check if the payment went through succesfully so I can include a javascript snippet of code inside that success statement to do things that need to be done on my end of things

cedar stone
#

It shouldn't have else { showMessage("An unexpected error occurred."); }

#

What docs do you see that in?

#

If it reaches your else block then the promise successfully resolved without an error and you would show a success

#

Then you can see the status of the PaymentIntent to ensure it is succeeded

grim kayak
#

Line 58-62 on the checkout.js file

cedar stone
#

Oh yikes

#

Well, to be fair, this assumes you don't use redirect: if_required

#

So that would be accurate in that case since you would only reach that code if there was an unexpected error.

#

So actually that is technically correct

#

But confusing

#

But yeah, since you aren't redirecting by defeault, you should just retrieve the PaymentIntent in that block like I mentioned above

grim kayak
#

Hmm... still a little confused to be honest

#
    elements,
    redirect: "if_required",
    confirmParams: {
        return_url: windowLocation,
        receipt_email: emailAddress,
    },
});

if (error) {
    // There was an error during payment confirmation
    if (error.type === "card_error" || error.type === "validation_error") {
        showMessage(error.message);
    } else {
        showMessage("An unexpected error occurred.");
    }
} else if (paymentIntent && paymentIntent.status === "succeeded") {
    // Payment was successful
    showMessage("Payment succeeded!");
} else {
    // Handle other cases if needed
    showMessage("An unexpected result occurred.");
}```
#

Does that look right?

cedar stone
#

Ah right I forgot we do supply the paymentIntent if the promise resolves successfully

#

So you don't even need to retrieve it

#

Yep that looks good to me

#

I'd test it out!

grim kayak
#

But wait - quick question

#

since I am using payment holds

#

it will not be succeeded unless its captured correct?

cedar stone
#

Ah yes, so you want status === 'requires_capture'

grim kayak
#

Ahh okay thank you.