Refunds
The myPOS Glass SDK also allows you to issue refunds for previous transactions. Similar to processing a payment, refunds are handled via helper classes and the onActivityResult mechanism.
1. Perform a Refund
To initiate a refund, use the MyPOSRefund builder:
// Build the refund request
MyPOSRefund refund = MyPOSRefund.builder()
// Mandatoy parameters
.refundAmount(1.23)
.currency(Currency.EUR)
.foreignTransactionId(UUID.randomUUID().toString())
// Set receipt mode if printer is paired
.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();
// Start the transaction
MyPOSAPI.openRefundActivity(MainActivity.this, refund, 2);
Tip: The foreignTransactionId should be unique to help track and reconcile transactions.
2. Handle the Refund Result
Just like with payments, override the onActivityResult() method in your calling activity to capture 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();
}
}
}