← Back
Editing: settings-payments-bacs.js
"use strict";(globalThis.webpackChunk_wcAdmin_webpackJsonp=globalThis.webpackChunk_wcAdmin_webpackJsonp||[]).push([[9680],{60431:(e,t,o)=>{o.d(t,{W:()=>c});var n=o(56427),a=o(39793);const c=({size:e="medium"})=>(0,a.jsx)("div",{className:`woocommerce-field-placeholder woocommerce-field-placeholder--${e}`,children:(0,a.jsx)(n.Placeholder,{})})},224:(e,t,o)=>{o.d(t,{w:()=>s});var n=o(56427),a=o(51609),c=o(39793);const s=({children:e})=>(0,c.jsx)(c.Fragment,{children:e});s.Layout=({children:e})=>((0,a.useEffect)(()=>{const e=document.getElementById("wpbody");e&&e.querySelector(".settings-layout")&&e.classList.add("has-settings-layout")},[]),(0,c.jsx)("div",{className:"settings-layout",children:e})),s.Section=({title:e,description:t,children:o,id:n})=>(0,c.jsxs)("div",{className:"settings-section",id:n,children:[(0,c.jsxs)("div",{className:"settings-section__details",children:[(0,c.jsx)("h2",{children:e}),(0,c.jsx)("p",{children:t})]}),(0,c.jsx)("div",{className:"settings-section__controls",children:o})]}),s.Actions=({children:e})=>(0,c.jsx)(n.Card,{className:"settings-card__wrapper ",children:(0,c.jsx)(n.CardBody,{className:"form__actions",children:e})}),s.Form=({children:e,onSubmit:t})=>(0,c.jsx)("form",{onSubmit:t,className:"settings-form",children:e})},56592:(e,t,o)=>{o.d(t,{C0:()=>c,lV:()=>i,mF:()=>s});var n=o(56427),a=o(39793);const c=({data:e,field:t,onChange:o})=>(0,a.jsx)(n.CheckboxControl,{label:t.label,help:t.description,checked:Boolean(t.getValue({item:e})),onChange:e=>o({[t.id]:e})}),s=({data:e,field:t,onChange:o})=>(0,a.jsx)(n.TextControl,{label:t.label,help:t.description,placeholder:t.placeholder,value:String(t.getValue({item:e})??""),onChange:e=>o({[t.id]:e})}),i=({data:e,field:t,onChange:o})=>(0,a.jsx)(n.TextareaControl,{label:t.label,help:t.description,value:String(t.getValue({item:e})??""),onChange:e=>o({[t.id]:e})})},2057:(e,t,o)=>{o.r(t),o.d(t,{SettingsPaymentsBacs:()=>C,default:()=>S});var n=o(27723),a=o(47143),c=o(56427),s=o(86087),i=o(40314),r=o(35453),l=o(224),d=o(60431),m=o(98846),u=o(51609),_=o(18537);const h=e=>{switch(e){case"AU":return(0,n.__)("BSB","woocommerce");case"CA":return(0,n.__)("Bank transit number","woocommerce");case"IN":return(0,n.__)("IFSC","woocommerce");case"IT":return(0,n.__)("Branch sort","woocommerce");case"NZ":case"SE":return(0,n.__)("Bank code","woocommerce");case"US":return(0,n.__)("Routing number","woocommerce");case"ZA":return(0,n.__)("Branch code","woocommerce");default:return(0,n.__)("Sort code","woocommerce")}},b=e=>{switch(e){case"AU":case"CA":case"IN":case"IT":case"NZ":case"SE":case"US":case"ZA":case"GB":case"IE":return!0;default:return!1}},p=()=>Math.random().toString(36).substring(2,10),x=e=>""===e.trim()?"This field is required.":void 0;var g=o(39793);const w=({account:e,onClose:t,onSave:o,defaultCountry:a})=>{const s=window.wcSettings.countries,[i,r]=(0,u.useState)(e||{account_name:"",account_number:"",bank_name:"",sort_code:"",iban:"",bic:"",country_code:a}),[l,d]=(0,u.useState)(e?.country_code||a),[m,p]=(0,u.useState)({}),w=(e,t)=>{r(o=>({...o,[e]:t}))};return(0,g.jsxs)(c.Modal,{className:"bank-account-modal",title:e?(0,n.__)("Edit bank account","woocommerce"):(0,n.__)("Add a bank account","woocommerce"),onRequestClose:t,shouldCloseOnClickOutside:!1,children:[(0,g.jsxs)("div",{className:"bank-account-modal__content",children:[(0,g.jsx)("p",{className:"bank-account-modal__description",children:e?(0,n.__)("Edit your bank account details.","woocommerce"):(0,n.__)("Add your bank account details.","woocommerce")}),(0,g.jsx)(c.SelectControl,{className:"bank-account-modal__field is-required",label:(0,n.__)("Country","woocommerce"),required:!0,value:l,options:Object.entries(s).map(([e,t])=>({label:(0,_.decodeEntities)(t),value:e})),onChange:e=>{d(e),w("country_code",e),w("sort_code","")}}),(0,g.jsx)(c.TextControl,{className:"bank-account-modal__field is-required",label:(0,n.__)("Account Name","woocommerce"),required:!0,value:i.account_name,onChange:e=>w("account_name",e),help:m.account_name?(0,g.jsx)("span",{className:"bank-account-modal__error",children:m.account_name}):void 0}),(0,g.jsx)(c.TextControl,{className:"bank-account-modal__field",label:(0,n.__)("Bank Name","woocommerce"),value:i.bank_name,onChange:e=>w("bank_name",e)}),(0,g.jsx)(c.TextControl,{className:"bank-account-modal__field",label:(0,n.__)("Account Number","woocommerce"),value:i.account_number,onChange:e=>w("account_number",e),help:m.account_number?(0,g.jsx)("span",{className:"bank-account-modal__error",children:m.account_number}):void 0}),b(l)&&(0,g.jsx)(c.TextControl,{className:"bank-account-modal__field is-required",label:h(l),required:!0,value:(j=i.sort_code||"",f=l,"GB"!==f&&"IE"!==f?j:j.replace(/\D/g,"").substring(0,6).match(/.{1,2}/g)?.join("-")??""),onChange:e=>{"GB"!==l&&"IE"!==l||(e=e.replace(/\D/g,"").substring(0,6)),w("sort_code",e)},help:m.sort_code?(0,g.jsx)("span",{className:"bank-account-modal__error",children:m.sort_code}):void 0}),(0,g.jsx)(c.TextControl,{className:"bank-account-modal__field",label:(0,n.__)("IBAN","woocommerce"),value:i.iban,onChange:e=>w("iban",e),help:m.iban?(0,g.jsx)("span",{className:"bank-account-modal__error",children:m.iban}):void 0}),(0,g.jsx)(c.TextControl,{className:"bank-account-modal__field",label:(0,n.__)("BIC / SWIFT","woocommerce"),value:i.bic,onChange:e=>w("bic",e),help:m.bic?(0,g.jsx)("span",{className:"bank-account-modal__error",children:m.bic}):void 0})]}),(0,g.jsxs)("div",{className:"bank-account-modal__actions",children:[(0,g.jsx)(c.Button,{variant:"tertiary",onClick:t,children:(0,n.__)("Cancel","woocommerce")}),(0,g.jsx)(c.Button,{className:"bank-account-modal__save",variant:"primary",onClick:()=>{(()=>{const e={};e.account_name=x(i.account_name),b(l)&&(e.sort_code=x(i.sort_code));const t=Object.fromEntries(Object.entries(e).filter(([,e])=>e));return p(t),0===Object.keys(t).length})()&&o(i)},children:(0,n.__)("Save","woocommerce")})]})]});var j,f};var j=o(31559);const f=({accounts:e,onChange:t,defaultCountry:o})=>{const[a,s]=(0,u.useState)(()=>e.map(e=>({...e,id:p()})));(0,u.useEffect)(()=>{e.length&&0===a.length&&s(e.map(e=>({...e,id:p()})))},[e,a.length]);const[i,r]=(0,u.useState)(null),[l,d]=(0,u.useState)(!1),[_,h]=(0,u.useState)(null),b=(e=null)=>{r(e),d(!0)};return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(j.q6,{items:a,className:"bank-accounts__list",setItems:e=>{s(e),t(e.map(({id:e,...t})=>t))},children:[(0,g.jsx)("div",{className:"bank-accounts__list-header",children:(0,g.jsxs)("div",{className:"bank-accounts__list-item-inner",children:[(0,g.jsx)("div",{className:"bank-accounts__list-item-before"}),(0,g.jsxs)("div",{className:"bank-accounts__list-item-text",children:[(0,g.jsx)("div",{children:"Account Name"}),(0,g.jsx)("div",{children:"Account Details"}),(0,g.jsx)("div",{children:"Bank Name"})]}),(0,g.jsx)("div",{className:"bank-accounts__list-item-after"})]})}),a.map((e,t)=>(0,g.jsx)(j.Uq,{id:e.id,className:"bank-accounts__list-item"+(0===t?" first-item":""),children:(0,g.jsxs)("div",{className:"bank-accounts__list-item-inner",children:[(0,g.jsx)("div",{className:"bank-accounts__list-item-before",children:(0,g.jsx)(j.Gh,{})}),(0,g.jsxs)("div",{className:"bank-accounts__list-item-text",children:[(0,g.jsx)("div",{children:e.account_name}),(0,g.jsx)("div",{children:e.account_number||e.iban}),(0,g.jsx)("div",{children:e.bank_name})]}),(0,g.jsx)("div",{className:"bank-accounts__list-item-after",children:(0,g.jsx)(m.EllipsisMenu,{label:(0,n.__)("Options","woocommerce"),placement:"bottom-right",renderContent:({onClose:t=()=>{}})=>(0,g.jsxs)(c.MenuGroup,{children:[(0,g.jsx)(c.MenuItem,{role:"menuitem",onClick:()=>{t(),b(e)},children:(0,n.__)("View / edit","woocommerce")}),(0,g.jsx)(c.MenuItem,{isDestructive:!0,onClick:()=>{t(),h(e)},children:(0,n.__)("Delete","woocommerce")})]})})})]})},e.id)),(0,g.jsx)("li",{className:"bank-accounts__list-item action"+(0===a.length?" first-item":""),children:(0,g.jsx)(c.Button,{variant:"secondary",onClick:()=>b(null),children:(0,n.__)("+ Add account","woocommerce")})})]}),l&&(0,g.jsx)(w,{account:i,onClose:()=>d(!1),onSave:e=>{const o=a.findIndex(e=>e.id===i?.id);let n;-1!==o?(n=[...a],n[o]={...e,id:i?.id||p()}):n=[...a,{...e,id:p()}],s(n),t(n.map(({id:e,...t})=>t)),d(!1)},defaultCountry:o}),_&&(0,g.jsxs)(c.Modal,{title:(0,n.__)("Delete account","woocommerce"),onRequestClose:()=>h(null),shouldCloseOnClickOutside:!1,children:[(0,g.jsx)("p",{children:(0,n.__)("Are you sure you want to delete this bank account?","woocommerce")}),(0,g.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px",marginTop:"16px"},children:[(0,g.jsx)(c.Button,{variant:"secondary",onClick:()=>h(null),children:(0,n.__)("Cancel","woocommerce")}),(0,g.jsx)(c.Button,{variant:"primary",isDestructive:!0,onClick:()=>{if(!_)return;const e=a.filter(e=>e.id!==_.id);s(e),t(e.map(({id:e,...t})=>t)),h(null)},children:(0,n.__)("Delete","woocommerce")})]})]})]})};var v=o(56592),y=o(72002);const k=e=>"string"==typeof e?e.split(":")[0]:"",C=()=>{const e=k(window.wcSettings?.admin?.woocommerce_payments_nox_profile?.business_country_code)||k(window.wcSettings?.admin?.preloadSettings?.general?.woocommerce_default_country)||"US",{createSuccessNotice:t,createErrorNotice:o}=(0,a.useDispatch)("core/notices"),{bacsSettings:m,isLoading:u}=(0,a.useSelect)(e=>({bacsSettings:e(i.paymentGatewaysStore).getPaymentGateway("bacs"),isLoading:!e(i.paymentGatewaysStore).hasFinishedResolution("getPaymentGateway",["bacs"])}),[]),{invalidateResolution:_,invalidateResolutionForStoreSelector:h}=(0,a.useDispatch)(i.paymentSettingsStore),{accountsOption:b,isLoadingAccounts:p}=(0,a.useSelect)(e=>{const t=e(i.optionsStore);return{accountsOption:t.getOption("woocommerce_bacs_accounts"),isLoadingAccounts:!t.hasFinishedResolution("getOption",["woocommerce_bacs_accounts"])}},[]),[x,w]=(0,s.useState)({}),[j,C]=(0,s.useState)(!1),[S,N]=(0,s.useState)(!1);(0,s.useEffect)(()=>{m&&(w({enabled:m.enabled,title:m.settings.title.value,description:m.description,instructions:m.settings.instructions.value,...(0,y.Z3)(m)}),N(!1))},[m]);const[A,E]=(0,s.useState)([]);(0,s.useEffect)(()=>{b&&E(b)},[b]);const{updateOptions:B}=(0,a.useDispatch)(i.optionsStore),{updatePaymentGateway:I}=(0,a.useDispatch)(i.paymentGatewaysStore),T=(0,s.useMemo)(()=>[{id:"enabled",label:(0,n.__)("Enable direct bank transfers","woocommerce"),Edit:v.C0},{id:"title",label:(0,n.__)("Title","woocommerce"),description:(0,n.__)("Payment method name that the customer will see during checkout.","woocommerce"),placeholder:(0,n.__)("Direct bank transfer payments","woocommerce"),Edit:v.mF},{id:"description",label:(0,n.__)("Description","woocommerce"),description:(0,n.__)("Payment method description that the customer will see during checkout.","woocommerce"),Edit:v.lV},{id:"instructions",label:(0,n.__)("Instructions","woocommerce"),description:(0,n.__)("Instructions that will be added to the thank you page and emails.","woocommerce"),Edit:v.lV},...(0,y.es)(m,(0,n.__)("direct bank transfer","woocommerce"))],[m]);return(0,g.jsx)(l.w,{children:(0,g.jsx)(l.w.Layout,{children:(0,g.jsxs)(l.w.Form,{onSubmit:e=>{e.preventDefault(),(async()=>{if(!m)return;C(!0);const e={title:String(x.title),instructions:String(x.instructions),...(0,y.YV)(x)};try{await Promise.all([B({woocommerce_bacs_accounts:A.map(({account_name:e,account_number:t,bank_name:o,sort_code:n,iban:a,bic:c,country_code:s})=>({account_name:e,account_number:t,bank_name:o,sort_code:n,iban:a,bic:c,country_code:s}))}),I("bacs",{enabled:Boolean(x.enabled),description:String(x.description),settings:e})]),N(!1),t((0,n.__)("Settings updated successfully","woocommerce"))}catch(e){o((0,n.__)("Failed to update settings","woocommerce"))}finally{C(!1),_("getPaymentProviders",[]),h("getOfflinePaymentGateways")}})()},children:[(0,g.jsx)(l.w.Section,{title:(0,n.__)("Enable and customise","woocommerce"),description:(0,n.__)("Choose how you want to present bank transfer to your customers during checkout.","woocommerce"),children:u?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(d.W,{size:"small"}),(0,g.jsx)(d.W,{size:"medium"}),(0,g.jsx)(d.W,{size:"large"}),(0,g.jsx)(d.W,{size:"large"}),(0,g.jsx)(d.W,{size:"medium"}),(0,g.jsx)(d.W,{size:"small"})]}):(0,g.jsx)(r.A,{data:x,fields:T,form:{layout:{type:"regular"},fields:["enabled","title","description","instructions","enable_for_methods","enable_for_virtual"]},onChange:e=>{w(t=>({...t,...e})),N(!0)}})}),(0,g.jsx)(l.w.Section,{title:(0,n.__)("Account details","woocommerce"),description:(0,n.__)("Configure your bank account details.","woocommerce"),children:p?(0,g.jsx)(d.W,{size:"large"}):(0,g.jsx)(f,{accounts:A,onChange:e=>{E(e),N(!0)},defaultCountry:e})}),(0,g.jsx)(l.w.Actions,{children:(0,g.jsx)(c.Button,{variant:"primary",type:"submit",isBusy:j,disabled:j||!S,children:(0,n.__)("Save changes","woocommerce")})})]})})})},S=C},72002:(e,t,o)=>{o.d(t,{es:()=>d,YV:()=>l,Z3:()=>r});var n=o(98846),a=o(27723);function c(e){const t=document.createElement("textarea");return t.innerHTML=e,t.value}var s=o(56592),i=o(39793);const r=e=>({enable_for_methods:Array.isArray(e.settings.enable_for_methods?.value)?e.settings.enable_for_methods.value:[],enable_for_virtual:"yes"===e.settings.enable_for_virtual?.value}),l=e=>({enable_for_methods:Array.isArray(e.enable_for_methods)?e.enable_for_methods:[],enable_for_virtual:e.enable_for_virtual?"yes":"no"}),d=(e,t)=>{const o=e?.settings.enable_for_methods?.options?(r=e.settings.enable_for_methods.options,Object.entries(r).map(([e,t])=>({label:c(e),value:e,children:Object.entries(t).map(([e,t])=>({value:e,label:c(t)}))}))):[];var r;const l=(0,a.__)("Select shipping methods for which this payment method is enabled.","woocommerce");return[{id:"enable_for_methods",label:(0,a.__)("Enable for shipping methods","woocommerce"),description:l,Edit:({data:e,field:t,onChange:a})=>{const c=t.getValue({item:e});return(0,i.jsx)(n.TreeSelectControl,{label:t.label,help:l,options:o,value:Array.isArray(c)?c:[],onChange:e=>a({[t.id]:e}),selectAllLabel:!1})}},{id:"enable_for_virtual",label:(0,a.__)("Accept for virtual orders","woocommerce"),description:(0,a.sprintf)((0,a.__)("Accept %s if the order is virtual","woocommerce"),t),Edit:s.C0}]}}}]);
Save File
Cancel