2017-06-19 82 views
0

我已將PayPal客戶端REST整合到我的網站。我用從鏈接提供下面的示例代碼:但是今天它顯示如下錯誤 錯誤 https://developer.paypal.com/demo/checkout/#/pattern/clientPayPal付款客戶端REST腳本

下面這段代碼工作了一個多月,:請求後https://www.sandbox.paypal.com/v1/payments/payment

failed with 400 error 

{ 
    "name": "MALFORMED_REQUEST", 
    "message": "Incoming JSON request does not map to API request", 
    "information_link": "https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST", 
    "debug_id": "a26904ff6211a" 
} 

我的代碼如下:

<div id="paypal-button-container" class="info"></div><script src="https://www.paypalobjects.com/api/checkout.js"></script> 
<script> 

    // Render the PayPal button 

    paypal.Button.render({ 

     // Set your environment 

     env: 'production', // sandbox | production 

     // PayPal Client IDs - replace with your own 
     // Create a PayPal app: https://developer.paypal.com/developer/applications/create 

     client: { 
      sandbox: '<?=SANDBOXPAYPAL?>', 
      production: '<?=PAYPAL_TOKEN?>' 
     }, 

     // Set to 'Pay Now' 

     commit: true, 

     // Wait for the PayPal button to be clicked 

     payment: function() { 
$('#card').attr('checked',true); 
      // Make a client-side call to the REST api to create the payment 


      return paypal.rest.payment.create(this.props.env, this.props.client, { 
       transactions: [ 
        { 
         amount: { total: '12.99', currency: 'GBP' } 
        } 
       ] 
      }); 
     }, 

     // Wait for the payment to be authorized by the customer 

     onAuthorize: function(data, actions) { 

      jQuery.ajax({ 
      type: "POST", 
      url: "ipn.php", 
      data: data, 
      success: function(data){ 
      } 
     }); 

      return actions.payment.execute().then(function() { 
       document.querySelector('#paypal-button-container').innerText = 'Payment Complete!'; 
      }); 
     } 

    }, '#paypal-button-container'); 

</script> 

回答

0

您的代碼與示例不太匹配,但我也使用了我正在構建的Laravel Shoping Cart的客戶端API,我使用AJAX將支付數據推回到我的系統是這樣的:

onAuthorize:function(data, actions) 
 
    { 
 
     console.log("onAuthorize()"); 
 
     console.log("Dumping DATA"); 
 
     console.log(data); 
 
     console.log("Dumping ACTIONS"); 
 
     console.log(actions); 
 
     return actions.payment.execute().then(function(payment) 
 
     { 
 
      console.log("payment.execute called"); 
 
      document.querySelector('#paypal-button-container').innerText = 'Payment Complete!'; 
 
      console.log("Dumping payment:"); 
 
      console.log("CART: "+payment['cart']); 
 
      console.log(payment); 
 

 
      var values = encodeURIComponent(JSON.stringify(payment)); 
 
      $.ajaxSetup({headers:{'X-CSRF-TOKEN':'{{ $token }}' } }); 
 
      ajaxRequest= $.ajax({ url: "/ajax/payment", type: "post",data:values }); 
 
      ajaxRequest.done(function(response, textStatus, jqXHR) 
 
      { 
 
       var result = $.parseJSON(response); 
 
       console.log(result); 
 
      }); 
 

 
     }); 
 
    },

/AJAX /支付我的捕獲腳本我在目前正在開發,但它確實記錄從購買的所有數據..希望它幫助。