"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.
- Which api can get oauth2.0 authorization_code? in REST APIs
- Google Pay SCA authentication dialog appears behind pay.google.com overlay in REST APIs
- Assistance Needed: Passing and Retrieving Custom Data in PayPal Webhook Payload in PayPal Payments Standard
- Advance checkout in Braintree Server-side Integration (PHP, Java, .NET, Ruby, Python, NodeJS SDKs)
- failed to pay with sandbox account in Sandbox Environment