IMPLEMENTATION - edfapay/edfa-pg-android-sdk GitHub Wiki


Pay By Card


EdfaPgCardPay

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

Step 1: Create an instance of EdfaPgCardPay

var edfaPgCardPay = EdfaPgCardPay()

Step 2: Create an instance of EdfaPgSaleOrder

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

Step 3: Create an instance of EdfaPgPayerOptions (Optional)

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

Step 4: Create an instance of EdfaPgPayer

/* Required (all fields are mandatory except `options`)*/
val payer = EdfaPgPayer(
    firstName = "Zohaib",
    lastName = "Kambrani",
    address = "Riyadh Olaya KSA",
    country = "SA",
    city = "Riyadh",
    zip = "12271",
    email = "[email protected]",
    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 EdfaPgCardPay instance.

edfaPgCardPay
    .setOrder(order)
    .setPayer(payer)

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

.onTransactionFailure(callback:(EdfaPgSaleResponse?, 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:(EdfaPgSaleResponse?, 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

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

    },
    onPresent = {

    }
)

Step 7.2: Self-Present Card Payment View Controller

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

payer.options = payerOptions // (optional)
let vc =  EdfaPgCardPay.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)
⚠️ **GitHub.com Fallback** ⚠️