# Getting started with App 2 App Integration

EasyPOS Integration Guidelines for Sunmi Payment Devices

# Introduction

This document explains the steps required to integrate Partner applications with the CM POS Payments App-2-app integration solution. This integration is based on the usage of the CM POS Payments SDK and Terminal application on an Android based Sunmi payment device.

[block:html]
{
"html": "An example ECR implementation that will speed up the development and allows integrators to focus on <em>their</em> logic can be found on the <a href=\"https://github.com/cmdotcom/sunmi-ecr-example-kotlin\" target=\"new\">GitHub pages of CM.com</a>. This code example shows the integration with the CM POS Payments SDK, which in turn can be found on the <a href=\"https://github.com/cmdotcom/android-pos-integration-sdk-kotlin\" target=\"new\">CM.com GitHub pages, where the SDK is located</a>.\n"
}
[/block]

In order to be able to use this library, the integrator has the possibility to choose between the following flavours:

* Developing a pure native Android app that will include the library as dependency to start transactions and other operations on CM POS Payments gateway.

* Developing a hybrid Android app that uses Web Views, of which the native part of the app will include the CM Payments Android POS integration library to start transactions and other operations on CM POS Payments gateway.

[block:html]
{
"html": "<blockquote class=\"callout callout_info\" theme=\"❗️\">\n  <h3 class=\"callout-heading empty\">\n    <img src=\"https://files.readme.io/0a789e6-info-removebg-preview.png\" width=\"75%\"/>\n  </h3>\n  <p><br/>\n    At this point in time, CM POS Payments does not support the SDK to be called from a browser running on the payment terminal.\n    <br/><br/>\n  </p>\n</blockquote>"
}
[/block]

# Terminology

<table>
<colgroup>
<col style="width: 50%" />
<col style="width: 50%" />
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">Term</th>
<th style="text-align: left;">Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;"><p>App-2-app integration</p></td>
<td style="text-align: left;"><p>Integration between two applications, namely Partner and CM POS Payments Terminal application, which are on the same Sunmi device</p></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>CM Payments Android POS integration SDK</p></td>
<td style="text-align: left;"><p>Android library that can be used in Partner applications to integrate with CM POS Payments apps and perform payment transactions.</p></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>CM POS Payments Terminal application</p></td>
<td style="text-align: left;"><p>Android based application which calls the CM POS Payments Gateway to process the payment</p></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>Development Sunmi Payment device</p></td>
<td style="text-align: left;"><p>Sunmi device that is used for development purposes and testing the application integration</p></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>ECR</p></td>
<td style="text-align: left;"><p>Electronic Cash Register, and in the context of this document the ECR will be an Android based app providing the ECR features.</p></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>Partner application</p></td>
<td style="text-align: left;"><p>Android based application developed by the partner integrating with CM POS Payments payment solution for payment acceptance</p></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>Sunmi</p></td>
<td style="text-align: left;"><p>Payment terminal device manufacturer of the Sunmi mobile payment terminals.</p></td>
</tr>
</tbody>
</table>

[block:html]
{
"html": "<blockquote class=\"callout callout_info\" theme=\"❗️\">\n  <h3 class=\"callout-heading empty\">\n    <img src=\"https://files.readme.io/0a789e6-info-removebg-preview.png\" width=\"75%\"/>\n  </h3>\n  <p><br/>\n    App-2-app integration is supported by all CM provided Sunmi mobile payment devices.\n    <br/><br/>\n  </p>\n</blockquote>"
}
[/block]

# Download the CM POS Payments apps

The following steps describe how to download the CM POS Payments Terminal application for the Development Sunmi Payment device. Once you have performed the Development activities as described in chapter 5, you can verify that the payment flow performs as expected with the Partner application.

<table>
<colgroup>
<col style="width: 50%" />
<col style="width: 50%" />
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">Step</th>
<th style="text-align: left;">Reference visual</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;"><p>Click ‘App Store’ on your Sunmi device</p></td>
<td style="text-align: center;"><p><img src="https://files.readme.io/9da2069-image006.jpg" alt="9da2069 image006" /></p></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>Choose and install the Terminal application</p></td>
<td style="text-align: center;"><p><img src="https://files.readme.io/d8463fb-image005.png" alt="d8463fb image005" /></p></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>You are done!</p></td>
<td style="text-align: center;"><p><img src="https://files.readme.io/82818fa-rsz_darkgreencheck.png" alt="82818fa rsz darkgreencheck" /></p></td>
</tr>
</tbody>
</table>

## Dependencies between library and Terminal version

Terminal version is the minimum version needed to use each version of the Integration SDK

<table>
<colgroup>
<col style="width: 33%" />
<col style="width: 33%" />
<col style="width: 33%" />
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">Integration Library version</th>
<th style="text-align: left;">Terminal version</th>
<th style="text-align: left;">Changelog</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;"><p>1.0.0</p></td>
<td style="text-align: left;"><p>1.1.0</p></td>
<td style="text-align: left;"><p>Initial version</p></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>1.0.1</p></td>
<td style="text-align: left;"><p>1.1.1</p></td>
<td style="text-align: left;"><p>Forward auto timezone not enabled error</p></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>1.1.0</p></td>
<td style="text-align: left;"><p>1.2.0</p></td>
<td style="text-align: left;"><ul>
<li><p>Support for pre authorization transactions</p></li>
<li><p>Forward low battery level error</p></li>
<li><p>Support for Android 9</p></li>
</ul></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>1.1.2</p></td>
<td style="text-align: left;"><p>2.0.0</p></td>
<td style="text-align: left;"><p>Fix crash in some edge cases</p></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>1.1.3</p></td>
<td style="text-align: left;"><p>2.0.1</p></td>
<td style="text-align: left;"><ul>
<li><p>Don't start new operation if another one is already in progress </p></li>
<li><p>Remove isTipping parameter from SDK payment Data </p></li>
</ul></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>1.1.4</p></td>
<td style="text-align: left;"><p>2.7.0</p></td>
<td style="text-align: left;"><ul>
<li><p>Send library version to terminal application </p></li>
<li><p>Fix typo in error description </p></li>
</ul></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>1.2.0</p></td>
<td style="text-align: left;"><p>2.11.0</p></td>
<td style="text-align: left;"><ul>
<li><p>Fix typo in error description </p></li>
</ul></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>1.2.1</p></td>
<td style="text-align: left;"><p>2.14.0</p></td>
<td style="text-align: left;"><ul>
<li><p>Support MAT functionality</p></li>
</ul></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>1.3.0</p></td>
<td style="text-align: left;"><p>2.17.0</p></td>
<td style="text-align: left;"><ul>
<li><p>Added support for <i>acceptance</i> build type</p></li>
<li><p>Deprecated the <i>debug</i> build type</p></li>
</ul></td>
</tr>
</tbody>
</table>

# Payment solution overview

This chapter provides an overview of the required applications and how they work together as a payment solution. The transaction flow is described step by step.

## Partner application, payment library and Terminal application

The App-2-app integration for the Sunmi Android platform consists of two applications and one library:

* **The Partner application**: Android based application developed by the partner integrating with CM POS Payments payment solution for payment acceptance

* **The CM POS Payments Terminal application**: handling card entry and the payment flow. It can perform payments and refund transactions. Also handles receipts for transactions.

* **The CM Payments Android POS integration library**: provides functionality to handle transactions on the gateway. It requests transaction data to Partner application and forwards it to the terminal application. It also provides functionality to get information about old transactions and other info that may be useful for integrators, such as current currency code used by Terminal application.

Partners need to have their Android app running on the same physical device as the CM POS Payments Terminal application and include the CM Payments Android POS integration library as a dependency on their app.

## Transaction Flow

In this section we explain how the Partner application initiates a transaction and we describe both the transaction flow through the Terminal application and the interactions between it and the user.

[block:image]
{
    "images": [
        {
            "image": [
                "https://files.readme.io/3283aee-diag-5b2514e3623515b37f51b01166b3c4aa.png",
                "diag-5b2514e3623515b37f51b01166b3c4aa.png",
                537,
                597,
                "#000000"
            ]
        }
    ]
}
[/block]

The basic functioning of the Integration library is that Partner Applications can send the transaction request (`doTransaction()` method on the Integration service class inside the Integration library) together with the call-back object. Once the result of the transaction is received, the library will trigger the appropriate call-back method.

A transaction starts with the merchant entering an amount. The device is then handed over to the cardholder, who presents their card, authorizes the transaction, and receives the transaction outcome. The device is then handed back to the merchant and, if needed, receipts are printed.

Transition between applications is seamless and the entire flow appears as if it is handled by the ECR application alone. This is done thanks to the integration library which integrates the call to the Terminal application within partner’s application context.

Also, it is important to mention that transaction flow in Terminal application does not manifest itself to the user in any way. When Terminal application is opened from the launcher screen it starts some functionality checks, such as terminal configuration availability, correct keys on device, network connection and gateway availability, and after those checks are finished, a banner advising the user to switch to an ECR application (In this case, the partner application) is displayed.

It is important to point out that while the Terminal application UI is visible during a transaction, it is not possible to interact with the Partner application.

You can also see on the diagram that sdk takes into account the possibility that the Terminal application or device can crash by any reason. In that case, Partner App should request the status of the transaction to be certain about the result of the operation. (see "Dealing with unexpected scenarios" chapter)

## I18n and language negotiation

The default language in which the user interface is presented by the CM POS Payments application is the language configured in the shop configuration in the Gateway. It is expected that the partner application does the same.

The CM POS Payments application will switch to the cardholder preferred language if suggested by the EMV card and if the translation into this language exists. The CM POS Payments application will switch language, if applicable, after the language setting on the card has been read.

