Process a Sale {#thunes-twint-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 Twint. When the customer completes the checkout, the customer is redirected to the merchant website using the success-URL provided in the sale request.

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-twint-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-twint-sale-intro_d8e301}  
**Test:** `https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor`{#thunes-twint-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-twint-intro/thunes-twint-status-intro.md "").
{#thunes-twint-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-twint-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 `TWN`.

   [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 Twint 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 Twint 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 Twint 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 `FR`.
   {#thunes-twint-sale-task_cntry}
   {#thunes-twint-sale-task_cntry}

   [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 "")
   :

   [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 `CHF`.
   {#thunes-twint-sale-task_crncy}
   {#thunes-twint-sale-task_crncy}

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

   {#thunes-twint-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_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-twint-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/Six/Order/PayPage/181364489025&lt;/merchantURL&gt;
   ```

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

4. When the customer completes the checkout using their Twint credentials, the customer is redirected to the merchant website based on the URL that you included in the apSaleService_successURL field.{#thunes-twint-sale-task_step-4-cmd}
   {#thunes-twint-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-twint-sale-task_step-5-cmd}

Example: Processing a Sale {#thunes-twint-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;CH&lt;/country&gt;
	&lt;/billTo&gt;
	&lt;purchaseTotals&gt;
		&lt;currency&gt;CHF&lt;/currency&gt;
		&lt;grandTotalAmount&gt;220.00&lt;/grandTotalAmount&gt;
	&lt;/purchaseTotals&gt;
	&lt;apPaymentType&gt;TWN&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;Twint-Sale&lt;/merchantReferenceCode&gt;
	&lt;requestID&gt;7169953435096261804012&lt;/requestID&gt;
	&lt;decision&gt;ACCEPT&lt;/decision&gt;
	&lt;reasonCode&gt;100&lt;/reasonCode&gt;
	&lt;requestToken&gt;AxjnrwSThK8XpS28dz/sANgZYjWmdqvDnVrLmWnvwgfANF6B8iBtDJpJl6MV+q1CThK8XpS28dz/sAAA1RS5&lt;/requestToken&gt;
	&lt;purchaseTotals&gt;
		&lt;currency&gt;CHF&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/Six/Order/PayPage/181364489025&lt;/merchantURL&gt;
		&lt;processorTransactionID&gt;181364489025&lt;/processorTransactionID&gt;
		&lt;reconciliationID&gt;XFZ3ZWCNVY9K&lt;/reconciliationID&gt;
		&lt;amount&gt;1.00&lt;/amount&gt;
		&lt;processorResponse&gt;00001&lt;/processorResponse&gt;
		&lt;dateTime&gt;2024-05-29T15:09:04Z&lt;/dateTime&gt;
	&lt;/apSaleReply&gt;
&lt;/replyMessage&gt;
```

