In this blog, we will learn about SSL Commerz payment gateway integration in android with SDK approach.
A payment gateway is a merchant service provided by an e-commerce application service provider. Which authorizes card or direct payment processing.
If you are planing on the integration of the SSL Commerz payment gateway by using SDK then this blog will help you to do so.
Implementation
1. Initial setup
Download SSL Commerz SDK
- Create your account on the link for integration if you have already an account then login to your account.
- Download the Android SDK from the console inside the developer tab.
Adding SSL Commerz SDK
- Unzip the downloaded file locate the sslCommerzSdk.aar file
- Inside your android project past the sslCommerzSdk.aar SDK file.
- After adding SDK go to add the below line in your settings.gradle.
1 |
include ':sslCommerzSdk' |
Adding SDK dependencies in your Application
- Add below SDK dependency in your app-level build file.
1 |
implementation project(':sslCommerzSdk') |
2. Initialize payment
After successfully adding the SDK initialize the payment, SSLCommerzInitialization class of SSL Commerz SDK is used to initialize payment. So you have to call its constructor like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
fun processPayment() { val sslCommerzInitialization = SSLCommerzInitialization(your store ID, your store Password, Amount To Pay, SSLCCurrencyType.BDT, //Currency type Transaction Id, Product category, SSLCSdkType.LIVE //SDK type for live payment use SSLCSdkType.TESTBOX for test mode ) IntegrateSSLCommerz .getInstance(this) .addSSLCommerzInitialization(sslCommerzInitialization) .buildApiCall(this) } |
Inside store Id field add valid store Id and password only because if you pass invalid key here payment UI will not initialize.
3. Handling payment callback:
It’s time to handle the payment callback. For this, implement the listener as :
1 |
class CheckoutActivity : BaseActivity(),SSLCTransactionResponseListener{ } |
For any error, success, and failure, we have to override the following method of implemented interface inside our activity. which will help you to handle the success and failure result.
1 2 3 4 5 6 7 8 9 10 11 |
override fun transactionFail(p0: String?) { // handle failure case } override fun merchantValidationError(p0: String?) { // handle error case } override fun transactionSuccess(p0: SSLCTransactionInfoModel?) { // handle success case } |
Here p0 is the SSLCTransactionInfoModel object from which you can get the payment details like:
1 |
p0?.tranId //geting transaction id |
Conclusion:
In this blog, you have learned about the implementation of the SSL Commerz payment gateway integration by using SDK.
For more documentation regarding the SSL Commerz payment gateway follow the link
Thanks for reading this blog. You can also check other blogs from here.