# Notify payment result

The Mobile Payment Provider (MPP) calls 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/1660734811367-3f133a8f-f77b-4d9c-84c3-31f34d4ec92a.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+](#yFe0E)

Step 2: [Receive the acknowledgment response from Alipay+](#yRFUd)

# 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

The notification URL can be obtained through the following two ways:

-   The URL is specified in the _paymentNotifyUrl_ parameter in the response of **userInitiatedPay** API.
-   The Alipay+ Solution Architect provides a default notification URL.

If the _paymentNotifyUrl_ parameter is specified in the API response, it must be given precedence. Otherwise, the default URL from Alipay+ is utilized.

## 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.

-   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 user's KYC fails, return a _paymentResult.resultCode_ of `USER_KYC_NOT_QUALIFIED`.
-   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"
 }
}
```

# Related links

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