2017-07-30 101 views
0

我想實現PayPal支付按鈕,使用此教程:PayPal支付錯誤 - 的ReferenceError:動作沒有定義

https://developer.paypal.com/docs/integration/direct/express-checkout/integration-jsv4/client-side-REST-integration/

我有checkout.js頁面上的文件:

<script src="https://www.paypalobjects.com/api/checkout.js"></script> 

按鈕的代碼是:

<div id="paypal-button"></div> 
<script> 
    paypal.Button.render({ 
     env: 'sandbox', // 'sandbox' Or 'production', 
     client: { 
      sandbox: '<sandbox id>', 
      production: '' 
     }, 
     locale: 'en_GB', 
     commit: true, // Show a 'Pay Now' button 
     payment: function() { 
      // Set up the payment here 
      return actions.payment.create({ 
       payment: { 
        transactions: [ 
         { 
          amount: { total: '1.00', currency: 'GBP' } 
         } 
        ] 
       } 
      }); 
     }, 
     onAuthorize: function(data, actions) { 
      // Execute the payment here 
      return actions.payment.execute().then(function(payment) { 

       // The payment is complete! 
       // You can now show a confirmation message to the customer 
      }); 
     } 
    }, '#paypal-button'); 
</script> 

但是當我點擊butto n在控制檯中出現「ReferenceError:actions is not defined」並且沒有任何反應。我是否應該包含另一個Javascript文件,因爲它在本教程中未提及?

回答

5
payment: function() { 

應該

payment: function(data, actions) { 
+0

媽的,我怎麼錯過。不知道我如何設法複製並粘貼錯誤,但非常感謝! – user3592246

+0

我認爲貝寶文檔示例沒有反映出這一點。謝謝你,這也幫助了我。 – jremi

相關問題