It is the responsibility of the partner application developers to make their application support the languages they want to use.

If the partner wants to override the language set for the shop, they can provide a language code to the CM POS Payments applications. The CM POS Payments applications will use that language, provided it is supported by our applications. If a language code is provided that is not supported by CM POS Payments, our applications will default to the English language.

# Development Guidelines

This section explains how your app communicates with the CM POS Payments applications.

A card payment goes through the following flow:

1. The Partner application uses the CM Payments Android POS integration library to start a transaction with the appropriate data (transaction type, amount, currency…​).

2. The CM POS Payments Terminal application receives the information thanks to the integration library and calls the CM POS Payments Gateway to process the payment.

3. CM POS Payments Android POS integration library receives the transaction result from Terminal application and send it back to the Partner applications using a call-back. The result consists of a result data and the receipts for the transaction (if any) from the Gateway.

4. The Partner application performs the transaction result and provides printer receipts.

## Integration Mechanism

In order to pass data to the CM POS Payments app, the Partner app needs to use the CM Payments Android POS integration library methods and wait for a result. To be able to use these methods, the Partner application needs to include the library as a dependency in the code. Integration library can be used to integrate in two different environments: acceptance and production. You should include the correct dependency for the environment in which you are operating. The acceptance build allows registered developers to use our acceptance environment, which offers simulators for various test scenarios. The production build connects to a real, production environment. A complete working example app is available at [GitHub](https://github.com/cmdotcom/sunmi-ecr-example-kotlin), to give you a head start in integrating with the SDK.

### Import Integration SDK as a dependency

**Code Sample. add jitpack repository to your main build or settings gradle file**

[block:code]
{
    "codes": [
        {
        "code": "dependencyResolutionManagement {\n    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)\n    repositories {\n        google()\n        mavenCentral()\n        maven { url 'https://jitpack.io' }\n    }\n}",
        "language": "groovy"
        }
    ]
}
[/block]

**Code Sample. dependency for production environment**

[block:code]
{
    "codes": [
        {
            "code": "dependencies {\n    ...\n    // CM Payments Android POS integration library\n    implementation 'com.github.cmdotcom.android-pos-integration-sdk-\nkotlin:androidposintegrationsdk:<version-tag>'\n}",
            "language": "groovy"
        }
    ]
}
[/block]

**Code Sample. dependency for acceptance environment**

[block:code]
{
    "codes": [
        {
            "code": "dependencies {\n    ...\n    // CM Payments Android POS integration library\n    implementation 'com.github.cmdotcom.android-pos-integration-sdk-\nkotlin:androidposintegrationsdk-acc:<version-tag>'\n}",
            "language": "groovy"
        }
    ]
}
[/block]

Please note: the "-acc" SDK will connect to our acceptance environment, whereas the SDK without "-acc" in the name will connect to our production environment. The difference between the two:

* Acceptance: payments are simulated

* Production: payments are real

It is the responsibility of the integrator to be able to produce **two** different builds of the same application, one for each environment that is targeted. **\<version-tag>** should be changed for the correct version number available in release notes

### Migrating from debug SDK to acceptance SDK

The debug variant of the POS SDK is deprecated from version 1.3.0, and we recommend that all integrators use the acceptance variant of the SDK for development and testing purposes.
If you are integrating the SDK for the first time, following the dependency instructions above will be enough to start using the acceptance variant of the SDK.
If you are already using the debug variant of the SDK, in order to migrate to the acceptance variant, you need to change the dependency in your build.gradle file in your ECR application as shown in the [code sample above](#import-integration-sdk-as-a-dependency).

### Creating a signed APK according to Sunmi Requirements

The APK needs to support the Android V1 and V2 signature. The Android build.gradle configuration automatically compiles signingConfigs and V1, V2 signing. For Sunmi applications both signatures need to be turned on, otherwise the APK upload in the MDM will fail.

[block:code]
{
    "codes": [
        {
            "code": "android {\n  ...\n  signingConfigs {\n    ...\n    release {\n      ...\n      v1SigningEnabled = true\n      v2SigningEnabled = true\n    }\n  }\n",
            "language": "groovy"
        }
    ]
}
[/block]

Finally, in the AndroidManifest.xml, the option extractNativeLibs needs to be set to true:

[block:code]
{
    "codes": [
        {
            "code": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\" package=\"....\">\n    ...\n    <application\n        android:extractNativeLibs=\"true\"\n        ...>\n        ...\n    </application>\n</manifest>",
            "language": "xml"
        }
    ]
}
[/block]

#### Additional information for P2 LITE SE and P3 models

Since these models are running a different version of the Sunmi OS, additional information in the Android Manifest file of your application is needed. In these devices it is also needed to request query permissions for the CM POS Payments Terminal app.

[block:code]
{
    "codes": [
        {
            "code": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\" package=\"....\">\n    ...\n    <queries>\n        <package android:name=\"com.payplaza.terminal.dev\" />\n        <package android:name=\"com.payplaza.terminal\" />\n    </queries>\n    ...\n</manifest>",
            "language": "xml"
        }
    ]
}
[/block]

First line is for dev devices and second line is to use it live.

### Import Integration SDK as a binary

* Download the desired .aar file from [releases](https://github.com/cmdotcom/android-pos-integration-sdk-kotlin/releases)

* Place the downloaded file into your project. We recommend create a folder called 'lib' near 'src' folder of the app module.

* Add the import in your build gradle file:

[block:code]
{
    "codes": [
        {
            "code": "dependencies {\n    [...]\n    // CM Payments Android POS integration library\n    implementation files('lib/<aar_file_name>')\n}",
            "language": "groovy"
        }
    ]
}
[/block]

Once this is done, your application should initialize the application with your android context application so CM POS Payments library can communicate with CM POS Payments Terminal application:

**Code Sample. Initialization of CM Payments Android POS integration library.**

[block:code]
{
    "codes": [
        {
            "code": "override fun onCreate() {\n    super.onCreate()\n    AndroidPosIntegration.init(this)\n}",
            "language": "kotlin"
        }
    ]
}
[/block]

Once you have done this you can access the PosIntegrationService instance in your code by using the `getInstance` method of the `AndroidPosIntegration` object in CM Payments Android POS integration Library

**Code Sample. Getting the CM POS PaymentsPaymentService instance.**

[block:code]
{
    "codes": [
        {
            "code": "val service = AndroidPosIntegration.getInstance()",
            "language": "kotlin"
        }
    ]
}
[/block]

This PosIntegrationService has a list of methods that can be used to perform operation in CM POS Payments environment. The methods are the following:

[block:code]
{
    "codes": [
        {
            "code": "interface PosIntegrationService { \n    fun doTransaction(data: TransactionData, callback:TransactionCallback)\n\n    fun transactionStatuses(data: RequestStatusData, callback:StatusesCallback)\n\n    fun getLastReceipt(options: LastReceiptOptions, callback:ReceiptCallback) \n      \n    fun getTerminalDayTotals(options:DayTotalsOptions, callback: ReceiptCallback)\n\n    fun getTerminalInfo(callback: TerminalInfoCallback)\n\n    fun finishPreAuth(data: PreAuthFinishData, callback:TransactionCallback)\n}",
            "language": "kotlin"
        }
    ]
}
[/block]

**doTransaction**: Is used to perform a transaction on CM POS Payments app.

**transactionStatuses**: It is used to request status of a previous transaction performed by CM POS Payments Terminal application.

**getLastReceipt**: It is used to request the receipt of the last transaction performed by Terminal application.

**getTerminalDayTotals**: It is used to request the totals information from the gateway.

**getTerminalInfo**: It is used to request information about the merchant shop in which the terminal is connected.

**finishPreAuth**: It is used to finish a previously pre authorized transaction.

### Passing data to the library for Transaction flow

Data can be passed to the CM Payments Android POS integration library by using a payment object with the appropriate data.

<span id="code-sample-transaction-data">**Code Sample. Transaction Data.**</span>

[block:code]
{
    "codes": [
        {
            "code": "data class TransactionData(val type: TransactionType,\n                           val amount: BigDecimal,\n                           val currency: Currency,\n                           val orderReference: String) {\n    var language: String? = null\n    var refundStan: String? = null\n    var refundDate: Date? = null\n    var isCaptureSignature = true\n    var isShowReceipt = true\n    var maxOfflineSaleAmount: BigDecimal? = null\n    var maxOfflineTransactionsCount: Int? = null\n    var maxOfflineSaleAmountPerTransaction: BigDecimal? = null\n}",
            "language": "kotlin"
        }
    ]
}
[/block]

Values for the payment data attributes are specified following this table;

<table>
<colgroup>
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">Attribute Name</th>
<th style="text-align: left;">Data Type/ Class</th>
<th style="text-align: left;">Required</th>
<th style="text-align: left;">Default</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;"><p>type</p></td>
<td style="text-align: left;"><p>com.cm.androidposintegration.enums.TransactionType Three options.</p></td>
<td style="text-align: left;"><p>Mandatory</p></td>
<td style="text-align: left;"></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>amount</p></td>
<td style="text-align: left;"><p>BigDecimal</p></td>
<td style="text-align: left;"><p>Mandatory</p></td>
<td style="text-align: left;"></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>currency</p></td>
<td style="text-align: left;"><p>java.util.Currency</p></td>
<td style="text-align: left;"><p>Mandatory</p></td>
<td style="text-align: left;"></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>orderReference</p></td>
<td style="text-align: left;"><p>String(max 14)</p></td>
<td style="text-align: left;"><p>Mandatory</p></td>
<td style="text-align: left;"></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>language</p></td>
<td style="text-align: left;"><p>String(2)</p></td>
<td style="text-align: left;"><p>Optional</p></td>
<td style="text-align: left;"><p>System Language</p></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>refundStan</p></td>
<td style="text-align: left;"><p>String(6)</p></td>
<td style="text-align: left;"><p>Optional</p></td>
<td style="text-align: left;"></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>refundDate</p></td>
<td style="text-align: left;"><p>java.util.Date</p></td>
<td style="text-align: left;"><p>Optional</p></td>
<td style="text-align: left;"></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>isCaptureSignature</p></td>
<td style="text-align: left;"><p>boolean</p></td>
<td style="text-align: left;"><p>Optional</p></td>
<td style="text-align: left;"><p>true</p></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>isShowReceipt</p></td>
<td style="text-align: left;"><p>boolean</p></td>
<td style="text-align: left;"><p>Optional</p></td>
<td style="text-align: left;"><p>true</p></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>maxOfflineSaleAmount</p></td>
<td style="text-align: left;"><p>BigDecimal</p></td>
<td style="text-align: left;"><p>Optional</p></td>
<td style="text-align: left;"><p></p></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>maxOfflineTransactionsCount</p></td>
<td style="text-align: left;"><p>Int</p></td>
<td style="text-align: left;"><p>Optional</p></td>
<td style="text-align: left;"><p></p></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>maxOfflineSaleAmountPerTransaction</p></td>
<td style="text-align: left;"><p>BigDecimal</p></td>
<td style="text-align: left;"><p>Optional</p></td>
<td style="text-align: left;"><p></p></td>
</tr>
</tbody>
</table>

#### Attributes explanation

**type** is a field in which you can specify the type of transaction that you want to use. An Enum is defined on the integration library so partners can choose between payment, refund or pre authorization.

**amount** is the transaction (payment or refund) amount. It is mandatory. It is represented as a BigDecimal including the decimal separator. For example, an amount in euro’s is represented as "12,34", twelve euros and thirty four cents.

**currency** is a java.util.Currency object and indicates the currency in which the transaction will be performed. There is a merchant shop configuration present on the gateway. This configuration contains the store currency among other parameters. Partners can retrieve that currency using the *getInfo* operation present on the library. CM POS Payments Terminal application can perform a transaction using a different currency from the default one, although in some cases that is not recommended (See ref for details).

**orderReference** is a mandatory string of up to 14 characters. You are free to put in any text. The CM POS Payments app will return your order reference in the receipt lines (see recovery procedure). Transactions are not accepted in case the order reference is not present in the intent. Order reference needs to have a unique ID per POS for each transaction and date. Order reference may contain a maximum of 14 alphanumeric characters without special characters.

**language** is specified as a two-character string that represents a valid Locale language. Should be set using ISO-639-1 Code ("EN" for English, "NL" for Dutch, …​) We currently support English, French, Dutch, German and Spanish. If you need other languages, please contact us. Language is configured in the merchant shop configuration in the Gateway. Only specify a language via the Intent if you need a language different from what is configured in the Gateway for your shop.

**refundStan** It is a String up to 6 characters. It represents the system trace audit number. It is only used for refund transactions and it can be found on the receipt for the previous transaction that has to be refunded

**transactionDate** is the date and time of the transaction. It is a java.util.Date object representing the date of the previous transaction. It is only used for refund transactions.

**isCaptureSignature** is a Boolean, indicating whether the Terminal application should perform on-screen signature capture for signature CVM transactions. When set to true and the transaction CVM is signature, the Terminal application will ask the user to sign on screen and send the signature back on the receipt to the partner application as a bitmap (see receipt handling on library for more details). This is the default behaviour. Partners can override that behaviour by setting this attribute to false.

**isShowReceipt** Indicates if the receipt(s) need(s) to be shown in CM POS Payments Terminal application. Default value is true, so terminal is always showing the receipts. Partners can override that behaviour by setting that attribute to false.

**maxOfflineSaleAmount**: This property is only used for MAT feature. It indicates the maximum total sale amount that can be stored in Terminal application while processing offline transactions. This value can be different for every transaction, but it always must be less than the corresponding CM defined limit for MAT feature (see [MAT feature chapter](#mat-feature) for more information)

**maxOfflineTransactionsCount**: This property is only used for MAT feature. It indicates the maximum number of transactions that can be stored in the Terminal application while processing transactions offline, in case that the gateway is unreachable. This value can be different for every transaction, but it always must be less than the corresponding CM defined limit for MAT feature (see [MAT feature chapter](#mat-feature) for more information)

**maxOfflineSaleAmountPerTransaction**: This property is only used for MAT feature. It indicates the maximum sale amount allowed per transaction when the Terminal application processes the transaction offline, in case that the gateway is unreachable. This value can be different for every transaction, but it always must be less than the corresponding CM defined limit for MAT feature (see [MAT feature chapter](#mat-feature) for more information)

Example of Transaction PaymentData object that can be used for the transaction:

* Transaction type: purchase

* Value: 5.95€

* Currency: EUR

* Order reference: 0303-000112

**Code Sample. Transaction Data object creation for Payment Transaction**

[block:code]
{
    "codes": [
        {
            "code": "val data = TransactionData(TransactionType.PURCHASE, BigDecimal(5.95), Currency\n.getInstance(\"EUR\"),\"0303-000112\")",
            "language": "kotlin"
        }
    ]
}
[/block]

## Transactions of type Refund

There are two possibilities when a refund transaction is sent as Transaction Type on the Transaction object: Standard refund transaction and STAN/TX refund transaction.

In the first case, no other information is required and the refund transaction will be performed with the amount sent.

In the second case, STAN and Transaction date information linked to a previous transaction, need to be provided to CM POS Payments application in the following form:

TRANSACTION\_STAN: string (6 characters. 6 STAN digits from the previous transaction) TRANSACTION\_DATE: string (8 characters with the following format: “dd/MM/yy”)

If the transaction type received by CM POS Payments app is "refund" and no other related information - like the STAN and transaction date - is present on the transaction object, the refund will be processed as standard refund flow. If transaction type is refund and STAN and Transaction date are present, refund flow will be linked to a previous existing transaction. If only one of the STAN and TX Date is present, an error will be returned by CM POS Payments Terminal application.

Example of Transaction Data object for a Refund transaction

* Transaction type: refund

* Value: 5.95€

* Currency: EUR

* Order reference: 0303-000113

* STAN of previous transaction: 065987

* Date of previous transaction: February 1st, 2021

**Code Sample. Transaction Data object creation for Refund Transaction**

[block:code]
{
    "codes": [
        {
            "code": "val data = TransactionData(\n                TransactionType.REFUND,\n                BigDecimal(5.95),\n                Currency.getInstance(\"EUR\"),\n                \"0303-000113\"\n           )\ndata.refundStan = \"065987\" // Can be found on the receipt\nval dateFormat = SimpleDateFormat(\"dd/MM/yy\")\ndata.refundDate = dateFormat.parse(\"01/02/21\") // Can be found on the receipt",
            "language": "kotlin"
        }
    ]
}
[/block]

## Transactions of type Pre Auth

[block:html]
{
    "html": "<blockquote class=\"callout callout_info\" theme=\"❗️\">\n  <h3 class=\"callout-heading empty\">\n    <img src=\"https://files.readme.io/0a789e6-info-removebg-preview.png\" width=\"75%\"/>\n  </h3>\n  <p><br/>\n   Support of pre-authorization transactions is dependent on the acquirer that is used. Please contact sales to find out which acquirers are supported.\n    <br/><br/>\n  </p>\n</blockquote>"
}
[/block]

CM POS Payments payment system supports also the functionality to pre authorize a transaction and confirm it or cancel it afterwards. In order to pre authorize a transaction, the method `doTransaction` can be used with the transaction type of the `TransactionData` object set to `PRE_AUTH`

**Code Sample. Transaction Data object creation for Pre Auth. Transaction**

[block:code]
{
    "codes": [
        {
            "code": "val data = TransactionData(\n                TransactionType.PRE_AUTH,\n                BigDecimal(5.95),\n                Currency.getInstance(\"EUR\"),\n                \"0303-000113\"\n           )",
            "language": "kotlin"
        }
    ]
}
[/block]

### Finishing a pre authorized transaction

A transaction that has been pre authorized then needs to be finished at some point in time. To do that, the POS integration library has a method that can confirm or cancel a previosly pre authorized transaction. This method receives a PreAuthFinishData object with the corresponding information to confirm or cancel a pre authorized transaction.

#### Finish pre authorization transaction

[block:image]
{
    "images": [
        {
            "image": [
                "https://files.readme.io/981d380-diag-576d853b14193b36b64704c647418fca.png",
                "diag-576d853b14193b36b64704c647418fca.png",
                537,
                597,
                "#000000"
            ]
        }
    ]
}
[/block]

Same as with a `doTransaction` operation, IntegrationLirary needs to receive the data for the operation and a transaction callback to send the result once it is has been received from CM POS Payments Terminal application.

The data class used for this operation is PreAuthFinishData. This class contains the following information:

**Code Sample. PreAuhtFinishData class.**

[block:code]
{
    "codes": [
        {
            "code": "class PreAuthFinishData(val type:PreAuthFinishType, val originalStan: String,\n                        val originalDate: Date, val orderRef: String) {\n    var amount: BigDecimal? = null\n    var currency: Currency? = null\n    var isShowReceipt: Boolean = true\n}",
            "language": "kotlin"
        }
    ]
}
[/block]

Values for the payment data attributes are specified following this table;

<table>
<colgroup>
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">Attribute Name</th>
<th style="text-align: left;">Data Type/ Class</th>
<th style="text-align: left;">Required</th>
<th style="text-align: left;">Default</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;"><p>type</p></td>
<td style="text-align: left;"><p>com.cm.androidposintegration.enums.PreAuthFinishType</p></td>
<td style="text-align: left;"><p>Mandatory</p></td>
<td style="text-align: left;"></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>originalStan</p></td>
<td style="text-align: left;"><p>String</p></td>
<td style="text-align: left;"><p>Mandatory</p></td>
<td style="text-align: left;"></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>originalDate</p></td>
<td style="text-align: left;"><p>String</p></td>
<td style="text-align: left;"><p>Mandatory</p></td>
<td style="text-align: left;"></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>orderRef</p></td>
<td style="text-align: left;"><p>String</p></td>
<td style="text-align: left;"><p>Mandatory</p></td>
<td style="text-align: left;"></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>amount</p></td>
<td style="text-align: left;"><p>BigDecimal</p></td>
<td style="text-align: left;"><p>Conditional</p></td>
<td style="text-align: left;"></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>currency</p></td>
<td style="text-align: left;"><p>Currency</p></td>
<td style="text-align: left;"><p>Conditional</p></td>
<td style="text-align: left;"></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>isShowReceipt</p></td>
<td style="text-align: left;"><p>Boolean</p></td>
<td style="text-align: left;"><p>Mandatory</p></td>
<td style="text-align: left;"><p>true</p></td>
</tr>
</tbody>
</table>

#### Atributes explanation

**type**: There are two possible values for this attribute `SALE_AFTER_PRE_AUTH` and `CANCEL_PRE_AUTH`.

**originalStan**: It is the stan of the previously pre authorized transaction

**originalDate**: It is the date of the previously pre authorized transaction

**orderRef**: It is the order reference use to identify the current transaction

**amount**: It is the amount of the operation. This parameter is mandatory when confirming a pre authorized transaction but is not needed when canceling a previously pre authorized transaction.

**currency**: It is the currency that will be used in the transaction. Same as the previous one is mandatory when confirming a pre authorized transaction but is not needed when canceling a previously pre authorized transaction.

**isShowReceipt**: This parameter indicates whether the terminal will show the receipt or not. In any case, this receipt will be included in the callback data that is going to be received by the partner application

#### Confirming a previously pre authorized transaction

In order to confirm a pre authorized transaction, CM POS Payments payment platform accepts two possible scenarios:

* Confirm the transaction with the total amount used in the previously pre authorized transaction

* Confirm the transaction with smaller amount than the one used in the previously pre authorized transaction.

It is not possible to confirm a pre authorized transaction with a higher amount that the one used in the first pre authorization transaction.

#### Canceling a previously pre authorized transaction

Cancel a pre authorized transaction is also possible. For this operation an amount can be sent, but it is going to be ignored as CM POS Payments payment platform is always canceling the total amount that was pre authorized in the original transaction.

## Receiving results

In order to receive the results for a transaction with the CM Payments Android POS integration library, partners have to define a call-back object that will be called back as soon as the result has been processed by the library.

<span id="code-sample-transactioncallback">**Code Sample. Definition of TransactionCallback**</span>

[block:code]
{
    "codes": [
        {
            "code": "interface TransactionCallback {\n    fun onResult(data : TransactionResultData)\n    fun onError (error : ErrorCode)\n    fun onCrash ()\n}",
            "language": "kotlin"
        }
    ]
}
[/block]

Object defined by Partner application needs to implement this interface. When library has the result of the transaction, it will call method *onResult* on the call-back and Partner application can get the result using the parameter on the call-back. For that, the class *TransactionResultData* is used

Values for the Transaction Result Data attributes are specified following this table:

<table>
<colgroup>
<col style="width: 33%" />
<col style="width: 33%" />
<col style="width: 33%" />
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">Atribute Name</th>
<th style="text-align: left;">Data Type/ Class</th>
<th style="text-align: left;">present</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;"><p>transactionResult</p></td>
<td style="text-align: left;"><p>com.cm.androidposintegration.enums.TransactionResult</p></td>
<td style="text-align: left;"><p>always</p></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>orderReference</p></td>
<td style="text-align: left;"><p>String(max 14)</p></td>
<td style="text-align: left;"><p>always</p></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>amount</p></td>
<td style="text-align: left;"><p>BigDecimal</p></td>
<td style="text-align: left;"><p>always</p></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>authResponseCode</p></td>
<td style="text-align: left;"><p>String</p></td>
<td style="text-align: left;"><p>If Tx processed</p></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>cardEntryMode</p></td>
<td style="text-align: left;"><p>String</p></td>
<td style="text-align: left;"><p>If Tx processed</p></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>ecrId</p></td>
<td style="text-align: left;"><p>String</p></td>
<td style="text-align: left;"><p>If present on the receipt</p></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>processorName</p></td>
<td style="text-align: left;"><p>String</p></td>
<td style="text-align: left;"><p>If present on the receipt</p></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>transactionDateTime</p></td>
<td style="text-align: left;"><p>java.util.Date</p></td>
<td style="text-align: left;"><p>If present on the receipt</p></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>transactionId</p></td>
<td style="text-align: left;"><p>String</p></td>
<td style="text-align: left;"><p>If Tx Processed</p></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>cardScheme</p></td>
<td style="text-align: left;"><p>String</p></td>
<td style="text-align: left;"><p>If present on the receipt</p></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>aid</p></td>
<td style="text-align: left;"><p>String</p></td>
<td style="text-align: left;"><p>if present on the receipt</p></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>cardNumber</p></td>
<td style="text-align: left;"><p>String</p></td>
<td style="text-align: left;"><p>If present on the receipt</p></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>cardType</p></td>
<td style="text-align: left;"><p>Integer</p></td>
<td style="text-align: left;"><p>If Tx Processed</p></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>stan</p></td>
<td style="text-align: left;"><p>String</p></td>
<td style="text-align: left;"><p>If present on the receipt</p></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>merchantReceipt</p></td>
<td style="text-align: left;"><p>com.cm.androidposintegration.beans.ReceiptData</p></td>
<td style="text-align: left;"><p>If merchant receipt received from Gateway</p></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>customerReceipt</p></td>
<td style="text-align: left;"><p>com.cm.androidposintegration.beans.ReceiptData</p></td>
<td style="text-align: left;"><p>If customer receipt received from Gateway</p></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>tipAmount</p></td>
<td style="text-align: left;"><p>BigDecimal</p></td>
<td style="text-align: left;"><p>If tip amount was entered by cardholder</p></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>isProcessedOffline</p></td>
<td style="text-align: left;"><p>Boolean</p></td>
<td style="text-align: left;"><p>If MAT feature is enabled for the device</p></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>storedTransactionsCount</p></td>
<td style="text-align: left;"><p>Integer</p></td>
<td style="text-align: left;"><p>If MAT feature is enabled for the device</p></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>storedSaleAmount</p></td>
<td style="text-align: left;"><p>BigDecimal</p></td>
<td style="text-align: left;"><p>If MAT feature is enabled for the device</p></td>
</tr>
</tbody>
</table>

### Attributes Explanation

**transactionResult**: The resultCode you receive on the call-back. It is an enum defined on the library and can be one of the following:

[block:code]
{
    "codes": [
        {
            "code": "SUCCESS (\"Operation was successful\")\nCANCELLED (\"Operation was cancelled\")\nAUTHORIZATION_FAILURE (\"Operation did not have authorization\")\nAUTHORIZATION_TIMEOUT (\"Timeout in last operation authorization\")\nCARD_BLOCKED (\"Card used is blocked\")\nCARD_INVALID (\"Card used is invalid\")\nDECLINED_BY_CARD (\"Operation was declined by card\")\nINSUFICIENT_FUNDS (\"Not sufficient funds to perform last authorization\")\nFAILED (\"Operation failed\")\nAMOUNT_EXCEEDED (\"Amount of last operation exceeded the limit\")\nHOST_BLOCKED_PRINT_RECEIPT (\"Operation couldn’t be performed. Receipt of the last\ntransaction pending\")\nREQUEST_RECEIPT(\"Request Receipt of current Transaction\")",
            "language": "kotlin"
        }
    ]
}
[/block]

Each value has its own description so it is easy for users to understand what happened with the transaction.

**orderReference**: Is the order reference used in the transaction this value was received to perform the transaction and it is sent back to the partner application

**amount**: Is the amount received for the transaction.

**authResponseCode**: Is the authorization response code received on the transaction. It is only present if the transaction has been processed.

**cardEntryMode**: Is the card entry mode used in the transaction. It is present only if the transaction has been processed. It has one of the following values:

[block:code]
{
    "codes": [
        {
            "code": "\"CARD_ENTRY_MODE_MAG_STRIPE\"\n\"CARD_ENTRY_MODE_MAG_STRIPE_FALL_BACK\"\n\"CARD_ENTRY_MODE_ICC\"\n\"CARD_ENTRY_MODE_CONTACTLESS\"\n\"CARD_ENTRY_MODE_CONTACTLESS_MAG\"",
            "language": "kotlin"
        }
    ]
}
[/block]

**processorName**: Is the name of the payment processor used in the transaction. It can also be found on the receipt lines.

**transactionDateTime**: It is the date and time of the transaction received from the gateway.

**transactionId**: It is the internal transaction id used in CM POS Payments gateway

**cardScheme**: Is the Scheme of the card (Mastercard, Visa, …​) used in the transaction.

**aid**: Is the AID of the card used in the transaction

**cardNumber**: It is the masked pan of the card that has been used in the transaction.

**cardType**: It is an integer that indicates the type of the card used in the transaction. It can have the following values:

[block:code]
{
    "codes": [
        {
            "code": "MAGNETIC CARD: 1\nNFC CARD: 4\nICC (CHIP): 2",
            "language": "text"
        }
    ]
}
[/block]

**stan**: Is the System Trace Audit Number of the transaction. It can also be found on the transaction.

**merchantReceipt**: It is the transaction receipt for the merchant. It is received if the merchant receipt was sent by the gateway. It is an object of the class *com.CM POS Payments.androidposintegration.beans.ReceiptData*

**customerReceipt**: It is the transaction receipt for the customer. It is received if the customer receipt was sent by the gateway. Same as merchant receipt, it is an object of the class *com.CM POS Payments.androdposintegration.beans.ReceiptData*

**tipAmount**: It is the transaction tip amount that was entered by the cardholder. This amount is only present in the response if it was entered by cardholder. For that, the device needs to be configured to support Tip feature.

**isProcessedOffline**: Indicates if the transaction has been processed offline. This is only true when MAT feature is enabled for the device and the terminal couldn't go online.

**storedTransactionsCount**: Indicates the total number of transactions that are stored in the Terminal application at the end of the transaction that has been processed. This is only different from 0 when the terminal has MAT feature enabled.

**storedSaleAmount**: Indicates the total sale amount of transactions that are stored in the Terminal application at the end of the transaction that has been processed. This is only different from 0 when the terminal has MAT feature enabled.

#### Receipt Data

The receipt data object received by partners has two attributes:

[block:code]
{
    "codes": [
        {
            "code": "var receiptLines: Array<String>?\nvar signature: ByteArray?",
            "language": "kotlin"
        }
    ]
}
[/block]

**receiptLines**: is an array with the formatted lines of the receipt

**signature**: It is a Byte Array with the bitmap signature performed on Screen if the receipt needs a signature. It is only present if the signature has been done on the device. You can create a bitmap from the signature byte array present on the receipt using `BitmapFactory.decodeByteArray(…)`:

[block:code]
{
    "codes": [
        {
            "code": "signatureInMerchantReceipt = BitmapFactory.decodeByteArray(\n    merchantReceiptgetSignature(),\n    0,\n    merchantReceipt.getSignature().length \n)",
            "language": "kotlin"
        }
    ]
}
[/block]

**Simple Receipt Sample**

```
Shopname

Terminal:       PPCCVBZS
Merchant:         654321
ECR:      E_SUNMI_P2lite
          _PL0919CQ00283
STAN:             130075

             CONTACTLESS
AID:      A0000000043060
                 MAESTRO
Card:       ********0308
Cardnb:                0

Date: 19-07-21  09:52:52
AC:     F9A1D8E9A1014A60
Processor:           CCV
Auth. code:       FA5822
Auth. resp. code:     00

Amount:         EUR 2,49
REF:             7000135

   Payment approved

CARDHOLDER RECEIPT

     shop footer
```

**Receipt with signature sample**

```
Shopname

Terminal:       PPCCVBZS
Merchant:         654321
ECR:      E_SUNMI_P2lite
          _PL0919CQ00283
STAN:             130075

             CONTACTLESS
AID:      A0000000043060
                 MAESTRO
Card:       ********0308
Cardnb:                0

Date: 19-07-21  09:52:52
AC:     F9A1D8E9A1014A60
Processor:           CCV
Auth. code:       FA5822
Auth. resp. code:     00

Amount:         EUR 2,49
REF:             7000135

   Payment approved

MERCHANT RECEIPT

CARDHOLDER SIGNATURE



......................

     shop footer
```

[block:html]
{
"html": "<blockquote class=\"callout callout_warning\" theme=\"❗️\">\n  <h3 class=\"callout-heading empty\">\n    <img src=\"https://files.readme.io/6e1e943-warning-exclamation-removebg-preview.png\" width=\"75%\"/>\n  </h3>\n  <p><br/>\n    It is responsibility of your application to print the signature in the appropriate\nposition on the merchant receipt.\n    <br/>\n  </p>\n</blockquote>"
}
[/block]

### Error Cases

CM Payments Android POS integration library uses `onResult` method in the callback when there is no error on the transaction flow between the card, terminal and gateway. However, it could be the case when some situations may lead into errors in the flow (e.g.: connection lost). For those cases, the method `onError` is used. CM POS Payments library also creates an ErrorCode Enum object with the following values:

[block:code]
{
    "codes": [
        {
            "code": "NO_ERROR (0, \"No error\")\nUNKNOWN_ERROR (-1, \"Unknown error\")\nAMOUNT_INVALID (-2, \"Amount used was invalid\")\nNO_INTERNET (-12, \"Device is not connected to the network\")\nPOS_NOT_CONFIGURED (-18, \"Device is not configured in gateway\")\nAUTO_TIMEZONE_NOT_ENABLED(-23, \"Autotimezone is not enabled on device\")\nBAD_TIMEZONE (-24, \"Timezone on the device is not correct\")\nHOST_NOT_CONNECTED (-25, \"Cannot connect with the gateway\")\nMERCHANT_ORDER_REF_NOT_PRESENT (-29, \"Order reference not present in request data\")\nTIMEOUT (-30, \"Timeout reaching the gateway\")\nREPEATED_OPERATION (-31, \"Transaction already in progress\")\nMERCHANT_ORDER_REF_TOO_LONG (-32, \"Order ref exceeds allowed length\")\nAMOUNT_LIMIT_EXCEEDED (-33, \"Transaction exceeds allowed limit\")\nINTERNAL_PROCESSING_ERROR (-34, \"Internal processing error during transaction flow. Transaction couldn't be processed\")\nINVALID_ORIGINAL_DATA (-35, \"Data related with previous transaction is invalid\")\nLOW_BATTERY_LEVEL (-36, \"Battery level is too low to start a transaction\")\nWRONG_EMV_AUTHORIZATION_DATE_AND_TIME (-37, \"Wrong date and time in authorization request. Please reboot your device.\")\nRECEIPT_NOT_AVAILABLE (-38, \"Receipt not available\")\nSTORE_TRANSACTIONS_COUNT_LIMIT_REACHED (-39, \"Maximum number of stored transactions limit reached\")\nSTORE_TRANSACTIONS_AMOUNT_LIMIT_WILL_BE_REACHED (-40, \"Maximum sale amount stored transactions limit will be reached with the current transaction\")\nSTORE_TRANSACTIONS_AMOUNT_LIMIT_REACHED (-41, \"Maximum sale amount stored transaction limit reached\")\nMAT_INVALID_TRANSACTION_TYPE (-42, \"Invalid transaction type for MAT\")\nMAX_TRANSACTION_AMOUNT_LIMIT_REACHED (-43, \"The sale amount exceeds offline payment limit.\")\nMAX_TRANSACTION_AMOUNT_LIMIT_INVALID (-46, \"Offline payment limit is invalid.\")\nMAX_TOTAL_AMOUNT_LIMIT_INVALID (-47, \"Total offline payments sale amount limit is invalid.\")\nMAX_TRANSACTIONS_COUNT_LIMIT_INVALID (-48, \"Offline payments count limit is invalid.\")\nTRANSACTION_STATUS_ERROR (-50, \"Status information not received\")\nINFO_REQUEST_FAILED (-51, \"Info Request towards the gateway has failed\")",
            "language": "kotlin"
        }
    ]
}
[/block]

Values also contain a description so users can know what went wrong with the previous transaction.

## Dealing with unexpected scenarios

The CM POS Payments app handles recovery of the payment transaction. This means, the CM POS Payments app receives a payment request from partner application using the payment library and takes responsibility for properly handling that.

After processing, the app will return the result of the payment (which can have succeeded or failed) or it will return an ErrorCode result containing information on a failed operation.

But CM POS Payments integration library can also call `onCrash` because of a crash on Terminal CM POS Payments. If this is the case or if the Partner app crashes or is not capable of receiving the result for whatever reason, the CM POS Payments integration library app allows Partner app to recover by requesting information of past transactions. This means we always need an order reference to be able to retrieve results of previous transactions. That is why order reference is a required attribute in the Transaction Data object needed by library to perform a transaction. Order reference does not need to be unique, because multiple transactions can refer to the same order reference. This happens when transactions fail, and new transactions are started with the same order reference for the same payment.

### Requesting transaction information for an existing order reference

If the partner app needs to recover, or wants to retrieve old transaction results, the CM POS Payments integration library allows the partner app to request the status of the previous transaction associated with an order reference. The method on the The CM POS Payments app will return the results for that order reference that were sent previously.

This is flow for requesting the transaction status:

[block:image]
{
    "images": [
        {
            "image": [
                "https://files.readme.io/0f77a6b-diag-5516c99efee3c7cf17b402eed9b5e1bd.png",
                "diag-5516c99efee3c7cf17b402eed9b5e1bd.png",
                393,
                269,
                "#000000"
            ]
        }
    ]
}
[/block]

Because the order reference is not unique on a transaction level - the payment for a particular order reference can be retried a number of times, resulting in multiple transactions with the same order reference - a request for previous transaction results can result in multiple results. Of these, one may be a success result, the others are typically failure results.

The method to be used to retrieved this statuses is `transactionStatuses`. It receives an object of class `RequestStatusData`:

[block:code]
{
    "codes": [
        {
            "code": "data class RequestStatusData (var orderReference: String? = null,\n                              var page: Int = 0,\n                              var size: Int = 0,\n                              var sortField: String? = null,\n                              var sortValue: String? = null) {\n    constructor (orderReference: String) : this() {\n        this.orderReference = orderReference\n    }\n}",
            "language": "kotlin"
        }
    ]
}
[/block]

[block:html]
{
"html": "<blockquote class=\"callout callout_info\" theme=\"❗️\">\n  <h3 class=\"callout-heading empty\">\n    <img src=\"https://files.readme.io/0a789e6-info-removebg-preview.png\" width=\"75%\"/>\n  </h3>\n  <p>Please note that you can create an object of class RequestStatusData with no info or an object passing the value for the merchant order reference. This is due to the fact that the transaction status can be requested with no specific order reference and you will received the status of all transactions performed by the Sunmi device that is being used in the current day.\n  </p>\n</blockquote>"
}
[/block]

**page**: It is an integer and can be used to indicate the number of the start page of the result (useful if there are too many transactions associated to one order reference)

**size**: It is an integer and can be used to indicate the number of statuses per reply (if 0 it is ignored).

**sortFiled**: It can be used to indicate in which field sorting needs to be performed.

**sortValue**: It can be used to indicate which type of sorting needs to be applied. Possible values are "asc" for ascending or "desc" for descending.

**Example**

[block:code]
{
    "codes": [
        {
            "code": "val requestData = RequestStatusData(\"003-00012\")\nPayplazaPaymentService.transactionStatuses(requestData, statusesCallback)",
            "language": "kotlin"
        }
    ]
}
[/block]

StatusesCallback is used to receive the result in the same way that TransactionCallback is used to received the result of a transaction.

statusesCallback object also has a method `onResult` to receive the result of the statuses request to CM POS Payments Terminal application.

[block:code]
{
    "codes": [
        {
            "code": "interface StatusesCallback {\n    fun onResult(data : TransactionStatusesData)\n    fun onError (error : ErrorCode)\n    fun onCrash ()\n}",
            "language": "kotlin"
        }
    ]
}
[/block]

TransactionStatusesData class is defined as follows:

[block:code]
{
    "codes": [
        {
            "code": "data class TransactionStatusesData constructor(val statusesInfo: List\n                                               <TransactionStatusData>?,\n                                               val errorMessage: String,\n                                               val totalCount: Int): Parcelable",
            "language": "kotlin"
        }
    ]
}
[/block]

**statusesInfo** is a list of objects of class `TransactionStatusData`, which contains the information for one transaction:

[block:code]
{
    "codes": [
        {
            "code": "class TransactionStatusData (val amount: BigDecimal,\n                             val currency: Currency,\n                             val result: TransactionResult,\n                             val type: TransactionType,\n                             var receipt: ReceiptData? = null) : Parcelable {",
            "language": "kotlin"
        }
    ]
}
[/block]

The transaction Status Data contains the amount of the transaction, the currency used in that transaction, the result of the transaction, the type of the transaction and the receipt of the transaction. `statusesInfo` attribute contains a list of all transactions associated with the order reference used.

### Sending an operation when there is already one operation in progress

It may be the case that integrators send more than one operation at the same time to the SDK. Terminal application can process only one operations at a time so SDK must ensure it.

In the case that integrators send more than one operations, the SDK it will call `onError` and sends `REPEATED_OPERATION (-31, "Transaction already in progress")` back to integrator's ECR.

It's up to integrators to implement `onError` callback and decide next actions. In order to perform a proper integration please implement `onResult(data : TransactionStatusesDa)`, `onError(error : ErrorCode)`, `onCrash()` callbacks. Check section <<5.4, 5.4>> for more details.

## Receiving REQUEST\_RECEIPT as transaction result

This is an special case of the recovery procedure. There are situations in which the CM POS Payments Terminal has received the transaction result but it is not possible to get the receipts of the transaction (e.g.: because of a connection lost event). In this case, we cannot be certain of the transaction result until the receipt is received for the transaction.

If CM POS Payments Integration library responds with that result, that means that Partner application should use the method `getLastReceipt` in order to complete the current transaction (see chapter 6 for more information about this operation).

## PrinterX integration

To integrate directly with PrinterX for printing receipts or creating custom receipts, refer to the official Sunmi documentation page available at [Sunmi Printing SDK Overview](https://developer.sunmi.com/docs/en-US/cdixeghjk491/xdzceghjk502). This guide provides detailed instructions, demo code, and resources to help you build and customize your integration effectively.

# Other Operations in SDK

## Last Receipt functionality

It is also possible to request the receipt for the last transaction performed by CM POS Payments terminal application. This can be used to retrieve a copy of the last receipt received on Partner application, but also to retrieve the receipt of the last transaction even if the result did not reach your application.

This is the flow for requesting the receipt of the previous transaction:

[block:image]
{
    "images": [
        {
            "image": [
                "https://files.readme.io/55aebbc-diag-740aa968546ebd077849e985350780e8.png",
                "diag-740aa968546ebd077849e985350780e8.png",
                382,
                269,
                "#000000"
            ]
        }
    ]
}
[/block]

**Request for the last receipt**

[block:code]
{
    "codes": [
        {
            "code": "val lastReceiptOptions = LastReceiptOptions(true)\npaymentService.getLastReceipt(options, receiptCallback)",
            "language": "kotlin"
        }
    ]
}
[/block]

**lastReceiptOptions**: is an object containing the options for the operation:

[block:code]
{
    "codes": [
        {
            "code": "val isShowReceipt: Boolean",
            "language": "kotlin"
        }
    ]
}
[/block]

You can select whether to show the receipt in CM POS Payments Terminal application or not by setting that attribute to true (receipt shown in terminal app) or false (receipt not shown in the Terminal application).

**receiptCallback** is a ReceiptCallback object that will be used by the CM Payments Android POS integration library to call Partner application back when the result of the operation and the receipt (if any) are received from the gateway.

[block:code]
{
    "codes": [
        {
            "code": "fun onResult(data : LastReceiptResultData)\nfun onError (error : ErrorCode)\nfun onCrash ()",
            "language": "kotlin"
        }
    ]
}
[/block]

receiptCallback object must implement ReceiptCallback interface which means that it needs to implement the onResult, onError and onCrash methods (same as other call-back objects) **data** is an object of class LastReceiptResultData which has the following attribute

[block:code]
{
    "codes": [
        {
            "code": "val receiptData : ReceiptData",
            "language": "kotlin"
        }
    ]
}
[/block]

This **receiptData** is the same as the receipt received on the transaction operations and contains the receipt received from the gateway.

If anything goes wrong in the call to the gateway, method onError will be triggered with the appropriate information, same as with the other functionality on the CM POS Payments Library.

## Day totals functionality

CM POS Payments also provides integrators with the possibility to request the total amount money handled by the device in one day. We call that the Day totals of the terminal.

This is the flow for the get Terminal day totals functionality.

[block:image]
{
    "images": [
        {
            "image": [
                "https://files.readme.io/99d0350-diag-6a06be9c9067162c90c5e61743f8a256.png",
                "diag-6a06be9c9067162c90c5e61743f8a256.png",
                428,
                269,
                "#000000"
            ]
        }
    ]
}
[/block]

Partners can make use of that functionality by calling the day totals operation on the library service:

[block:code]
{
    "codes": [
        {
            "code": "val dayTotalsOptions = DayTotalsOptions(true)\ndayTotalsOptions.setFrom(\"10:00\")\npaymentService.getTerminalDayTotals(dayTotalsOptions, receiptCallback)",
            "language": "kotlin"
        }
    ]
}
[/block]

**dayTotalsOptions** is an object containing the options for the operation:

[block:code]
{
    "codes": [
        {
            "code": "val isShowReceipt: Boolean\nvar from : String? = null",
            "language": "kotlin"
        }
    ]
}
[/block]

Same as with the last receipt functionality, you can select whether to show the receipt in the Terminal application or not. You can also select the hour of the present day from which the day totals will be calculated. If Partner application does not set that parameter, terminal will take `00:00` as the default hour and the day totals will be calculated from that time to the current time of the day in which the request is submitted.

**receiptCallback** is the same call-back that must be implemented for the last receipt functionality (see Last Receipt functionality chapter)

## Request Info functionality

CM POS Payments Terminal also provides this functionality to retrieve some useful information for partners. Terminal is configured on a merchant store on the gateway with some information (like the store name, address, language of the store, currency to use, …​). This information can be requested by partners by using this functionality present on the CM POS Payments integration library.

[block:image]
{
    "images": [
        {
            "image": [
                "https://files.readme.io/5ae0fe4-diag-caa4709bf135ee1616f7d410743059d5.png",
                "diag-caa4709bf135ee1616f7d410743059d5.png",
                354,
                269,
                "#000000"
            ]
        }
    ]
}
[/block]

**Request info data sample**

[block:code]
{
    "codes": [
        {
            "code": "paymentService.getTerminalInfo(infoCallback)",
            "language": "kotlin"
        }
    ]
}
[/block]

In this case, there is no need to send extra information on the request, therefore, the only parameters present on the call.

**infoCallback** is an object of class TerminalInfoCallback. Partner object must implement the methods present on the interface same as with other functions present on the library. It contains the following functions

[block:code]
{
    "codes": [
        {
            "code": "fun onResult(data : TerminalInfoData)\nfun onError (error : ErrorCode)\nfun onCrash ()",
            "language": "kotlin"
        }
    ]
}
[/block]

**onResult** method is called when CM POS Payments Library has received the information requested by Partner application. Parameter *data* contains all the data that is sent by Terminal application:

[block:code]
{
    "codes": [
        {
            "code": "var storeName: String? = null\nvar storeAddress: String? = null\nvar storeCity: String? = null\nvar storeZipCode: String? = null\nvar storeLanguage: String? = null\nvar storeCountry: String? = null\nvar storeCurrency: Currency? = null\nvar deviceSerialNumber: String? = null\nvar versionNumber: String? = null\nvar isMatAllowed: Boolean? = null\nvar maxOfflineSaleAmount: BigDecimal? = null\nvar maxOfflineTransactionsCount: Int? = null\nvar maxOfflineSaleAmountPerTransaction: BigDecimal? = null",
            "language": "kotlin"
        }
    ]
}
[/block]

**storeName** is the name of the store in which the terminal is configured on the gateway.

**storeAddress** is the address of the store in which the terminal is configured on the gateway.

**storeCity** is the city of the store in which the terminal is configured on the gateway.

**storeZipCode** is the zip code of the store in which the terminal is configured on the gateway.

**storeLanguage** is the default language of the store in which the terminal is configured on the gateway

**storeCurrency** is the default currency of the store in which the terminal is configured on the gateway

**deviceSerialNumber** is the serial number of the sunmi device in which the Terminal application is running.

**versionNumber** is the version number of the Terminal application.

**isMatAllowed** indicates if MAT feature is enabled for the Terminal application.

**maxOfflineSaleAmount** indicates the current CM-defined limit for the maximum sale amount that can be stored on the device.

**maxOfflineTransactionsCount** indicates the current CM-defined limit for the maximum number of transactions that can be stored on the device.

**maxOfflineSaleAmountPerTransaction** indicates the current CM-defined limit for the maximum sale amount per transaction to be stored on the device.

[block:html]
{
    "html": "<blockquote class=\"callout callout_info\" theme=\"❗️\">\n  <h3 class=\"callout-heading empty\">\n    <img src=\"https://files.readme.io/0a789e6-info-removebg-preview.png\" width=\"75%\"/>\n  </h3>\n  <p><br/>\n    onResult method in TerminalInfoCallback interface is the same as previous callbacks on the other operations.\n    <br/>\n  </p>\n</blockquote>"
}
[/block]

## MAT functionality

[block:html]
{
"html": "<blockquote class=\"callout callout_info\" theme=\"❗️\">\n  <h3 class=\"callout-heading empty\">\n    <img src=\"https://files.readme.io/0a789e6-info-removebg-preview.png\" width=\"75%\"/>\n  </h3>\n  <p><br/>\n This feature is available upon request. Please contact Sales for more information.\n    <br/>\n  </p>\n</blockquote>"
}
[/block]

Starting from version 2.14.0, the Terminal application introduces a feature called MAT (Merchant Approved Transactions), which allows the terminal to process purchase transactions when the network connection is unavailable and the gateway cannot be reached. This feature ensures business continuity by enabling offline transaction processing directly on the terminal, where each completed offline transaction is stored locally on the device. Once the network connection is restored, all stored transactions are automatically sent to the gateway for final processing.
It is important to note that MAT is exclusively available for offline purchase transactions and does not apply to other transaction types.

**MAT feature availability**

The MAT functionality can be enabled individually for each POS configured in a merchant store. The property `isMatAllowed` indicates whether the MAT feature is enabled for the Terminal application. If the value of `isMatAllowed` is `true`, the terminal is configured to support offline transactions through the MAT feature.

This property can be retrieved using the `getTerminalInfo()` method in the CM POS Payments Android POS integration library (see [Request Info functionality](#request-info-functionality) for more details).

**MAT Limits**

When the MAT feature is enabled, the terminal can process offline purchase transactions, but only under specific conditions known as MAT limits.

By default, the Terminal application uses limits configured by CM.com, known as hard limits. These hard limits are predefined thresholds that define the maximum limits allowed for offline purchase transactions on each terminal device, which are fixed and cannot be exceeded. These limits include:

* Maximum number of transactions (`maxOfflineTransactionsCount`): Hard limit for the total number of offline transactions that can be stored locally on each terminal device.
* Maximum total sale amount (`maxOfflineSaleAmount`): Hard limit for the cumulative total amount of all offline transactions stored locally on each terminal device.
* Maximum amount per transaction (`maxOfflineSaleAmountPerTransaction`): Hard limit for the highest amount allowed for a single offline transaction.

These properties can be retrieved using the `getTerminalInfo()` method in the CM POS Payments Android POS integration library (See [Request Info functionality](#request-info-functionality) for more details).

Integrators have the flexibility to define custom limits, known as soft limits, which must always be smaller than the hard limits set by CM.com. Soft limits allow integrators to adjust the offline transaction capacities of the terminal while staying within the boundaries of the hard limits.

Soft limits can be configured using the `TransactionData` object in the `doTransaction` function. The following properties are available for setting soft MAT limits (See code sample [Transaction Data](#code-sample-transaction-data) for more details):

* `maxOfflineTransactionsCount`: Specifies the soft limit for the maximum number of offline transactions that can be stored locally on the terminal.
* `maxOfflineSaleAmount`: Specifies the soft limit for the maximum cumulative sale amount of offline transactions stored locally on the terminal.
* `maxOfflineSaleAmountPerTransaction`: Specifies the soft limit for the maximum sale amount allowed for a single offline transaction.

**Validation of MAT transactions**

The Terminal application validates each purchase transaction against the configured MAT limits and the requirements to ensure compliance:

* If soft limits are not provided by the integrator, the Terminal application defaults to the hard limits set by CM.com. Transactions are validated against these hard limits.
* If the integrator chooses to use custom soft limits, the Terminal application uses them to validate the transaction. Soft limits must always be smaller than the hard limits set by CM.com. See error codes (-46), (-47) and (-48) from [MAT Errors](#mat-errors) if soft limits exceed hard limits.
* If any of the soft limits provided by the integrator is missing, the Terminal application will validate the transaction using the corresponding hard limit for the missing parameter.
* If the transaction amount exceeds the maximum offline sale amount, the transaction is canceled. See error code (-43) from [MAT Errors](#mat-errors) for more information.
* If the transaction type is not PURCHASE, the transaction is canceled. See error code (-42) from [MAT Errors](#mat-errors) for more information.

If the transaction complies with the MAT limits and the requirements, it can be processed offline, and if successful, is stored locally on the terminal. Once the connection is restored, the stored transactions are sent to the gateway for final processing.

**Offline Transaction Metrics**

The Terminal application tracks specific metrics related to offline transactions. These metrics provide valuable insights into the terminal's offline transaction activity and storage capacity, helping merchants and integrators monitor the status of the offline transactions stored.

These metrics can be accessed via the `TransactionResultData` object, which is provided in the callback method `onResult` when using the CM POS Payments Android POS integration library (See code sample [TransactionCallback](#code-sample-transactioncallback) for more details).

* `isProcessedOffline`: Indicates if the transaction has been processed offline successfully.
* `storedTransactionsCount`: Represents the total number of offline transactions currently stored locally on the device. This value is updated after each offline transaction. If the transactions count exceeds the MAT limit for total transactions, see error code (-39) from [MAT Errors](#mat-errors) for more information.
* `storedSaleAmount`: Represents the cumulative total sale amount of all offline transactions stored locally on the device. If the amount exceeds or is about to exceed the MAT limit, see error codes (-40) and (-41) from [MAT Errors](#mat-errors) for more information.

These metrics reflect the current state of offline transactions stored on the terminal. Once the terminal recovers its internet connection, it synchronizes with the gateway and begins sending the stored transactions online. When all transactions are successfully sent to the gateway, these parameters reset to zero. If the terminal loses its internet connection during the syncing process, these metrics will continue to reflect the transactions and total amount awaiting synchronization. The terminal will resume syncing once the connection is restored, until no transactions remain stored.

<span id="mat-errors">**MAT Errors**</span>

While using the MAT feature, certain errors may occur. The Terminal application provides specific error codes to help integrators identify and resolve these issues effectively. Below is a list of possible MAT-related errors and their descriptions:

* <span id="RECEIPT_NOT_AVAILABLE">RECEIPT\_NOT\_AVAILABLE (-38): Receipt not available for the transaction.</span>
* STORE\_TRANSACTIONS\_COUNT\_LIMIT\_REACHED (-39): Maximum number of stored transactions limit reached.
* STORE\_TRANSACTIONS\_AMOUNT\_LIMIT\_WILL\_BE\_REACHED (-40): Maximum sale amount for stored transactions will be exceeded with the current transaction.
* STORE\_TRANSACTIONS\_AMOUNT\_LIMIT\_REACHED (-41): Maximum sale amount for stored transactions has been reached.
* MAT\_INVALID\_TRANSACTION\_TYPE (-42): Invalid transaction type for MAT. Only purchase is supported.
* MAX\_TRANSACTION\_AMOUNT\_LIMIT\_REACHED (-43): The sale amount exceeds the offline payment limit.
* MAX\_TRANSACTION\_AMOUNT\_LIMIT\_INVALID (-46): Soft limit amount for a single offline transaction is invalid. It exceeds the hard limit.
* MAX\_TOTAL\_AMOUNT\_LIMIT\_INVALID (-47): Soft limit for the total offline payments sale amount limit is invalid. It exceeds the hard limit.
* MAX\_TRANSACTIONS\_COUNT\_LIMIT\_INVALID (-48): Soft limit for the total number of offline payments allowed is invalid. It exceeds the hard limit.

[block:html]
{
"html": "<br/><br/><hr/>"
}
[/block]

# Technical Support

When building and integrating, it can happen that technical support is required. In order for us to answer any technical questions you might have, we require at least the following information to be sent along with the question(s):

## **Validating Sunmi software versions**

**The Sunmi terminal**

1. The type of terminal (P2Pro, P2Lite, P2Mini, P3, etc)

2. Is it a development terminal or a production terminal?

3. The serial number of your terminal

4. The OS version of your terminal

5. The library version of the Sunmi Pay Hardware Service (SPHS)

6. The web view version on the Sunmi terminal

7. The App store service provider that your Sunmi terminal is linked to

**The POS Payments Terminal application**

1. The merchant store that your terminal is linked to

2. The software version of the SDK that is used to integrate with the Terminal application

3. The software version of the POS Payments Terminal application that you are integrating with

For technical questions, please contact CM POS Payments via <ecr.developer@cm.com>

# Simulator Test scenarios

In order to do a full system test there are several test scenario’s that will result in a response message which is not successful. These messages are triggered by the usage of the following amounts and the corresponding results are being presented by the simulators CM POS Payments created on its development platform. To make the CM POS Payments platform as accurate as possible, CM POS Payments has several simulators imitating the behavior of important processors.

[block:html]
{
    "html": "<blockquote class=\"callout callout_info\" theme=\"❗️\">\n  <h3 class=\"callout-heading empty\">\n    <img src=\"https://files.readme.io/0a789e6-info-removebg-preview.png\" width=\"75%\"/>\n  </h3>\n  <p>The only response code for a successful transaction is SUCCESS. With all other response codes the transaction has failed. Other (fail) messages may occur in production environment. To use contactless flow and error codes are required. The same codes are used but with a different amount.<br/>\n  </p>\n</blockquote>"
}
[/block]

<table>
<colgroup>
<col style="width: 10%" />
<col style="width: 10%" />
<col style="width: 20%" />
<col style="width: 30%" />
<col style="width: 30%" />
</colgroup>
<tbody>
<tr class="odd">
<td style="text-align: left;"><p><strong>case</strong></p></td>
<td colspan="2" style="text-align: center;"><p><strong>Value</strong></p></td>
<td style="text-align: left;"><p><strong>Description</strong></p></td>
<td style="text-align: left;"><p><strong>Result Code</strong></p></td>
</tr>
<tr class="even">
<td></td>
<td style="text-align: left;"><p><strong>All</strong></p></td>
<td style="text-align: left;"><p><strong>Under NFC limit</strong></p></td>
<td></td>
<td></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>1</p></td>
<td style="text-align: left;"><p>€200,01</p></td>
<td style="text-align: left;"><p>€20,01</p></td>
<td style="text-align: left;"><p>The cardholder has reached the total amount limit of his/her card</p></td>
<td style="text-align: left;"><p>AMOUNT_EXCEEDED</p></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>2</p></td>
<td style="text-align: left;"><p>€200,02</p></td>
<td style="text-align: left;"><p>€20,02</p></td>
<td style="text-align: left;"><p>The cardholder does not have enough funds to buy the goods</p></td>
<td style="text-align: left;"><p>INSUFFICIENT_FUNDS</p></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>3</p></td>
<td style="text-align: left;"><p>€200,03</p></td>
<td style="text-align: left;"><p>€20,03</p></td>
<td style="text-align: left;"><p>The issuer was not able to respond in time</p></td>
<td style="text-align: left;"><p>AUTHORIZATION_TIMEOUT</p></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>4</p></td>
<td style="text-align: left;"><p>€200,04</p></td>
<td style="text-align: left;"><p>€20,04</p></td>
<td style="text-align: left;"><p>The issuer denies the transaction due to special conditions, i.e., fraud suspect</p></td>
<td style="text-align: left;"><p>AUTHORIZATION_FAILURE</p></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>5</p></td>
<td style="text-align: left;"><p>€200,05</p></td>
<td style="text-align: left;"><p>€20,05</p></td>
<td style="text-align: left;"><p>The card used is valid but has been blocked, i.e., exceeded the number of PIN tries</p></td>
<td style="text-align: left;"><p>CARD_BLOCKED</p></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>6</p></td>
<td style="text-align: left;"><p>€200,06</p></td>
<td style="text-align: left;"><p>€20,06</p></td>
<td style="text-align: left;"><p>The card used is not valid anymore, i.e., the card is expired</p></td>
<td style="text-align: left;"><p>CARD_INVALID</p></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>7</p></td>
<td style="text-align: left;"><p>€200,07</p></td>
<td style="text-align: left;"><p>€20,07</p></td>
<td style="text-align: left;"><p>The cardholder has entered a wrong PIN and the processor gives another opportunity to enter it correctly</p></td>
<td style="text-align: left;"><p>PIN_INCORRECT_RETRY</p></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>8</p></td>
<td style="text-align: left;"><p>€200,08</p></td>
<td style="text-align: left;"><p>€20,08</p></td>
<td style="text-align: left;"><p>This case represents the generic error case.</p></td>
<td style="text-align: left;"><p>FAILED</p></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>9</p></td>
<td rowspan="2" style="text-align: left;"><p>SCA</p></td>
<td style="text-align: left;"><p>€20.90</p></td>
<td style="text-align: left;"><p>The issuer asks for further identification, in this case the PIN is needed</p></td>
<td style="text-align: left;"><p>SCA_ADDITION_REQUIRED</p></td>
</tr>
<tr class="even">
<td style="text-align: left;"><p>10</p></td>
<td style="text-align: left;"><p>€20.91</p></td>
<td style="text-align: left;"><p>The issuer asks to change the interface used to perform a contact chip transaction</p></td>
<td style="text-align: left;"><p>CONTACT_CHIP_REQUIRED</p></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><p>11</p></td>
<td style="text-align: left;"><p>€170,70</p></td>
<td style="text-align: left;"><p>€170,70</p></td>
<td style="text-align: left;"><p>The authorization response from processor is delayed</p></td>
<td style="text-align: left;"><p>SUCCESS</p></td>
</tr>
</tbody>
</table>

[block:html]
{
    "html": "<blockquote class=\"callout callout_warning\" theme=\"❗️\">\n  <h3 class=\"callout-heading empty\">\n    <img src=\"https://files.readme.io/6e1e943-warning-exclamation-removebg-preview.png\" width=\"75%\"/>\n  </h3>\n  <p>Cases 7, 9 and 10 can be performed by sending the corresponding amount from\npartner application, but PayPlaza terminal application is going to handle the Pin\nRetry and SCA process by itself. This way, if the process is successful, partner\nApplication will receive SUCCESS as a result code or the corresponding error code\notherwise.<br/>\n  </p>\n</blockquote>"
}
[/block]

[block:html]
{
    "html": "<blockquote class=\"callout callout_info\" theme=\"❗️\">\n  <h3 class=\"callout-heading empty\">\n    <img src=\"https://files.readme.io/0a789e6-info-removebg-preview.png\" width=\"75%\"/>\n  </h3>\n  <p>As mentioned before, the PayPlaza platform has several different Processor simulators, which try to mimic the real world behavior of actual processors in production. As a result it should be noted that not all cases are supported by every processor, which will be reflected in the behavior of the processor simulators as stated below.<br/></p>\n</blockquote>"
}
[/block]

<table style="width:100%;">
<colgroup>
<col style="width: 16%" />
<col style="width: 16%" />
<col style="width: 16%" />
<col style="width: 16%" />
<col style="width: 16%" />
<col style="width: 16%" />
</colgroup>
<thead>
<tr class="header">
<th style="text-align: center;">Case</th>
<th style="text-align: center;">OmniPay Simulator</th>
<th style="text-align: center;">CCV Simulator</th>
<th style="text-align: center;">Equens Simulator</th>
<th style="text-align: center;">SIX Simulator</th>
<th style="text-align: center;">Amex Simulator</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center;"><p>1</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>Not Supported</p></td>
</tr>
<tr class="even">
<td style="text-align: center;"><p>2</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>Not Supported</p></td>
</tr>
<tr class="odd">
<td style="text-align: center;"><p>3</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>Not Supported</p></td>
<td style="text-align: center;"><p>Not Supported</p></td>
</tr>
<tr class="even">
<td style="text-align: center;"><p>4</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
</tr>
<tr class="odd">
<td style="text-align: center;"><p>5</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
</tr>
<tr class="even">
<td style="text-align: center;"><p>6</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>Not Supported</p></td>
</tr>
<tr class="odd">
<td style="text-align: center;"><p>7</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>Not Supported</p></td>
<td style="text-align: center;"><p>Not Supported</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
</tr>
<tr class="even">
<td style="text-align: center;"><p>8</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
</tr>
<tr class="odd">
<td style="text-align: center;"><p>9</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>Not Supported</p></td>
</tr>
<tr class="even">
<td style="text-align: center;"><p>10</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>Not Supported</p></td>
</tr>
<tr class="even">
<td style="text-align: center;"><p>11</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
<td style="text-align: center;"><p>YES</p></td>
</tr>
</tbody>
</table>

# Integration with Java native application

Our library is written in Kotlin, but it is fully compatible with an Android Java application. The integration with a Java application is the same as with a Kotlin written application.

Once the library is included as dependency in the gradle file, the library needs to be initialized with the context of the application.

**Code Sample. initialize library in Java application**

[block:code]
{
    "codes": [
        {
            "code":"@Override \n public void onCreate() {\n     super.onCreate();\n     AndroidPosIntegration.INSTANCE.init(this); \n     ...\n}\n",
            "language": "kotlin"
        }
    ]
}
[/block]

In the previous example, in the onCreate method of the class that is extending the Android Application class, the `AndroidPosIntegration.init()` method is called from the Java code. The `INSTANCE` part is needed as compatibility between Java and Kotlin library.

Once the application has been initialized, an instance of the PosIntegrationService can be got using the following code:

**Code Sample. get PosIntegrationService instance from CM POS Payments AndroidPosIntegrationLibrary**

[block:code]
{
    "codes": [
        {
            "code": "PosIntegrationService paymentService = AndroidPosIntegration.INSTANCE.getInstance();",
            "language": "kotlin"
        }
    ]
}
[/block]