Transaction

TerraCore v0

Usage#

Currently Minerva only supports following payment methods:

  1. Online:
  • VNPayGateway (QR, ATM, InternationalCard, MobileBanking)
  • VNPayQRCode
  • VNPayTokenize
  • VNPayQRCustomer
  • VNPaySpos
  • VNPayEWallet
  • Loyalty
  • MoMoAIO
  1. Offline:
  • COD
  • BankTransfer
  • Installment
  • InputRef (e.g: MomoPay, GrabPay...)


1. AIO Transaction#

1.1. Initialization#

AIO Transaction stands for All-in-one transaction. It means we can initialize a customize transaction contains multiple sub transactions. Ex: online, offline, loyalty.

Firstly, you must define which payment payload will pay for the order like below

val method1 = LoyaltyMethodRequest(
points = 1,
amount = 10000,
redemptionCode = "redemptionCode")
val method2 = VNPayGatewayMethodRequest(amount = 10000)
val method3 = CODOfflineMethodRequest(amount = 10000, cashierCode = "cashierCode")

After that, using PayAIOBuilder to init request payload

val request = PayAIOBuilder()
.setOrderCode("yourOrderCode")
.setTotalPaymentAmount(20000)
.addPaymentMethods(method1, method2, method3)
.setSuccessUrl("https://payment.teko.vn") // optional
.setCancelUrl("https://payment.teko.vn") // optional
// perform request
val result = paymentGateway.initAIOTransaction(request)
// Handle the result
if (result.isSuccess()) {
// TODO: succeeded case
} else {
// TODO: failed case
}

1.2. Observe AIOTransaction result#

Observe the AIOTransaction result:

  • After init transaction successfully, You able to observe the result
paymentGateway.observePaymentResult(requestID)
.onEach { result ->
if (result.isSuccess()) {
//TODO: Handle for successfully case
} else {
val errorDetail = result.errorDetail()
//TODO: Handle for failed case
}
}.launchIn(lifecycleScope)

Notes: the requestId will be available after call initAIOTransaction successfully

And when you want to cancel observing the transaction result, you use method cancelObservePaymentResult

Auto cancelling based on lifecycleScope

2. Cancel Transaction#

A transaction can be canceled and unable to make payment by call this API.

val request = CancelTransactionRequestBuilder()
.setRequestId("requestId of transaction want to be canceled")
// perform request
val result = paymentGateway.cancelTransaction(request)
// Handle the result
if (result.isSuccess()) {
// TODO: succeeded case
} else {
// TODO: failed case
}

References#