Mobile SDKs

Android SDK

18min

Overview

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.

Installation

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:

settings.gradle.kts


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:

build.gradle.kts


Now, we can add the SDK dependency in the dependencies block inside build.gradle.kts file:

build.gradle.kts


Adding permissions

Make sure you have the following permissions in your Android manifest.

XML


Credit Card Payments

The SDK currently only provides Credit Card payment integration. We can use that by first preparing Moyasar's PaymentConfig object as follows:

Kotlin


Then, we initialize and display Moyasar's PaymentFragment as follows:

Kotlin


An error will be throwen if the API key format is incorrect.

The payment fragment looks like this:

Android SDK Dark AR
Android SDK Dark AR

Android SDK Dark EN
Android SDK Dark EN


Handling Credit Card Payment Result

Now, we can handle the Credit Card payment result as follows:

Kotlin


'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.

Java interoperability

The SDK is built with Kotlin and allows interoperability with Java.

Testing

Credit Cards

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.

Migration Guide



From 0.5 to 1.0

This upgrade changes the following:

Installation Setup

The disrtibtution of the SDK has been moved to Jitpack rather than MavenCentral, so you can modify the installation from this:

build.gradle.kts


To this:

Add the new SDK's hosting repository In the app's settings.gradle.kts file:

settings.gradle.kts


Add the new dependency In the app's build.gradle.kts file:

build.gradle.kts


Initialization

Modify the initialization of the SDK from this:

Kotlin


To this:

Kotlin



Demo Example



Updated 08 May 2024
Did this page help you?