@RequiredArgsConstructor
public class Refund {
private final StripeTransactionService stripeTransactionService;
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("PAYMENT_INTENT_ID", paymentIntentIdToRefund); // The PaymentIntent Id from the Capture transaction.
PaymentResponse paymentResponse = stripeTransactionService.refund(paymentRequest);
paymentResponse.isSuccessful();
paymentResponse.getGatewayResponseCode(); // The Stripe response code
paymentResponse.getFailureType(); // Failure type in case the transaction was not successful.
paymentResponse.getRawResponse(); // Stripe raw response stored as a JSON object.
paymentResponse.getResponseMap().get("TRANSACTION_ID"); // The Stripe Charge ID.
paymentResponse.getResponseMap().get("PAYMENT_INTENT_ID"); // The Stripe Payment Intent ID.
paymentResponse.getResponseMap().get("ERROR_CODE"); // The Stripe error response code.
paymentResponse.getResponseMap().get("ERROR_MESSAGE"); // The Stripe error message.
}
}