2017-02-24 227 views
1

我正在整合在我的網站PayPal快速結賬按鈕,我有以下代碼:PayPal快速結賬按鈕

paypal.Button.render({ 

    env: 'sandbox', // Optional: specify 'sandbox' environment 
    style: { 
     size: 'medium', 
     color: 'blue', 
     shape: 'rect' 
    }, 

    payment: function(resolve, reject) { 

     var CREATE_PAYMENT_URL = 'http://example.com/create-payment'; 

     paypal.request.post(CREATE_PAYMENT_UR) 
      .then(function(data) { 
       resolve(data.paymentID); 
      }) 
      .catch(function(err) { 
       reject(err); 
      }); 
    }, 

    onAuthorize: function(data) { 

     // Note: you can display a confirmation page before executing 

     var EXECUTE_PAYMENT_URL = 'http://example.com/execute-payment'; 

     paypal.request.post(EXECUTE_PAYMENT_URL, { 
      paymentID: data.paymentID, 
      payerID: data.payerID, 
     })  
      .then(function(data) { /* Go to a success page */ }) 
      .catch(function(err) { /* Go to an error page */ }); 
    } 

}, '#paypal-button'); 

我想設置paymentonAuthorize分開。有什麼辦法可以做到嗎?

類似於:`paypal.Button.onAuthorize = function(){};

回答

1

您可以創建單獨的功能,如果它可以幫助

function payment() { 
    ... 
} 

function onAuthorize() { 
    ... 
} 

paypal.Button.render({ 

    payment: payment, 
    onAuthorize: onAuthorize 

});