In this blog, we will learn about how to implement DotPay Payment gateway integration in android with SDK approach.
Before starting integration first, we need to know what a payment gateway is.
A payment gateway is a merchant service provided by an e-commerce application service provider. Which authorizes card or direct payment processing.
DotPay payment gateway provides quick and secure online transactions with various payment options like Credit Card, e-Wallets, and many others.
If you are planing on the integration of the DotPay payment gateway by using SDK then this blog will help you to do so.
Implementation
1. Initial setup
Adding SDK dependencies in your Application
- Add below SDK dependency and maven repository in your project-level build.gradle file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
dependencies { //Dotpay classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' } allprojects { repositories { google() jcenter() maven { url 'https://github.com/dotpay/Mobile-SDK-Android/raw/master/' } flatDir { dirs 'libs' } } } |
- Secondly, add the below dependencies in your app-level build file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
implementation('pl.mobiltek.paymentsmobile:dotpay:1.4.22@aar') { transitive = true } implementation project(':visacheckout-android-sdk-6.6.1') implementation 'com.google.dagger:dagger:2.6.1' annotationProcessor 'com.google.dagger:dagger-compiler:2.6.1' compileOnly 'javax.annotation:jsr250-api:1.0' implementation 'com.squareup.retrofit:retrofit:1.9.0' implementation 'com.squareup.okhttp:okhttp:2.4.0' implementation 'com.squareup.okhttp:okhttp-urlconnection:2.4.0' implementation 'com.squareup.picasso:picasso:2.5.2' implementation 'de.greenrobot:eventbus:2.2.0' implementation 'com.j256.ormlite:ormlite-core:4.47' |
2. Initialize payment
PaymentManager class of DotPay SDK is used to initialize payment. So you have to call the initialize() like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
fun processPayment() { PaymentManager.getInstance().initialize(this, getPaymentInformation()) } @NonNull private fun getPaymentInformation(): PaymentInformation? { val paymentInformation = PaymentInformation("your merchantId", "amount to pay", "description", "currency code") val sender: MutableMap<String, String> = HashMap() sender["firstname"] = "Customer first name" sender["lastname"] = "Customer last name" sender["email"] = "Customer email address" paymentInformation.senderInformation = sender return paymentInformation } |
Inside merchant Id field add valid key only because if you pass invalid key here payment UI will not initialize. And along with this also add the amount, description, and currency code also.
3. Handling payment callback:
It’s time to handle the payment callback. For this, implement the PaymentManagerCallback listener as :
1 2 3 4 5 6 |
class CheckoutActivity : BaseActivity(), PaymentManagerCallback { override fun onCreate(savedInstanceState: Bundle?) { PaymentManager.getInstance().setPaymentManagerCallback(this) PaymentManager.getInstance().applicationVersion = Configuration.RELEASE_VERSION } } |
For success and failure, we have to override onPaymentSuccess() and onPaymentFailure() inside our activity. which will help you to handle the success and failure result.
1 2 3 4 5 6 |
override fun onPaymentSuccess(p0: PaymentEndedEventArgs?) { //Handle Success case } override fun onPaymentFailure(p0: PaymentEndedEventArgs?) { //Handle Failure case } |
We have done with the DotPay payment gateway integration. Add below lines in proguard-rules for final release:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
-keep class de.greenrobot.event.SubscriberMethodFinder { *; } -keep class de.greenrobot.event.EventBus { *; } -keep class de.greenrobot.event.* { *; } -keep class pl.mobiltek.paymentsmobile.dotpay.fragment.PaymentMethodsFragment { *; } -keep class pl.mobiltek.paymentsmobile.dotpay.fragment.* { *; } -keep class pl.mobiltek.paymentsmobile.dotpay.managers.PaymentManager { *; } -keep class pl.mobiltek.paymentsmobile.dotpay.AppSDK { *; } -keep class pl.mobiltek.paymentsmobile.dotpay.events.PaymentEndedEventArgs { *; } -keep class pl.mobiltek.paymentsmobile.dotpay.events.PaymentManagerCallback { *; } -keep class pl.mobiltek.paymentsmobile.dotpay.events.* { *; } -keep class pl.mobiltek.paymentsmobile.dotpay.model.PaymentInformation { *; } -keep class pl.mobiltek.paymentsmobile.dotpay.model.* { *; } -keep class pl.mobiltek.paymentsmobile.dotpay.Configuration { *; } -keep class pl.mobiltek.paymentsmobile.dotpay.* { *; } -keep class pl.mobiltek.paymentsmobile.dotpay.**{ *; } -keep class pl.mobiltek.paymentsmobile.dotpay.***{ *; } |
Conclusion:
In this blog, you have learned about the implementation of the DotPay payment gateway integration by using SDK.
For more information regarding the DotPay payment gateway follow the link.
Thanks for reading this blog. You can also check other blogs from here.