Integration of problems causing problems

I am working on Braintree for the first time and getting problems at the first stage. I can’t access dropin functions and others .. I need help to figure it out.

I followed these steps: https://developers.braintreepayments.com/javascript+php/start/overview

The first step is the Javascript Client! - I followed, as already mentioned, added a script

<script src="https://js.braintreegateway.com/v2/braintree.js"></script> 

Then the HTML part is added.

 <form id="checkout" method="post" action="/checkout"> <div id="dropin"></div> <input type="submit" value="Pay $10"> </form> 

And finally I added below script in the script tag.

 braintree.setup("CLIENT_TOKEN_KEY", 'dropin', { container: 'checkout' }) 

I checked the Token client key received from our server.

for the next step, I added the configurations mentioned

 Braintree_Configuration::environment('sandbox'); Braintree_Configuration::merchantId('use_your_merchant_id'); //updated with our merchant id Braintree_Configuration::publicKey('use_your_public_key'); // updated with our public key Braintree_Configuration::privateKey('use_your_private_key'); //updated with our private key 

then added

 $clientToken = Braintree_ClientToken::generate(array( "customerId" => $aCustomerId )); 

Now the problems that I get -

When I updated $ aCustomerId with our customer ID, I had a fatal error in the field "customer_id" undefined in Braintree_ClientToken. Thus, the remote array ("client" => $ aCustomerId) received the client token.

This client token is used in brantree.setup('TOKEN_KEY','dropin',{container:'checkout'}) and received

 Error: Unable to find valid container. -braintree.js(line 18) 

I also once mentioned var braintree = Braintree.create("CLIENT_TOKEN_KEY"); above brantree.setup('TOKEN_KEY','dropin',{container:'checkout'}) , while I have TypeError: braintree.setup is not a function

I’m trying to figure this out from the last two days, but still I haven’t got a dropin screen as shown in the demo.

Hope for good help.

+6
source share
3 answers

Put all the scripts after the html / footer section, this will work:

 <?php require_once 'braintree-php-2.30.0/lib/Braintree.php'; Braintree_Configuration::environment('sandbox'); Braintree_Configuration::merchantId('-----------'); Braintree_Configuration::publicKey('-----------'); Braintree_Configuration::privateKey('-----------'); if(isset($_POST['submit'])){ /* process transaction */ $result = Braintree_Transaction::sale(array( 'amount' => '234.00', 'creditCard' => array( 'number' => '30569309025904', 'expirationDate' => '05/14' ) )); if ($result->success) { print_r("success!: " . $result->transaction->id); } else if ($result->transaction) { print_r("Error processing transaction:"); print_r("\n code: " . $result->transaction->processorResponseCode); print_r("\n text: " . $result->transaction->processorResponseText); } else { print_r("Validation errors: \n"); print_r($result->errors->deepAll()); } } $clientToken = Braintree_ClientToken::generate(); ?> <html> <head> </head> <body> <div id="checkout" method="post" action="/checkout"> <div id="dropin"></div> <input data-braintree-name="number" value="4111111111111111"> <input data-braintree-name="expiration_date" value="10/20"> <input type="submit" id="submit" value="Pay"> <div id="paypal-button"></div> </div> <!-- Scripts --> <script src="https://code.jquery.com/jquery-2.1.1.js"></script> <script src="https://js.braintreegateway.com/v2/braintree.js"></script> <script> braintree.setup("<?php print $clientToken; ?>", "dropin", { container: jQuery("#dropin") , form: jQuery("#checkout") , paymentMethodNonceReceived: function (event, nonce) { // do something } }); </script> </body> </html> 
+7
source

I had this problem and it was solved by putting javascript at the end of the page. An alternative would be to enclose it in a test document.

The problem arises because the braintree code tries to find the container as soon as the script loads. But if your code is at the beginning of the document, the container will not be loaded, so it will not find the container, and you will receive an error message.

The comment about base64_encoding is incorrect. It works fine if the code runs after the container has been loaded without re-encoding the offset to the already encoded string.

+5
source

I work at Braintree. Feel free to contact our support team if you have further questions.

The first error you saw is Unable to find valid container. , will be selected if JavaScript cannot find the container you specified. The accepted values ​​for container are an ID string, a DOM node, or a jQuery object. Your sample code should work, but if it is not, you can try passing another format, for example {container: $('#dropin')} .

Once you are sure that you are in the correct container, I also recommend that you interpolate correctly in your client token. If you are viewing the source on your page, your client token must be base64 encoded.

+4
source

Source: https://habr.com/ru/post/972710/


All Articles