Search code examples
phpjsonrestpaymentpayu

Integration of payments with PayU


I have a problem with integration of payments on PayU . I am not an advanced programmer , but I want to do this on my website. I created an sandbox account on the https://www.payu.pl/en . I was browsing forum but I still don't understand . First I used this code : https://repl.it/@PayU/pop-up-widget . But it's probably a combination of the store itself and the website.

Now probably i must use this code and create order from http://developers.payu.com/en/restapi.html#creating_new_order_api

    curl -X POST https://secure.snd.payu.com/api/v2_1/orders \
-H "Content-Type: application/json" \
-H "Authorization: Bearer d9a4536e-62ba-4f60-8017-6053211d3f47" \
-d '{
    "notifyUrl": "https://your.eshop.com/notify",
    "customerIp": "127.0.0.1",
    "merchantPosId": "300746",
    "description": "RTV market",
    "currencyCode": "PLN",
    "totalAmount": "21000",
    "buyer": {
        "email": "[email protected]",
        "phone": "654111654",
        "firstName": "John",
        "lastName": "Doe",
        "language": "pl"
    },
    "settings":{
        "invoiceDisabled":"true"
    },
    "products": [
        {
            "name": "Wireless Mouse for Laptop",
            "unitPrice": "15000",
            "quantity": "1"
        },
        {
            "name": "HDMI cable",
            "unitPrice": "6000",
            "quantity": "1"
        }
    ]
}'

If it's the correct code, how can I use it? To which format to save this file? How to run this script. I have never used curl and I don't know how to go about it.


Solution

  • The code You posted is a command, which will send an HTTP POST-REQUEST (see https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol).

    The request basically consists of:

    1. The destination address (https://secure.snd.payu.com/api/v2_1/orders), which identifies the server and the path for the request on the server, such that the server can execute the request appropriately.
    2. Two headers, the first informs, which content type the message has and the second provides some kind of identification / authorization.
    3. The message body itself, which provides the server with the actual content of the request.

    This request is executed by means of a terminal command (curl), so to execute it, You have several options. Either, You paste this code exactly like it is show into a terminal to execute it directly, or You save it into a normal text file, which ends on .sh and execute that (after making it executable). These methods of course only work provided You have a unix like operating system and the curl command line utility is in your executable path. However, there are multiply ways of sending an http request, curl is not necessarily needed. There are even some online forms, which allow doing that. Even PayU provides one, which You can find, if You click on the "Try it now" button on the page You just found the command on.

    So this answers your questions. However I still have a few remarks:

    Is it the correct code? It works, I tested it. But since You created an own sandbox account, You are probably supposed to change the line Authorization: Bearer d9a4536e-62ba-4f60-8017-6053211d3f47, such that it contains the authorization code, which You probably received.

    If You want to execute this code on Your website, You need to find out, how to do the request using the language You use for web-developing (e.g. PHP). Then You probably don't need to use curl, but the function in that language using the parts of the request, I pointed out above, appropriately. But that would probably be a new question here.

    Make a comment, if You do not understand parts of my answer and I will extend it.