
Hi, everyone in this example I am sharing how to use a Pos payment machine in android. PIN PAD D180 MPOS BLUETOOTH SMART CARD is a payment machine, used for cash leas India. The PIN PAd D180 MPOS payment machine integration to Ezetap payments SDK can be integrated into both Android native and hybrid applications. Integrating the SDK will allow you to access Ezetap services in your application. SDK is available in aar
format. Integration myPOS-SDK-Android for Payment Machine integration in android
How to include payments-SDK in your android application.
- Copy the
aar
file, available in the latest version in release folder, intolibs
folder under your project directory. - Add the below line in dependencies of your
build.gradle
file in your application.
compile(name: 'ezetapandroidsdk_X', ext: 'aar') Note: 'X' in the 'ezetapandroidsdk_X' represents the version (ex: ezetapandroidsdk_2_0)
- Add the below line in repositories section of your
build.gradle
flatDir {
dirs 'libs'
}
- Add the below provider in your project’s
manifest
file under application tag.
<provider android:name="com.ezetap.sdk.EzetapFileProvider" android:authorities="${applicationId}.EzetapFileProvider" android:exported="false" android:grantUriPermissions="true" > <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" /> </provider>
- If you have set attribute “tools: node” in you manifest for your application node. Please set it as tools:node=”merge” as shown below, it is needed to merge all the elements from our manifest.
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
tools:node="merge"
android:supportsRtl="true" >
- Create a file with a name
provider_paths.xml
in yourProject / res / xml
folder and paste the following code:
<?xml version="1.0" encoding="utf-8"?> <paths xmlns:android="http://schemas.android.com/apk/res/android" > <files-path name="ezetap-download" /> <external-path name="ezetap-download" /> </paths>
Native Android integration mPos D180 Payment Machine
To integrate this API, you need to have a good grasp of Android app development. The Ezetap integration part involves setting up a project, importing a library and then actual coding with just a few lines of code.
Sample app mPos D180 Payment Machine Integration in android
There is a sample Android App inside the sample folder of the repository. You can use this project as a reference to integrate Ezetap SDK.
Follow the steps below to get the sample app working:
- Import the project as an Android Project in Android Studio.
- Clean & build the project.
- Run the
EzeNativeSampleActivity
on your Smartphone. EzeNativeSampleActivity.java
will be your point of reference for native Android SDK integration.
Full Setup For Integration In Android
Step 1: Start Android Studio
Step 2 : Seconds step to Create a New Project Project ClickOn ==> File ==> NEW ==> New Project.
Step 3: Copy the aar
file, available in the latest version in release folder, into libs
folder under your project directory.
Step 4: Add the below line in dependencies of your build.gradle
file in your application.
compile(name: 'ezetapandroidsdk_X', ext: 'aar') Note: 'X' in the 'ezetapandroidsdk_X' represents the version (ex: ezetapandroidsdk_2_0)
- Add the below line in repositories section of your
build.gradle
flatDir {
dirs 'libs'
}
Step 5: Add the below provider in your project’s manifest
file under application tag.
<provider android:name="com.ezetap.sdk.EzetapFileProvider" android:authorities="${applicationId}.EzetapFileProvider" android:exported="false" android:grantUriPermissions="true" > <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" /> </provider>
<uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
Step 6: After opening your java file and XML file and you can just copy the code and paste on your file and run your project.
activity_payment.XML
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@color/text" tools:context="in.rocareindia.com.rocareindiaems.CardPayment.Online_Payment"> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/text" android:padding="10dp" android:orientation="vertical"> <pl.droidsonroids.gif.GifImageView android:layout_width="match_parent" android:layout_height="200dp" android:layout_marginTop="10dp" android:src="@drawable/pos"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="0dp" android:padding="10dp" android:orientation="horizontal"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1.5" android:padding="10dp" android:textStyle="bold" android:text="Name "/> <TextView android:id="@+id/PayName" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:padding="10dp" android:textStyle="bold" android:text=""/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="0dp" android:padding="10dp" android:orientation="horizontal"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1.5" android:padding="10dp" android:textStyle="bold" android:text="OderId"/> <TextView android:id="@+id/PayOrderID" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:padding="10dp" android:textStyle="bold" android:text=""/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="0dp" android:padding="10dp" android:orientation="horizontal"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1.5" android:padding="10dp" android:textStyle="bold" android:text="Amount"/> <TextView android:id="@+id/PayAmounts" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:padding="10dp" android:textStyle="bold" android:text=""/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:orientation="horizontal"> <Button android:id="@+id/btnInitialize" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="15dp" android:layout_weight="1" android:background="@drawable/button" android:elevation="2dp" android:onClick="onClick" android:text="Initialize" android:textColor="@color/text" /> <Button android:id="@+id/btnPrepare" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="15dp" android:layout_weight="1" android:background="@drawable/button" android:elevation="2dp" android:onClick="onClick" android:text="Prepare Device" android:textColor="@color/text" /> </LinearLayout> <Button android:id="@+id/btnSale" android:layout_width="150dp" android:layout_height="wrap_content" android:layout_margin="20dp" android:background="@drawable/button" android:elevation="2dp" android:padding="10dp" android:layout_gravity="center" android:onClick="onClick" android:text="payment" android:textColor="@color/text" /> </LinearLayout> </ScrollView> </LinearLayout>
Step 7: Create a payment_payload_popu.xml XML file
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ScrollView android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white" android:orientation="vertical"> <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Order number" android:layout_marginTop="10dp" android:textColorHint="@color/colorPrimary"> <EditText android:id="@+id/order_number" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="" android:backgroundTint="@color/colorPrimary" android:textColor="@color/colorPrimary" android:imeOptions="actionNext" android:inputType="number" android:maxLines="1" android:singleLine="true"/> </android.support.design.widget.TextInputLayout> <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Payable amount" android:layout_marginTop="10dp" android:textColorHint="@color/colorPrimary"> <EditText android:id="@+id/payable_amount" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" android:hint="" android:backgroundTint="@color/colorPrimary" android:textColor="@color/colorPrimary" android:imeOptions="actionNext" android:inputType="numberDecimal" android:maxLines="1" android:singleLine="true"/> </android.support.design.widget.TextInputLayout> <EditText android:id="@+id/cashback_amount" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" android:hint="Enter cash back amount" android:visibility="gone" android:backgroundTint="@color/colorPrimary" android:textColor="@color/colorPrimary" android:imeOptions="actionNext" android:inputType="numberDecimal" android:maxLength="10" android:maxLines="1" android:singleLine="true"/> <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Enter customer name" android:layout_marginTop="10dp" android:textColorHint="@color/colorPrimary"> <EditText android:id="@+id/user_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" android:hint="Enter customer name" android:backgroundTint="@color/colorPrimary" android:textColor="@color/colorPrimary" android:imeOptions="actionNext" android:inputType="text" android:maxLines="1" android:singleLine="true"/> </android.support.design.widget.TextInputLayout> <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Enter customer mobile number" android:layout_marginTop="10dp" android:textColorHint="@color/colorPrimary"> <EditText android:id="@+id/user_mobile" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" android:hint="" android:backgroundTint="@color/colorPrimary" android:textColor="@color/colorPrimary" android:imeOptions="actionNext" android:inputType="number" android:maxLength="10" android:maxLines="1" android:singleLine="true"/> </android.support.design.widget.TextInputLayout> <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Enter customer email id" android:layout_marginTop="10dp" android:textColorHint="@color/colorPrimary"> <EditText android:id="@+id/user_email" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" android:hint="Enter customer email id" android:backgroundTint="@color/colorPrimary" android:textColor="@color/colorPrimary" android:imeOptions="actionDone" android:inputType="textEmailAddress" android:maxLines="1" android:singleLine="true"/> </android.support.design.widget.TextInputLayout> <EditText android:id="@+id/product_brand" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" android:hint="Enter Product Brand" android:backgroundTint="@color/colorPrimary" android:textColor="@color/colorPrimary" android:imeOptions="actionDone" android:inputType="text" android:maxLines="1" android:singleLine="true" android:text="" android:visibility="gone"/> <EditText android:id="@+id/product_sku" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" android:backgroundTint="@color/colorPrimary" android:textColor="@color/colorPrimary" android:hint="Enter Product SKU" android:imeOptions="actionDone" android:inputType="text" android:maxLines="1" android:singleLine="true" android:text="" android:visibility="gone"/> <EditText android:id="@+id/product_serial" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" android:hint="Enter Product Serial" android:backgroundTint="@color/colorPrimary" android:textColor="@color/colorPrimary" android:imeOptions="actionDone" android:inputType="text" android:maxLines="1" android:singleLine="true" android:visibility="gone"/> <EditText android:id="@+id/acc_lab" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" android:hint="Enter Account Label" android:backgroundTint="@color/colorPrimary" android:visibility="gone" android:textColor="@color/colorPrimary" android:imeOptions="actionDone" android:inputType="textEmailAddress" android:maxLines="1" android:singleLine="true"/> <EditText android:id="@+id/serv_fee" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" android:hint="Enter service fee amount" android:backgroundTint="@color/colorPrimary" android:visibility="gone" android:textColor="@color/colorPrimary" android:imeOptions="actionDone" android:inputType="numberDecimal" android:maxLines="1" android:singleLine="true"/> <EditText android:id="@+id/pay_by" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" android:hint="Enter payment by" android:backgroundTint="@color/colorPrimary" android:textColor="@color/colorPrimary" android:visibility="gone" android:imeOptions="actionDone" android:inputType="textEmailAddress" android:maxLines="1" android:singleLine="true"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/cancel_button" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:layout_alignParentBottom="true" android:padding="16dp" android:background="@android:color/transparent" android:text="Cancel" android:textAllCaps="false" android:textColor="@android:color/black"/> <Button android:id="@+id/confirm_button" style="android:buttonStyle" android:textStyle="bold" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:padding="16dp" android:background="@android:color/transparent" android:text="Ok" android:textColor="@android:color/black"/> </LinearLayout> </LinearLayout> </ScrollView> </LinearLayout>
Step 8: Open your Main Java File and add this code.
public class Online_Payment extends AppCompatActivity implements View.OnClickListener { /** * The response is sent back to your activity with a result code and request * code based */ private final int REQUEST_CODE_INITIALIZE = 10001; private final int REQUEST_CODE_PREPARE = 10002; private final int REQUEST_CODE_WALLET_TXN = 10003; private final int REQUEST_CODE_CHEQUE_TXN = 10004; private final int REQUEST_CODE_SALE_TXN = 10006; private final int REQUEST_CODE_CASH_BACK_TXN = 10007; private final int REQUEST_CODE_CASH_AT_POS_TXN = 10008; private final int REQUEST_CODE_CASH_TXN = 10009; private final int REQUEST_CODE_SEARCH = 10010; private final int REQUEST_CODE_VOID = 10011; private final int REQUEST_CODE_ATTACH_SIGN = 10012; private final int REQUEST_CODE_UPDATE = 10013; private final int REQUEST_CODE_CLOSE = 10014; private final int REQUEST_CODE_GET_TXN_DETAIL = 10015; private final int REQUEST_CODE_GET_INCOMPLETE_TXN = 10016; private final int REQUEST_CODE_PAY = 10017; private final int REQUEST_CODE_UPI = 10018; private final int REQUEST_CODE_REMOTE_PAY = 10019; private final int REQUEST_CODE_QR_CODE_PAY = 10020; private final int REQUEST_CODE_NORMAL_EMI = 10021; private final int REQUEST_CODE_BRAND_EMI = 10022; private final int REQUEST_CODE_PRINT_RECEIPT = 10021; private final int REQUEST_CODE_PRINT_BITMAP = 10022; /** * The Base64 Image bitmap string for attach e-signature */ private ImageView img; /** * unique ID for a transaction in EzeTap EMI Id associated with the * transaction */ private String strTxnId = null, emiID = null; /** * Error message */ private String mandatoryErrMsg = "Please fill up mandatory params."; String Name,amount,Invoice,LeadsId; public static String EMAIL; TextView PayAmounts,PayOrderID,PayName; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_online__payment); Name=getIntent().getStringExtra("name"); amount=getIntent().getStringExtra("final_total"); Invoice=getIntent().getStringExtra("Invoce"); LeadsId=getIntent().getStringExtra("lead"); PayAmounts=(TextView)findViewById(R.id.PayAmounts); PayAmounts.setText(amount); PayOrderID=(TextView)findViewById(R.id.PayOrderID); PayOrderID.setText(LeadsId); PayName=(TextView)findViewById(R.id.PayName); PayName.setText(Name); SessionManagement sessionManagement =new SessionManagement(); Boolean checkLogin = sessionManagement.getLogin(this); EMAIL = sessionManagement.getSavedEmail(this); if (!checkLogin){ Intent intent = new Intent(this,LogIn.class); startActivity(intent); } loadConfigFromPrefs(); } private void loadConfigFromPrefs() { String merchant = Setting.getPrefs(MERCHANT_NAME, this); String apikey = Setting.getPrefs(API_KEY, this); String username = Setting.getPrefs(USER_NAME, this); String mode = Setting.getPrefs(APP_MODE, this); EzeConstants.AppMode appMode = EzeConstants.AppMode.EZETAP_DEMO; if(mode != null && mode.trim().length() > 0) { } if(merchant!= null && apikey!= null&& mode!= null&& username!= null) { Setting.config = new Setting.ConfigHolder(apikey, mode, username, merchant); } } @Override public void onClick(View view) { switch (view.getId()) { case R.id.btnInitialize: doInitializeEzeTap(); break; case R.id.btnPrepare: doPrepareDeviceEzeTap(); break; case R.id.btnSale: openPaymentPayloadPopup(REQUEST_CODE_SALE_TXN); break; default: break; } } /** * invoke to initialize the SDK with the merchant key and the device (card * reader) with bank keys */ private void doInitializeEzeTap() { /********************************************** { "demoAppKey": "your demo app key", "prodAppKey": "your prod app key", "merchantName": "your merchant name", "userName": "your user name", "currencyCode": "INR", "appMode": "DEMO/PROD", "captureSignature": "true/false", "prepareDevice": "true/false" } **********************************************/ JSONObject jsonRequest = new JSONObject(); if(Setting.config != null) { try { jsonRequest.put("demoAppKey", Setting.config.getAppKey()); jsonRequest.put("prodAppKey", Setting.config.getAppKey()); jsonRequest.put("merchantName", Setting.config.getMerchantName()); jsonRequest.put("userName", Setting.config.getUsername()); jsonRequest.put("currencyCode", "INR"); jsonRequest.put("appMode", Setting.config.getAppMode()); jsonRequest.put("captureSignature", "true"); jsonRequest.put("prepareDevice", "false"); } catch (JSONException e) { e.printStackTrace(); } } else { try { jsonRequest.put("demoAppKey", "*********************************"); jsonRequest.put("prodAppKey", "*********************************"); jsonRequest.put("merchantName", "********"); jsonRequest.put("userName",EMAIL); jsonRequest.put("currencyCode", "INR"); jsonRequest.put("appMode", "Demo"); jsonRequest.put("captureSignature", "true"); jsonRequest.put("prepareDevice", "false"); } catch (JSONException e) { e.printStackTrace(); } } EzeAPI.initialize(this, REQUEST_CODE_INITIALIZE, jsonRequest); } /** * optional mechanism to prepare a device for card transactions */ private void doPrepareDeviceEzeTap() { EzeAPI.prepareDevice(this, REQUEST_CODE_PREPARE); } /** * Ability to take wallet transaction for Mobiquick, Freecharge, Novopay * etc. */ private void doWalletTxn(JSONObject jsonRequest) { /******************************************* { "amount": "123", "options": { "references": { "reference1": "1234", "additionalReferences": [ "addRef_xx1", "addRef_xx2" ] }, "customer": { "name": "xyz", "mobileNo": "1234567890", "email": "abc@xyz.com" } } } *******************************************/ EzeAPI.walletTransaction(Online_Payment.this, REQUEST_CODE_WALLET_TXN, jsonRequest); } /** * Records cheque transaction */ private void doChequeTxn(JSONObject jsonRequest) { /***************************************** { "amount": "123", "options": { "references": { "reference1": "1234", "additionalReferences": [ "addRef_xx1", "addRef_xx2" ] }, "customer": { "name": "xyz", "mobileNo": "1234567890", "email": "abc@xyz.com" } }, "cheque": { "chequeNumber": "1234", "bankCode": "1234", "bankName": "xyz", "bankAccountNo": "1234", "chequeDate": "YYYY-MM-DD" } } *****************************************/ EzeAPI.chequeTransaction(this, REQUEST_CODE_CHEQUE_TXN, jsonRequest); } /** * Take credit card transactions for Visa, Mastercard and Rupay. Debit card * transactions for Indian banks. Ability to perform EMI option. */ private void doSaleTxn(JSONObject jsonRequest) { /****************************************** { "amount": "123", "options": { "amountCashback": 0, "amountTip": 0, "references": { "reference1": "1234", "additionalReferences": [ "addRef_xx1", "addRef_xx2" ] }, "customer": { "name": "xyz", "mobileNo": "1234567890", "email": "abc@xyz.com" } }, "mode": "SALE" } ******************************************/ EzeAPI.cardTransaction(this, REQUEST_CODE_SALE_TXN, jsonRequest); } private void doNormalEMITxn(JSONObject jsonRequest) { /****************************************** { "amount": "123", "options": { "amountCashback": 0, "amountTip": 0, "references": { "reference1": "1234", "additionalReferences": [ "addRef_xx1", "addRef_xx2" ] }, "customer": { "name": "xyz", "mobileNo": "1234567890", "email": "abc@xyz.com" } } } ******************************************/ EzeAPI.normalEMITransaction(this, REQUEST_CODE_NORMAL_EMI, jsonRequest); } private void doBrandEMITxn(JSONObject jsonRequest) { /****************************************** { "amount": "123", "options": { "amountCashback": 0, "amountTip": 0, "references": { "reference1": "1234", "additionalReferences": [ "addRef_xx1", "addRef_xx2" ] }, "customer": { "name": "xyz", "mobileNo": "1234567890", "email": "abc@xyz.com" }, "productDetails": { "brand": "NOKIA", "SKUCode": "Nokia6MB", "serial": "1233442323131331" } } } ******************************************/ EzeAPI.brandEMITransaction(this, REQUEST_CODE_BRAND_EMI, jsonRequest); } /** * Take credit card transactions for Visa, Mastercard and Rupay. Debit card * transactions for Indian banks. Ability to perform cashback option. */ private void doCashbackTxn(JSONObject jsonRequest) { /****************************************** { "amount": "123", "options": { "amountCashback": 100, "amountTip": 0, "references": { "reference1": "1234", "additionalReferences": [ "addRef_xx1", "addRef_xx2" ] }, "customer": { "name": "xyz", "mobileNo": "1234567890", "email": "abc@xyz.com" } }, "mode": "CASHBACK" } ******************************************/ EzeAPI.cardTransaction(this, REQUEST_CODE_CASH_BACK_TXN, jsonRequest); } /** * Take credit card transactions for Visa, Mastercard and Rupay. Debit card * transactions for Indian banks. Ability to perform cash@pos option. */ private void doCashAtPosTxn(JSONObject jsonRequest) { /****************************************** { "amount": "0", "options": { "amountCashback": 100, "amountTip": 0, "references": { "reference1": "1234", "additionalReferences": [ "addRef_xx1", "addRef_xx2" ] }, "customer": { "name": "xyz", "mobileNo": "1234567890", "email": "abc@xyz.com" } }, "mode": "CASH@POS" } ******************************************/ EzeAPI.cardTransaction(this, REQUEST_CODE_CASH_AT_POS_TXN, jsonRequest); } /** * Ability to record cash transaction */ private void doCashTxn(JSONObject jsonRequest) { /****************************************** { "amount": "123", "options": { "references": { "reference1": "1234", "additionalReferences": [ "addRef_xx1", "addRef_xx2" ] }, "customer": { "name": "xyz", "mobileNo": "1234567890", "email": "abc@xyz.com" } } } ******************************************/ EzeAPI.cashTransaction(this, REQUEST_CODE_CASH_TXN, jsonRequest); } /** * Ability to perform upi transaction */ private void doUPITxn(JSONObject jsonRequest) { /****************************************** { "amount": "123", "options": { "references": { "reference1": "1234", "additionalReferences": [ "addRef_xx1", "addRef_xx2" ] }, "customer": { "name": "xyz", "mobileNo": "1234567890", "email": "abc@xyz.com" } } } ******************************************/ EzeAPI.upiTransaction(this, REQUEST_CODE_UPI, jsonRequest); } private void doPay(JSONObject jsonRequest) { /****************************************** { "amount": "123", "options": { "references": { "reference1": "1234", "additionalReferences": [ "addRef_xx1", "addRef_xx2" ] }, "customer": { "name": "xyz", "mobileNo": "1234567890", "email": "abc@xyz.com" } } } ******************************************/ EzeAPI.pay(this, REQUEST_CODE_PAY, jsonRequest); } /** * Ability to perform upi transaction */ private void doRemotePayTxn(JSONObject jsonRequest) { /****************************************** { "amount": "123", "options": { "references": { "reference1": "1234", "additionalReferences": [ "addRef_xx1", "addRef_xx2" ] }, "customer": { "name": "xyz", "mobileNo": "1234567890", "email": "abc@xyz.com" } } } ******************************************/ EzeAPI.remotePayment(this, REQUEST_CODE_REMOTE_PAY, jsonRequest); } /** * Ability to perform upi transaction */ private void doQrCodePayTxn(JSONObject jsonRequest) { /****************************************** { "amount": "123", "options": { "references": { "reference1": "1234", "additionalReferences": [ "addRef_xx1", "addRef_xx2" ] }, "customer": { "name": "xyz", "mobileNo": "1234567890", "email": "abc@xyz.com" } } } ******************************************/ EzeAPI.qrCodeTransaction(this, REQUEST_CODE_QR_CODE_PAY, jsonRequest); } /** * search transactions for a merchant based on certain search parameters */ private void doSearchTxn() { /********************************* { "agentName": "Demo User" } *********************************/ JSONObject jsonRequest = new JSONObject(); try { jsonRequest.put("agentName", "Enter your user name"); EzeAPI.searchTransaction(this, REQUEST_CODE_SEARCH, jsonRequest); } catch (JSONException e) { e.printStackTrace(); } } /** * Void transaction method is invoked to void a payment transaction */ private void doVoidTxn() { if (isTransactionIdValid()) { EzeAPI.voidTransaction(this, REQUEST_CODE_VOID, strTxnId);// pass your transaction id value here } else displayToast("Inorrect txn Id, please make a Txn."); } /** * @param bitmap * @return */ public String getEncoded64ImageStringFromBitmap(Bitmap bitmap) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 70, stream); byte[] byteFormat = stream.toByteArray(); return Base64.encodeToString(byteFormat, Base64.NO_WRAP); } /** * Use this operation to attach an e-signature from the customer for * payments */ private void doAttachSignature() { /******************************************* { "tipAmount": 0, "image": { "imageData": "js9bsidvicbi3h", "imageType": "JPEG", "height": "", "weight": "" }, "txnId": "12355356345" } *******************************************/ JSONObject jsonRequest = new JSONObject(); JSONObject jsonImageObj = new JSONObject(); try { img.buildDrawingCache(); Bitmap bmap = img.getDrawingCache(); String encodedImageData = getEncoded64ImageStringFromBitmap(bmap); // Building Image Object jsonImageObj.put("imageData", encodedImageData); jsonImageObj.put("imageType", "JPEG"); jsonImageObj.put("height", "");// optional jsonImageObj.put("weight", "");// optional // Building final request object // jsonRequest.put("emiId", emiID);// pass this field if you have an // EMI Id associated with the transaction jsonRequest.put("tipAmount", 0.00);// optional jsonRequest.put("image", jsonImageObj); // Pass this attribute when you have a valid captured signature image jsonRequest.put("txnId", strTxnId);// pass your transaction id value here if (strTxnId != null) { EzeAPI.attachSignature(this, REQUEST_CODE_ATTACH_SIGN, jsonRequest); } else { displayToast("Inorrect txn Id, please pass txnId"); } } catch (JSONException e) { e.printStackTrace(); } } /** * Check For Updates method is only relevant in the Android platform. It is * invoked to check for any updates to the Android Service app. */ private void doCheckUpdate() { EzeAPI.checkForUpdates(this, REQUEST_CODE_UPDATE); } /** * use this method to check the status of an incomplete transaction due to * timeouts, network errors etc. */ private void doCheckIncompleteTxn() { EzeAPI.checkForIncompleteTransaction(this, REQUEST_CODE_GET_INCOMPLETE_TXN); } /** * Retrieve the details of a transaction given a transaction Id */ private void doGetTxnDetails() { if (!strTxnId.equals(null)) { EzeAPI.getTransaction(this, REQUEST_CODE_GET_TXN_DETAIL, strTxnId);// pass your reference id value here } else { displayToast("Inorrect txn Id, please pass txnId"); } } /** * closes the connection with Ezetap server and shut down gracefully */ private void doCloseEzetap() { EzeAPI.close(this, REQUEST_CODE_CLOSE); } /** * @param message * message for Toast */ private void displayToast(String message) { Toast.makeText(this, message, Toast.LENGTH_LONG).show(); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); Log.d("SampleAppLogs", "requestCode = " + requestCode + "resultCode = " + resultCode); try { if (intent != null && intent.hasExtra("response")) { Log.d("SampleAppLogs", intent.getStringExtra("response")); Toast.makeText(this, intent.getStringExtra("response"), Toast.LENGTH_LONG).show(); } switch (requestCode) { case REQUEST_CODE_UPI: case REQUEST_CODE_CASH_TXN: case REQUEST_CODE_CASH_BACK_TXN: case REQUEST_CODE_CASH_AT_POS_TXN: case REQUEST_CODE_WALLET_TXN: case REQUEST_CODE_SALE_TXN: if (resultCode == RESULT_OK) { JSONObject response = new JSONObject(intent.getStringExtra("response")); response = response.getJSONObject("result"); response = response.getJSONObject("txn"); strTxnId = response.getString("txnId"); emiID = response.getString("emiId"); if(strTxnId.equals("")||strTxnId.equals(null)){ Toast.makeText(this, intent.getStringExtra("response"), Toast.LENGTH_LONG).show(); }else { Intent intent1=new Intent(Online_Payment.this,SubmitPayment.class); intent1.putExtra("response",intent.getStringExtra("response")); intent1.putExtra("LeadsId",LeadsId); startActivity(intent1); finish(); } // } else if (resultCode == RESULT_CANCELED) { JSONObject response = new JSONObject(intent.getStringExtra("response")); response = response.getJSONObject("error"); String errorCode = response.getString("code"); String errorMessage = response.getString("message"); } break; case REQUEST_CODE_PREPARE: if (resultCode == RESULT_OK) { JSONObject response = new JSONObject(intent.getStringExtra("response")); response = response.getJSONObject("result"); } else if (resultCode == RESULT_CANCELED) { JSONObject response = new JSONObject(intent.getStringExtra("response")); response = response.getJSONObject("error"); String errorCode = response.getString("code"); String errorMessage = response.getString("message"); } break; default: break; } } catch (Exception e) { e.printStackTrace(); } } /** * @return transaction id is valid */ private boolean isTransactionIdValid() { if (strTxnId == null) return false; else return true; } private void openPaymentPayloadPopup(final int REQUEST_CODE) { try { LayoutInflater layoutInflater = LayoutInflater.from(Online_Payment.this); final View customView = layoutInflater.inflate(R.layout.payment_payload_popup, null); AlertDialog.Builder editCustomerPopup = new AlertDialog.Builder(Online_Payment.this); editCustomerPopup.setCancelable(false); editCustomerPopup.setView(customView); final AlertDialog alertDialog = editCustomerPopup.create(); alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); alertDialog.show(); Button cancelButton = (Button) customView.findViewById(R.id.cancel_button); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.cancel(); } }); final EditText customerNameEditText = (EditText) customView.findViewById(R.id.user_name); customerNameEditText.setText(Name); final EditText emailIdEditText = (EditText) customView.findViewById(R.id.user_email); final EditText mobileNumberEditText = (EditText) customView.findViewById(R.id.user_mobile); final EditText orderNumberEditText = (EditText) customView.findViewById(R.id.order_number); orderNumberEditText.setText(LeadsId); orderNumberEditText.setInputType(InputType.TYPE_NULL); final EditText payableAmountEditText = (EditText) customView.findViewById(R.id.payable_amount); payableAmountEditText.setText(amount); // payableAmountEditText.setInputType(InputType.TYPE_NULL); final EditText cashBackAmountEditText = (EditText) customView.findViewById(R.id.cashback_amount); final EditText productBrandEditText = (EditText) customView.findViewById(R.id.product_brand); final EditText productCodeEditText = (EditText) customView.findViewById(R.id.product_sku); final EditText productSerialEditText = (EditText) customView.findViewById(R.id.product_serial); final EditText accountLabelEditTet = (EditText) customView.findViewById(R.id.acc_lab); final EditText serviceFeeEditText = (EditText) customView.findViewById(R.id.serv_fee); final EditText paymentByEditText = (EditText) customView.findViewById(R.id.pay_by); if (REQUEST_CODE == REQUEST_CODE_CASH_BACK_TXN || REQUEST_CODE == REQUEST_CODE_CASH_AT_POS_TXN) { serviceFeeEditText.setVisibility(View.GONE); paymentByEditText.setVisibility(View.GONE); accountLabelEditTet.setVisibility(View.GONE); } if (REQUEST_CODE == REQUEST_CODE_CASH_AT_POS_TXN) { payableAmountEditText.setVisibility(View.GONE); } if(REQUEST_CODE == REQUEST_CODE_BRAND_EMI || REQUEST_CODE == REQUEST_CODE_PAY) { productBrandEditText.setVisibility(View.VISIBLE); productCodeEditText.setVisibility(View.VISIBLE); productSerialEditText.setVisibility(View.VISIBLE); cashBackAmountEditText.setVisibility(View.GONE); } Button confirmButton = (Button) customView.findViewById(R.id.confirm_button); confirmButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (orderNumberEditText.getText().toString().equalsIgnoreCase("") || payableAmountEditText.getText().toString().equalsIgnoreCase("") && (REQUEST_CODE != REQUEST_CODE_CASH_AT_POS_TXN)) { displayToast(mandatoryErrMsg); return; } try { JSONObject jsonRequest = new JSONObject(); JSONObject jsonOptionalParams = new JSONObject(); JSONObject jsonReferences = new JSONObject(); JSONObject jsonCustomer = new JSONObject(); // Building Customer Object jsonCustomer.put("name", customerNameEditText.getText().toString().trim()); jsonCustomer.put("mobileNo", mobileNumberEditText.getText().toString().trim()); jsonCustomer.put("email", emailIdEditText.getText().toString().trim()); // Building References Object jsonReferences.put("reference1", orderNumberEditText.getText().toString().trim()); jsonReferences.put("reference2", Invoice); jsonReferences.put("reference3",EMAIL) ; // Passing Additional References JSONArray array = new JSONArray(); array.put("addRef_xx1"); array.put("addRef_xx2"); jsonReferences.put("additionalReferences", array); // Building Optional params Object jsonOptionalParams.put("amountCashback", cashBackAmountEditText.getText().toString() + "");// Cannot // have // amount cashback in SALE transaction. jsonOptionalParams.put("amountTip", 0.00); jsonOptionalParams.put("references", jsonReferences); jsonOptionalParams.put("customer", jsonCustomer); // Service Fee double serviceFee = -1.0; String paymentBy = null; if (serviceFeeEditText.getText().toString().length() > 0) { serviceFee = Double.parseDouble(serviceFeeEditText.getText().toString()); } if (paymentByEditText.getText().toString().length() > 0) { paymentBy = paymentByEditText.getText().toString(); } jsonOptionalParams.put("serviceFee", serviceFee); jsonOptionalParams.put("paymentBy", paymentBy); // Pay to Account String accountLabel = null; if (accountLabelEditTet.getText().toString().length() > 0) { accountLabel = accountLabelEditTet.getText().toString(); } jsonOptionalParams.put("payToAccount", accountLabel); if(REQUEST_CODE == REQUEST_CODE_BRAND_EMI || REQUEST_CODE == REQUEST_CODE_PAY) { JSONObject brandDetails = new JSONObject(); brandDetails.put("SKUCode", productCodeEditText.getText().toString().trim()); brandDetails.put("brand", productBrandEditText.getText().toString().trim()); brandDetails.put("serial", productSerialEditText.getText().toString().trim()); jsonOptionalParams.put("productDetails", brandDetails); } JSONObject addlData = new JSONObject(); addlData.put("addl1", "addl1"); addlData.put("addl2", "addl2"); addlData.put("addl3", "addl3"); jsonOptionalParams.put("addlData", addlData); JSONObject appData = new JSONObject(); appData.put("app1", "app1"); appData.put("app2", "app2"); appData.put("app3", "app3"); jsonOptionalParams.put("appData", appData); // Building final request object jsonRequest.put("amount", payableAmountEditText.getText().toString().trim()); jsonRequest.put("options", jsonOptionalParams); InputMethodManager imm = (InputMethodManager) Online_Payment.this .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(emailIdEditText.getWindowToken(), 0); switch (REQUEST_CODE) { case REQUEST_CODE_WALLET_TXN: doWalletTxn(jsonRequest); break; case REQUEST_CODE_CHEQUE_TXN: // Building Cheque Object JSONObject jsonCheque = new JSONObject(); jsonCheque.put("chequeNumber", "125441"); jsonCheque.put("bankCode", "TEST0001233"); jsonCheque.put("bankName", "TEST Bank"); jsonCheque.put("bankAccountNo", "1234567890"); jsonCheque.put("chequeDate", "2017-12-10"); jsonRequest.put("cheque", jsonCheque); doChequeTxn(jsonRequest); break; case REQUEST_CODE_SALE_TXN: jsonRequest.put("mode", "SALE");//Card payment Mode doSaleTxn(jsonRequest); break; case REQUEST_CODE_CASH_BACK_TXN: jsonRequest.put("mode", "CASHBACK");//Card payment Mode doCashbackTxn(jsonRequest); break; case REQUEST_CODE_CASH_AT_POS_TXN: jsonRequest.put("mode", "CASH@POS");//Card payment Mode doCashAtPosTxn(jsonRequest); break; case REQUEST_CODE_CASH_TXN: doCashTxn(jsonRequest); break; case REQUEST_CODE_PAY: doPay(jsonRequest); break; case REQUEST_CODE_UPI: doUPITxn(jsonRequest); break; case REQUEST_CODE_REMOTE_PAY: doRemotePayTxn(jsonRequest); break; case REQUEST_CODE_QR_CODE_PAY: doQrCodePayTxn(jsonRequest); break; case REQUEST_CODE_NORMAL_EMI: doNormalEMITxn(jsonRequest); break; case REQUEST_CODE_BRAND_EMI: doBrandEMITxn(jsonRequest); break; } alertDialog.cancel(); } catch (Exception e) { e.printStackTrace(); } } }); alertDialog.show(); } catch (Exception e) { e.printStackTrace(); } } /** * Print Receipt method is invoked to print receipt for a payment transaction */ private void printReceipt() { if (isTransactionIdValid()) { EzeAPI.printReceipt(this, REQUEST_CODE_PRINT_RECEIPT, strTxnId);// pass your transaction id value here } else { displayToast("Inorrect txn Id, please make a Txn."); } } /** * Use this operation to print a bitmap image */ private void printBitmap() { /******************************************* { "image": { "imageData": "js9bsidvicbi3h", "imageType": "JPEG", "height": "", "weight": "" } } ******************************************/ JSONObject jsonRequest = new JSONObject(); JSONObject jsonImageObj = new JSONObject(); try { img.buildDrawingCache(); Bitmap bmap = img.getDrawingCache(); String encodedImageData = getEncoded64ImageStringFromBitmap(bmap); // Building Image Object jsonImageObj.put("imageData", encodedImageData); jsonImageObj.put("imageType", "JPEG"); jsonImageObj.put("height", "");// optional jsonImageObj.put("weight", "");// optional jsonRequest.put("image", jsonImageObj); // Pass this attribute when you have a valid captured signature image EzeAPI.printBitmap(this, REQUEST_CODE_PRINT_BITMAP, jsonRequest); } catch (JSONException e) { e.printStackTrace(); } } @Override public void onBackPressed() { super.onBackPressed(); finish(); } }