From 67df8c70c33b428ad73e5b29a15b594097bae414 Mon Sep 17 00:00:00 2001 From: Beppe Catanese Date: Fri, 9 Feb 2024 17:12:55 +0100 Subject: [PATCH] Refactor Giving payment method --- .../main/java/com/adyen/giving/api/CheckoutResource.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/giving-example/src/main/java/com/adyen/giving/api/CheckoutResource.java b/giving-example/src/main/java/com/adyen/giving/api/CheckoutResource.java index 165f8c1..6e433d0 100644 --- a/giving-example/src/main/java/com/adyen/giving/api/CheckoutResource.java +++ b/giving-example/src/main/java/com/adyen/giving/api/CheckoutResource.java @@ -5,6 +5,7 @@ import com.adyen.enums.Environment; import com.adyen.giving.util.DonationUtil; import com.adyen.model.checkout.*; +import com.adyen.service.checkout.DonationsApi; import com.adyen.service.checkout.PaymentsApi; import com.adyen.service.exception.ApiException; import jakarta.servlet.http.HttpServletRequest; @@ -31,6 +32,7 @@ public class CheckoutResource { private final ApplicationProperty applicationProperty; private final PaymentsApi paymentsApi; + private final DonationsApi donationsApi; public CheckoutResource(ApplicationProperty applicationProperty) { @@ -43,6 +45,7 @@ public CheckoutResource(ApplicationProperty applicationProperty) { var client = new Client(applicationProperty.getApiKey(), Environment.TEST); this.paymentsApi = new PaymentsApi(client); + this.donationsApi = new DonationsApi(client); } @@ -63,7 +66,7 @@ public ResponseEntity donations(@RequestBody Amount bod donationRequest.amount(body); donationRequest.reference(UUID.randomUUID().toString()); - donationRequest.setPaymentMethod(new DonationPaymentMethod(new CardDetails())); + donationRequest.setPaymentMethod(new DonationPaymentMethod(new CardDonations())); donationRequest.setDonationToken(donationToken); donationRequest.donationOriginalPspReference(pspReference); donationRequest.setDonationAccount(this.applicationProperty.getDonationMerchantAccount()); @@ -71,7 +74,7 @@ public ResponseEntity donations(@RequestBody Amount bod donationRequest.setMerchantAccount(this.applicationProperty.getMerchantAccount()); donationRequest.shopperInteraction(DonationPaymentRequest.ShopperInteractionEnum.CONTAUTH); - DonationPaymentResponse result = this.paymentsApi.donations(donationRequest); + DonationPaymentResponse result = this.donationsApi.donations(donationRequest); return ResponseEntity.ok().body(result); } catch (NotFoundException e) {