'2checkout. How to sync Return URL order parameters with my orders in database?
I have a database, in which user orders are recorded. Process:
- The user goes to the product page on the site (I get the products through the admin panel's API), selects the product, clicks on the generated buy link goes to the payment page.
- At this moment, this order is written to my database with the details of the order with the status "Unpaid".
- Next, the user makes a payment and then clicks on the return URL and is redirected to my site.
- Further on my site I get the data using the PHP GET method. Then, in case of successful payment, I need to change the status of the order to "Paid" in my database.
How can I identify the order that was recorded in the database before paying for the goods and the data that came through the return URL after the payment?
Here is my code of creating buy link and return URL, I dont know about correctness:
public function generateBuyLink($code, $qty)
{
$merchant = 'merchant=' . $this->merchantCode;
$template = 'tpl=' . $this->template;
$productCode = 'prod=' . $code;
$quantity = 'qty=' . $qty;
$data = strlen($this->redirectUrl) . $this->redirectUrl;
$signature = 'signature=' . hash_hmac('md5', $data, $this->secretKey);
$returnUrl = 'return-url=' . urlencode($this->redirectUrl);
$buyLink = $this->buyLink . $merchant . '&' . $returnUrl . '&' . $template . '&' . $productCode . '&' . $quantity . '&' . $signature;
// I get this link in the end:
// https://secure.2checkout.com/checkout/buy?merchant=250366051775&return-url=https%3A%2F%2Fmy-site.loc%2Fuser%2Fcallback&return-type=link&tpl=default&prod=431956EE48&qty=1&signature=f701a8c816b1e880624ab0ea23d4c17bfdf05c5a843db2d3fcf86c57b32a0648
return $buyLink;
}
Solution 1:[1]
The return URL should not be encoded.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Federico Schiocchet |
