In this blog, we are going to learn about how to implement checkout.com 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.
checkout.com payment gateway provides quick and secure online transactions with various 150 currencies and also accepts payment from a host of payment methods.
If you are planing on the integration of the checkout.com payment by using SDK then this blog will help you to do so.
Implementation
1. Initial setup
Adding SDK dependencies in your Application
- Add below dependency in your app-level build.gradle file.
1 2 3 |
dependencies { implementation 'com.github.checkout:frames-android:v2.0.6' } |
2. Initialize payment
SDK PaymentForm provides the UI interface for payment. So you have to add PaymentForm inside your payment activity layout file.
1 2 3 4 5 6 |
<com.checkout.android_sdk.PaymentForm android:id="@+id/checkout_card_form" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#ffffff" android:theme="@style/CheckoutTheme" /> |
Initialize the payment gateway as:
1 2 3 4 5 6 |
val mPaymentForm: PaymentForm = mBinding.checkoutCardForm // checkoutCardForm is the payment form added on the payment layout file mPaymentForm .setFormListener(mFormListener) .setEnvironment(Environment.LIVE) //use Environment.SANDBOX for test .setKey("your public key") //add your public key here .includeBilling(false) |
- mFormListener is the name of your custom listener for handling payment callback.
Inside setKey, add a valid key only because if you pass an invalid key here payment UI will not initialize. And along with this you can include billing by passing includeBilling as true also.
3. Handling payment callback:
It’s time to handle the payment callback. For this, use the form listener that you have used during the payment initialization as :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
private val mFormListener: PaymentFormCallback = object : PaymentFormCallback { override fun onFormSubmit() { // show processing.. } override fun onTokenGenerated(response: CardTokenisationResponse) { response.getId() //card id/token generated by payment SDK // dismiss the processing.. } override fun onError(response: CardTokenisationFail) { //Show error log by using response.getMessage() } override fun onNetworkError(error: VolleyError?) { //Network error } override fun onBackPressed() { //Handle back pressed } } |
For getting the generated token by SDK override onTokenGenerated. Inside this, you can get the id from the response.
1 2 3 4 5 |
override fun onTokenGenerated(response: CardTokenisationResponse) { response.getId() //card id generated by payment SDK // dismiss the processing.. } |
Conclusion:
In this blog, you have learned about the implementation of the checkout.com payment gateway integration by using SDK.
For more information regarding the checkout.com payment gateway follow the link.
Thanks for reading this blog. You can also check other blogs from here.