cancel
Showing results for 
Search instead for 
Did you mean: 

Need to Patch Order but Order Already Completed?

Highlighted
Contributor

Need to Patch Order but Order Already Completed?

Friends,

 

I'm trying to implement the solution described in this post:

https://www.paypal-community.com/t5/REST-APIs/How-do-I-get-a-TransactionId-from-an-OrderId-using-the...

 

So I added the PHP PayPal SDK on my server-side code to PATCH the order after I get the information back:

 

 

 

 protected function patchOrder($orderId, $invoiceId)
    {

        $client = PayPalClient::client();
        $request = new OrdersPatchRequest($orderId);
        $request->body = [  ['op' => 'add',
                                'path' => '/purchase_units/@reference_id==\'default\'/invoice_id',
                                'value' => $invoiceId] ];
        $client->execute($request);
    }

 

 

 But my current client-side implementation completes the transaction so I get the fatal ORDER_ALREADY_COMPLETED error. I have tried various solutions like passing commit=false and intent=authorize into the script tag and actions.order.create() method but I still can't seem to intercept it before it completes. What am I missing?

 

  • Definitely don't want to interrupt PayPal Express Checkout workflow
  • Need to retrieve shipping information and orderID to save to my database server-side, then I have a ID I'd like to assign to the order's Invoice ID as the original post suggests
  • I'm fine to only authorize the payment then capture the funds on the server-side but I'm not sure how to stop the transaction from completing client-side, the button still reads "Pay Now" even when I alter the script tag or pass in a parameter.

Please don't link me to https://developer.paypal.com/docs/checkout/integration-features/update-order-details/ , that's the page I'm referencing but something is malfunctioning.

 

 

 

paypal.Buttons({
                createOrder: function (data, actions) {
                    return actions.order.create({
                        purchase_units: [{
                            amount: {
                                value: amt.toFixed(2)
                            }
                        }]
                    });
                },

                commit: false,
                onApprove: function (data, actions) {
                    return actions.order.capture().then(function (details) { // also tried actions.order.authorize() but no luck
                        if (details.purchase_units.length > 0) {
                            $("#orderid").val(details.id);
                            $("#amount").val(details.purchase_units[0].amount.value);
                            $("#address1").val(details.purchase_units[0].shipping.address.address_line_1);
                            $("#address2").val(details.purchase_units[0].shipping.address.address_line_2);
                            $("#city").val(details.purchase_units[0].shipping.address.admin_area_2);
                            $("#province").val(details.purchase_units[0].shipping.address.admin_area_1);
                            $("#zipcd").val(details.purchase_units[0].shipping.address.postal_code);

                        }
                        $("form#payment").submit();
                    });
                }
            }).render('#paypal-button');

 

 

Thanks,

 

Dan Hermann

MUUSA Webmaster

 

2 REPLIES 2
Highlighted
Contributor

Re: Need to Patch Order but Order Already Completed?

Did you ever figure this out?

I believe I'm having a very similar issue.
The `details` I get back from `actions.order.capture()` always reads ` intent: "CAPTURE", status: "COMPLETED"`.

 

I have similar server-side code to patch the order, I don't get an ORDER_ALREADY_COMPLETED error, I get this one:

`INVALID_REQUEST", message="Request is not well-formed, syntactically incorrect, or violates schema.`

 

I haven't been able to tell if my request is actually invalid, or if I'm just getting this error because the order is already completed. 

 

I am passing commit=false to my script tags, I am pretty sure intent authorize is not what I want, I just want to complete the payment after the user returns to my site from paypal, not days later.

https://developer.paypal.com/docs/checkout/integration-features/auth-capture/#

Highlighted
Contributor

Re: Need to Patch Order but Order Already Completed?

I fixed a few syntax issues, and now I'm definitely getting the same ORDER_ALREADY_COMPLETED error.

 

There must be a way on the client to capture the order without completing it, but I'm just not seeing it.

Is there a different js method to call other than actions.order.capture(), or should that not be called at all?