Skip to content

Commit f5e0d14

Browse files
committed
Release 1.0.11
1 parent a3a3000 commit f5e0d14

File tree

234 files changed

+16486
-566
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

234 files changed

+16486
-566
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Have your Wallee credentials handy.
3939

4040
* Merchant Tools > Site Preferences > Wallee
4141

42-
If the path `Merchant Tools > Site Preferences > Wallee` does not exits, please repeat steps 1.3 and 1.4.
42+
If the path `Merchant Tools > Site Preferences > Wallee` does not exist, please repeat steps 1.3 and 1.4.
4343

4444

4545
### 6. Profit

cartridges/bm_wallee/cartridge/controllers/WalleeAdmin.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55
* Configure WebHooks
66
*/
77
function start() {
8-
var customPreferences = dw.object.CustomObjectMgr.getCustomObject("Wallee_Common", "wallee_common");
9-
var data = {
10-
customPreferences: customPreferences.custom
11-
};
12-
dw.template.ISML.renderTemplate("extensions/wallee.isml", data);
8+
try {
9+
var customPreferences = dw.object.CustomObjectMgr.getCustomObject("Wallee_Common", "wallee_common");
10+
var data = {
11+
customPreferences: customPreferences.custom
12+
};
13+
dw.template.ISML.renderTemplate("extensions/wallee.isml", data);
14+
}
15+
catch (e) {
16+
throw new Error("Please import metadata first. Custom object Wallee_Common is missing.");
17+
}
1318
}
1419
/**
1520
* Save Store configs
@@ -28,11 +33,24 @@ function saveConfiguration() {
2833
customPreferences_1.custom.apiSecret = params_1.apiSecret.stringValue;
2934
});
3035
var WebHookHelper = new (require("../../../int_wallee/cartridge/scripts/wallee/helpers/WebHook"));
31-
var data_1 = WebHookHelper.getTransactionListener();
32-
dw.system.Transaction.wrap(function () {
33-
customPreferences_1.custom.webHookContent = JSON.stringify(data_1);
34-
customPreferences_1.custom.webHookIsEnabled = true;
35-
});
36+
try {
37+
var data_1 = WebHookHelper.getTransactionListener();
38+
dw.system.Transaction.wrap(function () {
39+
customPreferences_1.custom.webHookContent = JSON.stringify(data_1);
40+
customPreferences_1.custom.webHookIsEnabled = true;
41+
});
42+
}
43+
catch (e) {
44+
var errorMessage = "Site \"" + dw.system.Site.getCurrent().getName() + "\" Transaction webhook was not created - already exists.";
45+
dw.system.Logger.warn(errorMessage);
46+
}
47+
try {
48+
WebHookHelper.getRefundListener();
49+
}
50+
catch (e) {
51+
var errorMessage = "Site \"" + dw.system.Site.getCurrent().getName() + "\" Refund webhook was not created - already exists.";
52+
dw.system.Logger.warn(errorMessage);
53+
}
3654
}
3755
start();
3856
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use strict";
2+
3+
function updatePaymentInformation(order) {
4+
alert('debug');
5+
}
6+
7+
module.exports.methods = {
8+
updatePaymentInformation: updatePaymentInformation
9+
};
Lines changed: 132 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,141 @@
11
"use strict";
2-
window.onload = function () {
3-
// reset validation when back button press
4-
$(window).on('popstate', function () { $('.tab-pane.active').attr('validation', 'false'); });
5-
// Listen to changes on billing and shipping forms and update the payment methods accordingly
6-
$('#dwfrm_billing > fieldset.billing-address-block > fieldset.billing-address, #dwfrm_shipping > div.shipping-address > fieldset.shipping-address-block').on('mouseleave', function () {
7-
var data = $(this).serializeArray();
8-
// @ts-ignore
9-
$.ajax({
10-
method: "POST",
11-
url: $("[name=WALLEE_url]").first().val(),
12-
data: data,
13-
success: function (result) {
14-
if (result && result.wallee && result.wallee.possiblePaymentMethodsArray) {
15-
result.wallee.possiblePaymentMethodsArray.forEach(function (value) {
16-
$('.WALLEE-nav-item-' + value + ', .wallee-content-' + value).show();
17-
});
2+
jQuery(function ($) {
3+
var WalleeCheckout = {
4+
active_payment_tab: '.tab-pane.active',
5+
customer_address: '#dwfrm_billing > fieldset.billing-address-block > fieldset.billing-address, #dwfrm_shipping > div.shipping-address > fieldset.shipping-address-block',
6+
submit_payment: '#checkout-main button.btn.btn-primary.btn-block.submit-payment',
7+
place_order: '#checkout-main button.btn.btn-primary.btn-block.place-order',
8+
available_payment_methods_tabs: 'a.wallee-tab',
9+
first_available: '#dwfrm_billing div.form-nav.billing-nav.payment-information > ul > li > a',
10+
payment_handler: '[name=WALLEE_handler]',
11+
/**
12+
* Initialize plugin
13+
*/
14+
init: function () {
15+
$(window).on('popstate', this.disableValidation);
16+
$(this.customer_address).on('mouseleave', this.addressUpdatePaymentMethods);
17+
$(this.submit_payment).on('click', this.submitPayment);
18+
$(this.place_order).on('click', this.placeOrder);
19+
$(this.available_payment_methods_tabs).on('click', this.getIframe);
20+
$('.submit-shipping').on('click', function () {
21+
$('#dwfrm_billing div.form-nav.billing-nav.payment-information > ul > li > a').first().trigger('click');
22+
$(".tab-pane.wallee-content").removeAttr("style");
23+
});
24+
window.WalleeCheckout = this;
25+
},
26+
/**
27+
* Disable validation when user clicks back button
28+
*/
29+
disableValidation: function () {
30+
$(this.active_payment_tab).attr('validation', false);
31+
},
32+
/**
33+
* Update payment methods on address change
34+
*/
35+
addressUpdatePaymentMethods: function () {
36+
var data = $(this).serializeArray();
37+
// @ts-ignore
38+
$.ajax({
39+
method: "POST",
40+
url: $("[name=WALLEE_url]").first().val(),
41+
data: data,
42+
success: function (result) {
43+
if (result && result.wallee && result.wallee.possiblePaymentMethodsArray) {
44+
result.wallee.possiblePaymentMethodsArray.forEach(function (value) {
45+
$('.WALLEE-nav-item-' + value + ', .wallee-content-' + value).show();
46+
});
47+
}
1848
}
19-
}
20-
});
21-
});
22-
// Validate selected WALLEE paymentmethod
23-
$('#checkout-main button.btn.btn-primary.btn-block.submit-payment').on('click', function (e) {
24-
var activeTabId = $('.tab-pane.active').data('id');
25-
if (activeTabId) {
26-
var activeTabValid = $('.tab-pane.active').attr('validation');
27-
if (activeTabValid && (activeTabValid === 'true')) {
28-
if ($('[name="WALLEE_handler"]').val() !== '') {
29-
return true;
49+
});
50+
},
51+
/**
52+
* Submit payment
53+
* @param event
54+
*/
55+
submitPayment: function (event) {
56+
var activeTabId = $(WalleeCheckout.active_payment_tab).data('id');
57+
if (activeTabId) {
58+
var activeTabValid = $(WalleeCheckout.active_payment_tab).attr('validation');
59+
if (activeTabValid) {
60+
if ($(WalleeCheckout.payment_handler).val() !== '') {
61+
return true;
62+
}
3063
}
64+
event.preventDefault();
65+
window['WALLEE_handler' + activeTabId].validate();
66+
return false;
3167
}
32-
e.preventDefault();
33-
window['WALLEE_handler' + activeTabId].validate();
34-
return false;
35-
}
36-
});
37-
// Submit selected WALLEE payment method and place order
38-
$('#checkout-main button.btn.btn-primary.btn-block.place-order').on('click', function (e) {
39-
var activeTabId = $('.tab-pane.active').data('id');
40-
if (activeTabId !== '') {
41-
var activeTabValid = $('.tab-pane.active').attr('validation');
42-
if (activeTabValid === 'true') {
43-
var handlerName_1 = $('[name="WALLEE_handler"]').val();
44-
if ((handlerName_1) && (window[handlerName_1] !== undefined)) {
45-
// disable the placeOrder button here
46-
$('body').trigger('checkout:disableButton', '.next-step-button button');
47-
$.ajax({
48-
url: $('.place-order').data('action'),
49-
method: 'POST',
50-
success: function (data) {
51-
// enable the placeOrder button here
52-
$('body').trigger('checkout:enableButton', '.next-step-button button');
53-
if (data.error) {
54-
if (data.cartError) {
55-
window.location.href = data.redirectUrl;
68+
},
69+
/**
70+
* Place order
71+
*/
72+
placeOrder: function (event) {
73+
var activeTabId = $(WalleeCheckout.active_payment_tab).data('id');
74+
if (activeTabId !== '') {
75+
var activeTabValid = $(WalleeCheckout.active_payment_tab).attr('validation');
76+
if (activeTabValid) {
77+
var handlerName_1 = $(WalleeCheckout.payment_handler).val();
78+
if ((handlerName_1) && (window[handlerName_1] !== undefined)) {
79+
// disable the placeOrder button here
80+
$('body').trigger('checkout:disableButton', '.next-step-button button');
81+
$.ajax({
82+
url: $('.place-order').data('action'),
83+
method: 'POST',
84+
success: function (data) {
85+
if (data.error) {
86+
// enable the placeOrder button here
87+
$('body').trigger('checkout:enableButton', '.next-step-button button');
88+
if (data.cartError) {
89+
window.location.href = data.redirectUrl;
90+
}
5691
}
92+
else {
93+
window[handlerName_1].submit();
94+
}
95+
},
96+
error: function () {
97+
// enable the placeOrder button here
98+
$('body').trigger('checkout:enableButton', $('.next-step-button button'));
5799
}
58-
else {
59-
var continueUrl = data.continueUrl;
60-
var urlParams_1 = {
61-
ID: data.orderID,
62-
token: data.orderToken
63-
};
64-
continueUrl += (continueUrl.indexOf('?') !== -1 ? '&' : '?') +
65-
Object.keys(urlParams_1).map(function (key) {
66-
// @ts-ignore
67-
return key + '=' + encodeURIComponent(urlParams_1[key]);
68-
}).join('&');
69-
window[handlerName_1].submit();
70-
//window.location.href = continueUrl;
71-
}
72-
},
73-
error: function () {
74-
// enable the placeOrder button here
75-
$('body').trigger('checkout:enableButton', $('.next-step-button button'));
76-
}
77-
});
100+
});
101+
}
78102
}
103+
return false;
104+
}
105+
return true;
106+
},
107+
/**
108+
* Get iframe
109+
* @param event
110+
*/
111+
getIframe: function (event) {
112+
var value = $(this).data('id');
113+
var payment_handler_name = 'WALLEE_handler' + value;
114+
if ($('#wallee-form-' + value).children().length === 0) { // iframe has not been loaded yet
115+
window[payment_handler_name] = window.IframeCheckoutHandler(value);
116+
window[payment_handler_name].setValidationCallback(function (validationResult) {
117+
WalleeCheckout.validationCallBack(payment_handler_name, validationResult);
118+
});
119+
window[payment_handler_name].create('wallee-form-' + value);
120+
}
121+
return true;
122+
},
123+
/**
124+
* validation callback
125+
* @param payment_handler_name
126+
* @param validationResult
127+
*/
128+
validationCallBack: function (payment_handler_name, validationResult) {
129+
if (validationResult.success) {
130+
$(WalleeCheckout.active_payment_tab).attr('validation', true);
131+
$(WalleeCheckout.payment_handler).val(payment_handler_name);
132+
$('#checkout-main button.btn.btn-primary.btn-block.submit-payment').trigger('click');
133+
}
134+
else {
135+
$(WalleeCheckout.active_payment_tab).attr('validation', false);
136+
$(WalleeCheckout.payment_handler).val('');
79137
}
80-
return false;
81-
}
82-
return true;
83-
});
84-
// Bind available payment methods and fetch iframe
85-
$('a.wallee-tab').on('click', function (e) {
86-
var value = $(this).data('id');
87-
if ($('#wallee-form-' + value).children().length === 0) { // iframe has not been loaded yet
88-
window['WALLEE_handler' + value] = window.IframeCheckoutHandler(value);
89-
window['WALLEE_handler' + value].create('wallee-form-' + value);
90-
window['WALLEE_handler' + value].setValidationCallback(function (validationResult) {
91-
if (validationResult.success) {
92-
$('.tab-pane.active').attr('validation', 'true');
93-
$('#checkout-main button.btn.btn-primary.btn-block.submit-payment').click();
94-
$('[name="WALLEE_handler"]').val('WALLEE_handler' + value);
95-
}
96-
else {
97-
$('.tab-pane.active').attr('validation', 'false');
98-
$('[name="WALLEE_handler"]').val('');
99-
}
100-
});
101138
}
102-
return true;
103-
});
104-
// Click on the first payment method
105-
$('#dwfrm_billing div.form-nav.billing-nav.payment-information > ul > li > a').first().click();
106-
};
139+
};
140+
WalleeCheckout.init();
141+
});

