# Alipay

## Introduction

Alipay is a mobile payment platform operated by Ant Group, and it is one of the most widely used payment methods in mainland China. Customers complete the payment by scanning a QR code with the Alipay App or by confirming the order inside the Alipay App, which provides a familiar and trusted payment experience for Chinese customers.

| Attribute | Support Status |
|  --- | --- |
| Payment Mode | Wallet |
| Integration Products | API-Only, Checkout, PaymentLink, Billing |
| Supported Currencies | EUR, CZK, HUF |
| Payment Flow | Redirect/QR Code |
| Auto-capture payment | ✅ |
| Authorization | ❌ |
| Capture | ❌ |
| Partial Capture | ❌ |
| Void | ✅ |
| Partial Void | ❌ |
| Refund | ✅ |
| Partial Refund | ✅ |
| Dispute | ❌ |
| Recurring Subscription | ❌ |
| 3DS | ❌ |


It has the following advantages:

- Widely adopted in mainland China, covering customers who prefer to pay with Alipay
- Fast payment experience, customers only need to scan a QR code or confirm the order in the Alipay App
- Secure and reliable, transactions are protected by Alipay's risk control system
- Support for both online and offline payments


Alipay is not supported in the WeChat in-app browser. If your checkout page can be opened inside WeChat, guide the customer to use another browser.

## Integration methods

PayKKa provides multiple ways to integrate Alipay, and you can choose the appropriate method according to your needs.

| Integration method | API | Use case |
|  --- | --- | --- |
| **Web Checkout** | [Create Session](/payments/apis/payments/openapi/session/session-opl_1) | Complete payment through PayKKa Hosted Checkout |
| **Component integration** | [Create Session](/payments/apis/payments/openapi/session/session-opl_1) | Load the payment component in the merchant page |


### Before you start

1. Obtain your transaction key.
2. Confirm that Alipay is enabled for the merchant and use a payment currency listed in the capability table: EUR, CZK, HUF.
3. Configure payment-result Webhooks and server-side transaction queries. Set a return URL when the flow requires a browser return.
4. Use a unique `trans_id` for each transaction and store the order identifiers returned by the API.


A browser return or receipt of payment data does not establish payment success. Confirm the result through a transaction query or Webhook.

## Web Checkout

### Create Checkout

If you use PayKKa's hosted checkout page to integrate Alipay, you only need to accept Alipay as a payment method during the merchant onboarding process, and PayKKa will handle all transactions with Alipay behind the scenes. This integration solution is the most convenient.

1. Call the interface [Create Session](/payments/apis/payments/openapi/session/session-opl_1)


```json
{
  "merchant_id": "YOUR_MERCHANT_ID",
  "payment_type": "PURCHASE",
  "trans_id": "t202311081113",
  "currency": "EUR",
  "amount": 1000,
  "session_mode": "HOSTED",
  "display_merchant_name": "PayKKa Merchant",
  "display_locale": "en-GB",
  "allowed_payment_methods": [
    "ALIPAY"
  ]
}
```

**Response example:**

```json
{
  "ret_code": "000000",
  "ret_msg": "Success",
  "data": {
    "merchant_id": "YOUR_MERCHANT_ID",
    "trans_id": "t202311081113",
    "session_id": "CS_order_id",
    "session_mode": "HOSTED",
    "status": "PROCESSING",
    "currency": "EUR",
    "amount": "1000",
    "session_url": "https://checkout.aq.paykka.com/hp/pay/CS_order_id"
  }
}
```

Where `session_mode` field value is specified as `HOSTED`, and `allowed_payment_methods` allows `ALIPAY`.

After creating Checkout:

1. Store `session_id` and direct the payer to the returned `session_url`.
2. The payer follows the Alipay instructions in Checkout to complete payment.
3. After the payer returns, confirm the order through a transaction query or Webhook.


Checkout selects payment methods with `allowed_payment_methods`. Direct transaction requests use `payment.payment_method`; follow the field definitions for each API separately.

