Hi guys!
I am integrating the PayPal into my own system. after I installed the smart payment button, I found I can’t pass the complete payment result to my PHP server.
my code is:
<script>
var turtle_id = document.getElementById("turtle_id");
console.log(turtle_id.value);
paypal.Buttons({
createOrder: function(data, actions) {
// This function sets up the details of the transaction, including the amount and line item details.
return actions.order.create({
purchase_units: [{
amount: {
value: '0.01'
}
}]
});
},
onApprove: function(data, actions) {
var capture_data = actions.order.capture();
var xhr = new XMLHttpRequest();
xhr.open('POST', "https://192.168.0.100/haigui/order_consultation/" + turtle_id.value, true);
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.onload = function () {
console.log(this.responseText);
};
**console.log(capture_data); //OK**
**xhr.send(JSON.stringify(capture_data));**
}
}).render('#paypal-button-container');
//This function displays Smart Payment Buttons on your web page.
</script>
above code only can post a JSON like this:
{resolved: false, rejected: false, errorHandled: false, handlers: []}
but, before the line of ‘xhr.send(JSON.stringify(capture_data));’,
I can console.log a complete JSON via 'console.log(capture_data); ’ like this:
n {resolved: false, rejected: false, errorHandled: false, value: undefined, error: undefined, …}dispatching: falseerror: undefinederrorHandled: falsehandlers: []rejected: falseresolved: truestack: undefinedvalue: {create_time: "2020-07-25T08:23:35Z", update_time: "2020-07-25T08:24:23Z", id: "0YM27746DT8358617", intent: "CAPTURE", status: "COMPLETED", …}__proto__: Object
Why I couldn’t pass a complete JSON through ‘xhr.send(JSON.stringify(capture_data));’?
I also tried ‘xhr.send(capture_data);’, but I only got request payload [object object]