4. Support manual mode
Last updated
Was this helpful?
Was this helpful?
// 01 - Temporarily change the default card to the selected card, if necessary.
DigitalizedCard originalDefault = null;
// Get card selected by the end user.
DigitalizedCard selectedCard = getSelectedCard();
// If selected card is not the default card, take note of the original default card,
// then set the selected card as the default, before proceeding with payment.
if (!isDefault(selectedCard)) {
originalDefault = getDefaultCard(); // Save the original default card.
setDefaultCard(selectedCard); // Set the selected card as the new default.
}
// 02 - Define the listener to handle the contactless payment flow events.
private PaymentServiceListener paymentServiceListener = new ContactlessPaymentServiceListener() {
@Override
public void onAuthenticationRequired(PaymentService paymentService,
CHVerificationMethod cvm, long cvmResetTimer) {
// 04 - Trigger the authentication according to the CDCVM method.
startInputCvmActivity(cvm);
}
@Override
public void onTransactionCompleted(TransactionContext ctx) {
// 05a - After successful transaction, revert to the original default card, if necessary.
setDefaultCard(originalDefault);
}
@Override
public void onError(TransactionContext transactionContext,
PaymentServiceErrorCode errorCode, String msg) {
// 05b - After failed transaction, revert to the original default card, if necessary.
setDefaultCard(originalDefault);
}
@Override
public void onTransactionStarted() {
}
@Override
public void onReadyToTap(PaymentService service) {
}
};
// 03 - Trigger authentication prior to payment.
final PaymentBusinessService paymentBusinessService = PaymentBusinessManager.getPaymentBusinessService();
paymentBusinessService.startAuthentication(paymentServiceListener, PaymentType.CONTACTLESS);