Once the SDK is added to your project, using the Payment API can be done with the provided helper classes.
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())
.build();
// 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
}
Refund
1. Perform the refund
// Build the refund request
MyPOSRefund refund = MyPOSRefund.builder()
.refundAmount(1.23)
.currency(Currency.EUR)
.foreignTransactionId(UUID.randomUUID().toString())
.build();
// Start the transaction
MyPOSAPI.openRefundActivity(MainActivity.this, refund, 2);
2. Handle the result
The same as with the payment, in your calling Activity, override the onActivityResult
method to handle the result of the refund:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// The same request code as when calling MyPOSAPI.openRefundActivity
if (requestCode == 2) {
// 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, "Refund 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();
}
}
}
Payment Request
This functionality allows a merchant to create a payment request and send it as an SMS directly from a myPOS Smart device.
1. Perform Payment Request
// Build the payment request transaction
private static final int PAYMENT_REQUEST_REQUEST_CODE = 4;
private void startPaymentRequest() {
// Build the payment request
MyPOSPaymentRequest paymentRequest = MyPOSPaymentRequest.builder()
.productAmount(3.55)
.currency(Currency.EUR)
.expiryDays(60)
.recipientName("John Doe")
.GSM("0899070087")
.eMail("")
.reason("System test")
.build();
// Start the payment request transaction
MyPOSAPI.createPaymentRequest(MainActivity.this, paymentRequest, PAYMENT_REQUEST_REQUEST_CODE);
}
2. Handle the result
The same as with the payment, in your calling Activity, override the onActivityResult
method to handle the result of the Payment request:
@Override
void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PAYMENT_REQUEST_REQUEST_CODE) {
// 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 request 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();
}
}
}