# Pre-payment validation check

In case of exchange payment, the merchant can check a few validations before initiating a payment ex:

1. Insufficient Balance
2. The deposit address is not whitelisted
3. Password is required
4. etc

This API is NOT a core element of the payment flow. However, this helps to make a user-friendly payment solution.

The validation messages vary from exchange to exchange, but the API returns the same object with a different code that needs to handle at the merchant website.

Example:

1. OKcoin needs the deposit address for the whitelist, so this API checks whether or not the user has already whitelisted this address. In the API response, if the key "showWhitelistElement: true" means the deposit address is not whitelisted and merchant website should display the customer error.
2. A shopper's password is needed to withdraw the fund. If API returns a key "password: true," the shopper didn't provide the password, and the merchant's website should display a message to enter the password.

This API accepts the request payload in an encrypted format. The encryption algo is <*algo\_name> and encryption key is \<client\_*&#x73;ecret>.

```
// The sample request payload that needs to encrypt
{
  "clientId": "merchantid",
  "assets": "Selected exchange currency",
  "cart": "cart array",
  "offerId": "Order_id",
  "confirmation": "true",
  "nativeAmount": "cart amount in usd"
}

// clientId: The RKFL merchant identifier
// assets: Selected exchange currency (BTC/ETH)
// cart: cart array [{},{}]
// offerId: merchant unique identifie
// confirmation: true/false, true if shopper accept term and condition
// nativeAmount: cart total amount in USD

// The key "data" should generate from the below way.
export const data = async (toEncrypt, publicKey) => {
  const buffer = Buffer.from(toEncrypt);
  const encrypted = crypto.publicEncrypt(publicKey, buffer);
  return encrypted.toString('base64');
};
```

<mark style="color:green;">`POST`</mark> `/exchanges/payment-validate/{exchange_name}`

The value of exchange\_name are "coinbase/okcoin/kraken/gemini/binanceus"

#### Headers

| Name                                            | Type   | Description                     |
| ----------------------------------------------- | ------ | ------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | String | "Bearer" + shopper access token |
| Content-Type                                    | String | application/json                |

#### Request Body

| Name                                   | Type   | Description      |
| -------------------------------------- | ------ | ---------------- |
| data<mark style="color:red;">\*</mark> | String | Encrypted string |

{% tabs %}
{% tab title="200: OK Success" %}

```javascript
{
    "ok": true,
    "result": {
        "receiverAddress": "3Jmmku8JTHP2YsqNZ3RuhZdburbdHMtSjT",
        "receiverMemo": null,
        "amount": 0,
        "currency": "BTC",
        "fee": 0.00000526,
        "password": false,
        "showWhitelistElement": false,
        "exchange": "coinbase",
        "nativeAmount": 5,
        "newRate": {
            "percentRate": 0,
            "newFiatRate": 0
        }
    }
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.rocketfuel.inc/developer-guides/api-reference/payins/utility-apis/exchange-payment/pre-payment-validation-check.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
