Skip to content

IMPLEMENTATION

Zohaib edited this page Feb 14, 2023 · 1 revision

Pay By Card


ExpressCardPay

ExpressCardPay class allows you to implement payment via CREDIT/DEBIT CARD by following easy steps:

Step 1: Create an instance of ExpressCardPay

var expressCardPay = ExpressCardPay()

Step 2: Create an instance of ExpressPaySaleOrder

 /* Required */
val order = ExpresspaySaleOrder(
    id = binding.etxtOrderId.text.toString(),
    amount = amount,
    currency = binding.etxtOrderCurrencyCode.text.toString(),
    description = binding.etxtOrderDescription.text.toString()
)

Step 3: Create an instance of ExpressPayPayerOptions (Optional)

/*
Optional
[if you don't want to pass these detail keep it nil ]
*/
val payerOptions = ExpresspayPayerOptions(
    middleName = "Muhammd Iqbal",
    address2 = "Hyderabad Pakistan",
    state = "Sindh",
    birthdate = Date(),
) 

Step 4: Create an instance of ExpressPayPayer

/* Required (all fields are mandatory except `options`)*/
val payer = ExpresspayPayer(
    firstName = "Zohaib",
    lastName = "Kambrani",
    address = "Riyadh Olaya KSA",
    country = "SA",
    city = "Riyadh",
    zip = "12271",
    email = "a2zzuhaib@gmail.com",
    phone = "+966500409598",
    ip = "188.54.52.147", // fetch your public IP -> https://github.com/chintan369/Ipify-Android
    options = payerOptions
)

Step 5: Set order, payer, payerOptions details to the ExpressCardPay instance.

expressCardPay
    .setOrder(order)
    .setPayer(payer)

Step 6: Set the callbacks to the ExpressCardPay instance to notify you of the different statuses.

.onTransactionFailure(callback:(ExpresspaySaleResponse?, Any?) -> Unit) This will be called when the process receives any type of failure during processing payment (must inspect the 'res' before proceeding)

.onTransactionFailure { res, data ->
    print("$res $data")
    Toast.makeText(this, "Transaction Failure", Toast.LENGTH_LONG).show()
}

onTransactionSuccess(callback:(ExpresspaySaleResponse?, Any?) -> Unit) This will be called when the process is completed with success status (must inspect the 'res' before proceeding)

.onTransactionSuccess { res, data ->
    print("$res $data")
    Toast.makeText(this, "Transaction Success", Toast.LENGTH_LONG).show()
}

Step 7.1: Initialize/Start the Card Payment

.initialize(context:Activity, onError:(Any) -> Unit, onPresent:(Activity) -> Unit) Facing Issue? Call/Message | Email

expressCardPay.initialize(
    context = this, // this == Activity
    onError = {

    },
    onPresent = {

    }
)

Step 7.2: Self-Present Card Payment View Controller

ExpressCardPay.viewController(target: payer: order: transactionSuccess: transactionFailure: onError: onPresent:) Facing Issue? Call/Message | Email

payer.options = payerOptions // (optional)
let vc =  ExpressCardPay.viewController(
    target: self,
    payer: payer,
    order: order,
    transactionSuccess: { res, data in
        <#code#>

    }, transactionFailure: { err, data in
        <#code#>

    }, onError: { err in
        <#code#>

    }, onPresent: {
        <#code#>
    }
)
present(vc, animated: true)

ExpressPay

The ExpressPay Android SDK - https://expresspay.sa

Clone this wiki locally