jQuery(function() {
let formatter = new Intl.NumberFormat('pl-PL', {
style: 'currency',
currency: 'PLN',
});
let mxComfinoInit = function () {
let config = {"active":1,"widget_key":"bdbb90bb-a2df-4a9f-8aed-4f62aafa9671","payment_id":18,"status_accepted_id":1,"status_cancelled_id":8,"sandbox_active":0,"sandbox_key":"","payment_name":"Comfino","payment_show_logo":0,"widget_show":0,"widget_type":"simple","widget_offer_type":"CONVENIENT_INSTALLMENTS","widget_localization":"under_addtobasket","widget_custom_id":"","widget_price_selector":"","__translatable_fields":[]};
if(!config.active) {
return true;
}
//moduł aktywny:
// PODZIĘKOWANIE ZA ZAMÓWIENIE basket_done
if($('body').hasClass('shop_basket_done')) {
if($('#mx_comfino_order_id_input').length) {
// new ways:
if($('#mx_comfino_payment_name_input').val().trim().toLowerCase() != $('#mx_comfino_target_payment_name_input').val().trim().toLowerCase()) {
//inna płatność
return true;
}
let new_order_data = {};
new_order_data.orderId = $('#mx_comfino_order_id_input').val();
new_order_data.notifyUrl = `https://shoper.comfino.pl/notify/113/` + $('#mx_comfino_order_id_input').val();
new_order_data.returnUrl = window.location.href;
let current_chosen_product = window.localStorage.getItem('mx_comfino_chosen_product');
if(current_chosen_product) {
current_chosen_product = current_chosen_product.split('||');
new_order_data.loanParameters = {
"term" : parseInt(current_chosen_product[1]),
"type" : current_chosen_product[0],
};
}
$.post("https://shoper.comfino.pl/order",{
"shop_id" : 113,
"order_data" : new_order_data,
"order_id" : $('#mx_comfino_order_id_input').val(),
"products_data" : mx_comfino_order_data.cart.products,
},function(order_response) {
if(order_response.status != 'SUCCESS') {
$('#box_basketfinal > div.innerbox').prepend(`
Wystąpił błąd podczas realizacji płatności. Spróbuj ponownie później.
`);
return true;
}
if(order_response.link && order_response.link.length > 0) {
window.location.href = order_response.link;
}
});
}
else {
// old ways:
let waitForOrderData = function() {
if(!mx_comfino_order_data) {
setTimeout(function (){
waitForOrderData();
},1);
return true;
}
if(mx_comfino_order_data.current_payment_name.trim().toLowerCase() != mx_comfino_order_data.target_payment_name.trim().toLowerCase()) {
//inna płatność
return true;
}
delete mx_comfino_order_data.target_payment_name;
delete mx_comfino_order_data.current_payment_name;
mx_comfino_order_data.notifyUrl = `https://shoper.comfino.pl/notify/113/${mx_comfino_order_data.orderId}`;
mx_comfino_order_data.returnUrl = window.location.href;
let current_chosen_product = window.localStorage.getItem('mx_comfino_chosen_product');
if(current_chosen_product) {
current_chosen_product = current_chosen_product.split('||');
mx_comfino_order_data.loanParameters = {
"term" : parseInt(current_chosen_product[1]),
"type" : current_chosen_product[0],
};
}
$.post("https://shoper.comfino.pl/order",{
"shop_id" : 113,
"order_data" : mx_comfino_order_data,
},function(order_response) {
if(order_response.status != 'SUCCESS') {
$('#box_basketfinal > div.innerbox').prepend(`
Wystąpił błąd podczas realizacji płatności. Spróbuj ponownie później.
`);
return true;
}
if(order_response.link && order_response.link.length > 0) {
window.location.href = order_response.link;
}
});
}
waitForOrderData();
}
}
//END PODZIĘKOWANIE ZA ZAMÓWIENIE basket_done
// KARTA PRODUKTU
if($('body').hasClass('shop_product')) {
if(config.widget_show) {
var script = document.createElement('script');
script.onload = function () {
ComfinoProductWidget.init({
widgetKey: 'bdbb90bb-a2df-4a9f-8aed-4f62aafa9671',
priceSelector: 'em.main-price',
widgetTargetSelector: '.maininfo .basket .form-basket',
type: 'simple',
offerType: 'CONVENIENT_INSTALLMENTS',
embedMethod: 'INSERT_AFTER',
priceObserverLevel: 0,
price: null
});
};
script.src = '//widget.comfino.pl/comfino.min.js';
script.async = true;
document.getElementsByTagName('head')[0].appendChild(script);
let css_karta = `.comfino-widget {margin-top: 7px;}`;
if($('.maininfo .basket').css('float') == 'left') {
$('.maininfo .basket').css('float', 'none');
css_karta = `.comfino-widget {padding-top: 7px;clear:both;}`;
}
let style = document.createElement('style');
if (style.styleSheet) {
style.styleSheet.cssText = css_karta;
} else {
style.appendChild(document.createTextNode(css_karta));
}
document.getElementsByTagName('head')[0].appendChild(style);
}
}
//END KARTA PRODUKTU
// KOSZYK
if($('body').hasClass('shop_basket')) {
// Pokaż logo Comfino przy metodzie płatności
let logo_in_form = '';
if(config.payment_show_logo) {
let logo_img = $('
');
$('label[for="payment_' + config.payment_id + '"]').last().append(logo_img);
}
else {
logo_in_form = '
';
}
//END Pokaż logo Comfino przy metodzie płatności
let mxInitComfinoBasket = function(logo_in_form,config) {
if(!$('#payment_' + config.payment_id).is(':checked')) {
$('.comfino').slideUp(0);
return true;
}
$('.comfino').remove();
//preloader:
$('label[for="payment_' + config.payment_id + '"]').last().parent().parent().append(``);
let current_basket_amount = $('.sum .value').first().text();
let re = new RegExp(String.fromCharCode(160), "g");
let current_basket_amount_float = parseFloat(current_basket_amount.replace(' ','').replace(re,'').replace('zł','').replace(',','.'));
let financial_products = window.localStorage.getItem('financial_products_' + current_basket_amount_float);
let financial_products_expires = window.localStorage.getItem('financial_products_expires_' + current_basket_amount_float);
let current_date = new Date();
if(financial_products && financial_products.length > 0 && financial_products_expires > current_date.getTime()) {
financial_products = JSON.parse(financial_products);
mxInitComfinoBasketForm(current_basket_amount,logo_in_form,config,financial_products);
}
else {
$.ajax({
type: "POST",
url: "https://shoper.comfino.pl/products",
data: {
"shop_id" : 113,
"amount" : current_basket_amount_float,
},
timeout: 20000,
success : function(financial_products){
window.localStorage.setItem('financial_products_' + current_basket_amount_float,JSON.stringify(financial_products));
let save_date = new Date();
save_date.setTime(save_date.getTime() + (60*60*1000));
window.localStorage.setItem('financial_products_expires_' + current_basket_amount_float,save_date.getTime());
mxInitComfinoBasketForm(current_basket_amount,logo_in_form,config,financial_products);
},
error: function(jqXHR, textStatus, errorThrown) {
let api_error_msg_url = 'https://widget.comfino.pl/paywall-error.json';
if(config.sandbox_active) {
api_error_msg_url = 'https://widget.craty.pl/paywall-error.json';
}
let default_error_msg = 'Przepraszamy, w tym momencie płatność Comfino nie jest dostępna.Spróbuj później.';
$.ajax({
type: "GET",
url: api_error_msg_url,
timeout: 10000,
success : function(error_msg){
$('.mx_comfino_preloader').slideUp(0);
error_msg = error_msg.error;
if(error_msg.length < 1) {
error_msg = default_error_msg;
}
$('.mx_comfino_error').slideUp(0);
$('label[for="payment_' + config.payment_id + '"]').last().parent().parent().append(`${error_msg}
`);
},
error: function(jqXHR, textStatus, errorThrown) {
$('.mx_comfino_preloader').slideUp(0);
$('.mx_comfino_error').slideUp(0);
$('label[for="payment_' + config.payment_id + '"]').last().parent().parent().append(`${default_error_msg}
`);
}
});
}
});
}
};
let mxInitComfinoBasketForm = function(amount,logo_in_form,config,financial_products) {
let current_chosen_product = '';
let radio_buttons = '';
let products_html = '';
let footer_html = '';
for(let k in financial_products) {
let kplus1 = parseInt(k) + 1;
let product = financial_products[k];
let checked = '';
if(kplus1 == 1) {
checked = ' checked';
}
if(current_chosen_product.length < 1) {
current_chosen_product = `${product.type}||${product.loanTerm}`;
window.localStorage.setItem('mx_comfino_chosen_product',current_chosen_product);
// console.log(current_chosen_product);
}
radio_buttons = radio_buttons + ``;
//poszczególne warianty widgetu:
if(product.type == 'PAY_LATER') {
products_html = products_html + `
Kup teraz, zapłać za 30 dni Jak to działa?
`;
}
else {
let rrso = (product.rrso * 100).toFixed(2);
let toPay = formatter.format(product.toPay/100);
let instalmentAmount = formatter.format(product.instalmentAmount/100);
let installments_html = '';
let loan_column_index = 1;
for (let loan_k in product.loanParameters) {
let current_loan = product.loanParameters[loan_k];
let current_loan_active = '';
if(current_loan.loanTerm == product.loanTerm) {
current_loan_active = ' comfino-active';
}
installments_html = installments_html + `
${current_loan.loanTerm}
`;
loan_column_index = loan_column_index + 1;
if(loan_column_index > 3) {
installments_html = installments_html + `
`;
loan_column_index = 1;
}
}
let txt_wybierz = 'Wybierz liczbę rat';
let txt_rata = 'Miesięczna rata:';
let txt_rrso = `
Łączna kwota do spłaty: ${toPay}
RRSO ${rrso} %
`;
if(product.type == 'COMPANY_BNPL') {
txt_wybierz = 'O ile dni chcesz odroczyć płatność?';
txt_rata = 'Łączna kwota do zapłaty:';
let wartosc_prowizji = product.toPay - product.instalmentAmount;
let txt_prowizja_operatora = formatter.format(wartosc_prowizji/100);
txt_rrso = `
Prowizja operatora: ${txt_prowizja_operatora}
`;
}
products_html = products_html + `
${txt_wybierz}
${installments_html}
${txt_rata}
${instalmentAmount}
${txt_rrso}
${product.description}
`;
if(product.representativeExample.length > 0) {
footer_html = footer_html + `
`;
}
}
}
$('.mx_comfino_preloader').slideUp(0);
$('label[for="payment_' + config.payment_id + '"]').last().parent().parent().append(`
Wartość zakupów:
${amount}
${products_html}
${footer_html}
`);
$('body').append($(''))
$('.comfino').slideDown(0);
// wybór liczby rat
$('.comfino-installments-quantity').click(function() {
let type = $(this).data('type');
let instalmentAmount = $(this).data('instalmentamount');
let loanTerm = $(this).data('loanterm');
let toPay = $(this).data('topay');
let rrso = $(this).data('rrso');
$(`.comfino-variant-${type} .comfino-installments-quantity`).removeClass('comfino-active');
$(this).addClass('comfino-active');
if(type == 'COMPANY_BNPL') {
let kwota_oryginalna = toPay;
toPay = toPay - instalmentAmount;
instalmentAmount = kwota_oryginalna;
}
toPay = formatter.format(toPay/100);
instalmentAmount = formatter.format(instalmentAmount/100);
rrso = (rrso * 100).toFixed(2) + ' %';
$(`.comfino-variant-${type} .comfino-monthly-rate`).text(instalmentAmount);
$(`.comfino-variant-${type} .comfino-summary-total span`).text(toPay);
$(`.comfino-variant-${type} .comfino-rrso span`).text(rrso);
window.localStorage.setItem('mx_comfino_chosen_product',`${type}||${loanTerm}`);
// console.log(`${type}||${loanTerm}`);
});
//END wybór liczby rat
// popup przykład reprezentatywny
$('.comfino-footer-link').click(function() {
$('.mx_comfino_popup_all').fadeIn(150);
let type = $(this).data('type');
$('.mx_comfino_popup_content').html($(`#representative-example-${type}`).val());
});
$('.mx_comfino_popup_close').click(function() {
$('.mx_comfino_popup_all').fadeOut(150);
});
//END popup przykład reprezentatywny
// odświeżanie widgetu po zmianie wyboru produktu finansowego
let mxRefreshComfinoBox = function() {
$('.comfino-variant').slideUp(0);
let current_variant = $('.comfino-variant-'+$('.comfino-input:checked').data('type'));
current_variant.slideDown(0);
if(current_variant.find('.comfino-installments-quantity.comfino-active').length > 0) {
current_variant.find('.comfino-installments-quantity.comfino-active').click();
}
else {
window.localStorage.setItem('mx_comfino_chosen_product',$('.comfino-input:checked').data('type') + '||');
// console.log($('.comfino-input:checked').data('type') + '||');
}
};
mxRefreshComfinoBox();
$('.comfino-input').change(function() {
mxRefreshComfinoBox();
});
};
let loadTimeout = setTimeout(() => {
mxInitComfinoBasket(logo_in_form,config);
}, 100);
// początkowe załadowanie formularza:
// mxInitComfinoBasket(logo_in_form,config);
// odświeżani formularza po zmianie płatności/dostawy
$('.payment input[type="radio"]').change(function() {
if($(this).hasClass('comfino-input')) {
return true;
}
clearTimeout(loadTimeout);
loadTimeout = setTimeout(() => {
mxInitComfinoBasket(logo_in_form,config);
}, 100);
});
$('.delivery input[type="radio"]').change(function() {
if($(this).hasClass('comfino-input')) {
return true;
}
clearTimeout(loadTimeout);
loadTimeout = setTimeout(() => {
mxInitComfinoBasket(logo_in_form,config);
}, 100);
});
//END odświeżani formularza po zmianie płatności/dostawy
let css = `
.comfino {
max-width: 700px;
margin: 7px auto;
border: 1px solid #e7e7e7;
padding: 14px;
border-radius: 14px;
}
.comfino * {
outline: none;
-webkit-tap-highlight-color: transparent;
}
.comfino-box {}
.comfino-header {
display: flex;
flex-direction: column;
}
.comfino-logo {
margin: 0 auto;
}
.comfino-title {
text-align: center;
font-weight: bold;
font-size: 1.2rem;
margin: 0.875rem 0;
}
.comfino-select-payment {}
.comfino-single-payment {
border-bottom: 1px solid #ddd;
display: flex;
align-items: center;
}
.comfino-single-payment label {
display: flex;
align-items: center;
width: 100%;
}
.comfino-single-payment__text {
padding-left: 5px;
}
.comfino-single-payment input {
width: 25px;
height: 25px;
}
.comfino-input[type="radio"]:checked, .comfino-input[type="radio"]:not(:checked) {
position: absolute;
left: -9999px;
}
.comfino-input[type="radio"]:checked+label, .comfino-input[type="radio"]:not(:checked)+label {
position: relative;
padding-left: 28px;
cursor: pointer;
line-height: 20px;
/* display: flex; */
color: #666;
}
.comfino-input[type="radio"]:checked+label:before, .comfino-input[type="radio"]:not(:checked)+label:before {
content: '';
position: absolute;
left: 0;
/* top: 0; */
width: 18px;
height: 18px;
border: 2px solid #ddd;
border-radius: 100%;
background: #fff;
}
.comfino-input[type="radio"]:checked+label:after, .comfino-input[type="radio"]:not(:checked)+label:after {
content: '';
width: 8px;
height: 8px;
background: #599e33;
;
position: absolute;
/* top: 4px; */
left: 7px;
border-radius: 100%;
-webkit-transition: all 0.2s ease;
transition: all 0.2s ease;
}
.comfino-input[type="radio"]:not(:checked)+label:after {
opacity: 0;
-webkit-transform: scale(0);
transform: scale(0);
}
.comfino-input[type="radio"]:checked+label:after {
opacity: 1;
-webkit-transform: scale(1);
transform: scale(1);
}
.comfino-payment-box {
background-color: rgb(221, 221, 221);
display: flex;
flex-direction: column;
align-items: center;
padding: 1rem 0;
font-size: 1.2rem;
margin-top: 1rem;
}
.comfino-payment-title {
color: #666;
margin-bottom: 7px;
}
.comfino-total-payment {
font-weight: bold;
}
.comfino-payment-delay {
padding: 1rem;
}
.comfino-payment-delay__title {
text-align: center;
font-weight: bold;
font-size: 1.2rem;
}
.comfino-payment-delay__title span {
display: block;
color: #599e33;
padding: .3rem 0;
}
.comfino-payment-delay__box {
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
}
.comfino-helper-box {
display: flex;
margin-top: 10px;
}
.comfino-payment-delay__single-instruction {
width: 140px;
margin: 10px;
display: flex;
flex-direction: column;
align-items: center;
}
.comfino-single-instruction__text {
text-align: center;
font-size: .9rem;
padding-top: 1rem;
color: #666;
}
.comfino-single-instruction-img__background {
width: 50px;
height: 50px;
background-color: #599e33;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
padding: .5rem;
}
.comfino-single-instruction-img {
width: 100px;
filter: invert(100%)
}
.comfino-total-payment {
font-weight: bold;
}
.comfino-installments-box {
display: flex;
flex-direction: column;
}
.comfino-installments-title {
font-size: 1.2rem;
font-weight: bold;
text-align: center;
padding: 20px 0;
}
.comfino-quantity-select {
display: flex;
align-items: center;
flex-wrap: wrap;
max-width: 90%;
justify-content: center;
margin: 0 auto;
}
.comfino-select-box {
display: flex;
}
.comfino-installments-quantity {
width: 50px;
height: 50px;
border-radius: 50%;
background-color: rgb(221, 221, 221);
display: flex;
align-items: center;
justify-content: center;
color: #fff;
font-size: 1.4rem;
margin: 10px 20px;
cursor: pointer;
}
@media screen and (max-width: 980px) {
.comfino-installments-quantity {
margin: 5px 10px;
}
}
.comfino-active {
background-color: #599e33;;
}
.comfino-monthly-box {
background-color: #599e33;;
display: flex;
flex-direction: column;
align-items: center;
padding: 1rem 0;
font-size: 1.2rem;
color: #fff;
margin-top: 1rem;
}
.comfino-monthly-title {
font-size: 1.2rem;
text-align: center;
margin-bottom: 7px;
}
.comfino-monthly-rate {
font-weight: bold;
}
.comfino-max_wrap { height: 7px; }
.comfino-summary-box {
text-align: center;
font-size: .8rem;
color: gray;
}
.comfino-summary-total {
padding: .5rem 0;
}
.comfino-rrso {}
.comfino-footer-link {
display: block;
text-align: center;
padding: .5rem 0;
color: gray;
font-size: .7rem;
margin: 7px 0;
text-decoration: underline;
cursor: pointer;
}
.comfino-footer-link:hover {
opacity: 0.9;
}
.mx_comfino_popup_mask {
position: fixed;
left: 0;
top: 0;
background: rgba(0,0,0,0.2);
z-index: 100;
width: 100%;
height: 100%;
display: grid;
justify-content: center;
align-items: center;
place-items: center;
}
.mx_comfino_popup {
background-color: #fff;
border-radius: 20px;
padding: 40px;
font-size: 13px;
color: #6d6d6d;
position: relative;
width: 80%;
min-width: 260px;
}
.mx_comfino_popup_close {
position: absolute;
top: 20px;
right: 20px;
font-size: 37px;
font-weight: bold;
cursor: pointer;
}
.mx_comfino_popup_close:hover{
opacity: 0.9;
}`;
let style = document.createElement('style');
if (style.styleSheet) {
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
document.getElementsByTagName('head')[0].appendChild(style);
}
//END KOSZYK
};
// init aplikacji po załadowaniu frontApi
let fApiWait = function() {
if(!window.frontAPI) {
setTimeout(fApiWait,1);
return;
}
mxComfinoInit();
}
fApiWait();
//END init
});