Skip to content

Commit

Permalink
SFCC Clearpay v24.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ghatamehta-afterpay committed Feb 9, 2024
1 parent 9a63995 commit 5fcfdcc
Show file tree
Hide file tree
Showing 331 changed files with 314 additions and 332 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ var checkoutTools = {

if (basket && basket.getAllProductLineItems().length > 0) {
var orderTotal = basket.totalGrossPrice.available ? basket.totalGrossPrice : basket.getAdjustedMerchandizeTotalPrice(true).add(basket.giftCertificateTotalPrice);
withinTheshold = thresholdUtilities.checkThreshold(orderTotal).status && !this.checkRestrictedCart();
withinTheshold = thresholdUtilities.checkThreshold(orderTotal).status && this.getCartData().cpCartEligible;
}

return withinTheshold;
Expand All @@ -171,7 +171,7 @@ var checkoutTools = {
}
var orderTotal = basket.totalGrossPrice.available ? basket.totalGrossPrice : basket.getAdjustedMerchandizeTotalPrice(true).add(basket.giftCertificateTotalPrice);

return thresholdUtilities.checkThreshold(orderTotal).status && !this.checkRestrictedCart();
return thresholdUtilities.checkThreshold(orderTotal).status && this.getCartData().cpCartEligible;
},
// compute a checksum from the Clearpay Response
// if anything changed
Expand All @@ -192,8 +192,13 @@ var checkoutTools = {
Logger.debug('Final Checksum' + cksum);
return cksum;
},
checkRestrictedCart: function () {
getCartData: function () {
var currentBasket = BasketMgr.getCurrentBasket();
var cartData = {
cpCartEligible: true
};

var cartProductIds = [];
if (currentBasket && currentBasket.getAllProductLineItems().length > 0) {
var productLineItems = currentBasket.getAllProductLineItems().iterator();
var ProductMgr = require('dw/catalog/ProductMgr');
Expand All @@ -207,14 +212,15 @@ var checkoutTools = {
}

if (product) {
var reqProductID = product.ID;
if (this.checkRestrictedProducts(reqProductID)) {
return true;
if (cartData.cpCartEligible && this.checkRestrictedProducts(product.ID)) {
cartData.cpCartEligible = false;
}
cartProductIds.push(product.ID);
}
}
}
return false;
cartData.cpProductIDs = cartProductIds.join(',');
return cartData;
},
checkRestrictedProducts: function (reqProductID) {
var cpSitePreferences = require('*/cartridge/scripts/util/clearpayUtilities').sitePreferencesUtilities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var Context = function () {
this.actionEndpointMap = {
getPayment: 'payments/{0}',
directCapturePayment: 'payments/capture',
getConfiguration: 'configuration?include=cbt&include=publicId',
getConfiguration: 'configuration?include=cbt&include=publicId&include=consumerLending',
createRefund: 'payments/{0}/refund',
authorise: 'payments/auth',
createOrders: 'checkouts',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function getClearpayHttpService() {
service.setRequestMethod(requestBody.requestMethod);
service.addHeader('Content-Type', 'application/json');

var clearpayCartridge = 'ClearpayCartridge/23.4.1';
var clearpayCartridge = 'ClearpayCartridge/24.1.0';
var merchantID = service.configuration.credential.user;
var siteURL = URLUtils.httpsHome().toString();
var storeFront = Site.getCurrent().getID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ var sitePreferencesUtilities = {
isExpressCheckoutPdpEnabled: function () {
return Site.getCurrent().getCustomPreferenceValue('cpEnableExpressCheckoutPdp');
},

isExpressCheckoutCartEnabled: function () {
return Site.getCurrent().getCustomPreferenceValue('cpEnableExpressCheckoutCart');
},
getRestrictedProducts: function () {
var excludedProducts = Site.getCurrent().getCustomPreferenceValue('cpRestrictedProducts');
var clearpayRestrictedProducts = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,10 @@ var thresholdUtilities = {
return result;
},
getThresholdResult: function (price) {
result.status = false;

if (price) {
var threshold = this.getThresholdAmounts();
var isApplicable = brandUtilities.isClearpayApplicable();
if (isApplicable) {
result.minThresholdAmount = threshold.minAmount;
result.maxThresholdAmount = threshold.maxAmount;
result.mpid = threshold.mpid;

if (price >= threshold.minAmount && price <= threshold.maxAmount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function getWidget(updatedProductID, updatedPrice, className, $productContainer)
/**
* @description Update widget for PDP specifically
*/
function updatePpdWidget() {
function updatePdpWidget() {
var productID = $('.product-id').text();
var productPrice = $('.prices-add-to-cart-actions .prices .price .sales .value').attr('content');
var productContainer = $('.product-detail');
Expand Down Expand Up @@ -67,7 +67,7 @@ $(document).ready(function () {
var cartTotal = '';

$('body').on('product:afterAttributeSelect', function () {
updatePpdWidget();
updatePdpWidget();
});

$(document).ajaxStart(function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
'use strict';

/**
* Updates Checkout Widget HTML
*/
function updateCheckoutWidget() {
var getUpdatedWidgetUrl = $('.checkout-widget').val();
$.ajax({
url: getUpdatedWidgetUrl,
method: 'GET',
success: function (data) {
if (data.updatedWidget) {
$('.clearpay-checkout-widget').html(data.updatedWidget);
$('.clearpay-checkout-widget').show();
}
},
error: function () {
$('.clearpay-checkout-widget').hide();
}
});
}

/**
* Updates the clearpay express checkout widget with the total value
* which should be located in the element '.grand-total-sum'
Expand All @@ -13,11 +33,7 @@ function updateExpressWidget() {
grandTotalSum = Number(grandTotalSum.replace(/[^0-9\.-]+/g, '')).toString();
$('#clearpay-widget-amount').val(grandTotalSum);
$('#clearpay-widget-currency').val(currency);
if ('clearpayWidget' in window) {
clearpayWidget.update({
amount: { amount: grandTotalSum, currency: currency }
});
}
updateCheckoutWidget();
}

module.exports.updateExpressWidget = updateExpressWidget;
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,20 @@ function handleStateChange() {
} else {
$('.ap-checkout-pay-notab-noecf').removeClass('clearpay-hide');
}
$(document).ajaxComplete(function () {
if (ecFinalize) {
if (typeof createClearpayWidget === 'function' && typeof AfterPay != 'undefined' && !('clearpayWidget' in window)) {
createClearpayWidget();
}
}
});
} else if (stage === 'placeOrder') {
var isClearpayPayment = $('#clearpay-payment-shown').length;

hideAllStates();
if (typeof createClearpayWidget === 'function' && typeof AfterPay != 'undefined' && !('clearpayWidget' in window)) {
createClearpayWidget();
}
if (isClearpayPayment) {
$('.ap-checkout-po-ecf').removeClass('clearpay-hide');
} else {
Expand Down Expand Up @@ -120,10 +130,6 @@ var exports = {
tabelemObserver.observe(tabelem, { attributes: true });
}

if (typeof createClearpayWidget === 'function') {
createClearpayWidget();
}

// Handle place-order button click
$('#clearpay-placeorder-button').on('click', function () {
if (typeof clearpayWidget !== 'undefined') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ $screen_width : 767px;
font-size: 0.85em;
}

.clearpay-image {
vertical-align: middle;
width: 7em;
margin: 5px 0;
}

.pdp-clearpay-message {
padding-top: 0.625em;
padding-bottom: 1.0625em;
Expand Down Expand Up @@ -241,3 +235,6 @@ $screen_width : 767px;
display: block;
}

img.clearpay-checkout-logo {
content: url('https://static.afterpay.com/integration/checkout/logo-clearpay-colour-131x25.png');
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@charset "UTF-8";

@import "~base/homePage";
@import "~base/global";

.clearpay-checkout-button {
background-color: #000;
Expand All @@ -16,3 +16,9 @@
display: none !important;
}

img.clearpay-image {
vertical-align: middle;
width: 7em;
margin: 5px 0;
content: url('https://static.afterpay.com/integration/product-page/logo-clearpay-colour.png');
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ server.get('IncludeClearpayLibrary', server.middleware.https, server.middleware.
};
if (scope.cpJavascriptURL) {
res.render('util/clearpayLibraryInclude', scope);
next();
}
}
next();
});

/**
Expand All @@ -31,7 +31,7 @@ server.get('GetUpdatedWidget', server.middleware.https, function (req, res, next
var priceContext;
var totalPrice;
var ClearpayCOHelpers = require('*/cartridge/scripts/checkout/clearpayCheckoutHelpers');
var reqProductID = req.querystring.productID;
var reqProductID = '';
var isWithinThreshold = ClearpayCOHelpers.isPDPBasketAmountWithinThreshold();
var cpBrandUtilities = cpUtilities.brandUtilities;

Expand All @@ -47,8 +47,10 @@ server.get('GetUpdatedWidget', server.middleware.https, function (req, res, next
cpEligible = !ClearpayCOHelpers.checkRestrictedProducts(reqProductID);
} else if (req.querystring.className === 'cart-clearpay-message') {
var currentBasket = BasketMgr.getCurrentBasket();
var cartData = ClearpayCOHelpers.getCartData();
totalPrice = currentBasket.totalGrossPrice;
cpEligible = !ClearpayCOHelpers.checkRestrictedCart();
cpEligible = cartData.cpCartEligible;
reqProductID = cartData.cproductIDs;
}
var clearpayLimits = thresholdUtilities.checkThreshold(totalPrice);

Expand All @@ -73,6 +75,33 @@ server.get('GetUpdatedWidget', server.middleware.https, function (req, res, next
next();
});

server.get('updateCheckoutWidget', server.middleware.https, function (req, res, next) {
var renderTemplateHelper = require('*/cartridge/scripts/renderTemplateHelper');
var updatedTemplate = 'util/clearpayMessage';
var priceContext;
var currentBasket = BasketMgr.getCurrentBasket();
var totalPrice = currentBasket.totalGrossPrice;
var clearpayLimits = thresholdUtilities.checkThreshold(totalPrice);

priceContext = {
totalprice: totalPrice.value ? totalPrice.value : totalPrice,
mpid: clearpayLimits.mpid,
classname: 'checkout-clearpay-message'
};

var updatedWidget = renderTemplateHelper.getRenderedHtml(
priceContext,
updatedTemplate
);

res.json({
error: false,
updatedWidget: updatedWidget
});

next();
});

server.get('IncludeClearpayMessage',
server.middleware.include,
function (req, res, next) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ getTemplateSpecificWidget.getWidgetData = function (productObject, className, cu
priceContext.cpEligible = isEligible;
priceContext.cpMpid = clearpayLimits.mpid;
priceContext.cpApplicable = isEligible && isWithinThreshold;
priceContext.cpProductIDs = reqProductID;
}

return priceContext;
Expand Down Expand Up @@ -102,6 +103,7 @@ getTemplateSpecificWidget.getWidgetDataForSet = function (productObject, classNa
clearpayWidgetData.cpEligible = isEligible;
clearpayWidgetData.cpMpid = clearpayLimits.mpid;
clearpayWidgetData.cpApplicable = isEligible && isWithinThreshold;
clearpayWidgetData.cpProductIDs = reqProductID;

getTemplateSpecificWidget.pushWidgetDataToProduct(singleSetProduct, clearpayWidgetData);
}
Expand All @@ -123,7 +125,7 @@ getTemplateSpecificWidget.pushWidgetDataToProduct = function (singleSetProduct,
* @returns {string} - request JSON
*/
getTemplateSpecificWidget.getCheckoutWidgetData = function (currentBasket, className, locale) {
var cartProductExcluded = ClearpayCOHelpers.checkRestrictedCart();
var cartData = ClearpayCOHelpers.getCartData();
cpBrandUtilities.initBrand(locale);

if (!currentBasket) {
Expand All @@ -138,12 +140,13 @@ getTemplateSpecificWidget.getCheckoutWidgetData = function (currentBasket, class
priceContext.totalPrice = totalPrice.value;

var clearpayLimits = thresholdUtilities.checkThreshold(totalPrice);
var isEligible = cpBrandUtilities.isClearpayApplicable() && !cartProductExcluded;
var isEligible = cpBrandUtilities.isClearpayApplicable() && cartData.cpCartEligible;
var isWithinThreshold = clearpayLimits.status;

priceContext.cpEligible = isEligible;
priceContext.cpMpid = clearpayLimits.mpid;
priceContext.cpApplicable = isEligible && isWithinThreshold;
priceContext.cpProductIDs = cartData.cpProductIDs;

return priceContext;
};
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 5fcfdcc

Please sign in to comment.