How do I insert the Braintree client client?

The Braintree documentation says that you create an environment like in your example var gateway=braintree.connect(environmental variables)

and then create clientToken

by doing

gateway.clientToken.generate({}, function (err, response) {
    var clientToken = response.clientToken;
  });

      

Then their example says to insert a customer token into the form used for payment

braintree.setup("CLIENT-TOKEN-FROM-SERVER", "custom", {id: "checkout"});

      

but they also indicate that the clientToken is an object. I don't see how to get the token value and the return value is only boolean. I found that it gateway.clientToken

communicates as an object using typeof()

.

I see a couple of people on Stackoverflow saying that the clientToken object should be base64 encoded, but how do you do that? Shouldn't the Braintree code be doing this?

So, I am missing a step or cannot find the documentation I need, but I am definitely lost.

EDIT: In response to the response from Braintree in the responses below, the ClientToken is not populating the response.clientToken in any of the forms I've tried, which is a lot. Looking at examples from all over the web, which are few and far between, and the Lightlight documentation from Braintree, it looks like I'm getting it right.

EDIT2: My solution to the problem is in my answer below.

+3


source to share


2 answers


The problem is where you put the code to interact with Braintree within any node.js calls you make. In my case, I had this internally http.createServer

so I could write values ​​while debugging, but some of that would not let this work. I haven't figured out the exact data yet.

Also, the sample code from Braintree shows the clientToken inside the call gateway.clientToken.generate()

, which would make me think that where it belongs, without even understanding how I should retrieve that token value. So by moving the clientToken outside of this call I thought I tried it sometime, solved it at least in part.



I say "partially" because you have to create a new token with every new client and it cannot be done that way. I still need to figure out how to generate a new token on every new client visit. It might just be a matter of making another function call, but I haven't tried it yet.

Also, I still don't understand if a new client needs to be created. I read the answer: no, but I also read the answer: yes, so confusion reigns, but that is probably a different topic of the question.

+1


source


I work at Braintree. If you have more detailed questions, please contact our support team .

It looks like you are misleading gateway.clientToken

which is the object that allows you to get the client token and the client token itself, which is the result of the callback gateway.clientToken.generate

- response.clientToken

.



Once you have a token (here var clientToken

), you need to get it for your client. From "Hello Server!" documents :

There are several ways to get your client token in JavaScript so you can customize Braintree. Many people prefer to interpolate the client token into a view that contains JavaScript to customize Braintree.

+1


source







All Articles