Skip to content

Commit

Permalink
Clearpay cartridge v23.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ghatamehta-afterpay committed Feb 28, 2022
1 parent d473da7 commit 43f5f56
Show file tree
Hide file tree
Showing 280 changed files with 8,196 additions and 1,292 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ cartridges/int_clearpay_sfra/cartridge/static/default/js/clearpay.js
cartridges/int_clearpay_sfra/cartridge/static/default/js/clearpayCheckout.js
cartridges/int_clearpay_sfra/cartridge/static/default/js/checkout.js
cartridges/int_clearpay_sfra/cartridge/static/default/js/productTile.js
cartridges/int_clearpay_sfra_6/cartridge/static/default/css
cartridges/int_clearpay_sfra_6/cartridge/static/default/js/clearpay.js
cartridges/int_clearpay_sfra_6/cartridge/static/default/js/clearpayCheckout.js
cartridges/int_clearpay_sfra_6/cartridge/static/default/js/checkout.js
cartridges/int_clearpay_sfra_6/cartridge/static/default/js/productTile.js
dw.json
11 changes: 6 additions & 5 deletions cartridges/bm_clearpay/cartridge/scripts/transActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ var UUIDUtils = require('dw/util/UUIDUtils');
/* Script Modules */
var LogUtils = require('*/cartridge/scripts/util/clearpayLogUtils');
var Logger = LogUtils.getLogger('TransActions');
var { brandUtilities } = require('*/cartridge/scripts/util/clearpayUtilities');
var clearpayUtilities = require('*/cartridge/scripts/util/clearpayUtilities');
var brandUtilities = clearpayUtilities.brandUtilities;

/**
* updates the order status
Expand Down Expand Up @@ -83,7 +84,7 @@ function callAction(request) {
function refund(orderNo, amountString) {
var order = OrderMgr.getOrder(orderNo);
var paymentInstrument;
var apPaymentInstrument;
var cpPaymentInstrument;
var paymentTransaction;
var status = false;
var amountArray = amountString.split(' ');
Expand All @@ -97,9 +98,9 @@ function refund(orderNo, amountString) {
var iter = order.getPaymentInstruments().iterator();

while (iter.hasNext()) {
apPaymentInstrument = iter.next();
if (apPaymentInstrument.paymentMethod === 'AFTERPAY' || apPaymentInstrument.paymentMethod === 'CLEARPAY') {
paymentInstrument = apPaymentInstrument;
cpPaymentInstrument = iter.next();
if (cpPaymentInstrument.paymentMethod === 'AFTERPAY' || cpPaymentInstrument.paymentMethod === 'CLEARPAY') {
paymentInstrument = cpPaymentInstrument;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
<isset name="isDirectPayment" value="${true}" scope="page" />
<isif condition="${paymentTransaction}">
<isset name="isDirectPayment" value="${paymentTransaction.custom.cpPaymentMode === 'DIRECT_CAPTURE'}" scope="page" />
<isset name="apPaymentStatus" value="${isDirectPayment ? paymentTransaction.custom.cpDirectPaymentStatus : paymentTransaction.custom.cpAuthoriseStatus}" scope="page" />
<isset name="canRefund" value="${isDirectPayment && apPaymentStatus.toLowerCase() == 'approved' && empty(paymentTransaction.custom.cpRefundID)}" scope="page" />
<isset name="cpPaymentStatus" value="${isDirectPayment ? paymentTransaction.custom.cpDirectPaymentStatus : paymentTransaction.custom.cpAuthoriseStatus}" scope="page" />
<isset name="canRefund" value="${isDirectPayment && cpPaymentStatus.toLowerCase() == 'approved' && empty(paymentTransaction.custom.cpRefundID)}" scope="page" />
<isif condition="${!(isDirectPayment && !canRefund)}">
<isset name="currentStatus" value="${apPaymentStatus}" scope="page" />
<isset name="currentStatus" value="${cpPaymentStatus}" scope="page" />
</isif>
</isif>
<td class="table_detail left e s" nowrap="nowrap" width="75%><label class="item-label" for="">${isDirectPayment ? paymentTransaction.custom.cpDirectPaymentStatus : paymentTransaction.custom.cpAuthoriseStatus}</label></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@
<isif condition="${paymentInstrument && paymentInstrument.custom && paymentInstrument.paymentTransaction}">
<isset name="paymentTransaction" value="${paymentInstrument.paymentTransaction}" scope="page" />
<isset name="isDirectPayment" value="${paymentTransaction.custom.cpPaymentMode === 'DIRECT_CAPTURE'}" scope="page" />
<isset name="apPaymentStatus" value="${isDirectPayment ? paymentTransaction.custom.cpDirectPaymentStatus : paymentTransaction.custom.cpAuthoriseStatus}" scope="page" />
<isset name="canRefund" value="${isDirectPayment && apPaymentStatus.toLowerCase() == 'approved' && empty(paymentTransaction.custom.cpRefundID)}" scope="page" />
<isset name="cpPaymentStatus" value="${isDirectPayment ? paymentTransaction.custom.cpDirectPaymentStatus : paymentTransaction.custom.cpAuthoriseStatus}" scope="page" />
<isset name="canRefund" value="${isDirectPayment && cpPaymentStatus.toLowerCase() == 'approved' && empty(paymentTransaction.custom.cpRefundID)}" scope="page" />
<isif condition="${!(isDirectPayment && !canRefund)}">
<isset name="currentStatus" value="${apPaymentStatus}" scope="page" />
<isset name="currentStatus" value="${cpPaymentStatus}" scope="page" />
</isif>
</isif>
<td class="table_detail left e s" nowrap="nowrap">${currentStatus}</td>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<iscontent type="text/html" charset="UTF-8" compact="true">
<link href="${URLUtils.staticURL('css/clearpay.css')}" type="text/css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="${URLUtils.staticURL('lib/jquery/jquery-2.1.1.min.js')}"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
"paymentMethod": "CLEARPAY",
"paymentProcessor": "*/cartridge/scripts/payment/processor/CLEARPAY"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
'use strict';
var { checkoutUtilities: apCheckoutUtilities, sitePreferencesUtilities: sitePreferences } = require('*/cartridge/scripts/util/clearpayUtilities');
var cpUtilities = require('*/cartridge/scripts/util/clearpayUtilities');
var cpCheckoutUtilities = cpUtilities.checkoutUtilities;
var thresholdUtilities = require('*/cartridge/scripts/util/thresholdUtilities');
var ArrayList = require('dw/util/ArrayList');
var LogUtils = require('*/cartridge/scripts/util/clearpayLogUtils');
var Logger = LogUtils.getLogger('clearpayCheckoutHelpers');


