# Creating payment link

<mark style="color:green;">`POST`</mark> `/api/public/v1/payment_links`

This endpoint creates payment links.

**Headers**

| Name          | Value                      |
| ------------- | -------------------------- |
| Content-Type  | `application/vnd.api+json` |
| Authorization | `Bearer <api_key>`         |

**Request Body**

| Name                                 | Type   | Required | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ------------------------------------ | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| data.type                            | string | Yes      | Can only be `payment_links`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| data.attributes.amount               | string | Yes      | Payment amount to display to end users.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| data.attributes.currency             | string | Yes      | Payment currency to display to end users. Refer to [supported](https://docs.txn.io/api-basics/supported-currencies) currencies.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| data.attributes.accountCurrency      | string | No       | Specifies the merchant account to be used for crediting invoice payments or debiting payout amounts. Can be EUR, USD, USDT or USDC.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| data.attributes.paymentType          | string | Yes      | Payment type. Can be either `Invoice` or `Payout`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| data.attributes.paymentMethods       | array  | No       | <p>This field is an array listing the supported payment methods for a particular invoice.</p><p></p><p>Can be ONE of these possible values:</p><p></p><ul><li><code>"on\_chain"</code> - Generates a deposit wallet address for receiving an <strong>on-chain cryptocurrency transaction</strong>. Users can send crypto directly from their wallet.</li><li><code>"binance\_pay"</code> - Generates payment instructions for an <strong>off-chain payment via the Binance app</strong>, allowing users to complete the transaction within Binance.</li><li><code>"nft"</code> - Generates payment instructions for purchasing an NFT.</li></ul><p>If no value supplied, defaults to <code>"on\_chain"</code>.</p> |
| data.attributes.payCurrencies\[]     | array  | No       | If you want to limit the cryptocurrency and token options your end-users can make payments in, provide a list of allowed options. Refer to [supported](https://docs.txn.io/api-basics/supported-currencies) currencies.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| data.attributes.reference            | string | No       | The custom reference ID to tie the payment to end-user. This can be anything you choose. Must be a unique value for each payment you create.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| data.attributes.expires\_at          | string | Yes      | Payment link expiration date and time. Follow the format `2025-01-12T23:00:00.000Z`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| data.attributes.successRedirectUrl   | string | No       | Only applicable to Invoices. URL you want your customer to be redirected from our hosted page to if the invoice completes.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| data.attributes.unsuccessRedirectUrl | string | No       | Only applicable to Invoices. URL you want your customer to be redirected from our hosted page to if the invoice gets expired, cancelled or rejected.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |

**cURL**

```json
curl -X "POST" "https://api.sandbox.txn.pro/api/public/v1/payment_links" \
     -H 'Content-Type: application/vnd.api+json' \
     -H 'Authorization: Bearer ' \
     -d $'{
  "data": {
    "type": "payment_links",
    "attributes": {
      "amount": "100",
      "currency": "EUR",
      "accountCurrency": "EUR",
      "reference": "8c40d8b6-ccdf-4861-a6d6-6c3125ce3f31",
      "expires_at": "2025-01-12T23:00:00.000Z",
      "paymentType": "Invoice",
      "paymentMethods": [
        "on_chain"
      ],
      "payCurrencies": [
        "USDC"
      ],
      "successRedirectUrl": "https://example.com/success",
      "unsuccessRedirectUrl": "https://example.com/fail"
    }
  }
}'
```

**Response Body**

<table><thead><tr><th>Name</th><th width="97">Type</th><th>Description</th></tr></thead><tbody><tr><td>data.id</td><td>string</td><td>Payment link ID.</td></tr><tr><td>data.type</td><td>string</td><td>Entity type returned. Always <code>paymentLinks</code>.</td></tr><tr><td>data.attributes</td><td>object</td><td>Set of payment attributes.</td></tr><tr><td>data.attributes.amount</td><td>string</td><td>Payment amount to display to end users.</td></tr><tr><td>data.attributes.currency</td><td>string</td><td>Payment currency to display to end users. Refer to <a href="../api-basics/supported-currencies">Supported currencies</a>.</td></tr><tr><td>data.attributes.accountCurrency</td><td>string</td><td>Specifies the merchant account to be used for crediting invoice payments or debiting payout amounts.</td></tr><tr><td>data.attributes.network</td><td>string</td><td>Payment network code. E.g. <code>trx:usdt</code>. Refer to <a href="../api-basics/supported-currencies">Supported currencies</a>.</td></tr><tr><td>data.attributes.networkName</td><td>string</td><td>Payment network name. E.g. <code>Tron (TRC20)</code>. Refer to <a href="../api-basics/supported-currencies">Supported currencies</a>.</td></tr><tr><td>data.attributes.reference</td><td>string</td><td>The custom reference ID to tie the payment to end-user.</td></tr><tr><td>data.attributes.hostedPageUrl</td><td></td><td>The payment hosted page URL to redirect your end-users to.</td></tr><tr><td>data.attributes.status</td><td>string</td><td>Payment link status context. Can be <code>created</code>, <code>pending</code>, <code>completed</code>, <code>expired</code>.</td></tr><tr><td>data.attributes.network</td><td>string</td><td>Network code. Refer to <a href="../api-basics/supported-currencies">Supported currencies</a>.</td></tr><tr><td>data.attributes.expiresAt</td><td>string</td><td>Payment link expiry date and time.</td></tr><tr><td>data.attributes.createdAt</td><td>string</td><td>Date and time payment was created at.</td></tr><tr><td>data.attributes.paymentType</td><td>string</td><td>Payment type. Can be either <code>Invoice</code> or <code>Payout</code>.</td></tr><tr><td>data.attributes.paymentMethods[]</td><td>array</td><td>Available payment methods.</td></tr><tr><td>data.attributes.payCurrencies[]</td><td>array</td><td>A list of cryptocurrency and token options your end-users can make payments in. This can be left empty if no value is passed in the request.</td></tr><tr><td>data.attributes.successRedirectUrl</td><td>string</td><td>URL you want your customer to be redirected from our hosted page to if the invoice completes.</td></tr><tr><td>data.attributes.unsuccessRedirectUrl</td><td>string</td><td>URL you want your customer to be redirected from our hosted page to if the invoice gets expired, cancelled or rejected.</td></tr><tr><td>data.relationships.target</td><td>object</td><td>This object will contain ID of the child Invoice or Payout generated by the Payment Link.</td></tr><tr><td>included</td><td>array</td><td>This array will contain data about the child Invoice or Payout generated by the Payment Link. For more details refer to <a href="../invoices/reading-invoice">Invoice</a> and <a href="../payouts/reading-payout">Payout</a> pyaloads.</td></tr></tbody></table>

**Response**

{% tabs %}
{% tab title="HTTP 201" %}

```json
{
  "data": {
    "id": "1e1a0c1b-4af0-4e3d-ae87-e31776a60a2c",
    "type": "paymentLinks",
    "attributes": {
      "amount": "100.00",
      "currency": "EUR",
      "accountCurrency": "EUR",
      "network": null,
      "networkName": null,
      "reference": "8c40d8b6-ccdf-4861-a6d6-6c3125ce3f31",
      "hostedPageUrl": "https://sandbox.txn.pro/redirect?payment_link_id=1e1a0c1b-4af0-4e3d-ae87-e31776a60a2c\u0026request_type=payment_link_hosted_page",
      "status": "created",
      "expiresAt": "2025-01-12T23:00:00.000Z",
      "createdAt": "2025-01-12T07:44:19.246Z",
      "paymentType": "Invoice",
      "successRedirectUrl": "https://example.com/success",
      "unsuccessRedirectUrl": "https://example.com/fail",
      "paymentMethods": [
        "on_chain"
      ]
    },
    },
    "relationships": {
      "target": {
        "data": null
      }
    }
  },
  "meta": {},
  "jsonapi": {
    "version": "1.0"
  }
}
```

{% endtab %}

{% tab title="HTTP 422" %}

```json
{
  "errors": [
    {
      "title": "Reference duplicate",
      "detail": "8c40d8b6-ccdf-4861-a6d6-6c3125ce3f31",
      "code": "reference_duplicate"
    }
  ]
}

// Dplicate reference.
```

{% endtab %}

{% tab title="HTTP 422" %}

```json
{
  "errors": [
    {
      "status": 422,
      "title": "Unsupported pay currency",
      "code": "unsupported_pay_currency",
      "detail": ""
    }
  ]
}

// Cryptocurrency code supplied in 'payCurrencies' array is not supported.
```

{% endtab %}
{% endtabs %}
