OwlCyberSecurity - MANAGER
Edit File: payPalCommerceGateway.js
(()=>{"use strict";var e={n:t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.React;var r,n,a,o=e.n(t);!function(e){e.INITIAL="initial",e.PENDING="pending",e.REJECTED="rejected",e.RESOLVED="resolved"}(r||(r={})),function(e){e.LOADING_STATUS="setLoadingStatus",e.RESET_OPTIONS="resetOptions",e.SET_BRAINTREE_INSTANCE="braintreeInstance"}(n||(n={})),function(e){e.NUMBER="number",e.CVV="cvv",e.EXPIRATION_DATE="expirationDate",e.EXPIRATION_MONTH="expirationMonth",e.EXPIRATION_YEAR="expirationYear",e.POSTAL_CODE="postalCode"}(a||(a={}));var i=function(){return i=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var a in t=arguments[r])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e},i.apply(this,arguments)};function s(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(n=Object.getOwnPropertySymbols(e);a<n.length;a++)t.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(e,n[a])&&(r[n[a]]=e[n[a]])}return r}function c(e,t,r){if(r||2===arguments.length)for(var n,a=0,o=t.length;a<o;a++)!n&&a in t||(n||(n=Array.prototype.slice.call(t,0,a)),n[a]=t[a]);return e.concat(n||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError;var l="data-react-paypal-script-id",d="react-paypal-js",u="dataNamespace",p="dataSdkIntegrationSource",f="3.84.0",m=("https://js.braintreegateway.com/web/".concat(f,"/js/client.min.js"),"https://js.braintreegateway.com/web/".concat(f,"/js/paypal-checkout.min.js"),"paypal");function y(e){return void 0===e&&(e=m),window[e]}function v(e){var t=e.reactComponentName,r=e.sdkComponentKey,n=e.sdkRequestedComponents,a=void 0===n?"":n,o=e.sdkDataNamespace,i=void 0===o?m:o,s=r.charAt(0).toUpperCase().concat(r.substring(1)),c="Unable to render <".concat(t," /> because window.").concat(i,".").concat(s," is undefined."),l="string"==typeof a?a:a.join(",");if(!l.includes(r)){var d=[l,r].filter(Boolean).join();c+="\nTo fix the issue, add '".concat(r,"' to the list of components passed to the parent PayPalScriptProvider:")+"\n`<PayPalScriptProvider options={{ components: '".concat(d,"'}}>`.")}return c}function h(e){var t=e,r=l;t[r];var n=s(t,[r+""]);return"react-paypal-js-".concat(function(e){for(var t="",r=0;r<e.length;r++){var n=e[r].charCodeAt(0)*r;e[r+1]&&(n+=e[r+1].charCodeAt(0)*(r-1)),t+=String.fromCharCode(97+Math.abs(n)%26)}return t}(JSON.stringify(n)))}function g(e,t){var a,o,s,c;switch(t.type){case n.LOADING_STATUS:return"object"==typeof t.value?i(i({},e),{loadingStatus:t.value.state,loadingStatusErrorMessage:t.value.message}):i(i({},e),{loadingStatus:t.value});case n.RESET_OPTIONS:return s=e.options[l],(null==(c=self.document.querySelector("script[".concat(l,'="').concat(s,'"]')))?void 0:c.parentNode)&&c.parentNode.removeChild(c),i(i({},e),{loadingStatus:r.PENDING,options:i(i((a={},a[p]=d,a),t.value),(o={},o[l]="".concat(h(t.value)),o))});case n.SET_BRAINTREE_INSTANCE:return i(i({},e),{braintreePayPalCheckoutInstance:t.value});default:return e}}var w=(0,t.createContext)(null);function E(){var e=function(e){if("function"==typeof(null==e?void 0:e.dispatch)&&0!==e.dispatch.length)return e;throw new Error("usePayPalScriptReducer must be used within a PayPalScriptProvider")}((0,t.useContext)(w));return[i(i({},e),{isInitial:e.loadingStatus===r.INITIAL,isPending:e.loadingStatus===r.PENDING,isResolved:e.loadingStatus===r.RESOLVED,isRejected:e.loadingStatus===r.REJECTED}),e.dispatch]}(0,t.createContext)({});var b=function(e){var r,n,a,l=e.className,d=void 0===l?"":l,p=e.disabled,f=void 0!==p&&p,m=e.children,h=e.forceReRender,g=void 0===h?[]:h,w=s(e,["className","disabled","children","forceReRender"]),S=f?{opacity:.38}:{},P="".concat(d," ").concat(f?"paypal-buttons-disabled":"").trim(),_=(0,t.useRef)(null),N=(0,t.useRef)(null),O=(n=w,a=(0,t.useRef)(new Proxy({},{get:function(e,t,r){return"function"==typeof e[t]?function(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return e[t].apply(e,r)}:Reflect.get(e,t,r)}})),a.current=Object.assign(a.current,n),a.current),F=E()[0],R=F.isResolved,I=F.options,C=(0,t.useState)(null),j=C[0],T=C[1],k=(0,t.useState)(!0),x=k[0],A=k[1],D=(0,t.useState)(null)[1];function L(){null!==N.current&&N.current.close().catch((function(){}))}return(null===(r=N.current)||void 0===r?void 0:r.updateProps)&&N.current.updateProps({message:w.message}),(0,t.useEffect)((function(){if(!1===R)return L;var e=y(I.dataNamespace);if(void 0===e||void 0===e.Buttons)return D((function(){throw new Error(v({reactComponentName:b.displayName,sdkComponentKey:"buttons",sdkRequestedComponents:I.components,sdkDataNamespace:I[u]}))})),L;try{N.current=e.Buttons(i(i({},O),{onInit:function(e,t){T(t),"function"==typeof w.onInit&&w.onInit(e,t)}}))}catch(e){return D((function(){throw new Error("Failed to render <PayPalButtons /> component. Failed to initialize: ".concat(e))}))}return!1===N.current.isEligible()?(A(!1),L):_.current?(N.current.render(_.current).catch((function(e){null!==_.current&&0!==_.current.children.length&&D((function(){throw new Error("Failed to render <PayPalButtons /> component. ".concat(e))}))})),L):L}),c(c([R],g,!0),[w.fundingSource],!1)),(0,t.useEffect)((function(){null!==j&&(!0===f?j.disable().catch((function(){})):j.enable().catch((function(){})))}),[f,j]),o().createElement(o().Fragment,null,x?o().createElement("div",{ref:_,style:S,className:P}):m)};function S(e,t){void 0===t&&(t={});var r=document.createElement("script");return r.src=e,Object.keys(t).forEach((function(e){r.setAttribute(e,t[e]),"data-csp-nonce"===e&&r.setAttribute("nonce",t["data-csp-nonce"])})),r}function P(e,t){if(void 0===t&&(t=Promise),N(e,t),"undefined"==typeof document)return t.resolve(null);var r=function(e){var t,r,n=e.sdkBaseUrl,a=e.environment,o=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(n=Object.getOwnPropertySymbols(e);a<n.length;a++)t.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(e,n[a])&&(r[n[a]]=e[n[a]])}return r}(e,["sdkBaseUrl","environment"]),i=n||function(e){return"sandbox"===e?"https://www.sandbox.paypal.com/sdk/js":"https://www.paypal.com/sdk/js"}(a),s=o,c=Object.keys(s).filter((function(e){return void 0!==s[e]&&null!==s[e]&&""!==s[e]})).reduce((function(e,t){var r,n=s[t].toString();return r=function(e,t){return(t?"-":"")+e.toLowerCase()},"data"===(t=t.replace(/[A-Z]+(?![a-z])|[A-Z]/g,r)).substring(0,4)||"crossorigin"===t?e.attributes[t]=n:e.queryParams[t]=n,e}),{queryParams:{},attributes:{}}),l=c.queryParams,d=c.attributes;return l["merchant-id"]&&-1!==l["merchant-id"].indexOf(",")&&(d["data-merchant-id"]=l["merchant-id"],l["merchant-id"]="*"),{url:"".concat(i,"?").concat((t=l,r="",Object.keys(t).forEach((function(e){0!==r.length&&(r+="&"),r+=e+"="+t[e]})),r)),attributes:d}}(e),n=r.url,a=r.attributes,o=a["data-namespace"]||"paypal",i=_(o);return a["data-js-sdk-library"]||(a["data-js-sdk-library"]="paypal-js"),function(e,t){var r=document.querySelector('script[src="'.concat(e,'"]'));if(null===r)return null;var n=S(e,t),a=r.cloneNode();if(delete a.dataset.uidAuto,Object.keys(a.dataset).length!==Object.keys(n.dataset).length)return null;var o=!0;return Object.keys(a.dataset).forEach((function(e){a.dataset[e]!==n.dataset[e]&&(o=!1)})),o?r:null}(n,a)&&i?t.resolve(i):function(e,t){void 0===t&&(t=Promise),N(e,t);var r=e.url,n=e.attributes;if("string"!=typeof r||0===r.length)throw new Error("Invalid url.");if(void 0!==n&&"object"!=typeof n)throw new Error("Expected attributes to be an object.");return new t((function(e,t){if("undefined"==typeof document)return e();!function(e){var t=e.url,r=e.attributes,n=e.onSuccess,a=e.onError,o=S(t,r);o.onerror=a,o.onload=n,document.head.insertBefore(o,document.head.firstElementChild)}({url:r,attributes:n,onSuccess:function(){return e()},onError:function(){var e=new Error('The script "'.concat(r,'" failed to load. Check the HTTP status code and response body in DevTools to learn more.'));return t(e)}})}))}({url:n,attributes:a},t).then((function(){var e=_(o);if(e)return e;throw new Error("The window.".concat(o," global variable is not available."))}))}function _(e){return window[e]}function N(e,t){if("object"!=typeof e||null===e)throw new Error("Expected an options object.");var r=e.environment;if(r&&"production"!==r&&"sandbox"!==r)throw new Error('The `environment` option must be either "production" or "sandbox".');if(void 0!==t&&"function"!=typeof t)throw new Error("Expected PromisePonyfill to be a function.")}b.displayName="PayPalButtons","function"==typeof SuppressedError&&SuppressedError;var O=function(e){var r=e.className,n=void 0===r?"":r,a=e.children,c=s(e,["className","children"]),l=E()[0],d=l.isResolved,p=l.options,f=(0,t.useRef)(null),m=(0,t.useState)(!0),h=m[0],g=m[1],w=(0,t.useState)(null)[1];return(0,t.useEffect)((function(){if(!1!==d){var e=y(p[u]);if(void 0===e||void 0===e.Marks)return w((function(){throw new Error(v({reactComponentName:O.displayName,sdkComponentKey:"marks",sdkRequestedComponents:p.components,sdkDataNamespace:p[u]}))}));!function(e){var t=f.current;if(!t||!e.isEligible())return g(!1);t.firstChild&&t.removeChild(t.firstChild),e.render(t).catch((function(e){null!==t&&0!==t.children.length&&w((function(){throw new Error("Failed to render <PayPalMarks /> component. ".concat(e))}))}))}(e.Marks(i({},c)))}}),[d,c.fundingSource]),o().createElement(o().Fragment,null,h?o().createElement("div",{ref:f,className:n}):a)};O.displayName="PayPalMarks";var F=function(e){var r=e.className,n=void 0===r?"":r,a=e.forceReRender,l=void 0===a?[]:a,d=s(e,["className","forceReRender"]),p=E()[0],f=p.isResolved,m=p.options,h=(0,t.useRef)(null),g=(0,t.useRef)(null),w=(0,t.useState)(null)[1];return(0,t.useEffect)((function(){if(!1!==f){var e=y(m[u]);if(void 0===e||void 0===e.Messages)return w((function(){throw new Error(v({reactComponentName:F.displayName,sdkComponentKey:"messages",sdkRequestedComponents:m.components,sdkDataNamespace:m[u]}))}));g.current=e.Messages(i({},d)),g.current.render(h.current).catch((function(e){null!==h.current&&0!==h.current.children.length&&w((function(){throw new Error("Failed to render <PayPalMessages /> component. ".concat(e))}))}))}}),c([f],l,!0)),o().createElement("div",{ref:h,className:n})};F.displayName="PayPalMessages";var R=function(e){var a,s=e.options,c=void 0===s?{clientId:"test"}:s,u=e.children,f=e.deferLoading,m=void 0!==f&&f,y=(0,t.useReducer)(g,{options:i(i({},c),(a={},a.dataJsSdkLibrary=d,a[p]=d,a[l]="".concat(h(c)),a)),loadingStatus:m?r.INITIAL:r.PENDING}),v=y[0],E=y[1];return(0,t.useEffect)((function(){if(!1===m&&v.loadingStatus===r.INITIAL)return E({type:n.LOADING_STATUS,value:r.PENDING});if(v.loadingStatus===r.PENDING){var e=!0;return P(v.options).then((function(){e&&E({type:n.LOADING_STATUS,value:r.RESOLVED})})).catch((function(t){console.error("".concat("Failed to load the PayPal JS SDK script."," ").concat(t)),e&&E({type:n.LOADING_STATUS,value:{state:r.REJECTED,message:String(t)}})})),function(){e=!1}}}),[v.options,m,v.loadingStatus]),o().createElement(w.Provider,{value:i(i({},v),{dispatch:E})},u)};function I(){}var C=(0,t.createContext)({cardFieldsForm:null,fields:{},registerField:I,unregisterField:I}),j=function(){return(0,t.useContext)(C)},T=function(e){var t=e.children;return o().createElement("div",{style:{width:"100%"}},t)},k=function(e){var r=e.children,n=s(e,["children"]),a=E()[0],c=a.isResolved,l=a.options,d=function(){var e=(0,t.useState)(null)[1],r=(0,t.useRef)({});return{fields:r.current,registerField:function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var a=t[0],o=t[1],i=t[2];return r.current[a]&&e((function(){throw new Error("Cannot use duplicate CardFields as children")})),r.current[a]=null==i?void 0:i[a](o),r.current[a]},unregisterField:function(e){var t=r.current[e];t&&(t.close().catch(I),delete r.current[e])}}}(),p=d.fields,f=d.registerField,v=d.unregisterField,h=(0,t.useState)(null),g=h[0],w=h[1],b=(0,t.useRef)(null),S=(0,t.useState)(!1),P=S[0],_=S[1],N=(0,t.useState)(null)[1];return(0,t.useEffect)((function(){var e,t,r;if(c){try{b.current=null!==(r=null===(t=(e=y(l[u])).CardFields)||void 0===t?void 0:t.call(e,i({},n)))&&void 0!==r?r:null}catch(e){return void N((function(){throw new Error("Failed to render <PayPalCardFieldsProvider /> component. Failed to initialize: ".concat(e))}))}if(b.current)return _(b.current.isEligible()),w(b.current),function(){w(null),b.current=null};N((function(){var e;throw new Error(function(e){var t=e.components,r=void 0===t?"":t,n=e[u],a=void 0===n?m:n,o=r?"".concat(r,",card-fields"):"card-fields",i="Unable to render <PayPalCardFieldsProvider /> because window.".concat(a,".CardFields is undefined.");return r.includes("card-fields")||(i+="\nTo fix the issue, add 'card-fields' to the list of components passed to the parent PayPalScriptProvider: <PayPalScriptProvider options={{ components: '".concat(o,"'}}>")),i}(((e={components:l.components})[u]=l[u],e)))}))}}),[c]),P?o().createElement(T,null,o().createElement(C.Provider,{value:{cardFieldsForm:g,fields:p,registerField:f,unregisterField:v}},r)):o().createElement("div",null)},x=function(e){var r=e.className,n=e.fieldName,a=s(e,["className","fieldName"]),i=j(),c=i.cardFieldsForm,l=i.registerField,d=i.unregisterField,u=(0,t.useRef)(null),p=(0,t.useState)(null)[1];function f(){d(n)}return(0,t.useEffect)((function(){if(!c)return p((function(){throw new Error("Individual CardFields must be rendered inside the PayPalCardFieldsProvider")})),f;if(!u.current)return f;var e=l(n,a,c);return null==e||e.render(u.current).catch((function(e){(function(e){var t;return!!(null===(t=e.current)||void 0===t?void 0:t.children.length)})(u)&&p((function(){throw new Error("Failed to render <PayPal".concat(n," /> component. ").concat(e))}))})),f}),[]),o().createElement("div",{ref:u,className:r})},A=function(e){var t=e.children;return o().createElement("div",{style:{display:"flex",width:"100%"}},t)},D=function(e){var t=e.className;return o().createElement("div",{className:t},o().createElement(x,{fieldName:"NameField"}),o().createElement(x,{fieldName:"NumberField"}),o().createElement(A,null,o().createElement(T,null,o().createElement(x,{fieldName:"ExpiryField"})),o().createElement(T,null,o().createElement(x,{fieldName:"CVVField"}))))};const L=window.wp.i18n;class M extends Error{constructor(e,...t){super(...t),Error.captureStackTrace&&Error.captureStackTrace(this,M),this.name="FormRequestError",this.errors=e}}const B=M;async function U(e,t,r,n){if(void 0!==n&&"subscription"===t?.donationType&&!n.supportsSubscriptions)return r("FORM_ERROR",{message:(0,L.__)("This payment gateway does not support recurring payments, please try selecting another payment gateway.","give")});try{const r=function(e){const t=new FormData;for(const r in e){const n=e[r];if(null===n||"object"!=typeof n||n instanceof File)t.append(r,n);else for(const e in n)t.append(`${r}[${e}]`,n[e])}return t}(t),{response:n}=await async function(e,t){return{response:await fetch(e,{method:"POST",mode:"cors",cache:"default",credentials:"same-origin",redirect:"follow",referrerPolicy:"no-referrer-when-downgrade",headers:{accept:"application/json"},body:t})}}(e,r),a=await n.json();if(function(e){return"gateway_error"===e.type}(a)||function(e){return"validation_error"===e.type||null!=e.data?.errors}(a))throw new B(a.data.errors.errors);return!0}catch(e){var a;return e instanceof B?((e,t,r)=>{Object.entries(t).forEach((([t,n])=>{if(Object.keys(e).includes(t)){const e=document.querySelector('input[name="'+t+'"]'),a=e&&"hidden"!==e.type;if(r(t,{message:Array.isArray(n)?n[0]:n},{shouldFocus:a}),!a)if(e)e.parentElement.scrollIntoView({behavior:"smooth"});else{const e=document.querySelector(".givewp-fields-"+t);e?.scrollIntoView({behavior:"smooth"})}}else r("FORM_ERROR","gateway_error"===t?{message:Array.isArray(n)?n[0]:n}:{message:(0,L.__)("Something went wrong, please try again or contact support.","give")})}))})(t,e.errors,r):r("FORM_ERROR",{message:null!==(a=e?.message)&&void 0!==a?a:(0,L.__)("Something went wrong, please try again or contact support.","give")})}}async function q(e,t,r){const n=await fetch(e,{method:"POST",body:r}),a=await n.json();if(!a.success)throw a.data.error;const o=a.data.id;return t.payPalOrderId=o,o}(()=>{let e,r,a,o,i,s,c,l,d,u,p,f,m,y,v,h,g,w,S,P=null;const _=e=>{S=S||window.givewp.form.hooks.useFormSubmitButton(),S&&(S.style.display="hide"===e?"none":"")},N={color:"gold",label:"paypal",layout:"vertical",shape:"rect",tagline:!1},O=({isSubscription:e})=>{let t={...s.sdkOptions};return e&&-1!==t.components.indexOf("card-fields")&&(t.components=t.components.split(",").filter((e=>"card-fields"!==e)).join(",")),t},F=()=>{const t=new FormData;return t.append("give-form-id",s.donationFormId),t.append("give-form-hash",s.donationFormNonce),t.append("give_payment_mode","paypal-commerce"),t.append("give-amount",e.toString()),t.append("give-recurring-period",p),t.append("period",p),t.append("frequency",d),t.append("times",u),t.append("give_first",a),t.append("give_last",o),t.append("give_email",i),f&&(t.append("card_address",v),t.append("card_address_2",h),t.append("card_city",y),t.append("card_state",m),t.append("card_zip",g),t.append("billing_country",f)),t.append("give-cs-form-currency",w),t},I=async()=>await q(`${s.ajaxUrl}?action=give_paypal_commerce_create_order`,J,F()),C=e=>{throw console.error("PayPal Card Fields Error:",e),new Error((0,L.__)("PayPal Card Fields Error:","give")+e.message)},T=async()=>await q(`${s.ajaxUrl}?action=give_paypal_commerce_create_order`,J,F()),x=async e=>{const{orderID:t,liabilityShift:r}=e;if(c=t,r&&!["POSSIBLE","YES"].includes(r))throw console.log("Liability shift not possible or not accepted."),new Error((0,L.__)("Card type and issuing bank are not ready to complete a 3D Secure authentication.","give"))},A=async(e,t)=>{const{planId:r,userAction:n}=await async function(e,t,r){const n=await fetch(e,{method:"POST",body:r}),a=await n.json();if(!a.success)throw a.data.error;const o=a.data.id;return t.payPalPlanId=o,{planId:o,userAction:a.data?.user_action}}(`${s.ajaxUrl}?action=give_paypal_commerce_create_plan_id`,J,F()),c={name:{given_name:a,surname:o},email_address:i};f&&(c.shipping_address={name:{full_name:`${a} ${o}`.trim()},address:{address_line_1:v,address_line_2:h,admin_area_2:y,admin_area_1:m,postal_code:g,country_code:f}});const d={plan_id:r,subscriber:c};return n&&(d.application_context={...d.application_context,user_action:n}),t.subscription.create(d).then((e=>l=e))},M=({label:e,style:r={}})=>{const n={container:{fontSize:"16px",fontStyle:"italic",display:"flex",justifyContent:"center",alignItems:"center",...r},dashedLine:{border:"1px solid #d4d4d4",flexGrow:1},label:{padding:"0 6px",fontSize:"14px",color:"#8d8e8e"}};return(0,t.createElement)("div",{className:"separator-with-text",style:n.container},(0,t.createElement)("div",{className:"dashed-line",style:n.dashedLine}),(0,t.createElement)("div",{className:"label",style:n.label},e),(0,t.createElement)("div",{className:"dashed-line",style:n.dashedLine}))},B=({children:t})=>{const{useWatch:n}=window.givewp.form.hooks,s=window.givewp.form.hooks.useFormData();return e=s.amount,r=n({name:"feeRecovery"}),a=s.firstName,o=s.lastName,i=s.email,d=s.subscriptionFrequency,u=s.subscriptionInstallments,p=s.subscriptionPeriod,v=s.billingAddress.addressLine1,h=s.billingAddress.addressLine2,y=s.billingAddress.city,m=s.billingAddress.state,g=s.billingAddress.postalCode,f=s.billingAddress.country,w=s.currency,t},G=()=>{const{useWatch:n,useFormState:d}=window.givewp.form.hooks,u=n({name:"donationType"}),{isSubmitting:p,isSubmitSuccessful:f}=d(),{useFormContext:m}=window.givewp.form.hooks,{getFieldState:y,setFocus:v,getValues:h,formState:{errors:g},trigger:E,setError:P}=m(),_=window.givewp.gateways.get("paypal-commerce"),O={style:N,disabled:p||f,forceReRender:[u,e,r,a,o,i,w],onClick:async(e,t)=>{if("subscription"===u&&!_.supportsSubscriptions)return P("FORM_ERROR",{message:(0,L.__)("This payment gateway does not support recurring payments, please try selecting another payment gateway.","give")},{shouldFocus:!0}),S.scrollIntoView({behavior:"smooth"}),t.reject();if(!await E()){for(const e in h())y(e).invalid&&v(e);return t.reject()}return await U(s.validateUrl,h(),P,_)?t.resolve():t.reject()},onApprove:async(e,t)=>{const r=e.orderID,n=e?.subscriptionID,a=S.textContent;if(S.textContent=(0,L.__)("Waiting for PayPal...","give"),S.disabled=!0,n&&"subscription"===u)return l=n,S.disabled=!1,S.textContent=a,void S.click();r&&(c=r),S.disabled=!1,S.textContent=a,S.click()}};return"subscription"===u?(0,t.createElement)(b,{...O,createSubscription:A,createOrder:null}):(0,t.createElement)(b,{...O,createOrder:I,createSubscription:null})},V=()=>{const{cardFieldsForm:e}=j();return P=e,J.payPalCardFieldsForm=e,(0,t.createElement)(D,null)},z=()=>(_("show"),(0,t.createElement)(k,{createOrder:T,onApprove:x,onError:C},(0,t.createElement)(t.Fragment,null,(0,t.createElement)(M,{label:(0,L.__)("Or pay with card","give"),style:{padding:"30px 0"}}),(0,t.createElement)(V,null))));function $(){const{isRecurring:e}=window.givewp.form.hooks.useFormData(),[{options:r},a]=E(),o=-1!==r.components.indexOf("card-fields");return(0,t.useEffect)((()=>{const t=O({isSubscription:e});a({type:n.RESET_OPTIONS,value:{...t,currency:w,vault:e,intent:e?"subscription":t.intent}})}),[w,e]),(0,t.useEffect)((()=>(o||_("hide"),()=>{_("show")})),[o]),(0,t.createElement)(t.Fragment,null,(0,t.createElement)(G,null),o&&(0,t.createElement)(z,null))}const J={id:"paypal-commerce",initialize(){s=this.settings},beforeCreatePayment:async function(e){if(l)return{payPalSubscriptionId:l};if(c)return{payPalOrderId:c};if(!P)throw new Error((0,L.__)("PayPal Card Fields are not available.","give"));if(!(await P.getState()).isFormValid)throw new Error((0,L.__)("PayPal Card Fields are invalid","give"));const t=S.textContent;if(S.textContent=(0,L.__)("Waiting for PayPal...","give"),S.disabled=!0,await P.submit(),S.textContent=t,!c)throw S.disabled=!1,new Error((0,L.__)("Missing PayPal Order ID.","give"));return{payPalOrderId:c}},Fields(){const{isRecurring:e}=window.givewp.form.hooks.useFormData();return(0,t.useEffect)((()=>{S=window.givewp.form.hooks.useFormSubmitButton()}),[]),(0,t.createElement)(B,null,(0,t.createElement)(R,{deferLoading:!0,options:O({isSubscription:e})},(0,t.createElement)($,null)))}};window.givewp.gateways.register(J)})()})();