Here is the paypal button function which makes an API call and receives a response, but the response causes the error "Expected an order id to be passed", what can be wrong here? See below for the response. paypal.Buttons({
createOrder: function () {
var data = {
'sku': $("input[type='radio']:checked").val(),
'qty': $('#productQty').val()
}
return fetch('/api/Paypal', {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify(data)
}).then(function (res) {
return res.json();
}).then(function (data) {
return data.Id; // Also tried data.orderID
});
},
onApprove: function (data, actions) {
// This function captures the funds from the transaction.
return actions.order.create().then(function (details) {
// This function shows a transaction success message to your buyer.
alert('Transaction completed by ' + details.payer.name.given_name);
});
}
}).render('#paypal-button-container'); You can see the response has a valid ID: Id: "32C401489U432333G"
Status: "CREATED" Here's the same response seen in visual studio: Here's my controller which is receiving the call and sending back the response to the button: public async Task<PayPalHttp.HttpResponse> Post([FromBody]Order order) {
return await Orders.CreateOrder(order); // returns the HttpResponse from paypal
} Again, I verified that this response has the above information in the screenshot.
... View more