# Alipay
source: https://developer.mastercard.com/mastercard-gateway/documentation/payment-methods/digital-wallets/alipay/index.md

Alipay is an e-wallet used in China that allows customers to purchase goods online using their Alipay balance or by selecting a payment method from the wallet.

Alipay is a supported browser payment method in the Mastercard Gateway. This page describes integration details specific to Alipay. It is recommended that you read the [integration guidelines for browser payments](https://developer.mastercard.com/mastercard-gateway/documentation/payment-methods/imp-brow-pay-int/index.md), before building an Alipay integration.

Alipay browser payments are supported for transactions in currencies AUD, CAD, EUR, GBP, HKD, SGD, USD, CHF, JPY, NZD, and CNY.

Note that the gateway only supports Alipay for cross-border merchants, in other words, international merchants entering the Chinese market and Chinese tourists abroad that want to pay with Alipay. The gateway does not allow processing CNY natively for Chinese-domiciled merchants.

In the case of cross-border merchants:

* The order amount will be presented to the payer (by the gateway) in the processing currency (for example EUR).
* The payer will be debited by Alipay in CNY and will be charged for the currency conversion.
* The merchant will be settled by the browser payments service provider in EUR.

## Prerequisites {#prerequisites}

To offer Alipay as a payment method through the Mastercard Gateway:

* Be registered with your browser payments service provider.
* Your merchant profile on the gateway must be configured using the details of your account with the browser payments service provider.
* You must have a bank account in one of the supported currencies registered against your merchant account at your browser payments service provider.

## Alipay Integration {#alipay-integration}

### Alipay through Hosted Checkout {#alipay-through-hosted-checkout}

With Hosted Checkout integrations version 51 and later, Alipay is automatically available to your payers when you are enabled and configured for it by your payment service provider.

For details, see [Browser Payments through Hosted Checkout Integration](https://developer.mastercard.com/mastercard-gateway/documentation/payment-methods/imp-brow-pay-int/index.md#browser-payments-through-hosted-checkout-integration).

### Alipay through Direct Payment {#alipay-through-direct-payment}

Direct Payment integration allows you to offer the Alipay payment method on your own checkout page.

Alert: Alipay is supported from API version 45 and later.

<br />

Make an Initiate Browser Payment request where `sourceOfFunds.type = ALIPAY` and `browserPayment.operation = PAY` (the Authorize operation is not supported by Alipay). For the standard fields, see [Browser Payments through Direct Payment Integration](https://developer.mastercard.com/mastercard-gateway/documentation/payment-methods/imp-brow-pay-int/index.md#browser-payments-through-direct-payment-integration).

##### Preferred Language {#preferred-language}

You can set the language that you prefer Alipay to use for pages displayed to the payer by providing the browserPayment.preferredLanguage field in the Initiate Browser Payment request. However, the language will be used only if Alipay supports it.

### Sample Code to Initiate Alipay Payment {#sample-code-to-initiate-alipay-payment}

```json
{
  "apiOperation": "INITIATE_BROWSER_PAYMENT",
  "browserPayment": {
    "operation": "PAY",
    "returnUrl": "https://<return_url>"
  },
  "order": {
    "amount": "10.00",
    "currency": "GBP"
  },
  "sourceOfFunds": {
    "type": "ALIPAY"
  }
}
```

## How to Interpret the Transaction Result {#how-to-interpret-the-transaction-result}

The table below shows the transaction Response Codes for the possible scenarios that you may encounter after initiating an Alipay payment.

|                     Initiate Browser Payment Response                     |                                                                                                                  What This Means...                                                                                                                  |
|---------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `response.gatewayCode`=SUBMITTED `result`=SUCCESS                         | Redirect the payer using the URL provided in the response.                                                                                                                                                                                           |
| **Retrieve Transaction/Retrieve Order Response**                          | **What This Means...**                                                                                                                                                                                                                               |
| `response.gatewayCode`=APPROVED `result`=SUCCESS                          | The payment is successful.                                                                                                                                                                                                                           |
| `response.gatewayCode`=PENDING `result`=PENDING                           | The Mastercard Gateway is waiting for a notification from the acquirer about the payment result. Try `RETRIEVE_TRANSACTION` again later or listen to notifications from the gateway.                                                                 |
| `response.gatewayCode`=CANCELLED `result`=FAILURE                         | The payer has cancelled the interaction for this payment. Offer the payer the option to try another payment method.                                                                                                                                  |
| `response.gatewayCode`=DECLINED or ACQUIRER_SYSTEM_ERROR `result`=FAILURE | The payment was declined. Offer the payer the option to try another payment method. In the case of an `ACQUIRER_SYSTEM_ERROR` you may want to inquire with the acquirer the reason for payment failure, or you can try `RETRIEVE_TRANSACTION` again. |
| `response.gatewayCode`=TIMED_OUT `result`=FAILURE                         | Treat this as a declined payment. The Mastercard Gateway will attempt ensure that the transaction is not successful or will revert the transaction.                                                                                                  |

## Refunds {#refunds}

You can refund Alipay payments in part or in full. Be configured for refunds on the Mastercard Gateway and on your merchant account at your browser payments service provider.

## Testing your Integration {#testing-your-integration}

The Mastercard Gateway provides a browser payments emulator that allows you to ***test your Alipay integration***.
