Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/release develop #81

Merged
merged 21 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3cf50ae
feat: MPP-187 initialize inPage
joyet-simon May 4, 2023
4255f6d
chore: refacto
joyet-simon May 4, 2023
b4d6538
feat: MPP-187 finalize implement inPage
joyet-simon May 5, 2023
81dc6ff
feat: MPP-187 change fragment to inpage everywhere
joyet-simon May 5, 2023
bf2c315
feat: MPP-187 update crowdin translation
joyet-simon May 10, 2023
c0650d7
feat/ MPP-187 paymentData online value
joyet-simon May 16, 2023
de8b469
feat/MPP-187 rename var online to origin
joyet-simon May 16, 2023
d5d0abc
feat/MPP-187 rename isPnx function
joyet-simon May 17, 2023
d81d86f
feat : prepare Inpage V2
Francois-Gomis Jul 7, 2023
ae0cecc
feat : format local to 2 digit
Francois-Gomis Jul 7, 2023
ecb6453
feat : In Page V2
Francois-Gomis Jul 19, 2023
0859c66
Merge branch 'main' into feat/MPP-187_in-page
joyet-simon Jul 19, 2023
166e528
fix : Purchase Amount
Francois-Gomis Jul 19, 2023
7aafaaa
Merge remote-tracking branch 'origin/feat/MPP-187_in-page' into feat/…
Francois-Gomis Jul 19, 2023
c4a11d0
fix : Non inPage payment
Francois-Gomis Jul 19, 2023
bff6afb
feat:mpp-187 in page rectifie non exluded categorie bug
joyet-simon Jul 24, 2023
f7983c9
feat:mpp-187 in page change bo wording
joyet-simon Jul 25, 2023
7586620
feat:mpp-187 in page hidden iframe for pay now
joyet-simon Jul 25, 2023
746b65c
feat:mpp-187 in page fix display payment plan
joyet-simon Jul 25, 2023
e8173c2
Merge pull request #58 from alma/feat/MPP-187_in-page
joyet-simon Jul 27, 2023
f62986a
chore: changelog update
joyet-simon Sep 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
CHANGELOG
=========

v4.4.0
------
* Feat: In Page checkout

v4.3.1
------
* Feat: add Pay Now with credit card with Alma.
Expand Down
56 changes: 28 additions & 28 deletions cartridges/int_alma/cartridge/controllers/Alma.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ function affectOrder(paymentObj, order) {
}

