Broadleaf Microservices
  • v1.0.0-latest-prod

MyFatoorah Authorize Transaction

Prerequisites

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

Executing an Authorize Transaction

Note

MyFatoorah does not support webhook notifications for Authorize transactions. Due to the risk of the Broadleaf ecosystem not being aware of transaction results, we suggest using AuthorizeAndCapture transactions.

By default, MyFatoorah is configured to use separate Authorize and Capture interactions (MyFatoorah docs here). If you wish to enable AuthorizeAndCapture transactions (i.e. Authorize and Capture in a single request), then you must request this configuration via the MyFatoorah team. Keep in mind that if this change is made, you won’t be able to execute Authorize transactions.

@RequiredArgsConstructor
public class Authorize {

 private final MyFatoorahTransactionService myFatoorahTransactionService;

 public void performAuthorization() {
		 CurrencyUnit currency = Monetary.getCurrency(currencyCode);
		 MonetaryAmount transactionTotal = Monetary.getDefaultAmountFactory().setCurrency(currency).setNumber(amount).create();

		 PaymentRequest paymentRequest = new PaymentRequest()
		        .transactionReferenceId(transactionReferenceId)
		        .transactionTotal(transactionTotal)
		        .additionalField("sessionId", sessionId); // The sessionId which we got from MyFatoorah init session endpoint.

	 	PaymentResponse paymentResponse = myFatoorahTransactionService.authorize(paymentRequest);

		paymentResponse.isSuccessful();
		paymentResponse.getGatewayResponseCode(); // The MyFatoorah response code
		paymentResponse.getFailureType(); // Failure type in case the transaction was not successful.
	   	paymentResponse.getRawResponse(); // MyFatoorah raw response stored as a JSON object.
		paymentResponse.getGatewayTransactionId(); // gatewayTransactionId from MyFatoorah.
		paymentResponse.getGatewayTransactionType(); // gateway transaction type.
		paymentResponse.getResponseMap().get("invoiceId"); // MyFatoorah invoiceId which will be used to execute subsequent reverse-authorize, capture, and/or refund transactions.
	   	paymentResponse.getResponseMap().get("paymentId"); // MyFatoorah paymentId.
	   	paymentResponse.getResponseMap().get("paymentGateway"); // MyFatoorah paymentGateway.
	   	paymentResponse.getResponseMap().get("transactionId");  // MyFatoorah transactionId.
	}
}

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()