The SDK is an AAR Library meant for Android Applications only. Usage in an application is as described below.
The SDK is an AAR Library meant for Android Applications only. Usage in an application is as described below.
Add the ecrSDK-release_2.0.x.aar file in your app module's libs folder and add the following dependencies in your app's gradle file.
Note: Download ECR SDK by clicking here.
dependencies {
implementation fileTree(dir: "libs", include: ["*.aar"])
implementation 'com.google.code.gson:gson:2.9.0'
}
Proguard entries are required for the library to be executable after obfuscation.
-keep interface com.paytm.ecr.bluetooth.sdk.*{*;}
-keep class com.paytm.ecr.bluetooth.sdk.*{*;}
Initialise the SDK object (preferably in onCreate() method of your Application class, so that it's accessible to all the components in your app)
@Override
public void onCreate() {
super.onCreate();
payments = PaytmPayments.with(this);
payments.init(new Config.Builder()
.setStatusCheckOnSaleRequestEnabled(true).build());
}
Config is used for the library to configure how sales status is received. Please refer to Config Params in the subsequent section.
S.No. | Name | Type | Description |
---|---|---|---|
1 | statusCheckOnSaleRequestEnabled | Boolean | If the statusCheckOnSaleRequestEnabled flag is true then the SDK will keep checking the status of the Sale transaction at regular interval(statusCheckIntervalSeconds) after the initial delay of statusCheckStartSeconds and till saleRequestTimeoutSeconds. The default value is false |
2 | saleRequestTimeoutSeconds | Integer | Timeout for the SALE request in case {@link #statusCheckOnSaleRequestEnabled} is true. default value is {@link com.paytm.ecr.bluetooth.sdk.constants.ConfigConstants#DEFAULT_SALE_REQUEST_TIMEOUT_IN_SECONDS}. the minimum value acceptable is {@link com.paytm.ecr.bluetooth.sdk.constants.ConfigConstants#MIN_SALE_REQUEST_TIMEOUT_IN_SECONDS} |
3 | statusCheckStartSeconds | Integer | The initial delay after which the sdk will start checking the status of the SALE response , in case {@link #statusCheckOnSaleRequestEnabled} is true default value is {@link com.paytm.ecr.bluetooth.sdk.constants.ConfigConstants#DEFAULT_STATUS_CHECK_START_SECONDS} the minimum value acceptable is {@link com.paytm.ecr.bluetooth.sdk.constants.ConfigConstants#MIN_STATUS_CHECK_START_SECONDS} |
4 | statusCheckIntervalSeconds | Integer | The interval at which the SDK will keep checking the status of the SALE transaction, in case {@link #statusCheckOnSaleRequestEnabled} is true default value is {@link com.paytm.ecr.bluetooth.sdk.constants.ConfigConstants#DEFAULT_STATUS_CHECK_INTERVAL_SECONDS} the minimum acceptable value is {@link com.paytm.ecr.bluetooth.sdk.constants.ConfigConstants#MIN_STATUS_CHECK_INTERVAL_SECONDS} |
/**
* If the statusCheckOnSaleRequestEnabled flag is true then the sdk will keep checking the status of the SALE
* transaction at regular interval(statusCheckIntervalSeconds) after initial delay of statusCheckStartSeconds and
* till saleRequestTimeoutSeconds.
* default value is false
*/
private final boolean statusCheckOnSaleRequestEnabled;
/**
* Timeout for the SALE request in case {@link #statusCheckOnSaleRequestEnabled} is true
* default value is default value is
* {@link com.paytm.ecr.bluetooth.sdk.constants.ConfigConstants#DEFAULT_SALE_REQUEST_TIMEOUT_IN_SECONDS}
* the minimum value acceptable is {@link com.paytm.ecr.bluetooth.sdk.constants.ConfigConstants#MIN_SALE_REQUEST_TIMEOUT_IN_SECONDS}
*/
private final int saleRequestTimeoutSeconds;
/**
* The initial delay after which the sdk will start checking the status of the SALE response , in case
* {@link #statusCheckOnSaleRequestEnabled} is true
* default value is {@link com.paytm.ecr.bluetooth.sdk.constants.ConfigConstants#DEFAULT_STATUS_CHECK_START_SECONDS}
* the minimum value acceptable is {@link com.paytm.ecr.bluetooth.sdk.constants.ConfigConstants#MIN_STATUS_CHECK_START_SECONDS}
*/
private final int statusCheckStartSeconds;
/**
* The interval at which the SDK will keep checking the status of the SALE transaction, in case
* {@link #statusCheckOnSaleRequestEnabled} is true
* default value is {@link com.paytm.ecr.bluetooth.sdk.constants.ConfigConstants#DEFAULT_STATUS_CHECK_INTERVAL_SECONDS}
* the minimum value acceptable is {@link com.paytm.ecr.bluetooth.sdk.constants.ConfigConstants#MIN_STATUS_CHECK_INTERVAL_SECONDS}
*/
private final int statusCheckIntervalSeconds;
Bluetooth ECR version 2 works with BT Connect App which takes care of the connection part. isClientAppAvailable() method is available in the library to find if BT Connect App is installed on the same device or not, programmatically.
If BT Connect App is not connected to any device, an error is returned for the same. Relevant messages can be shown to the user based on whether the app needs to be installed or the device connected.
Passing a unique requestId with every new API call is mandatory, as the SDK uses this requestId to manage the lifecycle of the request. A sample of the request can be seen below.
CancelRequest.Builder builder = new CancelRequest.Builder()
.setMerchantId(TextUtils.isEmpty(merchantId) ? null : merchantId)
.setOrderId(orderId);
CancelRequest cancelRequest = builder.build();
cancelRequestId = String.valueOf(System.currentTimeMillis());
Request<CancelRequest> request = Request.of(cancelRequest, cancelRequestId);
payments.doCancel(request, this);
Callbacks are available to receive responses to the requests sent. A sample of the same has been given below.
@Override
public void onResponse(Response<? extends BaseResponse> response) {
if (saleRequestId.equals(response.getRequestId())) {
handleSaleResponse(response);
} else if (statusCheckRequestId.equals(response.getRequestId())) {
handleStatusCheckResponse(response);
} else if (cancelRequestId.equals(response.getRequestId())) {
handleCancelResponse(response);
} else if (connectionCheckRequestId.equals(response.getRequestId())) {
handleConnectionCheckResponse(response);
} else if (printRequestId.equals(response.getRequestId())) {
handlePrintResponse(response);
} else if (voidRequestId.equals(response.getRequestId())) {
handleVoidResponse(response);
}
}
private void handleConnectionCheckResponse(Response<? extends BaseResponse> response) {
if (response.getStatus() == Response.Status.ERROR) {
// Check errorType and take action
Log.d(TAG, String.format("Error occurred in Connection Check request with requestId : %s, error : %s",
response.getRequestId(),
response.getError().getMsg()));
} else {
Log.d(TAG, "Paytm POS machine is connected and ready to communicate");
}
}