braintree / braintree-web

A suite of tools for integrating Braintree in the browser
https://developer.paypal.com/braintree/docs/start/hello-client/javascript/v3
MIT License
444 stars 134 forks source link

Cannot use a payment_method_nonce more than once. #306

Closed Gardezi1 closed 7 years ago

Gardezi1 commented 7 years ago

General information

Issue description

Hello, guys, I've started using your APi but I'm facing a problem and that is the second I try to do a payment it returns me an error Cannot use a payment_method_nonce more than once. Can you guys tell what is going wrong since I was reading in your issues and I think you fixed it

import BrainTree from 'braintree-web'
var dropin = require('braintree-web-drop-in');

   var button = document.querySelector('#submit-button');

            if(nextProps.user.clientToken && nextProps.user.clientToken != null ) {
                dropin.create({
                    authorization: nextProps.user.clientToken,
                    container: '#dropin-container',
                    paypal: {
                        flow: 'vault'
                    }
                },  (createErr, instance) => {
                    let me = this;
                    button.addEventListener('click', function () {

                        if(instance != undefined) {
                            debugger;
                            // me.testFunction("1")
                            // Submit payload.nonce to your server
                            instance.requestPaymentMethod(function (err, payload) {

                                if (err) {
                                    console.log('Error', err);
                                    return;
                                }

                                // Add the nonce to the form and submit
                                // document.querySelector('#nonce').value = payload.nonce;
                                // form.submit();
                                debugger;
                                me.checkoutPayment(payload.nonce);
                            });

                        }
                    });
                });
            }

                        }
                    });](url)
intelliot commented 7 years ago

Hi @Gardezi1 -

That error means you're attempting to use the nonce more than once. The nonce is a one-time-use token and can only be used for one operation.

I see the following:

me.checkoutPayment(payload.nonce);

What does your checkoutPayment function do?

Typically, you would send the nonce to your server and create a transaction with Transaction.sale.

If you're using PaymentMethod.create to store the payment method with a customer, then you can use the resulting token to create a transaction.

Does this help?

Gardezi1 commented 7 years ago

The checkourPayment method is sending ounce to the server for the transaction but I was going throught your documentation and there in some issue it was written that you guys solved the problem of ouce being generated once when this function is called but in the dropin this was not the case

intelliot commented 7 years ago

@Gardezi1 - I don't know which issue you're referring to. With Drop-in, the nonce is generated once requestPaymentMethod is called.

Has your problem been solved?

crookedneighbor commented 7 years ago

@Gardezi1 We haven't heard back from you, so I'm going to close this issue.

It sounds like a problem with your specific integration, not the SDK itself. If you're still having issues, please contact Braintree support for help. https://developers.braintreepayments.com/forms/contact

otanand commented 2 years ago

Hi,

I too have this issue on PWA studio headless storefront. I will attach the screenshot of the code and its output.

Screenshot from 2022-08-18 23-17-42 Screenshot from 2022-08-18 23-18-17 Screenshot from 2022-08-18 23-20-35 Screenshot from 2022-08-18 23-21-11

Is the code is correct or do i need to do anything else other than this ?