editor.js
1 lines
| 1 | (()=>{"use strict";const e=window.React,{compose:t}=wp.compose,{withSelect:a,withDispatch:l}=wp.data,{__:n}=wp.i18n,{TextControl:i,SelectControl:r,withNotices:o}=wp.components,{useEffect:s}=wp.element,{renderGateway:c}=JetFBActions,{withSelectGateways:m,withDispatchGateways:u}=JetFBHooks,{ToggleControl:d}=JetFBComponents,p=t(a(m),l(u),o)(function({setGatewayRequest:t,gatewaySpecific:a,setGatewaySpecific:l,gatewayScenario:o,setGatewayScenario:m,getSpecificOrGlobal:u,additionalSourceGateway:p,specificGatewayLabel:w,noticeOperations:y,noticeUI:g}){const{id:_="PAY_NOW"}=o;return s(()=>{t({id:_})},[_]),s(()=>{t({id:_})},[]),(0,e.createElement)(e.Fragment,null,g,(0,e.createElement)(d,{checked:a.use_global,onChange:e=>l({use_global:e})},n("Use","jet-form-builder")+" ",(0,e.createElement)("a",{href:JetFormEditorData.global_settings_url+"#payments-gateways__paypal"},n("Global Settings","jet-form-builder"))),(0,e.createElement)(i,{label:w("client_id"),key:"paypal_client_id_setting",value:u("client_id"),onChange:e=>l({client_id:e}),disabled:a.use_global}),(0,e.createElement)(i,{label:w("secret"),key:"paypal_secret_setting",value:u("secret"),onChange:e=>l({secret:e}),disabled:a.use_global}),(0,e.createElement)(r,{labelPosition:"side",label:w("gateway_type"),value:_,onChange:e=>{m({id:e})},options:p.scenarios}),c("paypal",{noticeOperations:y},_))}),{compose:w}=wp.compose,{withSelect:y,withDispatch:g}=wp.data,{TextControl:_,SelectControl:f,BaseControl:b,RadioControl:h}=wp.components,{withSelectFormFields:E,withSelectGateways:v,withDispatchGateways:S,withSelectActionsByType:G}=JetFBHooks,{GatewayFetchButton:C}=JetFBComponents,j=w(y((...e)=>({...E([],"--")(...e),...v(...e)})),g((...e)=>({...S(...e)})))(function({gatewayGeneral:t,gatewaySpecific:a,setGateway:l,setGatewaySpecific:n,formFields:i,getSpecificOrGlobal:r,loadingGateway:o,scenarioSource:s,noticeOperations:c,scenarioLabel:m,globalGatewayLabel:u}){return(0,e.createElement)(e.Fragment,null,(0,e.createElement)(b,{label:m("fetch_button_label")},(0,e.createElement)("div",{className:"jet-user-fields-map__list"},!o.success&&!o.loading&&(0,e.createElement)("span",{className:"description-controls"},m("fetch_button_help")),(0,e.createElement)(C,{initialLabel:m("fetch_button"),label:m("fetch_button_retry"),apiArgs:{...s.fetch,data:{client_id:r("client_id"),secret:r("secret")}},onFail:e=>{c.removeNotice(t.gateway),c.createNotice({status:"error",content:e.message,id:t.gateway})}}))),o.success&&(0,e.createElement)(e.Fragment,null,(0,e.createElement)(_,{label:m("currency"),key:"paypal_currency_code_setting",value:a.currency,onChange:e=>n({currency:e})}),(0,e.createElement)(f,{label:u("price_field"),key:"form_fields_price_field",value:t.price_field,labelPosition:"side",onChange:e=>{l({price_field:e})},options:i})))}),{gatewayAttr:k,renderGateway:F,renderGatewayWithPlaceholder:N}=JetFBActions,{__:B}=wp.i18n,{TextareaControl:A,BaseControl:D}=wp.components,{withSelect:J,withDispatch:x}=wp.data,{compose:T}=wp.compose,{withSelectGateways:O,withDispatchGateways:R}=JetFBHooks,I=k(),L=k("labels"),H=T(J((...e)=>({...O(...e)})),x(R))(function({gatewayGeneral:t,setGatewayInner:a,loadingGateway:l,gatewayRequest:n,CURRENT_SCENARIO:i,currentScenario:r}){const o=(e,t,l)=>{a({key:e,value:{[t]:l}})},s=(e,a,l=!1)=>t[e]&&t[e][a]?t[e][a]:l,c=(e,t)=>{o("messages",e,t)},m=e=>s("messages",e,I.messages[e]),u=(0,e.createElement)(e.Fragment,null,N(t.gateway,{gatewayGeneral:t,CURRENT_SCENARIO:i,currentScenario:r},"macrosList",(0,e.createElement)(D,{key:"payment_result_macros_base_control"},(0,e.createElement)("h4",null,B("Available macros list: ","jet-form-builder"),(0,e.createElement)("br",null),B("%gateway_amount% - payment amount returned from gateway template;","jet-form-builder"),(0,e.createElement)("br",null),B("%gateway_status% - payment status returned from payment gateway;","jet-form-builder"),(0,e.createElement)("br",null),B('%field_name% - replace "field_name" with any field name from the form;',"jet-form-builder"),(0,e.createElement)("br",null)))),(0,e.createElement)(A,{key:"payment_result_message_success",label:L("message_success"),value:m("success"),onChange:e=>c("success",e)}),(0,e.createElement)(A,{key:"payment_result_message_failed",label:L("message_failed"),value:m("failed"),onChange:e=>c("failed",e)}));return(0,e.createElement)(e.Fragment,null,F(t.gateway,{setValueInObject:o,getNotifications:s}),(-1===n.id||l.success||!n.id.includes(t.gateway))&&u)}),{Button:M,ToggleControl:P,BaseControl:U,Notice:q,__experimentalItemGroup:V,__experimentalItem:W}=wp.components,{withDispatch:z,withSelect:Y,useSelect:$,dispatch:K}=wp.data,{useState:Q,useEffect:X}=wp.element,{__:Z}=wp.i18n,{compose:ee}=wp.compose,{createBlock:te}=wp.blocks,{ActionModal:ae}=JetFBComponents,{withDispatchGateways:le,withSelectGateways:ne,useMetaState:ie}=JetFBHooks,re=window.JetFormEditorData.gateways,oe="manual",se="jet-forms/multi-gateway",ce=(e,t)=>{for(const a of e){if(a.name===t)return!0;if(a.innerBlocks?.length&&ce(a.innerBlocks,t))return!0}return!1},me=ee(z(le),Y(ne))(function(t){var a;const{setGateway:l,setGatewayScenario:n,clearGateway:i,clearScenario:r,gatewayGeneral:o,gatewayScenario:s}=t,[c,m]=ie("_jf_gateways"),[u,d]=Q(!1),[p,w]=Q(null!==(a=c?.gateway)&&void 0!==a?a:"none"),[y,g]=Q(null),_=c?.mode===oe,f=$(e=>{const t=e("core/block-editor");return!!t?.getBlocks&&ce(t.getBlocks(),se)},[]),b=()=>{K("core/block-editor").insertBlocks(te(se))};X(()=>{var e;w(_?oe:null!==(e=c?.gateway)&&void 0!==e?e:"none")},[c?.gateway,c?.mode]),X(()=>{if(!u)return i(),void r();const e=y||c?.gateway;e&&"none"!==e&&(_&&!y||(l({...c,gateway:e}),n(c?.[e]?.scenario)))},[u,y]);const h=(e=!1)=>{!1!==e&&m(e),d(!1),g(null)},E=[{label:"None",value:"none"},...re.list,{label:"Manual",value:oe}],v={row:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},item:{display:"flex",minHeight:"50px",flexDirection:"column",justifyContent:"center"},toggle:{paddingTop:"10px",paddingLeft:"20px",flexDirection:"column"},notice:{marginTop:"10px"},notice__btn:{marginLeft:"0"}},S=re.labels||{},G=!!c?.protect_price_field;return(0,e.createElement)(e.Fragment,null,(0,e.createElement)(V,{className:"jfb-gateways",isBordered:!0,isSeparated:!0},E.map(t=>{const a=p===t.value,l="none"!==t.value&&t.value!==oe&&(_||a),n=_&&"none"!==t.value&&t.value!==oe;return(0,e.createElement)(W,{key:t.value,className:"jfb-gateways__item",style:v.item},(0,e.createElement)("div",{className:"jfb-gateways__row",style:v.row},(0,e.createElement)("label",{className:"jfb-gateways__option"},(0,e.createElement)("input",{type:"radio",name:"jfb_gateway",value:t.value,checked:a,onChange:()=>{w(t.value),t.value!==oe?m({...c,mode:"single",gateway:t.value}):m({...c,mode:oe})}}),(0,e.createElement)("span",{className:"jfb-gateways__label"},t.label)),(0,e.createElement)("div",{className:"jfb-gateways__actions"},l?(0,e.createElement)(M,{onClick:()=>{g(t.value),d(!0)},icon:"admin-tools",isSecondary:!0,size:"small"},Z("Edit","jet-form-builder")):(0,e.createElement)("span",{className:"jfb-gateways__edit-spacer","aria-hidden":"true"}))),n&&(0,e.createElement)("div",{className:"jfb-gateways__toggle",style:v.toggle},(0,e.createElement)(P,{label:Z("Show on frontend","jet-form-builder"),checked:!!c?.[t.value]?.show_on_front,onChange:e=>{m({...c,[t.value]:{...c?.[t.value]||{},show_on_front:e}})}})),t.value===oe&&_&&!f&&(0,e.createElement)("div",{className:"jfb-gateways__notice",style:v.notice},(0,e.createElement)(q,{status:"warning",isDismissible:!1},(0,e.createElement)("div",null,Z("To display gateways on the frontend in Manual mode, add the Multi Gateway block to the form.","jet-form-builder")),(0,e.createElement)(M,{isSecondary:!0,onClick:b,size:"small",style:v.notice__btn},Z("Add block","jet-form-builder")))))})),(0,e.createElement)("div",{className:"jfb-gateways__common",style:{marginTop:"12px"}},(0,e.createElement)(P,{label:S.protect_price_field||Z("Secure payment amount","jet-form-builder"),checked:G,onChange:e=>{m({...c,protect_price_field:e})}}),(0,e.createElement)(U,{help:S.protect_price_field_help||Z("Applies to all payment gateways that use this amount field.","jet-form-builder")}),(0,e.createElement)(q,{status:G?"info":"warning",isDismissible:!1},G?(0,e.createElement)(e.Fragment,null,(0,e.createElement)("div",null,(0,e.createElement)("strong",null,Z("Valid:","jet-form-builder"))," ",S.protect_price_field_safe?.valid),(0,e.createElement)("div",null,(0,e.createElement)("strong",null,Z("Invalid:","jet-form-builder"))," ",S.protect_price_field_safe?.invalid)):S.protect_price_field_risk)),u&&(0,e.createElement)(ae,{classNames:["width-60"],onRequestClose:()=>h(),onCancelClick:()=>h(),onUpdateClick:()=>h({...o,[o.gateway]:{...o[o.gateway]||{},scenario:s}}),title:`Edit ${C=y||c?.gateway,re.list.find(e=>e.value===C)?.label||C} Settings`},(0,e.createElement)(H,null)));var C}),{__:ue}=wp.i18n,de={base:{name:"jf-gateways-panel",title:ue("Gateways Settings","jet-form-builder")},settings:{render:me,icon:"money-alt"}},{registerGateway:pe}=JetFBActions,{addFilter:we,applyFilters:ye}=wp.hooks,ge="paypal";function _e(){return window?.JetFormEditorData?.gateways?.validation||{}}JetFBActions.isGatewayValid=function(e,t){if("string"==typeof t)try{t=JSON.parse(t||"{}")}catch(e){t={}}const a=_e()?.required_map||{},l=a?.[e];if(!Array.isArray(l)||!l.length)return!1;const n=t?.[e]||{};if(n.use_global){const t=_e()?.global_valid||{};return!!t?.[e]}return l.every(e=>{const t=n?.[e];return"string"==typeof t?""!==t.trim():!!t})},pe(ge,p),pe(ge,j,"PAY_NOW"),we("jet.fb.register.plugin.jf-validation-panel.after","jet-form-builder/gateways",function(e){return e.push(de),e})})(); |