Once the SDK is added to your project, using the Payment API can be done with the provided helper classes.
Receive POS info
Add this to your AndroidManifest.xml file:
<queries>
<package android:name="com.mypos" />
</queries>
Here you can find simple info about myPOS terminal like TID, currency name, currency code, merchant info, etc.
MyPOSAPI.registerPOSInfo(MainActivity.this, new OnPOSInfoListener() {
@Override
public void onReceive(POSInfo info) {
//info is received
}
});
Make the payment
1. Make the payment
// Build the payment call
MyPOSPayment payment = MyPOSPayment.builder()
// Mandatory parameters
.productAmount(13.37)
.currency(Currency.EUR)
// Foreign transaction ID. Maximum length: 128 characters
.foreignTransactionId(UUID.randomUUID().toString())
// Optional parameters
// Enable tipping mode
.tippingModeEnabled(true)
.tipAmount(1.55)
// Operator code. Maximum length: 4 characters
.operatorCode("1234")
// Reference number. Maximum length: 50 alpha numeric characters
.reference("asd123asd", ReferenceType.REFERENCE_NUMBER)
// Enable fixed pinpad keyboard
.fixedPinpad(true)
// Enable mastercard and visa branding video
.mastercardSonicBranding(true)
.visaSensoryBranding(true)
// Set print receipt mode
.printMerchantReceipt(MyPOSUtil.RECEIPT_ON) // possible options RECEIPT_ON, RECEIPT_OFF
.printCustomerReceipt(MyPOSUtil.RECEIPT_ON) // possible options RECEIPT_ON, RECEIPT_OFF, RECEIPT_AFTER_CONFIRMATION, RECEIPT_E_RECEIPT
//set email or phone e-receipt receiver, works with customer receipt configuration RECEIPT_E_RECEIPT or RECEIPT_AFTER_CONFIRMATION
.ereceiptreceiver("examplename@example.com")
.build();
// If you want to initiate a moto transaction:
payment.setMotoTransaction(true)
// Or you want to initiate a giftcard transaction:
payment.setGiftCardTransaction(true)
// Start the transaction
MyPOSAPI.openPaymentActivity(MainActivity.this, payment, 1);
2. Handle the result
In your calling Activity, override the onActivityResult
method to handle the result of the payment:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// The same request code as when calling MyPOSAPI.openPaymentActivity
if (requestCode == 1) {
// The transaction was processed, handle the response
if (resultCode == RESULT_OK) {
// Something went wrong in the Payment core app and the result couldn't be returned properly
if (data == null) {
Toast.makeText(this, "Transaction cancelled", Toast.LENGTH_SHORT).show();
return;
}
int transactionResult = data.getIntExtra("status", TransactionProcessingResult.TRANSACTION_FAILED);
Toast.makeText(this, "Payment transaction has completed. Result: " + transactionResult, Toast.LENGTH_SHORT).show();
// TODO: handle each transaction response accordingly
if (transactionResult == TransactionProcessingResult.TRANSACTION_SUCCESS) {
// Transaction is successful
}
} else {
// The user cancelled the transaction
Toast.makeText(this, "Transaction cancelled", Toast.LENGTH_SHORT).show();
}
}
}
Checking if the transaction is approved can be done by reading the transaction_approved
boolean extra from the response:
boolean transaction_approved = data.getBooleanExtra("transaction_approved", false);
if (transaction_approved) {
// Transaction is approved
} else {
// Transaction was not approved
// The response code is in the "response_code" string extra
}