Broadleaf Microservices
  • v1.0.0-latest-prod

MyFatoorah Refund Transaction

Prerequisites

Before performing a Refund transaction with the MyFatoorah gateway, you’ll first need to set up your environment as described in the Environment Setup Guide.

Executing a Refund Transaction

@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.
	}
}
Note
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. In this case, webhooks are used to listen for RefundStatusChanged events to determine & record the result of the refund.

To set additional fields in the PaymentRequest, use method

PaymentRequest.additionalField(key, value)

To get values from responseMap, use

PaymentResponse.getResponseMap().get(key, value)

To get the transaction reference ID from response:

PaymentResponse.getTransactionReferenceId()

To get the Broadleaf Payment ID from the response:

PaymentResponse.getPaymentId()