The PayMaya Android SDK is a library that allows you integrate with PayMaya payments. It supports following methods:
- Checkout
- Checkout (WebView)
- Pay With PayMaya
- Single Payment (WebView)
- Create Wallet Link (WebView)
- PayMaya Vault
- Tokenize Card (native activity)
The SDK includes Demo application which uses Sandbox environment.
Android OS version 6.0 Marshmallow (API level 23) or higher.
Refer here for the released versions.
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.paymaya:paymaya-android-sdk-v2:<release tag>'
}
⚠️ Support for this repository has been deprecated (see here). Only versions 2.0.1 below are available in JCenter as read-only. Succeeding patches / releases will be uploaded to repositories documented above.
Refer here for the released versions.
repositories {
jcenter()
}
dependencies {
implementation 'com.paymaya:paymaya-sdk-android:+'
}
To initialize the SDK, build Checkout Client by specifying API key, environment type (sandbox or production) and a level of console logging.
val payMayaCheckoutClient = PayMayaCheckout.newBuilder()
.clientPublicKey("client_public_key")
.environment(PayMayaEnvironment.SANDBOX)
.logLevel(LogLevel.ERROR)
.build()
-
Create instance of a CheckoutRequest class, which contains information about the buyer (optional), bought items, transaction amount, merchant's request reference number, redirect URLs and metadata (optional).
val request = CheckoutRequest( totalAmount, buyer, items, requestReferenceNumber, redirectUrl, metadata )
In a typical case, RedirectUrl can be created as follows (with fake URLs):
RedirectUrl( success = "http://success.com", failure = "http://failure.com", cancel = "http://cancel.com" )
-
Call
startCheckoutActivityForResult
method to initiate payment with the checkout request data.payMayaCheckoutClient.startCheckoutActivityForResult(this, request)
The method starts a new activity in which the customer securely completes the process on a web page hosted by PayMaya. The result of the payment is returned to the application using standard Android Activity result mechanism.
-
To get the result, call
PayMayaCheckout.onActivityResult
from your Activity'sonActivityResult
, which returnsPayMayaCheckoutResult.Success
,PayMayaCheckoutResult.Cancel
orPayMayaCheckoutResult.Failure
with appropriate details likecheckoutId
. ThecheckoutId
can be used for further processing or to check detailed status of the payment usingcheckPaymentStatus
method.See example of
onActivityResult
usage in the Results handling sample section.NOTE: If user close Checkout Activity (e.g. by pressing the Back button) at any point, status of the payment will be automatically checked (if only
checkoutId
has been already retrieved from the PayMaya gateway). Payment status will be mapped to PayMayaCheckoutResult:- PAYMENT_SUCCESS → PayMayaCheckoutResult.Success
- AUTH_FAILED or PAYMENT_FAILED → PayMayaCheckoutResult.Failed
- otherwise → PayMayaCheckoutResult.Cancel
-
To manually check status of the payment, use
checkPaymentStatus
. The method is synchronous, so call it from other thread than Main for the best user experience. See sample usage in the Demo application (CartPresenter.payMayaCheckRecentPaymentStatusClicked
).
For Sandbox environment, use credit cards from the following link: Credit Cards for Sandbox Testing
To initialize the SDK, build Pay With PayMaya Client by specifying API key, environment type (sandbox or production) and a level of console logging.
val payWithPayMayaClient = PayWithPayMaya.newBuilder()
.clientPublicKey("client_public_key")
.environment(PayMayaEnvironment.SANDBOX)
.logLevel(LogLevel.ERROR)
.build()
-
Create instance of an SinglePaymentRequest class.
val request = SinglePaymentRequest( totalAmount, requestReferenceNumber, redirectUrl, metadata )
In a typical case, RedirectUrl can be created as follows (with fake URLs):
RedirectUrl( success = "http://success.com", failure = "http://failure.com", cancel = "http://cancel.com" )
-
Call
startSinglePaymentActivityForResult
method to initiate payment with the single payment request data.payMayaCheckoutClient.startSinglePaymentActivityForResult(this, request)
The method starts a new activity in which the customer securely completes the process on a web page hosted by PayMaya. The result of the payment is returned to the application using standard Android Activity result mechanism.
-
To get the result, call
PayWithPayMaya.onActivityResult
from your Activity'sonActivityResult
, which returnsPayWithPayMayaResult.Success
,PayWithPayMayaResult.Cancel
orPayWithPayMayaResult.Failure
with appropriate details likepaymentId
. ThepaymentId
can be used for further processing or to check detailed status of the payment usingcheckPaymentStatus
method.See example of
onActivityResult
usage in the Results handling sample section.NOTE: If user close Pay With PayMaya Activity at any point (e.g. by pressing the Back button), status of the payment will be automatically checked (if only the
paymentId
has been already retrieved from the PayMaya gateway). Payment status will be mapped to PayWithPayMayaResult:- PAYMENT_SUCCESS → PayWithPayMayaResult.Success
- AUTH_FAILED or PAYMENT_FAILED → PayWithPayMayaResult.Failed
- otherwise → PayWithPayMayaResult.Cancel
-
To manually check status of the payment, use
checkPaymentStatus
. The method is synchronous, so call it from other thread than Main for the best user experience. See sample usage in the Demo application (CartPresenter.payMayaCheckRecentPaymentStatusClicked
).
For Sandbox environment, use credit cards from the following link: Credit Cards for Sandbox Testing
Creates a wallet link that allows charging a PayMaya account later (Recurring Payment).
-
Create instance of an CreateWalletLinkRequest class.
val request = CreateWalletLinkRequest( requestReferenceNumber, redirectUrl, metadata )
In a typical case, RedirectUrl can be created as follows (with fake URLs):
RedirectUrl( success = "http://success.com", failure = "http://failure.com", cancel = "http://cancel.com" )
-
Call
startCreateWalletLinkActivityForResult
method to initiate creating wallet link process.payMayaCheckoutClient.startCreateWalletLinkActivityForResult(this, request)
The method starts a new activity in which the customer securely completes the process on a web page hosted by PayMaya. The result of the wallet link creation process is returned to the application using standard Android Activity result mechanism.
-
To get the result, call
PayWithPayMaya.onActivityResult
from your Activity'sonActivityResult
, which returnsCreateWalletLinkResult.Success
,CreateWalletLinkResult.Cancel
orCreateWalletLinkResult.Failure
with appropriate details likelinkId
. ThelinkId
can be used for further processing.See example of
onActivityResult
usage in the Results handling sample section.
To initialize the SDK, build the Pay With Vault Client by specifying API key,
environment type (sandbox or production) and a level of console logging.
You can also customize merchant's logo by using Builder.logo
method.
val payMayaVaultClient = PayMayaVault.newBuilder()
.clientPublicKey("client_public_key")
.environment(PayMayaEnvironment.SANDBOX)
.logLevel(LogLevel.ERROR)
.build()
The Card Vault helps you manage your customers and the cards linked to them. You can register customers as resources and vault their cards from payment tokens. Vaulting a card allows merchants to create a better experience for returning customers.
-
Call
startTokenizeCardActivityForResult
method to initiate card tokenization process.payMayaVaultClient.startTokenizeCardActivityForResult(this)
The method starts a new activity in which the customer securely completes the process on the SDK's activity. The result is returned to the application using standard Android Activity result mechanism.
-
To get the result, call
PayMayaVault.onActivityResult
from your Activity'sonActivityResult
, which returnsPayMayaVaultResult.Success
orPayMayaVaultResult.Cancel
with appropriate details likepaymentTokenId
andstate
. ThepaymentTokenId
can be used for further processing.See example of
onActivityResult
usage in the Results handling sample section.
Sample handling of the Checkout payment result in the merchant's activity.
Results of the other payment processes can be handled in a similar way. See the source
code of the Demo application for more detailed example (CartActivity.onActivityResult
and appropriate methods in CartPresenter
).
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
payMayaCheckoutClient.onActivityResult(requestCode, resultCode, data)?.let {
processCheckoutResult(it)
}
}
private fun processCheckoutResult(result: PayMayaCheckoutResult) {
when (result) {
is PayMayaCheckoutResult.Success -> {
val message = "Success, checkoutId: ${result.checkoutId}"
Toast.makeText(this, message, Toast.LENGTH_LONG).show()
}
is PayMayaCheckoutResult.Cancel -> {
val message = "Canceled, checkoutId: ${result.checkoutId}"
Toast.makeText(this, message, Toast.LENGTH_LONG).show()
}
is PayMayaCheckoutResult.Failure -> {
val message =
"Failure, checkoutId: ${result.checkoutId}, exception: ${result.exception}"
if (result.exception is BadRequestException) {
Log.d(TAG, (result.exception as BadRequestException).error.toString())
}
Toast.makeText(this, message, Toast.LENGTH_LONG).show()
}
}
}