app/Plugin/VeriTrans4G2/Resource/template/default/js/vt4g_js.twig line 1

Open in your IDE?
  1. {#
  2. Copyright (c) 2018 VeriTrans Inc., a Digital Garage company. All rights reserved.
  3. http://www.veritrans.co.jp/
  4. #}
  5. {{ include('VeriTrans4G2/Resource/template/default/css/vt4g_css.twig') }}
  6. {% if recaptchaAipUrl is not empty %}
  7.     <script src="{{ recaptchaAipUrl }}"></script>
  8. {% endif %}
  9. <script>
  10.     // 名前空間を設定
  11.     window.VeriTrans4G = window.VeriTrans4G || {};
  12.     VeriTrans4G.executeSubmit = function(form) {
  13.         {% if useRecaptcha %}
  14.             var tokenInput = document.getElementById('vt4g_recaptcha_token');
  15.             if (tokenInput == undefined) {
  16.                 $('#shopping-form').append('<input type="hidden" name="vt4g_recaptcha_token" id="vt4g_recaptcha_token">');
  17.                 tokenInput = document.getElementById('vt4g_recaptcha_token');
  18.             }
  19.             try {
  20.                 grecaptcha.execute("{{ recaptchaSiteKey }}", {action: 'vt4g_shopping_index'}).then(token => {
  21.                     tokenInput.value = token;
  22.                     form.submit();
  23.                 });
  24.             } catch (error) {
  25.                 console.error('reCAPTCHAトークン取得エラー',error);
  26.                 form.submit();
  27.             }
  28.         {% else %}
  29.             form.submit();
  30.         {% endif %}
  31.     }
  32.     // 決済方法ごとの処理
  33.     VeriTrans4G.processByPayment = function(e) {
  34.         var elm = e.currentTarget;
  35.         var form = $(elm).parents('form');
  36.         {% if payTypeId == '10' %}
  37.             $('.accordion_inner:visible').each(function(){
  38.                 var currentAccordion = $(this).parent();
  39.                 var targetId = currentAccordion.attr('id');
  40.                 switch (targetId) {
  41.                     case 'vt4g-credit-account':
  42.                         currentAccordion.find('input[name="mode"]').val('account');
  43.                         break;
  44.                     case 'vt4g-credit-retrade':
  45.                         currentAccordion.find('input[name="mode"]').val('retrade');
  46.                         break;
  47.                     case 'vt4g-credit':
  48.                         currentAccordion.find('input[name="mode"]').val('token');
  49.                         break;
  50.                     default:
  51.                         break;
  52.                 }
  53.                 VeriTrans4G.setSubmit(e, targetId);
  54.             });
  55.         {% elseif payTypeId == '20' %}
  56.             var field = document.querySelector('[name="payment_cvs[conveni]"]');
  57.             var value = field.value;
  58.             if (value == '' || value == null) {
  59.                 $(field).parent().addClass('error');
  60.                 $(field).next('.ec-errorMessage').text('※ 選択されていません。');
  61.                 VeriTrans4G.scrollIntoView();
  62.                 e.stopPropagation();
  63.                 loadingOverlay("hide");
  64.                 return false;
  65.             } else {
  66.                 VeriTrans4G.executeSubmit(form);
  67.             }
  68.         {% else %}
  69.             VeriTrans4G.executeSubmit(form);
  70.         {% endif %}
  71.     }
  72.     $(function() {
  73.         $('button.ec-blockBtn--action').on('click', function(e) {
  74.             e.preventDefault();
  75.             window.loadingOverlay();
  76.             {% if useThrottling %}
  77.                 {% set csrfToken = csrf_token('vt4g_rate_limitter') %}
  78.                 var params = {
  79.                     token: "{{ csrfToken }}",
  80.                     cosutomer_id: "{{ customerId }}",
  81.                     order_id: "{{ orderId }}",
  82.                 };
  83.                 fetch("{{ url }}",{
  84.                     method: 'POST',
  85.                     headers: {
  86.                         'Content-Type': 'application/json'
  87.                     },
  88.                     body: JSON.stringify(params)
  89.                 })
  90.                 .then(response => response.text())
  91.                 .then(content => {
  92.                     if (content == '') {
  93.                         VeriTrans4G.processByPayment(e);
  94.                     } else {
  95.                         window.location.href = content;
  96.                     }
  97.                 })
  98.                 .catch(error => {
  99.                     console.error('ご注文手続き画面確認ボタン押下回数制限エラー:', error);
  100.                     loadingOverlay("hide");
  101.                 });
  102.             {% else %}
  103.                 VeriTrans4G.processByPayment(e);
  104.             {% endif %}
  105.         });
  106.         {% if useThrottling and payTypeId == '10' %}
  107.             // requiredの除去(別JSでチェック実施)
  108.             document.getElementById('vt4g_card_no').required = false;
  109.             document.getElementById('vt4g_expiry_mon').required = false;
  110.             document.getElementById('payment_credit_expiry_year').required = false;
  111.             document.getElementById('payment_credit_card_name').required = false;
  112.             var cardRedist0 = document.getElementById('payment_credit_cardinfo_regist_0');
  113.             var cardRedist1 = document.getElementById('payment_credit_cardinfo_regist_1');
  114.             var cardRetrade0 = document.getElementById('payment_credit_cardinfo_retrade_0');
  115.             var cardRetrade1 = document.getElementById('payment_credit_cardinfo_retrade_1');
  116.             if(cardRedist0 !== null){
  117.                 cardRedist0.required = false;
  118.             }
  119.             if(cardRedist1 !== null){
  120.                 cardRedist1.required = false;
  121.             }
  122.             if(cardRetrade0 !== null){
  123.                 cardRetrade0.required = false;
  124.             }
  125.             if(cardRetrade1 !== null){
  126.                 cardRetrade1.required = false;
  127.             }
  128.         {% endif %}
  129.     })
  130. </script>