Lightweight library to implement the iPay Checkout mechanism within an Android App.
To use the iPay SDK in a project, simply add the dependency to your build.gradle or you can download and add Android Archive Library(AAR) file to your libs folder.
Important: If you're adding the SDK to an existing project, start at step 3.
implementation "bd.com.ipay.sdk:sdk-android:1.0.5"
If your project using kotlin and development language then add the following line to the dependencies{ } section.
implementation "bd.com.ipay.sdk:sdk-android-ktx:1.0.5"
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
Important: If your project compile SDK version is below 28 then add the following lines
configurations.all {
resolutionStrategy {
force "com.android.support:support-compat:$targetSupportLibraryVersion"
force "com.android.support:support-annotations:$targetSupportLibraryVersion"
}
}
Create strings for your callback url scheme and for those needed to receive checkout status result in a New Activity add the CallbackActivityName to your AndroidManifest.xml. Also you can enable/disable SDK initialize logs.
Important: Create a callback url scheme from iPay app. Please contact with us in order to create this url scheme.
<string name="ipay_callback_url_scheme" translatable="false">YOUR_CALLBACK_CODE_FROM_IPAY_APP</string>
<application>
<!-- Optional metadata field. If you want to get callback to a new activity,
then add the following like where the value will be the name of the callback activity
you want to open.-->
<meta-data
android:name="bd.com.ipay.sdk.CallbackActivityName"
android:value="bd.com.ipay.activity.IPayCheckoutCallBackActivity" />
<!-- Optional metadata field. If you don't want to print anything in the log,
use false as value.-->
<meta-data
android:name="com.facebook.sdk.AutoLogAppEventsEnabled"
android:value="true" />
<!-- Optional metadata field. update the value field by your own choice.
Use this value to receive request result from onActivityResult-->
<meta-data
android:name="bd.com.ipay.sdk.CallbackRequestCode"
android:value="1234" />
</application>
Follow the iPay Payment Gateway API guide for merchants(Version 1.2.1) to create an paymentUrl
. Use this paymentUrl
to perform checkout through your android application.
The simplest way to perform iPay checkout through iPay Android app from your app is to add the following lines of code.
// sample java checkout code.
public void iPayCheckoutPayment(Activity activity, String paymentUrl) {
final CheckoutState checkoutState = IPaySDK.performCheckout(activity, paymentUrl);
}
// sample kotlin checkout code.
fun iPayCheckoutPayment(paymentUrl : String) {
val checkoutState = performCheckout(paymentUrl)
}
In case of iPay android isn’t present, it will open play store to download the iPay app. Also you will the checkout result on onActivityResult
If you are willing to receive result in a new activity, use the following lines of code.
// sample java checkout code.
private final boolean SHOULD_THROW_ERROR_WHILE_PERFORMING_CHECKOUT = true;
private final boolean SHOULD_RECEIVE_RESULT_ON_NEW_ACTIVITY = true;
public void iPayCheckoutPayment(Activity activity, String paymentUrl) {
try {
final CheckoutState checkoutState = IPaySDK.performCheckout(activity, paymentUrl, SHOULD_THROW_ERROR_WHILE_PERFORMING_CHECKOUT,SHOULD_RECEIVE_RESULT_ON_NEW_ACTIVITY);
} catch(Exception e) {
// perform checkout failed exceptions
}
}
// sample kotlin checkout code.
const val SHOULD_THROW_ERROR_WHILE_PERFORMING_CHECKOUT = true
const val SHOULD_RECEIVE_RESULT_ON_NEW_ACTIVITY = true
fun iPayCheckoutPayment(paymentUrl : String) {
try {
val checkoutState = performCheckout(paymentUrl, SHOULD_THROW_ERROR_WHILE_PERFORMING_CHECKOUT, SHOULD_RECEIVE_RESULT_ON_NEW_ACTIVITY)
}catch(e: Exception) {
// perform checkout failed exceptions
}
}
On your onActivityResult
you will receive the CheckoutStatus and the checkoutId.
// sample java checkout code.
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
final int iPayCheckoutRequestCode = IPaySDK.getCheckoutRequestCode();
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case iPayCheckoutRequestCode:
switch (resultCode) {
case RESULT_OK:
if (data != null) {
final int checkoutId = data.getStringExtra(IPaySDK.CHECKOUT_ID_KEY);
final CheckoutStatus checkoutStatus = (CheckoutStatus) data.getSerializableExtra(IPaySDK.CHECKOUT_STATUS_KEY);
switch(checkoutStatus) {
case SUCCESS:
// call success callback url.
break;
case FAILED:
// call failed callback url.
break;
case CANCELLED:
// call cancelled callback url.
break;
}
}
break;
}
break;
}
}
// sample kotlin checkout code.
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
val iPayCheckoutRequestCode = IPaySDK.getCheckoutRequestCode()
when (requestCode) {
iPayCheckoutRequestCode -> {
when (resultCode) {
RESULT_OK -> {
if (data != null) {
val checkoutId = data.getStringExtra(IPaySDK.CHECKOUT_ID_KEY)
val checkoutStatus = data.getSerializableExtra(IPaySDK.CHECKOUT_STATUS_KEY) as CheckoutStatus
when(checkoutStatus) {
SUCCESS -> {
// call success callback url.
}
FAILED -> {
// call failed callback url.
}
CANCELLED -> {
// call cancelled callback url.
}
}
}
}
}
}
}
}
Important: You have to call the success/cancelled/failed callback api manually depending on the CheckoutStatus
If you are willing to receive result in a new activity, get checkoutStatus and checkoutId from intent.
// sample java checkout code.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(getIntent() != null) {
final int checkoutId = getIntent().getStringExtra(IPaySDK.CHECKOUT_ID_KEY);
final CheckoutStatus checkoutStatus = (CheckoutStatus) getIntent().getSerializableExtra(IPaySDK.CHECKOUT_STATUS_KEY);
switch(checkoutStatus) {
case SUCCESS:
// call success callback url.
break;
case FAILED:
// call failed callback url.
break;
case CANCELLED:
// call cancelled callback url.
break;
}
}
}
// sample kotlin checkout code.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val checkoutId = intent.getStringExtra(IPaySDK.CHECKOUT_ID_KEY)
val checkoutStatus = intent.getSerializableExtra(IPaySDK.CHECKOUT_STATUS_KEY) as CheckoutStatus
when(checkoutStatus) {
SUCCESS -> {
// call success callback url.
}
FAILED -> {
// call failed callback url.
}
CANCELLED ->{
// call cancelled callback url.
}
}
}