0

I have a database, in which user orders are recorded. Process:

  1. 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.
  2. At this moment, this order is written to my database with the details of the order with the status "Unpaid".
  3. Next, the user makes a payment and then clicks on the return URL and is redirected to my site.
  4. 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;
    }
8
  • 1
    The details are a bit vague. You mention that the user "makes a payment and then clicks on the return URL and is redirected to my site". Does that mean you are using a third-party website to make payments, like PayPal? Could you please specify if so? Please also share the code fragments for the "PHP GET" and a sample of the redirect URL, if possible. Commented May 28, 2020 at 14:17
  • @chaseisabelle The "Return URL" is generated by the 2checkout API on the same page, where user makes payment, I dont use any 3-d pary websites. I setup return URL from documentation (knowledgecenter.2checkout.com/Documentation/07Commerce/…) (knowledgecenter.2checkout.com/Documentation/07Commerce/…). I use GET like documentation says, no other parameters and in any other form comes anymore. $params = $_GET; Commented May 28, 2020 at 14:48
  • How you create a payment link and return link? Commented May 28, 2020 at 16:10
  • @SergheiLeonenco, I updated the quastion, please look. Commented May 28, 2020 at 16:27
  • 2
    Create a method where you will add order_id as a parameter to your return url https://my-site.loc/user/callback?order_id=2 and parse this id in your action. Commented May 28, 2020 at 17:14

1 Answer 1

0

The return URL should not be encoded.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.