Android SDK

Getting started with Android SDK for Number

The EasyPay Android SDK offers access to the Number API for seamless integration with any and all Android applications. For iOS integration, refer to the iOS SDK integration guide.


Installation

Requirements

  • Android 6.0 (API level 23) and above

  • Gradle 8.2 and above

  • Android Gradle Plugin 8.2.1

  • Kotlin 1.9.22 and above

Configuration

Add easypay to your dependencies in the build.gradle file.

dependencies {
    implementation 'com.easypaysolutions:easypay:1.1.5'
    
    // If you want to use widgets, add the following line
    implementation 'com.easypaysolutions:easypay-widgets:1.1.5'
}


Get started

Integration

1

Prerequisites - get API key, HMAC secret and optional Sentry DSN from Number.

2
3

During initialization, the RSA certificate download begins. Proceeding with any call before downloading has finished will result with an exception RSA_CERTIFICATE_NOT_FETCHED.

You can check the download status by accessing the following enum:

Using widgets

PaymentSheet

Number's prebuilt payment UI component that allows you to collect credit card information in a secure way and process payments.

1

Initialize a PaymentSheet inside onCreate of your checkout Fragment or Activity, passing a method to handle the payment result.

2

When the customer taps the payment button, call present method on the PaymentSheet instance with your configuration. PaymentSheet.Configuration requires the following parameters:

  • AmountsParam - total $ amount of the payment;

  • ConsentCreatorParam - annual consent details, that contains the following:

    • limitLifeTime - the maximum $ amount that can be charged in total,

    • limitPerCharge - the maximum $ amount that can be charged per transaction,

    • merchantId - the ID of the merchant that the consent is created for,

    • startDate - the date when the consent is created,

    • customerReferenceId or consentId to identify the customer.

Other parameters are optional.

3

Handle the payment result in the onPaymentSheetResult method.

CustomerSheet

Number's prebuilt UI component that lets your customers manage their saved credit cards.

1

Initialize a CustomerSheet inside onCreate of your checkout Fragment or Activity, passing a method to handle the customer sheet result.

2

To present the customer sheet, call the present method on the CustomerSheet instance, passing your configuration. CustomerSheet.Configuration requires the following parameters:

  • ConsentCreatorParam - annual consent details, that contains the following:

    • limitLifeTime - the maximum $ amount that can be charged in total,

    • limitPerCharge - the maximum $ amount that can be charged per transaction,

    • merchantId - the ID of the merchant that the consent is created for,

    • startDate - the date when the consent is created,

    • customerReferenceId or consentId to identify the customer.

Other parameters are optional.

3

Handle the customer sheet result in the onCustomerSheetResult method.

Screenshots

Save Card

Manage Cards

Store and Pay


Common components

SecureTextField component

The SDK's widgets use a component called SecureTextField which ensures a safe input of credit card number. It is a subclass of TextInputEditText which enables freedom of styling as needed.

SecureTextField supports only XML layout configuration:

To get the SecureData from the SecureTextField, use the following property:

Data in the SecureTextField component is already encrypted and can be used in the API calls without any additional encryption.


Common objects

Below you'll find code describing some of the objects that are commonly used in requests or responses. You can use it as a reference. The code includes parameter names, types, and some validation rules.

SecureData

Most commonly used as SecureData<String> coming from the SecureTextField component.

CreditCardInfoParam

AccountHolderDataParam

AccountHolderBillingAddressParam

EndCustomerDataParam

EndCustomerBillingAddressParam

AmountsParam

PurchaseItemsParam

ConsentCreatorParam


Public methods in the Android SDK

1. Charge credit card

This method processes a credit card when the credit card details are entered manually. Details include the card number, expiration date, CVV, card holder name and address.

REST API equivalent: Process a Card Sale Old

Request parameters

Response body

The response body will be serialized to ChargeCreditCardResult.

2. List annual consents

A query that returns annual consent details. Depending on the query sent, a single consent or multiple consents may be returned.

REST API equivalent: Query Old

Request parameters

  • ListAnnualConsentsBodyParams

    • merchantId: Int?

    • customerReferenceId: String?

    • rpguid: String?

    Either customerReferenceId or rpguid must be provided to get the list of consents of a specific customer.

Response body

The response body will be serialized to ListAnnualConsentsResult.

And the AnnualConsent looks like the following:

This method creates an annual consent by sending the credit card details, which include: card number, expiration date, CVV, and card holder contact data. It is not created by swiping the card through a reader device.

REST API equivalent: Create Annual Consent

Request parameters

Response body

The response body will be serialized to CreateAnnualConsentResult.

Cancels an annual consent. Credit card data is removed from the system after the cancellation is complete.

REST API equivalent: Consent Annual Older

Request parameters

  • CancelAnnualConsentBodyParams

    • consentId: Int

Response body

The response body will be serialized to CancelAnnualConsentResult.

This method uses the credit card stored on file to process a payment for an existing consent.

REST API equivalent: Consent Annual Older

Request parameters

  • ProcessPaymentAnnualBodyParams

    • consentId: Int

Response body

The response body will be serialized to ProcessPaymentAnnualResult.


How to properly consume the API response

All requests are suspended functions, so they should be called from coroutine scope. The result of the request is wrapped in a NetworkResource object, which can be handled in the following way:


Possible exceptions

EasyPaySdkException

Exceptions that are thrown by the SDK.

Exception name
Suggested solution

EASY_PAY_CONFIGURATION_NOT_INITIALIZED

Check if EasyPay.init(...) method has been called.

MISSED_SESSION_KEY

Check if correct SESSION_KEY has been provided in the EasyPay.init(...) method.

MISSED_HMAC_SECRET

Check if correct HMAC_SECRET has been provided in the EasyPay.init(...) method.

RSA_CERTIFICATE_NOT_FETCHED

RSA certificate might not be fetched yet. Check the status by calling the EasyPayConfiguration.getInstance().getRsaCertificateFetchingStatus() method.

RSA_CERTIFICATE_FETCH_FAILED

Contact Number.

RSA_CERTIFICATE_PARSING_ERROR

Contact Number.

EasyPayApiException

Exceptions that are thrown by the Number API.


Semantic versioning

The SDK follows semantic versioning with a three-part version number: MAJOR.MINOR.PATCH.

  • MAJOR version is incremented when there are incompatible API changes,

  • MINOR version is incremented when functionality is added in a backwards-compatible manner,

  • PATCH version is incremented when there are backwards-compatible bug fixes.


Feature flags

Rooted device detection

To enable rooted device detection, call the following method before calling EasyPay.init(...):

Last updated

Was this helpful?