> For the complete documentation index, see [llms.txt](https://developers.klasha.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.klasha.com/accepting-payments/payment-link/payment-link-api.md).

# Payment Link API

### Summary

The Payment Link API allows merchants to generate payment links for their sub-merchants to easily collect payments. Follow these steps to integrate:

1. Generate a Bearer Token
2. Create a Payment Link
3. Share the Payment Link
4. Monitor Payment Status
5. Fetch payment link transactions via `paylinkId`

{% hint style="info" %}
Before you begin!
{% endhint %}

## Integration steps

## Generate a Bearer Token

Obtain a token by following the authentication guide [here](https://developers.klasha.com/~/revisions/Tw5bfW3awcozGbmqzgEE/overview/authentication). Use this token as your Bearer token in subsequent API calls.

## Create a Payment Link

> <mark style="color:yellow;">**POST**</mark> - <mark style="color:$primary;">`{{env_url}}/merchant/api/v1/paylink/create`</mark>

This api generates a payment link that can be given to your customers to make payments.

**NB**: No need for an encryption of the plain json payload.

#### Headers

| Name          | Value                                                        |
| ------------- | ------------------------------------------------------------ |
| Authorization | Bearer <mark style="color:$primary;">{{token}}</mark>        |
| x-auth-token  | <mark style="color:$primary;">{{MERCHANT PUBLIC KEY}}</mark> |

#### Request Body

| Name                                            | Type    | Description                                                |
| ----------------------------------------------- | ------- | ---------------------------------------------------------- |
| name<mark style="color:red;">\*</mark>          | String  | Sub-Merchant Name                                          |
| subMerchantId<mark style="color:red;">\*</mark> | String  | Sub-Merchant Identification                                |
| description<mark style="color:red;">\*</mark>   | String  | Intending product or service.                              |
| currency<mark style="color:red;">\*</mark>      | String  | NGN                                                        |
| amount<mark style="color:red;">\*</mark>        | Decimal | <p>Amount to accept for the </p><p>product or service.</p> |

See an example of the plain json payload to send.

{% tabs fullWidth="true" %}
{% tab title="Sample Request" %}

```json
{
    "name": "Klash",
    "subMerchantId": "sub-klasha-23456",
    "description": "Payment for 1000 naira purchase",
    "currency": "NGN",
    "amount": 1000
}
```

{% endtab %}
{% endtabs %}

#### Response

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

```json
{
    "message": "success",
    "error": null,
    "data": {
        "paylinkId": "b8d0aab0-5974-45a6-ae4a-8b6d519b4da2",
        "paylinkUrl": "https://dev.d2qotb20wbiarg.amplifyapp.com/?token=b8d0aab0-5974-45a6-ae4a-8b6d519b4da2",
        "businessId": "111"
    }
}
```

{% endtab %}
{% endtabs %}

## Share the Payment Link

Distribute the generated payment link URL to your sub-merchants for them to receive payments. The link directs customers to a payment page (See sample of the page below).

<figure><img src="/files/EJvVEEqA04mOonlSxeiG" alt="" width="563"><figcaption><p>Paylink page for the customer to fill and click Pay with klasha button to proceed.</p></figcaption></figure>

## Monitor Payment Status

We would send payment status updates to your configured webhook URL. Monitor this to track payment outcomes. See webhook details [here](https://developers.klasha.com/~/revisions/ZnKl9fQgoz2UyPgPcwp6/misc/webhook).

## Fetch payment link transactions

> <mark style="color:green;">**GET**</mark> - <mark style="color:$primary;">`{{env_url}}/nucleus/paymentLinkTransaction/id/{{paylinkId}}`</mark>

This api fetches all transactions associated to the `paylinkId` generated above.

#### Headers

| Name                                            | Value                                                     |
| ----------------------------------------------- | --------------------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | Bearer <mark style="color:red;">`{{token}}`</mark>        |
| x-auth-token<mark style="color:red;">\*</mark>  | <mark style="color:red;">`{{MERCHANT PUBLIC KEY}}`</mark> |

#### Params

| Name                                        | Type   | Description                                  |
| ------------------------------------------- | ------ | -------------------------------------------- |
| paylinkId<mark style="color:red;">\*</mark> | String | paylink id generated while creating the link |

#### Response

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

```json
{
    "message": "success",
    "error": null,
    "data": [
        {
            "id": 155,
            "amount": 305.00,
            "currency": "KES",
            "sourceAmount": 305.000000,
            "sourceCurrency": "KES",
            "paymentLinkId": "10df0c84-11ec-434c-9020-33d79c0c7a5a",
            "subMerchantId": "89989aa6-7b59-429b-b855-27c289f02fb0",
            "status": "successful",
            "message": "Transaction Successful",
            "tnxRef": "paylink-87858e5b-8eba-4ebe-8cf4-7883f92c5c10",
            "gateRef": "3378988429",
            "paymentType": "MOBILE_MONEY",
            "customerEmail": "test@example.com"
        },
        {
            "id": 154,
            "amount": 1724.03,
            "currency": "NGN",
            "sourceAmount": 305.000000,
            "sourceCurrency": "KES",
            "paymentLinkId": "10df0c84-11ec-434c-9020-33d79c0c7a5a",
            "subMerchantId": "89989aa6-7b59-429b-b855-27c289f02fb0",
            "status": "failed",
            "message": "payment not authorised",
            "tnxRef": "paylink-bf1e85d5-f6e4-475f-b466-87693311a8c7",
            "gateRef": "",
            "paymentType": "BANK_TRANSFER",
            "customerEmail": "fooboo@test.com"
        }
    ]
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://developers.klasha.com/accepting-payments/payment-link/payment-link-api.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
