receipts - AEVI-AppFlow/pos-android-sdk GitHub Wiki
Receipts are typically generated for any payment flow, but there are scenarios where client applications may want to initiate specific receipt requests.
If the merchant and/or customer needs a receipt to get redelivered (via whatever delivery mechanism the receipt app on that device uses, such as printing), the client application can initiate a receiptDelivery
request. For this type of request. The request will contain information from the previous transaction which will be sent along with the request as additional data.
// First, retrieve the previous transaction to use for the request
Transaction transaction = paymentResponse.getTransactions().get(desiredTxnIndex);
Request request = new Request("receiptDelivery");
request.addAdditionalData("transaction", transaction);
// If the receipt handling application supports more than one delivery mechanism
request.addAdditionalData("deliveryMechanism", "printing");
If the merchant and/or customer needs a receipt for a non-card based payment e.g. cash. Then a request can be made with different additional data that can fulfil this type of request.
Request request = new Request("receiptDelivery");
request.addAdditionalData("receiptAmounts", new Amounts(15000, "EUR"));
request.addAdditionalData("receiptPaymentMethod", "cash");
request.addAdditionalData("receiptOutcome", "APPROVED");
Optionally a basket can also be added to the request using the key "receiptBasket" e.g.
Basket basket = new Basket();
// populate basket
request.addAdditionalData("receiptBasket", basket);
Receipt delivery flow services should ensure that they handle both types of request described above for re-delivery of a receipt as well as receipts for non-card based payments.
AdditionalData requestData = genericStageModel.getRequest().getRequestData();
if (requestData.hasData("transaction")) {
Transaction transaction = requestData.getValue("transaction", Transaction.class);
// If you want to re-use functionality in your application from printing payment transactions.
// You may want to create your own `TransactionSummary` object at this point from the `Transaction` e.g.
TransactionSummary transactionSummary = new TransactionSummary(transaction,
"receiptDelivery", DeviceAudience.CUSTOMER, transaction.getLastResponse().getCard()))
// handle printing of transactionSummary here
else if (requestData.hasData("receiptPaymentMethod")) {
Amounts amounts = requestData.getValue("receiptAmounts", Amounts.class);
String paymentMethod = requestData.getStringValue("receiptPaymentMethod");
String outcome = requestData.getStringValue("receiptOutcome");
// handle printing from the above fields here
}
// If the receipt was successfully delivered, outcome should be `true`, and `false` otherwise.
Response response = new Response(request, <outcome>, <outcome message>);
// Setting the delivery mechanism is optional but may be useful for the client application
response.addAdditionalData("deliveryMechanism", "printing");
if (response.wasSuccessful()) {
// Handle success
} else {
// Handle failure
}