diff --git a/includes/blocks/assets/js/build/omise_fpx.asset.php b/includes/blocks/assets/js/build/omise_fpx.asset.php new file mode 100644 index 00000000..7a46b8d8 --- /dev/null +++ b/includes/blocks/assets/js/build/omise_fpx.asset.php @@ -0,0 +1 @@ + array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => 'ad14494b770706f08d98935ee6998d63'); \ 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 new file mode 100644 index 00000000..5d44ef7b --- /dev/null +++ b/includes/blocks/assets/js/build/omise_fpx.js @@ -0,0 +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 diff --git a/includes/blocks/assets/js/omise-fpx.js b/includes/blocks/assets/js/omise-fpx.js new file mode 100644 index 00000000..dfe9782a --- /dev/null +++ b/includes/blocks/assets/js/omise-fpx.js @@ -0,0 +1,98 @@ +import {useEffect, useState, useRef} 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_fpx_data', {} ) +const label = decodeEntities( settings.title ) || 'No title set' +const Label = ( props ) => { + const { PaymentMethodLabel } = props.components + return +} + +const FpxPaymentMethod = (props) => { + const {eventRegistration, emitResponse} = props; + const {onPaymentSetup} = eventRegistration; + const description = decodeEntities( settings.description || '' ) + const { bank_list } = settings.data; + const noPaymentMethods = __( 'FPX is currently not available.', 'omise' ); + const bankRef = useRef(null); + + const onChange = (e) => { + bankRef.current = e.target.value + } + + useEffect(() => { + const unsubscribe = onPaymentSetup(async () => { + if (!bankRef.current) { + return {type: emitResponse.responseTypes.ERROR, message: 'Select a bank'} + } + try { + return { + type: emitResponse.responseTypes.SUCCESS, + meta: { + paymentMethodData: { "bank": bankRef.current } + } + }; + } catch (error) { + return {type: emitResponse.responseTypes.ERROR, message: error.message} + } + }); + return () => unsubscribe(); + }, [ onPaymentSetup ]); + + return (<> + {description &&

{description}

} + { + bank_list.length == 0 + ?

{noPaymentMethods}

+ : ( +
+
+ + +
+
+ By clicking on the "Place Order" button, you agree to FPX's + + Terms and Conditions + + +
+
+ ) + } + ) +} + +registerPaymentMethod( { + name: settings.name, + label: