# Sale

#### **Utilizing the `doSale` Method in the Merchant PayContactless  SDK**

**Overview**: The `doSale` method of the Merchant PayContactless SDK is a pivotal function for executing transactions within merchant applications. Primarily, it is designed to process and receive payments.

**Parameters**:

1. **Amount**:
   * **Description**: Denotes the transaction's value as specified by the user.
   * **Constraints**:
     * Should be a whole number, with its length capped at 12 digits.
     * Exclude any separators or currency symbols.
   * **Examples**:
     * A payment amount of $100 should be conveyed as 10000, where the trailing two digits represent cents.
     * Conversely, $1.01 is represented as 101.
2. **Description**:
   * **Description**: Provides contextual information detailing the purpose or reason behind the payment. It could relate to the product/service name, a brief summary, or any relevant description the merchant deems necessary.
3. **Currency Code**
   * **Description**: The currecy value of the transaction. It has be numeric code of ISO 4217 format.&#x20;
   * **Examples:**
     * 566 for Naira instead of NGN
4. **Activity**
   * **Description**: The current activity. Payment page is started as a new activity. In order to start payment activity Embed SDK needs the current acitivity of the app.
5. **RFU Map**
   * **Description:** RFUMap (Reserved for future use) object is used to transfer key value pairs between backend system and merchant application
6. **TransactionResultListener**:
   * **Description**: This interface is vital as it captures and manages transaction outcomes, be it success or failure scenarios.

**Usage**: To implement the `doSale` function in your application, ensure you're capturing the correct parameters, especially the format for the "Amount" and supplementing the necessary information in the "Description."

By adhering to these guidelines, you enable a precise and seamless transaction process, elevating the user experience within your application.

```java
PayContactlessEmbed.getInstance().doSale(
    amount: String,
    description: String?,
    currencyCode: String?,
    activity: FragmentActivity,
    rfuMap: Map<String, String>?,
    listener: TransactionResultListener
)

```

| Field Name   | Data Type                 | Required | Description                                                                                                                                                              |
| ------------ | ------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| amount       | String                    | true     | Transaction amount to be charged. The value should be formatted according to the SDK’s amount specification (e.g., minor units or decimal format as configured, 200000). |
| description  | String                    | false    | Optional description or narration for the transaction, used for reference and reporting purposes.                                                                        |
| currencyCode | String                    | false    | ISO 4217 currency code for the transaction (e.g., `NGN`, `USD`). If null, the default terminal currency is used.                                                         |
| activity     | FragmentActivity          | true     | Host activity used to launch and display the SDK transaction UI. Must be a valid and active `FragmentActivity`.                                                          |
| rfuMap       | Map\<String, String>      | false    | Reserved for future use (RFU). Allows passing additional key–value parameters for extended or custom transaction data.                                                   |
| listener     | TransactionResultListener | true     | Callback interface used to receive transaction success, failure, or status updates.                                                                                      |

{% hint style="info" %}
If currency parameter is set null, the default currency is used for transaction. The default currency is Naira in SDK.
{% endhint %}

When a transaction is completed, the TransactionResult class is received on onCompleted method, these class fields can be used for the payment result screens.

## **Transaction Listener**

```java
public interface TransactionResultListener {
   void onCompleted(TransactionResult transaction);
}
```

## **Transaction Result**

```kotlin
data class TransactionResult(
    var paymentType: String?,
    var status: String,
    var payWithCardResult: Transaction? = null,
    var payWithAccountResult: FinishTrx?=null;
    var payWithLinkResult: PayWithLinkResult? = null
    var error : ErrorData? = null
)
```

<table><thead><tr><th width="223">Field Names</th><th width="172.33333333333331">Field Descriptions</th><th>Values</th></tr></thead><tbody><tr><td>Payment Type</td><td>return the data in which method in use for this transaction</td><td><p><code>object PaymentType {</code> </p><p>   <code>const val CARD = "Card"</code></p><p>   <code>const val PAY_WITH_CARD = "PayWithCard"</code></p><p>   <code>const val ACCOUNT = "PayWithAccount"</code><br>  <code>const val PAY_WITH_LINK = "PayWithLink"</code></p><p>   <code>const val QR = "QR"</code></p><p>   <code>const val USSD = "USSD"</code> </p><p><code>}</code></p></td></tr><tr><td>Status</td><td>result of the transaction request</td><td><p><code>object TransactionResult {</code></p><p>   <code>const val SUCCESS = "Success"</code></p><p>   <code>const val FAIL = "Fail"</code></p><p>   <code>const val CANCEL = "Cancel"</code></p><p>   <code>const val TIMEOUT = "Timeout"</code> </p><p><code>}</code></p></td></tr><tr><td>PayWithCardResult</td><td>Returns only after completing tap with card payment</td><td></td></tr><tr><td>PayWithAccountResult</td><td>Returns only after completing BLE payment</td><td></td></tr><tr><td>PayWithLinkResult</td><td>Returns only after completing link payment</td><td></td></tr><tr><td>Error</td><td>Check 6.1 Error Handling section</td><td></td></tr></tbody></table>

## **Transaction Data**

```kotlin
data class Transaction (
    var type: String? = null
    var amount: String? = null
    var code: String? = null
    var date: String? = null
    var time: String? = null
    var respCode: String? = null
    var respDesc: String? = null
    var rrn: String? = null
    var authCode: String? = null
    var stan: String? = null
    var cardNumber: String? = null
    var cardType: String? = null
    var cardBrand: String? = null
    var aid: String? = null
    var isPinUsed = false
    var rfuList: Map<String, Any>? = null
)
```

<table><thead><tr><th width="329.3333333333333">Field Names</th><th>Descriptions</th><th>Sample Values</th></tr></thead><tbody><tr><td>type</td><td>type of the transaction</td><td>'PAYMENT'</td></tr><tr><td>amount</td><td>using amount value in the transaction</td><td>'150000'</td></tr><tr><td>code</td><td>a unique code of the transaction. It is used for finding the transaction.</td><td>'1D9F9EE737CE1262'</td></tr><tr><td>date</td><td>transaction date “yyyymmdd”</td><td>'20220823'</td></tr><tr><td>time</td><td>transaction time “hhmmss”</td><td>'080905'</td></tr><tr><td>respCode</td><td>Response Code of the transaction</td><td>'00'</td></tr><tr><td>respDesc</td><td>Response Description of the transaction</td><td>'Success'</td></tr><tr><td>rrn</td><td>Reference Retrieval Number of the transaction</td><td>'202208230809'</td></tr><tr><td>authCode</td><td>Authorization Code of transaction</td><td>'080905'</td></tr><tr><td>stan</td><td>System Trace Audit Number of the transaction</td><td>'15590'</td></tr><tr><td>cardNumber</td><td>masked pan of the card using in the transaction</td><td>'************6375'</td></tr><tr><td>cardType</td><td>type of the card using in the transaction</td><td>'CREDIT'</td></tr><tr><td>cardBrand</td><td>brand of the card using in the transaction</td><td>'VISA'</td></tr><tr><td>aid</td><td>Application Identifier of the card using in the transaction</td><td>'a0000000031010'</td></tr><tr><td>isPinUsed</td><td>is pin used in this transaction or not</td><td>false</td></tr><tr><td>rfuList</td><td>RFUList (Reserved for future use) object is used to transfer key value pairs between backend system and merchant application</td><td></td></tr></tbody></table>
