Skip to content

Commit

Permalink
Bugfixes Mollie settings & fail order flow
Browse files Browse the repository at this point in the history
- Mollie settings page bugfixes
- Fix fail order flow
  • Loading branch information
YbeSpapen committed Jun 23, 2021
1 parent a07ca9b commit 841c938
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 46 deletions.
25 changes: 19 additions & 6 deletions cartridges/bm_mollie/cartridge/controllers/MollieSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,25 @@ server.post('SavePreferences',
var paramNames = request.httpParameterMap.parameterNames;

collections.forEach(paramNames, function (paramName) {
var param = request.httpParameterMap.get(paramName);
var paramValue = param.empty ? false : param.booleanValue || param.dateValue || param.doubleValue || param.intValue || param.value;
if (paramName !== 'csrf_token' && (!preferences.custom[paramName] || (paramValue !== (preferences.custom[paramName].value || preferences.custom[paramName])))) {
Transaction.wrap(function () {
preferences.custom[paramName] = paramValue;
});
if (paramName !== 'csrf_token') {
var param = request.httpParameterMap.get(paramName);
var preference = preferences.custom[paramName];
var paramValue = param.booleanValue || param.dateValue || param.doubleValue || param.intValue || param.value;
if (preference && paramValue !== preference.value) {
Transaction.wrap(function () {
switch (paramValue) {
case 'checked':
preferences.custom[paramName] = true;
break;
case 'unchecked':
preferences.custom[paramName] = false;
break;
default:
preferences.custom[paramName] = paramValue;
break;
}
});
}
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<span class="input-group-text">&#128273;</span>
</div>
</isif>
<input class="form-control js-bm-preferences-password-field" type="${preference.inputType}" name="${preference.ID}"
<input class="form-control ${preference.inputType === 'password' ? 'js-bm-preferences-password-field' : ''}" type="${preference.inputType}" name="${preference.ID}"
value="${preference.selectedValue || preference.defaultValue || ''}" ${preference.mandotory ? 'required' : ''} />
<isif condition="${preference.inputType === 'password'}">
<div class="input-group-append">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<input class="checkbox" type="checkbox" data-toggle="toggle" value="true" name="${preference.ID}"
${preference.selectedValue ? 'checked' : ''}/>
<input type="hidden" name="${preference.ID}"/>
<input class="checkbox" type="checkbox" data-toggle="toggle" value="checked" name="${preference.ID}"
${preference.selectedValue ? 'checked' : ''} />
<input type="hidden" name="${preference.ID}" value="unchecked" />
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="card-body">
<div class="alert alert-success js-bm-preferences-alert-success d-none"></div>
<div class="alert alert-danger js-bm-preferences-alert-error d-none"></div>
<a href="javascript:history.back()" class="d-block mb-3">${Resource.msg('label.preference.back', 'bm', null)}</a>
<a href="javascript:history.back()" class="d-block mb-3">${Resource.msg('label.preferences.back', 'bm', null)}</a>
<div class="jumbotron">
<p>${Resource.msg('label.preferences.developed', 'bm', null)}</p>
<div class="row">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="row mb-4">
<div class="col-md-2">
<button type="button" class="btn btn-primary js-bm-preferences-test-api"
data-method-url="${URLUtils.url('MollieSettings-TestApiKey')}">${Resource.msg('label.preference.test', 'bm', null)}</button>
data-method-url="${URLUtils.url('MollieSettings-TestApiKey')}">${Resource.msg('label.preferences.test', 'bm', null)}</button>
</div>
<div class="col-md-4">
<div class="js-bm-preferences-test-api-result"></div>
Expand Down
23 changes: 14 additions & 9 deletions cartridges/int_mollie/cartridge/scripts/mollieConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ var REFUND_STATUS = {
REFUNDED: 'REFUND_STATUS_REFUNDED'
};

var ENABLED_MODE = {
TEST: 'TEST',
LIVE: 'LIVE'
};

// Mollie Configuration
/**
*
Expand All @@ -46,15 +51,15 @@ function Config() {
}

// #region GENERAL CONFIG
this.enabledMode = mollieConfigHelper.getPreference(sitePreferences, 'mollieEnabledMode');
this.bearerTestToken = mollieConfigHelper.getPreference(sitePreferences, 'mollieBearerTestToken');
this.bearerToken = mollieConfigHelper.getPreference(sitePreferences, 'mollieBearerToken');
this.profileId = mollieConfigHelper.getPreference(sitePreferences, 'mollieProfileId');
this.defaultEnabledTransActionAPI = mollieConfigHelper.getPreference(sitePreferences, 'mollieDefaultEnabledTransactionAPI');
this.defaultOrderExpiryDays = mollieConfigHelper.getPreference(sitePreferences, 'mollieDefaultOrderExpiryDays');
this.enableSingleClickPayments = mollieConfigHelper.getPreference(sitePreferences, 'mollieEnableSingleClickPayments');
this.componentsEnabled = mollieConfigHelper.getPreference(sitePreferences, 'mollieComponentsEnabled');
this.logCategory = mollieConfigHelper.getPreference(sitePreferences, 'mollieLogCategory');
this.enabledMode = mollieConfigHelper.getPreference(sitePreferences, 'mollieEnabledMode', true);
this.bearerTestToken = mollieConfigHelper.getPreference(sitePreferences, 'mollieBearerTestToken', this.enabledMode === ENABLED_MODE.LIVE);
this.bearerToken = mollieConfigHelper.getPreference(sitePreferences, 'mollieBearerToken', this.enabledMode === ENABLED_MODE.LIVE);
this.profileId = mollieConfigHelper.getPreference(sitePreferences, 'mollieProfileId', true);
this.defaultEnabledTransActionAPI = mollieConfigHelper.getPreference(sitePreferences, 'mollieDefaultEnabledTransactionAPI', true);
this.defaultOrderExpiryDays = mollieConfigHelper.getPreference(sitePreferences, 'mollieDefaultOrderExpiryDays', true);
this.enableSingleClickPayments = mollieConfigHelper.getPreference(sitePreferences, 'mollieEnableSingleClickPayments', true);
this.componentsEnabled = mollieConfigHelper.getPreference(sitePreferences, 'mollieComponentsEnabled', true);
this.logCategory = mollieConfigHelper.getPreference(sitePreferences, 'mollieLogCategory', false);
this.customPageFieldSettings = customPageFieldSettings;

/**
Expand Down
5 changes: 3 additions & 2 deletions cartridges/int_mollie/cartridge/scripts/mollieConfigHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ var MollieServiceException = require('*/cartridge/scripts/exceptions/MollieServi
* Returns preference
* @param {array} preferences - array of preferences
* @param {string} preferenceName - preference name
* @param {boolean} throwError - throw error when site preference not exist
* @returns {?} preference
*/
function getPreference(preferences, preferenceName) {
function getPreference(preferences, preferenceName, throwError) {
var pref = preferences[preferenceName];
if (!pref) throw new MollieServiceException('You must configure sitePreference by name ' + preferenceName + '.');
if (throwError && typeof pref === 'undefined') throw new MollieServiceException('You must configure sitePreference by name ' + preferenceName + '.');
return pref;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ function processPaymentResult(order, paymentResult) {
var paymentService = require('*/cartridge/scripts/payment/paymentService');

var orderId = order.orderNo;
var orderToken = order.orderToken;

// Uncomment block to support SFRA < 6.0.0
// var orderToken = order.orderToken;
// var url = URLUtils.https('Order-Confirm', 'ID', orderId, 'token', orderToken).toString();

// Comment block to support SFRA < 6.0.0
var url = URLUtils.https('Order-Confirm').toString();
var url = URLUtils.https('MolliePayment-RedirectSuccess', 'orderId', orderId, 'orderToken', orderToken).toString();
// End block

orderHelper.checkMollieRefundStatus(order, paymentResult);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.page {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: space-between;
}
46 changes: 27 additions & 19 deletions cartridges/int_mollie_sfra/cartridge/controllers/MolliePayment.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,30 @@ var URLUtils = require('dw/web/URLUtils');
var Resource = require('dw/web/Resource');

/**
* MolliePayment-Redirect : Handling of a payment hook. Redirects to order confirmation or order failure page.
* MolliePayment-RedirectSuccess : Handling of a successful payment. Redirects to order confirmation.
* @name Mollie/MolliePayment-RedirectSuccess
* @function
* @memberof MolliePayment
* @param {serverfunction} - get
*/
server.get('RedirectSuccess', function (req, res, next) {
var orderId = req.querystring.orderId;
var orderToken = req.querystring.orderToken;

if (orderId && orderToken) {
res.render('mollieRedirectTemplate', {
continueUrl: URLUtils.url('Order-Confirm'),
orderId: orderId,
orderToken: orderToken
});
} else {
res.redirect(URLUtils.home().toString());
}
return next();
});

/**
* MolliePayment-Redirect : Handling of a payment hook.
* @name Mollie/MolliePayment-Redirect
* @function
* @memberof MolliePayment
Expand All @@ -23,26 +46,11 @@ server.get('Redirect', server.middleware.https, function (req, res, next) {
var order = orderId && OrderMgr.getOrder(orderId, orderToken);
if (order) {
var url = paymentService.processPaymentUpdate(order);
if (url) {
// Comment block to support SFRA < 6.0.0
res.render('mollieRedirectTemplate', {
continueUrl: url,
orderId: orderId,
orderToken: orderToken
});
// End block

// Uncomment to support SFRA < 6.0.0
// res.redirect(url);
} else {
res.redirect(URLUtils.home().toString());
}
} else {
res.redirect(URLUtils.home().toString());
res.redirect(url);
return next();
}
} else {
res.redirect(URLUtils.home().toString());
}
res.redirect(URLUtils.home().toString());
} catch (e) {
var error = e;
if (error.name === 'PaymentProviderException') throw error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<isscript>
var assets = require('*/cartridge/scripts/assets.js');
assets.addJs('/js/redirect.js');
assets.addCss('/css/redirect.css');
</isscript>
<form method="POST" action="${pdict.continueUrl}" class="js-mollie-redirect-form">
<input type="hidden" name="orderID" value="${pdict.orderId}" />
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"compile:scss": "sgmf-scripts --compile css",
"compile:js": "sgmf-scripts --compile js",
"compile:fonts": "node bin/Makefile compileFonts",
"build": "npm run compile:js && npm run compile:fonts && npm run compile:scss",
"build": "npm run compile:js && npm run compile:scss",
"lint": "npm run lint:css && npm run lint:js",
"lint:css": "sgmf-scripts --lint css",
"lint:js": "sgmf-scripts --lint js",
Expand Down
2 changes: 1 addition & 1 deletion test/unit/int_mollie/scripts/mollieConfigHelper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('ConfigHelper', () => {
after(() => stubs.restore());

it('throw when sitepreference is missing', () => {
expect(() => mollieConfigHelper.getPreference(preferences, 'UnkownPreference')).to.throw();
expect(() => mollieConfigHelper.getPreference(preferences, 'UnkownPreference', true)).to.throw();
expect(stubs.serviceExceptionMock).to.have.been.calledOnce()
.and.to.have.been.calledWith(sinon.match('You must configure sitePreference by name'));
});
Expand Down

0 comments on commit 841c938

Please sign in to comment.