### Component integration

Component is a modular payment integration method, and developers can freely and flexibly choose to combine different payment components as needed. You can add Alipay payment elements to your payment page in this way.

1. Introduce PayKKa Checkout UI Component library


For specific usage steps, please refer to [PayKKa Checkout UI Component Usage Documentation - PayKKa Docs for Payments](/payments/docs/developer-resources/checkout-ui-component), and for the Alipay component, refer to [Alipay Component](/payments/docs/developer-resources/alipay-pay-component).

1. Call the interface [Create Session](/payments/apis/payments/openapi/session/session-opl_1)


```json
{
  "merchant_id": "YOUR_MERCHANT_ID",
  "payment_type": "PURCHASE",
  "trans_id": "t202311081113",
  "currency": "EUR",
  "amount": 1000,
  "session_mode": "HOSTED",
  "display_merchant_name": "PayKKa Merchant",
  "display_locale": "en-GB",
  "allowed_payment_methods": [
    "ALIPAY"
  ]
}
```

After creating the session, initialize and mount the component with the returned `session_id` according to [Alipay Component](/payments/docs/developer-resources/alipay-pay-component) and [Checkout UI Component](/payments/docs/developer-resources/checkout-ui-component). Handle submit, success, and error callbacks, then confirm the final order state with a server-side query or Webhook.

### Query Checkout

Query checkout status by checkout ID(`session_id`)

**Request example:**
[Query Session](/payments/apis/payments/openapi/session/session-query-opl_2)

```json
{
  "merchant_id": "YOUR_MERCHANT_ID",
  "trans_id": "m3246749195217",  # trans_id/session_id two choose one
  "session_id": "CS_order_id"
}
```

**Response example:**

Processing
```json
{
  "ret_code": "000000",
  "ret_msg": "Success",
  "data": {
    "merchant_id": "YOUR_MERCHANT_ID",
    "trans_id": "m3246749195217",
    "session_id": "CS_order_id",
    "session_mode": "HOSTED",
    "status": "PROCESSING",
    "amount": "1000",
    "currency": "EUR",
    "expire_time": "2025-05-05T17:17:24+08:00",
    "session_url": "https://checkout.aq.paykka.com/hp/pay/CS_order_id"
  }
}
```

Success
```json
{
  "ret_code": "000000",
  "ret_msg": "Success",
  "data": {
    "merchant_id": "YOUR_MERCHANT_ID",
    "trans_id": "m3246749195217",
    "session_id": "CS_order_id",
    "session_mode": "HOSTED",
    "status": "SUCCESS",  # checkout status
    "order_status": "SUCCESS",  # transaction status
    "error_code": "0000", # transaction error code
    "error_description": "request success",
    "order_id": "GW_order_id", # transaction order id
    "amount": "1000",
    "currency": "EUR",
    "expire_time": "2025-05-05T17:17:24+08:00",
    "session_url": "https://checkout.aq.paykka.com/hp/pay/CS_order_id"
  }
}
```

Expired
```json
Payment not initiated before expiration
{
  "ret_code": "000000",
  "ret_msg": "Success",
  "data": {
    "merchant_id": "YOUR_MERCHANT_ID",
    "trans_id": "m3246749195217",
    "session_id": "CS_order_id",
    "session_mode": "HOSTED",
    "status": "EXPIRED",  # checkout status
    "amount": "1000",
    "currency": "EUR",
    "expire_time": "2025-05-05T17:17:24+08:00"
  }
}

Payment failed
{
  "ret_code": "000000",
  "ret_msg": "Success",
  "data": {
    "merchant_id": "YOUR_MERCHANT_ID",
    "trans_id": "m3246749195217",
    "session_id": "CS_order_id",
    "session_mode": "HOSTED",
    "status": "EXPIRED",  # checkout status
    "amount": "1000",
    "currency": "EUR",
    "order_status": "FAILURE",  # transaction status
    "error_code": "0000", # transaction error code
    "error_description": "request success",
    "order_id": "GW_order_id", # transaction order id
    "expire_time": "2025-05-05T17:17:24+08:00"
  }
}
```

