diff --git a/.gitignore b/.gitignore
index 765fc42e..38f849ed 100755
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,4 @@ vendor
.phpunit.result.cache
composer.lock
.nvmrc
+wp-content
diff --git a/composer.json b/composer.json
index 4b78e989..e2d6e7eb 100644
--- a/composer.json
+++ b/composer.json
@@ -6,9 +6,16 @@
"require-dev": {
"phpunit/phpunit": "^5.7 || ^9.5",
"mockery/mockery": "^1.6",
- "brain/monkey": "^2.6"
+ "brain/monkey": "^2.6",
+ "woocommerce/woocommerce-blocks": "^11.7"
},
"scripts": {
"test": "vendor/bin/phpunit --testdox --colors"
+ },
+ "config": {
+ "allow-plugins": {
+ "composer/installers": true,
+ "automattic/jetpack-autoloader": true
+ }
}
}
diff --git a/includes/blocks/assets/js/build/credit_card.asset.php b/includes/blocks/assets/js/build/credit_card.asset.php
index 198cafb2..484c165d 100644
--- a/includes/blocks/assets/js/build/credit_card.asset.php
+++ b/includes/blocks/assets/js/build/credit_card.asset.php
@@ -1 +1 @@
- array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '88ba4364a3f634f4b5463c95dd4574e6');
\ No newline at end of file
+ array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '85f6dde2a4f73007da7b68a01588b596');
\ No newline at end of file
diff --git a/includes/blocks/assets/js/build/credit_card.js b/includes/blocks/assets/js/build/credit_card.js
index b1b51212..72866702 100644
--- a/includes/blocks/assets/js/build/credit_card.js
+++ b/includes/blocks/assets/js/build/credit_card.js
@@ -1 +1 @@
-(()=>{"use strict";const e=window.React,t=window.wp.i18n,n=window.wc.wcBlocksRegistry,r=window.wp.htmlEntities,a=window.wc.wcSettings,s=window.wp.element,c=({onChange:n,existingCards:r})=>(0,e.createElement)(e.Fragment,null,(0,e.createElement)("h3",null,(0,t.__)("Use an existing card","omise")),(0,e.createElement)("ul",{className:"omise-customer-card-list"},r.map(((t,r)=>(0,e.createElement)("li",{key:t.id,className:"item"},(0,e.createElement)("input",{defaultChecked:0===r,id:`card-${t.id}`,type:"radio",name:"card_id",value:t.id,onChange:n}),(0,e.createElement)("label",{htmlFor:`card-${t.id}`},(0,e.createElement)("strong",null,t.brand)," xxxx ",t.last_digits))))),(0,e.createElement)("input",{id:"new_card_info",type:"radio",name:"card_id",value:"",onChange:n}),(0,e.createElement)("label",{id:"label-new_card_info",htmlFor:"new_card_info"},(0,e.createElement)("h3",null,(0,t.__)("Create a charge using new card","omise")))),i=t=>{const{settings:n}=t,{existing_cards:a,description:i}=n,l=(0,s.useRef)(null),o=(0,s.useRef)(!1),m=(0,s.useRef)(null),d=(0,s.useRef)(null),u=(0,s.useRef)(null),[p,_]=(0,s.useState)(a&&a.length>0),{eventRegistration:E,emitResponse:g}=t,{onPaymentSetup:y,onCheckoutValidation:h}=E;return(0,s.useEffect)((()=>{var e;p||showOmiseEmbeddedCardForm({element:l.current,publicKey:n.public_key,hideRememberCard:!n.user_logged_in,locale:n.lcoale,theme:null!==(e=n.card_form_theme)&&void 0!==e?e:"light",design:n.form_design,brandIcons:n.card_brand_icons,onSuccess:e=>{e.remember&&(o.current=e.remember),m.current=e.token},onError:e=>{u.current=e}})}),[p]),(0,s.useEffect)((()=>{if(!p)return h((()=>(OmiseCard.requestCardToken(),!0)))}),[h,p]),(0,s.useEffect)((()=>{const e=y((async()=>await new Promise(((e,t)=>{const n=setInterval((()=>{if(d.current&&""!==d.current.value){clearInterval(n);try{const t={type:g.responseTypes.SUCCESS,meta:{paymentMethodData:{card_id:d.current.value}}};e(t)}catch(e){const n={type:g.responseTypes.ERROR,message:e.message};t(n)}}else if(m.current&&""!==m.current.value){clearInterval(n);try{const t={type:g.responseTypes.SUCCESS,meta:{paymentMethodData:{omise_save_customer_card:o.current.value,omise_token:m.current}}};e(t)}catch(e){const n={type:g.responseTypes.ERROR,message:e.message};t(n)}}else if(u.current){clearInterval(n);const e={type:g.responseTypes.ERROR,message:u.current};t(e)}}),1e3)}))));return()=>e()}),[g.responseTypes.ERROR,g.responseTypes.SUCCESS,y]),(0,e.createElement)(e.Fragment,null,a&&a.length>0&&(0,e.createElement)(c,{existingCards:a,onChange:e=>{const t=e.target;_(""!==t.value),d.current=t}}),!p&&(0,e.createElement)("p",null,(0,r.decodeEntities)(i||"")),(0,e.createElement)("div",{ref:l,id:"omise-card",style:{width:"100%",display:p?"none":"block"}}),!p&&(0,e.createElement)(e.Fragment,null,(0,e.createElement)("input",{type:"hidden",name:"omise_save_customer_card",id:"omise_save_customer_card"}),(0,e.createElement)("input",{type:"hidden",className:"omise_token",name:"omise_token"})))},l=(0,a.getSetting)("omise_data",{}),o=(0,t.__)("Credit/Debit card","omise"),m=(0,r.decodeEntities)(l.title)||o;window.OMISE_CUSTOM_FONT_OTHER="Other";const d=t=>(0,e.createElement)(i,{...t,settings:l});(0,n.registerPaymentMethod)({name:l.name||"",label:(0,e.createElement)((t=>{const{PaymentMethodLabel:n}=t.components;return(0,e.createElement)(n,{text:m})}),null),content:(0,e.createElement)(d,{settings:l}),edit:(0,e.createElement)(d,{settings:l}),canMakePayment:()=>!0,ariaLabel:m,supports:{features:l.supports}})})();
\ No newline at end of file
+(()=>{"use strict";const e=window.React,t=window.wp.i18n,n=window.wc.wcBlocksRegistry,r=window.wp.htmlEntities,a=window.wc.wcSettings,s=window.wp.element,c=({onChange:n,existingCards:r})=>(0,e.createElement)(e.Fragment,null,(0,e.createElement)("h3",null,(0,t.__)("Use an existing card","omise")),(0,e.createElement)("ul",{className:"omise-customer-card-list"},r.map(((t,r)=>(0,e.createElement)("li",{key:t.id,className:"item"},(0,e.createElement)("input",{defaultChecked:0===r,id:`card-${t.id}`,type:"radio",name:"card_id",value:t.id,onChange:n}),(0,e.createElement)("label",{htmlFor:`card-${t.id}`},(0,e.createElement)("strong",null,t.brand)," xxxx ",t.last_digits))))),(0,e.createElement)("input",{id:"new_card_info",type:"radio",name:"card_id",value:"",onChange:n}),(0,e.createElement)("label",{id:"label-new_card_info",htmlFor:"new_card_info"},(0,e.createElement)("h3",null,(0,t.__)("Create a charge using new card","omise")))),i=t=>{const{settings:n}=t,{existing_cards:a,description:i}=n,l=(0,s.useRef)(null),o=(0,s.useRef)(!1),m=(0,s.useRef)(null),d=(0,s.useRef)(null),u=(0,s.useRef)(null),[p,_]=(0,s.useState)(a&&a.length>0),{eventRegistration:g,emitResponse:E}=t,{onPaymentSetup:y,onCheckoutValidation:h}=g;return(0,s.useEffect)((()=>{var e;p||showOmiseEmbeddedCardForm({element:l.current,publicKey:n.public_key,hideRememberCard:!n.user_logged_in,locale:n.lcoale,theme:null!==(e=n.card_form_theme)&&void 0!==e?e:"light",design:n.form_design,brandIcons:n.card_brand_icons,onSuccess:e=>{e.remember&&(o.current=e.remember),m.current=e.token},onError:e=>{u.current=e}})}),[p]),(0,s.useEffect)((()=>{if(!p)return h((()=>(OmiseCard.requestCardToken(),!0)))}),[h,p]),(0,s.useEffect)((()=>{const e=y((async()=>await new Promise(((e,t)=>{const n=setInterval((()=>{if(d.current&&""!==d.current.value){clearInterval(n);try{const t={type:E.responseTypes.SUCCESS,meta:{paymentMethodData:{card_id:d.current.value}}};e(t)}catch(e){const n={type:E.responseTypes.ERROR,message:e.message};t(n)}}else if(m.current&&""!==m.current.value){clearInterval(n);try{const t={type:E.responseTypes.SUCCESS,meta:{paymentMethodData:{omise_save_customer_card:o.current.value,omise_token:m.current}}};e(t)}catch(e){const n={type:E.responseTypes.ERROR,message:e.message};t(n)}}else if(u.current){clearInterval(n);const e={type:E.responseTypes.ERROR,message:u.current};t(e)}}),1e3)}))));return()=>e()}),[E.responseTypes.ERROR,E.responseTypes.SUCCESS,y]),(0,e.createElement)(e.Fragment,null,a&&a.length>0&&(0,e.createElement)(c,{existingCards:a,onChange:e=>{const t=e.target;_(""!==t.value),d.current=t}}),!p&&(0,e.createElement)("p",null,(0,r.decodeEntities)(i||"")),(0,e.createElement)("div",{ref:l,id:"omise-card",style:{width:"100%",display:p?"none":"block"}}),!p&&(0,e.createElement)(e.Fragment,null,(0,e.createElement)("input",{type:"hidden",name:"omise_save_customer_card",id:"omise_save_customer_card"}),(0,e.createElement)("input",{type:"hidden",className:"omise_token",name:"omise_token"})))},l=(0,a.getSetting)("omise_data",{}),o=(0,t.__)("Credit/Debit card","omise"),m=(0,r.decodeEntities)(l.title)||o;window.OMISE_CUSTOM_FONT_OTHER="Other",console.log({settings:l});const d=t=>(0,e.createElement)(i,{...t,settings:l});(0,n.registerPaymentMethod)({name:l.name||"",label:(0,e.createElement)((t=>{const{PaymentMethodLabel:n}=t.components;return(0,e.createElement)(n,{text:m})}),null),content:(0,e.createElement)(d,{settings:l}),edit:(0,e.createElement)(d,{settings:l}),canMakePayment:()=>l.is_active,ariaLabel:m,supports:{features:l.supports}})})();
\ No newline at end of file
diff --git a/includes/blocks/assets/js/build/omise-mobilebanking.asset.php b/includes/blocks/assets/js/build/omise-mobilebanking.asset.php
index 03cf21c2..d321bb8e 100644
--- a/includes/blocks/assets/js/build/omise-mobilebanking.asset.php
+++ b/includes/blocks/assets/js/build/omise-mobilebanking.asset.php
@@ -1 +1 @@
- array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '8300bb1e0ea5db8412514a952f045a85');
\ No newline at end of file
+ array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '1c1381978da7eeae827a289aa53203d9');
\ No newline at end of file
diff --git a/includes/blocks/assets/js/build/omise-mobilebanking.js b/includes/blocks/assets/js/build/omise-mobilebanking.js
index 4e01793b..b7ef921b 100644
--- a/includes/blocks/assets/js/build/omise-mobilebanking.js
+++ b/includes/blocks/assets/js/build/omise-mobilebanking.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,i=(0,window.wc.wcSettings.getSetting)("omise_mobilebanking_data",{}),s=(0,a.decodeEntities)(i.title)||"No title set",m=l=>{const{eventRegistration:s,emitResponse:m}=l,{onPaymentSetup:r}=s,o=(0,a.decodeEntities)(i.description||""),c=i.data.backends,d=(0,n.__)("There are no payment methods available.","omise"),p=(0,t.useRef)({}),u=e=>{p.current=e.target.value};return(0,t.useEffect)((()=>{const e=r((async()=>{try{return{type:m.responseTypes.SUCCESS,meta:{paymentMethodData:{"omise-offsite":p.current}}}}catch(e){return{type:m.responseTypes.ERROR,message:e.message}}}));return()=>e()}),[r]),(0,e.createElement)(e.Fragment,null,o&&(0,e.createElement)("p",null,o),0==c.length?(0,e.createElement)("p",null,d):(0,e.createElement)("fieldset",{key:"omise-form-mobilebanking"+c.length,id:"omise-form-mobilebanking"},(0,e.createElement)("ul",{className:"omise-banks-list"},c.map(((t,n)=>(0,e.createElement)("li",{key:t._id+n,className:"item mobile-banking"},(0,e.createElement)("div",null,(0,e.createElement)("input",{id:t._id,type:"radio",name:"omise-offsite",value:t._id,onChange:u}),(0,e.createElement)("label",{htmlFor:t._id},(0,e.createElement)("div",{className:`mobile-banking-logo ${t.provider_logo}`}),(0,e.createElement)("div",{className:"mobile-banking-label"},(0,e.createElement)("span",{className:"title"},t.provider_name),(0,e.createElement)("br",null))))))))))};(0,l.registerPaymentMethod)({name:i.name||"",label:(0,e.createElement)((t=>{const{PaymentMethodLabel:n}=t.components;return(0,e.createElement)(n,{text:s})}),null),content:(0,e.createElement)(m,null),edit:(0,e.createElement)(m,null),canMakePayment:()=>!0,ariaLabel:s,supports:{features:i.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,l=window.wc.wcBlocksRegistry,i=(0,window.wc.wcSettings.getSetting)("omise_mobilebanking_data",{}),s=(0,a.decodeEntities)(i.title)||"No title set",m=l=>{const{eventRegistration:s,emitResponse:m}=l,{onPaymentSetup:r}=s,o=(0,a.decodeEntities)(i.description||""),c=i.data.backends,d=(0,n.__)("There are no payment methods available.","omise"),p=(0,t.useRef)({}),u=e=>{p.current=e.target.value};return(0,t.useEffect)((()=>{const e=r((async()=>{try{return{type:m.responseTypes.SUCCESS,meta:{paymentMethodData:{"omise-offsite":p.current}}}}catch(e){return{type:m.responseTypes.ERROR,message:e.message}}}));return()=>e()}),[r]),(0,e.createElement)(e.Fragment,null,o&&(0,e.createElement)("p",null,o),0==c.length?(0,e.createElement)("p",null,d):(0,e.createElement)("fieldset",{key:"omise-form-mobilebanking"+c.length,id:"omise-form-mobilebanking"},(0,e.createElement)("ul",{className:"omise-banks-list"},c.map(((t,n)=>(0,e.createElement)("li",{key:t._id+n,className:"item mobile-banking"},(0,e.createElement)("div",null,(0,e.createElement)("input",{id:t._id,type:"radio",name:"omise-offsite",value:t._id,onChange:u}),(0,e.createElement)("label",{htmlFor:t._id},(0,e.createElement)("div",{className:`mobile-banking-logo ${t.provider_logo}`}),(0,e.createElement)("div",{className:"mobile-banking-label"},(0,e.createElement)("span",{className:"title"},t.provider_name),(0,e.createElement)("br",null))))))))))};(0,l.registerPaymentMethod)({name:i.name||"",label:(0,e.createElement)((t=>{const{PaymentMethodLabel:n}=t.components;return(0,e.createElement)(n,{text:s})}),null),content:(0,e.createElement)(m,null),edit:(0,e.createElement)(m,null),canMakePayment:()=>i.is_active,ariaLabel:s,supports:{features:i.supports}})})();
\ No newline at end of file
diff --git a/includes/blocks/assets/js/build/omise-one-click-apms.asset.php b/includes/blocks/assets/js/build/omise-one-click-apms.asset.php
index a658be8a..e86a5de5 100644
--- a/includes/blocks/assets/js/build/omise-one-click-apms.asset.php
+++ b/includes/blocks/assets/js/build/omise-one-click-apms.asset.php
@@ -1 +1 @@
- array('react', 'wc-blocks-registry', 'wc-settings', 'wp-html-entities', 'wp-i18n'), 'version' => '9e361f14bcb633d57aec2bede0ca58f2');
\ No newline at end of file
+ array('react', 'wc-blocks-registry', 'wc-settings', 'wp-html-entities', 'wp-i18n'), 'version' => 'e6fac6c16b43d5aef4854d8cb63f068d');
\ No newline at end of file
diff --git a/includes/blocks/assets/js/build/omise-one-click-apms.js b/includes/blocks/assets/js/build/omise-one-click-apms.js
index 9839276b..8787b1ed 100644
--- a/includes/blocks/assets/js/build/omise-one-click-apms.js
+++ b/includes/blocks/assets/js/build/omise-one-click-apms.js
@@ -1 +1 @@
-(()=>{"use strict";window.wp.i18n;const a=window.wp.htmlEntities,e=window.React,t=window.wc.wcBlocksRegistry;function o({settings:o,label:i}){const n=()=>(0,a.decodeEntities)(o.description||"");(0,t.registerPaymentMethod)({name:o.name||"",label:(0,e.createElement)((a=>{const{PaymentMethodLabel:t}=a.components;return(0,e.createElement)(t,{text:i})}),null),content:(0,e.createElement)(n,null),edit:(0,e.createElement)(n,null),canMakePayment:()=>!0,ariaLabel:i,supports:{features:o.supports}})}const i=window.wc.wcSettings,n=["omise_alipay_data","omise_alipay_cn_data","omise_alipay_hk_data","omise_dana_data","omise_gcash_data","omise_kakaopay_data","omise_promptpay_data","omise_touch_n_go_data","omise_billpayment_tesco_data","omise_shopeepay_data","omise_wechat_pay_data","omise_grabpay_data","omise_paynow_data","omise_ocbc_data","omise_fpx_data","omise_maybank_qr_data","omise_duitnow_qr_data","omise_paypay_data","omise_rabbit_linepay_data"];for(const e of n){const t=(0,i.getSetting)(e,{});t.name&&o({settings:t,label:(0,a.decodeEntities)(t.title)||"No title set"})}})();
\ No newline at end of file
+(()=>{"use strict";window.wp.i18n;const a=window.wp.htmlEntities,e=window.React,t=window.wc.wcBlocksRegistry;function i({settings:i,label:o}){const s=()=>(0,a.decodeEntities)(i.description||"");(0,t.registerPaymentMethod)({name:i.name||"",label:(0,e.createElement)((a=>{const{PaymentMethodLabel:t}=a.components;return(0,e.createElement)(t,{text:o})}),null),content:(0,e.createElement)(s,null),edit:(0,e.createElement)(s,null),canMakePayment:()=>i.is_active,ariaLabel:o,supports:{features:i.supports}})}const o=window.wc.wcSettings,s=["omise_alipay_data","omise_alipay_cn_data","omise_alipay_hk_data","omise_dana_data","omise_gcash_data","omise_kakaopay_data","omise_promptpay_data","omise_touch_n_go_data","omise_billpayment_tesco_data","omise_shopeepay_data","omise_wechat_pay_data","omise_grabpay_data","omise_paynow_data","omise_ocbc_data","omise_fpx_data","omise_maybank_qr_data","omise_duitnow_qr_data","omise_paypay_data","omise_rabbit_linepay_data"];for(const e of s){const t=(0,o.getSetting)(e,{});t.name&&i({settings:t,label:(0,a.decodeEntities)(t.title)||"No title set"})}})();
\ No newline at end of file
diff --git a/includes/blocks/assets/js/build/omise_atome.asset.php b/includes/blocks/assets/js/build/omise_atome.asset.php
index ab8704b3..f666f34c 100644
--- a/includes/blocks/assets/js/build/omise_atome.asset.php
+++ b/includes/blocks/assets/js/build/omise_atome.asset.php
@@ -1 +1 @@
- array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '338c1cd6b30d199b030020d82f9fae92');
\ No newline at end of file
+ array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '038fdf4e9f72acd0b7ba55de2c3b74a8');
\ No newline at end of file
diff --git a/includes/blocks/assets/js/build/omise_atome.js b/includes/blocks/assets/js/build/omise_atome.js
index ea21ffae..a65c80be 100644
--- a/includes/blocks/assets/js/build/omise_atome.js
+++ b/includes/blocks/assets/js/build/omise_atome.js
@@ -1 +1 @@
-(()=>{"use strict";const e=window.React,t=window.wp.element,n=window.wp.i18n,a=window.wp.htmlEntities,o=window.wc.wcBlocksRegistry,s=(0,window.wc.wcSettings.getSetting)("omise_atome_data",{}),m=(0,a.decodeEntities)(s.title)||"No title set",r=o=>{const{eventRegistration:m,emitResponse:r}=o,{onPaymentSetup:l}=m,i=(0,a.decodeEntities)(s.description||""),{status:p,message:c}=s.data,[u,d]=(0,t.useState)(!1),[_,w]=(0,t.useState)(!0),[E,h]=(0,t.useState)("");return(0,t.useEffect)((()=>{const e=l((async()=>{if(!_&&0===E.length)return{type:r.responseTypes.ERROR,message:"Enter a phone number"};try{return{type:r.responseTypes.SUCCESS,meta:{paymentMethodData:{omise_atome_phone_default:(_?1:0).toString(),omise_atome_phone_number:E}}}}catch(e){return{type:r.responseTypes.ERROR,message:e.message}}}));return()=>e()}),[l,r.responseTypes.ERROR,r.responseTypes.SUCCESS,_,E]),(0,e.createElement)(e.Fragment,null,i&&(0,e.createElement)("p",null,i),p?(0,e.createElement)("fieldset",{id:"omise-form-atome"},(0,n.__)("Atome phone number","omise"),(0,e.createElement)("br",null),(0,e.createElement)("p",{className:"form-row form-row-wide omise-label-inline"},(0,e.createElement)("input",{id:"omise_atome_phone_default",type:"checkbox",name:"omise_atome_phone_default",value:_,defaultChecked:!0,onChange:e=>{w(!_),d(!u),_&&h("")}}),(0,e.createElement)("label",{htmlFor:"omise_atome_phone_default"},(0,n.__)("Same as Billing Detail","omise"))),(0,e.createElement)("p",{id:"omise_atome_phone_field",className:"form-row form-row-wide",style:{display:u?"block":"none"}},(0,e.createElement)("span",{className:"woocommerce-input-wrapper"},(0,e.createElement)("input",{id:"omise_atome_phone_number",className:"input-text",name:"omise_atome_phone_number",type:"tel",autoComplete:"off",placeholder:"+66123456789",onChange:e=>{h(e.target.value)}}))),(0,e.createElement)("p",{className:"omise-secondary-text"},(0,n.__)("The phone number will be used for creating Atome charge","omise"))):(0,e.createElement)("p",null,c))};(0,o.registerPaymentMethod)({name:s.name||"",label:(0,e.createElement)((t=>{const{PaymentMethodLabel:n}=t.components;return(0,e.createElement)(n,{text:m})}),null),content:(0,e.createElement)(r,null),edit:(0,e.createElement)(r,null),canMakePayment:()=>!0,ariaLabel:m,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,o=window.wc.wcBlocksRegistry,s=(0,window.wc.wcSettings.getSetting)("omise_atome_data",{}),m=(0,a.decodeEntities)(s.title)||"No title set",r=o=>{const{eventRegistration:m,emitResponse:r}=o,{onPaymentSetup:l}=m,i=(0,a.decodeEntities)(s.description||""),{status:c,message:p}=s.data,[u,d]=(0,t.useState)(!1),[_,w]=(0,t.useState)(!0),[E,h]=(0,t.useState)("");return(0,t.useEffect)((()=>{const e=l((async()=>{if(!_&&0===E.length)return{type:r.responseTypes.ERROR,message:"Enter a phone number"};try{return{type:r.responseTypes.SUCCESS,meta:{paymentMethodData:{omise_atome_phone_default:(_?1:0).toString(),omise_atome_phone_number:E}}}}catch(e){return{type:r.responseTypes.ERROR,message:e.message}}}));return()=>e()}),[l,r.responseTypes.ERROR,r.responseTypes.SUCCESS,_,E]),(0,e.createElement)(e.Fragment,null,i&&(0,e.createElement)("p",null,i),c?(0,e.createElement)("fieldset",{id:"omise-form-atome"},(0,n.__)("Atome phone number","omise"),(0,e.createElement)("br",null),(0,e.createElement)("p",{className:"form-row form-row-wide omise-label-inline"},(0,e.createElement)("input",{id:"omise_atome_phone_default",type:"checkbox",name:"omise_atome_phone_default",value:_,defaultChecked:!0,onChange:e=>{w(!_),d(!u),_&&h("")}}),(0,e.createElement)("label",{htmlFor:"omise_atome_phone_default"},(0,n.__)("Same as Billing Detail","omise"))),(0,e.createElement)("p",{id:"omise_atome_phone_field",className:"form-row form-row-wide",style:{display:u?"block":"none"}},(0,e.createElement)("span",{className:"woocommerce-input-wrapper"},(0,e.createElement)("input",{id:"omise_atome_phone_number",className:"input-text",name:"omise_atome_phone_number",type:"tel",autoComplete:"off",placeholder:"+66123456789",onChange:e=>{h(e.target.value)}}))),(0,e.createElement)("p",{className:"omise-secondary-text"},(0,n.__)("The phone number will be used for creating Atome charge","omise"))):(0,e.createElement)("p",null,p))};(0,o.registerPaymentMethod)({name:s.name||"",label:(0,e.createElement)((t=>{const{PaymentMethodLabel:n}=t.components;return(0,e.createElement)(n,{text:m})}),null),content:(0,e.createElement)(r,null),edit:(0,e.createElement)(r,null),canMakePayment:()=>s.is_active,ariaLabel:m,supports:{features:s.supports}})})();
\ No newline at end of file
diff --git a/includes/blocks/assets/js/build/omise_duitnow_obw.asset.php b/includes/blocks/assets/js/build/omise_duitnow_obw.asset.php
index da247044..28f44fb9 100644
--- a/includes/blocks/assets/js/build/omise_duitnow_obw.asset.php
+++ b/includes/blocks/assets/js/build/omise_duitnow_obw.asset.php
@@ -1 +1 @@
- array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '6ae37be8bb705c7421530c7338e22bca');
\ No newline at end of file
+ array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '9895ac689bce188c4a74717ce7c149c5');
\ No newline at end of file
diff --git a/includes/blocks/assets/js/build/omise_duitnow_obw.js b/includes/blocks/assets/js/build/omise_duitnow_obw.js
index 8fb8c993..02028bd0 100644
--- a/includes/blocks/assets/js/build/omise_duitnow_obw.js
+++ b/includes/blocks/assets/js/build/omise_duitnow_obw.js
@@ -1 +1 @@
-(()=>{"use strict";const e=window.React,t=window.wp.element,n=(window.wp.i18n,window.wp.htmlEntities),a=window.wc.wcBlocksRegistry,s=(0,window.wc.wcSettings.getSetting)("omise_duitnow_obw_data",{}),l=(0,n.decodeEntities)(s.title)||"No title set",o=a=>{const{eventRegistration:l,emitResponse:o}=a,{onPaymentSetup:c}=l,r=(0,n.decodeEntities)(s.description||""),{banks:i}=s.data,[m,p]=(0,t.useState)(null);return(0,t.useEffect)((()=>{const e=c((async()=>{if(!m)return{type:o.responseTypes.ERROR,message:"Select a bank"};try{return{type:o.responseTypes.SUCCESS,meta:{paymentMethodData:{bank:m}}}}catch(e){return{type:o.responseTypes.ERROR,message:e.message}}}));return()=>e()}),[o.responseTypes.ERROR,o.responseTypes.SUCCESS,c,m]),(0,e.createElement)(e.Fragment,null,r&&(0,e.createElement)("p",null,r),(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:"duitnow-obw-select-bank",name:"source[bank]",defaultValue:"",onChange:e=>{p(e.target.value)}},(0,e.createElement)("option",{value:"",disabled:!0},"-- Select your option --"),i.map((t=>(0,e.createElement)("option",{key:t.code,className:t.code,value:t.code},t.name)))))))};(0,a.registerPaymentMethod)({name:s.name||"",label:(0,e.createElement)((t=>{const{PaymentMethodLabel:n}=t.components;return(0,e.createElement)(n,{text:l})}),null),content:(0,e.createElement)(o,null),edit:(0,e.createElement)(o,null),canMakePayment:()=>!0,ariaLabel:l,supports:{features:s.supports}})})();
\ No newline at end of file
+(()=>{"use strict";const e=window.React,t=window.wp.element,n=(window.wp.i18n,window.wp.htmlEntities),a=window.wc.wcBlocksRegistry,s=(0,window.wc.wcSettings.getSetting)("omise_duitnow_obw_data",{}),l=(0,n.decodeEntities)(s.title)||"No title set",o=a=>{const{eventRegistration:l,emitResponse:o}=a,{onPaymentSetup:c}=l,r=(0,n.decodeEntities)(s.description||""),{banks:i}=s.data,[m,p]=(0,t.useState)(null);return(0,t.useEffect)((()=>{const e=c((async()=>{if(!m)return{type:o.responseTypes.ERROR,message:"Select a bank"};try{return{type:o.responseTypes.SUCCESS,meta:{paymentMethodData:{bank:m}}}}catch(e){return{type:o.responseTypes.ERROR,message:e.message}}}));return()=>e()}),[o.responseTypes.ERROR,o.responseTypes.SUCCESS,c,m]),(0,e.createElement)(e.Fragment,null,r&&(0,e.createElement)("p",null,r),(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:"duitnow-obw-select-bank",name:"source[bank]",defaultValue:"",onChange:e=>{p(e.target.value)}},(0,e.createElement)("option",{value:"",disabled:!0},"-- Select your option --"),i.map((t=>(0,e.createElement)("option",{key:t.code,className:t.code,value:t.code},t.name)))))))};(0,a.registerPaymentMethod)({name:s.name||"",label:(0,e.createElement)((t=>{const{PaymentMethodLabel:n}=t.components;return(0,e.createElement)(n,{text:l})}),null),content:(0,e.createElement)(o,null),edit:(0,e.createElement)(o,null),canMakePayment:()=>s.is_active,ariaLabel:l,supports:{features:s.supports}})})();
\ No newline at end of file
diff --git a/includes/blocks/assets/js/build/omise_fpx.asset.php b/includes/blocks/assets/js/build/omise_fpx.asset.php
index 20499093..ec0b321f 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' => '449ba1e9fbdfe36ffe11aee7d7ddd2b7');
\ No newline at end of file
+ array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => 'c0c1739fc2507037807a1361ff76059e');
\ 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 39c796af..f7c261e9 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,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
+(()=>{"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:()=>l.is_active,ariaLabel:r,supports:{features:l.supports}})})();
\ No newline at end of file
diff --git a/includes/blocks/assets/js/build/omise_googlepay.asset.php b/includes/blocks/assets/js/build/omise_googlepay.asset.php
index 254f4278..19396d37 100644
--- a/includes/blocks/assets/js/build/omise_googlepay.asset.php
+++ b/includes/blocks/assets/js/build/omise_googlepay.asset.php
@@ -1 +1 @@
- array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => 'bd8de8fe88d6de8afc3a7b89d8afcd23');
\ No newline at end of file
+ array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '77916390d59105c488920c81e3010814');
\ No newline at end of file
diff --git a/includes/blocks/assets/js/build/omise_googlepay.js b/includes/blocks/assets/js/build/omise_googlepay.js
index b9d61312..4b6e32a2 100644
--- a/includes/blocks/assets/js/build/omise_googlepay.js
+++ b/includes/blocks/assets/js/build/omise_googlepay.js
@@ -1 +1 @@
-(()=>{var e={21:function(e,t,n){e.exports=function(e){"use strict";var t=function(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}(e);function o(e,t,n,o){return new(n||(n=Promise))((function(i,a){function s(e){try{l(o.next(e))}catch(e){a(e)}}function r(e){try{l(o.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,r)}l((o=o.apply(e,t||[])).next())}))}let i={};class a{constructor(e){this.handleClick=e=>o(this,void 0,void 0,(function*(){const t=this.config;if(!t)throw new Error("google-pay-button: Missing configuration");const n=this.createLoadPaymentDataRequest(t);try{if(t.onClick&&t.onClick(e),e.defaultPrevented)return;const o=yield this.client.loadPaymentData(n);t.onLoadPaymentData&&t.onLoadPaymentData(o)}catch(e){"CANCELED"===e.statusCode?t.onCancel&&t.onCancel(e):t.onError?t.onError(e):console.error(e)}})),this.options=e}getElement(){return this.element}isGooglePayLoaded(){var e,t;return"google"in(window||n.g)&&!!(null===(t=null===(e=null===google||void 0===google?void 0:google.payments)||void 0===e?void 0:e.api)||void 0===t?void 0:t.PaymentsClient)}mount(e){var t;return o(this,void 0,void 0,(function*(){if(!this.isGooglePayLoaded())try{yield function(e){const t=i[e];if(t)return t;const n=new Promise(((t,n)=>{const o=document.createElement("script");o.src=e,o.async=!0;const a=()=>{t()},s=()=>{o.removeEventListener("load",a),o.removeEventListener("error",s),delete i[e],o.remove(),n(new Error(`Unable to load script ${e}`))};o.addEventListener("load",a),o.addEventListener("error",s),document.body.appendChild(o)}));return i[e]=n,n}("https://pay.google.com/gp/p/js/pay.js")}catch(e){return void((null===(t=this.config)||void 0===t?void 0:t.onError)?this.config.onError(e):console.error(e))}this.element=e,e&&(this.appendStyles(),this.config&&this.updateElement())}))}unmount(){this.element=void 0}configure(e){let t;return this.config=e,this.oldInvalidationValues&&!this.isClientInvalidated(e)||(t=this.updateElement()),this.oldInvalidationValues=this.getInvalidationValues(e),null!=t?t:Promise.resolve()}createClientOptions(e){const t={environment:e.environment,merchantInfo:this.createMerchantInfo(e)};return(e.onPaymentDataChanged||e.onPaymentAuthorized)&&(t.paymentDataCallbacks={},e.onPaymentDataChanged&&(t.paymentDataCallbacks.onPaymentDataChanged=t=>e.onPaymentDataChanged(t)||{}),e.onPaymentAuthorized&&(t.paymentDataCallbacks.onPaymentAuthorized=t=>e.onPaymentAuthorized(t)||{})),t}createIsReadyToPayRequest(e){const t=e.paymentRequest;return{apiVersion:t.apiVersion,apiVersionMinor:t.apiVersionMinor,allowedPaymentMethods:t.allowedPaymentMethods,existingPaymentMethodRequired:e.existingPaymentMethodRequired}}createLoadPaymentDataRequest(e){return Object.assign(Object.assign({},e.paymentRequest),{merchantInfo:this.createMerchantInfo(e)})}createMerchantInfo(e){const t=Object.assign({},e.paymentRequest.merchantInfo);return t.softwareInfo||(t.softwareInfo={id:this.options.softwareInfoId,version:this.options.softwareInfoVersion}),t}isMounted(){return null!=this.element&&!1!==this.element.isConnected}removeButton(){if(this.element instanceof ShadowRoot||this.element instanceof Element)for(const e of Array.from(this.element.children))"STYLE"!==e.tagName&&e.remove()}updateElement(){return o(this,void 0,void 0,(function*(){if(!this.isMounted())return;const e=this.getElement();if(!this.config)throw new Error("google-pay-button: Missing configuration");this.removeButton();try{this.client=new google.payments.api.PaymentsClient(this.createClientOptions(this.config))}catch(e){return void(this.config.onError?this.config.onError(e):console.error(e))}const t={buttonType:this.config.buttonType,buttonColor:this.config.buttonColor,buttonRadius:this.config.buttonRadius,buttonSizeMode:this.config.buttonSizeMode,buttonLocale:this.config.buttonLocale,onClick:this.handleClick,allowedPaymentMethods:this.config.paymentRequest.allowedPaymentMethods},n=e.getRootNode();n instanceof ShadowRoot&&(t.buttonRootNode=n);const o=this.client.createButton(t);this.setClassName(e,[e.className,"not-ready"]),e.appendChild(o);let i,a=!1;try{i=yield this.client.isReadyToPay(this.createIsReadyToPayRequest(this.config)),a=i.result&&!this.config.existingPaymentMethodRequired||i.result&&i.paymentMethodPresent&&this.config.existingPaymentMethodRequired||!1}catch(e){this.config.onError?this.config.onError(e):console.error(e)}if(this.isMounted()){if(a){try{this.client.prefetchPaymentData(this.createLoadPaymentDataRequest(this.config))}catch(e){console.log("Error with prefetch",e)}this.setClassName(e,(e.className||"").split(" ").filter((e=>e&&"not-ready"!==e)))}if((this.isReadyToPay!==(null==i?void 0:i.result)||this.paymentMethodPresent!==(null==i?void 0:i.paymentMethodPresent))&&(this.isReadyToPay=!!(null==i?void 0:i.result),this.paymentMethodPresent=null==i?void 0:i.paymentMethodPresent,this.config.onReadyToPayChange)){const e={isButtonVisible:a,isReadyToPay:this.isReadyToPay};this.paymentMethodPresent&&(e.paymentMethodPresent=this.paymentMethodPresent),this.config.onReadyToPayChange(e)}}}))}setClassName(e,t){const n=t.filter((e=>e)).join(" ");n?e.className=n:e.removeAttribute("class")}appendStyles(){var e,t,n;if("undefined"==typeof document)return;const o=null===(e=this.element)||void 0===e?void 0:e.getRootNode(),i=`default-google-style-${this.options.cssSelector.replace(/[^\w-]+/g,"")}-${null===(t=this.config)||void 0===t?void 0:t.buttonLocale}`;if(o&&!(null===(n=o.getElementById)||void 0===n?void 0:n.call(o,i))){const e=document.createElement("style");e.id=i,e.type="text/css",e.innerHTML=`\n ${this.options.cssSelector} {\n display: inline-block;\n }\n ${this.options.cssSelector}.not-ready {\n width: 0;\n height: 0;\n overflow: hidden;\n }\n `,o instanceof Document&&o.head?o.head.appendChild(e):o.appendChild(e)}}isClientInvalidated(e){return!this.oldInvalidationValues||this.getInvalidationValues(e).some(((e,t)=>JSON.stringify(e)!==JSON.stringify(this.oldInvalidationValues[t])))}getInvalidationValues(e){var t,n;return[e.environment,e.existingPaymentMethodRequired,!!e.onPaymentDataChanged,!!e.onPaymentAuthorized,e.buttonType,e.buttonColor,e.buttonRadius,e.buttonLocale,e.buttonSizeMode,e.paymentRequest.merchantInfo.merchantId,e.paymentRequest.merchantInfo.merchantName,null===(t=e.paymentRequest.merchantInfo.softwareInfo)||void 0===t?void 0:t.id,null===(n=e.paymentRequest.merchantInfo.softwareInfo)||void 0===n?void 0:n.version,e.paymentRequest.allowedPaymentMethods]}}const s="google-pay-button-container";class r extends t.default.Component{constructor(){super(...arguments),this.manager=new a({cssSelector:`.${s}`,softwareInfoId:"@google-pay/button-react",softwareInfoVersion:"3.1.0"}),this.elementRef=t.default.createRef()}componentDidMount(){return o(this,void 0,void 0,(function*(){const e=this.elementRef.current;e&&(yield this.manager.configure(this.props),yield this.manager.mount(e))}))}componentWillUnmount(){this.manager.unmount()}componentDidUpdate(){this.manager.configure(this.props)}render(){return t.default.createElement("div",{ref:this.elementRef,className:[s,this.props.className].filter((e=>e)).join(" "),style:this.props.style})}}return r}(n(609))},609:e=>{"use strict";e.exports=window.React}},t={};function n(o){var i=t[o];if(void 0!==i)return i.exports;var a=t[o]={exports:{}};return e[o].call(a.exports,a,a.exports,n),a.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";var e=n(609);const t=window.wp.element,o=window.wp.i18n,i=window.wp.htmlEntities,a=window.wc.wcBlocksRegistry,s=window.wc.wcSettings;var r=n(21),l=n.n(r);const d=(0,s.getSetting)("omise_googlepay_data",{}),c=(0,i.decodeEntities)(d.title)||"No title set",u=n=>{const a=(0,i.decodeEntities)(d.description||""),{data:s}=d,{eventRegistration:r,emitResponse:c,onSubmit:u}=n,{onPaymentSetup:h}=r,[m,y]=(0,t.useState)(null),[p,f]=(0,t.useState)(null);return(0,t.useEffect)((()=>{const e=h((async()=>m?{type:c.responseTypes.SUCCESS,meta:{paymentMethodData:{omise_token:m}}}:p?{type:c.responseTypes.ERROR,message:p}:void 0));return()=>e()}),[c.responseTypes.ERROR,c.responseTypes.SUCCESS,h,m,p]),(0,e.createElement)(e.Fragment,null,a&&(0,e.createElement)("p",null,a),(0,e.createElement)("fieldset",{id:"omise-form-googlepay"},(0,e.createElement)("div",{id:"googlepay-button-container"},(0,e.createElement)(l(),{environment:s.environment,paymentRequest:{apiVersion:s.api_version,apiVersionMinor:s.api_version_minor,allowedPaymentMethods:[{type:"CARD",parameters:{allowedAuthMethods:s.allowed_auth_methods,allowedCardNetworks:s.allowed_card_networks,billingAddressRequired:s.billing_address_required,billingAddressParameters:{format:"FULL",phoneNumberRequired:s.phone_number_required}},tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:"omise",gatewayMerchantId:s.public_key}}}],merchantInfo:{merchantId:s.merchant_id},transactionInfo:{totalPriceStatus:s.price_status,currencyCode:s.currency}},onLoadPaymentData:e=>{const{paymentMethodData:t}=e,n={method:"googlepay",data:JSON.stringify(JSON.parse(t.tokenizationData.token))},o=t.info?.billingAddress;o&&(n={...n,billing_name:o.name,billing_city:o.locality,billing_country:o.countryCode,billing_postal_code:o.postalCode,billing_state:o.administrativeArea,billing_street1:o.address1,billing_street2:[o.address2,o.address3].filter((e=>e)).join(" "),billing_phone_number:o.phoneNumber}),Omise.setPublicKey(s.public_key),Omise.createToken("tokenization",n,((e,t)=>{200==e?(f(null),y(t.id),u()):(f(t.message),console.error({response:t}))}))}})),(0,e.createElement)("p",{id:"googlepay-text",className:"omise-secondary-text"},(0,o.__)("You will be prompted to select a credit card stored in your Google Account.","omise"))))};(0,a.registerPaymentMethod)({name:d.name||"",label:(0,e.createElement)((t=>{const{PaymentMethodLabel:n}=t.components;return(0,e.createElement)(n,{text:c})}),null),content:(0,e.createElement)(u,null),edit:(0,e.createElement)(u,null),canMakePayment:()=>!0,ariaLabel:c,supports:{features:d.supports}})})()})();
\ No newline at end of file
+(()=>{var e={21:function(e,t,n){e.exports=function(e){"use strict";var t=function(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}(e);function o(e,t,n,o){return new(n||(n=Promise))((function(i,a){function s(e){try{l(o.next(e))}catch(e){a(e)}}function r(e){try{l(o.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,r)}l((o=o.apply(e,t||[])).next())}))}let i={};class a{constructor(e){this.handleClick=e=>o(this,void 0,void 0,(function*(){const t=this.config;if(!t)throw new Error("google-pay-button: Missing configuration");const n=this.createLoadPaymentDataRequest(t);try{if(t.onClick&&t.onClick(e),e.defaultPrevented)return;const o=yield this.client.loadPaymentData(n);t.onLoadPaymentData&&t.onLoadPaymentData(o)}catch(e){"CANCELED"===e.statusCode?t.onCancel&&t.onCancel(e):t.onError?t.onError(e):console.error(e)}})),this.options=e}getElement(){return this.element}isGooglePayLoaded(){var e,t;return"google"in(window||n.g)&&!!(null===(t=null===(e=null===google||void 0===google?void 0:google.payments)||void 0===e?void 0:e.api)||void 0===t?void 0:t.PaymentsClient)}mount(e){var t;return o(this,void 0,void 0,(function*(){if(!this.isGooglePayLoaded())try{yield function(e){const t=i[e];if(t)return t;const n=new Promise(((t,n)=>{const o=document.createElement("script");o.src=e,o.async=!0;const a=()=>{t()},s=()=>{o.removeEventListener("load",a),o.removeEventListener("error",s),delete i[e],o.remove(),n(new Error(`Unable to load script ${e}`))};o.addEventListener("load",a),o.addEventListener("error",s),document.body.appendChild(o)}));return i[e]=n,n}("https://pay.google.com/gp/p/js/pay.js")}catch(e){return void((null===(t=this.config)||void 0===t?void 0:t.onError)?this.config.onError(e):console.error(e))}this.element=e,e&&(this.appendStyles(),this.config&&this.updateElement())}))}unmount(){this.element=void 0}configure(e){let t;return this.config=e,this.oldInvalidationValues&&!this.isClientInvalidated(e)||(t=this.updateElement()),this.oldInvalidationValues=this.getInvalidationValues(e),null!=t?t:Promise.resolve()}createClientOptions(e){const t={environment:e.environment,merchantInfo:this.createMerchantInfo(e)};return(e.onPaymentDataChanged||e.onPaymentAuthorized)&&(t.paymentDataCallbacks={},e.onPaymentDataChanged&&(t.paymentDataCallbacks.onPaymentDataChanged=t=>e.onPaymentDataChanged(t)||{}),e.onPaymentAuthorized&&(t.paymentDataCallbacks.onPaymentAuthorized=t=>e.onPaymentAuthorized(t)||{})),t}createIsReadyToPayRequest(e){const t=e.paymentRequest;return{apiVersion:t.apiVersion,apiVersionMinor:t.apiVersionMinor,allowedPaymentMethods:t.allowedPaymentMethods,existingPaymentMethodRequired:e.existingPaymentMethodRequired}}createLoadPaymentDataRequest(e){return Object.assign(Object.assign({},e.paymentRequest),{merchantInfo:this.createMerchantInfo(e)})}createMerchantInfo(e){const t=Object.assign({},e.paymentRequest.merchantInfo);return t.softwareInfo||(t.softwareInfo={id:this.options.softwareInfoId,version:this.options.softwareInfoVersion}),t}isMounted(){return null!=this.element&&!1!==this.element.isConnected}removeButton(){if(this.element instanceof ShadowRoot||this.element instanceof Element)for(const e of Array.from(this.element.children))"STYLE"!==e.tagName&&e.remove()}updateElement(){return o(this,void 0,void 0,(function*(){if(!this.isMounted())return;const e=this.getElement();if(!this.config)throw new Error("google-pay-button: Missing configuration");this.removeButton();try{this.client=new google.payments.api.PaymentsClient(this.createClientOptions(this.config))}catch(e){return void(this.config.onError?this.config.onError(e):console.error(e))}const t={buttonType:this.config.buttonType,buttonColor:this.config.buttonColor,buttonRadius:this.config.buttonRadius,buttonSizeMode:this.config.buttonSizeMode,buttonLocale:this.config.buttonLocale,onClick:this.handleClick,allowedPaymentMethods:this.config.paymentRequest.allowedPaymentMethods},n=e.getRootNode();n instanceof ShadowRoot&&(t.buttonRootNode=n);const o=this.client.createButton(t);this.setClassName(e,[e.className,"not-ready"]),e.appendChild(o);let i,a=!1;try{i=yield this.client.isReadyToPay(this.createIsReadyToPayRequest(this.config)),a=i.result&&!this.config.existingPaymentMethodRequired||i.result&&i.paymentMethodPresent&&this.config.existingPaymentMethodRequired||!1}catch(e){this.config.onError?this.config.onError(e):console.error(e)}if(this.isMounted()){if(a){try{this.client.prefetchPaymentData(this.createLoadPaymentDataRequest(this.config))}catch(e){console.log("Error with prefetch",e)}this.setClassName(e,(e.className||"").split(" ").filter((e=>e&&"not-ready"!==e)))}if((this.isReadyToPay!==(null==i?void 0:i.result)||this.paymentMethodPresent!==(null==i?void 0:i.paymentMethodPresent))&&(this.isReadyToPay=!!(null==i?void 0:i.result),this.paymentMethodPresent=null==i?void 0:i.paymentMethodPresent,this.config.onReadyToPayChange)){const e={isButtonVisible:a,isReadyToPay:this.isReadyToPay};this.paymentMethodPresent&&(e.paymentMethodPresent=this.paymentMethodPresent),this.config.onReadyToPayChange(e)}}}))}setClassName(e,t){const n=t.filter((e=>e)).join(" ");n?e.className=n:e.removeAttribute("class")}appendStyles(){var e,t,n;if("undefined"==typeof document)return;const o=null===(e=this.element)||void 0===e?void 0:e.getRootNode(),i=`default-google-style-${this.options.cssSelector.replace(/[^\w-]+/g,"")}-${null===(t=this.config)||void 0===t?void 0:t.buttonLocale}`;if(o&&!(null===(n=o.getElementById)||void 0===n?void 0:n.call(o,i))){const e=document.createElement("style");e.id=i,e.type="text/css",e.innerHTML=`\n ${this.options.cssSelector} {\n display: inline-block;\n }\n ${this.options.cssSelector}.not-ready {\n width: 0;\n height: 0;\n overflow: hidden;\n }\n `,o instanceof Document&&o.head?o.head.appendChild(e):o.appendChild(e)}}isClientInvalidated(e){return!this.oldInvalidationValues||this.getInvalidationValues(e).some(((e,t)=>JSON.stringify(e)!==JSON.stringify(this.oldInvalidationValues[t])))}getInvalidationValues(e){var t,n;return[e.environment,e.existingPaymentMethodRequired,!!e.onPaymentDataChanged,!!e.onPaymentAuthorized,e.buttonType,e.buttonColor,e.buttonRadius,e.buttonLocale,e.buttonSizeMode,e.paymentRequest.merchantInfo.merchantId,e.paymentRequest.merchantInfo.merchantName,null===(t=e.paymentRequest.merchantInfo.softwareInfo)||void 0===t?void 0:t.id,null===(n=e.paymentRequest.merchantInfo.softwareInfo)||void 0===n?void 0:n.version,e.paymentRequest.allowedPaymentMethods]}}const s="google-pay-button-container";class r extends t.default.Component{constructor(){super(...arguments),this.manager=new a({cssSelector:`.${s}`,softwareInfoId:"@google-pay/button-react",softwareInfoVersion:"3.1.0"}),this.elementRef=t.default.createRef()}componentDidMount(){return o(this,void 0,void 0,(function*(){const e=this.elementRef.current;e&&(yield this.manager.configure(this.props),yield this.manager.mount(e))}))}componentWillUnmount(){this.manager.unmount()}componentDidUpdate(){this.manager.configure(this.props)}render(){return t.default.createElement("div",{ref:this.elementRef,className:[s,this.props.className].filter((e=>e)).join(" "),style:this.props.style})}}return r}(n(609))},609:e=>{"use strict";e.exports=window.React}},t={};function n(o){var i=t[o];if(void 0!==i)return i.exports;var a=t[o]={exports:{}};return e[o].call(a.exports,a,a.exports,n),a.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";var e=n(609);const t=window.wp.element,o=window.wp.i18n,i=window.wp.htmlEntities,a=window.wc.wcBlocksRegistry,s=window.wc.wcSettings;var r=n(21),l=n.n(r);const d=(0,s.getSetting)("omise_googlepay_data",{}),c=(0,i.decodeEntities)(d.title)||"No title set",u=n=>{const a=(0,i.decodeEntities)(d.description||""),{data:s}=d,{eventRegistration:r,emitResponse:c,onSubmit:u}=n,{onPaymentSetup:h}=r,[m,y]=(0,t.useState)(null),[p,f]=(0,t.useState)(null);return(0,t.useEffect)((()=>{const e=h((async()=>m?{type:c.responseTypes.SUCCESS,meta:{paymentMethodData:{omise_token:m}}}:p?{type:c.responseTypes.ERROR,message:p}:void 0));return()=>e()}),[c.responseTypes.ERROR,c.responseTypes.SUCCESS,h,m,p]),(0,e.createElement)(e.Fragment,null,a&&(0,e.createElement)("p",null,a),(0,e.createElement)("fieldset",{id:"omise-form-googlepay"},(0,e.createElement)("div",{id:"googlepay-button-container"},(0,e.createElement)(l(),{environment:s.environment,paymentRequest:{apiVersion:s.api_version,apiVersionMinor:s.api_version_minor,allowedPaymentMethods:[{type:"CARD",parameters:{allowedAuthMethods:s.allowed_auth_methods,allowedCardNetworks:s.allowed_card_networks,billingAddressRequired:s.billing_address_required,billingAddressParameters:{format:"FULL",phoneNumberRequired:s.phone_number_required}},tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:"omise",gatewayMerchantId:s.public_key}}}],merchantInfo:{merchantId:s.merchant_id},transactionInfo:{totalPriceStatus:s.price_status,currencyCode:s.currency}},onLoadPaymentData:e=>{const{paymentMethodData:t}=e,n={method:"googlepay",data:JSON.stringify(JSON.parse(t.tokenizationData.token))},o=t.info?.billingAddress;o&&(n={...n,billing_name:o.name,billing_city:o.locality,billing_country:o.countryCode,billing_postal_code:o.postalCode,billing_state:o.administrativeArea,billing_street1:o.address1,billing_street2:[o.address2,o.address3].filter((e=>e)).join(" "),billing_phone_number:o.phoneNumber}),Omise.setPublicKey(s.public_key),Omise.createToken("tokenization",n,((e,t)=>{200==e?(f(null),y(t.id),u()):(f(t.message),console.error({response:t}))}))}})),(0,e.createElement)("p",{id:"googlepay-text",className:"omise-secondary-text"},(0,o.__)("You will be prompted to select a credit card stored in your Google Account.","omise"))))};(0,a.registerPaymentMethod)({name:d.name||"",label:(0,e.createElement)((t=>{const{PaymentMethodLabel:n}=t.components;return(0,e.createElement)(n,{text:c})}),null),content:(0,e.createElement)(u,null),edit:(0,e.createElement)(u,null),canMakePayment:()=>d.is_active,ariaLabel:c,supports:{features:d.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 686cafac..a14ba683 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' => '0870d052051799446a862b643aaa00a1');
\ No newline at end of file
+ array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => 'd2a1602f618f3b67fe3f74ab703c2398');
\ 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 4ad69253..598eb37a 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,l=window.wc.wcBlocksRegistry,r=(0,window.wc.wcSettings.getSetting)("omise_installment_data",{}),s=(0,a.decodeEntities)(r.title)||"No title set",m=l=>{const{eventRegistration:s,emitResponse:m}=l,{onPaymentSetup:i}=s,c=(0,a.decodeEntities)(r.description||""),{installment_backends:o,is_zero_interest:u}=r.data,p=(0,n.__)("Purchase Amount is lower than the monthly minimum payment amount.","omise"),_=(0,t.useRef)(null),d=(0,t.useRef)(null),E=e=>{_.current=e.target.value,d.current=null},y=e=>{d.current=e.target.value};return(0,t.useEffect)((()=>{const e=i((async()=>{if(!_.current||!d.current)return{type:m.responseTypes.ERROR,message:"Select a bank and term"};try{return{type:m.responseTypes.SUCCESS,meta:{paymentMethodData:{source:_.current,[`${_.current}_installment_terms`]:d.current}}}}catch(e){return{type:m.responseTypes.ERROR,message:e.message}}}));return()=>e()}),[i]),(0,e.createElement)(e.Fragment,null,c&&(0,e.createElement)("p",null,c),0==o.length?(0,e.createElement)("p",null,p):(0,e.createElement)("fieldset",{id:"omise-form-installment"},(0,e.createElement)("ul",{className:"omise-banks-list"},o.map(((t,a)=>(0,e.createElement)("li",{key:t._id+a,className:"item"},(0,e.createElement)("input",{id:t._id,type:"radio",name:"source[type]",value:t._id,onChange:E}),(0,e.createElement)("label",{htmlFor:t._id},(0,e.createElement)("div",{className:`bank-logo ${t.provider_code}`}),(0,e.createElement)("div",{className:"bank-label"},(0,e.createElement)("span",{className:"title"},t.provider_name),(0,e.createElement)("br",null),(0,e.createElement)("select",{id:`${t._id}_installment_terms`,name:`${t._id}_installment_terms`,className:"installment-term-select-box",onChange:y},(0,e.createElement)("option",null,"Select term"),t.available_plans.map(((t,a)=>(0,e.createElement)("option",{key:`${t.term_length}_${t.monthly_amount}_${a}`,value:t.term_length},(0,n.__)(`${t.term_length} months`,"omise"),(0,e.createElement)(e.Fragment,null," "),"(",(0,n.__)(`${t.monthly_amount} / months`,"omise"),")")))),u&&(0,e.createElement)(e.Fragment,null,(0,e.createElement)("br",null),(0,e.createElement)("span",{className:"omise-installment-interest-rate"},(0,n.__)(`( interest ${t.interest_rate} )`,"omise")))))))))))};(0,l.registerPaymentMethod)({name:r.name||"",label:(0,e.createElement)((t=>{const{PaymentMethodLabel:n}=t.components;return(0,e.createElement)(n,{text:s})}),null),content:(0,e.createElement)(m,null),edit:(0,e.createElement)(m,null),canMakePayment:()=>!0,ariaLabel:s,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,l=window.wc.wcBlocksRegistry,r=(0,window.wc.wcSettings.getSetting)("omise_installment_data",{}),s=(0,a.decodeEntities)(r.title)||"No title set",m=l=>{const{eventRegistration:s,emitResponse:m}=l,{onPaymentSetup:i}=s,c=(0,a.decodeEntities)(r.description||""),{installment_backends:o,is_zero_interest:u}=r.data,_=(0,n.__)("Purchase Amount is lower than the monthly minimum payment amount.","omise"),p=(0,t.useRef)(null),d=(0,t.useRef)(null),E=e=>{p.current=e.target.value,d.current=null},y=e=>{d.current=e.target.value};return(0,t.useEffect)((()=>{const e=i((async()=>{if(!p.current||!d.current)return{type:m.responseTypes.ERROR,message:"Select a bank and term"};try{return{type:m.responseTypes.SUCCESS,meta:{paymentMethodData:{source:p.current,[`${p.current}_installment_terms`]:d.current}}}}catch(e){return{type:m.responseTypes.ERROR,message:e.message}}}));return()=>e()}),[i]),(0,e.createElement)(e.Fragment,null,c&&(0,e.createElement)("p",null,c),0==o.length?(0,e.createElement)("p",null,_):(0,e.createElement)("fieldset",{id:"omise-form-installment"},(0,e.createElement)("ul",{className:"omise-banks-list"},o.map(((t,a)=>(0,e.createElement)("li",{key:t._id+a,className:"item"},(0,e.createElement)("input",{id:t._id,type:"radio",name:"source[type]",value:t._id,onChange:E}),(0,e.createElement)("label",{htmlFor:t._id},(0,e.createElement)("div",{className:`bank-logo ${t.provider_code}`}),(0,e.createElement)("div",{className:"bank-label"},(0,e.createElement)("span",{className:"title"},t.provider_name),(0,e.createElement)("br",null),(0,e.createElement)("select",{id:`${t._id}_installment_terms`,name:`${t._id}_installment_terms`,className:"installment-term-select-box",onChange:y},(0,e.createElement)("option",null,"Select term"),t.available_plans.map(((t,a)=>(0,e.createElement)("option",{key:`${t.term_length}_${t.monthly_amount}_${a}`,value:t.term_length},(0,n.__)(`${t.term_length} months`,"omise"),(0,e.createElement)(e.Fragment,null," "),"(",(0,n.__)(`${t.monthly_amount} / months`,"omise"),")")))),u&&(0,e.createElement)(e.Fragment,null,(0,e.createElement)("br",null),(0,e.createElement)("span",{className:"omise-installment-interest-rate"},(0,n.__)(`( interest ${t.interest_rate} )`,"omise")))))))))))};(0,l.registerPaymentMethod)({name:r.name||"",label:(0,e.createElement)((t=>{const{PaymentMethodLabel:n}=t.components;return(0,e.createElement)(n,{text:s})}),null),content:(0,e.createElement)(m,null),edit:(0,e.createElement)(m,null),canMakePayment:()=>r.is_active,ariaLabel:s,supports:{features:r.supports}})})();
\ 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
index c86e6b44..83aa7b4c 100644
--- a/includes/blocks/assets/js/build/omise_internetbanking.asset.php
+++ b/includes/blocks/assets/js/build/omise_internetbanking.asset.php
@@ -1 +1 @@
- array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '5a7c1ca9a881b022e773ff44a4c3f27c');
\ No newline at end of file
+ array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => 'c801bb1c9f7a7c3d6f9048be28066278');
\ 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
index 5fc44ba5..3d845156 100644
--- a/includes/blocks/assets/js/build/omise_internetbanking.js
+++ b/includes/blocks/assets/js/build/omise_internetbanking.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,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
+(()=>{"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:()=>l.is_active,ariaLabel:i,supports:{features:l.supports}})})();
\ No newline at end of file
diff --git a/includes/blocks/assets/js/build/omise_truemoney.asset.php b/includes/blocks/assets/js/build/omise_truemoney.asset.php
index 82fd43bc..db6c507e 100644
--- a/includes/blocks/assets/js/build/omise_truemoney.asset.php
+++ b/includes/blocks/assets/js/build/omise_truemoney.asset.php
@@ -1 +1 @@
- array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '1f611dbfd6dc2d235ba16ce16a77cf92');
\ No newline at end of file
+ array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '37bff72b2040207c7c2e0297db0b9219');
\ No newline at end of file
diff --git a/includes/blocks/assets/js/build/omise_truemoney.js b/includes/blocks/assets/js/build/omise_truemoney.js
index fd531f07..e1037e3a 100644
--- a/includes/blocks/assets/js/build/omise_truemoney.js
+++ b/includes/blocks/assets/js/build/omise_truemoney.js
@@ -1 +1 @@
-(()=>{"use strict";const e=window.React,t=window.wp.element,n=window.wp.i18n,o=window.wp.htmlEntities,s=window.wc.wcBlocksRegistry,a=(0,window.wc.wcSettings.getSetting)("omise_truemoney_data",{}),m=(0,o.decodeEntities)(a.title)||"No title set",r=({content:s,...m})=>{const{eventRegistration:r,emitResponse:l}=m,{onPaymentSetup:i}=r,p=(0,o.decodeEntities)(a.description.trim()||""),{is_wallet:c}=a.data,[u,d]=(0,t.useState)(!1),[_,w]=(0,t.useState)(!0),[E,h]=(0,t.useState)("");return(0,t.useEffect)((()=>{const e=i((async()=>{if(!_&&0===E.length)return{type:l.responseTypes.ERROR,message:"Enter a phone number"};try{return{type:l.responseTypes.SUCCESS,meta:{paymentMethodData:{omise_phone_number_default:(_?1:0).toString(),omise_phone_number:E}}}}catch(e){return{type:l.responseTypes.ERROR,message:e.message}}}));return()=>e()}),[i,l.responseTypes.ERROR,l.responseTypes.SUCCESS,_,E]),(0,e.createElement)(e.Fragment,null,p&&(0,e.createElement)("p",null,p),c&&(0,e.createElement)("fieldset",{id:"omise-form-truemoney"},(0,n.__)("TrueMoney phone number","omise"),(0,e.createElement)("br",null),(0,e.createElement)("p",{id:"omise_phone_number_default_field",className:"form-row form-row-wide omise-label-inline"},(0,e.createElement)("input",{id:"omise_phone_number_default",type:"checkbox",name:"omise_phone_number_default",value:_,defaultChecked:!0,onChange:e=>{w(!_),d(!u),_&&h("")}}),(0,e.createElement)("label",{htmlFor:"omise_phone_number_default"},(0,n.__)("Same as Billing Detail","omise"))),(0,e.createElement)("p",{id:"omise_phone_number_field",className:"form-row form-row-wide",style:{display:u?"block":"none"}},(0,e.createElement)("span",{className:"woocommerce-input-wrapper"},(0,e.createElement)("input",{id:"omise_phone_number",className:"input-text",name:"omise_phone_number",type:"tel",autoComplete:"off",onChange:e=>{h(e.target.value)}}))),(0,e.createElement)("p",{className:"omise-secondary-text"},(0,n.__)("One-Time Password (OTP) will be sent to the phone number above","omise"))))};(0,s.registerPaymentMethod)({name:a.name||"",label:(0,e.createElement)((t=>{const{PaymentMethodLabel:n}=t.components;return(0,e.createElement)(n,{text:m})}),null),content:(0,e.createElement)(r,null),edit:(0,e.createElement)(r,null),canMakePayment:()=>!0,ariaLabel:m,supports:{features:a.supports}})})();
\ No newline at end of file
+(()=>{"use strict";const e=window.React,t=window.wp.element,n=window.wp.i18n,o=window.wp.htmlEntities,s=window.wc.wcBlocksRegistry,a=(0,window.wc.wcSettings.getSetting)("omise_truemoney_data",{}),m=(0,o.decodeEntities)(a.title)||"No title set",r=({content:s,...m})=>{const{eventRegistration:r,emitResponse:i}=m,{onPaymentSetup:l}=r,p=(0,o.decodeEntities)(a.description.trim()||""),{is_wallet:c}=a.data,[u,d]=(0,t.useState)(!1),[_,w]=(0,t.useState)(!0),[E,h]=(0,t.useState)("");return(0,t.useEffect)((()=>{const e=l((async()=>{if(!_&&0===E.length)return{type:i.responseTypes.ERROR,message:"Enter a phone number"};try{return{type:i.responseTypes.SUCCESS,meta:{paymentMethodData:{omise_phone_number_default:(_?1:0).toString(),omise_phone_number:E}}}}catch(e){return{type:i.responseTypes.ERROR,message:e.message}}}));return()=>e()}),[l,i.responseTypes.ERROR,i.responseTypes.SUCCESS,_,E]),(0,e.createElement)(e.Fragment,null,p&&(0,e.createElement)("p",null,p),c&&(0,e.createElement)("fieldset",{id:"omise-form-truemoney"},(0,n.__)("TrueMoney phone number","omise"),(0,e.createElement)("br",null),(0,e.createElement)("p",{id:"omise_phone_number_default_field",className:"form-row form-row-wide omise-label-inline"},(0,e.createElement)("input",{id:"omise_phone_number_default",type:"checkbox",name:"omise_phone_number_default",value:_,defaultChecked:!0,onChange:e=>{w(!_),d(!u),_&&h("")}}),(0,e.createElement)("label",{htmlFor:"omise_phone_number_default"},(0,n.__)("Same as Billing Detail","omise"))),(0,e.createElement)("p",{id:"omise_phone_number_field",className:"form-row form-row-wide",style:{display:u?"block":"none"}},(0,e.createElement)("span",{className:"woocommerce-input-wrapper"},(0,e.createElement)("input",{id:"omise_phone_number",className:"input-text",name:"omise_phone_number",type:"tel",autoComplete:"off",onChange:e=>{h(e.target.value)}}))),(0,e.createElement)("p",{className:"omise-secondary-text"},(0,n.__)("One-Time Password (OTP) will be sent to the phone number above","omise"))))};(0,s.registerPaymentMethod)({name:a.name||"",label:(0,e.createElement)((t=>{const{PaymentMethodLabel:n}=t.components;return(0,e.createElement)(n,{text:m})}),null),content:(0,e.createElement)(r,null),edit:(0,e.createElement)(r,null),canMakePayment:()=>a.is_active,ariaLabel:m,supports:{features:a.supports}})})();
\ No newline at end of file
diff --git a/includes/blocks/assets/js/common.js b/includes/blocks/assets/js/common.js
index 0a627f92..261584b3 100644
--- a/includes/blocks/assets/js/common.js
+++ b/includes/blocks/assets/js/common.js
@@ -17,7 +17,7 @@ export function registerOmisePaymentMethod({settings, label}) {
label: ,
content: ,
edit: ,
- canMakePayment: () => true,
+ canMakePayment: () => settings.is_active,
ariaLabel: label,
supports: {
features: settings.supports,
diff --git a/includes/blocks/assets/js/credit_card/saved-cards.js b/includes/blocks/assets/js/credit_card/saved-cards.js
index c2bbc792..e51cb7a0 100644
--- a/includes/blocks/assets/js/credit_card/saved-cards.js
+++ b/includes/blocks/assets/js/credit_card/saved-cards.js
@@ -26,4 +26,4 @@ export const SavedCard = ({onChange, existingCards}) => {
{ __('Create a charge using new card', 'omise') }
>)
-}
\ No newline at end of file
+}
diff --git a/includes/blocks/assets/js/omise-atome.js b/includes/blocks/assets/js/omise-atome.js
index 4bb8e9cb..9a08d12d 100644
--- a/includes/blocks/assets/js/omise-atome.js
+++ b/includes/blocks/assets/js/omise-atome.js
@@ -111,7 +111,7 @@ registerPaymentMethod( {
label: ,
content: ,
edit: ,
- canMakePayment: () => true,
+ canMakePayment: () => settings.is_active,
ariaLabel: label,
supports: {
features: settings.supports,
diff --git a/includes/blocks/assets/js/omise-credit-card.js b/includes/blocks/assets/js/omise-credit-card.js
index 7708cb3a..b4a03bed 100644
--- a/includes/blocks/assets/js/omise-credit-card.js
+++ b/includes/blocks/assets/js/omise-credit-card.js
@@ -26,7 +26,7 @@ registerPaymentMethod({
label: ,
content: ,
edit: ,
- canMakePayment: () => true,
+ canMakePayment: () => settings.is_active,
ariaLabel: label,
supports: {
features: settings.supports,
diff --git a/includes/blocks/assets/js/omise-duitnow-obw.js b/includes/blocks/assets/js/omise-duitnow-obw.js
index 1d7e9b46..810ad9ae 100644
--- a/includes/blocks/assets/js/omise-duitnow-obw.js
+++ b/includes/blocks/assets/js/omise-duitnow-obw.js
@@ -85,7 +85,7 @@ registerPaymentMethod( {
label: ,
content: ,
edit: ,
- canMakePayment: () => true,
+ canMakePayment: () => settings.is_active,
ariaLabel: label,
supports: {
features: settings.supports,
diff --git a/includes/blocks/assets/js/omise-fpx.js b/includes/blocks/assets/js/omise-fpx.js
index 8387382f..31e1fc90 100644
--- a/includes/blocks/assets/js/omise-fpx.js
+++ b/includes/blocks/assets/js/omise-fpx.js
@@ -94,7 +94,7 @@ registerPaymentMethod( {
label: ,
content: ,
edit: ,
- canMakePayment: () => true,
+ canMakePayment: () => settings.is_active,
ariaLabel: label,
supports: {
features: settings.supports,
diff --git a/includes/blocks/assets/js/omise-googlepay.js b/includes/blocks/assets/js/omise-googlepay.js
index c7de2cab..047c63a1 100644
--- a/includes/blocks/assets/js/omise-googlepay.js
+++ b/includes/blocks/assets/js/omise-googlepay.js
@@ -141,7 +141,7 @@ registerPaymentMethod({
label: ,
content: ,
edit: ,
- canMakePayment: () => true,
+ canMakePayment: () => settings.is_active,
ariaLabel: label,
supports: {
features: settings.supports,
diff --git a/includes/blocks/assets/js/omise-installment.js b/includes/blocks/assets/js/omise-installment.js
index d557be66..6466f987 100644
--- a/includes/blocks/assets/js/omise-installment.js
+++ b/includes/blocks/assets/js/omise-installment.js
@@ -112,7 +112,7 @@ registerPaymentMethod( {
label: ,
content: ,
edit: ,
- canMakePayment: () => true,
+ canMakePayment: () => settings.is_active,
ariaLabel: label,
supports: {
features: settings.supports,
diff --git a/includes/blocks/assets/js/omise-internetbanking.js b/includes/blocks/assets/js/omise-internetbanking.js
index 4cea7c89..0f377e9e 100644
--- a/includes/blocks/assets/js/omise-internetbanking.js
+++ b/includes/blocks/assets/js/omise-internetbanking.js
@@ -86,7 +86,7 @@ registerPaymentMethod( {
label: ,
content: ,
edit: ,
- canMakePayment: () => true,
+ canMakePayment: () => settings.is_active,
ariaLabel: label,
supports: {
features: settings.supports,
diff --git a/includes/blocks/assets/js/omise-mobilebanking.js b/includes/blocks/assets/js/omise-mobilebanking.js
index b836912b..438583b8 100644
--- a/includes/blocks/assets/js/omise-mobilebanking.js
+++ b/includes/blocks/assets/js/omise-mobilebanking.js
@@ -75,7 +75,7 @@ registerPaymentMethod( {
label: ,
content: ,
edit: ,
- canMakePayment: () => true,
+ canMakePayment: () => settings.is_active,
ariaLabel: label,
supports: {
features: settings.supports,
diff --git a/includes/blocks/assets/js/omise-truemoney.js b/includes/blocks/assets/js/omise-truemoney.js
index 3a8ddfb3..6c99e09e 100644
--- a/includes/blocks/assets/js/omise-truemoney.js
+++ b/includes/blocks/assets/js/omise-truemoney.js
@@ -108,7 +108,7 @@ registerPaymentMethod( {
label: ,
content: ,
edit: ,
- canMakePayment: () => true,
+ canMakePayment: () => settings.is_active,
ariaLabel: label,
supports: {
features: settings.supports,
diff --git a/includes/blocks/gateways/abstract-omise-block-apm.php b/includes/blocks/gateways/abstract-omise-block-apm.php
index 8d9ce482..b462dbe6 100644
--- a/includes/blocks/gateways/abstract-omise-block-apm.php
+++ b/includes/blocks/gateways/abstract-omise-block-apm.php
@@ -4,43 +4,43 @@
abstract class Omise_Block_Apm extends AbstractPaymentMethodType {
/**
- * The gateway instance.
- */
- protected $gateway;
+ * The gateway instance.
+ */
+ protected $gateway;
- /**
- * Payment method name/id/slug.
- *
- * @var string
- */
- protected $name;
+ /**
+ * Payment method name/id/slug.
+ *
+ * @var string
+ */
+ protected $name;
- /**
- * Initializes the payment method type.
- */
- public function initialize() {
- $this->settings = get_option( "woocommerce_{$this->name}_settings", [] );
- $gateways = WC()->payment_gateways->payment_gateways();
- $this->gateway = $gateways[ $this->name ];
- }
+ /**
+ * Initializes the payment method type.
+ */
+ public function initialize() {
+ $this->settings = get_option( "woocommerce_{$this->name}_settings", [] );
+ $gateways = WC()->payment_gateways->payment_gateways();
+ $this->gateway = $gateways[ $this->name ];
+ }
- /**
- * Returns if this payment method should be active. If false, the scripts will not be enqueued.
- *
- * @return boolean
- */
- public function is_active() {
- return $this->gateway->is_available();
- }
+ /**
+ * Returns if this payment method should be active. If false, the scripts will not be enqueued.
+ *
+ * @return boolean
+ */
+ public function is_active() {
+ return $this->gateway->is_available();
+ }
- /**
- * Returns an array of scripts/handles to be registered for this payment method.
- *
- * @return array
- */
- public function get_payment_method_script_handles() {
- if ( ! wp_script_is( 'wc-omise-one-click-apms-payments-blocks', 'enqueued' ) ) {
- $script_asset = require __DIR__ . '/../assets/js/build/omise-one-click-apms.asset.php';
+ /**
+ * Returns an array of scripts/handles to be registered for this payment method.
+ *
+ * @return array
+ */
+ public function get_payment_method_script_handles() {
+ if ( ! wp_script_is( 'wc-omise-one-click-apms-payments-blocks', 'enqueued' ) ) {
+ $script_asset = require_once __DIR__ . '/../assets/js/build/omise-one-click-apms.asset.php';
wp_register_script(
"wc-omise-one-click-apms-payments-blocks",
plugin_dir_url( __DIR__ ) . 'assets/js/build/omise-one-click-apms.js',
@@ -52,20 +52,21 @@ public function get_payment_method_script_handles() {
wp_enqueue_script( 'wc-omise-one-click-apms-payments-blocks' );
}
- return [ 'wc-omise-one-click-apms-payments-blocks' ];
- }
+ return [ 'wc-omise-one-click-apms-payments-blocks' ];
+ }
- /**
- * Returns an array of key=>value pairs of data made available to the payment methods script.
- *
- * @return array
- */
- public function get_payment_method_data() {
- return [
- 'name' => $this->name,
- 'title' => $this->get_setting( 'title' ),
- 'description' => $this->get_setting( 'description' ),
- 'supports' => array_filter( $this->gateway->supports, [ $this->gateway, 'supports' ] )
- ];
- }
+ /**
+ * Returns an array of key=>value pairs of data made available to the payment methods script.
+ *
+ * @return array
+ */
+ public function get_payment_method_data() {
+ return [
+ 'name' => $this->name,
+ 'title' => $this->get_setting( 'title' ),
+ 'description' => $this->get_setting( 'description' ),
+ 'supports' => array_filter( $this->gateway->supports, [ $this->gateway, 'supports' ] ),
+ 'is_active' => $this->is_active(),
+ ];
+ }
}
diff --git a/includes/blocks/gateways/abstract-omise-block-payment.php b/includes/blocks/gateways/abstract-omise-block-payment.php
index 3f3e8f68..218a05cb 100644
--- a/includes/blocks/gateways/abstract-omise-block-payment.php
+++ b/includes/blocks/gateways/abstract-omise-block-payment.php
@@ -3,89 +3,90 @@
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
abstract class Omise_Block_Payment extends AbstractPaymentMethodType {
- /**
- * The gateway instance.
- */
- protected $gateway;
+ /**
+ * The gateway instance.
+ */
+ protected $gateway;
- /**
- * Payment method name/id/slug.
- *
- * @var string
- */
- protected $name;
+ /**
+ * Payment method name/id/slug.
+ *
+ * @var string
+ */
+ protected $name;
- /**
- * Additional data required in the UI
- */
- protected $additional_data;
+ /**
+ * Additional data required in the UI
+ */
+ protected $additional_data;
- /**
- * Initializes the payment method type.
- */
- public function initialize() {
- $this->settings = get_option("woocommerce_{$this->name}_settings", []);
- $gateways = WC()->payment_gateways->payment_gateways();
- $this->gateway = $gateways[$this->name];
- }
+ /**
+ * Initializes the payment method type.
+ */
+ public function initialize() {
+ $this->settings = get_option("woocommerce_{$this->name}_settings", []);
+ $gateways = WC()->payment_gateways->payment_gateways();
+ $this->gateway = $gateways[$this->name];
+ }
- /**
- * Returns if this payment method should be active. If false, the scripts will not be enqueued.
- *
- * @return boolean
- */
- public function is_active() {
- return $this->gateway->is_available();
- }
+ /**
+ * Returns if this payment method should be active. If false, the scripts will not be enqueued.
+ *
+ * @return boolean
+ */
+ public function is_active() {
+ return $this->gateway->is_available();
+ }
- /**
- * Returns an array of scripts/handles to be registered for this payment method.
- *
- * @return array
- */
- public function get_payment_method_script_handles() {
- if (!wp_script_is("wc-{$this->name}-payments-blocks", 'enqueued')) {
- $script_asset = require __DIR__ . "/../assets/js/build/{$this->name}.asset.php";
- wp_register_script(
- "wc-{$this->name}-payments-blocks",
- plugin_dir_url(__DIR__) . "assets/js/build/{$this->name}.js",
- $script_asset['dependencies'],
- $script_asset['version'],
- true
- );
+ /**
+ * Returns an array of scripts/handles to be registered for this payment method.
+ *
+ * @return array
+ */
+ public function get_payment_method_script_handles() {
+ if (!wp_script_is("wc-{$this->name}-payments-blocks", 'enqueued')) {
+ $script_asset = require_once __DIR__ . "/../assets/js/build/{$this->name}.asset.php";
+ wp_register_script(
+ "wc-{$this->name}-payments-blocks",
+ plugin_dir_url(__DIR__) . "assets/js/build/{$this->name}.js",
+ $script_asset['dependencies'],
+ $script_asset['version'],
+ true
+ );
- wp_enqueue_script("wc-{$this->name}-payments-blocks");
- }
+ wp_enqueue_script("wc-{$this->name}-payments-blocks");
+ }
- return ["wc-{$this->name}-payments-blocks"];
- }
+ return ["wc-{$this->name}-payments-blocks"];
+ }
- /**
- * Returns an array of key=>value pairs of data made available to the payment methods script.
- *
- * @return array
- */
- public function get_payment_method_data() {
- if (!is_checkout()) {
- return [];
- }
+ /**
+ * Returns an array of key=>value pairs of data made available to the payment methods script.
+ *
+ * @return array
+ */
+ public function get_payment_method_data() {
+ if (!is_checkout()) {
+ return [];
+ }
- $this->set_additional_data();
+ $this->set_additional_data();
- return [
- 'name' => $this->name,
- 'title' => $this->get_setting('title'),
- 'description' => $this->get_setting('description'),
- 'supports' => array_filter($this->gateway->supports, [$this->gateway, 'supports']),
- 'data' => $this->additional_data,
- ];
- }
+ return [
+ 'name' => $this->name,
+ 'title' => $this->get_setting('title'),
+ 'description' => $this->get_setting('description'),
+ 'supports' => array_filter($this->gateway->supports, [$this->gateway, 'supports']),
+ 'data' => $this->additional_data,
+ 'is_active' => $this->is_active(),
+ ];
+ }
- /**
- * Set additional data requried to make UI work. Different payment
- * methods may require different additional data.
- *
- * @return void
- */
- abstract public function set_additional_data();
+ /**
+ * Set additional data requried to make UI work. Different payment
+ * methods may require different additional data.
+ *
+ * @return void
+ */
+ abstract public function set_additional_data();
}
diff --git a/includes/blocks/gateways/alipay/omise-block-alipay-cn.php b/includes/blocks/gateways/alipay/omise-block-alipay-cn.php
index c36e026d..86bee1e0 100644
--- a/includes/blocks/gateways/alipay/omise-block-alipay-cn.php
+++ b/includes/blocks/gateways/alipay/omise-block-alipay-cn.php
@@ -1,10 +1,10 @@
additional_data = $this->gateway->validate_atome_request();
- }
+ public function set_additional_data() {
+ $this->additional_data = $this->gateway->validate_atome_request();
+ }
}
diff --git a/includes/blocks/gateways/omise-block-bill-payment-lotus.php b/includes/blocks/gateways/omise-block-bill-payment-lotus.php
index 516aca38..9d8ed57f 100644
--- a/includes/blocks/gateways/omise-block-bill-payment-lotus.php
+++ b/includes/blocks/gateways/omise-block-bill-payment-lotus.php
@@ -1,10 +1,10 @@
settings = get_option( "woocommerce_{$this->name}_settings", [] );
- $gateways = WC()->payment_gateways->payment_gateways();
- $this->gateway = $gateways[ $this->name ];
- }
-
- /**
- * Returns if this payment method should be active. If false, the scripts will not be enqueued.
- *
- * @return boolean
- */
- public function is_active() {
- return $this->gateway->is_available();
- }
-
- /**
- * Returns an array of scripts/handles to be registered for this payment method.
- *
- * @return array
- */
- public function get_payment_method_script_handles() {
- if ( is_checkout() && $this->is_active() ) {
- $script_asset = require __DIR__ . '/../assets/js/build/credit_card.asset.php';
- wp_register_script(
- "{$this->name}-payments-blocks",
- plugin_dir_url( __DIR__ ) . 'assets/js/build/credit_card.js',
- $script_asset[ 'dependencies' ],
- $script_asset[ 'version' ],
- true
- );
- }
-
- return [ "{$this->name}-payments-blocks" ];
- }
-
- /**
- * Returns an array of key=>value pairs of data made available to the payment methods script.
- *
- * @return array
- */
- public function get_payment_method_data() {
+ /**
+ * Payment method name/id/slug.
+ *
+ * @var string
+ */
+ protected $name = 'omise';
- if ( is_user_logged_in() ) {
- $viewData['user_logged_in'] = true;
+ /**
+ * Initializes the payment method type.
+ */
+ public function initialize() {
+ $this->settings = get_option( "woocommerce_{$this->name}_settings", [] );
+ $gateways = WC()->payment_gateways->payment_gateways();
+ $this->gateway = $gateways[ $this->name ];
+ }
- $current_user = wp_get_current_user();
- $omise_customer_id = $this->gateway->is_test() ? $current_user->test_omise_customer_id : $current_user->live_omise_customer_id;
+ /**
+ * Returns if this payment method should be active. If false, the scripts will not be enqueued.
+ *
+ * @return boolean
+ */
+ public function is_active() {
+ return wc_string_to_bool( $this->get_setting( 'enabled', 'no' ) );
+ }
- if ( ! empty( $omise_customer_id ) ) {
- try {
- $cards = new OmiseCustomerCard;
- $existingCards = $cards->get($omise_customer_id);
+ /**
+ * Returns an array of scripts/handles to be registered for this payment method.
+ *
+ * @return array
+ */
+ public function get_payment_method_script_handles() {
+ if ( is_checkout() && $this->is_active() ) {
+ $script_asset = require_once __DIR__ . '/../assets/js/build/credit_card.asset.php';
- foreach($existingCards['data'] as $card) {
- $viewData['existing_cards'][] = [
- 'id' => $card['id'],
- 'brand' => $card['brand'],
- 'last_digits' => $card['last_digits'],
- ];
- }
- } catch (Exception $e) {
- // nothing
- }
- }
- } else {
- $viewData['user_logged_in'] = false;
- }
+ if (is_array($script_asset)) {
+ wp_register_script(
+ "{$this->name}-payments-blocks",
+ plugin_dir_url( __DIR__ ) . 'assets/js/build/credit_card.js',
+ $script_asset[ 'dependencies' ],
+ $script_asset[ 'version' ],
+ true
+ );
+ }
+ }
- $viewData['secure_form_enabled'] = (boolean)$this->gateway->get_option('secure_form_enabled');
+ return [ "{$this->name}-payments-blocks" ];
+ }
- if ($viewData['secure_form_enabled'] === $this->gateway::SECURE_FORM_ENABLED) {
- $viewData['card_form_theme'] = $this->gateway->get_option('card_form_theme');
- $viewData['card_icons'] = $this->gateway->get_card_icons();
- $viewData['form_design'] = Omise_Page_Card_From_Customization::get_instance()->get_design_setting();
- }
+ /**
+ * Returns an array of key=>value pairs of data made available to the payment methods script.
+ *
+ * @return array
+ */
+ public function get_payment_method_data() {
+ $viewData = $this->gateway->get_existing_cards();
+ $viewData = array_merge($viewData, $this->gateway->get_secure_form_config());
- return array_merge($viewData, [
- 'name' => $this->name,
- 'title' => $this->get_setting( 'title' ),
- 'description' => $this->get_setting( 'description' ),
- 'features' => array_filter( $this->gateway->supports, [ $this->gateway, 'supports' ] ),
- 'locale' => get_locale(),
- 'public_key' => Omise()->settings()->public_key(),
- ]);
- }
+ return array_merge($viewData, [
+ 'name' => $this->name,
+ 'title' => $this->get_setting( 'title' ),
+ 'description' => $this->get_setting( 'description' ),
+ 'features' => array_filter( $this->gateway->supports, [ $this->gateway, 'supports' ] ),
+ 'locale' => get_locale(),
+ 'public_key' => Omise_Setting::instance()->public_key(),
+ 'is_active' => $this->is_active(),
+ ]);
+ }
}
diff --git a/includes/blocks/gateways/omise-block-duitnow-obw.php b/includes/blocks/gateways/omise-block-duitnow-obw.php
index 8deb4f60..6e420395 100644
--- a/includes/blocks/gateways/omise-block-duitnow-obw.php
+++ b/includes/blocks/gateways/omise-block-duitnow-obw.php
@@ -2,17 +2,17 @@
class Omise_Block_DuitNow_OBW extends Omise_Block_Payment {
/**
- * Payment method name/id/slug.
- *
- * @var string
- */
- protected $name = 'omise_duitnow_obw';
+ * Payment method name/id/slug.
+ *
+ * @var string
+ */
+ protected $name = 'omise_duitnow_obw';
public function set_additional_data() {
- if (!$this->gateway->backend) {
- $this->gateway->init_payment_config();
- }
-
+ if (!$this->gateway->backend) {
+ $this->gateway->init_payment_config();
+ }
+
$this->additional_data = [ 'banks' => $this->gateway->backend->banks ];
}
}
diff --git a/includes/blocks/gateways/omise-block-duitnow-qr.php b/includes/blocks/gateways/omise-block-duitnow-qr.php
index ab58a78a..b85a38d3 100644
--- a/includes/blocks/gateways/omise-block-duitnow-qr.php
+++ b/includes/blocks/gateways/omise-block-duitnow-qr.php
@@ -1,10 +1,10 @@
additional_data = [
- 'bank_list' => $this->gateway->backend->get_available_banks()
- ];
- }
+ public function set_additional_data() {
+ $this->additional_data = [
+ 'bank_list' => $this->gateway->backend->get_available_banks()
+ ];
+ }
}
diff --git a/includes/blocks/gateways/omise-block-googlepay.php b/includes/blocks/gateways/omise-block-googlepay.php
index 00be5fbe..40b835aa 100644
--- a/includes/blocks/gateways/omise-block-googlepay.php
+++ b/includes/blocks/gateways/omise-block-googlepay.php
@@ -1,14 +1,14 @@
additional_data = $this->gateway->googlepay_config;
- }
+ public function set_additional_data() {
+ $this->additional_data = $this->gateway->googlepay_config;
+ }
}
diff --git a/includes/blocks/gateways/omise-block-grabpay.php b/includes/blocks/gateways/omise-block-grabpay.php
index 7f6d80be..d170afff 100644
--- a/includes/blocks/gateways/omise-block-grabpay.php
+++ b/includes/blocks/gateways/omise-block-grabpay.php
@@ -1,10 +1,10 @@
gateway->get_view_data();
- $installment_backends = [];
+ public function set_additional_data() {
+ $viewData = $this->gateway->get_view_data();
+ $installment_backends = [];
- foreach($viewData['installment_backends'] as $backend) {
- $installment_backends[] = (array)$backend;
- }
+ foreach($viewData['installment_backends'] as $backend) {
+ $installment_backends[] = (array)$backend;
+ }
- $this->additional_data = [
- 'is_zero_interest' => $viewData['is_zero_interest'],
- 'installment_min_limit' => $viewData['installment_min_limit'],
- 'installment_backends' => $installment_backends,
- ];
- }
+ $this->additional_data = [
+ 'is_zero_interest' => $viewData['is_zero_interest'],
+ 'installment_min_limit' => $viewData['installment_min_limit'],
+ 'installment_backends' => $installment_backends,
+ ];
+ }
}
diff --git a/includes/blocks/gateways/omise-block-internetbanking.php b/includes/blocks/gateways/omise-block-internetbanking.php
index be6c324f..033f304b 100644
--- a/includes/blocks/gateways/omise-block-internetbanking.php
+++ b/includes/blocks/gateways/omise-block-internetbanking.php
@@ -2,13 +2,13 @@
class Omise_Block_InternetBanking extends Omise_Block_Payment {
/**
- * Payment method name/id/slug.
- *
- * @var string
- */
- protected $name = 'omise_internetbanking';
+ * Payment method name/id/slug.
+ *
+ * @var string
+ */
+ protected $name = 'omise_internetbanking';
- public function set_additional_data() {
+ public function set_additional_data() {
$this->additional_data = [];
}
}
diff --git a/includes/blocks/gateways/omise-block-maybank-qr.php b/includes/blocks/gateways/omise-block-maybank-qr.php
index 24a5761c..5b80de93 100644
--- a/includes/blocks/gateways/omise-block-maybank-qr.php
+++ b/includes/blocks/gateways/omise-block-maybank-qr.php
@@ -1,10 +1,10 @@
settings = get_option("woocommerce_{$this->name}_settings", []);
- $gateways = WC()->payment_gateways->payment_gateways();
- $this->gateway = $gateways[$this->name];
- }
+ /**
+ * Initializes the payment method type.
+ */
+ public function initialize() {
+ $this->settings = get_option("woocommerce_{$this->name}_settings", []);
+ $gateways = WC()->payment_gateways->payment_gateways();
+ $this->gateway = $gateways[$this->name];
+ }
- /**
- * Returns if this payment method should be active. If false, the scripts will not be enqueued.
- *
- * @return boolean
- */
- public function is_active() {
- return $this->gateway->is_available();
- }
+ /**
+ * Returns if this payment method should be active. If false, the scripts will not be enqueued.
+ *
+ * @return boolean
+ */
+ public function is_active() {
+ return $this->gateway->is_available();
+ }
- /**
- * Returns an array of scripts/handles to be registered for this payment method.
- *
- * @return array
- */
- public function get_payment_method_script_handles() {
- if (!wp_script_is('wc-omise-mobilebanking-payments-blocks', 'enqueued')) {
- $script_asset = require __DIR__ . '/../assets/js/build/omise-mobilebanking.asset.php';
- wp_register_script(
- "wc-omise-mobilebanking-payments-blocks",
- plugin_dir_url(__DIR__) . 'assets/js/build/omise-mobilebanking.js',
- $script_asset['dependencies'],
- $script_asset['version'],
- true
- );
+ /**
+ * Returns an array of scripts/handles to be registered for this payment method.
+ *
+ * @return array
+ */
+ public function get_payment_method_script_handles() {
+ if (!wp_script_is('wc-omise-mobilebanking-payments-blocks', 'enqueued')) {
+ $script_asset = require_once __DIR__ . '/../assets/js/build/omise-mobilebanking.asset.php';
+ wp_register_script(
+ "wc-omise-mobilebanking-payments-blocks",
+ plugin_dir_url(__DIR__) . 'assets/js/build/omise-mobilebanking.js',
+ $script_asset['dependencies'],
+ $script_asset['version'],
+ true
+ );
- wp_enqueue_script('wc-omise-mobilebanking-payments-blocks');
- }
+ wp_enqueue_script('wc-omise-mobilebanking-payments-blocks');
+ }
- return ['wc-omise-mobilebanking-payments-blocks'];
- }
+ return ['wc-omise-mobilebanking-payments-blocks'];
+ }
- /**
- * Returns an array of key=>value pairs of data made available to the payment methods script.
- *
- * @return array
- */
- public function get_payment_method_data() {
- $currency = get_woocommerce_currency();
- return [
- 'name' => $this->name,
- 'title' => $this->get_setting('title'),
- 'description' => $this->get_setting('description'),
- 'supports' => array_filter($this->gateway->supports, [$this->gateway, 'supports']),
- 'data' => [
- 'backends' => $this->gateway->backend->get_available_providers($currency),
- ]
- ];
- }
+ /**
+ * Returns an array of key=>value pairs of data made available to the payment methods script.
+ *
+ * @return array
+ */
+ public function get_payment_method_data() {
+ $currency = get_woocommerce_currency();
+ return [
+ 'name' => $this->name,
+ 'title' => $this->get_setting('title'),
+ 'description' => $this->get_setting('description'),
+ 'supports' => array_filter($this->gateway->supports, [$this->gateway, 'supports']),
+ 'data' => [
+ 'backends' => $this->gateway->backend->get_available_providers($currency),
+ ],
+ 'is_active' => $this->is_active(),
+ ];
+ }
}
diff --git a/includes/blocks/gateways/omise-block-ocbc-digital.php b/includes/blocks/gateways/omise-block-ocbc-digital.php
index 59d0b3ec..a8a33c22 100644
--- a/includes/blocks/gateways/omise-block-ocbc-digital.php
+++ b/includes/blocks/gateways/omise-block-ocbc-digital.php
@@ -1,10 +1,10 @@
additional_data = [ 'is_wallet' => $this->gateway->is_wallet() ];
}
}
diff --git a/includes/blocks/gateways/omise-block-wechat-pay.php b/includes/blocks/gateways/omise-block-wechat-pay.php
index 2cc6016d..6dfdfa99 100644
--- a/includes/blocks/gateways/omise-block-wechat-pay.php
+++ b/includes/blocks/gateways/omise-block-wechat-pay.php
@@ -1,10 +1,10 @@
container = $container;
$this->register_payment_methods();
$this->container->get( Omise_Block_Payments::class );
@@ -15,8 +15,8 @@ function __construct($container) {
private function register_payment_methods() {
// register the payments API
- $this->container->register( Omise_Block_Payments::class, function ( $container ) {
- return new Omise_Block_Payments( $container );
- } );
- }
+ $this->container->register( Omise_Block_Payments::class, function ( $container ) {
+ return new Omise_Block_Payments( $container );
+ } );
+ }
}
diff --git a/includes/blocks/omise-block-payments.php b/includes/blocks/omise-block-payments.php
index 819b3442..51ba32f8 100644
--- a/includes/blocks/omise-block-payments.php
+++ b/includes/blocks/omise-block-payments.php
@@ -35,7 +35,7 @@ class Omise_Block_Payments {
Omise_Block_DuitNow_OBW::class,
];
- function __construct($container) {
+ public function __construct($container) {
$this->container = $container;
$this->add_payment_methods();
$this->initialize();
@@ -43,19 +43,19 @@ function __construct($container) {
private function add_payment_methods() {
foreach($this->payment_methods as $payment_method) {
- $this->container->register($payment_method, function ( $container ) use ($payment_method) {
+ $this->container->register($payment_method, function () use ($payment_method) {
return new $payment_method;
} );
}
}
private function initialize() {
- add_action( 'woocommerce_blocks_payment_method_type_registration', [ $this, 'register_payment_methods' ] );
+ add_action( 'woocommerce_blocks_payment_method_type_registration', [ $this, 'register_payment_methods' ] );
}
public function register_payment_methods( $registry ) {
- foreach ( $this->payment_methods as $clazz ) {
- $registry->register( new $clazz );
- }
+ foreach ( $this->payment_methods as $clazz ) {
+ $registry->register( new $clazz );
+ }
}
}
diff --git a/includes/blocks/omise-block.php b/includes/blocks/omise-block.php
index c5098d61..bbc82742 100644
--- a/includes/blocks/omise-block.php
+++ b/includes/blocks/omise-block.php
@@ -3,48 +3,46 @@
class Omise_Block {
public static function init() {
if ( self::is_active() ) {
- self::container()->get( Omise_Block_Config::class );
- }
+ self::container()->get( Omise_Block_Config::class );
+ }
}
/**
- * Loads the Blocks integration if WooCommerce Blocks is installed as a feature plugin.
- */
- private static function is_active() {
- if ( \class_exists( '\Automattic\WooCommerce\Blocks\Package' ) ) {
- if ( self::is_core_plugin_build() ) {
- return true;
- }
+ * Loads the Blocks integration if WooCommerce Blocks is installed as a feature plugin.
+ */
+ private static function is_active() {
+ if ( \class_exists( '\Automattic\WooCommerce\Blocks\Package' ) ) {
+ if ( self::is_core_plugin_build() ) {
+ return true;
+ }
- if ( \method_exists( '\Automattic\WooCommerce\Blocks\Package', 'feature' ) ) {
- $feature = \Automattic\WooCommerce\Blocks\Package::feature();
- if ( \method_exists( $feature, 'is_feature_plugin_build' ) ) {
- if ( $feature->is_feature_plugin_build() ) {
- return true;
- }
- }
- }
- }
+ if ( \method_exists( '\Automattic\WooCommerce\Blocks\Package', 'feature' ) ) {
+ $feature = \Automattic\WooCommerce\Blocks\Package::feature();
+ if ( \method_exists( $feature, 'is_feature_plugin_build' ) && $feature->is_feature_plugin_build() ) {
+ return true;
+ }
+ }
+ }
- return false;
- }
+ return false;
+ }
private static function is_core_plugin_build() {
- return \function_exists( 'WC' ) && \version_compare( '6.9.0', WC()->version, '<=' );
- }
+ return \function_exists( 'WC' ) && \version_compare( '6.9.0', WC()->version, '<=' );
+ }
/**
- * @return \Automattic\WooCommerce\Blocks\Registry\Container
- */
- public static function container() {
- static $container;
- if ( ! $container ) {
- $container = \Automattic\WooCommerce\Blocks\Package::container();
- $container->register( Omise_Block_Config::class, function ( $container ) {
- return new Omise_Block_Config( $container );
- } );
- }
+ * @return \Automattic\WooCommerce\Blocks\Registry\Container
+ */
+ public static function container() {
+ static $container;
+ if ( ! $container ) {
+ $container = \Automattic\WooCommerce\Blocks\Package::container();
+ $container->register( Omise_Block_Config::class, function ( $container ) {
+ return new Omise_Block_Config( $container );
+ } );
+ }
- return $container;
- }
+ return $container;
+ }
}
diff --git a/includes/class-omise-wc-myaccount.php b/includes/class-omise-wc-myaccount.php
index 101e7faf..a12e21c2 100644
--- a/includes/class-omise-wc-myaccount.php
+++ b/includes/class-omise-wc-myaccount.php
@@ -15,7 +15,7 @@ public static function get_instance() {
return self::$instance;
}
- private function __construct() {
+ public function __construct() {
// prevent running directly without wooCommerce
if ( ! class_exists( 'WC_Payment_Gateway' ) ) {
return;
diff --git a/includes/gateway/class-omise-payment-creditcard.php b/includes/gateway/class-omise-payment-creditcard.php
index 09c63c10..1be1859d 100644
--- a/includes/gateway/class-omise-payment-creditcard.php
+++ b/includes/gateway/class-omise-payment-creditcard.php
@@ -172,9 +172,13 @@ private function register_omise_credit_card_scripts() {
*/
public function payment_fields() {
parent::payment_fields();
+ $viewData = array_merge($this->get_existing_cards(), $this->get_secure_form_config());
+ Omise_Util::render_view( 'templates/payment/form.php', $viewData );
+ }
+ public function get_existing_cards() {
if ( is_user_logged_in() ) {
- $viewData['user_logged_in'] = true;
+ $data['user_logged_in'] = true;
$current_user = wp_get_current_user();
$omise_customer_id = $this->is_test() ? $current_user->test_omise_customer_id : $current_user->live_omise_customer_id;
@@ -182,24 +186,28 @@ public function payment_fields() {
if ( ! empty( $omise_customer_id ) ) {
try {
$cards = new OmiseCustomerCard;
- $viewData['existingCards'] = $cards->get($omise_customer_id);
+ $data['existingCards'] = $cards->get($omise_customer_id);
} catch (Exception $e) {
// nothing
}
}
- } else {
- $viewData['user_logged_in'] = false;
+
+ return $data;
}
- $viewData['secure_form_enabled'] = (boolean)$this->get_option('secure_form_enabled');
+ return [ 'user_logged_in' => false ];
+ }
+
+ public function get_secure_form_config() {
+ $data['secure_form_enabled'] = (boolean)$this->get_option('secure_form_enabled');
- if ($viewData['secure_form_enabled'] === self::SECURE_FORM_ENABLED) {
- $viewData['card_form_theme'] = $this->get_option('card_form_theme');
- $viewData['card_icons'] = $this->get_card_icons();
- $viewData['form_design'] = Omise_Page_Card_From_Customization::get_instance()->get_design_setting();
+ if ($data['secure_form_enabled'] === self::SECURE_FORM_ENABLED) {
+ $data['card_form_theme'] = $this->get_option('card_form_theme');
+ $data['card_icons'] = $this->get_card_icons();
+ $data['form_design'] = Omise_Page_Card_From_Customization::get_instance()->get_design_setting();
}
- Omise_Util::render_view( 'templates/payment/form.php', $viewData );
+ return $data;
}
/**
diff --git a/includes/gateway/class-omise-payment-googlepay.php b/includes/gateway/class-omise-payment-googlepay.php
index 18f9e897..9d081cdb 100644
--- a/includes/gateway/class-omise-payment-googlepay.php
+++ b/includes/gateway/class-omise-payment-googlepay.php
@@ -169,7 +169,7 @@ private function init_googlepay_config() {
'billing_address_required' => $this->get_option('request_billing_address') == 'yes',
'phone_number_required' => $this->get_option('request_phone_number') == 'yes',
'public_key' => $this->public_key(),
- 'merchantId' => $this->get_option('merchant_id'),
+ 'merchant_id' => $this->get_option('merchant_id'),
'price_status' => 'NOT_CURRENTLY_KNOWN',
'currency' => get_woocommerce_currency(),
];
@@ -198,7 +198,7 @@ private function google_pay_button_scripts() {
{
type: 'CARD',
parameters: {
- allowedAuthMethods: " . $this->googlepay_config['allowed_auth_methods'] . ",
+ allowedAuthMethods: " . json_encode($this->googlepay_config['allowed_auth_methods']) . ",
allowedCardNetworks: " . json_encode($this->googlepay_config['allowed_card_networks']) . ",
billingAddressRequired: " . $isBillingAddressRequired . ",
billingAddressParameters: {
@@ -223,10 +223,10 @@ private function google_pay_button_scripts() {
currencyCode: '" . $this->googlepay_config['currency'] . "',
},
}
-
- const div = document.getElementById('googlepay-button-container')
+
+ const div = document.getElementById('googlepay-button-container')
div.appendChild(button)
-
+
function toggleOrderButton() {
const placeOrderButton = document.getElementById('place_order')
const paymentBox = document.getElementById('payment_method_omise_googlepay')
@@ -235,7 +235,7 @@ function toggleOrderButton() {
placeOrderButton.style.display = paymentBox.checked ? 'none' : 'inline-block'
}
}
-
+
toggleOrderButton()
const paymentMethods = document.getElementsByClassName('input-radio')
Array.from(paymentMethods).forEach((el) => {
diff --git a/includes/gateway/class-omise-payment-installment.php b/includes/gateway/class-omise-payment-installment.php
index 30c0fcdb..7dc60580 100644
--- a/includes/gateway/class-omise-payment-installment.php
+++ b/includes/gateway/class-omise-payment-installment.php
@@ -69,10 +69,7 @@ public function payment_fields()
{
parent::payment_fields();
- Omise_Util::render_view(
- 'templates/payment/form-installment.php',
- $this->get_view_data()
- );
+ Omise_Util::render_view('templates/payment/form-installment.php', $this->get_view_data());
}
public function get_view_data()
diff --git a/includes/gateway/class-omise-payment.php b/includes/gateway/class-omise-payment.php
index 8fed68e1..62d7f45b 100644
--- a/includes/gateway/class-omise-payment.php
+++ b/includes/gateway/class-omise-payment.php
@@ -2,99 +2,99 @@
defined( 'ABSPATH' ) or die( 'No direct script access allowed.' );
if ( ! class_exists( 'WC_Payment_Gateway' ) ) {
- return;
+ return;
}
if ( class_exists( 'Omise_Payment' ) ) {
- return;
+ return;
}
abstract class Omise_Payment extends WC_Payment_Gateway {
- use Sync_Order;
-
- const WC_VERSION3 = '3.0.0';
-
- /** Omise charge id post meta key. */
- const CHARGE_ID = 'omise_charge_id';
-
- /**
- * @var string Omise charge statuses
- */
- const STATUS_SUCCESSFUL = 'successful';
- const STATUS_FAILED = 'failed';
- const STATUS_PENDING = 'pending';
- const STATUS_EXPIRED = 'expired';
- const STATUS_REVERSED = 'reversed';
- const STATUS_CANCELLED = 'cancelled';
- const STATUS_REFUNDED = 'refunded';
-
- /**
- * Error codes returned from the API
- */
- const ERROR_CODES = [
- 'FAILED_CAPTURE' => 'failed_capture',
- 'EXPIRED_CHARGE' => 'expired_charge',
- ];
-
- /**
- * @see woocommerce/includes/abstracts/abstract-wc-settings-api.php
- *
- * @var string
- */
- public $id = 'omise';
-
- /**
- * @since 3.4
- *
- * @var \Omise_Backend
- */
- public $backend;
-
- /**
- * @see omise/includes/class-omise-setting.php
- *
- * @var Omise_Setting
- */
- protected $omise_settings;
-
- /**
- * Payment setting values.
- *
- * @var array
- */
- public $payment_settings = array();
-
- /**
- * A list of countries the payment method can be operated with.
- *
- * @var array
- */
- public $restricted_countries = array();
-
- /**
- * A string of Omise Source's type
- * (e.g. paynow or bill_payment_tesco_lotus).
- *
- * @var string
- */
- public $source_type = '';
-
- /**
- * @var array
- */
- private $currency_subunits = [
- 'EUR' => 100,
- 'GBP' => 100,
- 'JPY' => 1,
- 'SGD' => 100,
- 'THB' => 100,
- 'USD' => 100
- ];
-
- /**
- * @var WC_Order|null
- */
- protected $order;
+ use Sync_Order;
+
+ const WC_VERSION3 = '3.0.0';
+
+ /** Omise charge id post meta key. */
+ const CHARGE_ID = 'omise_charge_id';
+
+ /**
+ * @var string Omise charge statuses
+ */
+ const STATUS_SUCCESSFUL = 'successful';
+ const STATUS_FAILED = 'failed';
+ const STATUS_PENDING = 'pending';
+ const STATUS_EXPIRED = 'expired';
+ const STATUS_REVERSED = 'reversed';
+ const STATUS_CANCELLED = 'cancelled';
+ const STATUS_REFUNDED = 'refunded';
+
+ /**
+ * Error codes returned from the API
+ */
+ const ERROR_CODES = [
+ 'FAILED_CAPTURE' => 'failed_capture',
+ 'EXPIRED_CHARGE' => 'expired_charge',
+ ];
+
+ /**
+ * @see woocommerce/includes/abstracts/abstract-wc-settings-api.php
+ *
+ * @var string
+ */
+ public $id = 'omise';
+
+ /**
+ * @since 3.4
+ *
+ * @var \Omise_Backend
+ */
+ public $backend;
+
+ /**
+ * @see omise/includes/class-omise-setting.php
+ *
+ * @var Omise_Setting
+ */
+ protected $omise_settings;
+
+ /**
+ * Payment setting values.
+ *
+ * @var array
+ */
+ public $payment_settings = array();
+
+ /**
+ * A list of countries the payment method can be operated with.
+ *
+ * @var array
+ */
+ public $restricted_countries = array();
+
+ /**
+ * A string of Omise Source's type
+ * (e.g. paynow or bill_payment_tesco_lotus).
+ *
+ * @var string
+ */
+ public $source_type = '';
+
+ /**
+ * @var array
+ */
+ private $currency_subunits = [
+ 'EUR' => 100,
+ 'GBP' => 100,
+ 'JPY' => 1,
+ 'SGD' => 100,
+ 'THB' => 100,
+ 'USD' => 100
+ ];
+
+ /**
+ * @var WC_Order|null
+ */
+ protected $order;
/**
* Fact for woocommerce to consider sending email to merchant whenever order status change to processing which will disable by default
@@ -102,472 +102,472 @@ abstract class Omise_Payment extends WC_Payment_Gateway {
*
* @var bool
*/
- protected $enabled_processing_notification = false;
+ protected $enabled_processing_notification = false;
+
+ public function __construct() {
+ $this->omise_settings = Omise()->settings();
+ $this->payment_settings = $this->omise_settings->get_settings();
+
+ add_action( 'wp_enqueue_scripts', array( $this, 'omise_checkout_assets' ) );
+ add_action( 'woocommerce_order_status_processing', 'OmisePluginHelperMailer::processing_admin_notification', 10, 2 );
+ add_filter( 'woocommerce_email_recipient_new_order', 'OmisePluginHelperMailer::disable_merchant_order_on_hold', 10, 2 );
+ add_filter('is_protected_meta', [ $this, 'protectMetadata'], 10, 2);
+ }
+
+ /**
+ * Protect the metadata that is included in the return URI. The token is used to
+ * validate the session for the order.
+ *
+ * @param boolean $protected
+ * @param array $metadataKeys
+ *
+ * @return boolean
+ */
+ public function protectMetadata($protected, $metadataKeys)
+ {
+ if ( in_array( $metadataKeys, [ 'token', 'is_omise_payment_resolved' ] )) {
+ return true;
+ }
+
+ return $protected;
+ }
+
+ /**
+ * get pending status
+ *
+ * This function is crate to get value for pending status,
+ * since we cannot mock constant values for unit test.
+ */
+ public function get_pending_status() {
+ return self::STATUS_PENDING;
+ }
+
+ /**
+ * Register all required javascripts
+ */
+ public function omise_checkout_assets() {
+ if ( is_checkout() ) {
+ wp_enqueue_style( 'omise', plugins_url( '../../assets/css/omise-css.css', __FILE__ ), array(), OMISE_WOOCOMMERCE_PLUGIN_VERSION );
+
+ do_action( 'omise_checkout_assets' );
+ }
+ }
+
+ /**
+ * @param string|WC_Order $order
+ *
+ * @return WC_Order|null
+ */
+ public function load_order( $order )
+ {
+ $this->order = ($order instanceof WC_Order) ? $order : wc_get_order( $order );
+
+ if (!$this->order) {
+ $this->order = null;
+ }
+
+ return $this->order;
+ }
+
+ /**
+ * @return WC_Order|null
+ */
+ public function order()
+ {
+ return $this->order;
+ }
+
+ /**
+ * Whether Sandbox (test) mode is enabled or not.
+ *
+ * @return bool
+ */
+ public function is_test() {
+ return $this->omise_settings->is_test();
+ }
+
+ /**
+ * Return Omise public key.
+ *
+ * @return string
+ */
+ protected function public_key() {
+ return $this->omise_settings->public_key();
+ }
+
+ /**
+ * Return Omise secret key.
+ *
+ * @return string
+ */
+ protected function secret_key() {
+ return $this->omise_settings->secret_key();
+ }
+
+ /**
+ * @param string $currency
+ *
+ * @return bool
+ */
+ protected function is_currency_support( $currency ) {
+ if ( isset( $this->currency_subunits[ strtoupper( $currency ) ] ) ) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * @param string $country_code
+ *
+ * @return bool
+ */
+ public function is_country_support( $country_code ) {
+ array_map( 'strtoupper', $this->restricted_countries );
+
+ if ( in_array( strtoupper( $country_code ), $this->restricted_countries ) ) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Check if the gateway is available for customer on checkout page.
+ *
+ * @see WC_Payment_Gateway::is_available()
+ * @see woocommerce/includes/abstracts/abstract-wc-payment-gateway.php
+ *
+ * @return bool
+ */
+ public function is_available(){
+ if ( !parent::is_available() ) {
+ return false;
+ }
+
+ $capabilities = Omise_Capabilities::retrieve();
+
+ if ( !$capabilities ) {
+ return false;
+ }
+
+ return $this->is_capability_support($capabilities->get_available_payment_methods());
+ }
+
+ /**
+ * check if payment method is support by omise capability api version 2017
+ *
+ * @param array of backends source_type
+ *
+ * @return bool
+ */
+ public function is_capability_support( $available_payment_methods ) {
+ return in_array($this->source_type, $available_payment_methods);
+ }
+
+ /**
+ * @since 3.4
+ *
+ * @see WC_Payment_Gateway::process_payment( $order_id )
+ * @see woocommerce/includes/abstracts/abstract-wc-payment-gateway.php
+ *
+ * @param int $order_id
+ *
+ * @return array
+ */
+ public function process_payment( $order_id ) {
+ if ( ! $this->load_order( $order_id ) ) {
+ return $this->invalid_order( $order_id );
+ }
+
+ $this->order->add_order_note( sprintf( __( 'Opn Payments: Processing a payment with %s', 'omise' ), $this->method_title ) );
+ $this->order->add_meta_data( 'is_omise_payment_resolved', 'no', true );
+ $this->order->save();
+
+ try {
+ $charge = $this->charge( $order_id, $this->order );
+ } catch ( Exception $e ) {
+ return $this->payment_failed( $e->getMessage() );
+ }
+
+ $this->order->add_order_note( sprintf( __( 'Opn Payments: Charge (ID: %s) has been created', 'omise' ), $charge['id'] ) );
+ $this->set_order_transaction_id( $charge['id'] );
+
+ return $this->result( $order_id, $this->order, $charge );
+ }
+
+ /**
+ * @since 3.4
+ *
+ * @see Omise_Payment::process_payment( $order_id )
+ *
+ * @param int $order_id
+ * @param WC_Order $order
+ *
+ * @return OmiseCharge|OmiseException
+ */
+ abstract public function charge( $order_id, $order );
+
+ /**
+ * @since 3.4
+ *
+ * @see Omise_Payment::process_payment( $order_id )
+ *
+ * @param int $order_id
+ * @param WC_Order $order
+ * @param OmiseCharge $charge
+ *
+ * @return array|Exception
+ */
+ abstract public function result( $order_id, $order, $charge );
+
+ /**
+ * Capture an authorized charge.
+ *
+ * @param WC_Order $order WooCommerce's order object
+ *
+ * @return void
+ *
+ * @see WC_Meta_Box_Order_Actions::save( $post_id, $post )
+ * @see woocommerce/includes/admin/meta-boxes/class-wc-meta-box-order-actions.php
+ */
+ public function process_capture( $order ) {
+ $this->load_order( $order );
+
+ try {
+ $charge = OmiseCharge::retrieve( $this->get_charge_id_from_order() );
+ $charge->capture();
+
+ if ( ! OmisePluginHelperCharge::isPaid( $charge ) ) {
+ throw new Exception( Omise()->translate( $charge['failure_message'] ) );
+ }
+
+ $this->order()->add_order_note(
+ sprintf(
+ wp_kses(
+ __( 'Opn Payments: Payment successful (manual capture).
An amount of %1$s %2$s has been paid', 'omise' ),
+ array( 'br' => array() )
+ ),
+
+ $this->order()->get_total(),
+ $this->order()->get_currency()
+ )
+ );
+ $this->delete_capture_metadata();
+ $this->order()->payment_complete();
+ } catch ( Exception $e ) {
+ $omiseError = $e->getOmiseError();
+ $this->order()->add_order_note(
+ sprintf(
+ wp_kses( __( 'Opn Payments: Capture failed (manual capture).
%s', 'omise' ), array( 'br' => array() ) ),
+ $e->getMessage()
+ )
+ );
+
+ // we don't want to delete the capture metadata for other errors like 401, 403, and 500
+ if ( self::ERROR_CODES['FAILED_CAPTURE'] === $omiseError['code'] || self::ERROR_CODES['EXPIRED_CHARGE'] === $omiseError['code'] ) {
+ $this->delete_capture_metadata();
+ }
+
+ if ( self::ERROR_CODES['EXPIRED_CHARGE'] === $omiseError['code'] ) {
+ $this->order()->update_status( self::STATUS_CANCELLED );
+ }
+ }
+ }
+
+ /**
+ * Process refund.
+ *
+ * @param int $order_id
+ * @param float $amount
+ * @param string $reason
+ *
+ * @return boolean True|False based on success, or a WP_Error object.
+ *
+ * @see WC_Payment_Gateway::process_refund( $order_id, $amount = null, $reason = '' )
+ */
+ public function process_refund( $order_id, $amount = null, $reason = '' ) {
+ if ( ! $order = wc_get_order( $order_id ) ) {
+ $message = __(
+ 'Refund failed. Cannot retrieve an order with the given ID: %s. Please try again or do a manual refund.',
+ 'omise'
+ );
+
+ return new WP_Error( 'error', sprintf( wp_kses( $message, array( 'br' => array() ) ), $order_id ) );
+ }
+
+ try {
+ $charge = OmiseCharge::retrieve( $order->get_transaction_id() );
+ $refund = $charge->refunds()->create( array(
+ 'amount' => Omise_Money::to_subunit( $amount, $order->get_currency() ),
+ 'metadata' => array( 'reason' => sanitize_text_field( $reason ) )
+ ) );
+
+ if ( $refund['voided'] ) {
+ $message = sprintf(
+ wp_kses(
+ __( 'Opn Payments: Voided an amount of %1$s %2$s.
Refund id is %3$s', 'omise' ),
+ array( 'br' => array() )
+ ),
+ $amount,
+ $order->get_currency(),
+ $refund['id']
+ );
+ } else {
+ $message = sprintf(
+ wp_kses(
+ __( 'Opn Payments: Refunded an amount of %1$s %2$s.
Refund id is %3$s', 'omise' ),
+ array( 'br' => array() )
+ ),
+ $amount,
+ $order->get_currency(),
+ $refund['id']
+ );
+ }
+
+ $order->add_order_note( $message );
+ return true;
+ } catch (Exception $e) {
+ return new WP_Error( 'error', __( 'Refund failed.' ) . ' ' . $e->getMessage() );
+ }
+ }
+
+ /**
+ * Set an order transaction id
+ *
+ * @param string $transaction_id Omise charge id.
+ */
+ protected function set_order_transaction_id( $transaction_id ) {
+ /** backward compatible with WooCommerce v2.x series **/
+ if ( version_compare( WC()->version, self::WC_VERSION3, '>=' ) ) {
+ $this->order()->set_transaction_id( $transaction_id );
+ $this->order()->save();
+ } else {
+ update_post_meta( $this->order()->id, '_transaction_id', $transaction_id );
+ }
+ }
+
+ /**
+ * @param int|mixed $order_id
+ */
+ protected function invalid_order( $order_id ) {
+ $message = wp_kses( __(
+ 'We have been unable to process your payment.
+ Please note that you\'ve done nothing wrong - this is likely an issue with our store.
+
+ Feel free to try submitting your order again, or report this problem to our support team (Your temporary order id is \'%s\')',
+ 'omise'
+ ), array( 'br' => array() ) );
+
+ wc_add_notice( sprintf( $message, $order_id ), 'error' );
+ }
+
+ /**
+ * @param string $reason
+ */
+ protected function payment_failed( $reason ) {
+ $message = __( "It seems we've been unable to process your payment properly:
%s", 'omise' );
+
+ if ( $this->order() ) {
+ $this->order()->add_order_note( sprintf( __( 'Opn Payments: Payment failed, %s', 'omise' ), $reason ) );
+ $this->order()->update_status( 'failed' );
+ }
+
+ wc_add_notice( sprintf( wp_kses( $message, array( 'br' => array() ) ), __( $reason, 'omise' ) ), 'error' );
+ }
+
+ /**
+ * Retrieve an attached charge id.
+ *
+ * @deprecated 3.4 We can simply retrieve Omise charge id via WC_Order::get_transaction_id().
+ * Unfortunately, we may need to leave this code
+ * as it is for backward compatibility reason.
+ *
+ * @return string
+ */
+ public function get_charge_id_from_order() {
+ if ( $charge_id = $this->order()->get_transaction_id() ) {
+ return $charge_id;
+ }
+
+ /**
+ * @deprecated 3.4
+ * The following code are for backward compatible only.
+ */
+ // Backward compatible for Omise v3.0 - v3.3
+ $order_id = version_compare( WC()->version, self::WC_VERSION3, '>=' ) ? $this->order()->get_id() : $this->order()->id;
+ $charge_id = get_post_meta( $order_id, self::CHARGE_ID, true );
+
+ // Backward compatible for Omise v1.2.3
+ if ( empty( $charge_id ) ) {
+ $charge_id = $this->deprecated_get_charge_id_from_post();
+ }
+
+ return $charge_id;
+ }
+
+ /**
+ * Attach a charge id into an order.
+ *
+ * @deprecated 3.4 Now using Omise_Payment::set_order_transaction_id().
+ * However, keeping this method here just in case
+ * if this method has been implemented in some other of 3rd-party plugins.
+ *
+ * @param string $charge_id Omise charge id.
+ */
+ public function attach_charge_id_to_order( $charge_id ) {
+ $this->set_order_transaction_id( $charge_id );
+ }
+
+ /**
+ * Retrieve a charge id from a post.
+ *
+ * @deprecated 3.0 No longer assign a new charge id with new post.
+ *
+ * @return string
+ */
+ protected function deprecated_get_charge_id_from_post() {
+ /** backward compatible with WooCommerce v2.x series **/
+ $order_id = version_compare( WC()->version, self::WC_VERSION3, '>=' ) ? $this->order()->get_id() : $this->order()->id;
+
+ $posts = get_posts(
+ array(
+ 'post_type' => 'omise_charge_items',
+ 'meta_query' => array(
+ array(
+ 'key' => '_wc_order_id',
+ 'value' => $order_id,
+ 'compare' => '='
+ )
+ )
+ )
+ );
+
+ if ( empty( $posts ) ) {
+ return '';
+ }
- public function __construct() {
- $this->omise_settings = Omise()->settings();
- $this->payment_settings = $this->omise_settings->get_settings();
+ $post = $posts[0];
+ $value = get_post_custom_values( '_omise_charge_id', $post->ID );
- add_action( 'wp_enqueue_scripts', array( $this, 'omise_checkout_assets' ) );
- add_action( 'woocommerce_order_status_processing', 'OmisePluginHelperMailer::processing_admin_notification', 10, 2 );
- add_filter( 'woocommerce_email_recipient_new_order', 'OmisePluginHelperMailer::disable_merchant_order_on_hold', 10, 2 );
- add_filter('is_protected_meta', [ $this, 'protectMetadata'], 10, 2);
+ if ( ! is_null( $value ) && ! empty( $value ) ) {
+ return $value[0];
+ }
}
- /**
- * Protect the metadata that is included in the return URI. The token is used to
- * validate the session for the order.
- *
- * @param boolean $protected
- * @param array $metadataKeys
- *
- * @return boolean
- */
- public function protectMetadata($protected, $metadataKeys)
- {
- if ( in_array( $metadataKeys, [ 'token', 'is_omise_payment_resolved' ] )) {
- return true;
- }
-
- return $protected;
- }
-
- /**
- * get pending status
- *
- * This function is crate to get value for pending status,
- * since we cannot mock constant values for unit test.
- */
- public function get_pending_status() {
- return self::STATUS_PENDING;
- }
-
- /**
- * Register all required javascripts
- */
- public function omise_checkout_assets() {
- if ( is_checkout() ) {
- wp_enqueue_style( 'omise', plugins_url( '../../assets/css/omise-css.css', __FILE__ ), array(), OMISE_WOOCOMMERCE_PLUGIN_VERSION );
-
- do_action( 'omise_checkout_assets' );
- }
- }
-
- /**
- * @param string|WC_Order $order
- *
- * @return WC_Order|null
- */
- public function load_order( $order )
- {
- $this->order = ($order instanceof WC_Order) ? $order : wc_get_order( $order );
-
- if (!$this->order) {
- $this->order = null;
- }
-
- return $this->order;
- }
-
- /**
- * @return WC_Order|null
- */
- public function order()
- {
- return $this->order;
- }
-
- /**
- * Whether Sandbox (test) mode is enabled or not.
- *
- * @return bool
- */
- public function is_test() {
- return $this->omise_settings->is_test();
- }
-
- /**
- * Return Omise public key.
- *
- * @return string
- */
- protected function public_key() {
- return $this->omise_settings->public_key();
- }
-
- /**
- * Return Omise secret key.
- *
- * @return string
- */
- protected function secret_key() {
- return $this->omise_settings->secret_key();
- }
-
- /**
- * @param string $currency
- *
- * @return bool
- */
- protected function is_currency_support( $currency ) {
- if ( isset( $this->currency_subunits[ strtoupper( $currency ) ] ) ) {
- return true;
- }
-
- return false;
- }
-
- /**
- * @param string $country_code
- *
- * @return bool
- */
- public function is_country_support( $country_code ) {
- array_map( 'strtoupper', $this->restricted_countries );
-
- if ( in_array( strtoupper( $country_code ), $this->restricted_countries ) ) {
- return true;
- }
-
- return false;
- }
-
- /**
- * Check if the gateway is available for customer on checkout page.
- *
- * @see WC_Payment_Gateway::is_available()
- * @see woocommerce/includes/abstracts/abstract-wc-payment-gateway.php
- *
- * @return bool
- */
- // public function is_available(){
- // if ( !parent::is_available() ) {
- // return false;
- // }
-
- // $capabilities = Omise_Capabilities::retrieve();
-
- // if ( !$capabilities ) {
- // return false;
- // }
-
- // return $this->is_capability_support($capabilities->get_available_payment_methods());
- // }
-
- /**
- * check if payment method is support by omise capability api version 2017
- *
- * @param array of backends source_type
- *
- * @return bool
- */
- public function is_capability_support( $available_payment_methods ) {
- return in_array($this->source_type,$available_payment_methods);
- }
-
- /**
- * @since 3.4
- *
- * @see WC_Payment_Gateway::process_payment( $order_id )
- * @see woocommerce/includes/abstracts/abstract-wc-payment-gateway.php
- *
- * @param int $order_id
- *
- * @return array
- */
- public function process_payment( $order_id ) {
- if ( ! $this->load_order( $order_id ) ) {
- return $this->invalid_order( $order_id );
- }
-
- $this->order->add_order_note( sprintf( __( 'Opn Payments: Processing a payment with %s', 'omise' ), $this->method_title ) );
- $this->order->add_meta_data( 'is_omise_payment_resolved', 'no', true );
- $this->order->save();
-
- try {
- $charge = $this->charge( $order_id, $this->order );
- } catch ( Exception $e ) {
- return $this->payment_failed( $e->getMessage() );
- }
-
- $this->order->add_order_note( sprintf( __( 'Opn Payments: Charge (ID: %s) has been created', 'omise' ), $charge['id'] ) );
- $this->set_order_transaction_id( $charge['id'] );
-
- return $this->result( $order_id, $this->order, $charge );
- }
-
- /**
- * @since 3.4
- *
- * @see Omise_Payment::process_payment( $order_id )
- *
- * @param int $order_id
- * @param WC_Order $order
- *
- * @return OmiseCharge|OmiseException
- */
- abstract public function charge( $order_id, $order );
-
- /**
- * @since 3.4
- *
- * @see Omise_Payment::process_payment( $order_id )
- *
- * @param int $order_id
- * @param WC_Order $order
- * @param OmiseCharge $charge
- *
- * @return array|Exception
- */
- abstract public function result( $order_id, $order, $charge );
-
- /**
- * Capture an authorized charge.
- *
- * @param WC_Order $order WooCommerce's order object
- *
- * @return void
- *
- * @see WC_Meta_Box_Order_Actions::save( $post_id, $post )
- * @see woocommerce/includes/admin/meta-boxes/class-wc-meta-box-order-actions.php
- */
- public function process_capture( $order ) {
- $this->load_order( $order );
-
- try {
- $charge = OmiseCharge::retrieve( $this->get_charge_id_from_order() );
- $charge->capture();
-
- if ( ! OmisePluginHelperCharge::isPaid( $charge ) ) {
- throw new Exception( Omise()->translate( $charge['failure_message'] ) );
- }
-
- $this->order()->add_order_note(
- sprintf(
- wp_kses(
- __( 'Opn Payments: Payment successful (manual capture).
An amount of %1$s %2$s has been paid', 'omise' ),
- array( 'br' => array() )
- ),
-
- $this->order()->get_total(),
- $this->order()->get_currency()
- )
- );
- $this->delete_capture_metadata();
- $this->order()->payment_complete();
- } catch ( Exception $e ) {
- $omiseError = $e->getOmiseError();
- $this->order()->add_order_note(
- sprintf(
- wp_kses( __( 'Opn Payments: Capture failed (manual capture).
%s', 'omise' ), array( 'br' => array() ) ),
- $e->getMessage()
- )
- );
-
- // we don't want to delete the capture metadata for other errors like 401, 403, and 500
- if ( self::ERROR_CODES['FAILED_CAPTURE'] === $omiseError['code'] || self::ERROR_CODES['EXPIRED_CHARGE'] === $omiseError['code'] ) {
- $this->delete_capture_metadata();
- }
-
- if ( self::ERROR_CODES['EXPIRED_CHARGE'] === $omiseError['code'] ) {
- $this->order()->update_status( self::STATUS_CANCELLED );
- }
- }
- }
-
- /**
- * Process refund.
- *
- * @param int $order_id
- * @param float $amount
- * @param string $reason
- *
- * @return boolean True|False based on success, or a WP_Error object.
- *
- * @see WC_Payment_Gateway::process_refund( $order_id, $amount = null, $reason = '' )
- */
- public function process_refund( $order_id, $amount = null, $reason = '' ) {
- if ( ! $order = wc_get_order( $order_id ) ) {
- $message = __(
- 'Refund failed. Cannot retrieve an order with the given ID: %s. Please try again or do a manual refund.',
- 'omise'
- );
-
- return new WP_Error( 'error', sprintf( wp_kses( $message, array( 'br' => array() ) ), $order_id ) );
- }
-
- try {
- $charge = OmiseCharge::retrieve( $order->get_transaction_id() );
- $refund = $charge->refunds()->create( array(
- 'amount' => Omise_Money::to_subunit( $amount, $order->get_currency() ),
- 'metadata' => array( 'reason' => sanitize_text_field( $reason ) )
- ) );
-
- if ( $refund['voided'] ) {
- $message = sprintf(
- wp_kses(
- __( 'Opn Payments: Voided an amount of %1$s %2$s.
Refund id is %3$s', 'omise' ),
- array( 'br' => array() )
- ),
- $amount,
- $order->get_currency(),
- $refund['id']
- );
- } else {
- $message = sprintf(
- wp_kses(
- __( 'Opn Payments: Refunded an amount of %1$s %2$s.
Refund id is %3$s', 'omise' ),
- array( 'br' => array() )
- ),
- $amount,
- $order->get_currency(),
- $refund['id']
- );
- }
-
- $order->add_order_note( $message );
- return true;
- } catch (Exception $e) {
- return new WP_Error( 'error', __( 'Refund failed.' ) . ' ' . $e->getMessage() );
- }
- }
-
- /**
- * Set an order transaction id
- *
- * @param string $transaction_id Omise charge id.
- */
- protected function set_order_transaction_id( $transaction_id ) {
- /** backward compatible with WooCommerce v2.x series **/
- if ( version_compare( WC()->version, self::WC_VERSION3, '>=' ) ) {
- $this->order()->set_transaction_id( $transaction_id );
- $this->order()->save();
- } else {
- update_post_meta( $this->order()->id, '_transaction_id', $transaction_id );
- }
- }
-
- /**
- * @param int|mixed $order_id
- */
- protected function invalid_order( $order_id ) {
- $message = wp_kses( __(
- 'We have been unable to process your payment.
- Please note that you\'ve done nothing wrong - this is likely an issue with our store.
-
- Feel free to try submitting your order again, or report this problem to our support team (Your temporary order id is \'%s\')',
- 'omise'
- ), array( 'br' => array() ) );
-
- wc_add_notice( sprintf( $message, $order_id ), 'error' );
- }
-
- /**
- * @param string $reason
- */
- protected function payment_failed( $reason ) {
- $message = __( "It seems we've been unable to process your payment properly:
%s", 'omise' );
-
- if ( $this->order() ) {
- $this->order()->add_order_note( sprintf( __( 'Opn Payments: Payment failed, %s', 'omise' ), $reason ) );
- $this->order()->update_status( 'failed' );
- }
-
- wc_add_notice( sprintf( wp_kses( $message, array( 'br' => array() ) ), __( $reason, 'omise' ) ), 'error' );
- }
-
- /**
- * Retrieve an attached charge id.
- *
- * @deprecated 3.4 We can simply retrieve Omise charge id via WC_Order::get_transaction_id().
- * Unfortunately, we may need to leave this code
- * as it is for backward compatibility reason.
- *
- * @return string
- */
- public function get_charge_id_from_order() {
- if ( $charge_id = $this->order()->get_transaction_id() ) {
- return $charge_id;
- }
-
- /**
- * @deprecated 3.4
- * The following code are for backward compatible only.
- */
- // Backward compatible for Omise v3.0 - v3.3
- $order_id = version_compare( WC()->version, self::WC_VERSION3, '>=' ) ? $this->order()->get_id() : $this->order()->id;
- $charge_id = get_post_meta( $order_id, self::CHARGE_ID, true );
-
- // Backward compatible for Omise v1.2.3
- if ( empty( $charge_id ) ) {
- $charge_id = $this->deprecated_get_charge_id_from_post();
- }
-
- return $charge_id;
- }
-
- /**
- * Attach a charge id into an order.
- *
- * @deprecated 3.4 Now using Omise_Payment::set_order_transaction_id().
- * However, keeping this method here just in case
- * if this method has been implemented in some other of 3rd-party plugins.
- *
- * @param string $charge_id Omise charge id.
- */
- public function attach_charge_id_to_order( $charge_id ) {
- $this->set_order_transaction_id( $charge_id );
- }
-
- /**
- * Retrieve a charge id from a post.
- *
- * @deprecated 3.0 No longer assign a new charge id with new post.
- *
- * @return string
- */
- protected function deprecated_get_charge_id_from_post() {
- /** backward compatible with WooCommerce v2.x series **/
- $order_id = version_compare( WC()->version, self::WC_VERSION3, '>=' ) ? $this->order()->get_id() : $this->order()->id;
-
- $posts = get_posts(
- array(
- 'post_type' => 'omise_charge_items',
- 'meta_query' => array(
- array(
- 'key' => '_wc_order_id',
- 'value' => $order_id,
- 'compare' => '='
- )
- )
- )
- );
-
- if ( empty( $posts ) ) {
- return '';
- }
-
- $post = $posts[0];
- $value = get_post_custom_values( '_omise_charge_id', $post->ID );
-
- if ( ! is_null( $value ) && ! empty( $value ) ) {
- return $value[0];
- }
- }
-
- /**
- * Getter method for enabled_processing_notification
- *
- * @return bool
- */
- public function is_enabled_processing_notification() {
+ /**
+ * Getter method for enabled_processing_notification
+ *
+ * @return bool
+ */
+ public function is_enabled_processing_notification() {
return $this->enabled_processing_notification;
- }
+ }
- private function delete_capture_metadata() {
- $this->order()->delete_meta_data( 'is_awaiting_capture');
- $this->order()->save();
- }
+ private function delete_capture_metadata() {
+ $this->order()->delete_meta_data( 'is_awaiting_capture');
+ $this->order()->save();
+ }
/**
*
diff --git a/tests/unit/includes/admin/class-omise-page-card-form-customization-test.php b/tests/unit/includes/admin/class-omise-page-card-form-customization-test.php
index 43a1dc41..aa485590 100644
--- a/tests/unit/includes/admin/class-omise-page-card-form-customization-test.php
+++ b/tests/unit/includes/admin/class-omise-page-card-form-customization-test.php
@@ -7,14 +7,14 @@
*/
class Omise_Page_Card_From_Customization_Test extends TestCase
{
- public function setUp(): void
+ protected function setUp(): void
{
Brain\Monkey\setUp();
Mockery::mock('alias:Omise_Admin_Page');
require_once __DIR__ . '/../../../../includes/admin/class-omise-page-card-form-customization.php';
}
- public function tearDown(): void
+ protected function tearDown(): void
{
Brain\Monkey\tearDown();
Mockery::close();
diff --git a/tests/unit/includes/blocks/gateways/abstract-omise-block-apm-test.php b/tests/unit/includes/blocks/gateways/abstract-omise-block-apm-test.php
new file mode 100644
index 00000000..4019988c
--- /dev/null
+++ b/tests/unit/includes/blocks/gateways/abstract-omise-block-apm-test.php
@@ -0,0 +1,99 @@
+mockWcGateways();
+ require_once __DIR__ . '/../../../../../includes/blocks/gateways/abstract-omise-block-apm.php';
+ $this->obj = new class extends Omise_Block_Apm {};
+ }
+
+ /**
+ * @test
+ */
+ public function initialize()
+ {
+ Monkey\Functions\expect('get_option')->andReturn(null);
+
+ $reflection = new \ReflectionClass($this->obj);
+ $name_property = $reflection->getProperty('name');
+ $name_property->setAccessible(true);
+ $name_property->setValue($this->obj, 'omise_promptpay');
+
+ $this->obj->initialize();
+
+ $gateway_property = $reflection->getProperty('gateway');
+ $gateway_property->setAccessible(true);
+ $gateway_val = $gateway_property->getValue($this->obj);
+
+ $this->assertEquals('object', gettype($gateway_val));
+ }
+
+ /**
+ * @test
+ */
+ public function is_active()
+ {
+ // Calling initialize() to set $gateway value
+ $reflection = new \ReflectionClass($this->obj);
+ $name_property = $reflection->getProperty('name');
+ $name_property->setAccessible(true);
+ $name_property->setValue($this->obj, 'omise_promptpay');
+
+ $this->obj->initialize();
+
+ $is_active = $this->obj->is_active();
+ $this->assertTrue($is_active);
+ }
+
+ /**
+ * @test
+ */
+ public function get_payment_method_data()
+ {
+ // Calling initialize() to set $gateway value
+ $reflection = new \ReflectionClass($this->obj);
+ $name_property = $reflection->getProperty('name');
+ $name_property->setAccessible(true);
+ $name_property->setValue($this->obj, 'omise_promptpay');
+
+ $this->obj->initialize();
+
+ $data = $this->obj->get_payment_method_data();
+
+ $this->assertArrayHasKey('title', $data);
+ $this->assertArrayHasKey('description', $data);
+ $this->assertArrayHasKey('supports', $data);
+ $this->assertEquals('array', gettype($data['supports']));
+ $this->assertEquals('omise_promptpay', $data['name']);
+ }
+
+ /**
+ * @test
+ */
+ public function get_payment_method_script_handles()
+ {
+ Monkey\Functions\expect('wp_script_is')->andReturn(false);
+ Monkey\Functions\expect('wp_register_script');
+ Monkey\Functions\expect('plugin_dir_url');
+ Monkey\Functions\expect('wp_enqueue_script');
+
+ $result = $this->obj->get_payment_method_script_handles();
+
+ $this->assertEquals([ 'wc-omise-one-click-apms-payments-blocks' ], $result);
+ }
+}
diff --git a/tests/unit/includes/blocks/gateways/abstract-omise-block-payment-test.php b/tests/unit/includes/blocks/gateways/abstract-omise-block-payment-test.php
new file mode 100644
index 00000000..d44d53c4
--- /dev/null
+++ b/tests/unit/includes/blocks/gateways/abstract-omise-block-payment-test.php
@@ -0,0 +1,109 @@
+mockWcGateways();
+ require_once __DIR__ . '/../../../../../includes/blocks/gateways/abstract-omise-block-payment.php';
+ $this->obj = new class extends Omise_Block_Payment {
+ public function set_additional_data() {
+ $this->additional_data = [];
+ }
+ };
+ }
+
+ /**
+ * @test
+ */
+ public function initialize()
+ {
+ Monkey\Functions\expect('get_option')->andReturn(null);
+
+ $reflection = new \ReflectionClass($this->obj);
+ $name_property = $reflection->getProperty('name');
+ $name_property->setAccessible(true);
+ $name_property->setValue($this->obj, 'omise_atome');
+
+ $this->obj->initialize();
+
+ $gateway_property = $reflection->getProperty('gateway');
+ $gateway_property->setAccessible(true);
+ $gateway_val = $gateway_property->getValue($this->obj);
+
+ $this->assertEquals('object', gettype($gateway_val));
+ }
+
+ /**
+ * @test
+ */
+ public function is_active()
+ {
+ // Calling initialize() to set $gateway value
+ $reflection = new \ReflectionClass($this->obj);
+ $name_property = $reflection->getProperty('name');
+ $name_property->setAccessible(true);
+ $name_property->setValue($this->obj, 'omise_atome');
+
+ $this->obj->initialize();
+
+ $is_active = $this->obj->is_active();
+ $this->assertTrue($is_active);
+ }
+
+ /**
+ * @test
+ */
+ public function get_payment_method_data()
+ {
+ Monkey\Functions\expect('is_checkout')->andReturn(true);
+ // Calling initialize() to set $gateway value
+ $reflection = new \ReflectionClass($this->obj);
+ $name_property = $reflection->getProperty('name');
+ $name_property->setAccessible(true);
+ $name_property->setValue($this->obj, 'omise_atome');
+
+ $this->obj->initialize();
+
+ $data = $this->obj->get_payment_method_data();
+
+ $this->assertArrayHasKey('title', $data);
+ $this->assertArrayHasKey('description', $data);
+ $this->assertArrayHasKey('supports', $data);
+ $this->assertEquals('array', gettype($data['supports']));
+ $this->assertEquals('omise_atome', $data['name']);
+ }
+
+ /**
+ * @test
+ */
+ public function get_payment_method_script_handles()
+ {
+ $reflection = new \ReflectionClass($this->obj);
+ $name_property = $reflection->getProperty('name');
+ $name_property->setAccessible(true);
+ $name_property->setValue($this->obj, 'omise_atome');
+
+ Monkey\Functions\expect('wp_script_is')->andReturn(false);
+ Monkey\Functions\expect('wp_register_script');
+ Monkey\Functions\expect('plugin_dir_url');
+ Monkey\Functions\expect('wp_enqueue_script');
+
+ $result = $this->obj->get_payment_method_script_handles();
+
+ $this->assertEquals([ 'wc-omise_atome-payments-blocks' ], $result);
+ }
+}
diff --git a/tests/unit/includes/blocks/gateways/omise-block-credit-card-test.php b/tests/unit/includes/blocks/gateways/omise-block-credit-card-test.php
new file mode 100644
index 00000000..8a9bf51f
--- /dev/null
+++ b/tests/unit/includes/blocks/gateways/omise-block-credit-card-test.php
@@ -0,0 +1,102 @@
+mockWcGateways();
+ require_once __DIR__ . '/../../../../../includes/blocks/gateways/omise-block-credit-card.php';
+ $this->omiseSettingMock = Mockery::mock('alias:Omise_Setting');
+ $this->obj = new Omise_Block_Credit_Card;
+ }
+
+ /**
+ * @test
+ */
+ public function initialize()
+ {
+ Monkey\Functions\expect('get_option')->andReturn(null);
+
+ $this->obj->initialize();
+
+ $reflection = new \ReflectionClass($this->obj);
+ $gateway_property = $reflection->getProperty('gateway');
+ $gateway_property->setAccessible(true);
+ $gateway_val = $gateway_property->getValue($this->obj);
+
+ $this->assertEquals('object', gettype($gateway_val));
+ }
+
+ /**
+ * @test
+ */
+ public function is_active()
+ {
+ Monkey\Functions\expect('wc_string_to_bool')->andReturn(true);
+ $this->obj->initialize();
+
+ $is_active = $this->obj->is_active();
+ $this->assertTrue($is_active);
+ }
+
+ /**
+ * @test
+ */
+ public function get_payment_method_data()
+ {
+ // Calling initialize() to set $gateway value
+ $reflection = new \ReflectionClass($this->obj);
+ $name_property = $reflection->getProperty('name');
+ $name_property->setAccessible(true);
+ $name_property->setValue($this->obj, 'omise');
+
+ Monkey\Functions\expect('wc_string_to_bool');
+ Monkey\Functions\expect('get_locale')->andReturn('thb');
+
+ $this->omiseSettingMock->shouldReceive('instance')->andReturn($this->omiseSettingMock);
+ $this->omiseSettingMock->shouldReceive('public_key')->andReturn('pkey_xxx');
+
+ $this->obj->initialize();
+
+ $data = $this->obj->get_payment_method_data();
+
+ $this->assertArrayHasKey('title', $data);
+ $this->assertArrayHasKey('description', $data);
+ $this->assertArrayHasKey('features', $data);
+ $this->assertEquals('array', gettype($data['features']));
+ $this->assertEquals('omise', $data['name']);
+ }
+
+ /**
+ * @test
+ */
+ public function get_payment_method_script_handles()
+ {
+ Monkey\Functions\expect('wp_script_is');
+ Monkey\Functions\expect('wp_register_script');
+ Monkey\Functions\expect('plugin_dir_url');
+ Monkey\Functions\expect('is_checkout')->andReturn(true);
+ Monkey\Functions\expect('wc_string_to_bool')->andReturn(null);
+
+ $this->obj->initialize();
+
+ $result = $this->obj->get_payment_method_script_handles();
+
+ $this->assertEquals([ 'omise-payments-blocks' ], $result);
+ }
+}
diff --git a/tests/unit/includes/blocks/gateways/omise-block-duitnow-obw-test.php b/tests/unit/includes/blocks/gateways/omise-block-duitnow-obw-test.php
new file mode 100644
index 00000000..097778b4
--- /dev/null
+++ b/tests/unit/includes/blocks/gateways/omise-block-duitnow-obw-test.php
@@ -0,0 +1,36 @@
+mockWcGateways();
+ require_once __DIR__ . '/../../../../../includes/blocks/gateways/abstract-omise-block-payment.php';
+ require_once __DIR__ . '/../../../../../includes/blocks/gateways/omise-block-duitnow-obw.php';
+ }
+
+ /**
+ * @test
+ */
+ public function set_additional_data()
+ {
+ Monkey\Functions\expect('get_option')->andReturn(null);
+ $obj = new Omise_Block_DuitNow_OBW;
+ $obj->initialize();
+ $obj->set_additional_data();
+
+ $clazz = new \ReflectionClass($obj);
+ $property = $clazz->getProperty('additional_data');
+ $property->setAccessible(true);
+ $result = $property->getValue($obj);
+
+ $this->assertIsArray($result);
+ $this->assertArrayHasKey('banks', $result);
+ }
+}
diff --git a/tests/unit/includes/blocks/gateways/omise-block-fpx-test.php b/tests/unit/includes/blocks/gateways/omise-block-fpx-test.php
new file mode 100644
index 00000000..f9098f6c
--- /dev/null
+++ b/tests/unit/includes/blocks/gateways/omise-block-fpx-test.php
@@ -0,0 +1,36 @@
+mockWcGateways();
+ require_once __DIR__ . '/../../../../../includes/blocks/gateways/abstract-omise-block-payment.php';
+ require_once __DIR__ . '/../../../../../includes/blocks/gateways/omise-block-fpx.php';
+ }
+
+ /**
+ * @test
+ */
+ public function set_additional_data()
+ {
+ Monkey\Functions\expect('get_option')->andReturn(null);
+ $obj = new Omise_Block_Fpx;
+ $obj->initialize();
+ $obj->set_additional_data();
+
+ $clazz = new \ReflectionClass($obj);
+ $property = $clazz->getProperty('additional_data');
+ $property->setAccessible(true);
+ $result = $property->getValue($obj);
+
+ $this->assertIsArray($result);
+ $this->assertArrayHasKey('bank_list', $result);
+ }
+}
\ No newline at end of file
diff --git a/tests/unit/includes/blocks/gateways/omise-block-installment-test.php b/tests/unit/includes/blocks/gateways/omise-block-installment-test.php
new file mode 100644
index 00000000..471ed4f4
--- /dev/null
+++ b/tests/unit/includes/blocks/gateways/omise-block-installment-test.php
@@ -0,0 +1,43 @@
+mockWcGateways();
+ require_once __DIR__ . '/../../../../../includes/blocks/gateways/abstract-omise-block-payment.php';
+ require_once __DIR__ . '/../../../../../includes/blocks/gateways/omise-block-installment.php';
+ $this->obj = new Omise_Block_Installment;
+ }
+
+ /**
+ * @test
+ */
+ public function set_additional_data()
+ {
+ Monkey\Functions\expect('get_option')->andReturn(null);
+ $this->obj->initialize();
+ $this->obj->set_additional_data();
+
+ $clazz = new \ReflectionClass($this->obj);
+ $property = $clazz->getProperty('additional_data');
+ $property->setAccessible(true);
+ $result = $property->getValue($this->obj);
+
+ $this->assertIsArray($result);
+ $this->assertArrayHasKey('is_zero_interest', $result);
+ $this->assertArrayHasKey('installment_min_limit', $result);
+ $this->assertArrayHasKey('installment_backends', $result);
+ }
+}
diff --git a/tests/unit/includes/blocks/gateways/omise-block-mobilebanking-test.php b/tests/unit/includes/blocks/gateways/omise-block-mobilebanking-test.php
new file mode 100644
index 00000000..81ebaf3f
--- /dev/null
+++ b/tests/unit/includes/blocks/gateways/omise-block-mobilebanking-test.php
@@ -0,0 +1,93 @@
+mockWcGateways();
+ require_once __DIR__ . '/../../../../../includes/blocks/gateways/omise-block-mobilebanking.php';
+ $this->obj = new Omise_Block_Mobile_Banking;
+ }
+
+ /**
+ * @test
+ */
+ public function initialize()
+ {
+ Monkey\Functions\expect('get_option')->andReturn(null);
+
+ $this->obj->initialize();
+
+ $reflection = new \ReflectionClass($this->obj);
+ $gateway_property = $reflection->getProperty('gateway');
+ $gateway_property->setAccessible(true);
+ $gateway_val = $gateway_property->getValue($this->obj);
+
+ $this->assertEquals('object', gettype($gateway_val));
+ }
+
+ /**
+ * @test
+ */
+ public function is_active()
+ {
+ $this->obj->initialize();
+
+ $is_active = $this->obj->is_active();
+ $this->assertTrue($is_active);
+ }
+
+ /**
+ * @test
+ */
+ public function get_payment_method_data()
+ {
+ // Calling initialize() to set $gateway value
+ $reflection = new \ReflectionClass($this->obj);
+ $name_property = $reflection->getProperty('name');
+ $name_property->setAccessible(true);
+ $name_property->setValue($this->obj, 'omise_mobilebanking');
+
+ Monkey\Functions\expect('get_woocommerce_currency')->andReturn('thb');
+
+ $this->obj->initialize();
+
+ $data = $this->obj->get_payment_method_data();
+
+ $this->assertArrayHasKey('title', $data);
+ $this->assertArrayHasKey('description', $data);
+ $this->assertArrayHasKey('supports', $data);
+ $this->assertEquals('array', gettype($data['supports']));
+ $this->assertEquals('omise_mobilebanking', $data['name']);
+ }
+
+ /**
+ * @test
+ */
+ public function get_payment_method_script_handles()
+ {
+ Monkey\Functions\expect('wp_script_is')->andReturn(false);
+ Monkey\Functions\expect('wp_register_script');
+ Monkey\Functions\expect('plugin_dir_url');
+ Monkey\Functions\expect('wp_enqueue_script');
+
+ $this->obj->initialize();
+
+ $result = $this->obj->get_payment_method_script_handles();
+
+ $this->assertEquals([ 'wc-omise-mobilebanking-payments-blocks' ], $result);
+ }
+}
diff --git a/tests/unit/includes/blocks/gateways/traits/mock-gateways.php b/tests/unit/includes/blocks/gateways/traits/mock-gateways.php
new file mode 100644
index 00000000..92793f71
--- /dev/null
+++ b/tests/unit/includes/blocks/gateways/traits/mock-gateways.php
@@ -0,0 +1,81 @@
+ '1.1.0',
+ 'payment_gateways' => new class {
+ function payment_gateways() {
+ // dummy gateway
+ $gateway = new class {
+ public $supports = ['products'];
+
+ public $backend;
+
+ public function is_available() {
+ return true;
+ }
+
+ public function supports() {
+ return $this->supports;
+ }
+
+ public function get_option() {
+ return false;
+ }
+
+ public function is_test() {
+ return true;
+ }
+
+ public function get_existing_cards() {
+ return ['user_logged_in' => false];
+ }
+
+ public function get_secure_form_config() {
+ return ['secure_form_enabled' => false];
+ }
+
+ public function get_view_data() {
+ return [
+ 'installment_backends' => [],
+ 'is_zero_interest' => true,
+ 'installment_min_limit' => 2000
+ ];
+ }
+ };
+
+ $gateway->backend = new class {
+ public $banks = ['bank1', 'bank2'];
+
+ public function get_available_providers($currency) {
+ return $currency;
+ }
+
+ public function get_available_banks() {
+ return ['bank1', 'bank2'];
+ }
+ };
+
+ return [
+ 'omise' => $gateway,
+ 'omise_promptpay' => $gateway,
+ 'omise_atome' => $gateway,
+ 'omise_mobilebanking' => $gateway,
+ 'omise_installment' => $gateway,
+ 'omise_fpx' => $gateway,
+ 'omise_duitnow_obw' => $gateway,
+ ];
+ }
+ }
+ ];
+
+ Monkey\Functions\expect('WC')->andReturn($wc);
+ }
+}
\ No newline at end of file
diff --git a/tests/unit/includes/blocks/omise-block-config-test.php b/tests/unit/includes/blocks/omise-block-config-test.php
new file mode 100644
index 00000000..fd0c865d
--- /dev/null
+++ b/tests/unit/includes/blocks/omise-block-config-test.php
@@ -0,0 +1,25 @@
+expectNotToPerformAssertions();
+ $container = \Automattic\WooCommerce\Blocks\Package::container();
+ Monkey\Functions\expect('add_action')->andReturn(null);
+ new Omise_Block_Config($container);
+ }
+}
\ No newline at end of file
diff --git a/tests/unit/includes/blocks/omise-block-payments-test.php b/tests/unit/includes/blocks/omise-block-payments-test.php
new file mode 100644
index 00000000..2e1deb53
--- /dev/null
+++ b/tests/unit/includes/blocks/omise-block-payments-test.php
@@ -0,0 +1,45 @@
+expectNotToPerformAssertions();
+ $container = \Automattic\WooCommerce\Blocks\Package::container();
+
+ Monkey\Functions\expect('add_action')->andReturn(null);
+
+ $obj = new Omise_Block_Payments($container);
+
+ $reflection = new \ReflectionClass($obj);
+ $property = $reflection->getProperty('payment_methods');
+ $payment_methods = $property->getValue($obj);
+
+ $mock = new class {
+ public function register($class) { }
+ };
+
+ foreach($payment_methods as $payment_method) {
+ $this->getMockBuilder($payment_method)
+ ->disableOriginalConstructor()
+ ->getMock();
+ }
+
+ $obj->register_payment_methods($mock);
+ }
+}
diff --git a/tests/unit/includes/blocks/omise-block-test.php b/tests/unit/includes/blocks/omise-block-test.php
new file mode 100644
index 00000000..62a64478
--- /dev/null
+++ b/tests/unit/includes/blocks/omise-block-test.php
@@ -0,0 +1,42 @@
+obj = new Omise_Block;
+ }
+
+ /**
+ * @test
+ */
+ public function container()
+ {
+ $result = $this->obj::container();
+ $this->assertTrue(isset($result));
+ }
+
+ /**
+ *@test
+ */
+ public function is_active_returns_false()
+ {
+ $clazz = new \ReflectionClass($this->obj);
+ $property = $clazz->getMethod('is_active');
+ $property->setAccessible(true);
+ $result = $property->invoke($clazz);
+
+ $this->assertFalse($result);
+ }
+}
diff --git a/tests/unit/includes/class-omise-capabilities-test.php b/tests/unit/includes/class-omise-capabilities-test.php
index 6ea5badc..c4cc6cac 100644
--- a/tests/unit/includes/class-omise-capabilities-test.php
+++ b/tests/unit/includes/class-omise-capabilities-test.php
@@ -14,7 +14,7 @@ class Omise_Capabilities_Test extends Bootstrap_Test_Setup
/**
* setup add_action and do_action before the test run
*/
- public function setUp(): void
+ protected function setUp(): void
{
parent::setUp();
diff --git a/tests/unit/includes/class-omise-setting-test.php b/tests/unit/includes/class-omise-setting-test.php
index ef066f74..7be6b719 100644
--- a/tests/unit/includes/class-omise-setting-test.php
+++ b/tests/unit/includes/class-omise-setting-test.php
@@ -4,7 +4,7 @@
class Omise_Setting_Test extends TestCase
{
- public function setUp(): void
+ protected function setUp(): void
{
require_once __DIR__ . '/../../../includes/class-omise-setting.php';
}
diff --git a/tests/unit/includes/gateway/abstract-omise-payment-base-card-test.php b/tests/unit/includes/gateway/abstract-omise-payment-base-card-test.php
index cff4a717..fb965455 100644
--- a/tests/unit/includes/gateway/abstract-omise-payment-base-card-test.php
+++ b/tests/unit/includes/gateway/abstract-omise-payment-base-card-test.php
@@ -6,7 +6,7 @@ class Omise_Payment_Base_Card_Test extends TestCase
{
public $obj;
- public function setUp(): void
+ protected function setUp(): void
{
$omisePaymentMock = Mockery::mock('overload:Omise_Payment');
$omisePaymentMock->shouldReceive('is_test')
@@ -45,9 +45,10 @@ public function returnThis()
/**
* close mockery after tests are done
*/
- public function tearDown(): void
+ protected function tearDown(): void
{
Mockery::close();
+ parent::tearDown();
}
public function getOrderMock($expectedAmount, $expectedCurrency)
diff --git a/tests/unit/includes/gateway/abstract-omise-payment-offline-test.php b/tests/unit/includes/gateway/abstract-omise-payment-offline-test.php
index c2a7355e..64db2275 100644
--- a/tests/unit/includes/gateway/abstract-omise-payment-offline-test.php
+++ b/tests/unit/includes/gateway/abstract-omise-payment-offline-test.php
@@ -4,7 +4,7 @@
abstract class Omise_Payment_Offline_Test extends Bootstrap_Test_Setup
{
- public function setUp(): void
+ protected function setUp(): void
{
parent::setUp();
Mockery::mock('alias:Omise_Payment')->makePartial();
diff --git a/tests/unit/includes/gateway/bootstrap-test-setup.php b/tests/unit/includes/gateway/bootstrap-test-setup.php
index 6bdec48f..65f3e312 100644
--- a/tests/unit/includes/gateway/bootstrap-test-setup.php
+++ b/tests/unit/includes/gateway/bootstrap-test-setup.php
@@ -1,27 +1,31 @@
null,
- 'add_action' => null,
- ] );
+ parent::setUp();
+ Monkey\setUp();
}
/**
* close mockery after tests are done
*/
- public function tearDown(): void
+ protected function tearDown(): void
{
- Brain\Monkey\tearDown();
+ Monkey\tearDown();
Mockery::close();
+ parent::tearDown();
}
public function getOrderMock($expectedAmount, $expectedCurrency)
diff --git a/tests/unit/includes/gateway/class-omise-offsite-test.php b/tests/unit/includes/gateway/class-omise-offsite-test.php
index f6918934..a40c50cc 100644
--- a/tests/unit/includes/gateway/class-omise-offsite-test.php
+++ b/tests/unit/includes/gateway/class-omise-offsite-test.php
@@ -6,7 +6,7 @@ abstract class Omise_Offsite_Test extends Bootstrap_Test_Setup
{
public $sourceType;
- public function setUp(): void
+ protected function setUp(): void
{
parent::setUp();
@@ -19,9 +19,6 @@ public function setUp(): void
->andReturn([
'source' => [ 'type' => $this->sourceType ]
]);
-
- // destroy object and clear memory
- unset($offsite);
}
public function getChargeTest($classObj)
diff --git a/tests/unit/includes/gateway/class-omise-payment-alipayplus-hk-test.php b/tests/unit/includes/gateway/class-omise-payment-alipayplus-hk-test.php
index b65a5538..bb3b9fe9 100644
--- a/tests/unit/includes/gateway/class-omise-payment-alipayplus-hk-test.php
+++ b/tests/unit/includes/gateway/class-omise-payment-alipayplus-hk-test.php
@@ -1,5 +1,7 @@
sourceType = 'alipay_hk';
parent::setUp();
+
+ Monkey\Functions\expect('wp_kses');
+ Monkey\Functions\expect('wc_get_user_agent')->andReturn('Chrome Web');
+
require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-alipayplus.php';
if (!function_exists('wc_get_user_agent')) {
diff --git a/tests/unit/includes/gateway/class-omise-payment-alipayplus-kakaopay-test.php b/tests/unit/includes/gateway/class-omise-payment-alipayplus-kakaopay-test.php
index f9de6a00..31583132 100644
--- a/tests/unit/includes/gateway/class-omise-payment-alipayplus-kakaopay-test.php
+++ b/tests/unit/includes/gateway/class-omise-payment-alipayplus-kakaopay-test.php
@@ -1,5 +1,7 @@
sourceType = 'kakaopay';
parent::setUp();
+ Monkey\Functions\expect('wp_kses');
require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-alipayplus.php';
}
diff --git a/tests/unit/includes/gateway/class-omise-payment-atome-test.php b/tests/unit/includes/gateway/class-omise-payment-atome-test.php
index 497313a1..756b8ed0 100644
--- a/tests/unit/includes/gateway/class-omise-payment-atome-test.php
+++ b/tests/unit/includes/gateway/class-omise-payment-atome-test.php
@@ -2,21 +2,19 @@
require_once __DIR__ . '/class-omise-offsite-test.php';
+use Brain\Monkey;
+
class Omise_Payment_Atome_Test extends Omise_Offsite_Test
{
- public function setUp(): void
+ protected function setUp(): void
{
$this->sourceType = 'atome';
parent::setUp();
require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-atome.php';
- if (!function_exists('wp_enqueue_script')) {
- function wp_enqueue_script() {}
- }
-
- if (!function_exists('plugins_url')) {
- function plugins_url() {}
- }
+ Monkey\Functions\expect('wp_enqueue_script');
+ Monkey\Functions\expect('wp_kses');
+ Monkey\Functions\expect('plugins_url');
// dummy version
if (!defined('WC_VERSION')) {
@@ -42,13 +40,11 @@ public function testGetChargeRequest()
$result = $obj->get_charge_request($orderId, $orderMock);
$this->assertEquals($this->sourceType, $result['source']['type']);
-
- unset($_POST['source']);
- unset($obj);
}
public function testCharge()
{
+ Monkey\Functions\expect('add_action');
$_POST['omise_atome_phone_default'] = true;
$obj = new Omise_Payment_Atome();
$this->getChargeTest($obj);
diff --git a/tests/unit/includes/gateway/class-omise-payment-creditcard-test.php b/tests/unit/includes/gateway/class-omise-payment-creditcard-test.php
index 7067008c..25ddb0d4 100644
--- a/tests/unit/includes/gateway/class-omise-payment-creditcard-test.php
+++ b/tests/unit/includes/gateway/class-omise-payment-creditcard-test.php
@@ -1,17 +1,21 @@
shouldReceive('init_settings');
- $omisePaymentMock->shouldReceive('get_option');
- $omisePaymentMock->shouldReceive('is_test')
+ $this->omisePaymentMock = Mockery::mock('overload:Omise_Payment');
+ $this->omisePaymentMock->shouldReceive('init_settings');
+ $this->omisePaymentMock->shouldReceive('get_option')
+ ->andReturn(true);
+ $this->omisePaymentMock->shouldReceive('is_test')
->andReturn(true);
$omiseCardImage = Mockery::mock('alias:Omise_Card_Image');
@@ -29,36 +33,99 @@ public function setUp(): void
$omiseCardImage->shouldReceive('get_discover_image')->once();
$omiseCardImage->shouldReceive('get_discover_default_display')->once();
+ // dummy version
+ if (!defined('WC_VERSION')) {
+ define('WC_VERSION', '1.0.0');
+ }
+
+ Monkey\Functions\expect('add_action')->andReturn(null);
+ Monkey\Functions\expect('wp_enqueue_script');
+ Monkey\Functions\expect('wp_kses')
+ ->times(3)
+ ->andReturn(
+ 'Accept payment through Credit / Debit Card via Opn Payments.',
+ 'This only controls the icons displayed on the checkout page.
It is not related to card processing on Opn Payments.'
+ );
+
require_once __DIR__ . '/../../../../includes/gateway/traits/charge-request-builder-trait.php';
require_once __DIR__ . '/../../../../includes/gateway/abstract-omise-payment-base-card.php';
require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-creditcard.php';
}
- public function tearDown(): void
+ protected function tearDown(): void
{
- Brain\Monkey\tearDown();
+ Monkey\tearDown();
Mockery::close();
+ parent::tearDown();
}
/**
* @test
*/
- public function testClassIsInitializedProperly()
+ public function test_class_is_initialized_properly()
{
- Brain\Monkey\Functions\stubs( [
- 'wp_kses' => null,
- ] );
+ Monkey\Functions\expect('plugins_url');
+
$creditCard = new Omise_Payment_Creditcard;
- $this->assertEquals($creditCard->source_type, 'credit_card');
+ $this->assertEquals('credit_card', $creditCard->source_type);
$this->assertEquals(
+ 'Accept payment through Credit / Debit Card via Opn Payments.',
$creditCard->method_description,
- 'Accept payment through Credit / Debit Card via Opn Payments.'
);
$this->assertEquals(
+ 'This only controls the icons displayed on the checkout page.
It is not related to card processing on Opn Payments.',
$creditCard->form_fields['accept_amex']['description'],
- 'This only controls the icons displayed on the checkout page.
It is not related to card processing on Opn Payments.'
);
}
+
+ /**
+ * @test
+ */
+ public function get_secure_form_config() {
+ $cardFormCustomization = Mockery::mock('alias:Omise_Page_Card_From_Customization');
+ $cardFormCustomization->shouldReceive('get_instance')->andReturn($cardFormCustomization);
+ $cardFormCustomization->shouldReceive('get_design_setting')->andReturn(['abc' => ['xyz']]);
+
+ Monkey\Functions\expect('plugins_url');
+
+ $creditCard = new Omise_Payment_Creditcard;
+
+ $config = $creditCard->get_secure_form_config();
+
+ $this->assertArrayHasKey('secure_form_enabled', $config);
+ $this->assertArrayHasKey('card_form_theme', $config);
+ $this->assertArrayHasKey('card_icons', $config);
+ $this->assertArrayHasKey('form_design', $config);
+ }
+
+ /**
+ * @test
+ */
+ public function get_existing_cards_for_user_logged_in() {
+ Monkey\Functions\expect('is_user_logged_in')->andReturn(true);
+ Monkey\Functions\expect('wp_get_current_user')->andReturn((object)['test_omise_customer_id' => 1]);
+ Monkey\Functions\expect('plugins_url');
+
+ $customerCard = Mockery::mock('alias:OmiseCustomerCard');
+ $customerCard->shouldReceive('get')->andReturn(1);
+
+ $creditCard = new Omise_Payment_Creditcard;
+
+ $data = $creditCard->get_existing_cards();
+
+ $this->assertIsArray($data);
+ $this->assertArrayHasKey('user_logged_in', $data);
+ }
+
+ public function get_existing_cards_for_user_not_logged_in() {
+ Monkey\Functions\expect('is_user_logged_in')->andReturn(false);
+
+ $creditCard = new Omise_Payment_Creditcard;
+ $data = $creditCard->get_existing_cards();
+
+ $this->assertIsArray($data);
+ $this->assertArrayHasKey('user_logged_in', $data);
+ }
}
diff --git a/tests/unit/includes/gateway/class-omise-payment-duitnow-obw-test.php b/tests/unit/includes/gateway/class-omise-payment-duitnow-obw-test.php
index 34196abf..29019ac0 100644
--- a/tests/unit/includes/gateway/class-omise-payment-duitnow-obw-test.php
+++ b/tests/unit/includes/gateway/class-omise-payment-duitnow-obw-test.php
@@ -1,17 +1,20 @@
sourceType = 'duitnow_obw';
parent::setUp();
- require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-duitnow-obw.php';
+ Monkey\Functions\expect('add_action');
$this->omise_capability_mock = Mockery::mock('alias:Omise_Capabilities');
+ require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-duitnow-obw.php';
}
public function testCharge()
@@ -23,7 +26,6 @@ function sanitize_text_field() {
}
$this->omise_capability_mock->shouldReceive('retrieve')->once();
-
$_POST['source'] = ['bank' => 'SCB'];
$obj = new Omise_Payment_DuitNow_OBW();
$this->getChargeTest($obj);
diff --git a/tests/unit/includes/gateway/class-omise-payment-fpx-test.php b/tests/unit/includes/gateway/class-omise-payment-fpx-test.php
index 71bc2e8f..c6b8d229 100644
--- a/tests/unit/includes/gateway/class-omise-payment-fpx-test.php
+++ b/tests/unit/includes/gateway/class-omise-payment-fpx-test.php
@@ -1,13 +1,16 @@
sourceType = 'fpx';
parent::setUp();
+ Monkey\Functions\expect('add_action');
require_once __DIR__ . '/../../../../includes/backends/class-omise-backend-fpx.php';
require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-fpx.php';
}
diff --git a/tests/unit/includes/gateway/class-omise-payment-googlepay-test.php b/tests/unit/includes/gateway/class-omise-payment-googlepay-test.php
new file mode 100644
index 00000000..3476b4e7
--- /dev/null
+++ b/tests/unit/includes/gateway/class-omise-payment-googlepay-test.php
@@ -0,0 +1,159 @@
+andReturn(null);
+ Monkey\Functions\expect('wp_kses')->andReturn(null);
+ Monkey\Functions\expect('wp_enqueue_script');
+ Monkey\Functions\expect('plugins_url')->andReturn('');
+ Monkey\Functions\expect('get_woocommerce_currency')->andReturn('thb');
+
+ // dummy version
+ if (!defined('WC_VERSION')) {
+ define('WC_VERSION', '1.0.0');
+ }
+
+ $omisePaymentMock = Mockery::mock('overload:Omise_Payment');
+ $omisePaymentMock->shouldReceive('init_settings');
+ $omisePaymentMock->shouldReceive('get_option');
+ $omisePaymentMock->shouldReceive('is_test')
+ ->andReturn(true);
+ $omisePaymentMock->shouldReceive('public_key')
+ ->andReturn('pkey_123');
+
+ $omiseCardImage = Mockery::mock('alias:Omise_Card_Image');
+ $omiseCardImage->shouldReceive('get_css')->times(4);
+ $omiseCardImage->shouldReceive('get_visa_image')->once();
+ $omiseCardImage->shouldReceive('get_visa_default_display')->once();
+ $omiseCardImage->shouldReceive('get_mastercard_image')->once();
+ $omiseCardImage->shouldReceive('get_mastercard_default_display')->once();
+ $omiseCardImage->shouldReceive('get_jcb_image')->once();
+ $omiseCardImage->shouldReceive('get_jcb_default_display')->once();
+ $omiseCardImage->shouldReceive('get_amex_image')->once();
+ $omiseCardImage->shouldReceive('get_amex_default_display')->once();
+
+ require_once __DIR__ . '/../../../../includes/gateway/traits/charge-request-builder-trait.php';
+ require_once __DIR__ . '/../../../../includes/gateway/abstract-omise-payment-base-card.php';
+ require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-googlepay.php';
+ }
+
+ protected function tearDown(): void
+ {
+ Monkey\tearDown();
+ Mockery::close();
+ parent::tearDown();
+ }
+
+ /**
+ * @test
+ */
+ public function init_googlepay_config()
+ {
+ $expected = [
+ 'environment' => 'TEST',
+ 'api_version' => 2,
+ 'api_version_minor' => 0,
+ 'allowed_auth_methods' => ['PAN_ONLY'],
+ 'allowed_card_networks' => [],
+ 'billing_address_required' => false,
+ 'phone_number_required' => false,
+ 'public_key' => 'pkey_123',
+ 'merchant_id' => null,
+ 'price_status' => 'NOT_CURRENTLY_KNOWN',
+ 'currency' => 'thb',
+ ];
+
+ $googlepay = new Omise_Payment_GooglePay;
+
+ $reflection = new \ReflectionClass($googlepay);
+ $config = $reflection->getMethod('init_googlepay_config');
+ $config->setAccessible(true);
+ $config->invoke($googlepay);
+
+ $result = $googlepay->googlepay_config;
+
+ $this->assertEquals($expected, $result);
+ }
+
+ /**
+ * @test
+ */
+ public function google_pay_button_scripts()
+ {
+ $googlepay = new Omise_Payment_GooglePay;
+
+ $reflection = new \ReflectionClass($googlepay);
+ $config = $reflection->getMethod('google_pay_button_scripts');
+ $config->setAccessible(true);
+ $result = $config->invoke($googlepay);
+
+ $expected = [
+ 'script' => ""
+ ];
+
+ $this->assertEquals($expected, $result);
+ }
+}
\ No newline at end of file
diff --git a/tests/unit/includes/gateway/class-omise-payment-installment-test.php b/tests/unit/includes/gateway/class-omise-payment-installment-test.php
index 329b86bb..fc437799 100644
--- a/tests/unit/includes/gateway/class-omise-payment-installment-test.php
+++ b/tests/unit/includes/gateway/class-omise-payment-installment-test.php
@@ -2,25 +2,39 @@
require_once __DIR__ . '/class-omise-offsite-test.php';
+use Brain\Monkey;
+
+/**
+ * @runInSeparateProcess
+ * @preserveGlobalState disabled
+ */
+
class Omise_Payment_Installment_Test extends Omise_Offsite_Test
{
- public function setUp(): void
+ protected $backend_installment_mock;
+
+ protected function setUp(): void
{
$this->sourceType = 'installment_ktc';
parent::setUp();
+
+ Monkey\Functions\expect('wp_kses');
+ Omise_Unit_Test::include_class('backends/class-omise-backend.php');
+ Omise_Unit_Test::include_class('backends/class-omise-backend-installment.php');
+
+ $this->backend_installment_mock = Mockery::mock('Omise_Backend_Installment');
require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-installment.php';
+ }
- if (!function_exists('sanitize_text_field')) {
- function sanitize_text_field() {
- return 'Sanitized text';
- }
- }
+ protected function tearDown(): void
+ {
+ parent::tearDown();
}
/**
* @test
*/
- public function getTotalAmountFromAdminOrderpage()
+ public function get_total_amount_from_admin_order_page()
{
// mocking built-in WooCommerce function
if (!function_exists('wc_get_order')) {
@@ -34,6 +48,9 @@ public function get_total() {
}
}
+ Monkey\Functions\expect('add_action');
+
+
// mocking the WP global variable $wp
$wp = new stdClass();
$wp->query_vars = ['order-pay' => 123];
@@ -43,26 +60,20 @@ public function get_total() {
$total = $installment->get_total_amount();
$this->assertEquals($total, 999999);
-
- unset($GLOBALS['wp']);
- unset($installment);
- unset($wp);
}
/**
* @test
*/
- public function getTotalAmountFromCart()
+ public function get_total_amount_from_cart()
{
- // mocking WC() method
- if (!function_exists('WC')) {
- function WC() {
- $class = new stdClass();
- $class->cart = new stdClass();
- $class->cart->total = 999999;
- return $class;
- }
- }
+ Monkey\Functions\expect('add_action');
+
+ $clazz = new stdClass();
+ $clazz->cart = new stdClass();
+ $clazz->cart->total = 999999;
+
+ Monkey\Functions\expect('WC')->andReturn($clazz);
$installment = new Omise_Payment_Installment();
$total = $installment->get_total_amount();
@@ -70,8 +81,12 @@ function WC() {
$this->assertEquals($total, 999999);
}
- public function testGetChargeRequest()
+ public function test_get_charge_request()
{
+ $this->backend_installment_mock->shouldReceive('get_provider');
+
+ Monkey\Functions\expect('add_action');
+
$expectedAmount = 999999;
$expectedCurrency = 'thb';
$orderId = 'order_123';
@@ -86,12 +101,52 @@ public function testGetChargeRequest()
$this->assertEquals($this->sourceType, $result['source']['type']);
}
- public function testCharge()
+ public function test_charge()
{
+ $this->backend_installment_mock->shouldReceive('get_provider');
+
+ Monkey\Functions\expect('add_action');
+
$_POST['source'] = ['type' => $this->sourceType];
$_POST[$this->sourceType . '_installment_terms'] = 3;
$obj = new Omise_Payment_Installment();
$this->getChargeTest($obj);
}
+
+ public function test_get_view_data()
+ {
+ $capability = Mockery::mock('alias:Omise_Capabilities');
+ $capability->shouldReceive('retrieve')
+ ->andReturn(new class {
+ public function getInstallmentMinLimit() {
+ return 2000;
+ }
+
+ public function is_zero_interest() {
+ return true;
+ }
+
+ public function getInstallmentBackends() {
+ return [];
+ }
+ });
+
+ $this->backend_installment_mock->shouldReceive('get_available_providers');
+ Monkey\Functions\expect('get_woocommerce_currency')->andReturn('thb');
+
+ $clazz = new stdClass();
+ $clazz->cart = new stdClass();
+ $clazz->cart->total = 999999;
+
+ Monkey\Functions\expect('WC')->andReturn($clazz);
+ Monkey\Functions\expect('add_action');
+
+ $obj = new Omise_Payment_Installment();
+ $result = $obj->get_view_data();
+
+ $this->assertArrayHasKey('installment_backends', $result);
+ $this->assertArrayHasKey('is_zero_interest', $result);
+ $this->assertArrayHasKey('installment_min_limit', $result);
+ }
}
diff --git a/tests/unit/includes/gateway/class-omise-payment-internetbanking-test.php b/tests/unit/includes/gateway/class-omise-payment-internetbanking-test.php
index 37e44b68..4196e2db 100644
--- a/tests/unit/includes/gateway/class-omise-payment-internetbanking-test.php
+++ b/tests/unit/includes/gateway/class-omise-payment-internetbanking-test.php
@@ -1,13 +1,17 @@
sourceType = 'fpx';
parent::setUp();
+ Monkey\Functions\expect('wp_kses');
+ Monkey\Functions\expect('add_action');
require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-internetbanking.php';
}
diff --git a/tests/unit/includes/gateway/class-omise-payment-konbini-test.php b/tests/unit/includes/gateway/class-omise-payment-konbini-test.php
index a29dcf4f..a6e0ef8a 100644
--- a/tests/unit/includes/gateway/class-omise-payment-konbini-test.php
+++ b/tests/unit/includes/gateway/class-omise-payment-konbini-test.php
@@ -1,13 +1,18 @@
shouldReceive('init_settings');
@@ -21,12 +26,6 @@ public function setUp(): void
]);
require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-konbini.php';
-
- if (!function_exists('sanitize_text_field')) {
- function sanitize_text_field() {
- return 'Sanitized text';
- }
- }
}
public function testGetChargeRequest()
diff --git a/tests/unit/includes/gateway/class-omise-payment-mobilebanking-test.php b/tests/unit/includes/gateway/class-omise-payment-mobilebanking-test.php
index cad1e084..e87f9e3a 100644
--- a/tests/unit/includes/gateway/class-omise-payment-mobilebanking-test.php
+++ b/tests/unit/includes/gateway/class-omise-payment-mobilebanking-test.php
@@ -1,10 +1,12 @@
with('123')
->andReturn('Chrome Web');
+ Monkey\Functions\expect('wp_kses');
+ Monkey\Functions\expect('add_action');
$_POST['omise-offsite'] = 'mobile_banking_bbl';
$obj = new Omise_Payment_Mobilebanking();
$this->getChargeTest($obj);
diff --git a/tests/unit/includes/gateway/class-omise-payment-ocbc-digital-test.php b/tests/unit/includes/gateway/class-omise-payment-ocbc-digital-test.php
index 14987bc8..0e1c85f6 100644
--- a/tests/unit/includes/gateway/class-omise-payment-ocbc-digital-test.php
+++ b/tests/unit/includes/gateway/class-omise-payment-ocbc-digital-test.php
@@ -1,32 +1,20 @@
sourceType = 'mobile_banking_ocbc';
parent::setUp();
+ Monkey\Functions\expect('add_action');
require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-ocbc-digital.php';
require_once __DIR__ . '/../../../../includes/classes/class-omise-image.php';
$this->obj = new Omise_Payment_OCBC_Digital();
-
- // mocking WP built-in functions
- if (!function_exists('plugins_url')) {
- function plugins_url() {
- return "http://localhost";
- }
- }
- }
-
- public function tearDown(): void
- {
- parent::tearDown();
- // destroy object and clear memory
- unset($this->obj);
}
/**
@@ -67,6 +55,7 @@ public function supportsIsCorrect()
*/
public function getIconReturnsCorrectImageLink()
{
+ Monkey\Functions\expect('plugins_url');
$result = $this->obj->get_icon();
$this->assertEquals(
"",
diff --git a/tests/unit/includes/gateway/class-omise-payment-ocbc-pao-test.php b/tests/unit/includes/gateway/class-omise-payment-ocbc-pao-test.php
index 5d1f6de2..d3a78890 100644
--- a/tests/unit/includes/gateway/class-omise-payment-ocbc-pao-test.php
+++ b/tests/unit/includes/gateway/class-omise-payment-ocbc-pao-test.php
@@ -1,32 +1,28 @@
sourceType = 'mobile_banking_ocbc';
parent::setUp();
+ Monkey\Functions\expect('add_action');
require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-ocbc-pao.php';
$this->obj = new Omise_Payment_OCBC_PAO();
}
- public function tearDown(): void
- {
- parent::tearDown();
- // destroy object and clear memory
- unset($this->obj);
- }
-
/**
* @test
*/
public function testCharge()
{
- Brain\Monkey\Functions\expect('wc_get_user_agent')
+ Monkey\Functions\expect('wc_get_user_agent')
->with('123')
->andReturn('Chrome Web');
$this->getChargeTest($this->obj);
diff --git a/tests/unit/includes/gateway/class-omise-payment-promptpay-test.php b/tests/unit/includes/gateway/class-omise-payment-promptpay-test.php
index a053b9a8..d3dfd115 100644
--- a/tests/unit/includes/gateway/class-omise-payment-promptpay-test.php
+++ b/tests/unit/includes/gateway/class-omise-payment-promptpay-test.php
@@ -1,5 +1,7 @@
mockFileGetContent->shouldReceive('get_contents')->once()->andReturn('');
diff --git a/tests/unit/includes/gateway/class-omise-payment-rabbit-linepay-test.php b/tests/unit/includes/gateway/class-omise-payment-rabbit-linepay-test.php
index 6594cea1..16fbcbbf 100644
--- a/tests/unit/includes/gateway/class-omise-payment-rabbit-linepay-test.php
+++ b/tests/unit/includes/gateway/class-omise-payment-rabbit-linepay-test.php
@@ -1,26 +1,22 @@
sourceType = 'mobile_banking_ocbc';
parent::setUp();
+ Monkey\Functions\expect('add_action');
require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-rabbit-linepay.php';
$this->obj = new Omise_Payment_RabbitLinePay();
}
- public function tearDown(): void
- {
- parent::tearDown();
- // destroy object and clear memory
- unset($this->obj);
- }
-
/**
* @test
*/
diff --git a/tests/unit/includes/gateway/class-omise-payment-touch-n-go-test.php b/tests/unit/includes/gateway/class-omise-payment-touch-n-go-test.php
index 15f459d4..9683a57b 100644
--- a/tests/unit/includes/gateway/class-omise-payment-touch-n-go-test.php
+++ b/tests/unit/includes/gateway/class-omise-payment-touch-n-go-test.php
@@ -1,10 +1,12 @@
sourceType = 'touch_n_go';
parent::setUp();
@@ -16,6 +18,7 @@ public function setUp(): void
*/
public function restrictedCountriesHasRequiredCountries()
{
+ Monkey\Functions\expect('add_action');
$obj = new Omise_Payment_TouchNGo();
$expectedCountries = ['SG', 'MY', 'TH'];
diff --git a/tests/unit/includes/gateway/class-omise-payment-truemoney-test.php b/tests/unit/includes/gateway/class-omise-payment-truemoney-test.php
index 258567f5..943676cd 100644
--- a/tests/unit/includes/gateway/class-omise-payment-truemoney-test.php
+++ b/tests/unit/includes/gateway/class-omise-payment-truemoney-test.php
@@ -1,24 +1,28 @@
sourceType = 'truemoney';
parent::setUp();
- Brain\Monkey\Functions\expect('is_admin')
+ Monkey\Functions\expect('is_admin')
->with('123')
->andReturn(true);
- Brain\Monkey\Functions\expect('is_checkout')
+ Monkey\Functions\expect('is_checkout')
->with('123')
->andReturn(true);
- Brain\Monkey\Functions\expect('is_wc_endpoint_url')
+ Monkey\Functions\expect('is_wc_endpoint_url')
->with('123')
->andReturn(true);
+ Monkey\Functions\expect('wp_kses');
+ Monkey\Functions\expect('add_action');
require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-truemoney.php';
$this->omise_capability_mock = Mockery::mock('alias:Omise_Capabilities');
}
diff --git a/tests/unit/includes/gateway/class-omise-payment-wechat-pay-test.php b/tests/unit/includes/gateway/class-omise-payment-wechat-pay-test.php
index 648f96ad..36b8dd64 100644
--- a/tests/unit/includes/gateway/class-omise-payment-wechat-pay-test.php
+++ b/tests/unit/includes/gateway/class-omise-payment-wechat-pay-test.php
@@ -1,16 +1,17 @@
sourceType = 'wechat_pay';
- Brain\Monkey\setUp();
- Brain\Monkey\Functions\stubs([
+ Monkey\Functions\stubs([
'apply_filters' => function () {
return Omise_Image::get_image([
'file' => 'wechat_pay.svg',
@@ -19,6 +20,9 @@ public function setUp(): void
},
]);
+ Monkey\Functions\expect('wp_kses');
+ Monkey\Functions\expect('add_action');
+
require_once __DIR__ . '/../../../../includes/libraries/omise-plugin/helpers/request.php';
require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-wechat-pay.php';
}
@@ -29,7 +33,6 @@ public function test_restricted_countries_field_has_required_countries()
$expectedCountries = ['TH'];
$this->assertEqualsCanonicalizing($expectedCountries, $obj->restricted_countries);
- unset($expectedCountries);
}
public function test_charge()
@@ -40,6 +43,7 @@ public function test_charge()
public function test_get_icon()
{
+ Monkey\Functions\expect('plugins_url');
$obj = new Omise_Payment_Wechat_Pay();
$res = $obj->get_icon();
$expected = "";
diff --git a/tests/unit/includes/gateway/traits/charge-request-builder-test.php b/tests/unit/includes/gateway/traits/charge-request-builder-test.php
index 3ffe5cc4..6411cd06 100644
--- a/tests/unit/includes/gateway/traits/charge-request-builder-test.php
+++ b/tests/unit/includes/gateway/traits/charge-request-builder-test.php
@@ -18,7 +18,7 @@ function get_rest_url() {
/**
* close mockery after tests are done
*/
- public function tearDown(): void
+ protected function tearDown(): void
{
Mockery::close();
}
diff --git a/tests/unit/includes/libraries/omise-plugin/helpers/request-test.php b/tests/unit/includes/libraries/omise-plugin/helpers/request-test.php
index b235a8a7..b0bd0e53 100644
--- a/tests/unit/includes/libraries/omise-plugin/helpers/request-test.php
+++ b/tests/unit/includes/libraries/omise-plugin/helpers/request-test.php
@@ -4,7 +4,7 @@
class RequestHelperTest extends TestCase
{
- public function setUp(): void
+ protected function setUp(): void
{
require_once __DIR__ . '/../../../../../../includes/libraries/omise-plugin/helpers/request.php';
}
diff --git a/tests/unit/omise-woocommerce-test.php b/tests/unit/omise-woocommerce-test.php
index 0d97262e..37652f4a 100644
--- a/tests/unit/omise-woocommerce-test.php
+++ b/tests/unit/omise-woocommerce-test.php
@@ -1,6 +1,7 @@
andReturn(null);
+ Monkey\Functions\expect('do_action')->andReturn(null);
+
require_once __DIR__ . '/../../omise-woocommerce.php';
$this->model = Omise::instance();
}
@@ -28,9 +24,10 @@ function do_action()
/**
* close mockery after test cases are done
*/
- public function tearDown(): void
+ protected function tearDown(): void
{
- Mockery::close();
+ Monkey\tearDown();
+ parent::tearDown();
}
/**