# Payments with Pre-authorization

Preauthorization is a two-stage payment: first the amount on the client's card is blocked and then debited separately upon the merchant's confirmation. This approach is used when it is necessary to guarantee the availability of funds, but to debit them later - for example, after confirmation of an order or service.

How it works:

* Blocking funds - the amount is frozen on the customer's card, but not debited.
* Confirm or cancel - the merchant can either confirm the debit or cancel the payment.
* Automatic unlocking - if the payment is not confirmed within a set period of time, the funds are automatically unlocked.

***

### Initialization of payment with preauthorization

To create a payment with preauthorization it is necessary to pass an additional parameter preauth. The full set of parameters is described on the [page of payment creation](https://help.unitpay.ru/en/payments/create-payment).

<mark style="color:blue;">`GET`</mark> `https://unitpay.ru/api?method=initPayment`

#### Mandatory parameters

<table><thead><tr><th width="186.6666259765625">Name</th><th width="111.2222900390625">Type</th><th>Description</th></tr></thead><tbody><tr><td>preauth</td><td>integer</td><td>Use this flag to create a payment with preauthorization. By default the flag is disabled and the value is 0, to enable it you must pass 1.</td></tr><tr><td>preauthExpireLogic</td><td>integer</td><td>Field for preauthorization payment blocking logic:<br>0 - if there is no request for confirmation or cancelation, the payment will be confirmed upon expiration of the blocking period on the side of the acquiring bank (~114 hours after payment creation);<br>1 - if there is no request for confirmation or cancelation, the payment will be canceled upon expiration of the blocking period on the acquiring bank's side (~114 hours after payment creation).<br><br>If the option is not used, the payment will be canceled after the deadline.</td></tr></tbody></table>

```
{
    "result": {
        "type": "redirect",
        "paymentId": 1234567890,
        "message": "The invoice has been successfully issued and payment is pending",
        "receiptUrl": "https://unitpay.ru/pay/receipt/1234567890-454ac183ac",
        "statusUrl": "https://unitpay.ru/pay/receipt/1234567890-454ac183ac",
        "redirectUrl": "https://unitpay.ru/pay/redirect/1234567890-454ac183ac"
    }
}
```

### Payment confirmation with preauthorization

To confirm a payment with preauthorization (debit of funds blocked on the payer's card), execute this request:

```
GET: https://unitpay.ru/api?method=confirmPayment
     params[paymentId]=2142345678
     params[secretKey]=secretkey
```

#### Mandatory parameters

<table><thead><tr><th width="159">Name</th><th width="104.00006103515625">Type</th><th>Description</th></tr></thead><tbody><tr><td>paymentId</td><td>integer</td><td>Payment ID in the UnitPay system</td></tr><tr><td>secretKey</td><td>string</td><td>Project secret key, available in the project settings</td></tr></tbody></table>

{% tabs %}
{% tab title="Successful response" %}

```
{ "message": "Payment successfully confirmed" }
```

{% endtab %}

{% tab title="Incorrect response" %}

```
{
   "error": {
      "message": "Payment cannot be confirmed"
   }
}
```

{% endtab %}
{% endtabs %}

### Cancellation of payment with preauthorization

To cancel a payment with preauthorization (unblocking of funds on the payer's card), perform the following request:

```
GET: https://unitpay.ru/api?method=cancelPayment
     params[paymentId]=2142345678
     params[secretKey]=secretkey
```

#### Mandatory parameters

<table><thead><tr><th width="172.33331298828125">Name</th><th width="129.77783203125">Type</th><th>Description</th></tr></thead><tbody><tr><td>paymentId</td><td>integer</td><td>Payment ID in the UnitPay system</td></tr><tr><td>secretKey</td><td>string</td><td>Project secret key, available in the project settings</td></tr></tbody></table>

{% tabs %}
{% tab title="Successful response" %}

```
{ "message": "The blocking has been successfully canceled" }
```

{% endtab %}

{% tab title="Incorrect response" %}

```
{
   "error": {
      "message": "Payment cannot be canceled"
   }
}
```

{% endtab %}
{% endtabs %}

{% hint style="danger" %}
Two-stage payments do not work concurrently with [subscriptions](https://help.unitpay.ru/en/payments/recurring-payments).
{% endhint %}
