diff --git a/assets/javascripts/omise-payment-form-handler.js b/assets/javascripts/omise-payment-form-handler.js index db5a3970..3a0a473c 100755 --- a/assets/javascripts/omise-payment-form-handler.js +++ b/assets/javascripts/omise-payment-form-handler.js @@ -65,27 +65,15 @@ } function omiseInstallmentFormHandler() { - function getSelectedCardId() { - const $selected_card_id = $("input[name='card_id']:checked"); - if ($selected_card_id.length > 0) { - return $selected_card_id.val(); - } - - return ""; + if (!$('#payment_method_omise_installment').is(':checked')) { + return true; } - if ($('#payment_method_omise_installment').is(':checked')) { - if (getSelectedCardId() !== "") { - //submit the form right away if the card_id is not blank - return true; - } - - if (0 === $('input.omise_token').length && 0 === $('input.omise_source').length) { - requestCardToken(); - return false; - } - return true; + if (0 === $('input.omise_token').length && 0 === $('input.omise_source').length) { + requestCardToken(); + return false; } + return true; } @@ -272,13 +260,13 @@ function setupOmiseForm() { var selectedPaymentMethod = $('input[name="payment_method"]:checked').val(); - if (selectedPaymentMethod === 'omise') { - initializeSecureCardForm(); - } else if (selectedPaymentMethod === 'omise_installment') { - initializeInstallmentForm(); - } else { - OmiseCard.destroy(); - } + if (selectedPaymentMethod === 'omise') { + initializeSecureCardForm(); + } else if (selectedPaymentMethod === 'omise_installment') { + initializeInstallmentForm(); + } else { + OmiseCard.destroy(); + } } $(function () { diff --git a/includes/blocks/assets/js/build/omise_installment.asset.php b/includes/blocks/assets/js/build/omise_installment.asset.php index 5d88bbbf..428316a6 100644 --- a/includes/blocks/assets/js/build/omise_installment.asset.php +++ b/includes/blocks/assets/js/build/omise_installment.asset.php @@ -1 +1 @@ - array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => 'e2436da6ade36f0dc6835eb771337040'); \ No newline at end of file + array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '34ae2a7f9367048bb27a58ad9955227b'); \ No newline at end of file diff --git a/includes/blocks/assets/js/build/omise_installment.js b/includes/blocks/assets/js/build/omise_installment.js index 84f607e0..05d60ae0 100644 --- a/includes/blocks/assets/js/build/omise_installment.js +++ b/includes/blocks/assets/js/build/omise_installment.js @@ -1 +1 @@ -(()=>{"use strict";const e=window.React,t=window.wp.element,n=window.wp.i18n,a=window.wp.htmlEntities,s=window.wc.wcBlocksRegistry,r=(0,window.wc.wcSettings.getSetting)("omise_installment_data",{}),l=(0,a.decodeEntities)(r.title)||"No title set",{select:o,subscribe:c}=window.wp.data,i=window.wc.wcBlocksData.CART_STORE_KEY,u=s=>{const{eventRegistration:l,emitResponse:u}=s,{onPaymentSetup:m,onCheckoutValidation:w,onCheckoutFail:d}=l,p=(0,a.decodeEntities)(r.description||""),{installments_enabled:E,total_amount:f,public_key:y}=r.data,h=(0,n.__)("Purchase Amount is lower than the monthly minimum payment amount.","omise"),_=(0,t.useRef)(null),R=(0,t.useRef)(null),g=(0,t.useRef)(null),C=(0,t.useRef)(null),k=()=>{if(E){const e=o(i).getCartData();C.current=e.totals.total_price;let t=r.locale.toLowerCase();t=["en","th","ja"].includes(t)?t:"en",_.current.innerHTML="",showOmiseInstallmentForm({element:_.current,publicKey:y,amount:C.current,locale:t,onSuccess:e=>{R.current=e},onError:e=>{g.current=e}})}},b=()=>{const e=o(i).getCartData();C.current=e.totals.total_price,k()};return(0,t.useEffect)((()=>c(b,i)),[i]),(0,t.useEffect)((()=>{k()}),[E]),(0,t.useEffect)((()=>w((()=>(OmiseCard.requestCardToken(),!0)))),[w]),(0,t.useEffect)((()=>d((()=>(R.current=null,k(),!0)))),[d]),(0,t.useEffect)((()=>{const e=m((async()=>await new Promise(((e,t)=>{const n=setInterval((()=>{if(R.current){clearInterval(n);try{const t={type:u.responseTypes.SUCCESS,meta:{paymentMethodData:{omise_source:R.current.source,omise_token:R.current.token}}};e(t)}catch(e){clearInterval(n);const a={type:u.responseTypes.ERROR,message:e.message};t(a)}}}),1e3)}))));return()=>e()}),[m]),(0,e.createElement)(e.Fragment,null,p&&(0,e.createElement)("p",null,p),E?(0,e.createElement)("div",{ref:_,id:"omise-installment",style:{width:"100%",maxWidth:"400px"}}):(0,e.createElement)("p",null,h))};(0,s.registerPaymentMethod)({name:r.name||"",label:(0,e.createElement)((t=>{const{PaymentMethodLabel:n}=t.components;return(0,e.createElement)(n,{text:l})}),null),content:(0,e.createElement)(u,null),edit:(0,e.createElement)(u,null),canMakePayment:()=>r.is_active,ariaLabel:l,supports:{features:r.supports}})})(); \ No newline at end of file +(()=>{"use strict";const e=window.React,t=window.wp.element,n=window.wp.i18n,a=window.wp.htmlEntities,s=window.wc.wcBlocksRegistry,l=(0,window.wc.wcSettings.getSetting)("omise_installment_data",{}),r=(0,a.decodeEntities)(l.title)||"No title set",{select:c,subscribe:o}=window.wp.data,i=window.wc.wcBlocksData?window.wc.wcBlocksData.CART_STORE_KEY:"",u=s=>{const{eventRegistration:r,emitResponse:u}=s,{onPaymentSetup:m,onCheckoutValidation:w,onCheckoutFail:d}=r,p=(0,a.decodeEntities)(l.description||""),{installments_enabled:E,total_amount:f,public_key:y}=l.data,h=(0,n.__)("Purchase Amount is lower than the monthly minimum payment amount.","omise"),_=(0,t.useRef)(null),R=(0,t.useRef)(null),g=(0,t.useRef)(null),k=(0,t.useRef)(null),C=()=>{if(E){const e=c(i).getCartData();k.current=e.totals.total_price;let t=l.locale.toLowerCase();t=["en","th","ja"].includes(t)?t:"en",_.current.innerHTML="",showOmiseInstallmentForm({element:_.current,publicKey:y,amount:k.current,locale:t,onSuccess:e=>{R.current=e},onError:e=>{g.current=e}})}},b=()=>{const e=c(i).getCartData();k.current=e.totals.total_price,C()};return(0,t.useEffect)((()=>o(b,i)),[i]),(0,t.useEffect)((()=>{C()}),[E]),(0,t.useEffect)((()=>w((()=>(OmiseCard.requestCardToken(),!0)))),[w]),(0,t.useEffect)((()=>d((()=>(R.current=null,C(),!0)))),[d]),(0,t.useEffect)((()=>{const e=m((async()=>await new Promise(((e,t)=>{const n=setInterval((()=>{if(R.current){clearInterval(n);try{const t={type:u.responseTypes.SUCCESS,meta:{paymentMethodData:{omise_source:R.current.source,omise_token:R.current.token}}};e(t)}catch(e){clearInterval(n);const a={type:u.responseTypes.ERROR,message:e.message};t(a)}}}),1e3)}))));return()=>e()}),[m]),(0,e.createElement)(e.Fragment,null,p&&(0,e.createElement)("p",null,p),E?(0,e.createElement)("div",{ref:_,id:"omise-installment",style:{width:"100%",maxWidth:"400px"}}):(0,e.createElement)("p",null,h))};(0,s.registerPaymentMethod)({name:l.name||"",label:(0,e.createElement)((t=>{const{PaymentMethodLabel:n}=t.components;return(0,e.createElement)(n,{text:r})}),null),content:(0,e.createElement)(u,null),edit:(0,e.createElement)(u,null),canMakePayment:()=>l.is_active,ariaLabel:r,supports:{features:l.supports}})})(); \ No newline at end of file diff --git a/includes/blocks/assets/js/omise-installment.js b/includes/blocks/assets/js/omise-installment.js index e0a0daed..70abaef7 100644 --- a/includes/blocks/assets/js/omise-installment.js +++ b/includes/blocks/assets/js/omise-installment.js @@ -12,7 +12,7 @@ const Label = ( props ) => { } const {select, subscribe} = window.wp.data; -const cartStoreKey = window.wc.wcBlocksData.CART_STORE_KEY; +const cartStoreKey = window.wc.wcBlocksData ? window.wc.wcBlocksData.CART_STORE_KEY : ''; const InstallmentPaymentMethod = (props) => { const {eventRegistration, emitResponse} = props; diff --git a/includes/gateway/class-omise-payment.php b/includes/gateway/class-omise-payment.php index eec5e5f5..a4360497 100644 --- a/includes/gateway/class-omise-payment.php +++ b/includes/gateway/class-omise-payment.php @@ -474,7 +474,6 @@ protected function payment_failed( $reason ) { $this->order()->update_status( 'failed' ); } - wc_add_notice( sprintf( wp_kses( $message, array( 'br' => array() ) ), __( $reason, 'omise' ) ), 'error' ); throw new \Exception(sprintf( wp_kses( $message, array( 'br' => array() ) ), __( $reason, 'omise' ) )); }