﻿# API Integration

### 1. Create PayByLink

::: warning Note:
For the detailed API parameters information, please refer to the [Create PayByLink](https://docs.payermax.com/api.html?docName=New%20Version&docVer=v1.0&docLang=en#/paths/aggregate-pay-api-gateway-createPaybylink/post) interface.
:::

Request API, the environment and address are as follows:

| API Environment | Request URL                                                                 |
| --------------- | --------------------------------------------------------------------------- |
| Test            | https://pay-gate-uat.payermax.com/aggregate-pay/api/gateway/createPaybylink |
| Prod            | https://pay-gate.payermax.com/aggregate-pay/api/gateway/createPaybylink     |

Request Header Example:

```json
{
    'Content-Type': 'application/json;charset=utf-8',
    'Accept': 'application/json',
    'sign': <Please refer to: https://docs.payermax.com/en/202606-version/developer/signature-rules.html>
};
```

Request Body Example:

```json
{
	"appId": <Merchant Platform appid>,
    "merchantNo": <Merchant Number>,
	"keyVersion": "1",
	"requestTime": "2024-02-27T13:45:36.960+08:00",
	"version": "1.1",
    "data": {
        "merchantLinkId": "paylinktest999",
        "linkType": "ONETIME",
        "expiresTime": "86400",
        "country": "ID",
        "currency": "IDR",
        "totalAmount": "40000",
        "language": "en",
        "description": "冬季新款运动鞋",
        "linkDescription": "链接收款衣物鞋帽",
        "userInfo": {
            "userId": "98",
            "username": "payermax"
        },
        "goodsDetails": [
            {
                "goodsName": "运动鞋",
                "goodsDescription": "冬季新款减震跑步运动鞋",
                "quantity": "2",
                "price": "20000",
                "goodsCurrency": "IDR",
                "showUrl": "http://www.baidu.com"
            }
        ],
        "notifyUrl": "http://www.baidu.com"
    }
}
```

Request Response Example:

```json
{
    "msg": "Success.",
    "code": "APPLY_SUCCESS",
    "data": {
        "linkStatus": "ACTIVE",
        "linkId": "BYLqPQaQlD",
        "qrCodeUrl": "https://img-cdn.shareitpay.in/qrcode/20240227054625j6r5x8.png",
        "linkUrl": "http://uat.payermax.link/uat/#/BYLqPQaQlD",
        "merchantLinkId": "paylinktest999",
        "expiresAt": "2024-02-28T05:46:25Z"
    }
}
```

### 2. Query Paybylink

+ [Query Paybylink](https://docs.payermax.com/api.html?docName=New%20Version&docVer=v1.0&docLang=en#/paths/aggregate-pay-api-gateway-queryPaybylink/post) interface will return the specific time when the link becomes invalid.
+ This interface is only a link status query and does not represent the order status.

### 3. Expired PayByLink

+ Before the user completes the payment, you can call the [Expired PayByLink](https://docs.payermax.com/api.html?docName=New%20Version&docVer=v1.0&docLang=en#/paths/aggregate-pay-api-gateway-expirePaybylink/post) interface in advance to invalidate the link. After the expiration, the user will not be able to open the payment.
+ If the user has already completed the payment, this function will not be available.

### 4. PayByLink Updates & Callbacks

You need to add the callback address of the link payment in the background.

![](https://img-cdn-sg.payermax.com/public/20240913-1ed3467a-bffa-489c-b66b-b5c4ae54f4a8.png)

We will call back the link update status to the server through the address you configured. For callback data, please refer to the [PayByLink Updates & Callbacks](https://docs.payermax.com/api.html?docName=New%20Version&docVer=v1.0&docLang=en#/paths/payLinkResultNotifyUrl/post) interface.
