# Orders

{% hint style="success" %}
Production URL: <https://orders-v1-api-rdqehkur6a-ey.a.run.app>
{% endhint %}

## Create Order

{% hint style="info" %}
Please Note: If you want to pre-populate user data for the **Stripe Onramp** payment feature - Please ensure to add the `customerInformation` object data.
{% endhint %}

{% openapi src="<https://820186084-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpCZIBuMMKukshUmEKQzb%2Fuploads%2F8VicTOvYhEdmoV6a6WSY%2Fdefinition.new.json?alt=media&token=60ac049a-c07a-4a3e-9dfe-6a603166fe84>" path="/orders" method="post" %}
[definition.new.json](https://820186084-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpCZIBuMMKukshUmEKQzb%2Fuploads%2F8VicTOvYhEdmoV6a6WSY%2Fdefinition.new.json?alt=media\&token=60ac049a-c07a-4a3e-9dfe-6a603166fe84)
{% endopenapi %}

## Order Notify Url (Webhook)

{% hint style="warning" %}
WARNING: Ensure that your system accepts payments ONLY when the status of the notifyUrl request is "**success**".
{% endhint %}

## Order Completed Notify Url

<mark style="color:green;">`POST`</mark> `https://your-notify-url`

#### Request Body

<table><thead><tr><th>Name</th><th width="459">Type</th><th>Description</th></tr></thead><tbody><tr><td>orderId<mark style="color:red;">*</mark></td><td>string</td><td>TygaPay Order Id.</td></tr><tr><td>orderNumber<mark style="color:red;">*</mark></td><td>string</td><td>Unique Order Number .</td></tr><tr><td>status<mark style="color:red;">*</mark></td><td>string</td><td><p>Status of the order upon completion:</p><p><code>success</code>: Payment has been successfully processed.</p><p><code>expired</code>: The order has expired.</p><p><code>cancelled</code>: The order has been cancelled.</p></td></tr><tr><td>date<mark style="color:red;">*</mark></td><td>string</td><td><p>Order complettion date. i.e </p><p>2024-01-07T19:05:30.175Z</p></td></tr><tr><td>amount</td><td>number</td><td>The paid amount. Amount will only be present if the status is equal to <code>success</code>.</td></tr><tr><td>currency</td><td>string</td><td>i.e USDT, KRU etc<br>Currency will only be present if the status is equal to <code>success</code>.</td></tr><tr><td>txId</td><td>String</td><td>The payment TygaPay txId. TxID will only be present if the status is equal to <code>success</code>.</td></tr></tbody></table>

## Order Redirect Url

When an order receives a final outcome, the Payment Gateway will redirect to the specified redirect URL. The redirect URL will have the following parameters appended: \
`?orderId=[ORDER_ID]&orderNumber=[ORDER_NUMBER]&status=[STATUS]`

i.e <https://your-redirect-url?orderId=004Qs494RxpEMFYUyXBz\\&orderNumber=323421\\&status=success>

| Fields        | Description                                                                                                                                                                                                                     |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ORDER\_ID     | The TygaPay Order Id                                                                                                                                                                                                            |
| ORDER\_NUMBER | The orderNumber supplied in the creation of the order.                                                                                                                                                                          |
| STATUS        | <p>Status of the order upon completion:</p><p><code>success</code>: Payment has been successfully processed.</p><p><code>expired</code>: The order has expired.</p><p><code>cancelled</code>: The order has been cancelled.</p> |

{% hint style="info" %}
Note: TygaPay will accommodate the specific format required for your redirect URL.
{% endhint %}

## Get Order

{% openapi src="<https://tygapay.github.io/docs/definition.json>" path="/orders" method="get" %}
<https://tygapay.github.io/docs/definition.json>
{% endopenapi %}

## Cancel Order

{% openapi src="<https://tygapay.github.io/docs/definition.json>" path="/orders/:orderId/cancel" method="put" %}
<https://tygapay.github.io/docs/definition.json>
{% endopenapi %}

## Refund Order to TygaPay Account

{% openapi src="<https://tygapay.github.io/docs/definition.json>" path="/orders/:orderId/refund" method="post" %}
<https://tygapay.github.io/docs/definition.json>
{% endopenapi %}

## Refund Order to Crypto Address

{% hint style="info" %}

* To process a refund to a cryptocurrency address, an OTP (One-Time Password) is necessary. Please reach out to <support@tygapay.com> to set up the Tenant Admin account that will receive these OTPs.
  {% endhint %}

{% openapi src="<https://tygapay.github.io/docs/definition.json>" path="/orders/:orderId/refund/crypto/otp" method="post" %}
<https://tygapay.github.io/docs/definition.json>
{% endopenapi %}

{% openapi src="<https://tygapay.github.io/docs/definition.json>" path="/orders/:orderId/refund/crypto" method="post" %}
<https://tygapay.github.io/docs/definition.json>
{% endopenapi %}

## Refund NotifyUrl Request (Webhook)

<mark style="color:green;">`POST`</mark> `https://your-refund-notify-url`

#### Request Body

<table><thead><tr><th>Name</th><th width="459">Type</th><th>Description</th></tr></thead><tbody><tr><td>type<mark style="color:red;">*</mark></td><td>string</td><td><code>order_refund</code> | <code>order_refund_crypto</code></td></tr><tr><td>orderId<mark style="color:red;">*</mark></td><td>string</td><td>TygaPay Order Id.</td></tr><tr><td>orderNumber<mark style="color:red;">*</mark></td><td>string</td><td>Unique Order Number .</td></tr><tr><td>status<mark style="color:red;">*</mark></td><td>string</td><td><p>Status of the order refund upon completion:</p><p><code>refunded</code>: Order has been refunded successfully.</p></td></tr><tr><td>date<mark style="color:red;">*</mark></td><td>string</td><td><p>Order complettion date. i.e </p><p>2024-01-07T19:05:30.175Z</p></td></tr><tr><td>amount<mark style="color:red;">*</mark></td><td>number</td><td>The refunded amount. </td></tr><tr><td>currency<mark style="color:red;">*</mark></td><td>string</td><td>The refunded currency. i.e USDT</td></tr><tr><td>txId<mark style="color:red;">*</mark></td><td>string</td><td>The payment TygaPay txId. </td></tr><tr><td>thirdPartyId</td><td>string</td><td>The specified <code>thirdPartyId</code> is used to initiate the refund request.</td></tr><tr><td>address</td><td>string</td><td>The address to which the refunded amount was sent. This address is provided when the type is <code>order_refund_crypto</code>.</td></tr><tr><td>token</td><td>string</td><td>The token, such as USDT, that has been transferred to the blockchain address.</td></tr><tr><td>network</td><td>string</td><td>The network used to transmit the token.</td></tr><tr><td>txHash</td><td>string</td><td>The blockchain transaction ID, which can be used to verify the legitimacy of the transfer.</td></tr></tbody></table>