/* Script Modules */
var ctrlCartridgeName = sitePreferences.getControllerCartridgeName();
var app = require(ctrlCartridgeName + '/cartridge/scripts/app');

var checkoutTools = {
// splits name into first/last
splitName: function (singleName) {
Expand All @@ -30,19 +26,19 @@ var checkoutTools = {
}
return phone;
},
addConsumerToBasket: function (basket, apConsumer) {
addConsumerToBasket: function (basket, cpConsumer) {
var Transaction = require('dw/system/Transaction');
Transaction.wrap(function () {
basket.setCustomerEmail(apConsumer.email || '');
basket.setCustomerName((apConsumer.givenNames || '').trim() + ' ' + (apConsumer.givenNames || '').trim());
basket.setCustomerEmail(cpConsumer.email || '');
basket.setCustomerName((cpConsumer.givenNames || '').trim() + ' ' + (cpConsumer.givenNames || '').trim());
});
// ignoring
// apConsumer.phoneNumber;
// cpConsumer.phoneNumber;
},
addBillingAddressToBasket: function (basket, apBilling) {
addBillingAddressToBasket: function (basket, cpBilling) {
var Transaction = require('dw/system/Transaction');
var billingAddress = basket.billingAddress;
let name = this.splitName(apBilling.name || '');
let name = this.splitName(cpBilling.name || '');
let stripLeadingOne = this.stripUSPhoneNumberLeadingOne;

Transaction.wrap(function () {
Expand All @@ -53,78 +49,20 @@ var checkoutTools = {
billingAddress.setFirstName(name.firstName || '');
billingAddress.setLastName(name.lastName || '');

billingAddress.setAddress1(apBilling.line1 || '');
billingAddress.setAddress2(apBilling.line2 || '');
billingAddress.setCity(apBilling.area1 || '');
billingAddress.setPostalCode(apBilling.postcode || '');
billingAddress.setStateCode(apBilling.region || '');
billingAddress.setCountryCode(apBilling.countryCode || '');
if (apBilling.countryCode.toUpperCase() === 'US') {
billingAddress.setPhone(stripLeadingOne(apBilling.phoneNumber || ''));
} else {
billingAddress.setPhone(apBilling.phoneNumber || '');
}
});
},

addShippingAddressToBasket: function (basket, apShipping) {
var Transaction = require('dw/system/Transaction');
var shipment = basket.defaultShipment;
var shippingAddress = shipment.shippingAddress;

/*
there are some utility methods if we need them
COHelpers.copyShippingAddressToShipment(
shippingData,
basket.defaultShipment
);
*/
let name = this.splitName(apShipping.name || '');
let stripLeadingOne = this.stripUSPhoneNumberLeadingOne;
Transaction.wrap(function () {
if (shippingAddress === null) {
shippingAddress = shipment.createShippingAddress();
}
shippingAddress.setFirstName(name.firstName || '');
shippingAddress.setLastName(name.lastName || '');
shippingAddress.setAddress1(apShipping.line1 || '');
shippingAddress.setAddress2(apShipping.line2 || '');
shippingAddress.setCity(apShipping.area1 || '');
shippingAddress.setPostalCode(apShipping.postcode || '');
shippingAddress.setStateCode(apShipping.region || '');
shippingAddress.setCountryCode(apShipping.countryCode || '');
if (apShipping.countryCode.toUpperCase() === 'US') {
shippingAddress.setPhone(stripLeadingOne(apShipping.phoneNumber || ''));
billingAddress.setAddress1(cpBilling.line1 || '');
billingAddress.setAddress2(cpBilling.line2 || '');
billingAddress.setCity(cpBilling.area1 || '');
billingAddress.setPostalCode(cpBilling.postcode || '');
billingAddress.setStateCode(cpBilling.region || '');
billingAddress.setCountryCode(cpBilling.countryCode || '');
if (cpBilling.countryCode.toUpperCase() === 'US') {
billingAddress.setPhone(stripLeadingOne(cpBilling.phoneNumber || ''));
} else {
shippingAddress.setPhone(apShipping.phoneNumber || '');
billingAddress.setPhone(cpBilling.phoneNumber || '');
}
});
},
getShippingMethodsForAddress: function (cart, apShipping) {
var TransientAddress = app.getModel('TransientAddress');
var address = new TransientAddress();
address.countryCode = apShipping.countryCode || '';
address.stateCode = apShipping.region || '';
address.postalCode = apShipping.postcode || '';
address.city = apShipping.area1 || '';
address.address1 = apShipping.line1 || '';
address.address2 = apShipping.line2 || '';

var applicableShippingMethods = cart.getApplicableShippingMethods(address);
return applicableShippingMethods;
},
getDefaultShippingMethodForAddress: function (cart, apShipping) {
let shipMethods = this.getShippingMethodsForAddress(cart, apShipping);
let shipIter = shipMethods.iterator();
while (shipIter.hasNext()) {
let shipMethod = shipIter.next();
if (shipMethod.defaultMethod == true) {
return shipMethod;
}
}
return null;
},
// returns a Map with storeid's -> addresses. The "NONE" corresponds to
// returns a Map with storeid's -> addresses. The "NONE" corresponds to
// items which are not a store pickup
getInStorePickupsMap: function (basket) {
// let lineItems = cart.object.getProductLineItems();
Expand All @@ -150,36 +88,9 @@ var checkoutTools = {
}
return cnt;
},
shouldEnableExpressPickupMode: function (cart) {
if (!cart) {
cart = app.getModel('Cart').get();
}
if (!cart) {
return false;
}
let storeMap = this.getInStorePickupsMap(cart.object);
// items that are being shipped
let numNonStorePickups = this.getNumHomeDeliveries(cart.object);
if ((numNonStorePickups == 0) && (Object.keys(storeMap).length == 1)) {
return true;
}
return false;
},
removeAllNonGiftCertificatePayments: function (cart) {
let PaymentInstrument = require('dw/order/PaymentInstrument');

let payInstr = cart.getPaymentInstruments();
let iter = payInstr.iterator();
while (iter.hasNext()) {
let pi = iter.next();
if (!PaymentInstrument.METHOD_GIFT_CERTIFICATE.equals(pi.getPaymentMethod())) {
cart.removePaymentInstrument(pi);
}
}
},
getCurrentClearpayPaymentAmount: function (basket) {
// Just gets the amount currently associated with the Clearpay payment instrument
var paymentMethod = apCheckoutUtilities.getPaymentMethodName();
var paymentMethod = cpCheckoutUtilities.getPaymentMethodName();
let pi = basket.getPaymentInstruments(paymentMethod);
if (pi.length == 0) {
return new dw.value.Money(0.0, basket.currencyCode);
Expand All @@ -193,15 +104,15 @@ var checkoutTools = {
// compute a checksum for the current items in the basket so we can check
// if anything changed
computeBasketProductLineItemChecksum: function (ctnr) {
let crc32 = require('*/cartridge/scripts/util/clearpayUtilities.js').crc32;
let crc32 = cpUtilities.crc32;
// Should use whatever info we use in building the create checkout
var lineItems = ctnr.getAllProductLineItems().toArray();
// let product = li.product;
let cksum = 0;

lineItems.map(function (li) {
let product = li.product;
// just ignore names. Using quantity/price/currency
// just ignore names. Using quantity/productid/price/currency
// product can be null if line-item is something like a warranty. Just ignoring those.
let cc = null;
let id = null;
Expand All @@ -216,7 +127,7 @@ var checkoutTools = {
cksum += crc32(s);
Logger.debug('Line and checksum: ' + s + ' Checksum:' + cksum);
});
Logger.debug("Final Checksum" + cksum);
Logger.debug('Final Checksum' + cksum);
return cksum;
},
// compute a checksum for the current shipping address so we can check
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var clearpayConstants = require('*/cartridge/scripts/util/clearpayConstants');
var apUtilities = require('*/cartridge/scripts/util/clearpayUtilities');
var apCheckoutUtilities = apUtilities.checkoutUtilities;
var cpUtilities = require('*/cartridge/scripts/util/clearpayUtilities');
var cpCheckoutUtilities = cpUtilities.checkoutUtilities;
var Transaction = require('dw/system/Transaction');
var Logger = require('dw/system/Logger');

Expand Down Expand Up @@ -38,7 +38,7 @@ var clearpayUpdateOrder = {
// eslint-disable-next-line no-unused-vars
savePaymentTransaction: function (paymentTransaction, paymentResult, paymentMode) {
var Money = require('dw/value/Money');
var BrandUtilities = apUtilities.brandUtilities;
var BrandUtilities = cpUtilities.brandUtilities;
var payTrans = paymentTransaction;
var amount = null;

Expand Down Expand Up @@ -69,7 +69,7 @@ var clearpayUpdateOrder = {
*/
getPaymentTransaction: function (order) {
var paymentTransaction;
var paymentMethodName = apCheckoutUtilities.getPaymentMethodName();
var paymentMethodName = cpCheckoutUtilities.getPaymentMethodName();

if (!paymentMethodName) {
return null;
Expand All @@ -90,7 +90,7 @@ var clearpayUpdateOrder = {
*/
getPaymentProcessor: function () {
var PaymentMgr = require('dw/order/PaymentMgr');
var paymentMethodName = apCheckoutUtilities.getPaymentMethodName();
var paymentMethodName = cpCheckoutUtilities.getPaymentMethodName();

if (!paymentMethodName) {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
var Transaction = require('dw/system/Transaction');
var PreapprovalModel = require('*/cartridge/scripts/models/preapprovalModel');
var clearpayUtilities = require('*/cartridge/scripts/util/clearpayUtilities');
var LogUtils = require('*/cartridge/scripts/util/clearpayLogUtils');
var Logger = LogUtils.getLogger('afterpaUpdatePreapprovalStatus');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ var AuthorisePaymentService = {
var isCheckoutAdjusted = false;
let CaptureHelpers = require('*/cartridge/scripts/payment/expressCaptureHelpers');
let body = CaptureHelpers.generateItemsAndShippingBody(order);
if (expressCheckoutModel.apTempShippingAddressChanged) {
if (expressCheckoutModel.cpTempShippingAddressChanged) {
shippingObj = body.shipping;
isCheckoutAdjusted = true;
}
if (expressCheckoutModel.apTempBasketItemsChanged) {
if (expressCheckoutModel.cpTempBasketItemsChanged) {
itemsObj = body.items;
isCheckoutAdjusted = true;
}
// Possibly account for coupons, or possibly other factors
if (expressCheckoutModel.apTempCheckoutAmountChanged) {
if (expressCheckoutModel.cpTempCheckoutAmountChanged) {
isCheckoutAdjusted = true;
}
// express checkout has 2 types of capture. One is with the Clearpay widget (has checksum)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ var DirectCapturePaymentService = {
var isCheckoutAdjusted = false;
let CaptureHelpers = require('*/cartridge/scripts/payment/expressCaptureHelpers');
let body = CaptureHelpers.generateItemsAndShippingBody(order);
if (expressCheckoutModel.apTempShippingAddressChanged) {
if (expressCheckoutModel.cpTempShippingAddressChanged) {
shippingObj = body.shipping;
isCheckoutAdjusted = true;
}
if (expressCheckoutModel.apTempBasketItemsChanged) {
if (expressCheckoutModel.cpTempBasketItemsChanged) {
itemsObj = body.items;
isCheckoutAdjusted = true;
}
// Possibly account for coupons, or possibly other factors
if (expressCheckoutModel.apTempCheckoutAmountChanged) {
if (expressCheckoutModel.cpTempCheckoutAmountChanged) {
isCheckoutAdjusted = true;
}
// express checkout has 2 types of capture. One is with the Clearpay widget (has checksum)
Expand Down
Loading

0 comments on commit 43f5f56

Please sign in to comment.