# Notify payment result

It is recommended that the  Mobile Payment Provider (MPP) call the [notifyPayment](../api_mpp/notify_payment) API to notify Alipay+ of the payment result when the payment processing reaches a final status of success or failure.

The following figure shows the payment result notification flow of a transaction.

![image](https://idocs-assets.marmot-cloud.com/storage/idocs87c36dc8dac653c1/1671609585732-b964cc4a-61a0-480b-86b5-e4cee3000d2c.png)

Figure 1. The payment result notification flow of a transaction

To notify Alipay+ of the final payment result, you (the MPP) need to complete the following steps:

Step 1: Send the payment notification to Alipay+

Step 2: Receive the acknowledgment response from Alipay+

# Step 1: Send the payment notification

When a payment reaches a final state of success or failure, you need to send the notification to the URL provided by Alipay+ through the **notifyPayment** API.

## 1\. Receive the notification URL

You first need to receive the notification URL provided by Alipay+. This fixed URL is specified in the parameter _paymentNotifyUrl_ in the request of the **pay** API.

## 2\. Send the payment notification request

When the payment processing reaches a final status of success or failure, you must send the payment result notification to Alipay+ and pay attention to the rules below.

-   If the payment succeeds, return a _paymentResult.resultStatus_ of `S` and _paymentResult.resultCode_ of `SUCCESS`.
-   If the payment fails, return a _paymentResult.resultStatus_ of `F` and an error code that corresponds to a specific reason.

-   Required: If the balance of the user account is not enough, return a _paymentResult.resultCode_ of `USER_BALANCE_NOT_ENOUGH`.

-   Recommended: If the user does not exist, or the user status is abnormal, return a _paymentResult.resultCode_ of `USER_NOT_EXIST` or `USER_STATUS_ABNORMAL`.
-   Recommended: If the payment is declined for risk reasons, return a _paymentResult.resultCode_ of `RISK_REJECT`.
-   Recommended: If the user's payment methods that are linked to the MPP are unavailable, return a _paymentResult.resultCode_ of `UNAVAILABLE_PAYMENT_METHOD`.
-   Recommended: If the user verification fails, return a _paymentResult.resultCode_ of `USER_PAYMENT_VERIFICATION_FAILED`.
-   Recommended: If the merchant verification fails, return a _paymentResult.resultCode_ of `MERCHANT_NOT_REGISTERED`.

-   If the payment is canceled, return a _paymentResult.resultStatus_ of `F` and a _paymentResult.resultCode_ of `ORDER_IS_CLOSED`.

## Sample

**Request from the MPP to Alipay+**

The MPP sends a payment notification request that indicates a successful payment:

```json
{
 "paymentResult": {
    "resultCode":"SUCCESS",
    "resultStatus":"S",
    "resultMessage":"success"
 },
 "paymentRequestId":"2020010123456789****",
 "paymentId":"202001012345678901322222",
 "paymentTime": "2020-01-01T12:01:01+08:30",
 "paymentAmount":{
    "value":"100",
    "currency":"JPY"
 },
 "payToAmount":{
    "value":"1000",
    "currency":"KRW"
 },
 "customerId":"1234567"
}
```

# Step 2: Receive the acknowledgment response

After receiving the payment notification from the MPP, Alipay+ returns an acknowledgment response to the MPP. It is recommended that you are able to detect whether Alipay+ fails to return the response with the parameter _result.resultStatus_ of `S` and handle the response according to the instructions below.

| **result.resultStatus** | **result.resultCode** | **Notification status** | **Actions** |
| --- | --- | --- | --- |
| S | SUCCESS | Notification succeeds. | N/A |
| F | ... | Notification fails. | Take actions according to the result code (specified in the _result.resultCode_ parameter). For more information, see _Result code_ in the API reference for [notifyPayment](../api_mpp/notify_payment). |
| U | ... | Unknown | Retry the same request as below. - Retry 1~2 times within 5 seconds. - The subsequent intervals increase consecutively. For example, 30s, 1m, 2m, ... - A total of 15 retries are suggested. |
| No result received | No result received | Unknown | Retry the same request as below. - Retry 1~2 times within 5 seconds. - The subsequent intervals increase consecutively. For example, 30s, 1m, 2m, ... - A total of 15 retries are suggested. |

## Sample

**Response from Alipay+ to the MPP**

The MPP receives a response that indicates Alipay+ has successfully received the notification:

```json
{
 "result": {
    "resultCode":"SUCCESS",
    "resultStatus":"S",
    "resultMessage":"Success"
  },
  "acquirerId": "102218800000000****",
  "pspId": "102217200000000****"
}
```

# Related links

For more information about how to use the **notifiyPayment** API (such as the field description), see [notifyPayment](../api_mpp/notify_payment).