/**
* Request order from OrderMgr
* Request order from OrderMgr by Alma payment ID
* @param {string} pid payment id
* @returns {Object} order
*/
function buildOrder(pid) {
function getOrderByAlmaPaymentId(pid) {
var OrderMgr = require('dw/order/OrderMgr');
return OrderMgr.queryOrder(
'custom.almaPaymentId={0}',
Expand Down Expand Up @@ -126,7 +126,7 @@ server.get('PaymentSuccess', function (req, res, next) {
});
return next();
}
var order = buildOrder(req.querystring.pid);
var order = getOrderByAlmaPaymentId(req.querystring.pid);

if (!order) {
order = paymentHelper.createOrderFromBasket(req.querystring.alma_payment_method);
Expand Down Expand Up @@ -195,7 +195,7 @@ server.get('IPN', function (req, res, next) {
});
return next();
}
var order = buildOrder(req.querystring.pid);
var order = getOrderByAlmaPaymentId(req.querystring.pid);

if (!order) {
var basketUuid = paymentObj.custom_data.basket_id;
Expand Down Expand Up @@ -320,44 +320,44 @@ server.post(
);

server.get(
'FragmentCheckout',
'InpageCheckout',
server.middleware.https,
function (req, res, next) {
var almaPaymentHelper = require('*/cartridge/scripts/helpers/almaPaymentHelper');
var BasketMgr = require('dw/order/BasketMgr');
var getLocale = require('*/cartridge/scripts/helpers/almaHelpers').getLocale;
var paymentData = almaPaymentHelper.buildPaymentData(
req.querystring.installments,
req.querystring.deferred_days,
getLocale(req)
);

try {
var basketAmount = Math.round(BasketMgr.getCurrentBasket().totalGrossPrice.multiply(100).value);
var paymentFormAmount = parseInt(req.querystring.amount, 10);
if (basketAmount !== paymentFormAmount) {
var mismatchErrorContext = {
basketAmount: basketAmount,
paymentFormAmount: paymentFormAmount
};

logger.warn('Mismatch error | {0}', [JSON.stringify(mismatchErrorContext)]);
res.setStatusCode(400);
res.json({
error: 'The amount of the shopping cart was changed.'
});
}

var order = buildOrder(req.querystring.pid);
var almaPayment = almaPaymentHelper.createPayment(paymentData);
var order = getOrderByAlmaPaymentId(almaPayment.id);

if (!order) {
order = almaPaymentHelper.createOrderFromBasket(req.querystring.alma_payment_method);
syncOrderAndPaymentDetails(req.querystring.pid, order);
syncOrderAndPaymentDetails(almaPayment.id, order);
}

res.setStatusCode(200);
res.json({
order: JSON.stringify(order)
order: order,
payment_id: almaPayment.id
});
} catch (e) {
res.setStatusCode(500);
res.json({
error: e.message
});

if (e.name === 'create_payment_error') {
res.json({
error: 'Could not create payment on Alma side'
});
} else {
res.json({
error: e.message
});
}
}

return next();
});

Expand Down
7 changes: 4 additions & 3 deletions cartridges/int_alma/cartridge/controllers/Checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function getAlmaUrls() {
data_url: URLUtils.http('Alma-BasketData').toString(),
create_payment_url: URLUtils.https('Alma-CreatePaymentUrl').toString(),
order_amount_url: URLUtils.http('Alma-OrderAmount').toString(),
checkout_fragment_url: URLUtils.http('Alma-FragmentCheckout').toString(),
inpage_checkout_url: URLUtils.http('Alma-InpageCheckout').toString(),
plans_url: URLUtils.http('Alma-Plans').toString()
};
}
Expand Down Expand Up @@ -68,8 +68,9 @@ server.append('Begin', function (req, res, next) {
currencyCode: currentBasket.currencyCode,
purchase_amount: Math.round(currentBasket.totalGrossPrice.multiply(100).value),
plans: almaPlanHelper.getPlansForCheckout(getLocale(req), currentBasket),
fragment_on_close_message: Resource.msg('alma.fragment_on_close_message', 'alma', null),
fragment_on_failure_message: Resource.msg('alma.fragment_on_failure_message', 'alma', null)
inpage_on_close_message: Resource.msg('alma.inpage_on_close_message', 'alma', null),
inpage_on_failure_message: Resource.msg('alma.inpage_on_failure_message', 'alma', null),
locale: getLocale(req)
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function getInstallmentCountAfterFirst(plan) {
}

/**
* Returns the property displaying installments before calling fragment
* Returns the property displaying installments before calling inpage
* @param {Object} plan any alma plan
* @param {string} currencyCode e.g. 'EUR'
* @returns {string} the message to display for a payment option
Expand Down Expand Up @@ -158,21 +158,22 @@ function getPropertiesForPlan(plan, currencyCode) {

/**
* Returns if the current payment option is pnx 2,3 or 4
* @param {Object} plan any alma plan
* @returns {boolean} true means we can use fragment
* @param {int} installmentsCount installments count
* @param {int} deferredDays deferred days
* @returns {boolean} true means we can use inpage
*/
function isPnx(plan) {
return plan.installments_count <= 4;
function isAvailableForInpage(installmentsCount, deferredDays) {
return installmentsCount <= 4 && deferredDays <= 0;
}

/**
* Returns true if the merchant want in-page payment
* @returns {boolean} if we can use fragment
* @returns {boolean} if we can use inpage
*/
function isFragmentActivated() {
function isInpageActivated() {
var Site = require('dw/system/Site');

return Site.getCurrent().getCustomPreferenceValue('ALMA_Fragment_Payment');
return Site.getCurrent().getCustomPreferenceValue('ALMA_Inpage_Payment');
}

/**
Expand Down Expand Up @@ -223,7 +224,7 @@ function formatPlanForCheckout(plan, currencyCode) {
var formatPlan = {};
if (plan.installments_count < 5 && planIsActivated(PaymentMgr.getPaymentMethod(ALMA_PNX_ID), plan)) {
formatPlan = {
in_page: isPnx(plan) && isFragmentActivated(),
in_page: isAvailableForInpage(plan.installments_count, plan.deferred_days) && isInpageActivated(),
selector: getSelectorNameFromPlan(plan),
installments_count: plan.installments_count,
deferred_days: plan.deferred_days,
Expand All @@ -236,7 +237,7 @@ function formatPlanForCheckout(plan, currencyCode) {
}
if (plan.installments_count >= 5 && planIsActivated(PaymentMgr.getPaymentMethod(ALMA_CREDIT_ID), plan)) {
formatPlan = {
in_page: isPnx(plan) && isFragmentActivated(),
in_page: isAvailableForInpage(plan.installments_count, plan.deferred_days) && isInpageActivated(),
selector: getSelectorNameFromPlan(plan),
installments_count: plan.installments_count,
deferred_days: plan.deferred_days,
Expand All @@ -249,7 +250,7 @@ function formatPlanForCheckout(plan, currencyCode) {
}
if (plan.deferred_days > 0 && planIsActivated(PaymentMgr.getPaymentMethod(ALMA_DEFERRED_ID), plan)) {
formatPlan = {
in_page: isPnx(plan) && isFragmentActivated(),
in_page: isAvailableForInpage(plan.installments_count, plan.deferred_days) && isInpageActivated(),
selector: getSelectorNameFromPlan(plan),
installments_count: plan.installments_count,
deferred_days: plan.deferred_days,
Expand All @@ -262,7 +263,7 @@ function formatPlanForCheckout(plan, currencyCode) {
}
if (plan.installments_count === 1 && plan.deferred_days === 0 && planIsActivated(PaymentMgr.getPaymentMethod(ALMA_PAY_NOW_ID), plan)) {
formatPlan = {
in_page: false,
in_page: isAvailableForInpage(plan.installments_count, plan.deferred_days) && isInpageActivated(),
selector: getSelectorNameFromPlan(plan),
installments_count: plan.installments_count,
deferred_days: plan.deferred_days,
Expand All @@ -278,5 +279,7 @@ function formatPlanForCheckout(plan, currencyCode) {

module.exports = {
formatPlanForCheckout: formatPlanForCheckout,
getPlanPaymentMethodID: getPlanPaymentMethodID
getPlanPaymentMethodID: getPlanPaymentMethodID,
isAvailableForInpage: isAvailableForInpage,
isInpageActivated: isInpageActivated
};
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,12 @@ function haveExcludedCategory(productIds) {
});
}
});
logger.warn('categoriesID {0}', [JSON.stringify(categoriesID)]);

var categoriesExcluded = Site.getCurrent().getCustomPreferenceValue('categoryExclusion').trim().split(' | ');
var categoriesExcluded = [];

if (Site.getCurrent().getCustomPreferenceValue('categoryExclusion')) {
categoriesExcluded = Site.getCurrent().getCustomPreferenceValue('categoryExclusion').trim().split(' | ');
}

var haveExcludedCategoryReturn = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,12 @@ function createOrderFromBasket(almaPaymentMethod) {
*/
function createPayment(param) {
var service = require('*/cartridge/scripts/services/alma');

var httpResult = service.createPayment().call(param);

if (httpResult.msg !== 'OK') {
throw new Error('API error : ' + httpResult.status);
var e = new Error('API error : ' + httpResult.status);
e.name = 'create_payment_error';
throw e;
}
return JSON.parse(httpResult.getObject().text);
}
Expand All @@ -290,11 +292,17 @@ function buildPaymentData(installmentsCount, deferredDays, locale) {
var BasketMgr = require('dw/order/BasketMgr');
var URLUtils = require('dw/web/URLUtils');
var almaHelper = require('*/cartridge/scripts/helpers/almaHelpers');
var almaCheckoutHelper = require('*/cartridge/scripts/helpers/almaCheckoutHelper');

var formatAddress = require('*/cartridge/scripts/helpers/almaAddressHelper').formatAddress;
var isOnShipmentPaymentEnabled = require('*/cartridge/scripts/helpers/almaOnShipmentHelper').isOnShipmentPaymentEnabled;
var formatCustomerData = require('*/cartridge/scripts/helpers/almaHelpers').formatCustomerData;

var origin = 'online';
if (almaCheckoutHelper.isAvailableForInpage(installmentsCount, deferredDays) && almaCheckoutHelper.isInpageActivated()) {
origin = 'online_in_page';
}

var currentBasket = BasketMgr.getCurrentBasket();
var isEnableOnShipment = isOnShipmentPaymentEnabled(installmentsCount);

Expand All @@ -308,7 +316,7 @@ function buildPaymentData(installmentsCount, deferredDays, locale) {
ipn_callback_url: URLUtils.http('Alma-IPN').toString(),
customer_cancel_url: URLUtils.https('Alma-CustomerCancel').toString(),
locale: locale,
origin: 'online',
origin: origin,
shipping_address: formatAddress(currentBasket.getDefaultShipment().shippingAddress),
billing_address: formatAddress(currentBasket.getBillingAddress()),
deferred: isEnableOnShipment ? 'trigger' : '',
Expand Down
Loading