# Pay Invoice

As We learned in the earlier section about [invoices](https://docs.relysia.com/payments/invoices), there are advantages to pre-determine request amounts. From a infrastructure perspective, it is advantageous to create invoice alike schemas even if no invoice was given to exactly determine what script to use to make certain payments.&#x20;

The [/pay](#undefined) endpoint takes up [lookup ](https://docs.relysia.com/payments/uri)response formats and triggers a payment. While that might sound a bit complex, we can imagine is as a standardization machine that can take up a variety of formats without worrying about their compatibility. \
\
Similar to the get invoice methods, there are also two ways to pay for an invoice. This includes an internal method and and external method.

{% hint style="info" %}
Whereas the payment endpoint is essential to complete invoice requests, we created utility wrappers around the pay endpoint, such as the [/send](https://docs.relysia.com/payments/transactions) endpoint that lets you define address, type and amount to make transactions in a simpler format.&#x20;
{% endhint %}

### Pay Invoice using by URI response (external)

To make a invoice payment, take the response of the [URI](https://docs.relysia.com/payments/invoices/get-invoice) endpoint (the **data**) without any additional changes to pay a payment invoice.&#x20;

#### DPP using /pay

This is an example of paying for a DPP invoice using the /pay endpoint. Please check in [Get Invoice ](https://docs.relysia.com/payments/invoices/get-invoice)to get extended values for the body input using DPP.

## Pay an Invoice

<mark style="color:green;">`POST`</mark> `https://api.relysia.com/v1/pay`

The endpoint enables users to pay their invoices that were earlier resolved and put into a standardized format by the /URI endpoint.

#### Request Body

| Name                                           | Type   | Description |
| ---------------------------------------------- | ------ | ----------- |
| network<mark style="color:red;">\*</mark>      | String |             |
| uri<mark style="color:red;">\*</mark>          | String |             |
| memo<mark style="color:red;">\*</mark>         | String |             |
| type<mark style="color:red;">\*</mark>         | String |             |
| paymentUrl<mark style="color:red;">\*</mark>   | String |             |
| mainProtocol<mark style="color:red;">\*</mark> | String |             |
| modes<mark style="color:red;">\*</mark>        | Object |             |
| beneficiary <mark style="color:red;">\*</mark> | Object |             |
| version<mark style="color:red;">\*</mark>      | String |             |

#### BIP270 using /pay

This is an example if paying for a BIP270 invoice using the /pay endpoint. Please check in [Get Invoice ](https://docs.relysia.com/payments/invoices/get-invoice)to get extended values for the body input using BIP270.<br>

## Pay an Invoice

<mark style="color:green;">`POST`</mark> `https://api.relysia.com/v1/pay`

The endpoint enables users to pay their invoices that were earlier resolved and put into a standardized format by the /URI endpoint.

#### Request Body

| Name         | Type   | Description |
| ------------ | ------ | ----------- |
| uri          | String |             |
| type         | String |             |
| mainProtocol | String |             |
| outputs      | Array  |             |
| inputs       | Array  |             |
| memo         | String |             |
| isBSV        | String |             |
| peer         | String |             |
| peerData     | String |             |
| peerProtocol | String |             |

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

```json
{
  "statusCode": 200,
  "data": {
    "status": "success",
    "msg": "Transaction sent successfully",
    "txid": "80e5b09f1613a0f82c94216e84db747b80b631be8618eb97f3ea4ab440ea223f"
  }
}
```

{% endtab %}
{% endtabs %}

### Pay Invoice using payment-request Invoice (internal)

This method involves constructing a transaction using the[ /rawTx ](https://docs.relysia.com/payments/raw-transactions)API and using it as a parameter in another API to associate it with an internal invoice ID for payment confirmation.

Whether DPP or BIP270 is used, the process remains consistent. The /rawTx API is used to create the transaction, and its data is passed as a parameter in the relevant API to link it with an internal invoice ID.

Regardless of the invoice standard (DPP or BIP270) being utilized, the transaction construction and referencing process remains the same, ensuring compatibility and consistency across both methods.

## Settle an invoice request

<mark style="color:green;">`POST`</mark> `https://api.relysia.com/v1/paymentRequest/pay/:invoiceId`

The API takes invoice and settles it.

#### Headers

| Name                                        | Type   | Description           |
| ------------------------------------------- | ------ | --------------------- |
| invoiceId<mark style="color:red;">\*</mark> | String | Invoice ID to be paid |

#### Request Body

| Name                                          | Type   | Description                       |
| --------------------------------------------- | ------ | --------------------------------- |
| merchantData                                  | String | merchant information              |
| transaction<mark style="color:red;">\*</mark> | String | Transaction hexadecimal value     |
| refundTo                                      | String | Address for refund if required    |
| memo                                          |        | Description about the transaction |

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

```json
{
  "statusCode": 200,
  "data": {
    "status": "success",
    "msg": "Operation completed successfully.",
    "statusCode": 200,
    "data": {
      "status": "success",
      "msg": "Payment Completed Successfully",
      "txId": "ef8bdedd64477adcf1d297cf7fbb92c743251634841418e43f6e74db921770a3"
    }
  }
}
```

{% endtab %}
{% endtabs %}
