Skip to content

Commit

Permalink
Improve advanced payment API script
Browse files Browse the repository at this point in the history
  • Loading branch information
firstred committed Jul 2, 2017
1 parent 61c917e commit adc58d3
Showing 1 changed file with 50 additions and 62 deletions.
112 changes: 50 additions & 62 deletions advanced-payment-api.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,7 @@
$(document).ready(function() {
var handler = new PaymentOptionHandler();

if (!!$.prototype.fancybox)
$('a.iframe').fancybox({
'type': 'iframe',
'width': 600,
'height': 600
});

$('p.payment_module').on('click', function(event) {
handler.selectOption($(this));
return;
});

$('#confirmOrder').on('click', function(event) {
/* Avoid any further action */
event.preventDefault();
event.stopPropagation();

if (handler.checkTOS() === false) {
PrestaShop.showError(aeuc_tos_err_str);
return;
}
if (aeuc_has_virtual_products === true && handler.checkVirtualProductRevocation() === false) {
PrestaShop.showError(aeuc_virt_prod_err_str);
return;
}
if (handler.selected_option === null) {
PrestaShop.showError(aeuc_no_pay_err_str);
return;
}
if (handler.submitForm() === false) {
PrestaShop.showError(aeuc_submit_err_str);
return;
}
return;
});

});

var PaymentOptionHandler = function() {

var PaymentOptionHandler = function () {
this.selected_option = null;

this.selectOption = function(elem) {
this.selectOption = function (elem) {
if (typeof elem === 'undefined' || elem.hasClass('payment_selected')) {
return;
}
Expand All @@ -55,37 +13,67 @@ var PaymentOptionHandler = function() {
this.selected_option.children('a:first').children('.payment_option_selected:first').fadeIn();
};

this.unselectOption = function() {
this.unselectOption = function () {
this.selected_option.children('a:first').children('.payment_option_selected:first').fadeOut();
this.selected_option.removeClass('payment_selected');
};

/* Return array with all payment option information required */
this.submitForm = function() {
this.submitForm = function () {
if (typeof this.selected_option !== 'undefined' && this.selected_option !== null && this.selected_option.hasClass('payment_selected')) {
var form_to_submit = this.selected_option.next('.payment_option_form').children('form:first');
if (typeof form_to_submit !== 'undefined') {
form_to_submit.submit();
var formToSubmit = this.selected_option.next('.payment_option_form').children('form:first');
if (typeof formToSubmit !== 'undefined') {
formToSubmit.submit();
return true;
}
}
return false;
};

this.checkTOS = function() {

if ($('#cgv').prop('checked')) {
return true;
}

return false;
this.checkTOS = function () {
return !!$('#cgv').prop('checked');
};

this.checkVirtualProductRevocation = function() {
if ($('#revocation_vp_terms_agreed').prop('checked')) {
return true;
}

return false;
this.checkVirtualProductRevocation = function () {
return !!$('#revocation_vp_terms_agreed').prop('checked');
};
};

$(document).ready(function () {
var handler = new PaymentOptionHandler();

if (typeof $.prototype.fancybox !== 'undefined' && $.prototype.fancybox) {
$('a.iframe').fancybox({
type: 'iframe',
width: 600,
height: 600
});
}

$('p.payment_module').on('click', function () {
handler.selectOption($(this));
});

$('#confirmOrder').on('click', function (event) {
/* Avoid any further action */
event.preventDefault();
event.stopPropagation();

if (handler.checkTOS() === false) {
PrestaShop.showError(window.aeuc_tos_err_str);
return;
}
if (window.aeuc_has_virtual_products === true && handler.checkVirtualProductRevocation() === false) {
PrestaShop.showError(window.aeuc_virt_prod_err_str);
return;
}
if (handler.selected_option === null) {
PrestaShop.showError(window.aeuc_no_pay_err_str);
return;
}
if (handler.submitForm() === false) {
PrestaShop.showError(window.aeuc_submit_err_str);
return;
}
});
});

0 comments on commit adc58d3

Please sign in to comment.