📱Cowpay Android SDK

This document is a guide for Cowpay Android SDK. In addition, following the below steps will help you learn how to add and use (Cowpay SDK) in your Android Application.

1. REQUIREMENTS

  • Minimum Android SDK 24

  • Target API level 34

2. INSTALLATION

1- Add the JitPack repository to the project-level build.gradle file:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
} 

2- Add Frames SDK dependency to the module gradle file:

dependencies {
    implementation 'com.github.CowpayPayment:Cowpay-Android:${latest version}'
}

You can find the latest version here

3- Update org.jetbrains.kotlin.android in build.grade (Project: Your Project) to be 1.9.0:

plugins {
    id 'com.android.application' version '8.0.2' apply false
    id 'com.android.library' version '8.0.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.9.0' apply false
}

4- Update kotlinCompilerExtensionVersion in build.grade (Module :app) to be 1.5.1:

    composeOptions {
        kotlinCompilerExtensionVersion '1.5.1'
    }

3. IMPORT

import com.luminsoft.cowpay_sdk.sdk.*
import com.luminsoft.cowpay_sdk.sdk.model.*

4. USAGE

Step 1: Initialize the payment info:

val paymentInfo = PaymentInfo(
    merchantReferenceId = "merchantReferenceId",
    customerMerchantProfileId = "customerMerchantProfileId",
    amount = 200.0,
    customerFirstName = "FirstName",
    customerLastName = "LastName",
    customerMobile = "01234567890",
    customerEmail = "customer@customer.com",
    description = "description",
    isFeesOnCustomer = false
)

Step 2: Initialize the SDK:

CowpaySDK.init function is used for Initializing Cowpay SDK instance to use it.

It’s a throws function so please put it in a try…catch blocs.

try {

    CowpaySDK.init(
        merchantCode = merchantCode,
        merchantHash = merchantHash,
        merchantPhoneNumber = merchantPhoneNumber,
        paymentInfo = paymentInfo,
        environment = CowpayEnvironment.STAGING or CowpayEnvironment.PRODUCTION,
        localizationCode = LocalizationCode.AR or LocalizationCode.EN,
        merchantLogo = merchantIconLink
    )
} catch (e: Exception) {
    Log.e("error", e.toString())
}

Step 3: launch SDK and create a callback object:

CowpaySDK.launch function is used for launching Cowpay SDK.

It’s a throws function so please put it in a try…catch blocs.

CowpayCallBack object contains Success, error and closedByUser call backs

try {

    CowpaySDK.launch(activity, object : CowpayCallback {
        override fun success(paymentSuccessModel: PaymentSuccessModel) {
            // Successful payment call back
            // paymentSuccessModel.paymentMethodName
            // paymentSuccessModel.paymentReferenceId
        }

        override fun error(paymentFailedModel: PaymentFailedModel) {
            // error during the payment process
        }

        override fun closedByUser() {
            // the user decided to leave the payment page
        }
    })
} catch (e: Exception) {
    Log.e("error", e.toString())
}

5. ADDITIONAL OPTIONS

If you want to do an action based on payment method you can make success call back like that:

override fun success(paymentSuccessModel: PaymentSuccessModel) {

    if (paymentSuccessModel is PaymentSuccessModel.FawrySuccessModel) {
        Log.e("SuccessFawry", paymentSuccessModel.paymentMethodName)
    }
     else if (paymentSuccessModel is PaymentSuccessModel.CreditCardSuccessModel) {
        Log.e("SuccessCard", paymentSuccessModel.paymentReferenceId)
        Log.e("SuccessCard", paymentSuccessModel.paymentMethodName)
    }
    Log.e("SuccessCard", paymentSuccessModel.toString())
}

5. VALUES DESCRIPTION

Keys
Values

localizationCode

Select your language code LocalizationCode.EN for English, and LocalizationCode.AR for Arabic. The default value is English

environment

Select the environment CowpayEnvironment.STAGING for staging and CowpayEnvironment.PRODUCTION for production.

amount

Transaction amount. Two decimal values like "15.60", were sent in case of partial capture. (Required)

description

charge request description that reserves the payment name. (Required)

customerMerchantProfileId

The ID of the customer being charged on your system. (Required)

merchantReferenceId

A unique alphanumeric value is required as an identifier for the charge request. (Required)

customerFirstName

customer first name (Required)

customerLastName

customer last name (Required)

customerEmail

customer valid email address. (Required)

customerMobile

Nationally formatted customer mobile that should start with 01. (Required)

isFeesOnCustomer

Boolean variable, True if the customer will pay transaction fees and false if not.

Default value is false.

merchantCode

Your code that presented in your panel. (Required)

merchantHash

Hash Key that is presented in your panel. (Required)

merchantPhoneNumber

merchant phone number. (Required)

merchantLogo

merchant logo url

CowpayCallback

Call back functions model. It contains success, error, and closedByUser callbacks. (Required)

success

Call back function if transaction succeeds.

error

Call back function when an error occurres.

closedByUser

Call back function if customer goes back before making a transaction.

paymentSuccessMode

Payment success model that contains paymentReferenceId and paymentMethodName.

paymentReferenceId

Payment reference number.

paymentMethodName

Payment method name (credit card, fawry, etc…)

Last updated