public class Transaction
extends java.lang.Object
Transaction
singleton class is the base class for performing EMV transactions on the Yello terminal.
TransactionConfiguration
class. The TransactionConfiguration
class is
set within the Transaction
singleton class:
setTransactionConfig(TransactionConfiguration)
startTransaction(TransactionConfiguration, TransactionType, BigDecimal, BigDecimal)
TransactionGateway
interface). Within the Yello EMV transaction library,
gateway selection and configuration is performed via the
TransactionGatewayFactory
singleton class.TransactionDisplayListener
interface to receive text
updates showing progress of the transaction (like PRESENT CARD, PROCESSING PIN OK, etc),
as well as menu selection requests for handling interaction with the EMV kernel (like AID selection).
One can register its implementation of the TransactionDisplayListener
interface within the
Transaction
singleton class via the method registerTransactionDisplayListener(TransactionDisplayListener)
.startTransaction(TransactionType, BigDecimal, BigDecimal)
or the method
startTransaction(TransactionConfiguration, TransactionType, BigDecimal, BigDecimal)
TransactionDisplayListener
called MySimpleDisplayListener.
See the TransactionDisplayListener
interface for an example of the implementation.// Get instance of the Transaction Singleton Transaction trans = Transaction.getInstance() try { // Setup the EMV configuration TransactionConfiguration config = new TransactionConfiguration("EUR", "TestMerchantID", true, true, false); trans.setTransactionConfig(config); // Register the simulated gateway available from the Yello library as the gateway to use TransactionGatewayFactory tgf = TransactionGatewayFactory.getInstance(); tgf.registerCurrentGateway(TransactionGateways.SIMULATED); // Register the SimpleDisplayListener with the Transaction Singleton MySimpleDisplayListener displayListener = new MySimpleDisplayListener(); trans.registerTransactionDisplayListener(displayListener); // Open the transaction session using default timeout setting trans.openTransactionSession(0); // Start a purchase transaction of 10 euros TransactionStatus status = trans.startTransaction(TransactionType.PURCHASE, new BigDecimal("10.0"), new BigDecimal("0.0")); System.out.println("Result: " + TransactionResult.toString(status.getTransactionResult())); if (status.isXMLReceiptAvailable()) { System.out.println("Receipt: " + status.getXMLReceipt()); } } catch(Exception e) { System.out.println("Error performing transaction " + e); } finally { trans.closeTransactionSession(); }
TransactionGateway
interface called MyAutoApprovedGateway.
See the TransactionGateway
interface for an example of the implementation.// Get instance of the Transaction Singleton Transaction trans = Transaction.getInstance() try { // Setup the EMV configuration TransactionConfiguration config = new TransactionConfiguration("EUR", "TestMerchantID", true, true, false); trans.setTransactionConfig(config); // Register the MyAutoApprovedGateway implementation MyAutoApprovedGateway gateway = new MyAutoApprovedGateway(); TransactionGatewayFactory tgf = TransactionGatewayFactory.getInstance(); tgf.registerCurrentGateway(gateway); // Register the SimpleDisplayListener with the Transaction Singleton MySimpleDisplayListener displayListener = new MySimpleDisplayListener(); trans.registerTransactionDisplayListener(displayListener); // Open the transaction session using default timeout setting trans.openTransactionSession(0); // Start a purchase transaction of 10 euros TransactionStatus status = trans.startTransaction(TransactionType.PURCHASE, new BigDecimal("10.0"), new BigDecimal("0.0")); System.out.println("Result: " + TransactionResult.toString(status.getTransactionResult())); if (status.isXMLReceiptAvailable()) { System.out.println("Receipt: " + status.getXMLReceipt()); } } catch(Exception e) { System.out.println("Error performing transaction " + e); } finally { trans.closeTransactionSession(); }
int timeout = 30 * 1000; Transaction trans = Transaction.getInstance(); trans.openTransactionSession(timeout + 1 * 1000); byte[] hash = trans.getMSRToken(timeout); LOG.debug("MSR token: " + StringUtils.convertBytesToHex(hash, "-")); trans.closeTransactionSession();
Modifier and Type | Method and Description |
---|---|
void |
cancelOngoingTransaction()
Cancels the EMV transaction currently in progress
|
boolean |
cancelTransaction(java.lang.String transactionID)
Cancels an EMV transaction that has not been settled yet.
|
void |
clearTransactionConfig()
Clears the EMV transaction configuration currently in use
|
void |
closeTransactionSession()
Closes the currently opened EMV transaction session
|
java.util.LinkedList<com.yello.api.secure.configuration.EMVConfiguration> |
getEMVConfigsFromCurrentGateway()
Gets List of EMV configurations from current transaction gateway
|
byte[] |
getEMVTag(EMVKernelType kernel,
java.lang.String tag,
int timeoutMs)
Retrieves an EMV configuration by tag from a specific EMV kernel
|
static Transaction |
getInstance()
Gets the instance of the
Transaction singleton |
byte[] |
getMSRToken(int timeout)
Request a tokenized MSR card data from a secure processor
|
java.util.LinkedList<TransactionStatus> |
getTransactions()
Gets the list of EMV transactions that are yet to be settled / finalized by the
transaction gateway
|
boolean |
isTransactionInProgress()
Check if an EMV transaction in progress
|
boolean |
isTransactionSessionOpened()
Checks if an EMV transaction session to the secure processor is already opened
|
void |
openTransactionSession(int timeoutMs)
Opens an EMV transaction session with the secure-processor
|
void |
registerTransactionDisplayListener(TransactionDisplayListener displayListener)
Registers a
TransactionDisplayListener interface implementation |
boolean |
settleTransaction(java.lang.String transactionID)
Settles an EMV transaction with the transaction gateway
|
void |
setTransactionConfig(TransactionConfiguration config)
Sets the EMV transaction configuration to use
|
TransactionStatus |
startTransaction(TransactionConfiguration config,
TransactionType type,
java.math.BigDecimal amount,
java.math.BigDecimal cashBackAmount)
Starts an EMV transaction with the secure processor using a given EMV configuration
|
TransactionStatus |
startTransaction(TransactionType type,
java.math.BigDecimal amount,
java.math.BigDecimal cashBackAmount)
Starts an EMV transaction with the secure processor
|
void |
unregisterCurrentTransactionDisplayListener()
Unregisters the currently use
TransactionDisplayListener interface |
public static Transaction getInstance()
Transaction
singletonTransaction
objectpublic void setTransactionConfig(TransactionConfiguration config) throws java.lang.NullPointerException, java.lang.IllegalAccessException
config
- EMV transaction configuration defined by TransactionConfiguration
java.lang.NullPointerException
- if config is nulljava.lang.IllegalAccessException
- if one tries to set the EMV transaction configuration while
an EMV transaction is in progresspublic void clearTransactionConfig() throws java.lang.IllegalAccessException
java.lang.IllegalAccessException
- if one tries to clear the EMV trannsaction configuration while
an EMV transaction is in progress.public void openTransactionSession(int timeoutMs) throws java.lang.Exception
timeoutMs
- Timeout in milliseconds. If timeoutMs is <= 0, internal default timeout will be usedjava.lang.IllegalAccessException
- if an EMV transaction session is already openedjava.io.IOException
- if the EMV transaction session cannot be opened due to IO errorsjava.lang.Exception
- for other types of exceptionspublic void closeTransactionSession()
public boolean isTransactionSessionOpened()
public void cancelOngoingTransaction() throws java.io.IOException
java.io.IOException
- if the cancel request fails due to IO errorspublic TransactionStatus startTransaction(TransactionType type, java.math.BigDecimal amount, java.math.BigDecimal cashBackAmount) throws java.lang.Exception
type
- Type of Transaction to performed, as defined by TransactionType
amount
- Amount of the transactioncashBackAmount
- cashback amount if the transaction is a purchase transaction with
cashback option (identified by TransactionType.CASHBACK
)TransactionStatus
representing the outcome of the EMV transaction.java.lang.NullPointerException
- if no EMV configuration is set before starting the transactionjava.io.IOException
- if the EMV transaction session is NOT opened or if the transaction fails due
to IO errors.java.lang.IllegalAccessException
- if an EMV transaction is already in progressjava.lang.Exception
public TransactionStatus startTransaction(TransactionConfiguration config, TransactionType type, java.math.BigDecimal amount, java.math.BigDecimal cashBackAmount) throws java.lang.Exception
config
- EMV transaction configuration (as defined by TransactionConfiguration
to use for this transactiontype
- Type of Transaction to performed, as defined by TransactionType
amount
- Amount of the transactioncashBackAmount
- cashback amount if the transaction is a purchase transaction with
cashback option (identified by TransactionType.CASHBACK
)TransactionStatus
representing the outcome of the EMV transaction.java.lang.NullPointerException
- if the EMV configuration is nulljava.io.IOException
- if the EMV transaction session is NOT opened or if the transaction fails due
to IO errors.java.lang.IllegalAccessException
- if an EMV transaction is already in progressjava.lang.Exception
public boolean isTransactionInProgress()
public void registerTransactionDisplayListener(TransactionDisplayListener displayListener) throws java.lang.IllegalAccessException
TransactionDisplayListener
interface implementationdisplayListener
- display listenerjava.lang.IllegalAccessException
- if an EMV transaction is in progresspublic void unregisterCurrentTransactionDisplayListener() throws java.lang.IllegalAccessException
TransactionDisplayListener
interfacejava.lang.IllegalAccessException
- if an EMV transaction is in progresspublic java.util.LinkedList<TransactionStatus> getTransactions() throws java.lang.IllegalAccessException, java.io.IOException
LinkedList
of EMV TransactionStatus
java.lang.IllegalAccessException
- if an EMV transaction is in progressjava.io.IOException
- if EMV session is not openedpublic boolean settleTransaction(java.lang.String transactionID) throws java.lang.IllegalArgumentException, java.lang.IllegalAccessException, java.io.IOException
transactionID
- identifier of the transaction to settlejava.lang.NullPointerException
- if no EMV configuration has been set beforehandjava.lang.IllegalArgumentException
- if transactionId is not validjava.lang.IllegalAccessException
- if an EMV transaction is in progressjava.io.IOException
- if EMV session is not openedpublic boolean cancelTransaction(java.lang.String transactionID) throws java.lang.IllegalArgumentException, java.lang.IllegalAccessException, java.io.IOException
cancelTransaction(String)
will cause the framework to send a cancel request
to the transaction gateway.
NOTE: an online authorized transaction cannot be cancelled if it has been settled with the
transaction gateway. In this case, a refund transaction should be performed.
If the EMV transaction is an offline transaction, calling the
cancelTransaction(String)
will cause the framework to just delete the
transaction from the transaction database.transactionID
- identifier of the transaction to canceljava.lang.NullPointerException
- if no EMV configuration has been set beforehandjava.lang.IllegalArgumentException
- if transactionID is not validjava.lang.IllegalAccessException
- if an EMV transaction is in progressjava.io.IOException
- if EMV session is not openedpublic byte[] getEMVTag(EMVKernelType kernel, java.lang.String tag, int timeoutMs) throws java.lang.Exception
kernel
- - kernel to read config fromtag
- - String hex representation of a tag to be retrievedtimeoutMs
- - timeout in msjava.lang.IllegalAccessException
- if an EMV session is NOT openedjava.util.NoSuchElementException
- if tag is not availablejava.lang.Exception
- for other types of exceptionspublic byte[] getMSRToken(int timeout) throws java.lang.Exception
timeout
- - K81 side operation timeoutjava.lang.Exception
- if wlink protocol reports an errorpublic java.util.LinkedList<com.yello.api.secure.configuration.EMVConfiguration> getEMVConfigsFromCurrentGateway() throws java.lang.Exception
LinkedList
of EMVConfiguration
representing the of list
of EMV configurations obtained from tha transaction gateway. If null if no
EMV configs are availablejava.lang.NullPointerException
- if no EMV configuration has been set beforehandjava.lang.IllegalAccessException
- if an EMV transaction is in progressjava.io.IOException
- if EMV session is not openedjava.lang.Exception
- for other types of errorsCopyright © 2019 Yello. All rights reserved.