diff --git a/assets/javascripts/front/reactCheckout/payments/CreditCard/index.js b/assets/javascripts/front/reactCheckout/payments/CreditCard/index.js index 73e26334..f52e0b3a 100644 --- a/assets/javascripts/front/reactCheckout/payments/CreditCard/index.js +++ b/assets/javascripts/front/reactCheckout/payments/CreditCard/index.js @@ -10,18 +10,22 @@ import { useSelect } from "@wordpress/data"; const backendConfig = wc.wcSettings.getSetting( "woo-pagarme-payments-credit_card_data", ); +const googlePayBackendConfig = wc.wcSettings.getSetting( + "woo-pagarme-payments-googlepay_data", +); const PagarmeCreditCardComponent = (props) => { const googleCards = useSelect((select) => { return select(pagarmeTokenStore).getToken(); }); - const { emitResponse, eventRegistration } = props; - const googleActive = backendConfig.googlepayEnable; + const googleActive = googlePayBackendConfig.enabled; + const hasSubscriptionInCart = googlePayBackendConfig.hasSubscriptionInCart; + useCreditCard(backendConfig, emitResponse, eventRegistration, googleCards); return (
- {googleActive && ( + {googleActive && !hasSubscriptionInCart && (
diff --git a/build/credit_card.asset.php b/build/credit_card.asset.php index 4917cc42..4390e935 100644 --- a/build/credit_card.asset.php +++ b/build/credit_card.asset.php @@ -1 +1 @@ - array('react', 'react-dom', 'wp-data', 'wp-element'), 'version' => '8423892adc887b576de0'); + array('react', 'react-dom', 'wp-data', 'wp-element'), 'version' => '4df6da733d92f5ffc390'); diff --git a/build/credit_card.js b/build/credit_card.js index e7c5af1e..0b132abb 100644 --- a/build/credit_card.js +++ b/build/credit_card.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 r(e,t,n,r){return new(n||(n=Promise))((function(a,o){function s(e){try{l(r.next(e))}catch(e){o(e)}}function i(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,i)}l((r=r.apply(e,t||[])).next())}))}let a={};class o{constructor(e){this.handleClick=e=>r(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 r=yield this.client.loadPaymentData(n);t.onLoadPaymentData&&t.onLoadPaymentData(r)}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 r(this,void 0,void 0,(function*(){if(!this.isGooglePayLoaded())try{yield function(e){const t=a[e];if(t)return t;const n=new Promise(((t,n)=>{const r=document.createElement("script");r.src=e,r.async=!0;const o=()=>{t()},s=()=>{r.removeEventListener("load",o),r.removeEventListener("error",s),delete a[e],r.remove(),n(new Error(`Unable to load script ${e}`))};r.addEventListener("load",o),r.addEventListener("error",s),document.body.appendChild(r)}));return a[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 r(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 r=this.client.createButton(t);this.setClassName(e,[e.className,"not-ready"]),e.appendChild(r);let a,o=!1;try{a=yield this.client.isReadyToPay(this.createIsReadyToPayRequest(this.config)),o=a.result&&!this.config.existingPaymentMethodRequired||a.result&&a.paymentMethodPresent&&this.config.existingPaymentMethodRequired||!1}catch(e){this.config.onError?this.config.onError(e):console.error(e)}if(this.isMounted()){if(o){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==a?void 0:a.result)||this.paymentMethodPresent!==(null==a?void 0:a.paymentMethodPresent))&&(this.isReadyToPay=!!(null==a?void 0:a.result),this.paymentMethodPresent=null==a?void 0:a.paymentMethodPresent,this.config.onReadyToPayChange)){const e={isButtonVisible:o,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 r=null===(e=this.element)||void 0===e?void 0:e.getRootNode(),a=`default-google-style-${this.options.cssSelector.replace(/[^\w-]+/g,"")}-${null===(t=this.config)||void 0===t?void 0:t.buttonLocale}`;if(r&&!(null===(n=r.getElementById)||void 0===n?void 0:n.call(r,a))){const e=document.createElement("style");e.id=a,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 `,r instanceof Document&&r.head?r.head.appendChild(e):r.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 i extends t.default.Component{constructor(){super(...arguments),this.manager=new o({cssSelector:`.${s}`,softwareInfoId:"@google-pay/button-react",softwareInfoVersion:"3.1.0"}),this.elementRef=t.default.createRef()}componentDidMount(){return r(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 i}(n(609))},694:(e,t,n)=>{"use strict";var r=n(925);function a(){}function o(){}o.resetWarningCache=a,e.exports=function(){function e(e,t,n,a,o,s){if(s!==r){var i=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw i.name="Invariant Violation",i}}function t(){return e}e.isRequired=e;var n={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:o,resetWarningCache:a};return n.PropTypes=n,n}},556:(e,t,n)=>{e.exports=n(694)()},925:e=>{"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},844:(e,t,n)=>{e.exports=n(200)},200:(e,t,n)=>{"use strict";var r,a=(r=n(609))&&"object"==typeof r&&"default"in r?r.default:r,o=n(795);function s(){return(s=Object.assign||function(e){for(var t=1;tr.length&&p(e,t.length-1);)t=t.slice(0,t.length-1);return t.length}for(var a=r.length,o=t.length;o>=r.length;o--){var s=t[o];if(!p(e,o)&&m(e,o,s)){a=o+1;break}}return a}function g(e,t){return f(e,t)===e.mask.length}function v(e,t){var n=e.maskChar,r=e.mask,a=e.prefix;if(!n){for((t=y(e,"",t,0)).lengtht.length&&(t+=a.slice(t.length,r)),i.every((function(n){for(;c=n,p(e,u=r)&&c!==a[u];){if(r>=t.length&&(t+=a[r]),i=n,o&&p(e,r)&&i===o)return!0;if(++r>=a.length)return!1}var i,u,c;return!m(e,r,n)&&n!==o||(ra.start?d=(c=function(e,t,n,r){var a=e.mask,o=e.maskChar,s=n.split(""),i=r;return s.every((function(t){for(;s=t,p(e,n=r)&&s!==a[n];)if(++r>=a.length)return!1;var n,s;return(m(e,r,t)||t===o)&&r++,r=o.length?h=o.length:h=s.length&&h{"use strict";e.exports=window.React},795:e=>{"use strict";e.exports=window.ReactDOM}},t={};function n(r){var a=t[r];if(void 0!==a)return a.exports;var o=t[r]={exports:{}};return e[r].call(o.exports,o,o.exports,n),o.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 r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},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";function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;t{const s=o(a),i=o(t);return 1===n?`${e} (${s})`:`${n}x ${e} ${s} (${i}) ${r}`.trim()},i=e=>e.map((e=>({label:s(e),value:e.value}))),l=(e,n,r,a,o,s,l)=>{const[u,c]=(0,t.useState)(i(e)),d=(e=>{const n=(0,t.useRef)();return(0,t.useEffect)((()=>{n.current=e})),n.current})(a);return(0,t.useEffect)((()=>{(async()=>{if(2===n&&!r||1===n&&(!d||d===a))return;s(!0);const e=parseFloat(a/100).toFixed(2).replace(".",",");try{const t=await fetch("/wp-admin/admin-ajax.php?"+new URLSearchParams({action:"xqRhBHJ5sW",flag:r,total:e}),{headers:{"X-Request-Type":"Ajax"}});if(!t.ok)return void s(!1);const n=await t.json();if(!n?.installments?.length)return void s(!1);c(i(n.installments)),o(l,1),s(!1)}catch(e){return void s(!1)}})()}),[r,a,n,c,i,o,l]),(0,t.useEffect)((()=>{2===n&&c([{label:"...",value:""}])}),[n,c]),{installmentsOptions:u,filterHandler:e=>{u.filter((t=>t.label.toLowerCase().startsWith(e.toLowerCase())))},installmentsChangeHandler:e=>{o(l,e)}}},{ComboboxControl:u}=wp.components,c=({label:e,installments:n,installmentsType:r,selectedInstallment:a,setSelectedInstallment:o,brand:s,cartTotal:i,setIsLoading:c,cardIndex:d})=>{const{installmentsOptions:p,filterHandler:m,installmentsChangeHandler:h}=l(n,r,s,i,o,c,d);return(0,t.createElement)("div",{className:"wc-block-components-select-input pagarme-installments-combobox"},(0,t.createElement)("div",{className:"wc-block-components-combobox is-active"},(0,t.createElement)(u,{className:"wc-block-components-combobox-control",label:e,onChange:h,value:a,options:p,onFilterValueChange:m,allowReset:!1,autoComplete:"off"})))};c.propTypes={label:a().string.isRequired,installments:a().array.isRequired,installmentsType:a().number.isRequired,selectedInstallment:a().oneOfType([a().string,a().number]).isRequired,setSelectedInstallment:a().func.isRequired,brand:a().string.isRequired,cartTotal:a().number.isRequired,setIsLoading:a().func.isRequired,cardIndex:a().number.isRequired};const d=c;function p(e){return e.replace(/\s/g,"").split("/")}const m=(e,t,n,r)=>{const a=(e,t)=>(delete t.inputHolderName,e.length>0||(t.inputHolderName=r.holderName),t),o=(e,t)=>(delete t.inputNumber,16===(e=e.replace(/(\D)/g,"")).length||(t.inputNumber=r.cardNumber),t),s=(e,t)=>{if(delete t.inputExpiry,0===e.length)return t.inputExpiry=r.emptyExpiry,t;const[n,a]=p(e),o=new Date(`20${a}`,n-1);let s=new Date;return s=new Date(s.getFullYear(),s.getMonth()),n>=1&&n<=12||(t.inputExpiry=r.invalidExpiryMonth),!a.includes("_")||(t.inputExpiry=r.invalidExpiryYear),o(delete t.inputCvv,0===(e=e.replace(/(\D)/g,"")).length?(t.inputCvv=r.emptyCvv,t):(3===e.length||4===e.length||(t.inputCvv=r.invalidCvv),t));return{validateInputHolderName:r=>{const o=a(r,t);return n(e,{...o}),!!o.inputHolderName},validateInputNumber:r=>{const a=o(r,t);return n(e,{...a}),!!a.inputNumber},validateInputExpiry:r=>{const a=s(r,t);return n(e,{...a}),!!a.inputExpiry},validateInputCvv:r=>{const a=i(r,t);return n(e,{...a}),!!a.inputCvv},validateAllFields:(r,l,u,c)=>{let d={...t};return d=a(r,d),d=o(l,d),d=s(u,d),d=i(c,d),n(e,{...d}),0===Object.keys(d).length}}},h=({id:e,label:n,inputValue:r,setInputValue:a,cardIndex:o,errors:s,setErrors:i,fieldErrors:l})=>{const{setIsActive:u,cssClasses:c,inputChangeHandler:d,inputBlurHandler:p}=((e,n,r,a,o,s)=>{const{validateInputHolderName:i}=m(r,a,o,s);let l="wc-block-components-text-input";const[u,c]=(0,t.useState)(!1);return(u||e.length)&&(l+=" is-active"),a.hasOwnProperty("inputHolderName")&&(l+=" has-error"),{setIsActive:c,cssClasses:l,inputChangeHandler:e=>{const t=e.target.value.replace(/[^a-z ]/gi,"");n(r,t)},inputBlurHandler:e=>{i(e.target.value),c(!1)}}})(r,a,o,s,i,l);return(0,t.createElement)("div",{className:c},(0,t.createElement)("label",{htmlFor:e},n),(0,t.createElement)("input",{type:"text",id:e,value:r,onChange:d,onFocus:()=>u(!0),onBlur:p}),s.inputHolderName&&(0,t.createElement)("div",{className:"wc-block-components-validation-error",role:"alert"},(0,t.createElement)("p",null,s.inputHolderName)))};h.propTypes={id:a().string.isRequired,label:a().string.isRequired,inputValue:a().string.isRequired,setInputValue:a().func.isRequired,cardIndex:a().number.isRequired,errors:a().object.isRequired,setErrors:a().func.isRequired,fieldErrors:a().object.isRequired};const f=h;var g=n(844),v=n.n(g);function y(e){return e.replace(/\s|•/g,"")}const b=(e,n,r,a,o,s,i,l,u)=>{const{validateInputNumber:c}=m(s,i,l,u),[d,p]=(0,t.useState)("");let h="wc-block-components-text-input pagarme-credit-card-number-container";const[f,g]=(0,t.useState)(!1);(f||e.length)&&(h+=" is-active"),i.hasOwnProperty("inputNumber")&&(h+=" has-error");const v=()=>{a(s,""),p("")};return{setIsActive:g,cssClasses:h,brandImageSrc:d,inputChangeHandler:e=>{r(s,e.target.value)},inputBlurHandler:t=>{c(t.target.value),(async()=>{const t=y(e);if(16!==t.length)return void v();o(!0);const r=t.substring(0,6),i=`https://api.pagar.me/bin/v1/${r}`;try{const e=await fetch(i),t=await e.json();let l=t.brand;if(e.ok&&void 0!==t.brandName||(l=(e=>{let t="",r=null;for(const[a,o]of Object.entries(n))for(const n of o.prefixes){const o=n.toString();0===e.indexOf(o)&&t.length{const{setIsActive:m,cssClasses:h,brandImageSrc:f,inputChangeHandler:g,inputBlurHandler:y}=b(r,i,a,s,l,u,c,d,p);return(0,t.createElement)("div",{className:h},(0,t.createElement)("label",{htmlFor:e},n),(0,t.createElement)(v(),{className:"pagarme-card-form-card-number",type:"text",id:e,mask:"9999 9999 9999 9999",maskChar:"•",onFocus:()=>m(!0),onChange:g,value:r,onBlur:y}),f&&(0,t.createElement)("img",{src:f,alt:o}),c.inputNumber&&(0,t.createElement)("div",{className:"wc-block-components-validation-error",role:"alert"},(0,t.createElement)("p",null,c.inputNumber)))};E.propTypes={id:a().string.isRequired,label:a().string.isRequired,inputValue:a().string.isRequired,setInputValue:a().func.isRequired,brand:a().string.isRequired,setBrand:a().func.isRequired,brands:a().object.isRequired,setIsLoading:a().func.isRequired,cardIndex:a().number.isRequired,errors:a().object.isRequired,setErrors:a().func.isRequired,fieldErrors:a().object.isRequired};const C=E,w=({id:e,label:n,inputValue:r,setInputValue:a,cardIndex:o,validate:s,validateIndex:i,mask:l,maskChar:u=null,errors:c})=>{const{setIsActive:d,cssClasses:p,inputChangeHandler:m,inputBlurHandler:h}=((e,n,r,a,o,s)=>{let i="wc-block-components-text-input";const[l,u]=(0,t.useState)(!1);return(l||e.length)&&(i+=" is-active"),s.hasOwnProperty(o)&&(i+=" has-error"),{setIsActive:u,cssClasses:i,inputChangeHandler:e=>{n(r,e.target.value)},inputBlurHandler:e=>{a(e.target.value),u(!1)}}})(r,a,o,s,i,c);return(0,t.createElement)("div",{className:p},(0,t.createElement)("label",{htmlFor:e},n),(0,t.createElement)(v(),{type:"text",id:e,mask:l,maskChar:u,onChange:m,value:r,onFocus:()=>d(!0),onBlur:h}))};w.propTypes={id:a().string.isRequired,label:a().string.isRequired,inputValue:a().string.isRequired,setInputValue:a().func.isRequired,cardIndex:a().number.isRequired,mask:a().string.isRequired,maskChar:a().string,validate:a().func.isRequired,validateIndex:a().string.isRequired,errors:a().object.isRequired};const I=w,R=({id:e,label:n,cardIndex:r,inputValue:a,setInputValue:o,errors:s,setErrors:i,fieldErrors:l})=>{const{validateInputExpiry:u}=m(r,s,i,l);return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(I,{id:e,label:n,mask:"99/99",maskChar:"_",inputValue:a,setInputValue:o,cardIndex:r,validate:u,validateIndex:"inputExpiry",errors:s}),s.inputExpiry&&(0,t.createElement)("div",{className:"wc-block-components-validation-error",role:"alert"},(0,t.createElement)("p",null,s.inputExpiry)))};R.propTypes={id:a().string.isRequired,label:a().string.isRequired,cardIndex:a().number.isRequired,inputValue:a().string.isRequired,setInputValue:a().func.isRequired,errors:a().object.isRequired,setErrors:a().func.isRequired,fieldErrors:a().object.isRequired};const k=R,S=({id:e,label:n,cardIndex:r,inputValue:a,setInputValue:o,errors:s,setErrors:i,fieldErrors:l})=>{const{validateInputCvv:u}=m(r,s,i,l);return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(I,{id:e,label:n,mask:"9999",inputValue:a,setInputValue:o,cardIndex:r,validate:u,validateIndex:"inputCvv",errors:s}),s.inputCvv&&(0,t.createElement)("div",{className:"wc-block-components-validation-error",role:"alert"},(0,t.createElement)("p",null,s.inputCvv)))};S.propTypes={id:a().string.isRequired,label:a().string.isRequired,cardIndex:a().number.isRequired,inputValue:a().string.isRequired,setInputValue:a().func.isRequired,errors:a().object.isRequired,setErrors:a().func.isRequired,fieldErrors:a().object.isRequired};const x=S,{ComboboxControl:P}=wp.components,O=({cards:e,label:n,cardIndex:r,selectedCard:a,setSelectCard:o,setBrand:s})=>{const{filterHandler:i,cardChangeHandler:l}=((e,t,n,r)=>({filterHandler:t=>{e.filter((e=>e.label.toLowerCase().startsWith(t.toLowerCase())))},cardChangeHandler:a=>{if(n(t,a),!e)return;const o=e.find((e=>e.value===a));r(t,o?o.brand:"")}}))(e,r,o,s);return(0,t.createElement)("div",{className:"wc-block-components-select-input pagarme-installments-combobox"},(0,t.createElement)("div",{className:"wc-block-components-combobox is-active"},(0,t.createElement)(P,{className:"wc-block-components-combobox-control",label:n,onChange:l,value:a,options:e,onFilterValueChange:i,allowReset:!1,autoComplete:"off"})))};O.propTypes={cards:a().array.isRequired,label:a().string.isRequired,cardIndex:a().number.isRequired,selectedCard:a().string.isRequired,setSelectCard:a().func.isRequired,setBrand:a().func.isRequired};const N=O,T=window.wp.data,M={holderName:"",number:"",expirationDate:"",installment:1,brand:"",cvv:"",saveCard:!1,walletId:"",errors:{}},V={cards:{1:{...M},2:{...M}}},q=(0,T.createReduxStore)("pagarme-cards",{reducer(e=V,t){switch(t.type){case"SET_PROPERTY_VALUE":return 0===t.propertyName?.length?e:{...e,cards:{...e.cards,[t.cardIndex]:{...e.cards[t.cardIndex],[t.propertyName]:t.value}}};case"RESET":return V}return e},actions:{setHolderName:(e,t)=>({type:"SET_PROPERTY_VALUE",cardIndex:e,value:t,propertyName:"holderName"}),setNumber:(e,t)=>({type:"SET_PROPERTY_VALUE",cardIndex:e,value:t,propertyName:"number"}),setExpirationDate:(e,t)=>({type:"SET_PROPERTY_VALUE",cardIndex:e,value:t,propertyName:"expirationDate"}),setInstallment:(e,t)=>({type:"SET_PROPERTY_VALUE",cardIndex:e,value:t,propertyName:"installment"}),setBrand:(e,t)=>({type:"SET_PROPERTY_VALUE",cardIndex:e,value:t,propertyName:"brand"}),setCvv:(e,t)=>({type:"SET_PROPERTY_VALUE",cardIndex:e,value:t,propertyName:"cvv"}),setSaveCard:(e,t)=>({type:"SET_PROPERTY_VALUE",cardIndex:e,value:t,propertyName:"saveCard"}),setWalletId:(e,t)=>({type:"SET_PROPERTY_VALUE",cardIndex:e,value:t,propertyName:"walletId"}),setErrors:(e,t)=>({type:"SET_PROPERTY_VALUE",cardIndex:e,value:t,propertyName:"errors"}),reset:()=>({type:"RESET"})},selectors:{getHolderName:(e,t)=>e.cards[t].holderName,getNumber:(e,t)=>e.cards[t].number,getExpirationDate:(e,t)=>e.cards[t].expirationDate,getInstallment:(e,t)=>e.cards[t].installment,getBrand:(e,t)=>e.cards[t].brand,getCvv:(e,t)=>e.cards[t].cvv,getSaveCard:(e,t)=>e.cards[t].saveCard,getWalletId:(e,t)=>e.cards[t].walletId,getCards:e=>e.cards,getErrors:(e,t)=>e.cards[t].errors}});(0,T.register)(q);const D=q,{CheckboxControl:L}=window.wc.blocksComponents,_=({billing:e,components:n,backendConfig:r,cardIndex:a,eventRegistration:o})=>{const{LoadingMask:s}=n,{holderNameLabel:i,numberLabel:l,expiryLabel:u,cvvLabel:c,installmentsLabel:p,saveCardLabel:h,walletLabel:g}=r.fieldsLabels,{isLoading:v,setIsLoading:y,setHolderName:b,setNumber:E,setExpirationDate:w,setInstallment:I,setBrand:R,setCvv:S,setWalletId:P,setErrors:O,saveCardChangeHandler:M,formatFieldId:V,holderName:q,number:_,expirationDate:j,selectedInstallment:A,brand:B,cvv:F,saveCard:H,walletId:U,errors:Y}=((e,n,r)=>{const[a,o]=(0,t.useState)(!1),{setHolderName:s,setNumber:i,setExpirationDate:l,setInstallment:u,setBrand:c,setCvv:d,setSaveCard:p,setWalletId:h,setErrors:f}=(0,T.useDispatch)(D),g=(0,T.useSelect)((t=>t(D).getHolderName(e)),[e]),v=(0,T.useSelect)((t=>t(D).getNumber(e)),[e]),y=(0,T.useSelect)((t=>t(D).getExpirationDate(e)),[e]),b=(0,T.useSelect)((t=>t(D).getInstallment(e)),[e]),E=(0,T.useSelect)((t=>t(D).getBrand(e)),[e]),C=(0,T.useSelect)((t=>t(D).getCvv(e)),[e]),w=(0,T.useSelect)((t=>t(D).getSaveCard(e)),[e]),I=(0,T.useSelect)((t=>t(D).getWalletId(e)),[e]),R=(0,T.useSelect)((t=>t(D).getErrors(e)),[e]),{validateAllFields:k}=m(e,R,f,r.fieldErrors),{onCheckoutValidation:S}=n;return(0,t.useEffect)((()=>S((()=>(0===I.length&&k(g,v,y,C),!0)))),[S,g,v,y,C,r,I]),{isLoading:a,setIsLoading:o,setHolderName:s,setNumber:i,setExpirationDate:l,setInstallment:u,setBrand:c,setCvv:d,setWalletId:h,setErrors:f,saveCardChangeHandler:t=>{p(e,t)},formatFieldId:t=>`pagarme_credit_card_${e}_${t}`,holderName:g,number:v,expirationDate:y,selectedInstallment:b,brand:E,cvv:C,saveCard:w,walletId:I,errors:R}})(a,o,r);return(0,t.createElement)(s,{isLoading:v},(0,t.createElement)("div",{className:"wc-block-components-form"},r?.walletEnabled&&r?.cards?.length>0&&(0,t.createElement)(N,{label:g,selectedCard:U,cards:r.cards,cardIndex:a,setSelectCard:P,setBrand:R}),0===U.length&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(f,{id:V("holder_name"),label:i,inputValue:q,setInputValue:b,cardIndex:a,errors:Y,setErrors:O,fieldErrors:r?.fieldErrors}),(0,t.createElement)(C,{id:V("number"),label:l,inputValue:_,setInputValue:E,brand:B,setBrand:R,brands:r?.brands,setIsLoading:y,cardIndex:a,errors:Y,setErrors:O,fieldErrors:r?.fieldErrors}),(0,t.createElement)(k,{id:V("expiry"),label:u,inputValue:j,setInputValue:w,cardIndex:a,errors:Y,setErrors:O,fieldErrors:r?.fieldErrors}),(0,t.createElement)(x,{id:V("cvv"),label:c,inputValue:F,setInputValue:S,cardIndex:a,errors:Y,setErrors:O,fieldErrors:r?.fieldErrors})),(0,t.createElement)(d,{label:p,installments:r?.installments,installmentsType:r?.installmentsType,selectedInstallment:A,setSelectedInstallment:I,brand:B,cartTotal:e.cartTotal.value,setIsLoading:y,cardIndex:a}),0===U.length&&r?.walletEnabled&&(0,t.createElement)(L,{label:h,checked:H,onChange:M})))};_.propType={billing:a().object.isRequired,components:a().object.isRequired,backendConfig:a().object.isRequired,cardIndex:a().number.isRequired,eventRegistration:a().object.isRequired};const j=_;var A=n(21),B=n.n(A);const F={token:"",errors:{}},H=(0,T.createReduxStore)("pagarme-googlepay",{reducer(e=F,t){switch(t.type){case"SET_PROPERTY_VALUE":return t.propertyName?{...e,[t.propertyName]:t.value}:e;case"RESET":return F;default:return e}},actions:{setToken:e=>({type:"SET_PROPERTY_VALUE",value:e,propertyName:"token"}),setErrors:e=>({type:"SET_PROPERTY_VALUE",value:e,propertyName:"errors"}),reset:()=>({type:"RESET"})},selectors:{getToken:e=>e.token,getErrors:e=>e.errors}});(0,T.register)(H);const U=H,Y=e=>{const n=wc.wcSettings.getSetting("woo-pagarme-payments-googlepay_data"),r=n.isSandboxMode?"TEST":"PRODUCTION",a=e?.billing?.billingAddress,{setToken:o}=(0,T.useDispatch)(U);return(0,t.createElement)(B(),{environment:r,buttonLocale:"pt",buttonType:"pay",paymentRequest:{apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:[{type:"CARD",parameters:{allowedAuthMethods:["PAN_ONLY"],allowedCardNetworks:n.allowedGoogleBrands},tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:"pagarme",gatewayMerchantId:n.accountId}}}],merchantInfo:{merchantId:n.merchantId,merchantName:n.merchantName},transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Total",totalPrice:(e.billing.cartTotal.value/100).toString(),currencyCode:"BRL",countryCode:"BR"}},onLoadPaymentData:e=>{if(function(e){const t=["first_name","last_name","email","phone","address_1","city","postcode","state","country"];for(const n of t)if(!e[n])return!1;return!0}(a)){let t=e.paymentMethodData.tokenizationData.token;o(t)}jQuery(".wc-block-components-checkout-place-order-button").click()}})};class $ extends Error{constructor(e){super(e),this.name=this.constructor.name}}const W=(e,t,n)=>{const r=`${e.replace("request.","").replace("card.","")}: ${t}`;return n.hasOwnProperty(r)?n[r]:""};async function z(e,t,n,r,a,o){const[s,i]=p(n),l={card:{holder_name:t,number:y(e),exp_month:s,exp_year:i,cvv:r}};try{const e=`https://api.pagar.me/core/v5/tokens?appId=${a}`,t=await fetch(e,{method:"POST",body:JSON.stringify(l)});if(!t.ok){const e=await t.text();if(0===e.length)return{errorMessage:o.serviceUnavailable};const n=((e,t)=>{let n="";for(const r in e.errors)for(const a of e.errors[r]||[]){const e=W(r,a,t);0!==e.length&&(n+=`${e}
`)}return n})(JSON.parse(e),o);return{errorMessage:n}}return{token:(await t.json()).id}}catch(e){return{errorMessage:o.serviceUnavailable}}}const J=(e,n,r,a)=>{const{reset:o}=(0,T.useDispatch)(D),{reset:s}=(0,T.useDispatch)(U),{onPaymentSetup:i}=r,l=(0,T.useSelect)((e=>e(D).getCards()));(0,t.useEffect)((()=>{o()}),[]),(0,t.useEffect)((()=>i((async()=>{try{if(a)return s(),{type:n.responseTypes.SUCCESS,meta:{paymentMethodData:{pagarme:JSON.stringify({googlepay:{googlepay:{payload:a}}}),payment_method:"googlepay"}}};let t=!1;if("object"==typeof l&&(t=Object.values(l).some((e=>Object.keys(e.errors).length>0))),t)return{type:n.responseTypes.ERROR,message:e.errorMessages.creditCardFormHasErrors};const r=await(async(e,t,n)=>{const r=[];for(let a=1;a0){r[a]={"wallet-id":d,brand:l,installment:u};continue}const p=await z(o,t,s,i,n.appId,n.errorMessages);if(p.errorMessage)throw new $(p.errorMessage);r[a]={token:p.token,brand:l,installment:u},c&&(r[a]["save-card"]=c)}return r})(l,1,e);return{type:n.responseTypes.SUCCESS,meta:{paymentMethodData:{pagarme:JSON.stringify({[e.key]:{cards:{...r}}}),payment_method:e.key}}}}catch(t){let r=e.errorMessages.serviceUnavailable;return t instanceof $&&(r=t.message),{type:n.responseTypes.ERROR,message:r}}}))),[i,l,e,a])},{registerPaymentMethod:X}=window.wc.wcBlocksRegistry,G=wc.wcSettings.getSetting("woo-pagarme-payments-credit_card_data"),Z=n=>{const r=(0,T.useSelect)((e=>e(U).getToken())),{emitResponse:a,eventRegistration:o}=n,s=G.googlepayEnable;return J(G,a,o,r),(0,t.createElement)("div",null,s&&(0,t.createElement)("div",null,(0,t.createElement)(Y,n),(0,t.createElement)("div",{className:"pagarme_creditcard_divider"},(0,t.createElement)("p",null,"Ou pague com cartão"))),!r&&(0,t.createElement)(j,e({},n,{backendConfig:G,cardIndex:1})))},Q=({components:e})=>{const{PaymentMethodLabel:n}=e;return(0,t.createElement)(n,{text:G.label})};Z.propTypes={emitResponse:a().object,eventRegistration:a().object},Q.propTypes={components:a().object},X({name:G.name,label:(0,t.createElement)(Q,null),content:(0,t.createElement)(Z,null),edit:(0,t.createElement)(Z,null),canMakePayment:()=>!0,ariaLabel:G.ariaLabel})})()})(); \ 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 r(e,t,n,r){return new(n||(n=Promise))((function(a,o){function s(e){try{l(r.next(e))}catch(e){o(e)}}function i(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,i)}l((r=r.apply(e,t||[])).next())}))}let a={};class o{constructor(e){this.handleClick=e=>r(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 r=yield this.client.loadPaymentData(n);t.onLoadPaymentData&&t.onLoadPaymentData(r)}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 r(this,void 0,void 0,(function*(){if(!this.isGooglePayLoaded())try{yield function(e){const t=a[e];if(t)return t;const n=new Promise(((t,n)=>{const r=document.createElement("script");r.src=e,r.async=!0;const o=()=>{t()},s=()=>{r.removeEventListener("load",o),r.removeEventListener("error",s),delete a[e],r.remove(),n(new Error(`Unable to load script ${e}`))};r.addEventListener("load",o),r.addEventListener("error",s),document.body.appendChild(r)}));return a[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 r(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 r=this.client.createButton(t);this.setClassName(e,[e.className,"not-ready"]),e.appendChild(r);let a,o=!1;try{a=yield this.client.isReadyToPay(this.createIsReadyToPayRequest(this.config)),o=a.result&&!this.config.existingPaymentMethodRequired||a.result&&a.paymentMethodPresent&&this.config.existingPaymentMethodRequired||!1}catch(e){this.config.onError?this.config.onError(e):console.error(e)}if(this.isMounted()){if(o){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==a?void 0:a.result)||this.paymentMethodPresent!==(null==a?void 0:a.paymentMethodPresent))&&(this.isReadyToPay=!!(null==a?void 0:a.result),this.paymentMethodPresent=null==a?void 0:a.paymentMethodPresent,this.config.onReadyToPayChange)){const e={isButtonVisible:o,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 r=null===(e=this.element)||void 0===e?void 0:e.getRootNode(),a=`default-google-style-${this.options.cssSelector.replace(/[^\w-]+/g,"")}-${null===(t=this.config)||void 0===t?void 0:t.buttonLocale}`;if(r&&!(null===(n=r.getElementById)||void 0===n?void 0:n.call(r,a))){const e=document.createElement("style");e.id=a,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 `,r instanceof Document&&r.head?r.head.appendChild(e):r.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 i extends t.default.Component{constructor(){super(...arguments),this.manager=new o({cssSelector:`.${s}`,softwareInfoId:"@google-pay/button-react",softwareInfoVersion:"3.1.0"}),this.elementRef=t.default.createRef()}componentDidMount(){return r(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 i}(n(609))},694:(e,t,n)=>{"use strict";var r=n(925);function a(){}function o(){}o.resetWarningCache=a,e.exports=function(){function e(e,t,n,a,o,s){if(s!==r){var i=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw i.name="Invariant Violation",i}}function t(){return e}e.isRequired=e;var n={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:o,resetWarningCache:a};return n.PropTypes=n,n}},556:(e,t,n)=>{e.exports=n(694)()},925:e=>{"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},844:(e,t,n)=>{e.exports=n(200)},200:(e,t,n)=>{"use strict";var r,a=(r=n(609))&&"object"==typeof r&&"default"in r?r.default:r,o=n(795);function s(){return(s=Object.assign||function(e){for(var t=1;tr.length&&p(e,t.length-1);)t=t.slice(0,t.length-1);return t.length}for(var a=r.length,o=t.length;o>=r.length;o--){var s=t[o];if(!p(e,o)&&m(e,o,s)){a=o+1;break}}return a}function g(e,t){return f(e,t)===e.mask.length}function v(e,t){var n=e.maskChar,r=e.mask,a=e.prefix;if(!n){for((t=y(e,"",t,0)).lengtht.length&&(t+=a.slice(t.length,r)),i.every((function(n){for(;c=n,p(e,u=r)&&c!==a[u];){if(r>=t.length&&(t+=a[r]),i=n,o&&p(e,r)&&i===o)return!0;if(++r>=a.length)return!1}var i,u,c;return!m(e,r,n)&&n!==o||(ra.start?d=(c=function(e,t,n,r){var a=e.mask,o=e.maskChar,s=n.split(""),i=r;return s.every((function(t){for(;s=t,p(e,n=r)&&s!==a[n];)if(++r>=a.length)return!1;var n,s;return(m(e,r,t)||t===o)&&r++,r=o.length?h=o.length:h=s.length&&h{"use strict";e.exports=window.React},795:e=>{"use strict";e.exports=window.ReactDOM}},t={};function n(r){var a=t[r];if(void 0!==a)return a.exports;var o=t[r]={exports:{}};return e[r].call(o.exports,o,o.exports,n),o.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 r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},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";function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;t{const s=o(a),i=o(t);return 1===n?`${e} (${s})`:`${n}x ${e} ${s} (${i}) ${r}`.trim()},i=e=>e.map((e=>({label:s(e),value:e.value}))),l=(e,n,r,a,o,s,l)=>{const[u,c]=(0,t.useState)(i(e)),d=(e=>{const n=(0,t.useRef)();return(0,t.useEffect)((()=>{n.current=e})),n.current})(a);return(0,t.useEffect)((()=>{(async()=>{if(2===n&&!r||1===n&&(!d||d===a))return;s(!0);const e=parseFloat(a/100).toFixed(2).replace(".",",");try{const t=await fetch("/wp-admin/admin-ajax.php?"+new URLSearchParams({action:"xqRhBHJ5sW",flag:r,total:e}),{headers:{"X-Request-Type":"Ajax"}});if(!t.ok)return void s(!1);const n=await t.json();if(!n?.installments?.length)return void s(!1);c(i(n.installments)),o(l,1),s(!1)}catch(e){return void s(!1)}})()}),[r,a,n,c,i,o,l]),(0,t.useEffect)((()=>{2===n&&c([{label:"...",value:""}])}),[n,c]),{installmentsOptions:u,filterHandler:e=>{u.filter((t=>t.label.toLowerCase().startsWith(e.toLowerCase())))},installmentsChangeHandler:e=>{o(l,e)}}},{ComboboxControl:u}=wp.components,c=({label:e,installments:n,installmentsType:r,selectedInstallment:a,setSelectedInstallment:o,brand:s,cartTotal:i,setIsLoading:c,cardIndex:d})=>{const{installmentsOptions:p,filterHandler:m,installmentsChangeHandler:h}=l(n,r,s,i,o,c,d);return(0,t.createElement)("div",{className:"wc-block-components-select-input pagarme-installments-combobox"},(0,t.createElement)("div",{className:"wc-block-components-combobox is-active"},(0,t.createElement)(u,{className:"wc-block-components-combobox-control",label:e,onChange:h,value:a,options:p,onFilterValueChange:m,allowReset:!1,autoComplete:"off"})))};c.propTypes={label:a().string.isRequired,installments:a().array.isRequired,installmentsType:a().number.isRequired,selectedInstallment:a().oneOfType([a().string,a().number]).isRequired,setSelectedInstallment:a().func.isRequired,brand:a().string.isRequired,cartTotal:a().number.isRequired,setIsLoading:a().func.isRequired,cardIndex:a().number.isRequired};const d=c;function p(e){return e.replace(/\s/g,"").split("/")}const m=(e,t,n,r)=>{const a=(e,t)=>(delete t.inputHolderName,e.length>0||(t.inputHolderName=r.holderName),t),o=(e,t)=>(delete t.inputNumber,16===(e=e.replace(/(\D)/g,"")).length||(t.inputNumber=r.cardNumber),t),s=(e,t)=>{if(delete t.inputExpiry,0===e.length)return t.inputExpiry=r.emptyExpiry,t;const[n,a]=p(e),o=new Date(`20${a}`,n-1);let s=new Date;return s=new Date(s.getFullYear(),s.getMonth()),n>=1&&n<=12||(t.inputExpiry=r.invalidExpiryMonth),!a.includes("_")||(t.inputExpiry=r.invalidExpiryYear),o(delete t.inputCvv,0===(e=e.replace(/(\D)/g,"")).length?(t.inputCvv=r.emptyCvv,t):(3===e.length||4===e.length||(t.inputCvv=r.invalidCvv),t));return{validateInputHolderName:r=>{const o=a(r,t);return n(e,{...o}),!!o.inputHolderName},validateInputNumber:r=>{const a=o(r,t);return n(e,{...a}),!!a.inputNumber},validateInputExpiry:r=>{const a=s(r,t);return n(e,{...a}),!!a.inputExpiry},validateInputCvv:r=>{const a=i(r,t);return n(e,{...a}),!!a.inputCvv},validateAllFields:(r,l,u,c)=>{let d={...t};return d=a(r,d),d=o(l,d),d=s(u,d),d=i(c,d),n(e,{...d}),0===Object.keys(d).length}}},h=({id:e,label:n,inputValue:r,setInputValue:a,cardIndex:o,errors:s,setErrors:i,fieldErrors:l})=>{const{setIsActive:u,cssClasses:c,inputChangeHandler:d,inputBlurHandler:p}=((e,n,r,a,o,s)=>{const{validateInputHolderName:i}=m(r,a,o,s);let l="wc-block-components-text-input";const[u,c]=(0,t.useState)(!1);return(u||e.length)&&(l+=" is-active"),a.hasOwnProperty("inputHolderName")&&(l+=" has-error"),{setIsActive:c,cssClasses:l,inputChangeHandler:e=>{const t=e.target.value.replace(/[^a-z ]/gi,"");n(r,t)},inputBlurHandler:e=>{i(e.target.value),c(!1)}}})(r,a,o,s,i,l);return(0,t.createElement)("div",{className:c},(0,t.createElement)("label",{htmlFor:e},n),(0,t.createElement)("input",{type:"text",id:e,value:r,onChange:d,onFocus:()=>u(!0),onBlur:p}),s.inputHolderName&&(0,t.createElement)("div",{className:"wc-block-components-validation-error",role:"alert"},(0,t.createElement)("p",null,s.inputHolderName)))};h.propTypes={id:a().string.isRequired,label:a().string.isRequired,inputValue:a().string.isRequired,setInputValue:a().func.isRequired,cardIndex:a().number.isRequired,errors:a().object.isRequired,setErrors:a().func.isRequired,fieldErrors:a().object.isRequired};const f=h;var g=n(844),v=n.n(g);function y(e){return e.replace(/\s|•/g,"")}const b=(e,n,r,a,o,s,i,l,u)=>{const{validateInputNumber:c}=m(s,i,l,u),[d,p]=(0,t.useState)("");let h="wc-block-components-text-input pagarme-credit-card-number-container";const[f,g]=(0,t.useState)(!1);(f||e.length)&&(h+=" is-active"),i.hasOwnProperty("inputNumber")&&(h+=" has-error");const v=()=>{a(s,""),p("")};return{setIsActive:g,cssClasses:h,brandImageSrc:d,inputChangeHandler:e=>{r(s,e.target.value)},inputBlurHandler:t=>{c(t.target.value),(async()=>{const t=y(e);if(16!==t.length)return void v();o(!0);const r=t.substring(0,6),i=`https://api.pagar.me/bin/v1/${r}`;try{const e=await fetch(i),t=await e.json();let l=t.brand;if(e.ok&&void 0!==t.brandName||(l=(e=>{let t="",r=null;for(const[a,o]of Object.entries(n))for(const n of o.prefixes){const o=n.toString();0===e.indexOf(o)&&t.length{const{setIsActive:m,cssClasses:h,brandImageSrc:f,inputChangeHandler:g,inputBlurHandler:y}=b(r,i,a,s,l,u,c,d,p);return(0,t.createElement)("div",{className:h},(0,t.createElement)("label",{htmlFor:e},n),(0,t.createElement)(v(),{className:"pagarme-card-form-card-number",type:"text",id:e,mask:"9999 9999 9999 9999",maskChar:"•",onFocus:()=>m(!0),onChange:g,value:r,onBlur:y}),f&&(0,t.createElement)("img",{src:f,alt:o}),c.inputNumber&&(0,t.createElement)("div",{className:"wc-block-components-validation-error",role:"alert"},(0,t.createElement)("p",null,c.inputNumber)))};E.propTypes={id:a().string.isRequired,label:a().string.isRequired,inputValue:a().string.isRequired,setInputValue:a().func.isRequired,brand:a().string.isRequired,setBrand:a().func.isRequired,brands:a().object.isRequired,setIsLoading:a().func.isRequired,cardIndex:a().number.isRequired,errors:a().object.isRequired,setErrors:a().func.isRequired,fieldErrors:a().object.isRequired};const w=E,C=({id:e,label:n,inputValue:r,setInputValue:a,cardIndex:o,validate:s,validateIndex:i,mask:l,maskChar:u=null,errors:c})=>{const{setIsActive:d,cssClasses:p,inputChangeHandler:m,inputBlurHandler:h}=((e,n,r,a,o,s)=>{let i="wc-block-components-text-input";const[l,u]=(0,t.useState)(!1);return(l||e.length)&&(i+=" is-active"),s.hasOwnProperty(o)&&(i+=" has-error"),{setIsActive:u,cssClasses:i,inputChangeHandler:e=>{n(r,e.target.value)},inputBlurHandler:e=>{a(e.target.value),u(!1)}}})(r,a,o,s,i,c);return(0,t.createElement)("div",{className:p},(0,t.createElement)("label",{htmlFor:e},n),(0,t.createElement)(v(),{type:"text",id:e,mask:l,maskChar:u,onChange:m,value:r,onFocus:()=>d(!0),onBlur:h}))};C.propTypes={id:a().string.isRequired,label:a().string.isRequired,inputValue:a().string.isRequired,setInputValue:a().func.isRequired,cardIndex:a().number.isRequired,mask:a().string.isRequired,maskChar:a().string,validate:a().func.isRequired,validateIndex:a().string.isRequired,errors:a().object.isRequired};const I=C,R=({id:e,label:n,cardIndex:r,inputValue:a,setInputValue:o,errors:s,setErrors:i,fieldErrors:l})=>{const{validateInputExpiry:u}=m(r,s,i,l);return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(I,{id:e,label:n,mask:"99/99",maskChar:"_",inputValue:a,setInputValue:o,cardIndex:r,validate:u,validateIndex:"inputExpiry",errors:s}),s.inputExpiry&&(0,t.createElement)("div",{className:"wc-block-components-validation-error",role:"alert"},(0,t.createElement)("p",null,s.inputExpiry)))};R.propTypes={id:a().string.isRequired,label:a().string.isRequired,cardIndex:a().number.isRequired,inputValue:a().string.isRequired,setInputValue:a().func.isRequired,errors:a().object.isRequired,setErrors:a().func.isRequired,fieldErrors:a().object.isRequired};const k=R,S=({id:e,label:n,cardIndex:r,inputValue:a,setInputValue:o,errors:s,setErrors:i,fieldErrors:l})=>{const{validateInputCvv:u}=m(r,s,i,l);return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(I,{id:e,label:n,mask:"9999",inputValue:a,setInputValue:o,cardIndex:r,validate:u,validateIndex:"inputCvv",errors:s}),s.inputCvv&&(0,t.createElement)("div",{className:"wc-block-components-validation-error",role:"alert"},(0,t.createElement)("p",null,s.inputCvv)))};S.propTypes={id:a().string.isRequired,label:a().string.isRequired,cardIndex:a().number.isRequired,inputValue:a().string.isRequired,setInputValue:a().func.isRequired,errors:a().object.isRequired,setErrors:a().func.isRequired,fieldErrors:a().object.isRequired};const x=S,{ComboboxControl:P}=wp.components,O=({cards:e,label:n,cardIndex:r,selectedCard:a,setSelectCard:o,setBrand:s})=>{const{filterHandler:i,cardChangeHandler:l}=((e,t,n,r)=>({filterHandler:t=>{e.filter((e=>e.label.toLowerCase().startsWith(t.toLowerCase())))},cardChangeHandler:a=>{if(n(t,a),!e)return;const o=e.find((e=>e.value===a));r(t,o?o.brand:"")}}))(e,r,o,s);return(0,t.createElement)("div",{className:"wc-block-components-select-input pagarme-installments-combobox"},(0,t.createElement)("div",{className:"wc-block-components-combobox is-active"},(0,t.createElement)(P,{className:"wc-block-components-combobox-control",label:n,onChange:l,value:a,options:e,onFilterValueChange:i,allowReset:!1,autoComplete:"off"})))};O.propTypes={cards:a().array.isRequired,label:a().string.isRequired,cardIndex:a().number.isRequired,selectedCard:a().string.isRequired,setSelectCard:a().func.isRequired,setBrand:a().func.isRequired};const N=O,T=window.wp.data,M={holderName:"",number:"",expirationDate:"",installment:1,brand:"",cvv:"",saveCard:!1,walletId:"",errors:{}},V={cards:{1:{...M},2:{...M}}},q=(0,T.createReduxStore)("pagarme-cards",{reducer(e=V,t){switch(t.type){case"SET_PROPERTY_VALUE":return 0===t.propertyName?.length?e:{...e,cards:{...e.cards,[t.cardIndex]:{...e.cards[t.cardIndex],[t.propertyName]:t.value}}};case"RESET":return V}return e},actions:{setHolderName:(e,t)=>({type:"SET_PROPERTY_VALUE",cardIndex:e,value:t,propertyName:"holderName"}),setNumber:(e,t)=>({type:"SET_PROPERTY_VALUE",cardIndex:e,value:t,propertyName:"number"}),setExpirationDate:(e,t)=>({type:"SET_PROPERTY_VALUE",cardIndex:e,value:t,propertyName:"expirationDate"}),setInstallment:(e,t)=>({type:"SET_PROPERTY_VALUE",cardIndex:e,value:t,propertyName:"installment"}),setBrand:(e,t)=>({type:"SET_PROPERTY_VALUE",cardIndex:e,value:t,propertyName:"brand"}),setCvv:(e,t)=>({type:"SET_PROPERTY_VALUE",cardIndex:e,value:t,propertyName:"cvv"}),setSaveCard:(e,t)=>({type:"SET_PROPERTY_VALUE",cardIndex:e,value:t,propertyName:"saveCard"}),setWalletId:(e,t)=>({type:"SET_PROPERTY_VALUE",cardIndex:e,value:t,propertyName:"walletId"}),setErrors:(e,t)=>({type:"SET_PROPERTY_VALUE",cardIndex:e,value:t,propertyName:"errors"}),reset:()=>({type:"RESET"})},selectors:{getHolderName:(e,t)=>e.cards[t].holderName,getNumber:(e,t)=>e.cards[t].number,getExpirationDate:(e,t)=>e.cards[t].expirationDate,getInstallment:(e,t)=>e.cards[t].installment,getBrand:(e,t)=>e.cards[t].brand,getCvv:(e,t)=>e.cards[t].cvv,getSaveCard:(e,t)=>e.cards[t].saveCard,getWalletId:(e,t)=>e.cards[t].walletId,getCards:e=>e.cards,getErrors:(e,t)=>e.cards[t].errors}});(0,T.register)(q);const D=q,{CheckboxControl:L}=window.wc.blocksComponents,_=({billing:e,components:n,backendConfig:r,cardIndex:a,eventRegistration:o})=>{const{LoadingMask:s}=n,{holderNameLabel:i,numberLabel:l,expiryLabel:u,cvvLabel:c,installmentsLabel:p,saveCardLabel:h,walletLabel:g}=r.fieldsLabels,{isLoading:v,setIsLoading:y,setHolderName:b,setNumber:E,setExpirationDate:C,setInstallment:I,setBrand:R,setCvv:S,setWalletId:P,setErrors:O,saveCardChangeHandler:M,formatFieldId:V,holderName:q,number:_,expirationDate:j,selectedInstallment:A,brand:B,cvv:F,saveCard:H,walletId:U,errors:Y}=((e,n,r)=>{const[a,o]=(0,t.useState)(!1),{setHolderName:s,setNumber:i,setExpirationDate:l,setInstallment:u,setBrand:c,setCvv:d,setSaveCard:p,setWalletId:h,setErrors:f}=(0,T.useDispatch)(D),g=(0,T.useSelect)((t=>t(D).getHolderName(e)),[e]),v=(0,T.useSelect)((t=>t(D).getNumber(e)),[e]),y=(0,T.useSelect)((t=>t(D).getExpirationDate(e)),[e]),b=(0,T.useSelect)((t=>t(D).getInstallment(e)),[e]),E=(0,T.useSelect)((t=>t(D).getBrand(e)),[e]),w=(0,T.useSelect)((t=>t(D).getCvv(e)),[e]),C=(0,T.useSelect)((t=>t(D).getSaveCard(e)),[e]),I=(0,T.useSelect)((t=>t(D).getWalletId(e)),[e]),R=(0,T.useSelect)((t=>t(D).getErrors(e)),[e]),{validateAllFields:k}=m(e,R,f,r.fieldErrors),{onCheckoutValidation:S}=n;return(0,t.useEffect)((()=>S((()=>(0===I.length&&k(g,v,y,w),!0)))),[S,g,v,y,w,r,I]),{isLoading:a,setIsLoading:o,setHolderName:s,setNumber:i,setExpirationDate:l,setInstallment:u,setBrand:c,setCvv:d,setWalletId:h,setErrors:f,saveCardChangeHandler:t=>{p(e,t)},formatFieldId:t=>`pagarme_credit_card_${e}_${t}`,holderName:g,number:v,expirationDate:y,selectedInstallment:b,brand:E,cvv:w,saveCard:C,walletId:I,errors:R}})(a,o,r);return(0,t.createElement)(s,{isLoading:v},(0,t.createElement)("div",{className:"wc-block-components-form"},r?.walletEnabled&&r?.cards?.length>0&&(0,t.createElement)(N,{label:g,selectedCard:U,cards:r.cards,cardIndex:a,setSelectCard:P,setBrand:R}),0===U.length&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(f,{id:V("holder_name"),label:i,inputValue:q,setInputValue:b,cardIndex:a,errors:Y,setErrors:O,fieldErrors:r?.fieldErrors}),(0,t.createElement)(w,{id:V("number"),label:l,inputValue:_,setInputValue:E,brand:B,setBrand:R,brands:r?.brands,setIsLoading:y,cardIndex:a,errors:Y,setErrors:O,fieldErrors:r?.fieldErrors}),(0,t.createElement)(k,{id:V("expiry"),label:u,inputValue:j,setInputValue:C,cardIndex:a,errors:Y,setErrors:O,fieldErrors:r?.fieldErrors}),(0,t.createElement)(x,{id:V("cvv"),label:c,inputValue:F,setInputValue:S,cardIndex:a,errors:Y,setErrors:O,fieldErrors:r?.fieldErrors})),(0,t.createElement)(d,{label:p,installments:r?.installments,installmentsType:r?.installmentsType,selectedInstallment:A,setSelectedInstallment:I,brand:B,cartTotal:e.cartTotal.value,setIsLoading:y,cardIndex:a}),0===U.length&&r?.walletEnabled&&(0,t.createElement)(L,{label:h,checked:H,onChange:M})))};_.propType={billing:a().object.isRequired,components:a().object.isRequired,backendConfig:a().object.isRequired,cardIndex:a().number.isRequired,eventRegistration:a().object.isRequired};const j=_;var A=n(21),B=n.n(A);const F={token:"",errors:{}},H=(0,T.createReduxStore)("pagarme-googlepay",{reducer(e=F,t){switch(t.type){case"SET_PROPERTY_VALUE":return t.propertyName?{...e,[t.propertyName]:t.value}:e;case"RESET":return F;default:return e}},actions:{setToken:e=>({type:"SET_PROPERTY_VALUE",value:e,propertyName:"token"}),setErrors:e=>({type:"SET_PROPERTY_VALUE",value:e,propertyName:"errors"}),reset:()=>({type:"RESET"})},selectors:{getToken:e=>e.token,getErrors:e=>e.errors}});(0,T.register)(H);const U=H,Y=e=>{const n=wc.wcSettings.getSetting("woo-pagarme-payments-googlepay_data"),r=n.isSandboxMode?"TEST":"PRODUCTION",a=e?.billing?.billingAddress,{setToken:o}=(0,T.useDispatch)(U);return(0,t.createElement)(B(),{environment:r,buttonLocale:"pt",buttonType:"pay",paymentRequest:{apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:[{type:"CARD",parameters:{allowedAuthMethods:["PAN_ONLY"],allowedCardNetworks:n.allowedGoogleBrands},tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:"pagarme",gatewayMerchantId:n.accountId}}}],merchantInfo:{merchantId:n.merchantId,merchantName:n.merchantName},transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Total",totalPrice:(e.billing.cartTotal.value/100).toString(),currencyCode:"BRL",countryCode:"BR"}},onLoadPaymentData:e=>{if(function(e){const t=["first_name","last_name","email","phone","address_1","city","postcode","state","country"];for(const n of t)if(!e[n])return!1;return!0}(a)){let t=e.paymentMethodData.tokenizationData.token;o(t)}jQuery(".wc-block-components-checkout-place-order-button").click()}})};class $ extends Error{constructor(e){super(e),this.name=this.constructor.name}}const W=(e,t,n)=>{const r=`${e.replace("request.","").replace("card.","")}: ${t}`;return n.hasOwnProperty(r)?n[r]:""};async function z(e,t,n,r,a,o){const[s,i]=p(n),l={card:{holder_name:t,number:y(e),exp_month:s,exp_year:i,cvv:r}};try{const e=`https://api.pagar.me/core/v5/tokens?appId=${a}`,t=await fetch(e,{method:"POST",body:JSON.stringify(l)});if(!t.ok){const e=await t.text();if(0===e.length)return{errorMessage:o.serviceUnavailable};const n=((e,t)=>{let n="";for(const r in e.errors)for(const a of e.errors[r]||[]){const e=W(r,a,t);0!==e.length&&(n+=`${e}
`)}return n})(JSON.parse(e),o);return{errorMessage:n}}return{token:(await t.json()).id}}catch(e){return{errorMessage:o.serviceUnavailable}}}const J=(e,n,r,a)=>{const{reset:o}=(0,T.useDispatch)(D),{reset:s}=(0,T.useDispatch)(U),{onPaymentSetup:i}=r,l=(0,T.useSelect)((e=>e(D).getCards()));(0,t.useEffect)((()=>{o()}),[]),(0,t.useEffect)((()=>i((async()=>{try{if(a)return s(),{type:n.responseTypes.SUCCESS,meta:{paymentMethodData:{pagarme:JSON.stringify({googlepay:{googlepay:{payload:a}}}),payment_method:"googlepay"}}};let t=!1;if("object"==typeof l&&(t=Object.values(l).some((e=>Object.keys(e.errors).length>0))),t)return{type:n.responseTypes.ERROR,message:e.errorMessages.creditCardFormHasErrors};const r=await(async(e,t,n)=>{const r=[];for(let a=1;a0){r[a]={"wallet-id":d,brand:l,installment:u};continue}const p=await z(o,t,s,i,n.appId,n.errorMessages);if(p.errorMessage)throw new $(p.errorMessage);r[a]={token:p.token,brand:l,installment:u},c&&(r[a]["save-card"]=c)}return r})(l,1,e);return{type:n.responseTypes.SUCCESS,meta:{paymentMethodData:{pagarme:JSON.stringify({[e.key]:{cards:{...r}}}),payment_method:e.key}}}}catch(t){let r=e.errorMessages.serviceUnavailable;return t instanceof $&&(r=t.message),{type:n.responseTypes.ERROR,message:r}}}))),[i,l,e,a])},{registerPaymentMethod:X}=window.wc.wcBlocksRegistry,G=wc.wcSettings.getSetting("woo-pagarme-payments-credit_card_data"),Z=wc.wcSettings.getSetting("woo-pagarme-payments-googlepay_data"),Q=n=>{const r=(0,T.useSelect)((e=>e(U).getToken())),{emitResponse:a,eventRegistration:o}=n,s=Z.enabled,i=Z.hasSubscriptionInCart;return J(G,a,o,r),(0,t.createElement)("div",null,s&&!i&&(0,t.createElement)("div",null,(0,t.createElement)(Y,n),(0,t.createElement)("div",{className:"pagarme_creditcard_divider"},(0,t.createElement)("p",null,"Ou pague com cartão"))),!r&&(0,t.createElement)(j,e({},n,{backendConfig:G,cardIndex:1})))},K=({components:e})=>{const{PaymentMethodLabel:n}=e;return(0,t.createElement)(n,{text:G.label})};Q.propTypes={emitResponse:a().object,eventRegistration:a().object},K.propTypes={components:a().object},X({name:G.name,label:(0,t.createElement)(K,null),content:(0,t.createElement)(Q,null),edit:(0,t.createElement)(Q,null),canMakePayment:()=>!0,ariaLabel:G.ariaLabel})})()})(); \ No newline at end of file diff --git a/src/Block/ReactCheckout/AbstractCard.php b/src/Block/ReactCheckout/AbstractCard.php index cc046770..6aa1dca3 100644 --- a/src/Block/ReactCheckout/AbstractCard.php +++ b/src/Block/ReactCheckout/AbstractCard.php @@ -36,8 +36,7 @@ protected function getAdditionalPaymentMethodData() { 'brands' => $this->paymentModel->getConfigDataProvider()['brands'], 'errorMessages' => CardBlock::getCardErrorsMessagesTranslated(), 'cards' => $this->paymentModel->getCards(), - 'fieldErrors' => $this->getFieldErrors(), - 'googlepayEnable' => $this->config->getEnableGooglepay() === 'yes' + 'fieldErrors' => $this->getFieldErrors() ]; if ( $additionalData['walletEnabled'] ) { diff --git a/src/Block/ReactCheckout/GooglePay.php b/src/Block/ReactCheckout/GooglePay.php index 6755bcea..2aeffbec 100644 --- a/src/Block/ReactCheckout/GooglePay.php +++ b/src/Block/ReactCheckout/GooglePay.php @@ -3,6 +3,7 @@ namespace Woocommerce\Pagarme\Block\ReactCheckout; use Woocommerce\Pagarme\Model\Config; +use Woocommerce\Pagarme\Model\Subscription; use Woocommerce\Pagarme\Model\Payment\GooglePay as GooglePayModel; class GooglePay extends AbstractPaymentMethodBlock @@ -53,11 +54,13 @@ protected function jsUrl() public function getAdditionalPaymentMethodData() { return [ + 'enabled' => $this->config->getEnableGooglepay() === 'yes', 'accountId' => $this->config->getAccountId(), 'merchantName' => $this->config->getGooglepayGoogleMerchantName(), 'merchantId' => $this->config->getGooglepayGoogleMerchantId(), 'isSandboxMode' => $this->config->getIsSandboxMode(), - 'allowedGoogleBrands' => $this->getGooglepayBrands() + 'allowedGoogleBrands' => $this->getGooglepayBrands(), + 'hasSubscriptionInCart' => Subscription::hasSubscriptionProductInCart() ]; } } diff --git a/src/Model/SubscriptionMeta.php b/src/Model/SubscriptionMeta.php index bccbc3a2..b0ec870d 100644 --- a/src/Model/SubscriptionMeta.php +++ b/src/Model/SubscriptionMeta.php @@ -22,7 +22,7 @@ public function __construct($logger) public function saveCardInSubscriptionUsingOrderResponse($response) { $platformOrder = $response->getPlatformOrder()->getPlatformOrder(); - $subscription = $this->getSubscription($platformOrder->getCode()); + $subscription = $this->getSubscription($platformOrder->get_id()); $subscriptionCard = $this->getCardToProcessSubscription($subscription); $cardData = $this->getCardDataByResponse($response); if ( @@ -31,7 +31,7 @@ public function saveCardInSubscriptionUsingOrderResponse($response) ) { return; } - $this->saveCardDataToOrderAndSubscriptions($platformOrder->getCode(), $cardData); + $this->saveCardDataToOrderAndSubscriptions($platformOrder->get_id(), $cardData); } public function saveCardDataToOrderAndSubscriptions($orderId, $cardData) diff --git a/vendor/pagarme/pagarmecoreapi/src/Models/CreateCreditCardPaymentRequest.php b/vendor/pagarme/pagarmecoreapi/src/Models/CreateCreditCardPaymentRequest.php index 4a71b49e..7c665ca4 100644 --- a/vendor/pagarme/pagarmecoreapi/src/Models/CreateCreditCardPaymentRequest.php +++ b/vendor/pagarme/pagarmecoreapi/src/Models/CreateCreditCardPaymentRequest.php @@ -208,7 +208,7 @@ public function jsonSerialize() $json['operation_type'] = $this->operationType; $json['recurrency_cycle'] = $this->recurrencyCycle; $json['recurrence_cycle'] = $this->recurrenceCycle; - $json['payment_origin'] = $this->paymentOrigin; + $json['payment_origin'] = $this->paymentOrigin; return $json; }