@RequiredArgsConstructor
public class AuthAndCapture {
private final MyFatoorahTransactionService myFatoorahTransactionService;
public void performAuthorizeAndCapture() {
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.authorizeAndCapture(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(); // MyFatoorah gateway transaction type.
paymentResponse.getResponseMap().get("invoiceId"); // MyFatoorah invoiceId which will be used to execute subsequent refund transactions.
paymentResponse.getResponseMap().get("paymentId"); // MyFatoorah paymentId.
paymentResponse.getResponseMap().get("paymentGateway"); // MyFatoorah paymentGateway.
paymentResponse.getResponseMap().get("transactionId"); // MyFatoorah transactionId.
}
}