cartridges/int_wallee/cartridge/config/wallee/preferences.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
function getPreferences() {
44
try {
55
var customPreferences = dw.object.CustomObjectMgr.getCustomObject("Wallee_Common", "wallee_common");
6-
var prefs = {
6+
return {
77
spaceId: customPreferences.custom.spaceId,
88
serviceName: "int_wallee.http.rest.payment.wallee",
99
macVersion: 1,
1010
userId: customPreferences.custom.userId,
11-
apiSecret: customPreferences.custom.apiSecret,
11+
apiSecret: customPreferences.custom.apiSecret
1212
};
13-
return prefs;
1413
}
1514
catch (e) {
1615
var errorMessage = "Site \"" + dw.system.Site.getCurrent().getName() + "\" is not configured. You must update settings in BM > Merchant Tools > Site Preferences > Wallee";

cartridges/int_wallee/cartridge/controllers/Checkout.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
"use strict";
22

3+
var Locale = require("dw/util/Locale");
34
var server = require("server");
45
// @ts-ignore
56
server.extend(module.superModule);
67
var TransactionHelperImport = require("~/cartridge/scripts/wallee/helpers/Transaction");
78
server.append("Begin", function (req, res, next) {
89
var currentBasket = dw.order.BasketMgr.getCurrentBasket();
910
if (!currentBasket) {
10-
next();
11-
return;
11+
return next();
1212
}
13-
var viewData = res.getViewData();
1413
var transactionHelper = new TransactionHelperImport(currentBasket);
14+
var viewData = res.getViewData();
15+
var currentLocale = Locale.getLocale(req.locale.id);
16+
session.custom.language = currentLocale.language;
1517
viewData.wallee = transactionHelper.handleTransaction();
1618
res.setViewData(viewData);
1719
return next();

0 commit comments

Comments
 (0)