How to add a number of the order to the redirect URL (2checkout)?

214 Views Asked by At

I set up payments through the payment system 2checkout.com. I have a problem with the redirect URL. I need a redirect to my site after payment. And I need the order number in the redirect URL. But he's not there. How do I add this parameter to a redirect URL?

2

There are 2 best solutions below

0
On

If you are using hosted checkout with using this method \Twocheckout_Charge::form($params, 'auto');, then use "return_url" => 'YOUR-RETURN-URL-HERE' parameter for redirect on your custom URL after placed an order.

You can also use Order No. or any parameter in return_url e.g: "return_url" => 'yourdomain.com/order-placed/123', or "return_url" => 'yourdomain.com/order-placed?order_id=123',

Or if you are using Checkout as charge on your own website by using this method: $charge = \Twocheckout_Charge::auth(); then try this code:

if ($charge['response']['responseCode'] == 'APPROVED') 
    {
        $statusMsg = "";
        $statusMsg = '<h2>Thanks for your Order!</h2>';
        $statusMsg .= '<h4>The transaction was successful. Order details are given below:</h4>';
        $statusMsg .= "<p>Response Code: ".$charge['response']['responseCode']."</p>";
        $statusMsg .= "<p>Order ID: ".$charge['response']['orderNumber']."</p>";
        $statusMsg .= "<p>Transaction ID: ".$charge['response']['transactionId']."</p>";
        $statusMsg .= "<p>Order Total: ".$charge['response']['total']." USD</p>";
    }
    else
    {
        $statusMsg = "";
        $statusMsg .= "<p>Transaction Faild. Response Code: ".$charge['response']['responseCode']."</p>";
    }

    REDIRECT HERE: on yourdomain.com/order-placed/$charge['response']['orderNumber']
1
On

Have you checked the 2checkout documentation for accepted parameters for checkout?

Find 2checkout documentation for all available parameters. https://knowledgecenter.2checkout.com/Documentation/07Commerce/2Checkout-ConvertPlus/ConvertPlus_URL_parameters