-
Notifications
You must be signed in to change notification settings - Fork 1
3. Android Payment SDK
API Level 15 and above
Import UnoPayPaymentSDKRelease1.0.2.aar module into your project: Follow below steps to import the aar file. In the Android studio Click on File->New->New Module. Now In the New Module screen select Import .JAR/.AAR Package and click Next. In the next screen locate the UnoPayPaymentSDKRelease1.0.2.aar file and click Finish.
Please add below dependencies in your app’s build.gradle
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.squareup.retrofit2:retrofit:2.0.0'
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
compile 'com.google.android.gms:play-services-location:8.1.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:design:23.1.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
compile project(':UnoPayPaymentSDKRelease1.0')
Add the below proguard rule in you custom proguard file.(Only add this if you are building your app with proguard enabled).
-keep class com.techjini.android.paymnetlibrary.activities.{*;} -keep class com.techjini.android.paymnetlibrary.constants.{*;} -keep class com.techjini.android.paymnetlibrary.UnoPayParams{ public ; } -keep class retrofit2.** { ; } -keepclasseswithmembers class com.techjini.android.paymnetlibrary.network.model.response.MasterWalletResponse,**{;} -keepattributes Annotation, InnerClasses, Signature
Make sure following permission are defined in your app’s AndroidManifest.xml
Create an object of UnoPayParams and set the parameters those are required for the transactions. Below are the parameters we need for the transaction ( * marked are mandatory).
- Partner Id : A unique id which UnoPay provides
- Merchant SDK Key: A unique key which UnoPay provides
- Order ID: The Unique Id that app should provide for their reference
- App Name: Pass the Application Name to the sdk
- Amount: Payable Amount Email: It is used to prefill the data while making the payment Mobile: User mobile number. Production: set true or false. False to point to UnoPay test server and true to point to UnoPay production server
Below is the sample code snippet for Initialization of Parameters
UnoPayParams unoPayParams = new UnoPayParams(); unoPayParams.setAmount(Double.valueOf(mAmountET.getText().toString())); unoPayParams.setAppName("Sample App"); unoPayParams.setEmail("[email protected]"); unoPayParams.setMobileNumber(Long.parseLong(mMobileNumberET.getText().toString())); unoPayParams.setPartnerId("b643f013cb9f3ccc9b44c0bd1ebbc669"); unoPayParams.setMerchantSdkKey("da35732a966ac2e96b99b5c640808ff0cdd4c18e"); unoPayParams.setName("Test"); unoPayParams.setOrderId(String.valueOf(System.currentTimeMillis())); unoPayParams.setProduction(false);
After the parameters initialization you are ready to initiate the payment. To Initiate the payment call the UnoPayPayment activity from your class. Sample code snippet to initiate the payment:
Intent payUsingUnoPayIntent = new Intent(MainActivity.this, UnoPayPayment.class);
//pass the UnoPayParams object populated with required params payUsingUnoPayIntent.putExtra(UnoPayPayment.PAYMENT_PARAMS, unoPayParams);
startActivityForResult(payUsingUnoPayIntent, 100); Callback from UnoPay Please note that all the payment status callbacks you will receive in onActivityResult() of your calling activity. So your Activity should call UnoPayPayment activity as given above.
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 100) { // The order id to payment is requested for String orderId = data.getStringExtra("ORDER_ID"); // complete payment result String result = data.getStringExtra("RESULT"); } }
Status codes: 0 - SUCCESS 1 - FAILED 2 - CANCELED
For Canceled transaction : Cancelled by the user
{"status":2,"error":{"message":"User canceled the transaction","code":6}}
For Success transaction:
{"status":0,"data":{"message":"Transaction successfull","transactionId":"abc-122324345454","requestedAmount","1.0","merchantAmount","1.0"},"error":null}
For Failed transaction
{"status":1,"error":{"message":"Transaction failed due to insufficient fund","code":8}}