Skip to content

Commit

Permalink
Merge pull request #1 from Affirm/shifting_to_1905
Browse files Browse the repository at this point in the history
uploading 1905 compatible
  • Loading branch information
ninersontherize authored Mar 29, 2022
2 parents 7e5e4b1 + adaf83e commit 9fc70e4
Show file tree
Hide file tree
Showing 385 changed files with 4,393 additions and 50 deletions.
14 changes: 14 additions & 0 deletions bin/modules/affirm/affirmpaymentaddon/.springBeans
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<beansProjectDescription>
<version>1</version>
<pluginVersion><![CDATA[3.4.0.201310051539-RELEASE]]></pluginVersion>
<configSuffixes>
<configSuffix><![CDATA[xml]]></configSuffix>
</configSuffixes>
<enableImports><![CDATA[true]]></enableImports>
<configs>
<config>resources/affirmpaymentaddon-spring.xml</config>
</configs>
<configSets>
</configSets>
</beansProjectDescription>
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public AffirmOrderTrackingResult orderConfirmation(@PathVariable("orderCode") fi
{
final String productCode = entry.getProduct().getCode();
final ProductData product = productFacade.getProductForCodeAndOptions(productCode,
Arrays.asList(ProductOption.BASIC, ProductOption.PRICE, ProductOption.CATEGORIES));
Arrays.asList(ProductOption.BASIC, ProductOption.PRICE, ProductOption.CATEGORIES, ProductOption.CLASSIFICATION));
entry.setProduct(product);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ public String saveBillingAddress(final HttpServletRequest request,
}

@RequestMapping(value = "/authorise", method = {RequestMethod.POST,RequestMethod.GET})
public String authorise(@RequestParam(name = "checkout_token", required = false) final String checkoutToken,
public String authorise(@RequestParam(required=false) final String checkout_token,
final Model model, final RedirectAttributes redirectModel) {

boolean success = false;

try
{
success = affirmPaymentFacade.authorisePayment(checkoutToken);
success = affirmPaymentFacade.authorisePayment(checkout_token);
}
catch (RuntimeException re)
{
Expand Down Expand Up @@ -130,8 +130,8 @@ public String authorise(@RequestParam(name = "checkout_token", required = false)

@ResponseBody
@RequestMapping(value = "/refund", method = {RequestMethod.POST,RequestMethod.GET})
public String refundOrder(@RequestParam(name = "order_id", required = false) final String orderId,
@RequestParam(name = "refund_amount", required = false) final Double refundAmount,
public String refundOrder(@RequestParam("order_id") final String orderId,
@RequestParam("refund_amount") final Double refundAmount,
final Model model, final RedirectAttributes redirectModel) {

if(!affirmPaymentFacade.isAffirmPaymentEnabled()){
Expand All @@ -157,7 +157,7 @@ public String refundOrder(@RequestParam(name = "order_id", required = false) fin

@ResponseBody
@RequestMapping(value = "/capture", method = {RequestMethod.POST,RequestMethod.GET})
public String captureOrder(@RequestParam(name = "order_id", required = false) final String orderId,
public String captureOrder(@RequestParam("order_id") final String orderId,
final Model model, final RedirectAttributes redirectModel) {

if(!affirmPaymentFacade.isAffirmPaymentEnabled()){
Expand All @@ -178,7 +178,7 @@ public String captureOrder(@RequestParam(name = "order_id", required = false) fi

@ResponseBody
@RequestMapping(value = "/void", method = {RequestMethod.POST,RequestMethod.GET})
public String voidOrder(@RequestParam(name = "order_id", required = false) final String orderId,
public String voidOrder(@RequestParam("order_id") final String orderId,
final Model model, final RedirectAttributes redirectModel) {

if(!affirmPaymentFacade.isAffirmPaymentEnabled()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import de.hybris.platform.servicelayer.config.ConfigurationService;
import de.hybris.platform.servicelayer.dto.converter.ConversionException;
import de.hybris.platform.site.BaseSiteService;
import de.hybris.platform.variants.model.VariantProductModel;

import java.math.BigInteger;
import java.util.HashMap;
Expand All @@ -41,9 +42,6 @@

public class AffirmCheckoutDataPopulator implements Populator<CartModel, AffirmCheckoutData> {

public static final String FINAL = "final";
public static final String DR_MARTENS = "Dr. Martens";

public static final String CHECKOUT_AFFIRM_CANCEL_URL = "/checkout/affirm/cancel";
public static final String CHECKOUT_AFFIRM_CONFIRMATION_URL = "/checkout/affirm/authorise";

Expand Down Expand Up @@ -77,7 +75,7 @@ public class AffirmCheckoutDataPopulator implements Populator<CartModel, AffirmC

checkoutData.setOrder_id(cartModel.getCode());
checkoutData.setShipping_amount(convertToBigInteger(cartModel.getDeliveryCost()));
checkoutData.setTaxAmount(convertToBigInteger(cartModel.getTotalTax()));
checkoutData.setTax_amount(convertToBigInteger(cartModel.getTotalTax()));

checkoutData.setTotal(convertToBigInteger(cartModel.getTotalIncludingTax()));

Expand Down Expand Up @@ -161,7 +159,7 @@ private String getCouponCode(final PromotionResultModel promo)
AbstractRuleBasedPromotionActionModel promoAction = (AbstractRuleBasedPromotionActionModel) action;
if(CollectionUtils.isNotEmpty(promoAction.getUsedCouponCodes()))
{
promoAction.getUsedCouponCodes().stream().collect(Collectors.joining(","));
return promoAction.getUsedCouponCodes().stream().collect(Collectors.joining(","));
}
}
}
Expand Down Expand Up @@ -194,14 +192,33 @@ private void populateItems(CartModel cartModel, AffirmCheckoutData checkoutData)
if(entry.getProduct().getThumbnail() != null) {
itemData.setItem_image_url(entry.getProduct().getThumbnail().getURL());
}
//ToDo-BE - where categories should we populate from
itemData.setCategories(new String[]{"Home", "Bedroom"});
itemData.setCategories(getCategories(entry.getProduct()));
items[index++] = itemData;
}
checkoutData.setItems(items);
}
}

private String[] getCategories(final ProductModel product)
{
if(CollectionUtils.isNotEmpty(product.getSupercategories()))
{
return product.getSupercategories().stream().map(categoryModel -> categoryModel.getName())
.collect(Collectors.toList()).toArray(new String[product.getSupercategories().size()]);
}

if(product instanceof VariantProductModel){
ProductModel baseProduct = ((VariantProductModel) product).getBaseProduct();
if (CollectionUtils.isNotEmpty(baseProduct.getSupercategories()))
{
return baseProduct.getSupercategories().stream().map(categoryModel -> categoryModel.getName())
.collect(Collectors.toList()).toArray(new String[baseProduct.getSupercategories().size()]);
}
}

return null;
}

private BigInteger convertToBigInteger(Double doubleValue) {
return BigInteger.valueOf(Double.valueOf(doubleValue * 100.0).longValue());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
package com.affirm.payment.converter;

import com.affirm.checkout.pojo.AffirmOrderItemTracking;
import com.affirm.checkout.pojo.AffirmOrderTracking;
import com.affirm.checkout.pojo.AffirmOrderTrackingResult;
import de.hybris.platform.commercefacades.order.data.OrderData;
import de.hybris.platform.commercefacades.order.data.OrderEntryData;
import de.hybris.platform.commercefacades.product.data.ClassificationData;
import de.hybris.platform.commercefacades.product.data.FeatureData;
import de.hybris.platform.commercefacades.product.data.ProductData;
import de.hybris.platform.converters.Populator;
import de.hybris.platform.servicelayer.dto.converter.ConversionException;
import de.hybris.platform.servicelayer.i18n.CommonI18NService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.Optional;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.util.Assert;

import com.affirm.checkout.pojo.AffirmOrderItemTracking;
import com.affirm.checkout.pojo.AffirmOrderTracking;
import com.affirm.checkout.pojo.AffirmOrderTrackingResult;

public class AffirmOrderTrackingDataPopulator implements Populator<OrderData, AffirmOrderTrackingResult> {

public static final String AFFIRM = "Affirm";
@Resource private CommonI18NService commonI18NService;

@Override public void populate(OrderData source, AffirmOrderTrackingResult target) throws ConversionException {
Expand Down Expand Up @@ -50,6 +59,14 @@ private AffirmOrderTracking convertOrderDetails(OrderData source, String coupon)
orderTracking.setStoreName(source.getStore());
orderTracking.setTax(multiply100(source.getTotalTax().getValue()));
orderTracking.setTotal(multiply100(source.getTotalPriceWithTax().getValue()));
orderTracking.setCheckoutId(source.getGuid());
if(source.getPaymentInfo() != null && source.getPaymentInfo().getCardType() != null ){
orderTracking.setPaymentMethod(source.getPaymentInfo().getCardType());
}else{
orderTracking.setPaymentMethod(AFFIRM);
}


return orderTracking;
}

Expand All @@ -70,9 +87,30 @@ private AffirmOrderItemTracking[] convertOrderItems(OrderData source, String cou
item.setPrice(multiply100(entry.getBasePrice().getValue()));
item.setProductId(entry.getProduct().getCode());
item.setQuantity(entry.getQuantity());
item.setBrand(entry.getProduct().getManufacturer());
item.setCurrency(source.getTotalPrice().getCurrencyIso());
item.setVariant(getColour(entry.getProduct()));
if(CollectionUtils.isNotEmpty(entry.getProduct().getCategories())){
item.setCategory(entry.getProduct().getCategories().iterator().next().getName());
}
items[i] = item;
}
return items;
}

private String getColour(final ProductData product)
{
if(product.getClassifications() != null){
Optional<ClassificationData> colourOp = product.getClassifications().stream().filter(c -> "Colour".equals(c.getName())).findAny();
if(colourOp.isPresent()){
ClassificationData classificationData = colourOp.get();
if(CollectionUtils.isNotEmpty(classificationData.getFeatures())){
FeatureData featureData = classificationData.getFeatures().iterator().next();
return Optional.ofNullable(featureData.getFeatureValues()).orElse(Collections.emptyList()).stream().map(f -> f.getValue()).collect(Collectors.joining(","));
}
}
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<spring:theme code="text.voucher.apply.input.placeholder" var="voucherInputPlaceholder" htmlEscape="false"/>
<label class="control-label cart-voucher__label" for="voucher-code"><spring:theme
code="text.voucher.apply.input.label"/></label>
<form:form id="applyVoucherForm" action="${applyVoucherAction}" method="post" commandName="voucherForm">
<form:form id="applyVoucherForm" action="${applyVoucherAction}" method="post" modelAttribute="voucherForm">
<form:input cssClass="js-voucher-code cart-voucher__input form-control input-sm" name="voucher-code"
id="js-voucher-code-text" maxlength="100" placeholder="${voucherInputPlaceholder}"
path="voucherCode" disabled="${disableUpdate}"/>
Expand All @@ -43,7 +43,7 @@
<c:forEach items="${cartData.appliedVouchers}" var="voucher" varStatus="loop">
<li class="voucher-list__item">
<form:form id="removeVoucherForm${loop.index}" action="${removeVoucherAction}" method="post"
commandName="voucherForm">
modelAttribute="voucherForm">
<span class="js-release-voucher voucher-list__item-box" id="voucher-code-${fn:escapeXml(voucher)}">
${fn:escapeXml(voucher)}
<form:input hidden="hidden" value="${fn:escapeXml(voucher)}" path="voucherCode"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<%@ tag body-content="empty" trimDirectiveWhitespaces="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="product" tagdir="/WEB-INF/tags/responsive/product"%>
<%@ taglib prefix="cms" uri="http://hybris.com/tld/cmstags"%>
<%@ taglib prefix="ycommerce" uri="http://hybris.com/tld/ycommercetags"%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<spring:htmlEscape defaultHtmlEscape="true" />

<form:form id="silentOrderPostForm" class="js-card-payment" name="silentOrderPostForm" commandName="sopPaymentDetailsForm" action="${paymentFormUrl}" method="POST" >
<form:form id="silentOrderPostForm" class="js-card-payment" name="silentOrderPostForm" modelAttribute="sopPaymentDetailsForm" action="${paymentFormUrl}" method="POST" >
<c:forEach items="${sopPaymentDetailsForm.parameters}" var="entry" varStatus="status">
<input type="hidden" id="${fn:escapeXml(entry.key)}" name="${fn:escapeXml(entry.key)}" value="${fn:escapeXml(entry.value)}"/>
</c:forEach>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<button type="button" class="js-affirm-payment btn btn-primary btn-block js-affirm-pay-button" data-vcnmode="${affirmVcnMode}">Checkout with affirm</button>
</c:when>
<c:otherwise>
<form:form action="${placeOrderUrl}" id="placeOrderForm1" commandName="placeOrderForm">
<form:form action="${placeOrderUrl}" id="placeOrderForm1" modelAttribute="placeOrderForm">
<div class="checkbox">
<label> <form:checkbox id="Terms1" path="termsCheck" />
<spring:theme var="termsAndConditionsHtml" code="checkout.summary.placeOrder.readTermsAndConditions" arguments="${fn:escapeXml(getTermsAndConditionsUrl)}" htmlEscape="false"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</c:if>

<c:if test="${not empty paymentFormUrl}">
<form:form id="silentOrderPostForm" class="js-card-payment" name="silentOrderPostForm" commandName="sopPaymentDetailsForm" action="${paymentFormUrl}" method="POST" >
<form:form id="silentOrderPostForm" class="js-card-payment" name="silentOrderPostForm" modelAttribute="sopPaymentDetailsForm" action="${paymentFormUrl}" method="POST" >
<div >
<input type="hidden" name="orderPage_receiptResponseURL" value="${fn:escapeXml(silentOrderPageData.parameters['orderPage_receiptResponseURL'])}"/>
<input type="hidden" name="orderPage_declineResponseURL" value="${fn:escapeXml(silentOrderPageData.parameters['orderPage_declineResponseURL'])}"/>
Expand Down Expand Up @@ -151,7 +151,7 @@
</ycommerce:testId>

<c:if test="${not empty affirmAddressFormUrlFull}">
<form:form id="affirmAddressForm" class="js-affirm-payment " name="affirmAddressForm" commandName="affirmAddressForm" action="${affirmAddressFormUrlFull}" method="POST" data-modalmode="${affirmModalMode}" data-vcnmode="${affirmVcnMode}">
<form:form id="affirmAddressForm" class="js-affirm-payment " name="affirmAddressForm" modelAttribute="affirmAddressForm" action="${affirmAddressFormUrlFull}" method="POST" data-modalmode="${affirmModalMode}" data-vcnmode="${affirmVcnMode}">
<formElement:formCheckbox
path="useDeliveryAddress"
idKey="affirmUseDeliveryAddress"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Mon, 10 Dec 2018 16:53:46 +0100
#Fri, 17 Jan 2020 10:20:13 +0000
# -----------------------------------------------------------------------
# [y] hybris Platform
#
Expand Down Expand Up @@ -26,13 +26,3 @@ affirmpaymentaddon.css.paths.responsive=/responsive/common/css/affirmpaymentaddo
yacceleratorstorefront.additionalWebSpringConfigs.affirmpaymentaddon=classpath\:/affirmpaymentaddon/web/spring/affirmpaymentaddon-web-spring.xml

yacceleratorstorefront.wro4jconfigscan.affirmpaymentaddon=true

affirm.merchant.name=Hybris - Affirm plugin
affirm.authorisation.endpoint=BASE_URL/api/v2/charges
affirm.capture.endpoint=BASE_URL/api/v2/charges/CHARGE_ID/capture
affirm.refund.endpoint=BASE_URL/api/v2/charges/CHARGE_ID/refund
affirm.void.endpoint=BASE_URL/api/v2/charges/CHARGE_ID/void
affirm.update.endpoint=BASE_URL/api/v2/charges/CHARGE_ID/update

#To disable debug mode for Affirm payment please change this configuration parameter to info
log4j.logger.com.affirm.payment=debug
Loading

0 comments on commit 9fc70e4

Please sign in to comment.