To get available currencies you have to use this method
private void getCurrencies() {
try {
// get list of available currencies from tetra
transactionCurrencyValues = getTransaction().getAvailableCurrencies();
// check transactionCurrencyValues contains values
if (!transactionCurrencyValues.isEmpty()) {
// init list of currencies code to display
List transactionCurrencyCode = new ArrayList();
// create a list of currencies code to display
transactionCurrencyValues.forEach(currency -> {
transactionCurrencyCode.add(currency.getCode());
});
} else {
}
} catch (IngenicoException e) {
e.printStackTrace();
}
}
Register the listener for transaction Done
getTransaction().registerTransactionDoneListener(this);
Start transaction
private void startTransaction() {
// Initialize numeric code value
Long currencyNumericCode = -1L;
// Check availability of items in spinner
if (transactionCurrencyValues.size() > 0 ) {
// Get selected numeric code value
currencyNumericCode = (long) (transactionCurrencyValues.get(0)).getNumericCode();
}
// Cast to final numeric code value
Long finalCurrencyNumericCode = currencyNumericCode;
new Thread(() -> {
try {
// Fill transaction parameters
TransactionInputData inputData = TransactionInputData.builder()
.setAmount(new BigDecimal(5.20))
.setCurrency(finalCurrencyNumericCode)
.setTransactionType(TransactionTypes.SALE)
.build();
// Start the transaction
TransactionRequest request = getTransaction().start(inputData);
// Request accepted?
if (!request.isRequestAccepted())
throw new Exception("Could not start transaction: " + request.getTransactionStatus());
// Fine, ongoing payment
changeState(PaymentState.InProgress);
} catch (Exception e) {
Log.e(TAG, "Start transaction failed", e);
}
}).start();
}
To abort transaction you have to use this source code
private void abortOngoingTransaction() {
new Thread(() -> {
try {
getTransaction().abortOngoingTransaction();
} catch (Exception e) {
Log.e(TAG, "Abort transaction failed", e);
isProcesscing = false;
}
}).start();
}
When the transaction is done you have to check the result
@Override
public void onTransactionDone(TransactionResult transactionResult) {
boolean success = transactionResult.getStatus() == TransactionStatus.TXN_STATUS_TXN_APPROVED;
mContext.runOnUiThread(() -> {
// Show OK or KO according to the transaction success
if(success){
mPaymenetListener.paymentDoneListener(transactionResult);
}else{
mPaymenetListener.paymentErrorListener(transactionResult.getStatus().name());
}
isProcesscing = false;
});
changeState(PaymentState.Done);
}