If Checkout expires, query any transaction already created. Session expiry alone does not establish that the transaction failed.

### Query transaction

Query transaction status by transaction ID(`order_id`)

**Request example:**
[Query Transaction](/payments/apis/payments/openapi/transaction/payments-query-opl_1)

```json
{
  "merchant_id": "YOUR_MERCHANT_ID",
  "trans_id": "m3246749195217",    # session_id/order_id/trans_id three choose one
  "session_id": "CS_order_id",
  "order_id": "GW_order_id"
}
```

**Response example:**

```json
{
  "ret_code": "000000",
  "ret_msg": "Success",
  "data": {
    "merchant_id": "YOUR_MERCHANT_ID",
    "trans_id": "m3246749195217",
    "order_id": "GW_order_id",
    "status": "SUCCESS",
    "error_code": "0000",
    "error_description": "request success",
    "amount": "1000",
    "currency": "EUR",
    "pay_finish_time": "2025-05-05T17:17:24+08:00"
  }
}
```

When handling a transaction query:

- `SUCCESS`: Confirm payment and avoid duplicate fulfillment.
- `PROCESSING`: Keep the order pending. A payer leaving the page is not sufficient reason to mark failure or create another payment.
- `FAILURE`: Investigate `error_code` and `error_description`. Use a new transaction ID for a new payment attempt.


A successful API call and a successful payment are separate results. Check the transaction `status`.

## Result notifications

Use [Webhook](/payments/docs/developer-resources/webhook) for asynchronous notifications. Follow that reference for notification fields and event types.

1. Validate notifications according to the shared integration rules and match the merchant order using `trans_id` and `order_id`.
2. Update the order from `event_type` and `status`. Make duplicate notifications idempotent to avoid duplicate fulfillment or accounting.
3. If a notification is delayed, missing, or inconsistent with the local order, verify the result with [Query Transaction](/payments/apis/payments/openapi/transaction/payments-query-opl_1).


The browser return URL displays a result to the payer; a Webhook updates the merchant server. A front-end redirect alone cannot confirm payment success.

## Refund limitations

This payment method supports refunds and partial refunds. Submit a refund through [Create Refund](/payments/apis/payments/openapi/refund/refund-opl_1) and follow [Refund](/payments/docs/payment-processing/refund) to query and handle the result.

Submitting a refund request does not establish refund success. Confirm the final status of the refund order.

## Error codes

See [Transaction Error Code](/payments/docs/developer-resources/transaction-error-code). Retain `trans_id`, `order_id` when returned, `error_code`, `error_description`, the request time, and the environment to help identify the order.

If a request times out or returns `PROCESSING`, query the original transaction before deciding whether to retry.

## Related documentation

- [Create Session](/payments/apis/payments/openapi/session/session-opl_1)
- [Query Session](/payments/apis/payments/openapi/session/session-query-opl_2)
- [Initiate Transaction](/payments/apis/payments/openapi/transaction/payments-opl_1)
- [Query Transaction](/payments/apis/payments/openapi/transaction/payments-query-opl_1)
- [Webhook](/payments/docs/developer-resources/webhook)
- [Transaction Error Code](/payments/docs/developer-resources/transaction-error-code)
- [API Only](/payments/docs/transaction/web/api-only)
- [Alipay+ Component](/payments/docs/developer-resources/alipay-component)
- [Checkout UI Component](/payments/docs/developer-resources/checkout-ui-component)
- [iOS SDK Introduction](/payments/docs/developer-resources/native-sdks/ios-sdk/introduction)
- [Android SDK Introduction](/payments/docs/developer-resources/native-sdks/android-sdk/introduction)
- [Alipay Component](/payments/docs/developer-resources/alipay-pay-component)
- [Refund](/payments/docs/payment-processing/refund)