Skip to content

Commit

Permalink
AD-295 Refactor Private Methods to Protected for Enhanced Class Exten…
Browse files Browse the repository at this point in the history
…sibility
  • Loading branch information
pjaneta committed Sep 4, 2024
1 parent 85dbf71 commit 5469cdd
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ public void preHandlePlaceOrder(PaymentRequest paymentRequest, String adyenPayme
});
}

private static void saveBrowserInfoOnPaymentInfo(BrowserInfo browserInfo, PaymentInfoModel paymentInfo) {
protected static void saveBrowserInfoOnPaymentInfo(BrowserInfo browserInfo, PaymentInfoModel paymentInfo) {
if (browserInfo != null) {
paymentInfo.setAdyenBrowserInfo(getBrowserInfoJson(browserInfo));
}
}

private static String getBrowserInfoJson(BrowserInfo browserInfo) {
protected static String getBrowserInfoJson(BrowserInfo browserInfo) {
try {
return browserInfo.toJson();
} catch (JsonProcessingException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public String execute(final OrderProcessModel process) {
return processOrderAuthorization(process, order);
}

private boolean isTransactionAuthorized(final PaymentTransactionModel paymentTransactionModel) {
protected boolean isTransactionAuthorized(final PaymentTransactionModel paymentTransactionModel) {
for (final PaymentTransactionEntryModel entry : paymentTransactionModel.getEntries()) {
if (entry.getType().equals(PaymentTransactionType.AUTHORIZATION)
&& TransactionStatus.ACCEPTED.name().equals(entry.getTransactionStatus())) {
Expand All @@ -85,7 +85,7 @@ private boolean isTransactionAuthorized(final PaymentTransactionModel paymentTra
return false;
}

private String processOrderAuthorization(final OrderProcessModel process, final OrderModel order) {
protected String processOrderAuthorization(final OrderProcessModel process, final OrderModel order) {
//No transactions means that is not authorized yet
if (order.getPaymentTransactions() == null || order.getPaymentTransactions().isEmpty()) {
LOG.debug("Process: " + process.getCode() + " Order Waiting");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public CaptureResult perform(final CaptureRequest request) {
return result;
}

private CaptureResult createCaptureResultFromRequest(CaptureRequest request) {
protected CaptureResult createCaptureResultFromRequest(CaptureRequest request) {
CaptureResult result = new CaptureResult();

result.setCurrency(request.getCurrency());
Expand All @@ -126,7 +126,7 @@ private CaptureResult createCaptureResultFromRequest(CaptureRequest request) {
return result;
}

private boolean supportsManualCapture(String paymentMethod) {
protected boolean supportsManualCapture(String paymentMethod) {
switch (paymentMethod) {
case "cup":
case "cartebancaire":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public PaymentResponse convert(SaleToPOIResponse saleToPOIResponse) {
/*
* Parse base64 encoded additionalResponse and return as a name/value map
*/
private Map<String, String> parseAdditionalResponse(String additionalResponse) {
protected Map<String, String> parseAdditionalResponse(String additionalResponse) {
Map<String, String> additionalData = new HashMap<>();
if (StringUtils.isNotEmpty(additionalResponse)) {
String decodedAdditionalResponse = new String(Base64.getDecoder().decode(additionalResponse), StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public PaymentDetailsWsDTO addPaymentDetails(PaymentDetailsWsDTO paymentDetails)
}


private AddressModel createBillingAddress(PaymentDetailsWsDTO paymentDetails) {
protected AddressModel createBillingAddress(PaymentDetailsWsDTO paymentDetails) {
String titleCode = paymentDetails.getBillingAddress().getTitleCode();
final AddressModel billingAddress = getModelService().create(AddressModel.class);
if (StringUtils.isNotBlank(titleCode)) {
Expand Down Expand Up @@ -377,7 +377,7 @@ public PaymentDetailsResponse handleRedirectPayload(PaymentCompletionDetails det
return response;
}

private void updateOrderPaymentStatusAndInfo(OrderModel orderModel, PaymentDetailsResponse paymentDetailsResponse) {
protected void updateOrderPaymentStatusAndInfo(OrderModel orderModel, PaymentDetailsResponse paymentDetailsResponse) {

if (PaymentDetailsResponse.ResultCodeEnum.RECEIVED != paymentDetailsResponse.getResultCode()) {
//payment authorisation is finished, update payment info
Expand Down Expand Up @@ -501,7 +501,7 @@ public PaymentDetailsResponse componentDetails(PaymentDetailsRequest detailsRequ
return response;
}

private void updateCartWithSessionData(CartData cartData) {
protected void updateCartWithSessionData(CartData cartData) {
cartData.setAdyenCseToken(getSessionService().getAttribute(SESSION_CSE_TOKEN));
cartData.setAdyenEncryptedCardNumber(getSessionService().getAttribute(SESSION_SF_CARD_NUMBER));
cartData.setAdyenEncryptedExpiryMonth(getSessionService().getAttribute(SESSION_SF_EXPIRY_MONTH));
Expand Down Expand Up @@ -560,7 +560,7 @@ protected OrderData createAuthorizedOrder(final PaymentResponse paymentsResponse
return createOrderFromPaymentResponse(paymentsResponse);
}

private void updateAdyenSelectedReferenceIfPresent(final CartModel cartModel, final PaymentResponse paymentsResponse) {
protected void updateAdyenSelectedReferenceIfPresent(final CartModel cartModel, final PaymentResponse paymentsResponse) {
Map<String, String> additionalData = paymentsResponse.getAdditionalData();
if (additionalData != null) {
String recurringDetailReference = additionalData.get(RECURRING_RECURRING_DETAIL_REFERENCE);
Expand All @@ -573,7 +573,7 @@ private void updateAdyenSelectedReferenceIfPresent(final CartModel cartModel, fi
/**
* Create order
*/
private OrderData createOrderFromPaymentResponse(final PaymentResponse paymentsResponse) throws InvalidCartException {
protected OrderData createOrderFromPaymentResponse(final PaymentResponse paymentsResponse) throws InvalidCartException {
LOGGER.debug("Create order from paymentsResponse: " + paymentsResponse.getPspReference());

OrderData orderData = getCheckoutFacade().placeOrder();
Expand Down Expand Up @@ -613,7 +613,7 @@ protected OrderData placePendingOrder(String resultCode) throws InvalidCartExcep
return orderData;
}

private OrderData placeAuthorisedOrder(PaymentResponse.ResultCodeEnum resultCode) throws InvalidCartException {
protected OrderData placeAuthorisedOrder(PaymentResponse.ResultCodeEnum resultCode) throws InvalidCartException {
CartModel cartModel = getCartService().getSessionCart();
cartModel.setStatus(OrderStatus.PAYMENT_AUTHORIZED);
cartModel.setStatusInfo(resultCode.getValue());
Expand Down Expand Up @@ -905,28 +905,28 @@ public CheckoutConfigDTO getCheckoutConfig() throws ApiException {
}

@Deprecated
private static boolean isSepaDirectDebit(List<PaymentMethod> alternativePaymentMethods) {
protected static boolean isSepaDirectDebit(List<PaymentMethod> alternativePaymentMethods) {
return alternativePaymentMethods.stream().
anyMatch(paymentMethod -> !paymentMethod.getType().isEmpty() &&
PAYMENT_METHOD_SEPA_DIRECTDEBIT.contains(paymentMethod.getType()));
}

private static void updateCartWithAmazonPay(PaymentMethod amazonPayMethod, CartModel cartModel) {
protected static void updateCartWithAmazonPay(PaymentMethod amazonPayMethod, CartModel cartModel) {
Map<String, String> amazonPayConfiguration = amazonPayMethod.getConfiguration();
if (!CollectionUtils.isEmpty(amazonPayConfiguration)) {
cartModel.setAdyenAmazonPayConfiguration(amazonPayConfiguration);
}
}

private static Optional<PaymentMethod> getAmazonPayMethod(List<PaymentMethod> alternativePaymentMethods) {
protected static Optional<PaymentMethod> getAmazonPayMethod(List<PaymentMethod> alternativePaymentMethods) {
return alternativePaymentMethods.stream()
.filter(paymentMethod -> !paymentMethod.getType().isEmpty()
&& PAYMENT_METHOD_AMAZONPAY.contains(paymentMethod.getType()))
.findFirst();
}

@Deprecated
private static void updateIssuerList(List<PaymentMethod> issuerPaymentMethods, Map<String, String> issuerLists) {
protected static void updateIssuerList(List<PaymentMethod> issuerPaymentMethods, Map<String, String> issuerLists) {
if (!CollectionUtils.isEmpty(issuerPaymentMethods)) {
Gson gson = new Gson();
for (PaymentMethod paymentMethod : issuerPaymentMethods) {
Expand All @@ -936,7 +936,7 @@ private static void updateIssuerList(List<PaymentMethod> issuerPaymentMethods, M
}

@Deprecated
private static List<PaymentMethod> getIssuerPaymentMethods(List<PaymentMethod> alternativePaymentMethods) {
protected static List<PaymentMethod> getIssuerPaymentMethods(List<PaymentMethod> alternativePaymentMethods) {
if (alternativePaymentMethods != null) {
return alternativePaymentMethods.stream()
.filter(paymentMethod -> !paymentMethod.getType().isEmpty() && ISSUER_PAYMENT_METHODS.contains(paymentMethod.getType()))
Expand All @@ -946,15 +946,15 @@ private static List<PaymentMethod> getIssuerPaymentMethods(List<PaymentMethod> a
return Collections.emptyList();
}

private PaymentMethodsResponse getPaymentMethods(AdyenCheckoutApiService adyenPaymentService, CartData cartData, CustomerModel customerModel) throws IOException, ApiException {
protected PaymentMethodsResponse getPaymentMethods(AdyenCheckoutApiService adyenPaymentService, CartData cartData, CustomerModel customerModel) throws IOException, ApiException {
return adyenPaymentService.getPaymentMethodsResponse(cartData.getTotalPriceWithTax().getValue(),
cartData.getTotalPriceWithTax().getCurrencyIso(),
cartData.getDeliveryAddress().getCountry().getIsocode(),
getShopperLocale(),
customerModel.getCustomerID());
}

private PaymentMethodsResponse getPaymentMethods(AdyenCheckoutApiService adyenPaymentService, CartData cartData, CustomerModel customerModel, List<String> excludedPaymentMethods) throws IOException, ApiException {
protected PaymentMethodsResponse getPaymentMethods(AdyenCheckoutApiService adyenPaymentService, CartData cartData, CustomerModel customerModel, List<String> excludedPaymentMethods) throws IOException, ApiException {
return adyenPaymentService.getPaymentMethodsResponse(cartData.getTotalPriceWithTax().getValue(),
cartData.getTotalPriceWithTax().getCurrencyIso(),
cartData.getDeliveryAddress().getCountry().getIsocode(),
Expand All @@ -963,7 +963,7 @@ private PaymentMethodsResponse getPaymentMethods(AdyenCheckoutApiService adyenPa
}


private Map<String, String> getApplePayConfigFromPaymentMethods(List<PaymentMethod> paymentMethods) {
protected Map<String, String> getApplePayConfigFromPaymentMethods(List<PaymentMethod> paymentMethods) {
if (paymentMethods != null) {
Optional<PaymentMethod> applePayMethod = paymentMethods.stream()
.filter(paymentMethod -> !paymentMethod.getType().isEmpty()
Expand All @@ -980,7 +980,7 @@ private Map<String, String> getApplePayConfigFromPaymentMethods(List<PaymentMeth
return new HashMap<>();
}

private CreateCheckoutSessionResponse getAdyenSessionData() throws ApiException {
protected CreateCheckoutSessionResponse getAdyenSessionData() throws ApiException {
try {
final CartData cartData = getCheckoutFacade().getCheckoutCart();
return getAdyenPaymentService().getPaymentSessionData(cartData);
Expand All @@ -993,7 +993,7 @@ private CreateCheckoutSessionResponse getAdyenSessionData() throws ApiException
}
}

private CreateCheckoutSessionResponse getAdyenSessionData(Amount amount) throws ApiException {
protected CreateCheckoutSessionResponse getAdyenSessionData(Amount amount) throws ApiException {
try {
return getAdyenPaymentService().getPaymentSessionData(amount);
} catch (JsonProcessingException e) {
Expand Down Expand Up @@ -1061,7 +1061,7 @@ public void initializeApplePayExpressPDPData(Model model, ProductData productDat
initializeApplePayExpressDataInternal(amountValue, currencyIso, model);
}

private void initializeApplePayExpressDataInternal(BigDecimal amountValue, String currency, Model model) throws ApiException {
protected void initializeApplePayExpressDataInternal(BigDecimal amountValue, String currency, Model model) throws ApiException {
final BaseStoreModel baseStore = baseStoreService.getCurrentBaseStore();

try {
Expand Down Expand Up @@ -1095,7 +1095,7 @@ private void initializeApplePayExpressDataInternal(BigDecimal amountValue, Strin
model.addAttribute(MODEL_CHECKOUT_SHOPPER_HOST, getCheckoutShopperHost());
}

private BigDecimal getExpressDeliveryModeValue(final String currencyIso) {
protected BigDecimal getExpressDeliveryModeValue(final String currencyIso) {
Optional<ZoneDeliveryModeValueModel> expressDeliveryModePrice = adyenExpressCheckoutFacade.getExpressDeliveryModePrice();

BigDecimal deliveryValue = BigDecimal.ZERO;
Expand All @@ -1112,7 +1112,7 @@ private BigDecimal getExpressDeliveryModeValue(final String currencyIso) {
return deliveryValue;
}

private String setLocale(final Map<String, String> map, final String shopperLocale) {
protected String setLocale(final Map<String, String> map, final String shopperLocale) {
if (Objects.nonNull(map) && !map.get(REGION).isBlank() && map.get(REGION).equals(US)) {
return US_LOCALE;
} else {
Expand All @@ -1131,7 +1131,7 @@ private String setLocale(final Map<String, String> map, final String shopperLoca
}
}

private boolean isHiddenPaymentMethod(PaymentMethod paymentMethod) {
protected boolean isHiddenPaymentMethod(PaymentMethod paymentMethod) {
String paymentMethodType = paymentMethod.getType();

if (paymentMethodType == null || paymentMethodType.isEmpty() ||
Expand All @@ -1148,7 +1148,7 @@ private boolean isHiddenPaymentMethod(PaymentMethod paymentMethod) {
return false;
}

private List<StoredPaymentMethod> getStoredOneClickPaymentMethods(PaymentMethodsResponse response) {
protected List<StoredPaymentMethod> getStoredOneClickPaymentMethods(PaymentMethodsResponse response) {
List<StoredPaymentMethod> storedPaymentMethodList = null;
if (response.getStoredPaymentMethods() != null) {
storedPaymentMethodList = response.getStoredPaymentMethods().stream()
Expand Down Expand Up @@ -1496,7 +1496,7 @@ public OrderData checkPosPaymentStatus(HttpServletRequest request, CartData cart
throw new AdyenNonAuthorizedPaymentException(terminalApiResponse);
}

private boolean isPosTimedOut(HttpServletRequest request) {
protected boolean isPosTimedOut(HttpServletRequest request) {
long currentTime = System.currentTimeMillis();
long processStartTime = (long) request.getAttribute("paymentStartTime");
int totalTimeout = ((int) request.getAttribute("totalTimeout")) * 1000;
Expand Down Expand Up @@ -1550,7 +1550,7 @@ protected OrderModel retrievePendingOrder(String orderCode) throws InvalidCartEx
return orderModel;
}

private void restoreCartFromOrder(String orderCode) throws CalculationException, InvalidCartException {
protected void restoreCartFromOrder(String orderCode) throws CalculationException, InvalidCartException {
LOGGER.info("Restoring cart from order");

OrderModel orderModel = getOrderRepository().getOrderModel(orderCode);
Expand Down Expand Up @@ -1606,7 +1606,7 @@ private void restoreCartFromOrder(String orderCode) throws CalculationException,
getCalculationService().calculate(cartModel);
}

private boolean hasUserContextChanged(OrderModel orderModel, CartModel cartModel) {
protected boolean hasUserContextChanged(OrderModel orderModel, CartModel cartModel) {
return !orderModel.getUser().equals(cartModel.getUser())
|| !orderModel.getStore().equals(cartModel.getStore());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,15 @@ public void removeDeliveryModeFromSessionCart() throws CalculationException {
}
}

private void prepareCart(CartModel cart, DeliveryModeModel deliveryMode, AddressModel addressModel, PaymentInfoModel paymentInfo) {
protected void prepareCart(CartModel cart, DeliveryModeModel deliveryMode, AddressModel addressModel, PaymentInfoModel paymentInfo) {
cart.setDeliveryMode(deliveryMode);
cart.setDeliveryAddress(addressModel);
cart.setPaymentAddress(addressModel);
cart.setPaymentInfo(paymentInfo);
modelService.save(cart);
}

private AddressModel prepareAddressModel(AddressData addressData, CustomerModel user) {
protected AddressModel prepareAddressModel(AddressData addressData, CustomerModel user) {
AddressModel addressModel = modelService.create(AddressModel.class);
addressReverseConverter.convert(addressData, addressModel);
validateParameterNotNull(addressModel, "Empty address");
Expand All @@ -203,7 +203,7 @@ private AddressModel prepareAddressModel(AddressData addressData, CustomerModel
return addressModel;
}

private void addProductToCart(String productCode, CartModel cart) {
protected void addProductToCart(String productCode, CartModel cart) {
ProductModel product = productService.getProductForCode(productCode);

if (product != null) {
Expand All @@ -219,13 +219,13 @@ public Optional<ZoneDeliveryModeValueModel> getExpressDeliveryModePrice() {
return deliveryMode.getValues().stream().filter(valueModel -> valueModel.getCurrency().equals(currentCurrency)).findFirst();
}

private CustomerModel createGuestCustomer(String emailAddress) throws DuplicateUidException {
protected CustomerModel createGuestCustomer(String emailAddress) throws DuplicateUidException {
Assert.isTrue(EmailValidator.getInstance().isValid(emailAddress), "Invalid email address");

return createGuestUserForAnonymousCheckout(emailAddress, USER_NAME);
}

private CustomerModel createGuestUserForAnonymousCheckout(final String email, final String name) throws DuplicateUidException {
protected CustomerModel createGuestUserForAnonymousCheckout(final String email, final String name) throws DuplicateUidException {
validateParameterNotNullStandardMessage("email", email);
final CustomerModel guestCustomer = modelService.create(CustomerModel.class);
final String guid = customerFacade.generateGUID();
Expand All @@ -242,14 +242,14 @@ private CustomerModel createGuestUserForAnonymousCheckout(final String email, fi
return guestCustomer;
}

private CartModel createCartForExpressCheckout(CustomerModel guestUser) {
protected CartModel createCartForExpressCheckout(CustomerModel guestUser) {
CartModel cart = cartFactory.createCart();
cart.setUser(guestUser);
modelService.save(cart);
return cart;
}

private PaymentInfoModel createPaymentInfoForCart(CustomerModel customerModel, AddressModel addressModel, CartModel cartModel, String paymentMethod, String merchantId, String merchantName) {
protected PaymentInfoModel createPaymentInfoForCart(CustomerModel customerModel, AddressModel addressModel, CartModel cartModel, String paymentMethod, String merchantId, String merchantName) {
final PaymentInfoModel paymentInfo = modelService.create(PaymentInfoModel.class);
paymentInfo.setUser(customerModel);
paymentInfo.setCode(generateCcPaymentInfoCode(cartModel));
Expand All @@ -268,7 +268,7 @@ protected String generateCcPaymentInfoCode(final CartModel cartModel) {
return cartModel.getCode() + "_" + UUID.randomUUID();
}

private boolean cartHasEntries(CartModel cartModel) {
protected boolean cartHasEntries(CartModel cartModel) {
return cartModel != null && !CollectionUtils.isEmpty(cartModel.getEntries());
}

Expand Down
Loading

0 comments on commit 5469cdd

Please sign in to comment.