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