# SDK Integrations

Libs

For 330TR add the libs below.

{% file src="<https://3604734571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPaz8tFKqEd6volXC5G4B%2Fuploads%2FvcKk8BmGl9qahfCeEDHS%2Frklbinding-debug.aar?alt=media&token=5bfa0b2f-c8e0-4b06-8adf-a9f646e2d720>" %}
RKL
{% endfile %}

{% file src="<https://3604734571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPaz8tFKqEd6volXC5G4B%2Fuploads%2F0QY8zF5aScA2img2fA3k%2FlibTokenKMS_release_v1.1.4.aar?alt=media&token=75768793-ac01-49d6-bfc3-1ed904a72f5e>" %}
KMS
{% endfile %}

{% file src="<https://3604734571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPaz8tFKqEd6volXC5G4B%2Fuploads%2Fvmp7yWrkKGQ1YCERtO8t%2Ftokeninc_printer_v19.6.aar?alt=media&token=e7f5db9d-3f90-4308-b791-49071b4c72c8>" %}
Printer-Deprecated
{% endfile %}

{% file src="<https://3604734571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPaz8tFKqEd6volXC5G4B%2Fuploads%2FsggbUXiKOd3NRawCWkRZ%2Ftokeninc_printer_v20.1.aar?alt=media&token=00d54b53-7929-4533-8ee5-472fe8ec1314>" %}
Printer
{% endfile %}

{% file src="<https://3604734571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPaz8tFKqEd6volXC5G4B%2Fuploads%2F8ReVyMdvy79i1AlOQpt9%2FSunmiUSDKForToken_1.6.2.aar?alt=media&token=2f168d8d-76c4-4a50-88db-341be459ebd4>" %}
SunmiUSDK
{% endfile %}

{% file src="<https://3604734571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPaz8tFKqEd6volXC5G4B%2Fuploads%2FFZMS3QHs7NWmH4mw6gnL%2Fcardservicebinding_240320.aar?alt=media&token=17782438-b2f2-41d9-8236-4b1173c13b0c>" %}
Card Service
{% endfile %}

{% file src="<https://3604734571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPaz8tFKqEd6volXC5G4B%2Fuploads%2FTuon6y72WXlQYMEXyT0y%2FTDeviceInfo_1.7.aar?alt=media&token=8a67d17b-c94a-4197-aa18-f79682347dbd>" %}

###

### Manifest

**330TR:**

```java
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
```

### Build Gradle

**Ui Components**

```java
implementation 'com.google.android.material:material:1.6.0'
```

Note: Add to app/build.gradle for x30 ui components

## **KMS**

**400TR:**\
new CtKMS2System().checkKey(VersionParams.*keyset*, 0);

**330TR:**\
kms.checkKeyExist(VersionParams.*tpk*);

**Service Binding:**

```java
kms = new TokenKMS();
kms.init(getApplicationContext(), new KMSWrapperInterface.InitCallbacks() {
    @Override
    public void onInitSuccess() {
        Log.v("Token KMS onInitSuccess", "KMS Init OK");
    }
    @Override
    public void onInitFailed() {
        Log.v("Token KMS onInitFailed", "KMS Init Failed");
    }
});
```

### **Enc/Dec**

#### **400TR:**

```java
CtKMS2FixedKey enckey = new CtKMS2FixedKey();
enckey.setCipherMethod(CTOS.CtKMS2FixedKey.DATA_ENCRYPT_METHOD_ECB);
…

CtKMS2FixedKey deckey = new CtKMS2FixedKey();
deckey.setCipherMethod(CTOS.CtKMS2FixedKey.DATA_ENCRYPT_METHOD_ECB);
…

```

#### **330TR:**

```java
kms.encryptData(VersionParams.kek, tdata2encrypt, TokenKMSConstants.TOKENKMS_PROTECTION_MODE_ECB, ICV);

kms.decryptData(VersionParams.pek, data, TokenKMSConstants.TOKENKMS_PROTECTION_MODE_CBC, ICV);
```

### **Write Key**

#### **400TR:**

```java
CtKMS2KPK kpk = new CtKMS2KPK();
…
kpk.setCipherKeyLocation(KEK_keyset, KEK_keyindex);
kpk.setKeyLocation(keyset, keyindex);
…
kpk.writekey();
```

#### **330TR**

```java
kms.injectKeybyKEK(VersionParams.kek, 1, TokenKMSConstants.TOKENKMS_KEYTYPE_TDK, TokenKMSConstants.TOKENKMS_KEY_ALG_TYPE_3DES,
```

