"Expected an order id to be passed"

bg_nox
Contributor
Contributor

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:

image.png

 

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.

 

Login to Me Too
5 REPLIES 5

supplyside
Contributor
Contributor

Hello, did you find a solution to this problem. stuck in the same situation.

Login to Me Too

C_Cataldo
Contributor
Contributor

Me too.

Login to Me Too

MarcosMarchette
New Community Member

Me too

 

Does the Paypal staff have a solution for this error?

Login to Me Too

C_Cataldo
Contributor
Contributor

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;});"

 

Login to Me Too

voss01
Contributor
Contributor

this is a really important question, it happens to a LOT of devs, someone needs to respond 

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.