Android SDK
This guide will walk you through a straightforward solution to accept payments within your Android application. The Moyasar Android SDK helps you accept multiple payment methods in your app including Mada, Visa, and MasterCard.
Before we can use the SDK, we have to add a couple of things within the app module build.gradle.kts and settings.gradle.kts files.
Add the SDK's hosting repository by adding the following to your settings.gradle.kts file:
Next, we need to enable the data binding feature, so we have to add the kotlin-kapt plugin and add the following within the android block in the app module build.gradle.kts file:
Now, we can add the SDK dependency in the dependencies block inside build.gradle.kts file:
Make sure you have the following permissions in your Android manifest.
The SDK currently only provides Credit Card payment integration. We can use that by first preparing Moyasar's PaymentConfig object as follows:
Then, we initialize and display Moyasar's PaymentFragment as follows:
An error will be throwen if the API key format is incorrect.
The payment fragment looks like this:
Now, we can handle the Credit Card payment result as follows:
'Completed' payment doesn't necessarily mean that the payment is successful. It means that the payment process has been completed successfully.
You need to check the payment status to make sure that the payment is successful.
You can find payment statuses here: Payment Status Reference
Make sure to remove the payment's view after getting the result.
The SDK is built with Kotlin and allows interoperability with Java.
Moyasar provides a sandbox environment for testing credit card payments without charging any real money. This allows you to test your integration and ensure that everything is working correctly before going live with actual payments. Learn more about our testing cards here.
This upgrade changes the following:
The disrtibtution of the SDK has been moved to Jitpack rather than MavenCentral, so you can modify the installation from this:
To this:
Add the new SDK's hosting repository In the app's settings.gradle.kts file:
Add the new dependency In the app's build.gradle.kts file:
Modify the initialization of the SDK from this:
To this: