Payments with myPOS Android SDK
Once your application is initialized and the terminal is connected, you can start accepting in-person card payments using the myPOS Android SDK. This includes support for standard purchases, refunds, pre-authorizations, MO/TO (Mail Order / Telephone Order) transactions, voids, and receipt management.
Take a Payment
Variant 1: Using the Built-in SDK Activity
mPOSHandler.openPaymentActivity(
MainActivity.this /*activity*/,
REQUEST_CODE_MAKE_PAYMENT /*requestCode*/,
"10.50" /*amount*/,
UUID.randomUUID().toString()/*transaction reference*/
);
Variant 2: Using the Direct SDK Method
POSHandler.getInstance().purchase(PaymentParams.builder()
.productAmount("13.37")
.currency("EUR")
.tipAmount("1.55")
.receiptConfiguration(POSHandler.RECEIPT_PRINT_AUTOMATICALLY)
.operatorCode("1234")
.reference("asd123asd", ReferenceType.REFERENCE_NUMBER)
.preauthTransaction(false)
.motoTransaction(false)
.build());
Handle Payment Results
Activity-based Payments:
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if( requestCode == REQUEST_CODE_MAKE_PAYMENT && resultCode == RESULT_OK) {
TransactionData transactionData = data.getParcelableExtra(POSHandler.INTENT_EXTRA_TRANSACTION_DATA);
// Handle the response here
}
}
** Direct Method Payments:**
mPOSHandler.setPOSInfoListener(new POSInfoListener() {
@Override
public void onPOSInfoReceived(final int command, final int status, final String description) {
// Handle the response here
}
@Override
public void onTransactionComplete(final TransactionData transactionData) {
// Handle the response here
}
});
POSHandler.getInstance().setTransactionClearedListener(new PosTransactionClearedListener() {
@Override
public void onComplete(int phStatus) {
// transaction is cleared and fully completed, terminal is ready for new operations
}
});
Refunds
Variant 1: Refund via Activity
mPOSHandler.openRefundActivity(
MainActivity.this /*activity*/,
REQUEST_CODE_MAKE_REFUND /*requestCode*/,
"10.50" /*amount*/,
UUID.randomUUID().toString()/*transaction reference*/
);
Variant 2: Refund via Direct Method
POSHandler.getInstance().refund(RefundParams.builder()
.refundAmount("13.37")
.currency("EUR")
.receiptConfiguration(POSHandler.RECEIPT_PRINT_AUTOMATICALLY)
.motoTransaction(false)
.build());
Handling results
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if( requestCode == REQUEST_CODE_MAKE_REFUND && resultCode == RESULT_OK) {
TransactionData transactionData = data.getParcelableExtra(POSHandler.INTENT_EXTRA_TRANSACTION_DATA);
// Handle the response here
}
}
mPOSHandler.setPOSInfoListener(new POSInfoListener() {
@Override
public void onPOSInfoReceived(final int command, final int status, final String description) {
// Handle the response here
}
@Override
public void onTransactionComplete(final TransactionData transactionData) {
// Handle the response here
}
});
POSHandler.getInstance().setTransactionClearedListener(new PosTransactionClearedListener() {
@Override
public void onComplete(int phStatus) {
// transaction is cleared and fully completed, terminal is ready for new operations
}
});
See more information in:
POS Info statuses
Pre-Authorization
Initiate Pre-authorization
POSHandler.getInstance().purchase(PaymentParams.builder()
.productAmount("13.37")
.receiptConfiguration(POSHandler.RECEIPT_PRINT_AUTOMATICALLY)
.reference("asd123asd", ReferenceType.REFERENCE_NUMBER)
.preauthTransaction(true)
.motoTransaction(false)
.build());
Complete Pre-authorization
POSHandler.getInstance().preAuthCompletion(PreauthorizationCompletionParams.builder()
.preauthorizationCode("1111")
.productAmount("13.37")
.build());
Cancel Pre-authorization
POSHandler.getInstance().preAuthCancellation(PreauthorizationCancellationParams.builder()
.preauthorizationCode("1111")
.build());
MO/TO Transactions
MO/TO Purchase
POSHandler.getInstance().purchase(PaymentParams.builder()
.productAmount("13.37")
.currency("EUR")
.tipAmount("1.55")
.receiptConfiguration(POSHandler.RECEIPT_PRINT_AUTOMATICALLY)
.operatorCode("1234")
.reference("asd123asd", ReferenceType.REFERENCE_NUMBER)
.preauthTransaction(false)
.motoTransaction(true)
.PAN("1234123412341234")
.expDate("1022")
.build());
MO/TO Refund
POSHandler.getInstance().refund(RefundParams.builder()
.refundAmount("13.37")
.currency("EUR")
.receiptConfiguration(POSHandler.RECEIPT_PRINT_AUTOMATICALLY)
.motoTransaction(true)
.PAN("1234123412341234")
.expDate("1022")
.build());
Void Transaction
Use this to reverse the last transaction:
POSHandler.getInstance().reversal(ReversalParams.builder()
.reason("enter reason text")
.build());
Receipt Management
Reprint Last Receipt
mPOSHandler.reprintReceipt();
Check if Terminal Has Printer
mPOSHandler.hasPrinter()
Print a Custom Receipt
ReceiptData receiptData = new ReceiptData();
receiptData.addLogo(1 /*Logo index*/);
receiptData.addEmptyRow();
receiptData.addRow(
"HEAD" /*text*/,
ReceiptData.Align.CENTER, /* Enum align setting (LEFT, CENTER, RIGHT) */
ReceiptData.FontSize.DOUBLE /* Enum font size setting (SINGLE, DOUBLE) */
);
mPOSHandler.printReceipt(receiptData);
Best Practices:
- Always handle
TransactionDatafor reconciliation and reporting. - Monitor the terminal's busy state using
isTerminalBusy()before sending a new request. - Use UUIDs or unique references for tracking transactions.