Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Problem with confirmCardPayment call with Stripe

I am using a Stripe cardElement in a payment page, and I have run into an issue with the call to ".confirmCardPayment". Here is the Javascript code invoking it:

 stripe.confirmCardPayment(
                    "<%=clientSecret %>",
                    {
                        receipt_email: "<%=customerEmail%>",
                        payment_method: {
                            card: cardElement,
                        },
                        billing_details: {
                            name: "me",
                            address: {
                                country: "US",
                                line1: "123 main street",
                                line2: null,
                                city: "pueblo",
                                state: "co",
                                postal_code: "81003",
                            },
                        },
                    }
                ).then(function (result) {
                    loading(false);
                    if (result.error) {
                        showError(result.error.message);
                    } else {
                        $("#hdData").val(JSON.stringify(result.paymentIntent));
                        frmBuy.submit();
                    }
                });

Everything works, except I get an error message back from Stripe saying:

Received unknown element: billing_details

I have looked through all the documentation I can find, and everything says this is the correct way to invoke the call. I want to be sure to include client billing address info so that the PaymentIntent reflects the customer’s info in the event of a claim of fraudulent activity. I removed the code that adds in the actual customer info for the sake of testing AND for simplicity with this question.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Can anyone tell me how I’m structuring this call incorrectly? The Stripe docs don’t provide any help with this.

>Solution :

It looks like the issue is due to the billing_details parameter not nested within the payment_method parameter on your Card Payment confirmation. Instead, your code should look something like this:

stripe.confirmCardPayment(
                    "<%=clientSecret %>",
                    {
                        receipt_email: "<%=customerEmail%>",
                        payment_method: {
                            card: cardElement,
                            billing_details: {
                               name: "me",
                               address: {
                                 country: "US",
                                 line1: "123 main street",
                                 line2: null,
                                 city: "pueblo",
                                 state: "co",
                                 postal_code: "81003",
                              },
                            },
                        },
                    }
                )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading