Process a Sale {#thunes-alipay-sale-intro}
==========================================

Send a sale request to authorize and capture a payment in the same request. A successful sale response includes a redirect URL and a pending status. Redirect the customer to the URL to allow the customer to complete the checkout using Alipay+. When the customer completes the checkout, the customer is redirected to your merchant website based on the success URL you include in the apSaleService_successURL request field.

Supported Digital Wallets {#thunes-alipay-sale-intro_dw}
--------------------------------------------------------

This table lists the supported digital wallet types and the relevant digital wallet code, country code, and currency code for each country. When sending a sale request, set these fields to the specified values listed in the table:

[apPaymentType](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/ap-payment-type.md "")
:
Set to a value listed in the Digital Wallet Code column.

[billTo_country](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/bill-to-country.md "")
:
Set to a value listed in the Country Code column.

[purchaseTotals_currency](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/purchase-totals-currency.md "")
:
Set to a value listed in the Currency Code column.

|          Country           |   Digital Wallet    | Digital Wallet Code | Country Code | Currency Code |
|----------------------------|---------------------|---------------------|--------------|---------------|
| China                      | Alipay              | `ALO`               | `CN`         | `CNY`         |
| Hong Kong (CN)             | Alipay+             | `ALP`               | `HK`         | `HKD`         |
| Indonesia                  | Akulaku PayLater    | `APL`               | `ID`         | `IDR`         |
| Indonesia                  | Dana                | `DNA`               | `ID`         | `IDR`         |
| Korea, Republic of (South) | KakaoPay            | `KPT`               | `KR`         | `KRW`         |
| Malaysia                   | Boost               | `BST`               | `MY`         | `MYR`         |
| Malaysia                   | Touch'n'GO          | `TNG`               | `MY`         | `MYR`         |
| Philippines                | Bank of Philippines | `BPI`               | `PH`         | `PHP`         |
| Philippines                | Gcash               | `GCH`               | `PH`         | `PHP`         |
| Thailand                   | Rabbit Line Pay     | `RPL`               | `TH`         | `THB`         |
| Thailand                   | TrueMoney           | `TMY`               | `TH`         | `THB`         |
[Supported Digital Wallets]

Line Items
----------

Line items can be included in a sale request. Line items correspond to the item_#_ fields, starting with item_0_ and increasing in numerical order.  
For more information about how to properly format line items in your request, see [Using Line Items](/docs/cybs/en-us/thunes/developer/all/so/thunes/thunes-ref-info/thunes-intro-lineitems.md "").

Tax Amounts {#thunes-alipay-sale-intro_tax-info}
------------------------------------------------

You can include the tax amount for every type of purchased product in the item_#_taxAmount field when you request the sale service.

Calculating the Grand Total
---------------------------

Include the grand total in the request by using the purchaseTotals_grandTotalAmount field.  
For information about how to calculate the grand total, see [Calculating the Grand Total for Line Items](/docs/cybs/en-us/thunes/developer/all/so/thunes/thunes-ref-info/thunes-intro-total.md "").

Endpoints
---------

Set the apSaleService_run field to `true`, and send the request to one of these endpoints:  
**Production:** `https://ics2ws.ic3.com/commerce/1.x/transactionProcessor`{#thunes-alipay-sale-intro_d8e301}  
**Test:** `https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor`{#thunes-alipay-sale-intro_d8e308}

Response Statuses
-----------------

`Cybersource` responds to your sale request with one of these statuses in the apSaleReply_status field:

Sale Status
:
* `FAILED`: The sale cannot be completed.
* `PENDING`: The sale request is accepted but is not completed. Request the check status service every 60 minutes to retrieve status updates. See [Check a Request Status](/docs/cybs/en-us/thunes/developer/all/so/thunes/thunes-alipay-intro/thunes-alipay-status-intro.md "").
{#thunes-alipay-sale-intro_ul_pdp_lkr_3yb}  
The sale service also responds with a reason code in the apSaleReply_reasonCode field.  
For more information about reason codes, see [Reason Codes and Response Codes](/docs/cybs/en-us/thunes/developer/all/so/thunes/thunes-ref-info/thunes-refinfo-codes.md "").  
When you send a check status request to retrieve an updated sale status, these are the possible responses:

Check Status for a Sale
:
* `ABANDONED`: The customer did not complete the payment using the redirect URL.
* `FAILED`: The sale cannot be completed.
* `FUNDED`: The settled amount is funded to the merchant bank account.
* `PENDING`: The sale request is accepted but is not complete. Continue sending the check status request every 60 minutes.
* `SETTLED`: The sale request is settled for the requested amount. You cannot receive a settled status until the customer has completed checking out.

Processing a Sale {#thunes-alipay-sale-task}
============================================

Follow these steps to successfully process sale.

1. Send a `POST` request to the `https://ics2ws.ic3.com/commerce/1.x/transactionProcessor` endpoint and include these required fields:

   [apPaymentType](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/ap-payment-type.md "")
   :
   Set to a value listed in the Digital Wallet Code column.

   [apSaleService_cancelURL](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/ap-sale-service-cancel-url.md "")
   :
   Set to the URL to which the customer is redirected after successfully completing the Alipay+ payment.
   :
   Add `?action=cancel` to the end of the URL to help identify the response.

   [apSaleService_failureURL](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/ap-sale-service-failure-url.md "")
   :
   Set to the URL to which the customer is redirected after successfully completing the Alipay+ payment.
   :
   Add `?action=failure` to the end of the URL to help identify the response.

   [apSaleService_successURL](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/ap-sale-service-success-url.md "")
   :
   Set to the URL to which the customer is redirected after successfully completing the Alipay+ payment.
   :
   Add `?action=success` to the end of the URL to help identify the response.

   [apSaleService](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/ap-sale-service-run.md "")
   :
   Set to `true`.

   [billTo_country](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/bill-to-country.md "")
   :
   Set to one of these possible values:
   * `CN`: China
   * `HK`: Hong Kong (CN)
   * `ID`: Indonesia
   * `KR`: Korea, Republic of (South)
   * `MY`: Malaysia
   * `PH`: Philippines
   * `TH`: Thailand

       {#thunes-alipay-sale-task_cntry-alipay}

   {#thunes-alipay-sale-task_cntry-alipay}

   [merchantID](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/merchant-id.md "")
   :

   [merchantReferenceCode](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/merchant-reference-code.md "")
   :

   [purchaseTotals_currency](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/purchase-totals-currency.md "")
   :
   Set to one of these possible values:
   * `CNY`: Chinese yuan renminbi
   * `HKD`: Hong Kong dollar
   * `IDR`: Indonesian rupiah
   * `KRW`: South Korean won
   * `MYR`: Malaysian ringgit
   * `PHP`: Philippine peso
   * `THB`: Thai baht

       {#thunes-alipay-sale-task_crncy-alipay}

   {#thunes-alipay-sale-task_crncy-alipay}

   [purchaseTotals_grandTotalAmount](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/purchase-totals-grand-total-amount.md "")
   :

   {#thunes-alipay-sale-task_step-1-cmd}

2. You can include these optional fields in the request:

   [billTo_city](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/bill-to-city.md "")
   :

   [billTo_email](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/bill-to-email.md "")
   :

   [billTo_firstName](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/bill-to-first-name.md "")
   :

   [billTo_lastName](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/bill-to-last-name.md "")
   :

   [billTo_phoneNumber](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/bill-to-phone-number.md "")
   :

   [billTo_postalCode](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/bill-to-postal-code.md "")
   :

   [billTo_state](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/bill-to-state.md "")
   :

   [billTo_street1](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/bill-to-street1.md "")
   :

   [invoiceHeader_merchantDescriptor](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/invoice-header-merchant-descriptor-a.md "")
   :

   [item_#_productCode](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/item-no-product-code.md "")
   :
   Replace the `#` character with a sequential number starting from `0`.

   [item_#_productDescription](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/item-no-product-description.md "")
   :
   Replace the `#` character with a sequential number starting from `0`.

   [item_#_productName](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/item-no-product-name.md "")
   :
   Replace the `#` character with a sequential number starting from `0`.

   [item_#_productSKU](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/item-no-product-sku.md "")
   :
   Replace the `#` character with a sequential number starting from `0`.

   [item_#_quantity](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/item-no-quantity.md "")
   :
   Replace the `#` character with a sequential number starting from `0`.

   [item_#_taxAmount](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/item-no-tax-amount.md "")
   :
   Replace the `#` character with a sequential number starting from `0`.

   [item_#_totalAmount](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/item-no-total-amount.md "")
   :
   If this field is present, the purchaseTotals_currency field is optional.
   :
   Replace the `#` character with a sequential number starting from `0`.

   [item_#_unitPrice](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/item-no-unit-price.md "")
   :
   Replace the `#` character with a sequential number starting from `0`.

   [merchantDefinedData_mddField_#](https://developer.cybersource.com/docs/cybs/en-us/api-fields/reference/all/so/api-fields/merchant-defined-data-mdd-field-1-100.md "")
   :
   {#thunes-alipay-sale-task_step-2-cmd}

3. Redirect the customer to the returned URL in the merchantURL response field.

   ```
   &lt;merchantURL&gt;https://payment.limonetikqualif.com/AlipayPlus/Order/PayPage/500877975585&lt;/merchantURL&gt;
   ```

   {#thunes-alipay-sale-task_step-3-cmd}

4. When the customer completes the checkout using their Alipay+ credentials, the customer is redirected to the merchant website based on the URL that you included in the apSaleService_successURL field.

   > The customer must select Return to Merchant at the end of check out in order for the sale to settle.
   > {#thunes-alipay-sale-task_step-4-cmd}
   > {#thunes-alipay-sale-task_step-4}

5. Save the request ID in the requestID field from the sale response. Include the request ID in a check status request to confirm that the payment is complete.

   ```
   &lt;requestID&gt;6989535327666834103007&lt;/requestID&gt;
   ```

{#thunes-alipay-sale-task_step-5-cmd}

Example: Processing a Sale {#thunes-alipay-sale-ex-so}
======================================================

Request

```
&lt;requestMessage xmlns="urn:schemas-cybersource-com:transaction-data-1.215"&gt;
	&lt;merchantID&gt;test_merchant&lt;/merchantID&gt;
	&lt;merchantReferenceCode&gt;refnum-1234&lt;/merchantReferenceCode&gt;
	&lt;billTo&gt;
		&lt;country&gt;CN&lt;/country&gt;
	&lt;/billTo&gt;
	&lt;purchaseTotals&gt;
		&lt;currency&gt;CNY&lt;/currency&gt;
		&lt;grandTotalAmount&gt;220.00&lt;/grandTotalAmount&gt;
	&lt;/purchaseTotals&gt;
	&lt;apPaymentType&gt;ALO&lt;/apPaymentType&gt;
	&lt;apSaleService run="true"&gt;
		&lt;cancelURL&gt;https://www.test.com?action=cancel&lt;/cancelURL&gt;
		&lt;successURL&gt;https://www.test.com?action=success&lt;/successURL&gt;
		&lt;failureURL&gt;https://www.test.com?action=failure&lt;/failureURL&gt;
	&lt;/apSaleService&gt;
&lt;/requestMessage&gt;		
```

Response to a Successful Request

```
&lt;replyMessage xmlns:c="urn:schemas-cybersource-com:transaction-data-1.215"&gt;
	&lt;merchantReferenceCode&gt;refnum-1234&lt;/merchantReferenceCode&gt;
	&lt;requestID&gt;6953229557336619903008&lt;/requestID&gt;
	&lt;decision&gt;ACCEPT&lt;/decision&gt;
	&lt;reasonCode&gt;100&lt;/reasonCode&gt;
	&lt;requestToken&gt;AxjnrwSTfCrhKA1WZ6GDANgZYiy6lag2k0Y0+SnkF2K8QJOD6vgaCwyaSZejFfqtQk3wq4SgNVmehgwA7Awz&lt;/requestToken&gt;
	&lt;purchaseTotals&gt;
		&lt;currency&gt;CNY&lt;/currency&gt;
	&lt;/purchaseTotals&gt;
	&lt;apSaleReply&gt;
		&lt;reasonCode&gt;100&lt;/reasonCode&gt;
		&lt;paymentStatus&gt;pending&lt;/paymentStatus&gt;
		&lt;responseCode&gt;00001&lt;/responseCode&gt;
		&lt;merchantURL&gt;https://payment.limonetikqualif.com/AlipayPlus/Order/PayPage/401484998592&lt;/merchantURL&gt;
		&lt;processorTransactionID&gt;401484998592&lt;/processorTransactionID&gt;
		&lt;reconciliationID&gt;XEKTVP6IQFOI&lt;/reconciliationID&gt;
		&lt;amount&gt;220.00&lt;/amount&gt;
		&lt;processorResponse&gt;00001&lt;/processorResponse&gt;
		&lt;dateTime&gt;2023-11-29T19:14:15Z&lt;/dateTime&gt;
	&lt;/apSaleReply&gt;
&lt;/replyMessage&gt;
```

