{#
Copyright (c) 2018 VeriTrans Inc., a Digital Garage company. All rights reserved.
http://www.veritrans.co.jp/
#}
{{ include('VeriTrans4G2/Resource/template/default/css/vt4g_css.twig') }}
{% if recaptchaAipUrl is not empty %}
<script src="{{ recaptchaAipUrl }}"></script>
{% endif %}
<script>
// 名前空間を設定
window.VeriTrans4G = window.VeriTrans4G || {};
VeriTrans4G.executeSubmit = function(form) {
{% if useRecaptcha %}
var tokenInput = document.getElementById('vt4g_recaptcha_token');
if (tokenInput == undefined) {
$('#shopping-form').append('<input type="hidden" name="vt4g_recaptcha_token" id="vt4g_recaptcha_token">');
tokenInput = document.getElementById('vt4g_recaptcha_token');
}
try {
grecaptcha.execute("{{ recaptchaSiteKey }}", {action: 'vt4g_shopping_index'}).then(token => {
tokenInput.value = token;
form.submit();
});
} catch (error) {
console.error('reCAPTCHAトークン取得エラー',error);
form.submit();
}
{% else %}
form.submit();
{% endif %}
}
// 決済方法ごとの処理
VeriTrans4G.processByPayment = function(e) {
var elm = e.currentTarget;
var form = $(elm).parents('form');
{% if payTypeId == '10' %}
$('.accordion_inner:visible').each(function(){
var currentAccordion = $(this).parent();
var targetId = currentAccordion.attr('id');
switch (targetId) {
case 'vt4g-credit-account':
currentAccordion.find('input[name="mode"]').val('account');
break;
case 'vt4g-credit-retrade':
currentAccordion.find('input[name="mode"]').val('retrade');
break;
case 'vt4g-credit':
currentAccordion.find('input[name="mode"]').val('token');
break;
default:
break;
}
VeriTrans4G.setSubmit(e, targetId);
});
{% elseif payTypeId == '20' %}
var field = document.querySelector('[name="payment_cvs[conveni]"]');
var value = field.value;
if (value == '' || value == null) {
$(field).parent().addClass('error');
$(field).next('.ec-errorMessage').text('※ 選択されていません。');
VeriTrans4G.scrollIntoView();
e.stopPropagation();
loadingOverlay("hide");
return false;
} else {
VeriTrans4G.executeSubmit(form);
}
{% else %}
VeriTrans4G.executeSubmit(form);
{% endif %}
}
$(function() {
$('button.ec-blockBtn--action').on('click', function(e) {
e.preventDefault();
window.loadingOverlay();
{% if useThrottling %}
{% set csrfToken = csrf_token('vt4g_rate_limitter') %}
var params = {
token: "{{ csrfToken }}",
cosutomer_id: "{{ customerId }}",
order_id: "{{ orderId }}",
};
fetch("{{ url }}",{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(params)
})
.then(response => response.text())
.then(content => {
if (content == '') {
VeriTrans4G.processByPayment(e);
} else {
window.location.href = content;
}
})
.catch(error => {
console.error('ご注文手続き画面確認ボタン押下回数制限エラー:', error);
loadingOverlay("hide");
});
{% else %}
VeriTrans4G.processByPayment(e);
{% endif %}
});
{% if useThrottling and payTypeId == '10' %}
// requiredの除去(別JSでチェック実施)
document.getElementById('vt4g_card_no').required = false;
document.getElementById('vt4g_expiry_mon').required = false;
document.getElementById('payment_credit_expiry_year').required = false;
document.getElementById('payment_credit_card_name').required = false;
var cardRedist0 = document.getElementById('payment_credit_cardinfo_regist_0');
var cardRedist1 = document.getElementById('payment_credit_cardinfo_regist_1');
var cardRetrade0 = document.getElementById('payment_credit_cardinfo_retrade_0');
var cardRetrade1 = document.getElementById('payment_credit_cardinfo_retrade_1');
if(cardRedist0 !== null){
cardRedist0.required = false;
}
if(cardRedist1 !== null){
cardRedist1.required = false;
}
if(cardRetrade0 !== null){
cardRetrade0.required = false;
}
if(cardRetrade1 !== null){
cardRetrade1.required = false;
}
{% endif %}
})
</script>