cancel
Showing results for 
Search instead for 
Did you mean: 

Who Me Too'd this topic

Need to Patch Order but Order Already Completed?

dhermann
Contributor
Contributor

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

 

Login to Me Too
Who Me Too'd this topic