Skip to content

Commit

Permalink
Refactor Giving payment method
Browse files Browse the repository at this point in the history
  • Loading branch information
gcatanese committed Feb 9, 2024
1 parent 5ca422b commit 67df8c7
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +32,7 @@ public class CheckoutResource {
private final ApplicationProperty applicationProperty;

private final PaymentsApi paymentsApi;
private final DonationsApi donationsApi;

public CheckoutResource(ApplicationProperty applicationProperty) {

Expand All @@ -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);
}


Expand All @@ -63,15 +66,15 @@ public ResponseEntity<DonationPaymentResponse> 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());
donationRequest.returnUrl(request.getScheme() + "://" + host);
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) {
Expand Down

0 comments on commit 67df8c7

Please sign in to comment.