## Printer

{% hint style="info" %}
v19.6 is deprecated. v20.0 contains major changes that will lock the main thread while printing long content. Please test it with long print content before using it.
{% endhint %}

### **400TR:**

```java
printService = new PrintServiceBinding(); // Bind Service
printService.print(printText); // Print
```

### **330TR:**

```java
StyledString styledText = new StyledString();
/* Add text…*/
styledText.print(PrinterService.getService(getApplicationContext())); // Print, without service binding
```

## Card Service

### **getCard** &#x20;

String config:

```
{
 "forceOnline":1,
 "fallback":1,
 "zeroAmount":1,
 "keyIn":1,
 "askCVV":1,       
 "showAmount":1,   
 "showCardScreen":1,
 "partialEMV":1, 
 "qrPay":1,  
 "emvTxnType":0,
 "emvProcessType":1,
 "reqEMVData":"575A5F245F204F84959F12",
 "cardReadTypes":6,
 "getOnlinePIN":1,
 "kmsVersion": 2,
 "keySet": 0,
 "keyIndex": 4,
 "minLen": 4,
 "maxLen": 12,
}
```

<mark style="color:red;">**Note**</mark>**:**   The following fields are mandatory to be added for x30 integration.

* **getOnlinePIN:** Must sent during the **getCard** Operation for **ICC** transactions.
* **kmsVersion** :&#x20;

&#x20;         **1 :** Deprecated: Compatible with 400TR and 1000TR Castles-based systems.

&#x20;         **2 :** new KMS library, compatible with all devices.

* **keyIndex** : keyIndex value of the PIN key
* **keySet** : allocated keySet value of the bank. Only set for kmsVersion 1. Not needed for kmsVersion 2.
* **keyIndex** : keyIndex value of the PIN key.

### **getOnlinePINEx**

<mark style="color:red;">**Note**</mark>**: getOnlinePINEx** API use to get Encrypted PIN with kmsVersion 2, and As kmsVersion 1 has been deprecated, please use **getOnlinePINEx**.&#x20;

**getOnlinePINEx(**&#x53;tring confi&#x67;**) API Details**

```
{
  "amount": 80000,
  "PAN": "4797957003463700",
  "kmsVersion": 2,
  "keySet": 0,
  "keyIndex": 4,
  "minLen": 4,
  "maxLen": 12,
  "timeout": 30
}
```

* **kmsVersion** : Send 2 for new KMS&#x20;
* **keyIndex** : keyIndex value of the PIN key.

### **completeEMVTxn**

All ICC transactions must be completed in 330TR. The card read process is not completed until completeEmvTxn is called. Other than requested actions by API,  ICC transactions can be completed as follows:

```java
if (card.getmCardReadType() == CardReadType.ICC.value) {
    byte action = (byte) 0x01;
    int emvResult = cardServiceBinding.completeEmvTxn(action, new byte[]{0, 0}, new byte[]{0, 0}, 0, new byte[]{0, 0}, 0);
}
```

### setEMVConfiguration

```
<TerminalConfig>   
.
.
.
.
.
<Item name="Trans Currency Code" tag="5F2A" attribute="hex">0949</Item>
</TerminalConfig>
```

<mark style="color:red;">Note:</mark> 5F2A field mandatory to be added for x30 integration.

<mark style="color:red;">**Note:**</mark> The setEMVConfiguration should be called first and followed by the setEMVCLConfiguration.

## Android Studio Configuration:

You need to edit your configurations in 330TR unlike 400/1000TR because its version is more than Android 11. Therefore you need to open Edit Configurations and then select "Always install with package manager". If you don't select that configuration, your latest changes won't work on your 330TR device.

<figure><img src="https://3604734571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPaz8tFKqEd6volXC5G4B%2Fuploads%2FLOlzL3NMYXdgC0vDMzhx%2FScreenshot%202024-04-25%20at%2013.09.15.png?alt=media&#x26;token=eaa0e2f2-c77b-4ef4-aee5-13944dce6955" alt=""><figcaption><p>Click Edit Configurations</p></figcaption></figure>

<figure><img src="https://3604734571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPaz8tFKqEd6volXC5G4B%2Fuploads%2F6Veia0HbblexbDDp5x46%2FScreenshot%202024-04-25%20at%2013.10.59.png?alt=media&#x26;token=073515f3-1395-4504-a82d-2a72c3de674f" alt=""><figcaption><p>Make sure you choose Always install with package manager option</p></figcaption></figure>
