This repository provides a native Android SDK, which enables to integrate your Mobile App with myPOS Card terminals, processed by its platform, to accept card payments (including but not limited to VISA, Mastercard, UnionPay International, JCB, Bancontact). myPOS SDK Android communicates transparently to the card terminal(s) via Bluetooth. To process checkout SDK provides management of the terminal to complete all the steps for transaction processing, return or refund, card storage for recurring transactions, and communicates to the application transaction status, card token, card masked PAN.
No sensitive card data is ever passed through to or stored on the merchant's phone. All data is encrypted by the card terminal, which has been fully certified to the highest industry standards (PCI, EMV I & II, Visa, MasterCard & Amex).
- Merchant account on www.myPOS.eu (or received a test account).
- Received myPOS terminal
- Deployment Target Android 4.0.3 or later.
- Android SDK Platform 25 or later.
- Android SDK Build-tools version 25.0.0 or later.
- Android Device.
Add the repository to your gradle dependencies:
allprojects {
repositories {
mavenCentral()
}
}Add the dependency to a module:
implementation 'com.mypos:slavesdk:2.1.9'Initialize the MyPos components in your app:
public class SampleApplication extends Application {
private POSHandler mPOSHandler;
@Override
public void onCreate() {
super.onCreate();
POSHandler.setCurrency(Currency.EUR);
POSHandler.setApplicationContext(this);
mPOSHandler = POSHandler.getInstance();
}
}Optional setting for default receipt configuration:
POSHandler.setDefaultReceiptConfig(POSHandler.RECEIPT_PRINT_ONLY_MERCHANT_COPY);If set, the default receipt configuration can be removed:
POSHandler.clearDefaultReceiptConfig();Optional setting for the language of the receipts (default is Language.ENGLISH):
POSHandler.setLanguage(Language.GERMAN);Check if an operation is currently being performed:
POSHandler.getInstance().isTerminalBusy();Choose connection type:
POSHandler.setConnectionType(ConnectionType.BLUETOOTH); // Use ConnectionType.USB for USB connectionPOSHandler.getInstance().connectDevice(context);If connection type is set to BLUETOOTH, make sure the needed permissions are granted in order to discover available Bluetooth devices.
if (POSHandler.getInstance().checkPermissions(context)) {
// continue...
} else {
// permissions request is sent...
}Handle permissions result:
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == POSHandler.PERMISSIONS_REQUEST_CODE) {
// check permissions result...
}
}To connect directly to a known Bluetooth device by serial number:
POSHandler.getInstance().connectDevice(context, "DEVICE_SERIAL_NUMBER");To connect directly to a BluetoothDevice object:
POSHandler.getInstance().connectDevice(context, bluetoothDevice);To enable USB auto-reconnect on device attach/detach:
POSHandler.getInstance().connectDevice(context, true /*usbAutoReconnect*/);To unregister listeners and the USB receiver when done:
POSHandler.getInstance().unregisterListeners();POSHandler.setConnectionType(ConnectionType.TCP_IP);
POSHandler.setTcpIpConnectivity("192.168.1.100", 8080);
POSHandler.getInstance().connectDevice(context);mPOSHandler.setConnectionListener(new ConnectionListener() {
@Override
public void onConnected(final BluetoothDevice device) {
// handle connected event here
}
});To clear all registered connection listeners:
mPOSHandler.clearConnectionListeners();mPOSHandler.setPOSReadyListener(new POSReadyListener() {
@Override
public void onPOSReady() {
// now you can start a transaction
}
});In case you want to use email/phone receipt, choose POSHandler.RECEIPT_E_RECEIPT as receipt configuration.
The following listener will be fired immediately after the transaction is approved:
POSHandler.getInstance().setPOSCredentialsListener(new POSCredentialsListener() {
@Override
public void askForCredentials(final CredentialsListener listener) {
listener.onCredentialsSet("email@example.com"); // or a phone number
}
});You can configure a safety timeout for the e-receipt credential prompt (0 = no timeout):
POSHandler.setSafetyClearingTimeout(30000); // 30 secondsOnce initialization is completed, you can start using the myPOS SDK Android to accept card payments.
Amount and transaction reference are optional and can be null.
mPOSHandler.openPaymentActivity(
MainActivity.this /*activity*/,
REQUEST_CODE_MAKE_PAYMENT /*requestCode*/,
"10.50" /*amount*/,
UUID.randomUUID().toString() /*transaction reference*/
);PaymentParams paymentParams = PaymentParams.builder()
.productAmount("10.50") // required
.currency("EUR") // optional, defaults to POSHandler currency
.tranRef(UUID.randomUUID().toString()) // optional
.receiptConfiguration(POSHandler.RECEIPT_PRINT_AUTOMATICALLY) // optional
.tipAmount("1.00") // optional
.motoTransaction(false) // optional
.PAN("4111111111111111") // optional, for MOTO
.expDate("1228") // optional, for MOTO (MMYY)
.motoPassword("password") // optional, for MOTO
.operatorCode("OP01") // optional
.reference("REF123", ReferenceType.REFERENCE_NUMBER) // optional
.fixedPinpad(false) // optional
.applicationId("app-id") // optional
.build();
mPOSHandler.purchase(paymentParams);All available PaymentParams builder options:
| Method | Description |
|---|---|
productAmount(String) |
Required. The transaction amount. |
currency(String) |
ISO 4217 currency code (e.g. "EUR"). Defaults to the currency set via POSHandler.setCurrency(). |
tranRef(String) |
Optional transaction reference. |
receiptConfiguration(int) |
One of the RECEIPT_* constants. |
tipAmount(String) |
Optional tip amount added on top of the product amount. |
motoTransaction(boolean) |
Set to true for MOTO (Mail Order / Telephone Order) transactions. |
PAN(String) |
Card PAN for MOTO transactions. |
expDate(String) |
Card expiry date for MOTO transactions (format: MMYY). |
motoPassword(String) |
Password for MOTO transactions. |
operatorCode(String) |
Optional operator/cashier code. |
reference(String referenceNumber, int referenceType) |
Optional custom reference number and type (see ReferenceType). |
fixedPinpad(boolean) |
Lock the pinpad layout. |
applicationId(String) |
Optional application identifier. |
@Override
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
}
}mPOSHandler.setPOSInfoListener(new POSInfoListener() {
@Override
public void onPOSInfoReceived(final int command, final int status, final String description, final Bundle extra) {
// Handle status updates here
}
@Override
public void onTransactionComplete(final TransactionData transactionData) {
// Handle the completed transaction 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 POS Info statuses for more information.
With refund, the host application can initiate a refund transaction to the customer's card account.
Amount and transaction reference are optional and can be null.
mPOSHandler.openRefundActivity(
MainActivity.this /*activity*/,
REQUEST_CODE_MAKE_REFUND /*requestCode*/,
"10.50" /*amount*/,
UUID.randomUUID().toString() /*transaction reference*/
);RefundParams refundParams = RefundParams.builder()
.refundAmount("10.50") // required
.currency("EUR") // optional, defaults to POSHandler currency
.tranRef(UUID.randomUUID().toString()) // optional
.receiptConfiguration(POSHandler.RECEIPT_PRINT_AUTOMATICALLY) // optional
.motoTransaction(false) // optional
.PAN("4111111111111111") // optional, for MOTO
.expDate("1228") // optional, for MOTO (MMYY)
.password("password") // optional, for protected refunds
.fixedPinpad(false) // optional
.applicationId("app-id") // optional
.build();
mPOSHandler.refund(refundParams);All available RefundParams builder options:
| Method | Description |
|---|---|
refundAmount(String) |
Required. The refund amount. |
currency(String) |
ISO 4217 currency code. Defaults to the currency set via POSHandler.setCurrency(). |
tranRef(String) |
Optional transaction reference. |
receiptConfiguration(int) |
One of the RECEIPT_* constants. |
motoTransaction(boolean) |
Set to true for MOTO refunds. |
PAN(String) |
Card PAN for MOTO refunds. |
expDate(String) |
Card expiry date for MOTO refunds (format: MMYY). |
password(String) |
Optional password for protected refunds. |
fixedPinpad(boolean) |
Lock the pinpad layout. |
applicationId(String) |
Optional application identifier. |
@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
}
}See Handle payment result – Variant 2.
Preauthorization places a hold on funds without completing the transaction. The result returns a preAuthCode in TransactionData.getPreAuthCode().
mPOSHandler.openPreauthActivity(
MainActivity.this /*activity*/,
REQUEST_CODE_PREAUTH /*requestCode*/,
"10.50" /*amount*/,
UUID.randomUUID().toString() /*transaction reference*/
);PaymentParams preauthParams = PaymentParams.builder()
.productAmount("10.50") // required
.currency("EUR") // optional, defaults to POSHandler currency
.tranRef(UUID.randomUUID().toString()) // optional
.receiptConfiguration(POSHandler.RECEIPT_PRINT_AUTOMATICALLY) // optional
.tipAmount("1.00") // optional
.motoTransaction(false) // optional
.PAN("4111111111111111") // optional, for MOTO
.expDate("1228") // optional, for MOTO (MMYY)
.motoPassword("password") // optional, for MOTO
.operatorCode("OP01") // optional
.reference("REF123", ReferenceType.REFERENCE_NUMBER) // optional
.fixedPinpad(false) // optional
.applicationId("app-id") // optional
.preauthTransaction(true) // required for preauth
.build();
mPOSHandler.purchase(preauthParams);Completes a previously placed preauthorization hold.
PreauthorizationCompletionParams params = PreauthorizationCompletionParams.builder()
.productAmount("10.50") // required
.preauthorizationCode("PREAUTH_CODE_FROM_TRANSACTION_DATA") // required
.applicationId("app-id") // optional
.build();
mPOSHandler.preAuthCompletion(params);mPOSHandler.openPreauthCompletionActivity(
MainActivity.this,
REQUEST_CODE_PREAUTH_COMPLETION,
"10.50" /*amount*/,
"PREAUTH_CODE" /*preauth code*/
);Cancels a previously placed preauthorization hold.
PreauthorizationCancellationParams params = PreauthorizationCancellationParams.builder()
.preauthorizationCode("PREAUTH_CODE_FROM_TRANSACTION_DATA") // required
.applicationId("app-id") // optional
.build();
mPOSHandler.preAuthCancellation(params);mPOSHandler.openPreauthCancellationActivity(
MainActivity.this,
REQUEST_CODE_PREAUTH_CANCELLATION,
"PREAUTH_CODE" /*preauth code*/
);Reverses a previous transaction identified by a transaction reference.
ReversalParams params = ReversalParams.builder()
.tranRef("ORIGINAL_TRANSACTION_REFERENCE") // required
.reason("Customer request") // optional
.password("PASSWORD") // optional, if required
.applicationId("app-id") // optional
.build();
mPOSHandler.reversal(params);All available ReversalParams builder options:
| Method | Description |
|---|---|
tranRef(String) |
Reference of the transaction to reverse. |
reason(String) |
Optional reason for the reversal. |
password(String) |
Optional password if reversal is password-protected. |
applicationId(String) |
Optional application identifier. |
Sends a payment request to a customer via GSM or email.
PaymentRequestParams params = PaymentRequestParams.builder()
.productAmount("25.00") // required
.currency("EUR") // optional, defaults to POSHandler currency
.GSM("+359888123456") // optional, recipient phone (use GSM or eMail)
.eMail("customer@example.com") // optional, recipient email (use GSM or eMail)
.recipientName("John Doe") // optional
.reason("Invoice #1234") // optional
.expiryDays(3) // optional, days until request expires
.applicationId("app-id") // optional
.build();
mPOSHandler.paymentRequest(params);All available PaymentRequestParams builder options:
| Method | Description |
|---|---|
productAmount(String) |
Required. The requested amount. |
currency(String) |
ISO 4217 currency code. Defaults to the currency set via POSHandler.setCurrency(). |
GSM(String) |
Recipient's phone number. |
eMail(String) |
Recipient's email address. |
recipientName(String) |
Optional recipient name. |
reason(String) |
Optional payment reason / description. |
expiryDays(int) |
Optional number of days before the request expires. |
applicationId(String) |
Optional application identifier. |
Sends a reminder for a previously sent payment request.
PaymentRequestReminderParams params = PaymentRequestReminderParams.builder()
.requestCode("PAYMENT_REQUEST_CODE") // required
.GSM("+359888123456") // optional, use GSM or eMail
.eMail("customer@example.com") // optional, use GSM or eMail
.applicationId("app-id") // optional
.build();
mPOSHandler.paymentRequestReminder(params);All available PaymentRequestReminderParams builder options:
| Method | Description |
|---|---|
requestCode(String) |
Required. The code of the original payment request. |
GSM(String) |
Recipient's phone number. |
eMail(String) |
Recipient's email address. |
applicationId(String) |
Optional application identifier. |
Initiates a TWINT QR-code-based payment.
QRPaymentParams params = QRPaymentParams.builder()
.productAmount("10.50") // required
.currency("CHF") // optional, defaults to POSHandler currency
.transRef(UUID.randomUUID().toString()) // optional
.applicationId("app-id") // optional
.build();
mPOSHandler.twintPurchase(params);All available QRPaymentParams builder options:
| Method | Description |
|---|---|
productAmount(String) |
Required. The transaction amount. |
currency(String) |
ISO 4217 currency code. Defaults to the currency set via POSHandler.setCurrency(). |
transRef(String) |
Optional transaction reference. |
applicationId(String) |
Optional application identifier. |
Check if the connected myPOS device has printer hardware:
mPOSHandler.hasPrinter();mPOSHandler.giftcardActivation(
"50.00" /*amount*/,
"EUR" /*currency*/,
POSHandler.RECEIPT_PRINT_AUTOMATICALLY /*receipt type*/,
false /*fixedPinpad*/
);mPOSHandler.giftcardDeactivation();mPOSHandler.giftcardBalanceCheck();Cancels the current in-progress transaction:
mPOSHandler.cancelTransaction();Requests a reprint of the last transaction slip:
mPOSHandler.reprintReceipt();Printing a custom receipt is performed by passing a ReceiptData object to printReceipt():
ReceiptData receiptData = new ReceiptData();
receiptData.addLogo(1 /*Logo index*/);
receiptData.addEmptyRow();
receiptData.addRow(
"HEAD" /*text*/,
ReceiptData.Align.CENTER, /* LEFT, CENTER, RIGHT */
ReceiptData.FontSize.DOUBLE /* SINGLE, DOUBLE */
);
mPOSHandler.printReceipt(receiptData);Before using the terminal for the first time, the SDK must initiate terminal activation to set up the Terminal ID, Merchant ID, etc.
mPOSHandler.activate();mPOSHandler.update();mPOSHandler.deactivate();mPOSHandler.checkConnection();Retrieves the data of the last processed transaction:
mPOSHandler.getLastTransactionData();Checks whether a password is required before performing a given transaction type:
mPOSHandler.checkForPassword(TransactionData.TransactionType.REFUND);
// Available types: REFUND, REVERSAL, MOTOSends the terminal log to myPOS support:
mPOSHandler.sendLog();mPOSHandler.openSettings();Clears the current batch of transactions:
mPOSHandler.clearBatch();mPOSHandler.rebootPOS();String terminalId = POSHandler.getTerminalID();-
POS_STATUS_PENDING_USER_INTERACTION POS terminal received Purchase or Refund operation. Waiting for user to provide card.
-
POS_STATUS_USER_CANCEL Current operation terminated because the user cancelled it on the POS terminal.
-
POS_STATUS_INTERNAL_ERROR Current operation terminated due to an internal error.
-
POS_STATUS_TERMINAL_BUSY Current operation terminated because the POS terminal is busy with another operation.
-
POS_STATUS_UNSUPPORTED_SDK_VERSION Current operation terminated because the terminal version is not compatible with this SDK version.
-
POS_STATUS_NO_UPDATE_FOUND Update operation terminated because no update is available.
-
POS_STATUS_MANDATORY_UPDATE Current operation terminated due to a mandatory update. Update is performed automatically.
-
POS_STATUS_OPTIONAL_UPDATE An optional update is available for the POS terminal.
-
POS_STATUS_POS_UPDATING Terminal received an Update operation and started the procedure.
-
POS_STATUS_ACTIVATION_REQUIRED Current operation terminated because the terminal is not activated.
-
POS_STATUS_PROCESSING A communication with the host is in progress (Purchase, Refund, Activate or Deactivate).
-
POS_STATUS_DEACTIVATION_NOT_COMPLETED Deactivate operation finished unsuccessfully.
-
POS_STATUS_ACTIVATION_NOT_REQUIRED Activate operation terminated because the terminal is already activated.
-
POS_STATUS_ACTIVATION_NOT_COMPLETED Activate operation finished unsuccessfully.
-
POS_STATUS_WRONG_ACTIVATION_CODE Activate operation terminated due to wrong activation code.
-
POS_STATUS_WRONG_DEACTIVATION_CODE Deactivate operation terminated due to wrong deactivation code.
-
POS_STATUS_WAIT_ACTIVATION_CODE Terminal received Activate operation and is waiting for the activation code.
-
POS_STATUS_WAIT_DEACTIVATION_CODE Terminal received Deactivate operation and is waiting for the deactivation code.
-
POS_STATUS_UPDATE_NOT_COMPLETED Update operation finished unsuccessfully.
-
POS_STATUS_TRANSACTION_NOT_FOUND Reprint last receipt: last transaction not found.
-
POS_STATUS_NO_PRINTER_AVAILABLE Print/Reprint terminated because the POS device has no printer hardware.
-
POS_STATUS_NO_PAPER Print/Reprint terminated due to no paper in the printer.
-
POS_STATUS_WRONG_AMOUNT Current operation terminated due to invalid amount.
-
POS_STATUS_NO_CARD_FOUND Current operation terminated because no card was presented.
-
POS_STATUS_NOT_SUPPORTED_CARD The presented card is not supported.
-
POS_STATUS_CARD_CHIP_ERROR Current operation terminated due to card chip reading failure.
-
POS_STATUS_INVALID_PIN Invalid PIN. Terminal is waiting for another PIN attempt.
-
POS_STATUS_MAX_PIN_COUNT_EXCEEDED Current operation terminated because the maximum wrong PIN count has been exceeded.
-
POS_STATUS_PIN_CHECK_ONLINE PIN validation is being performed online. Operation continues.
-
POS_STATUS_SUCCESS_ACTIVATION Activate operation finished successfully.
-
POS_STATUS_SUCCESS_DEACTIVATION Deactivate operation finished successfully.
-
POS_STATUS_SUCCESS_UPDATE Update operation finished successfully.
-
POS_STATUS_SUCCESS_PURCHASE Purchase operation finished successfully.
-
POS_STATUS_SUCCESS_REFUND Refund operation finished successfully.
-
POS_STATUS_SUCCESS_REPRINT_RECEIPT Reprint last receipt operation finished successfully.
-
POS_STATUS_SUCCESS_PRINT_RECEIPT Print operation finished successfully.
-
POS_STATUS_DOWNLOADING_CERTIFICATES_IN_PROGRESS The SDK is downloading certificates from the POS terminal.
-
POS_STATUS_DOWNLOADING_CERTIFICATES_COMPLETED Certificate download completed successfully.
-
POS_STATUS_INCORRECT_PRINT_DATA Print operation terminated due to incorrect print data.
-
POS_STATUS_INCORRECT_LOGO_INDEX Print operation terminated due to incorrect logo index.
-
POS_STATUS_INVALID_OR_MISSING_PREAUTH_CODE Preauth completion/cancellation terminated due to invalid or missing preauth code.
-
POS_STATUS_INVALID_PREAUTH_AMOUNT Preauth completion terminated due to invalid amount.
-
POS_STATUS_PREAUTH_TRAN_BEEN_COMPLETED Preauth completion terminated because the preauth has already been completed.
-
POS_STATUS_SUCCESS_PREAUTH Preauthorization operation finished successfully.
-
POS_STATUS_SUCCESS_PREAUTH_COMPLETION Preauth completion operation finished successfully.
-
POS_STATUS_SUCCESS_PREAUTH_CANCELLATION Preauth cancellation operation finished successfully.
-
POS_STATUS_REVERSING_TRANSACTION A reversal operation is in progress.
-
POS_STATUS_SUCCESS_REVERSAL Reversal operation finished successfully.
-
POS_STATUS_REVERSAL_NOT_FOUND Reversal operation terminated because the referenced transaction was not found.
-
POS_STATUS_GIFTCARD_ACTIVATING Gift card activation is in progress.
-
POS_STATUS_GIFTCARD_DEACTIVATING Gift card deactivation is in progress.
-
POS_STATUS_GIFTCARD_BALANCE_CHECK Gift card balance check is in progress.
-
POS_STATUS_SUCCESS_GIFTCARD_ACTIVATION Gift card activation finished successfully.
-
POS_STATUS_SUCCESS_GIFTCARD_DEACTIVATION Gift card deactivation finished successfully.
-
POS_STATUS_SUCCESS_GIFTCARD_BALANCE_CHECK Gift card balance check finished successfully.
-
POS_STATUS_WRONG_TIPPING_AMOUNT Current operation terminated due to an invalid tip amount.
-
POS_STATUS_WRONG_PASSWORD Current operation terminated due to a wrong password.
-
POS_STATUS_INVALID_OPERATOR_CODE Current operation terminated due to an invalid operator code.
-
POS_STATUS_INVALID_REFERENCE_NUMBER_TYPE Current operation terminated due to an invalid reference number type.
-
POS_STATUS_INVALID_REFERENCE_NUMBER Current operation terminated due to an invalid reference number.
-
POS_STATUS_PREAUTH_NOT_SUPPORTED_PARAM Preauthorization operation terminated due to an unsupported parameter.
-
POS_STATUS_PAYMENT_REQUEST_WRONG_RECIPIENT Payment request terminated due to an invalid recipient.
-
POS_STATUS_PAYMENT_REQUEST_INVALID_EXP_DAYS Payment request terminated due to invalid expiry days.
-
POS_STATUS_PAYMENT_INVALID_REQUEST_CODE Payment request reminder terminated due to an invalid request code.
-
POS_STATUS_TRANSACTION_FORBIDDEN Current operation is not permitted.
-
POS_STATUS_SUCCESS_PING Ping (connection check) finished successfully.
-
POS_STATUS_PING_FAILED Ping (connection check) failed.
-
POS_STATUS_PRESENT_CARD_SCREEN Terminal is displaying the "Present Card" screen.
-
POS_STATUS_SELECT_DCC_SCREEN Terminal is displaying the DCC (Dynamic Currency Conversion) selection screen.
-
POS_STATUS_ENTER_PIN_SCREEN Terminal is displaying the PIN entry screen.
-
POS_STATUS_DCC_BEEN_SELECTED DCC option has been selected by the cardholder.
-
POS_STATUS_PASSWORD_REQUIRED A password is required to complete the operation.
-
POS_STATUS_COM_ERROR A communication error occurred.
-
POS_STATUS_UNKNOWN An unknown status was received.
-
POS_INVALID_APPLICATION_ID Current operation terminated due to an invalid application ID.