5. Payment Flow — startPayment()
startPayment() launches the SDK's built-in transaction UI as a DialogFragment.
startPayment()
pos.startPayment(
activity = this,
amountInCents = 50000L,
merchantName = "My Hospital",
listener = object : PaymentResultListener {
override fun onApproved(
result: TransactionResult) {
Log.d(TAG,
"Approved RRN: ${result.rrn}")
}
override fun onDeclined(
result: TransactionResult) {
Log.w(TAG,
"Declined: ${result.responseMessage}")
}
override fun onCancelled() {
}
override fun onError(message: String) {
Log.e(TAG, "Error: $message")
}
}
)
pos.startPayment(
this,
50000L,
"My Hospital",
new PaymentResultListener() {
@Override
public void onApproved(TransactionResult result) {
Log.d(TAG, "Approved RRN: " + result.getRrn());
}
@Override
public void onDeclined(TransactionResult result) {
Log.w(TAG,
"Declined: " + result.getResponseMessage());
}
@Override
public void onCancelled() {
}
@Override
public void onError(String message) {
Log.e(TAG, "Error: " + message);
}
}
);
WARNING
startPayment() must be called from the main thread.
5.1 PaymentResultListener Interface
| Method | Called when |
|---|---|
| onApproved(result) | The issuer approved the transaction. |
| onDeclined(result) | The issuer declined the transaction. |
| onCancelled() | User cancelled or timed out. |
| onError(message) | Non-recoverable SDK error. |
5.2 TransactionResult Model
| Field | Type | Description |
|---|---|---|
| transactionRef | String | SDK-generated unique transaction reference. |
| terminalId | String | Terminal ID from TMS. |
| maskedPan | String | Masked card number. |
| cardType | String | Card scheme. |
| responseCode | String | ISO 8583 response code. |
| responseMessage | String | Human-readable response message. |
| rrn | String | Retrieval reference number from the acquirer. |