# Payment Links

## Introduction

* Payment links are a quick and easy way for merchants to accept payments from customers. With Sonic Payment Gateway, you can create unique payment links that can be shared via email, social media, or any other medium.
* Payment links can be customized with various options such as custom amounts, currency, and expiration date. They can also be associated with a specific product or pricing.

## Create a payment link

* Payment links can be created using our API or through the Sonic Payment Gateway Dashboard.

<mark style="color:green;">`POST`</mark> `https://api.sonicpay.org/v1/payment_links`

#### Request Body

| Name                                           | Type                          | Description |
| ---------------------------------------------- | ----------------------------- | ----------- |
| amount<mark style="color:red;">\*</mark>       | 1000                          |             |
| currency<mark style="color:red;">\*</mark>     | USDT                          |             |
| price\_id<mark style="color:red;">\*</mark>    | def456                        |             |
| expiry\_date<mark style="color:red;">\*</mark> | 2022-12-31                    |             |
| metadata                                       | "customer\_name: "John Smith" |             |

{% tabs %}
{% tab title="201: Created " %}
```javascript
{
    "id": "ghi789",
    "url": "https://sonicpay.org/p/ghi789",
    "amount": 1000,
    "currency": "USDT",
    "product_id": "abc123",
    "price_id": "def456
}
```
{% endtab %}
{% endtabs %}

## Get a Payment Link

* To retrieve an existing payment link, you can use the GET endpoint and pass in the payment link ID. This will return a JSON object containing information about the link, including its status, expiration date, and any metadata associated with it.

<mark style="color:blue;">`GET`</mark> `https://api.sonicpay.org/v1/payment_links/{link_id}`

#### Headers

| Name                                                    | Type   | Description |
| ------------------------------------------------------- | ------ | ----------- |
| Authorization: Bearer<mark style="color:red;">\*</mark> | xxxxxx |             |

{% tabs %}
{% tab title="200: OK " %}
```javascript
{
    "id": "5f0efa72-f2b9-4b5d-9c1b-8f8f1e0b0c2d",
    "status": "active",
    "amount": 100,
    "currency": "USD",
    "expires_at": "2022-10-01T00:00:00.000Z",
    "metadata": {
        "product_id": "5f0efa72-f2b9-4b5d-9c1b-8f8f1e0b0c2d"
    }
```
{% endtab %}
{% endtabs %}

## Delete a Payment Link

