"Expected an order id to be passed"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Labels:
-
PayPal HTML Buttons
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I found the solution to my particular issue. The example code that I was using was incorrect. The reference to the order id was wrong. It should be ".then((order) => {return order.data.id;});"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
this is a really important question, it happens to a LOT of devs, someone needs to respond
Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
- [UNPROCESSABLE_ENTITY], but payment went through in PayPal Payments Standard
- PAYER_ACTION_REQUIRED returned for Capture intent when calling v2 checkout orders in Sandbox Environment
- API TRANSACTION_REFUSED in Sandbox when Capturing Payment in REST APIs
- When clicking on a payment button generates error: Unexpected token ... in PayPal Payments Standard
- Error: "Unable to change shipping method. Please try again." in PayPal popup in REST APIs