# Configure Alipay and WeChat QR

This guide explains how to integrate **Alipay** and **WeChat Pay** using QR-based flows. Instead of reading a physical card, the customer presents a QR code that your TPV scans and sends to the Get Smart SDK Payment Service through the corresponding repository.

Before using these APMs, ensure the TPV is initialized with `InitializationRepository.initTpv()` and that each payment method is enabled in the terminal configuration.

## Alipay

To process Alipay payments, use the `AlipayRepository`. The typical flow is:

1. The customer presents an Alipay QR code.
2. Your app scans the code and extracts the `qrId`.
3. You call `makePayment` on `AlipayRepository` with the amount and QR data.

### Repository

- **Repository**: `AlipayRepository`

### Alipay Payment

**Function**: `makePayment`

**Parameters:**

- `amount`: The `Money` object.  
- `tip`: The tip amount (can be zero or omitted depending on your logic).  
- `qrId`: The code string scanned from the customer's QR.  
- `transactionName`: A label for the transaction.  
- `qrIdType`: The type of QR code (for example `QrIdType.ALIPAY`).  
- `languageIso6391`: Language for the service UI.

> **Test Environment Constraint**: In the integration/test environment, Alipay payments are only accepted if the amount is exactly **3.33€**.

```kotlin
suspend fun payWithAlipay(amount: Money, scannedQr: String) {
    val result = alipayRepository.makePayment(
        amount = amount,
        tip = Money(BigDecimal.ZERO, Currency.getInstance("EUR")),
        qrId = scannedQr,
        transactionName = "Sale #123",
        qrIdType = QrIdType.ALIPAY,
        languageIso6391 = LanguageIso6391.ES
    )

    // Handle RepositoryResult<AlipayResult> here...
}
```

### Alipay Refund

**Function**: `makeRefund`

**Parameters:**

- `amount`: Amount to refund.  
- `originalOperationId`: The ID of the original Alipay payment.  
- `languageIso6391`: UI language.

```kotlin
suspend fun refundAlipay(amount: Money, originalId: String) {
    val result = alipayRepository.makeRefund(
        amount = amount,
        originalOperationId = originalId,
        languageIso6391 = LanguageIso6391.ES
    )

    // Handle RepositoryResult<AlipayResult> here...
}
```

## WeChat Pay

To process WeChat payments, use the `WeChatRepository`. The flow is similar to Alipay and also relies on scanning the customer's QR code.

### Repository

- **Repository**: `WeChatRepository`

### WeChat Payment

**Function**: `makePayment`

**Parameters:**

- `amount`: The `Money` object.  
- `tip`: The tip amount.  
- `qrId`: The code string scanned from the customer's QR.  
- `transactionName` (optional): A label for the transaction.  
- `languageIso6391`: UI language.

> **Constraint**: Testing WeChat in the integration environment may be limited due to the lack of a provider test kit.

```kotlin
suspend fun payWithWeChat(amount: Money, scannedQr: String) {
    val result = weChatRepository.makePayment(
        amount = amount,
        tip = Money(BigDecimal.ZERO, Currency.getInstance("EUR")),
        qrId = scannedQr,
        transactionName = "Sale #124",
        languageIso6391 = LanguageIso6391.ES
    )

    // Handle RepositoryResult<WeChatResult> here...
}
```

### WeChat Refund

**Function**: `makeRefund`

**Parameters:**

- `amount`: Amount to refund.  
- `originalOperationId`: The ID of the original WeChat payment.  
- `languageIso6391`: UI language.

```kotlin
suspend fun refundWeChat(amount: Money, originalId: String) {
    val result = weChatRepository.makeRefund(
        amount = amount,
        originalOperationId = originalId,
        languageIso6391 = LanguageIso6391.ES
    )

    // Handle RepositoryResult<WeChatResult> here...
}
```

### Next Steps

- For phone-number–based Alternative Payments Methods (APMs), see **Configure Bizum Payments**.  
- To understand shared response handling and error codes, see **Core Concepts / Handle Responses and Errors** and **Reference / Response and Error Codes**.