alt

Important information

The API reference is now available here.
The deprecated API reference is available here.

Unzer

Accept PayU with server-side-only integration

Build your own payment form to add PayU payment to your checkout page.

Overview

PayU doesn’t require any input from the customer on the merchant website. The customer must be redirected to PayU to provide the required information to process the transaction. After that, the customer is redirected back to the merchant’s website, displaying the result of the payment.

<h2 id="before-you-begin">Before you begin</h2>

Step 1: Create a payment type resource
server side

When creating the payment type payu, you need to send a request to the Unzer API. The response will contain an id, this is later referred to as typeId. You will need this typeId to perform the transaction.

POST https://api.unzer.com/v1/types/payu/
<?php
$unzer = new Unzer('s-priv-xxxxxxxxxx');
$payU = $unzer->createPaymentType(new PayU());
Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");

PayU payU = unzer.createPaymentType(new PayU());

The response looks similar to the following example:

{
    "id": "s-pyu-mnzdgnjmuane",
    "method": "payu",
    "recurring": false,
    "geoLocation": {
        "clientIp": "127.0.0.1",
        "countryIsoA2": "DE"
    }
}

For a full description of PayU payment type creation, check the API reference.

Step 2: Make a payment
server side

Make a charge transaction

Now, make a charge transaction with the payu typeId that you created in step 1 and the returnUrl leading back to your shop after the payment is finished on the external page. With the charge transaction, an amount is requested but is not yet transferred. Initially the transaction will be pending and a payment resource is created.

POST https://api.unzer.com/v1/payments/charges
{
  "amount" : "1",
  "currency" : "PLN",
  "returnUrl": "https://www.unzer.com",
  "resources" : {
    "typeId" : "s-pyu-mnzdgnjmuane",
      "customerId": "s-cst-041fbdedbb9b"
  }
}
<?php
$unzer     = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');

$charge = new Charge(100.00, 'PLN', 'https://www.my-shop-url.de/returnhandler');
$typeId = 's-pyu-3qujdbdjas5w';

$unzer->performCharge($charge, $typeId);
Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");

Charge charge = (Charge) new Charge()
        .setAmount(BigDecimal.valueOf(190.00))
        .setCurrency(Currency.getInstance("PLN"))
        .setTypeId("s-pyu-zex7c9iibpek")
        .setReturnUrl(unsafeUrl("https://www.my-shop-url.de/returnhandler");

unzer.charge(charge);

The response looks similar to the following example:

{
    "id": "s-chg-1",
    "isSuccess": false,
    "isPending": true,
    "isResumed": false,
    "isError": false,
    "card3ds": false,
    "redirectUrl": "https://payment.unzer.com/v1/redirect/payu/s-dsm7nSlWTBee",
    "message": {
        "code": "COR.000.000.000",
        "merchant": "Transaction succeeded",
        "customer": "Your payments have been successfully processed."
    },
    "amount": "1.0000",
    "currency": "PLN",
    "returnUrl": "https://www.unzer.com",
    "date": "2023-08-23 09:41:29",
    "resources": {
        "customerId": "s-cst-041fbdedbb9b",
        "paymentId": "s-pay-2",
        "traceId": "8843268aa44e31f6f8cef582ae5bcea9",
        "typeId": "s-pyu-mnzdgnjmuane"
    },
    "paymentReference": "",
    "processing": {
        "uniqueId": "6925139e.a763.495e.bbd2.6ee3679834bf",
        "shortId": "2226.5195.0176",
        "traceId": "8843268aa44e31f6f8cef582ae5bcea9"
    }
}

For a full description of the charge transaction, refer to the relevant server-side integration documentation page: Charge a payment (direct API calls), Charge a payment (PHP SDK), Charge a payment (Java SDK).

Step 3: Check status of the payment
server side

Once the customer is redirected to the returnUrl, you can fetch the payment details from the API, by using the resources.paymentId from the charge response above to handle the payment according to its status. If the status of the payment is completed , the payment process has been finished successfully and can be considered as paid. Check all possible payment states here.

GET: https://api.unzer.com/v1/payments/s-pay-2
{
    "id": "s-chg-1",
    "isSuccess": true,
    "isPending": false,
    "isResumed": false,
    "isError": false,
    "card3ds": false,
    "redirectUrl": "",
    "message": {
        "code": "COR.000.000.000",
        "merchant": "Transaction succeeded",
        "customer": "Your payments have been successfully processed."
    },
    "amount": "1.0000",
    "currency": "PLN",
    "returnUrl": "https://www.unzer.com",
    "date": "2023-08-23 09:41:29",
    "resources": {
        "customerId": "s-cst-041fbdedbb9b",
        "paymentId": "s-pay-2",
        "basketId": "",
        "metadataId": "",
        "payPageId": "",
        "traceId": "8843268aa44e31f6f8cef582ae5bcea9",
        "typeId": "s-pyu-mnzdgnjmuane"
    },
    "paymentReference": "",
    "processing": {
        "uniqueId": "eef44197.5aa5.444d.b169.797fa2a8dd5f",
        "shortId": "2226.5668.2560",
        "traceId": "8843268aa44e31f6f8cef582ae5bcea9"
    }
}
<h2 id="step-4-display-the-payment-result-client-side">Step 4: Display the payment result <div class='uds-tag uds-raspberry'>client side</div></h2>

Use the information from the Check status of the payment step to display the payment result to your customer.
This can be the success or error page of your shop. If something went wrong, you can use the client message from the API response and show it to the customer.

Manage payment
server side

For more details on managing PayU payments, such as refunding them, see Manage PayU payments.

Notifications

We recommend subscribing to the payment event to receive notifications about any changes to the payment resource. As soon as the event is triggered you should fetch the payment and update the order status in your shop according to its status.

  {
    "event":"payment.pending",
    "publicKey":"s-pub-xxxxxxxxxx",
    "retrieveUrl":"https://api.unzer.com/v1/payments/s-pay-774",
    "paymentId":"s-pay-774"
  }

For more details on implementing webhooks to receive notifications, see Notifications page.

Error handling

All requests to the API can result in an error that should be handled. Refer to the Error handling guide to learn more about Unzer API (and other) errors and handling them.

Test & go live

You should always test your integration before going live. First perform test transactions using test data. Next, check against Integration checklist and Go-live checklist to make sure the integration is complete and you’re ready to go live.

See also