# Trigger Exchange payment

When the shopper makes the exchange payment, this API creates a transaction record in the RKFL system.&#x20;

A crypto transaction may take 2 min to 2 hours to complete the transaction. When a crypto transaction is initiated successfully, this API returns the immediate status of the transaction, which can be pending/processing/canceled/completed.&#x20;

The RKFL wallet receives all crypto transactions and settles with the merchant daily.&#x20;

The merchant can set up a webhook through the merchant portal to receive updates on every status change in the RKFL system. The merchant must set up only one webhook for crypto and bank transfer.&#x20;

This API receives the request payload in an encrypted format, where the encryption algorithm is RSA, and the encryption key is the merchant's public key.

```
// The sample request payload that needs to encrypt
{
  "clientId": "cc238708-02a0-48af-a70d-9d05cfe3a66d",
  "assets": "BTC",
  "cart": [
    {
      "id": "1",
      "name": "Starbucks Gift Card",
      "price": 2,
      "quantity": 1,
      "localAmount": 2,
      "localCurrency": "USD"
    },
    {
      "id": "3",
      "name": "Best Buy Gift Card",
      "price": 2,
      "quantity": 1,
      "localAmount": 2,
      "localCurrency": "USD"
    },
    {
      "id": "5",
      "name": "Amazon Gift Card",
      "price": 1,
      "quantity": 1,
      "localAmount": 1,
      "localCurrency": "USD"
    }
  ],
  "shippingAddress": {
    "city": "jam",
    "email": "john@exmaple.com",
    "state": "jh",
    "country": "india",
    "phoneNo": "+1 123456789",
    "zipcode": "831008",
    "address1": "some address",
    "address2": "",
    "landmark": "",
    "lastname": "Doe",
    "firstname": "John"
  },
  "offerId": "1656674750778",
  "nativeAmount": "5",
  "savepassword": false,
  "code2fa": "",
  "merchantStoreCurrency": "USD"
}

// clientId is the RKFL merchant id.

// 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/payments/{exchange_name}`

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

**Error codes to be handled over the front end in payment API**

code: 418,&#x20;

message: 'Authentication Failed! Please try again after some time.'&#x20;

&#x20;

code: 419,&#x20;

message: 'Insufficient Balance'&#x20;

&#x20;\
&#x20;code: 420,&#x20;

message: 'Address whitelist is pending!' \
&#x20;

&#x20;code: 421,&#x20;

&#x20;message: 'Coin Wallet is not supported at this moment! please try again after some time.' \
&#x20;

&#x20; code: 422,&#x20;

message: 'Amount is less than minimum transaction amount supported by'&#x20;

&#x20; &#x20;

#### 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 | String | Enctrypted string |

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

```javascript
{
  "id": "176c7937-b4c9-48ac-bda9-a9b1a9472de1",
  "status": 1,
  "nativeAmount": "5.00",
  "nativeCurrency": "USD",
  "amount": "0.00423297",
  "receivedAmount": "0.00423227",
  "currency": "ETH",
  "type": 0,
  "description": null,
  "check": [
    {
      "id": "1",
      "num": 0,
      "name": "In store",
      "price": 5,
      "quantity": 1,
      "localAmount": 5,
      "statusRefund": {
        "pending": 0,
        "success": 0,
        "rejected": 0
      },
      "amountFinal": 5
    }
  ],
  "subscriptionIds": [
    
  ],
  "subscriptionOrder": false,
  "meta": {
    "hash": {
      "value": [
        "794afe809c063d6655d638dd731f07212063ebc967a8fc963334ab65fa0dfc2b"
      ],
      "network": "ethereum"
    },
    "offerId": "8ac346d4-19c2-4f55-b1f0-c3588ca16140",
    "receiverAddress": "0x27544a72AcB6567Dc261cB38c651dA96DD4C9bf4"
  },
  "stockId": null,
  "userId": null,
  "merchantId": "14ec584d-53af-476d-aacd-2b7f025cf21b",
  "settlementId": "fcec8a08-dd19-485d-9657-dd64498b0f83",
  "statusRefund": 20,
  "localAmount": "5.00",
  "referenceDwolla": null,
  "localCurrency": "USD",
  "merchantPayableAmount": "5",
  "errorMessage": null,
  "settlementStatus": 1,
  "txMetaId": "9504cebd-841a-4eb2-aed4-660522fed92d",
  "partnerId": null,
  "createdBy": "14ec584d-53af-476d-aacd-2b7f025cf21b",
  "createdAt": "2022-06-21T14:32:34.529Z",
  "updatedAt": "2022-06-21T15:44:55.400Z",
  "merchant": {
    "shopData": {
      "url": "https://webhook.site",
      "logo": "https://dev-rocketfuel-videos.s3.us-east-1.amazonaws.com/shoplogo/MTRlYzU4NGQtNTNhZi00NzZkLWFhY2QtMmI3ZjAyNWNmMjFi_1651734165.png",
      "companyName": "Rocketfuel",
      "description": "buy rocket fuel at cheap price"
    }
  },
  "customer": {
    "email": "",
    "fullname": ""
  },
  "currencyInfo": {
    "isFiat": false
  },
  "stock": null,
  "partner": null,
  "txMetadata": {
    "id": "9504cebd-841a-4eb2-aed4-660522fed92d",
    "shippingAddress": null,
    "nativeConversionRate": "1"
  },
  "receivedAmountFinal": 5,
  "receivedAmountCal": 4.999178485307677
}
```

{% 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/trigger-exchange-payment.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.
