Skip to content

Commit

Permalink
Merge pull request #93 from alma/feature/ecom-1464-sfcc-remove-restri…
Browse files Browse the repository at this point in the history
…ction-to-filter-out-deferred-payments-from

Remove restriction to filter out deferred payments from In-Page
  • Loading branch information
Benjamin-Freoua-Alma authored Mar 21, 2024
2 parents fd37bea + 3d0e10f commit 3f9cb42
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Checkout current repo in CI
uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,10 @@ function getPropertiesForPlan(plan, currencyCode) {
/**
* Returns if the current payment option is pnx 2,3 or 4
* @param {int} installmentsCount installments count
* @param {int} deferredDays deferred days
* @returns {boolean} true means we can use inpage
*/
function isAvailableForInpage(installmentsCount, deferredDays) {
return installmentsCount <= 4 && deferredDays <= 0;
function isAvailableForInpage(installmentsCount) {
return installmentsCount <= 4;
}

/**
Expand Down Expand Up @@ -223,7 +222,7 @@ function formatPlanForCheckout(plan, currencyCode) {
var formatPlan = {};
if (plan.installments_count < 5 && planIsActivated(PaymentMgr.getPaymentMethod(ALMA_PNX_ID), plan)) {
formatPlan = {
in_page: isAvailableForInpage(plan.installments_count, plan.deferred_days) && almaConfigHelper.isInpageActivated(),
in_page: isAvailableForInpage(plan.installments_count) && almaConfigHelper.isInpageActivated(),
selector: getSelectorNameFromPlan(plan),
installments_count: plan.installments_count,
deferred_days: plan.deferred_days,
Expand All @@ -236,7 +235,7 @@ function formatPlanForCheckout(plan, currencyCode) {
}
if (plan.installments_count >= 5 && planIsActivated(PaymentMgr.getPaymentMethod(ALMA_CREDIT_ID), plan)) {
formatPlan = {
in_page: isAvailableForInpage(plan.installments_count, plan.deferred_days) && almaConfigHelper.isInpageActivated(),
in_page: isAvailableForInpage(plan.installments_count) && almaConfigHelper.isInpageActivated(),
selector: getSelectorNameFromPlan(plan),
installments_count: plan.installments_count,
deferred_days: plan.deferred_days,
Expand All @@ -249,7 +248,7 @@ function formatPlanForCheckout(plan, currencyCode) {
}
if (plan.deferred_days > 0 && planIsActivated(PaymentMgr.getPaymentMethod(ALMA_DEFERRED_ID), plan)) {
formatPlan = {
in_page: isAvailableForInpage(plan.installments_count, plan.deferred_days) && almaConfigHelper.isInpageActivated(),
in_page: isAvailableForInpage(plan.installments_count) && almaConfigHelper.isInpageActivated(),
selector: getSelectorNameFromPlan(plan),
installments_count: plan.installments_count,
deferred_days: plan.deferred_days,
Expand All @@ -262,7 +261,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: isAvailableForInpage(plan.installments_count, plan.deferred_days) && almaConfigHelper.isInpageActivated(),
in_page: isAvailableForInpage(plan.installments_count) && almaConfigHelper.isInpageActivated(),
selector: getSelectorNameFromPlan(plan),
installments_count: plan.installments_count,
deferred_days: plan.deferred_days,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ function buildPaymentData(installmentsCount, deferredDays, locale, isManualCaptu
var formatCustomerData = require('*/cartridge/scripts/helpers/almaHelpers').formatCustomerData;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,14 @@ window.addEventListener('DOMContentLoaded',
window.location = body.url;
}

async function inPageInitialize(inPageContainer, installments_count, captureMethod) {
async function inPageInitialize(inPageContainer, installments_count, deferred_days, captureMethod) {
return Alma.InPage.initialize(
{
merchantId: almaContext.merchantId,
amountInCents: purchase_amount,
installmentsCount: installments_count,
deferredDays: deferred_days,
deferredMonths: 0,
selector: "#" + inPageContainer,
locale: almaContext.locale.slice(0, 2),
environment: almaContext.almaMode,
Expand Down Expand Up @@ -186,6 +188,7 @@ window.addEventListener('DOMContentLoaded',
await inPageInitialize(
t.id + "-inpage",
installments_count,
deferred_days,
captureMethod
)
.then(function (inPage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<externally-managed-flag>false</externally-managed-flag>
</attribute-definition>
<attribute-definition attribute-id="ALMA_Inpage_Payment">
<display-name xml:lang="x-default">Activate in-page checkout for P1X, P2X, P3X and P4X</display-name>
<display-name xml:lang="x-default">Activate in-page checkout for Pay Now, Installment, and Deferred payments.</display-name>
<type>boolean</type>
<mandatory-flag>false</mandatory-flag>
<externally-managed-flag>false</externally-managed-flag>
Expand Down
5 changes: 3 additions & 2 deletions test/unit/int_alma/scripts/helpers/almaPaymentHelperTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var paymentAuthorizationNotExpired = {

describe('almaPaymentHelper', function () {
describe('Build payment data', function () {
// TODO : Add test for payment deferred and pnx without inpage
it('payment data for pnx is well formed', function () {
setIsAvailableForInpage(true);
setCustomPreferenceValue(true);
Expand All @@ -43,9 +44,9 @@ describe('almaPaymentHelper', function () {
assert.deepEqual(payment, resolvedPaymentData(3, 0, 'fr_FR', 'online_in_page'));
});
it('payment data for deferred', function () {
setIsAvailableForInpage(false);
setIsAvailableForInpage(true);
var payment = almaPaymentHelper.buildPaymentData(1, 15, 'fr_FR', false);
assert.deepEqual(payment, resolvedPaymentData(1, 15, 'fr_FR', 'online'));
assert.deepEqual(payment, resolvedPaymentData(1, 15, 'fr_FR', 'online_in_page'));
});
it('payment data for credit has car property', function () {
setIsAvailableForInpage(false);
Expand Down

0 comments on commit 3f9cb42

Please sign in to comment.