2017-09-15 30 views
0

我正在與braintree paypal結帳功能,我發現jquery代碼爲此,我需要將Braintree沙箱驗證密鑰放入jquery變量中,我在braintree中創建帳戶,我嘗試了所有代碼,但在jQuery控制檯日誌中說,authrization失敗,任何人都可以請幫我我在哪裏可以找到代碼? 這裏是我的sameple代碼我如何才能找到Braintree沙盒驗證密鑰

  <!DOCTYPE html> 

      <head> 
       <meta http-equiv="X-UA-Compatible" content="IE=edge" /> 
       <meta name="viewport" content="width=device-width, initial-scale=1"> 
       <script src="https://www.paypalobjects.com/api/checkout.js"></script> 
       <script src="https://js.braintreegateway.com/web/3.11.0/js/client.min.js"></script> 
       <script src="https://js.braintreegateway.com/web/3.11.0/js/paypal-checkout.min.js"></script> 
      </head> 

      <body> 
       <div id="paypal-button-container"></div> 

       <script> 

        var BRAINTREE_SANDBOX_AUTH = '38mqtdwp4nth5tbk'; 

        // Render the PayPal button 

        paypal.Button.render({ 

         // Pass in the Braintree SDK 

         braintree: braintree, 

         // Pass in your Braintree authorization key 

         client: { 
          sandbox: BRAINTREE_SANDBOX_AUTH, 
          production: '<insert production auth key>' 
         }, 

         // Set your environment 

         env: 'sandbox', // sandbox | production 

         // Wait for the PayPal button to be clicked 

         payment: function(data, actions) { 

          // Make a call to create the payment 

          return actions.payment.create({ 
           payment: { 
            transactions: [ 
             { 
              amount: { total: '1', currency: 'USD' } 
             } 
            ] 
           } 
          }); 
         }, 
         // Wait for the payment to be authorized by the customer 
         onAuthorize: function(data, actions) { 
          // Call your server with data.nonce to finalize the payment 
          console.log('Braintree nonce:', data.nonce); 
          // Get the payment and buyer details 
          return actions.payment.get().then(function(payment) { 
           console.log('Payment details:', payment); 
          }); 
         } 
        }, '#paypal-button-container'); 
       </script> 
      </body> 

我需要將代碼放在這個變量var BRAINTREE_SANDBOX_AUTH = '38mqtdwp4nth5tbk';誰能幫助我解決這個問題?

回答

1

完全披露:我在布倫特裏工作。如果您有任何其他問題,請隨時聯繫[email protected]

看起來您正在將您的BRAINTREE_SANDBOX_AUTH變量設置爲商家ID,而不是Client Token。爲了啓動Braintree結帳,您需要生成,然後傳入client_token

您生成client_tokenon your server,然後將其傳遞到您的client-side callbraintree.client.create()

如果成功,braintree.client.create()將返回一個客戶端實例,您可以使用該實例創建一個包含braintree.paypalCheckout.create()的PayPal結帳組件。

paypalCheckout component之內,您可以使用paypal.Button.render()配置您的PayPal按鈕。

+0

感謝現在爲我工作 –