Updated 11 October 2021
In this blog, we are going to learn about how to implement Omise 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.
Omise payment gateway provides quick and secure online transactions. The use of JSON data makes the omise payment gateway easy for understanding and for integration. It provides fraud detection and protection with the regulation of VISA and Mastercard.
If you are interested in Omise payment and want Omise payment gateway integration in android with SDK then this blog will help you to do so.
Omise payment gateway work on the below steps:
Add below dependency in your app-level build.gradle file.
1 2 3 |
dependencies { implementation 'co.omise:omise-android:3.1.+' } |
SDK PaymentForm provides the UI interface for payment. So you have to create or initialize the view.
We are using the omise CreditCardActivity
that will contain the UI for payment. So we have to start the Activity for result like:
1 2 3 |
val intent = Intent(mFragmentContext.context, CreditCardActivity::class.java) intent.putExtra(OmiseActivity.EXTRA_PKEY, "your omis public key") mFragmentContext.startActivityForResult(intent, RC_PAYMENT) |
Declare the CreditCardActivity
in
AndroidManifest.xml
file like below:
1 2 3 4 5 |
<activity android:name="co.omise.android.ui.CreditCardActivity" android:theme="@style/OmiseCustomTheme" android:screenOrientation="portrait" android:windowSoftInputMode="stateHidden|adjustResize" /> |
It’s time to handle the payment callback. For that, you have to get the data from the intent like :
1 2 3 |
val token = data?.getParcelableExtra<Token>(OmiseActivity.EXTRA_TOKEN_OBJECT) Log.d("OMISE_TOKEN", "omise_token:$token") Log.d("OMISE_TOKEN", "omise_token_id:" + token?.id) |
Complete code for handling the callback will look like below:
1 2 3 4 5 6 7 8 9 10 |
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (resultCode == AppCompatActivity.RESULT_OK) { if (requestCode == RC_PAYMENT) { val token = data?.getParcelableExtra<Token>(OmiseActivity.EXTRA_TOKEN_OBJECT) Log.d("OMISE_TOKEN", "omise_token:$token") Log.d("OMISE_TOKEN", "omise_token_id:" + token?.id) } } } |
If you wants to provide the custom style for the Omise CreditCardActivity
then add the below code on your style file:
1 2 3 4 5 6 7 8 9 10 |
<style name="OmiseCustomTheme" parent="Theme.AppCompat.Light"> <item name="colorAccent">@color/colorAccent</item> <item name="android:windowBackground">@android:color/white</item> <item name="actionBarStyle">@style/OmiseActionBarStyle</item> <item name="android:editTextStyle">@style/OmiseEditText</item> <item name="android:buttonStyle">@style/OmiseButton</item> <item name="android:itemTextAppearance">@style/OmiseItemTextAppearance</item> <item name="editTextLabelStyle">@style/OmiseEditTextLabel</item> <item name="editTextErrorStyle">@style/OmiseEditTextErrorMessage</item> </style> |
In this blog, you have learned about the implementation of the Omis payment gateway integration by using SDK.
For more information regarding the Omise payment gateway follow the link.
Thanks for reading this blog. You can also check other blogs from here.
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.