# Payment Gateway

The CoinbarPay Payment Gateway is a secure web interface that allows your customers to select their preferred cryptocurrency and complete the payment process.&#x20;

By following the steps in this topic, you will learn how to open the CoinbarPay Payment Gateway using the appropriate URL and understand what happens once the payment is executed, canceled, or times out.

## Opening the Payment Gateway

To open the CoinbarPay Payment Gateway for a customer, you will need to construct a URL with the following format:

{% code overflow="wrap" %}

```url
https://sandbox.coinbar.io/paymentgateway/pay?requestToken={{REQUEST_TOKEN}}&serviceClientId={{SERVICE_CLIENT_ID}}&timestamp={{current_timestamp}}
```

{% endcode %}

Replace the following placeholders with actual values for your specific transaction:

* `REQUEST_TOKEN` (requestToken): The payment request token received from the CoinbarPay API upon initiating a new payment request.
* <mark style="color:purple;">`SERVICE_CLIENT_ID`</mark> (serviceClientId): Your account's authentication key (Service Client ID).
* timestamp (timestamp): The current timestamp in milliseconds.

{% hint style="info" %}
When directing the customer to this URL, they will be presented with the CoinbarPay Payment Gateway, where they can choose their preferred cryptocurrency to complete the payment.
{% endhint %}

## Post-Payment Actions

Once the payment is either executed, canceled, or times out, CoinbarPay will perform the following actions:

### **(1) Backend Callback**&#x20;

{% hint style="warning" %}

#### <mark style="color:orange;">Warning</mark>

Your backend system should handle this request by updating the relevant database records, triggering necessary actions, and maintaining a log for future reference.
{% endhint %}

The server will send a secure HTTP request to your configured <mark style="color:blue;">`BE_CALLBACK_URL`</mark> to update the payment status on your shop.&#x20;

Here is an example of response sent by Coinbar Payment Gateway to your web shop :

{% hint style="success" %} <mark style="color:green;">**SUCCESS**</mark> Response :
{% endhint %}

```json
{
    "result" : "success",
    "payment_id_coinbar": "id_48483",
    "payment_request_id_client" : "id_48485354",
    "service_client_id" : "SERVICE_CLIENT_ID",
    "customer" : {
        "email" : "customer.email",
    },
    "products" : [Array of products..],
    "input_coin" : "EUR",
    "status" : "SUCCESS",
    "status_descr" : "Payment Executed",
    "payment_detail" : {
        "transaction_id": "transaction_id",
        "timestamp"  : "timestamp",
        "total_price" :  "total_price",
    },
    "creation_time" : 11111111111,
    "update_time" : 1111111111,
}
```

{% hint style="danger" %} <mark style="color:red;">**FAILED/CANCELED**</mark> Response :
{% endhint %}

```json
{
    "result" : "success",
    "payment_id_coinbar": "id_48483",
    "payment_request_id_client" : "id_48485354",
    "service_client_id" : "SERVICE_CLIENT_ID",
    "customer" : {
        "email" : "customer.email",
    },
    "products" : [Array of products..],
    "input_coin" : "EUR",
    "status" : "FAILED",
    "status_descr" : "Payment timeout",
    "payment_detail" : {
        "transaction_id": "transaction_id",
        "timestamp"  : "timestamp",
        "total_price" :  "total_price",
    },
    "creation_time" : 11111111111,
    "update_time" : 1111111111,
}
```

{% hint style="info" %}
As for incoming calls, the Payment Gateway will send its callback with <mark style="color:purple;">`SERVICE_CLIENT_ID`</mark> and `SIGNATURE_TOKEN` to let your application manage securely the incoming calls.
{% endhint %}

### **(2) Frontend Redirect User**

CoinbarPay will redirect the customer to the configured <mark style="color:blue;">`WEB_CALLBACK_URL`</mark> as set in the CoinbarPay Dashboard, in order to complete the payment flow.&#x20;