* To delete a payment link, you will need to make a DELETE request to our API endpoint at [https://api.sonicpay.org/api/v1/%3Cpayment\_link\_id%3E](https://api.sonicpay.org/api/v1/%3Cpayment_link_id%3E). The \<payment\_link\_id> in the endpoint should be replaced with the unique identifier of the payment link you want to delete.
* Before making the request, you will need to include your API key in the headers of the request for authentication.

<mark style="color:red;">`DELETE`</mark> `https://api.sonicpay.org/api/v1/links/<payment_link_id>`

#### Headers

| Name                                                    | Type           | Description |
| ------------------------------------------------------- | -------------- | ----------- |
| Authorization: Bearer<mark style="color:red;">\*</mark> | YOUR\_API\_KEY |             |

{% tabs %}
{% tab title="204: No Content " %}
```javascript
{
    "status": "success",
    "message": "Payment link with id e7f0a97-9de8-4cdc-b130-e8dd5f06caf4 was successfully deleted"
}
```
{% endtab %}
{% endtabs %}

## Update a payment link

* To update a payment link, you will need to make a PUT request to the [https://api.sonicpay.org/api/v1/payment\_links/:id](https://api.sonicpay.org/api/v1/payment_links/:id) endpoint, passing in the updated values in the request body.&#x20;
* The request body should include the updated values for the payment link such as the name, description, amount, and currency.

Here is an example of how to update a payment link using our SDK:

```
const SonicPaymentGateway = require('SonicPaymentGateway')
const client = new SonicPaymentGateway({apiKey: 'your_api_key'})

const linkId = 'link_id'
const updates = {
    name: 'updated name',
    description: 'updated description',
    amount: 1000,
    currency: 'USDT'
}

client.updatePaymentLink(linkId, updates).then((response) => {
    console.log(response)
}).catch((error) => {
    console.log(error)
})

```

<mark style="color:orange;">`PUT`</mark> `https://api.sonicpay.org/api/v1/payment_links/:id`

#### Headers

| Name                                                     | Type             | Description |
| -------------------------------------------------------- | ---------------- | ----------- |
| Authorization: Bearer <mark style="color:red;">\*</mark> | your\_api\_key   |             |
| Content-Type<mark style="color:red;">\*</mark>           | application/json |             |

#### Request Body

| Name                                          | Type                | Description |
| --------------------------------------------- | ------------------- | ----------- |
| name<mark style="color:red;">\*</mark>        | Updated Name        |             |
| description<mark style="color:red;">\*</mark> | Updated Description |             |
| amount<mark style="color:red;">\*</mark>      | 100                 |             |
| currency<mark style="color:red;">\*</mark>    | USDT                |             |

{% tabs %}
{% tab title="200: OK " %}
```javascript
HTTP/1.1 200 OK
Content-Type: application/json
{
    "id": "5f0efa72-f2b9-4b5d-9c1b-8f8f1e0b0c2d",
    "name": "updated name",
    "description": "updated description",
    "amount": 100,
    "currency": "USDT",
    "created_at": "2022-01-19T00:00:00.000Z",
    "updated_at": "2022-01-19T00:00:00.000Z"
}

```
{% endtab %}
{% endtabs %}

| Parameter   | Type   | Required | Description                             |
| ----------- | ------ | -------- | --------------------------------------- |
| name        | string | Yes      | Updated name of the payment link        |
| description | string | No       | Updated description of the payment link |
| amount      | number | No       | Updated amount of the payment link      |
| currency    | string | No       | Updated currency of the payment link    |

\
Get all Payment Links
---------------------

* To retrieve all payment links, you will need to make a GET request to the [https://api.sonicpay.org/api/v1/payment\_links](https://api.sonicpay.org/api/v1/payment_links)

Here is an example of how to retrieve all payment links using our SDK:

```
const SonicPay = require('SonicPay')
const client = new SonicPay({apiKey: 'your_api_key'})

client.getAllPaymentLinks().then((response) => {
    console.log(response)
}).catch((error) => {
    console.log(error)
})

```

<mark style="color:blue;">`GET`</mark> `https://api.sonicpay.org/api/v1/payment_links`

#### Headers

| Name                                                    | Type             | Description |
| ------------------------------------------------------- | ---------------- | ----------- |
| Content-Type<mark style="color:red;">\*</mark>          | application/json |             |
| Authorization: Bearer<mark style="color:red;">\*</mark> | your\_api\_key   |             |

{% tabs %}
{% tab title="200: OK " %}
```javascript
HTTP/1.1 200 OK
Content-Type: application/json
{
    "payment_links": [
        {
            "id": "5f0efa72-f2b9-4b5d-9c1b-8f8f1e0b0c2d",
            "name": "Payment Link 1",
            "description": "This is a payment link for product 1",
            "amount": 100,
            "currency": "USD",
            "created_at": "2022-01-19T00:00:00.000Z",
            "updated_at": "2022-01-19T00:00:00.000Z"
        },
        {
            "id": "5f0efa72-f2b9-4b5d-9c1b-8f8f1e0b0c2e",
            "name": "Payment Link 2",
            "description": "This is a payment link for product 2",
            "amount": 50,
            "currency": "USD",
            "created_at": "2022-01-19T00:00:00.000Z",
            "updated_at": "2022-01-19T00:00:00.000Z"
        }
    ]
}

```
{% endtab %}
{% endtabs %}

You can also pass in query parameters to filter the payment links returned such as `status`, `created_at`, `updated_at`, and `limit`.

Example:

```
const filters = {
    status: 'active',
    limit: 10
}

client.getAllPaymentLinks(filters).then((response) => {
    console.log(response)
}).catch((error) => {
    console.log(error)
})

```
