@RequiredArgsConstructor
public class Refund {
private final MyFatoorahTransactionService myFatoorahTransactionService;
public void performRefund() {
CurrencyUnit currency = Monetary.getCurrency(currencyCode);
MonetaryAmount transactionTotal = Monetary.getDefaultAmountFactory().setCurrency(currency).setNumber(amount).create();
PaymentRequest paymentRequest = new PaymentRequest()
.transactionReferenceId(transactionReferenceId)
.transactionTotal(transactionTotal)
.additionalField("invoiceId", invoiceId); // The invoiceId from the Capture transaction.
PaymentResponse paymentResponse = myFatoorahTransactionService.refund(paymentRequest);
paymentResponse.isSuccessful();
paymentResponse.isAwaitingAsyncResults(); // Often MyFatoorah refund transactions are placed into a pending state because they must be manually reviewed by the MyFatoorah team. In this case, #isAwaitingAsyncResults() will be set to true.
paymentResponse.getGatewayResponseCode(); // The MyFatoorah response code
paymentResponse.getFailureType(); // Failure type in case the transaction was not successful.
paymentResponse.getGatewayTransactionId();
paymentResponse.getRawResponse(); // MyFatoorah raw response stored as a JSON object.
paymentResponse.getResponseMap().get("REFUND_ID"); // The MyFatoorah refund ID.
paymentResponse.getResponseMap().get("REFUND_REFERENCE"); // The MyFatoorah refund reference.
}
}