diff --git a/includes/blocks/assets/js/build/omise_fpx.asset.php b/includes/blocks/assets/js/build/omise_fpx.asset.php index 052c7bb6..20499093 100644 --- a/includes/blocks/assets/js/build/omise_fpx.asset.php +++ b/includes/blocks/assets/js/build/omise_fpx.asset.php @@ -1 +1 @@ - array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '5951a588e6a47ee3e88d47cac5cfe115'); \ No newline at end of file + array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '449ba1e9fbdfe36ffe11aee7d7ddd2b7'); \ No newline at end of file diff --git a/includes/blocks/assets/js/build/omise_fpx.js b/includes/blocks/assets/js/build/omise_fpx.js index b8859da0..39c796af 100644 --- a/includes/blocks/assets/js/build/omise_fpx.js +++ b/includes/blocks/assets/js/build/omise_fpx.js @@ -1 +1 @@ -(()=>{"use strict";const e=window.React,t=window.wp.element,n=window.wp.i18n,a=window.wp.htmlEntities,l=window.wc.wcBlocksRegistry,s=(0,window.wc.wcSettings.getSetting)("omise_fpx_data",{}),c=(0,a.decodeEntities)(s.title)||"No title set",r=l=>{const{eventRegistration:c,emitResponse:r}=l,{onPaymentSetup:o}=c,i=(0,a.decodeEntities)(s.description||""),{bank_list:m}=s.data,d=(0,n.__)("FPX is currently not available.","omise"),p=(0,t.useRef)(null);return(0,t.useEffect)((()=>{const e=o((async()=>{if(!p.current)return{type:r.responseTypes.ERROR,message:"Select a bank"};try{return{type:r.responseTypes.SUCCESS,meta:{paymentMethodData:{bank:p.current}}}}catch(e){return{type:r.responseTypes.ERROR,message:e.message}}}));return()=>e()}),[o]),(0,e.createElement)(e.Fragment,null,i&&(0,e.createElement)("p",null,i),0==m.length?(0,e.createElement)("p",null,d):(0,e.createElement)("fieldset",{id:"omise-form-installment"},(0,e.createElement)("div",{className:"fpx-select-bank"},(0,e.createElement)("label",{htmlFor:"fpx-select-bank"},"Select Bank"),(0,e.createElement)("select",{className:"fpx-bank-logo default",id:"fpx-select-bank",name:"source[bank]",defaultValue:"",onChange:e=>{p.current=e.target.value}},(0,e.createElement)("option",{value:"",disabled:!0},"-- Select your option --"),m.map((t=>(0,e.createElement)("option",{key:t.code,className:t.code,value:t.code,disabled:"1"===t.active},t.name,!t.active&&" (offline)"))))),(0,e.createElement)("div",{className:"fpx-terms-and-conditions-block"},(0,e.createElement)("span",null,"By clicking on the ",(0,e.createElement)("b",null,'"Place Order"')," button, you agree to FPX's",(0,e.createElement)("a",{href:"https://www.mepsfpx.com.my/FPXMain/termsAndConditions.jsp",target:"_blank"},"Terms and Conditions")))))};(0,l.registerPaymentMethod)({name:s.name||"",label:(0,e.createElement)((t=>{const{PaymentMethodLabel:n}=t.components;return(0,e.createElement)(n,{text:c})}),null),content:(0,e.createElement)(r,null),edit:(0,e.createElement)(r,null),canMakePayment:()=>!0,ariaLabel:c,supports:{features:s.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_fpx_data",{}),r=(0,a.decodeEntities)(l.title)||"No title set",c=s=>{const{eventRegistration:r,emitResponse:c}=s,{onPaymentSetup:o}=r,i=(0,a.decodeEntities)(l.description||""),{bank_list:m}=l.data,p=(0,n.__)("FPX is currently not available.","omise"),d=(0,t.useRef)(null);return(0,t.useEffect)((()=>{const e=o((async()=>{if(!d.current)return{type:c.responseTypes.ERROR,message:"Select a bank"};try{return{type:c.responseTypes.SUCCESS,meta:{paymentMethodData:{bank:d.current}}}}catch(e){return{type:c.responseTypes.ERROR,message:e.message}}}));return()=>e()}),[c.responseTypes.ERROR,c.responseTypes.SUCCESS,o]),(0,e.createElement)(e.Fragment,null,i&&(0,e.createElement)("p",null,i),0==m.length?(0,e.createElement)("p",null,p):(0,e.createElement)("fieldset",{id:"omise-form-installment"},(0,e.createElement)("div",{className:"fpx-select-bank"},(0,e.createElement)("label",{htmlFor:"fpx-select-bank"},"Select Bank"),(0,e.createElement)("select",{className:"fpx-bank-logo default",id:"fpx-select-bank",name:"source[bank]",defaultValue:"",onChange:e=>{d.current=e.target.value}},(0,e.createElement)("option",{value:"",disabled:!0},"-- Select your option --"),m.map((t=>(0,e.createElement)("option",{key:t.code,className:t.code,value:t.code,disabled:"1"===t.active},t.name,!t.active&&" (offline)"))))),(0,e.createElement)("div",{className:"fpx-terms-and-conditions-block"},(0,e.createElement)("span",null,"By clicking on the ",(0,e.createElement)("b",null,'"Place Order"')," button, you agree to FPX's",(0,e.createElement)("a",{href:"https://www.mepsfpx.com.my/FPXMain/termsAndConditions.jsp",target:"_blank"},"Terms and Conditions")))))};(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)(c,null),edit:(0,e.createElement)(c,null),canMakePayment:()=>!0,ariaLabel:r,supports:{features:l.supports}})})(); \ No newline at end of file diff --git a/includes/blocks/assets/js/build/omise_installment.asset.php b/includes/blocks/assets/js/build/omise_installment.asset.php index 893e920d..686cafac 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' => '2abd4215eaac67e9b0541242851edae3'); \ No newline at end of file + array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '0870d052051799446a862b643aaa00a1'); \ No newline at end of file diff --git a/includes/blocks/assets/js/build/omise_internetbanking.asset.php b/includes/blocks/assets/js/build/omise_internetbanking.asset.php new file mode 100644 index 00000000..c86e6b44 --- /dev/null +++ b/includes/blocks/assets/js/build/omise_internetbanking.asset.php @@ -0,0 +1 @@ + array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '5a7c1ca9a881b022e773ff44a4c3f27c'); \ No newline at end of file diff --git a/includes/blocks/assets/js/build/omise_internetbanking.js b/includes/blocks/assets/js/build/omise_internetbanking.js new file mode 100644 index 00000000..5fc44ba5 --- /dev/null +++ b/includes/blocks/assets/js/build/omise_internetbanking.js @@ -0,0 +1 @@ +(()=>{"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_internetbanking_data",{}),i=(0,a.decodeEntities)(l.title)||"No title set",r=s=>{const{eventRegistration:i,emitResponse:r}=s,{onPaymentSetup:m}=i,o=(0,a.decodeEntities)(l.description||""),[c,b]=(0,t.useState)(null),p=e=>{b(e.target.value)};return(0,t.useEffect)((()=>{const e=m((async()=>{if(!c)return{type:r.responseTypes.ERROR,message:"Select a bank"};try{return{type:r.responseTypes.SUCCESS,meta:{paymentMethodData:{"omise-offsite":c}}}}catch(e){return{type:r.responseTypes.ERROR,message:e.message}}}));return()=>e()}),[r.responseTypes.ERROR,r.responseTypes.SUCCESS,m,c]),(0,e.createElement)(e.Fragment,null,o&&(0,e.createElement)("p",null,o),(0,e.createElement)("fieldset",{id:"omise-form-internetbanking"},(0,e.createElement)("ul",{className:"omise-banks-list"},(0,e.createElement)("li",{className:"item"},(0,e.createElement)("input",{id:"internet_banking_bay",type:"radio",name:"omise-offsite",value:"internet_banking_bay",onChange:p}),(0,e.createElement)("label",{htmlFor:"internet_banking_bay"},(0,e.createElement)("div",{className:"bank-logo bay"}),(0,e.createElement)("div",{className:"bank-label"},(0,e.createElement)("span",{className:"title"},(0,n.__)("Krungsri Bank","omise")),(0,e.createElement)("br",null),(0,e.createElement)("span",{className:"omise-secondary-text"},(0,n.__)("Fee: 15 THB (same zone), 15 THB (out zone)","omise"))))),(0,e.createElement)("li",{className:"item"},(0,e.createElement)("input",{id:"internet_banking_bbl",type:"radio",name:"omise-offsite",value:"internet_banking_bbl",onChange:p}),(0,e.createElement)("label",{htmlFor:"internet_banking_bbl"},(0,e.createElement)("div",{className:"bank-logo bbl"}),(0,e.createElement)("div",{className:"bank-label"},(0,e.createElement)("span",{className:"title"},(0,n.__)("Bangkok Bank","omise")),(0,e.createElement)("br",null),(0,e.createElement)("span",{className:"omise-secondary-text"},(0,n.__)("Fee: 10 THB (same zone), 20 THB (out zone)","omise"))))))))};(0,s.registerPaymentMethod)({name:l.name||"",label:(0,e.createElement)((t=>{const{PaymentMethodLabel:n}=t.components;return(0,e.createElement)(n,{text:i})}),null),content:(0,e.createElement)(r,null),edit:(0,e.createElement)(r,null),canMakePayment:()=>!0,ariaLabel:i,supports:{features:l.supports}})})(); \ No newline at end of file diff --git a/includes/blocks/assets/js/omise-fpx.js b/includes/blocks/assets/js/omise-fpx.js index 409cd080..8387382f 100644 --- a/includes/blocks/assets/js/omise-fpx.js +++ b/includes/blocks/assets/js/omise-fpx.js @@ -40,7 +40,11 @@ const FpxPaymentMethod = (props) => { } }); return () => unsubscribe(); - }, [ onPaymentSetup ]); + }, [ + emitResponse.responseTypes.ERROR, + emitResponse.responseTypes.SUCCESS, + onPaymentSetup, + ]); return (<> {description &&

{description}

} diff --git a/includes/blocks/assets/js/omise-installment.js b/includes/blocks/assets/js/omise-installment.js index 89d0b930..d557be66 100644 --- a/includes/blocks/assets/js/omise-installment.js +++ b/includes/blocks/assets/js/omise-installment.js @@ -1,4 +1,4 @@ -import {useEffect, useState, useRef} from '@wordpress/element'; +import {useEffect, useRef} from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { decodeEntities } from '@wordpress/html-entities'; import { registerPaymentMethod } from '@woocommerce/blocks-registry'; diff --git a/includes/blocks/assets/js/omise-internetbanking.js b/includes/blocks/assets/js/omise-internetbanking.js new file mode 100644 index 00000000..4cea7c89 --- /dev/null +++ b/includes/blocks/assets/js/omise-internetbanking.js @@ -0,0 +1,94 @@ +import {useEffect, useState} from '@wordpress/element'; +import { __ } from '@wordpress/i18n'; +import { decodeEntities } from '@wordpress/html-entities'; +import { registerPaymentMethod } from '@woocommerce/blocks-registry'; +import { getSetting } from '@woocommerce/settings'; + +const settings = getSetting( 'omise_internetbanking_data', {} ) +const label = decodeEntities( settings.title ) || 'No title set' +const Label = ( props ) => { + const { PaymentMethodLabel } = props.components + return +} + +const InternetBankingPaymentMethod = (props) => { + const {eventRegistration, emitResponse} = props; + const {onPaymentSetup} = eventRegistration; + const description = decodeEntities( settings.description || '' ) + const [selectedBank, setSelectedBank] = useState(null); + + const onBankSelected = (e) => { + setSelectedBank(e.target.value) + } + + useEffect(() => { + const unsubscribe = onPaymentSetup(async () => { + if (!selectedBank) { + return {type: emitResponse.responseTypes.ERROR, message: 'Select a bank'} + } + + try { + return { + type: emitResponse.responseTypes.SUCCESS, + meta: { + paymentMethodData: { + "omise-offsite": selectedBank, + } + } + }; + } catch (error) { + return {type: emitResponse.responseTypes.ERROR, message: error.message} + } + }); + return () => unsubscribe(); + }, [ + emitResponse.responseTypes.ERROR, + emitResponse.responseTypes.SUCCESS, + onPaymentSetup, + selectedBank + ]); + + return (<> + {description &&

{description}

} +
+ +
+ + ) +} + +registerPaymentMethod( { + name: settings.name || "", + label: