UNPKG

@malga-checkout-full/core

Version:
1 lines 10.3 kB
import{r as t,c as o,h as a,F as i,H as e}from"./p-dc9e50be.js";import{c}from"./p-2a19115a.js";import"./p-a0ceaf8b.js";import{_ as s,Z as n}from"./p-a24853cf.js";import"./p-3e8ff66b.js";let r;const l=new Uint8Array(16);function h(){if(!r&&(r="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!r))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return r(l)}const u=[];for(let t=0;t<256;++t)u.push((t+256).toString(16).slice(1));const m={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function d(t,o,a){if(m.randomUUID&&!o&&!t)return m.randomUUID();const i=(t=t||{}).random||(t.rng||h)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,o){a=a||0;for(let t=0;t<16;++t)o[a+t]=i[t];return o}return function(t,o=0){return(u[t[o+0]]+u[t[o+1]]+u[t[o+2]]+u[t[o+3]]+"-"+u[t[o+4]]+u[t[o+5]]+"-"+u[t[o+6]]+u[t[o+7]]+"-"+u[t[o+8]]+u[t[o+9]]+"-"+u[t[o+10]]+u[t[o+11]]+u[t[o+12]]+u[t[o+13]]+u[t[o+14]]+u[t[o+15]]).toLowerCase()}(i)}const g=t=>11===t.length?"cpf":"cnpj",p=class{constructor(a){t(this,a),this.transactionSuccess=o(this,"transactionSuccess",7),this.transactionFailed=o(this,"transactionFailed",7),this.sandbox=!1,this.debug=!1,this.paymentMethods={pix:void 0,credit:void 0,boleto:void 0,nupay:void 0,drip:void 0},this.pageConfig={brandUrl:"",footerDescription:"",backRoute:"",delivery:0,products:[],internationalCustomer:!1},this.transactionConfig={statementDescriptor:"",amount:0,description:"",orderId:"",customerId:"",currency:"BRL",capture:!1,fraudAnalysis:null,paymentFlowMetadata:null,splitRules:null,providerReferenceKey:null},this.dialogConfig={show:!0},this.isLoading=!0,this.language="default",this.currentSection="identification",this.customerFormFields={name:"",email:"",phoneNumber:"",documentCountry:"",documentType:"",identification:"",zipCode:"",street:"",streetNumber:"",complement:"",district:"",city:"",state:"",country:""},this.handleChangeCustomization=t=>{t&&t.customization&&(this.customization=t.customization)},this.handleSetPaymentSessionData=t=>{this.paymentSession=t,this.isLoading=!1},this.handleChangeSection=t=>{this.currentSection=t},this.handleSetCustomerFormValues=(t,o)=>{this.customerFormFields=Object.assign(Object.assign({},this.customerFormFields),{[t]:o})},this.handleSetManyCustomerFormValues=t=>{this.customerFormFields=Object.assign(Object.assign({},this.customerFormFields),t)},this.handleFraudAnalysis=t=>{var o,a;const i=((t,o,a)=>!!this.paymentSession?(this.paymentSession&&this.paymentSession.items).map((t=>({name:t.name,unitPrice:t.unitPrice,quantity:t.quantity,sku:t.name,risk:"Low"}))):a?a.map((t=>({name:t.name,quantity:t.quantity,sku:t.sku,unitPrice:t.amount,risk:t.risk}))):[])(0,0,this.pageConfig.products);return this.transactionConfig.customerId?((t,o)=>({cart:t,usePartialCustomer:o}))(i,null===(o=this.transactionConfig.fraudAnalysis)||void 0===o?void 0:o.usePartialCustomer):((t,o,a)=>({customer:t,cart:o,usePartialCustomer:a}))(t,i,null===(a=this.transactionConfig.fraudAnalysis)||void 0===a?void 0:a.usePartialCustomer)},this.renderBrand=()=>this.customization&&this.customization.brandUrl?this.customization.brandUrl:this.pageConfig.brandUrl,this.handleGetAmount=()=>this.paymentSession?this.paymentSession.amount:this.transactionConfig.amount,this.handleGetProducts=()=>this.paymentSession?this.paymentSession.items.map((t=>({name:t.name,amount:t.unitPrice,quantity:t.quantity,description:t.description}))):this.pageConfig.products,this.handleChangeLanguage=t=>{this.language=t},this.handlePaymentMethods=()=>this.paymentSession?this.paymentSession.checkoutPaymentMethods:((t,o)=>{const a=t;return a.drip&&(a.drip=((t,o)=>{const a=o.map((t=>({id:d(),title:t.name,quantity:t.quantity,unitPrice:t.amount})));return{items:t.items||a,browser:t.browser||null}})(t.drip,o)),a})(this.paymentMethods,this.pageConfig.products)}componentWillLoad(){this.sessionId||(this.isLoading=!1),this.transactionConfig.customerId&&(this.currentSection="payments"),this.language=s(this.locale)}render(){const t=((t,o)=>{const a={zipCode:t.zipCode,street:t.street,streetNumber:t.streetNumber,complement:t.complement,district:t.district,city:t.city,state:t.state,country:t.country},i=Object.values(a).some((t=>t))?a:null,e=o?(t=>({type:t.documentType,country:t.documentCountry,number:t.identification}))(t):(t=>{const o=c(t.identification);return{type:g(o),country:"BR",number:o}})(t);return{name:t.name,email:t.email,phoneNumber:t.phoneNumber,document:e,address:i}})(this.customerFormFields,this.pageConfig.internationalCustomer),o=this.transactionConfig.customerId?null:t,s=this.paymentSession?this.paymentSession.currency:this.transactionConfig.currency,r=this.paymentSession?this.paymentSession.transactionConfig:this.transactionConfig,l=this.handlePaymentMethods(),h=this.handleFraudAnalysis(t);return a(e,{class:{"malga-checkout-full__container":!0,"malga-checkout-full__container--full-height":"identification"===this.currentSection}},a("malga-checkout-full-header",{locale:this.language,language:this.language,brand:this.renderBrand(),backRoute:this.pageConfig.backRoute,onChangeLanguage:({detail:{value:t}})=>this.handleChangeLanguage(t)}),a("malga-checkout-full-content",null,a("checkout-order-summary",{slot:"order",locale:this.language,label:n("page.order",this.language),amount:this.handleGetAmount(),products:this.handleGetProducts(),delivery:this.pageConfig.delivery,currency:s,isLoading:this.isLoading}),a("div",{slot:"informations",class:"malga-checkout-full__informations"},!this.transactionConfig.customerId&&a("checkout-accordion",{label:n("page.identification",this.language),isEditable:"identification"!==this.currentSection,opened:"identification"===this.currentSection,onExpandClick:()=>this.handleChangeSection("identification")},a("malga-checkout-full-identification",{locale:this.language,internationalCustomer:this.pageConfig.internationalCustomer,formValues:this.customerFormFields,onFieldChange:({detail:t})=>{this.handleSetCustomerFormValues(t.field,t.value)},onManyFieldsChange:({detail:t})=>{this.handleSetManyCustomerFormValues(t.customerFormValues)},onSubmitForm:()=>this.handleChangeSection("payments"),isLoading:this.isLoading})),a("checkout-accordion",{label:n("page.payment",this.language),opened:"payments"===this.currentSection||this.isLoading,onExpandClick:()=>this.handleChangeSection("payments")},a(i,null,a("span",{slot:"accordion-header-additional-information"},a("checkout-icon",{icon:"lock"}),n("page.secureAndEncrypted",this.language)),a("malga-checkout",{locale:this.language,publicKey:this.publicKey,clientId:this.clientId,sessionId:this.sessionId,merchantId:this.merchantId,idempotencyKey:this.idempotencyKey,sandbox:this.sandbox,debug:this.debug,transactionConfig:Object.assign(Object.assign({},r),{customerId:this.transactionConfig.customerId,customer:o,fraudAnalysis:h}),paymentMethods:l,dialogConfig:this.dialogConfig,onPaymentSuccess:({detail:{data:t}})=>{return this.transactionSuccess.emit({data:(o=t,Object.assign({},o))});var o},onPaymentFailed:({detail:{error:t}})=>this.transactionFailed.emit({error:t}),onPaymentSessionFetch:({detail:{paymentSession:t}})=>{this.handleChangeCustomization(t),this.handleSetPaymentSessionData(((t,o)=>{if(t)return Object.assign(Object.assign({},t),{checkoutPaymentMethods:t.checkoutPaymentMethods,transactionConfig:Object.assign(Object.assign({},o),t.transactionConfig),customization:t.customization})})(t,this.transactionConfig))},isLoading:this.isLoading,appInfo:Object.assign(Object.assign({},this.appInfo),{platform:{name:"Checkout Full SDK",version:"1.22.2"}})}))))),a("malga-checkout-full-footer",{language:this.language,onChangeLanguage:({detail:{value:t}})=>this.handleChangeLanguage(t),description:this.pageConfig.footerDescription}))}};p.style='@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap"); :root{--malga-checkout-color-page-background:#eef2f6;--malga-checkout-color-brand-accent-light:#79DBD4;--malga-checkout-color-brand-accent-normal:#39BFAD;--malga-checkout-color-brand-clean:#C3F4EF;--malga-checkout-color-brand-light:#79DBD4;--malga-checkout-color-brand-normal:#39BFAD;--malga-checkout-color-brand-middle:#2FAC9B;--malga-checkout-color-brand-dark:#147F70;--malga-checkout-color-grey-light:#666666;--malga-checkout-color-grey-normal:#4D4D4D;--malga-checkout-color-grey-middle:#333333;--malga-checkout-color-grey-dark:#1A1A1A;--malga-checkout-color-grey-darkness:#000000;--malga-checkout-color-accent-light:#ffffff;--malga-checkout-color-accent-normal:#F1F1F1;--malga-checkout-color-accent-middle:#CBCBCB;--malga-checkout-color-warning-light:#FFF8E6;--malga-checkout-color-warning-normal:#F9DF8D;--malga-checkout-color-warning-middle:#FFA400;--malga-checkout-color-warning-dark:#ED3A3D;--malga-checkout-color-modal-success:#00AE42;--malga-checkout-color-modal-error:#ED3A3D;--malga-checkout-color-modal-neutral:#4D4D4D;--malga-checkout-color-disabled:#F9F9F9;--malga-checkout-color-modal-action-button-error:#000000;--malga-checkout-color-modal-action-button-error-hover:#333333;--malga-checkout-color-modal-action-button-success:#000000;--malga-checkout-color-modal-action-button-success-hover:#333333;--malga-checkout-color-modal-action-button-success-font-color:#ffffff;--malga-checkout-color-modal-action-button-error-font-color:#ffffff;--malga-checkout-typography-family:"Inter", sans-serif;--malga-checkout-spacing-xxs:4px;--malga-checkout-spacing-xs:8px;--malga-checkout-spacing-sm:16px;--malga-checkout-spacing-default:24px;--malga-checkout-spacing-md:32px;--malga-checkout-spacing-lg:48px;--malga-checkout-spacing-xlg:64px;--malga-checkout-spacing-xxlg:96px;--malga-checkout-size-min-width:250px;--malga-checkout-border-radius-default:4px;--malga-checkout-border-radius-md:6px;--malga-checkout-border-radius-lg:20px;--malga-checkout-transition-slow:0.3s;--malga-checkout-transition-default:0.5s}body{padding:0;margin:0}.malga-checkout-full__container{display:flex;flex-direction:column;margin:0;padding:0;width:100%;height:100vh;background-color:var(--malga-checkout-color-page-background)}.malga-checkout-full__container--full-height{height:100%}.malga-checkout-full__informations>checkout-accordion:first-child{margin-bottom:var(--malga-checkout-spacing-sm)}';export{p as malga_checkout_full}