Created
July 16, 2025 14:06
-
-
Save teles/66c8564b3c6e69d30fb25b2226ca7e90 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*! For license information please see appmax.min.js.LICENSE.txt */ | |
| (()=>{"use strict";const e=class{constructor(e,t,n,a,r){this.number=e,this.holderName=t,this.expirationMonth=n,this.expirationYear=a,this.cvv=r}toJSON(){return{payment_data:{credit_card:{number:this.number,holder_name:this.holderName,expiration_month:this.expirationMonth,expiration_year:this.expirationYear,cvv:this.cvv}}}}},t=class{constructor(e){this.apiClient=e}async tokenizeCard(t,n){const a=new e(t.number,t.holderName,t.expirationMonth,t.expirationYear,t.cvv).toJSON(),r=await this.apiClient.post(`${"MISSING_ENV_VAR".API_APPMAX_URL}/v1/payments/tokenize`,{headers:{"Content-Type":"application/json","external-id":n},body:JSON.stringify(a)});if(r.ok){const{data:e}=await r.json();return e.token}throw new Error("Failed to tokenize card.")}},n=class{async get(e){return await fetch(e)}async post(e,t){return await fetch(e,{method:"POST",...t})}},a=class{constructor(e){this.apiClient=e}async getIP(){const e=await this.apiClient.get(`${"MISSING_ENV_VAR".API_APPMAX_URL}/ip`);if(e.ok)return await e.json();throw new Error("Failed to fetch IP.")}};var r={d:(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},o={};r.d(o,{A:()=>l,k:()=>c});var s=function(e,t,n,a){return new(n||(n=Promise))((function(r,o){function s(e){try{c(a.next(e))}catch(e){o(e)}}function i(e){try{c(a.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,i)}c((a=a.apply(e,t||[])).next())}))},i=function(e,t){var n,a,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function i(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,i[0]&&(s=0)),s;)try{if(n=1,a&&(r=2&i[0]?a.return:i[0]?a.throw||((r=a.return)&&r.call(a),0):a.next)&&!(r=r.call(a,i[1])).done)return r;switch(a=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,a=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((r=(r=s.trys).length>0&&r[r.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){s.label=i[1];break}if(6===i[0]&&s.label<r[1]){s.label=r[1],r=i;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(i);break}r[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],a=0}finally{n=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}};function c(){return s(this,void 0,Promise,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,new Promise((function(e,t){var n,a,r="Unknown";function o(t){e({isPrivate:t,browserName:r})}function s(e){return e===eval.toString().length}void 0!==(a=navigator.vendor)&&0===a.indexOf("Apple")&&s(37)?(r="Safari",void 0!==navigator.maxTouchPoints?function(){var e=String(Math.random());try{window.indexedDB.open(e,1).onupgradeneeded=function(t){var n,a,r=null===(n=t.target)||void 0===n?void 0:n.result;try{r.createObjectStore("test",{autoIncrement:!0}).put(new Blob),o(!1)}catch(e){var s=e;return e instanceof Error&&(s=null!==(a=e.message)&&void 0!==a?a:e),"string"!=typeof s?void o(!1):void o(s.includes("BlobURLs are not yet supported"))}finally{r.close(),window.indexedDB.deleteDatabase(e)}}}catch(e){o(!1)}}():function(){var e=window.openDatabase,t=window.localStorage;try{e(null,null,null,null)}catch(e){return void o(!0)}try{t.setItem("test","1"),t.removeItem("test")}catch(e){return void o(!0)}o(!1)}()):function(){var e=navigator.vendor;return void 0!==e&&0===e.indexOf("Google")&&s(33)}()?(n=navigator.userAgent,r=n.match(/Chrome/)?void 0!==navigator.brave?"Brave":n.match(/Edg/)?"Edge":n.match(/OPR/)?"Opera":"Chrome":"Chromium",void 0!==self.Promise&&void 0!==self.Promise.allSettled?navigator.webkitTemporaryStorage.queryUsageAndQuota((function(e,t){var n;o(Math.round(t/1048576)<2*Math.round((void 0!==(n=window).performance&&void 0!==n.performance.memory&&void 0!==n.performance.memory.jsHeapSizeLimit?performance.memory.jsHeapSizeLimit:1073741824)/1048576))}),(function(e){t(new Error("detectIncognito somehow failed to query storage quota: "+e.message))})):(0,window.webkitRequestFileSystem)(0,1,(function(){o(!1)}),(function(){o(!0)}))):void 0!==document.documentElement&&void 0!==document.documentElement.style.MozAppearance&&s(37)?(r="Firefox",o(void 0===navigator.serviceWorker)):void 0!==navigator.msSaveBlob&&s(39)?(r="Internet Explorer",o(void 0===window.indexedDB)):t(new Error("detectIncognito cannot determine the browser"))}))];case 1:return[2,e.sent()]}}))}))}"undefined"!=typeof window&&(window.detectIncognito=c);const l=c;var p=o.k;const d=class{async isPrivateMode(){try{return(await p()).isPrivate}catch(e){return!1}}},h=class{constructor(e){this.privacyService=e}async getFingerprint(){const e=navigator.userAgent,t=navigator.language,n=screen.width,a=screen.height,r=screen.colorDepth,o=navigator.deviceMemory||"unknown",s=await this.privacyService.isPrivateMode();return{userAgent:e,language:t,screenWidth:n,screenHeight:a,colorDepth:r,deviceMemory:o,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,hardwareConcurrency:navigator.hardwareConcurrency,touchPoints:navigator.maxTouchPoints||0,isPrivate:s}}},u=class{constructor(e){this.onSuccess=e.onSuccess,this.onError=e.onError,this.externalId=e.externalId||null,this.paymentService=new t(new n),this.ipService=new a(new n),this.fingerprintService=new h(new d),this.ip=null,this.initialize()}async initialize(){try{if(await this.fingerprintService.getFingerprint(),document.getElementsByClassName("appmax-ip").length){const e=await this.ipService.getIP();return this.ip=e.ip,void this.onSuccess({ip:this.ip})}if(document.querySelector("form[data-appmax-customer]")){const e=await this.ipService.getIP();this.ip=e.ip,this.onSuccess({ip:this.ip});try{const e=document.createElement("input");e.type="hidden",e.id="ip",e.name="ip",e.value=this.ip,document.querySelector("form[data-appmax-customer]").appendChild(e)}catch(e){console.error("Error fetching IP on load:",e)}}this.setupFormSubmission()}catch(e){console.error("Error fetching IP on load:",e)}}setupFormSubmission(){const e=document.querySelector("[data-appmax-checkout]");e&&e.addEventListener("submit",(async t=>{t.preventDefault(),await this.handleFormSubmit(e)}))}async handleFormSubmit(t){this.validateExternalId();const n=new FormData(t),a=new e(n.get("card-number"),n.get("card-holder-name"),n.get("exp-month"),n.get("exp-year"),n.get("cvv"));try{const e=await this.paymentService.tokenizeCard(a,this.externalId);this.onSuccess(e)}catch(e){this.onError("Failed to process payment: "+e.message)}}validateExternalId(){if(!this.externalId)throw new Error("External ID is required.")}};var y=class extends Error{metadata={};constructor(e){super(e),this.name="ExpressCheckoutError"}withMetadata(e){return this.metadata={...this.metadata,...e},this}},m=class extends y{constructor(e){super("Invalid merchant session: "+e),this.name="InvalidMerchantSessionError"}},g=class extends y{constructor(e){super("Strategy not supported: "+e),this.name="StrategyNotSupportedError"}},w=class extends y{constructor(){super("Payment sheet not initialized"),this.name="PaymentSheetNotInitializedError"}},S=class extends y{constructor(){super("No supported payment methods available."),this.name="NoStrategyAvailableError"}},f=class extends y{constructor(){super("You must select a payment method before executing the payment"),this.name="PaymentMethodNotSelectedError"}},v=class extends y{constructor(){super("You can only use one payment method at a time"),this.name="MultiplePaymentMethodsError"}},x=class extends y{constructor(e){super(`Handler for ${e} not found.`),this.name="HandlerNotFoundError"}},b=class extends y{constructor(){super("Payment authorization failed"),this.name="PaymentAuthorizationError"}},P=class e{reporters=[];static instance;constructor(){}static getInstance(){return e.instance||(e.instance=new e),e.instance}subscribe(e){this.reporters.some((t=>t.name===e.name))||this.reporters.push(e)}publish(e){this.reporters.forEach((t=>t.report(e)))}}.getInstance(),C=class{strategies;constructor(e){this.strategies=e}isAnyStrategySupported(){return this.strategies.some((e=>e.isSupported()))}async executePayment(e,t){let n=this.strategies.find((e=>e.isSupported()));if(!n)throw new S;try{return t.typeStrategy=n.name,n.initPaymentSheet(e),t.onPaymentSheetOpen(),await n.showPaymentSheet()?(t.onSessionEnded(),!0):(t.onPaymentSheetClose(),!1)}catch(t){throw t instanceof y&&P.publish(t.withMetadata({strategy:n.name,amount:e.total.amount})),t}}},E=class{session=null;configs;name="ApplePaySession";paymentSheetPromiseResolve;paymentSheetPromiseReject;constructor(e){this.configs=e}initPaymentSheet(e){if(!this.isSupported())throw new g("Apple Pay JS não é suportado neste ambiente");let t=this.configs,n={countryCode:t.countryCode,currencyCode:e.total.amount.currency,supportedNetworks:t.supportedNetworks,merchantCapabilities:t.merchantCapabilities,total:{label:e.total.label,amount:e.total.amount.value,type:"final"},lineItems:e.displayItems?.map((e=>({label:e.label,amount:e.amount.value})))};this.session=new ApplePaySession(3,n),this.session.onvalidatemerchant=async()=>{let n={...t.merchantSession.payload,cart:t.data?.cart};try{let e=await(await fetch(t.merchantSession.url,{method:"POST",body:JSON.stringify(n),headers:{"Content-Type":"application/json"}})).json();this.session?.completeMerchantValidation(e)}catch(n){n instanceof y&&P.publish(n.withMetadata({strategy:"ApplePaySessionStrategy",amount:e.total.amount,cart:t.data.cart}));let a=new m(String(n));throw P.publish(a.withMetadata({strategy:"ApplePaySessionStrategy",amount:e.total.amount,cart:t.data.cart})),a}},this.session.onpaymentauthorized=async e=>{let t=e.payment.token,n=await this.configs.onPaymentAuthorized(t);return this.session?.completePayment(n?ApplePaySession.STATUS_SUCCESS:ApplePaySession.STATUS_FAILURE),this.paymentSheetPromiseResolve&&this.paymentSheetPromiseReject&&(n?this.paymentSheetPromiseResolve(n):this.paymentSheetPromiseReject(new b),this.paymentSheetPromiseResolve=void 0,this.paymentSheetPromiseReject=void 0),n}}async showPaymentSheet(){if(!this.session)throw new w;return new Promise(((e,t)=>{this.paymentSheetPromiseResolve=e,this.paymentSheetPromiseReject=t,this.session.oncancel=()=>{e(!1)},this.session.begin()}))}isSupported(){if(typeof ApplePaySession>"u")return!1;try{return ApplePaySession.canMakePayments()}catch{return!1}}},k=class{request=null;configs;name="PaymentRequest";constructor(e){this.configs=e}initPaymentSheet(e){if(!this.isSupported())throw new g("Native Apple Pay is not supported");let t=this.configs,n={supportedMethods:t.supportedMethods,data:{version:3,merchantIdentifier:t.merchantIdentifier,merchantCapabilities:t.merchantCapabilities,supportedNetworks:t.supportedNetworks,countryCode:t.countryCode}},a=new PaymentRequest([n],e,{});a.addEventListener("merchantvalidation",(async n=>{let a=n;try{let e={...t.merchantSession.payload,cart:t.data?.cart},n=await fetch(t.merchantSession.url,{method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/json"}}).then((e=>e.json()));a.complete(n)}catch(n){throw n instanceof y&&P.publish(n.withMetadata({strategy:"PaymentRequestStrategy",amount:e.total.amount,cart:t.data.cart})),new m(String(n))}})),this.request=a}async showPaymentSheet(){if(!this.request)throw new w;try{if("function"!=typeof this.request.show)throw new y("Payment failed");let e=await this.request.show(),t=e.details,n=await this.configs.onPaymentAuthorized(t);if(!n)throw e.complete("fail"),new b;return e.complete("success"),n}catch(e){if(e instanceof Error&&"AbortError"===e.name)return!1;throw e}}isSupported(){return"PaymentRequest"in window&&"function"==typeof window.PaymentRequest}},A=class extends k{name="ApplePaymentRequest";isSupported(){if(!super.isSupported())return!1;if(/^((?!chrome|android).)*safari/i.test(navigator.userAgent)){let e=navigator.userAgent.match(/Version\/(\d+\.\d+)/);if(e){let t=parseFloat(e[1]);if(navigator.userAgent.includes("Macintosh")&&t>=11.1||/iPad|iPhone|iPod/.test(navigator.userAgent)&&t>=11.3)return!0}}return!1}},_=class{handlers=new Map;configs;options;selectedHandlerType=null;constructor(e,t){this.configs=e,this.options=t,this.options.errorReporter&&P.subscribe(this.options.errorReporter)}isApplePaySupported(){let e=this.handlers.get("apple-pay");return!!e&&e.isAnyStrategySupported()}applePay(){this.validateNoHandlerSelected(),this.selectedHandlerType="apple-pay",this.options.eventTracker.typeHandler=this.selectedHandlerType,this.options.eventTracker.onButtonClick();let e={...this.configs,supportedMethods:"https://apple.com/apple-pay"},t=new E(e),n=new A(e),a=new C([t,n]);return this.handlers.set("apple-pay",a),this}async execute(e){if(null===this.selectedHandlerType){let t=(new f).withMetadata({selectedHandlerType:this.selectedHandlerType,amount:e.total.amount,cart:this.configs.data?.cart});throw P.publish(t),t}let t=this.handlers.get(this.selectedHandlerType);if(!t)throw new x(this.selectedHandlerType).withMetadata({selectedHandlerType:this.selectedHandlerType,amount:e.total.amount});try{return t.executePayment(e,this.options.eventTracker)}catch(t){throw t instanceof y&&P.publish(t.withMetadata({amount:e.total.amount,cart:this.configs.data?.cart})),t}}validateNoHandlerSelected(){if(null!==this.selectedHandlerType)throw(new v).withMetadata({selectedHandlerType:this.selectedHandlerType})}},I=class{_typeHandler;_typeStrategy;set typeHandler(e){this._typeHandler=e}set typeStrategy(e){this._typeStrategy=e}onButtonClick(){console.log(`[DEBUG] Button clicked: Type: ${this._typeHandler}, Strategy: Not defined yet`)}onSessionEnded(){console.log(`[DEBUG] Session ended: Type: ${this._typeHandler}, Strategy: ${this._typeStrategy}`)}onPaymentSheetOpen(){console.log(`[DEBUG] On Payment Sheet Open: Type: ${this._typeHandler}, Strategy: ${this._typeStrategy}`)}onPaymentAuthorized(){console.log(`[DEBUG] Payment authorized: Type: ${this._typeHandler}, Strategy: ${this._typeStrategy}`)}onPaymentSheetClose(){console.log(`[DEBUG] Sheet closed: Type: ${this._typeHandler}, Strategy: ${this._typeStrategy}`)}},L=class{name="";async report(e){await this.prepare(e)}async prepare(e){try{let t={...this.captureCommonData(),name:e.name,message:e.message,stack:e.stack,metadata:e.metadata||{}};await this.send(t)}catch(e){console.error("Erro ao reportar:",e)}}captureCommonData(){return{href:window.location.href,userAgent:navigator.userAgent,timestamp:(new Date).toISOString()}}},M=class extends L{name="LogErrorReporter";async send(e){try{console.group("Erro Reportado"),console.log("Timestamp:",e.timestamp),console.log("Carrinho:",e.metadata.cart),console.log("URL:",e.href),console.log("User Agent:",e.userAgent),console.log("Nome do erro:",e.name),console.log("Mensagem do erro:",e.message),console.groupCollapsed("Metadados"),Object.entries(e.metadata).forEach((([e,t])=>{console.log(`${e}:`,t)})),console.groupEnd(),console.groupCollapsed("Stack trace"),console.log(e.stack),console.groupEnd(),console.groupEnd()}catch(e){console.error("Erro ao exibir relatório no console:",e)}}},T=class extends L{name="SlackErrorReporter";slackWebhookUrl;constructor(e){super(),this.slackWebhookUrl=e}async send(e){if("PaymentAuthorizationError"!==e.name)try{let t=this.formatSlackMessage(e),n=await fetch(this.slackWebhookUrl,{method:"POST",body:JSON.stringify(t)});if(!n.ok)throw new Error(`Falha ao enviar mensagem para o Slack: ${n.statusText}`)}catch(e){console.error("Erro ao enviar relatório para o Slack:",e)}}formatSlackMessage(e){let t=e.metadata.cart;return{blocks:[{type:"header",text:{type:"plain_text",text:"Novo erro detectado",emoji:!0}},{type:"divider"},{type:"rich_text",elements:[{type:"rich_text_section",elements:[{type:"text",text:"Detalhes do Erro:",style:{bold:!0}}]},{type:"rich_text_list",style:"bullet",elements:[{type:"rich_text_section",elements:[{type:"text",text:"Timestamp: "},{type:"text",text:e.timestamp,style:{bold:!0}}]},{type:"rich_text_section",elements:[{type:"text",text:"Carrinho: "},{type:"text",text:t||"N/A",style:{bold:!0}}]},{type:"rich_text_section",elements:[{type:"text",text:"URL: "},{type:"link",url:e.href,text:e.href,style:{bold:!0}}]},{type:"rich_text_section",elements:[{type:"text",text:"User Agent: "},{type:"text",text:e.userAgent,style:{bold:!0}}]},{type:"rich_text_section",elements:[{type:"text",text:"Nome do erro: "},{type:"text",text:e.name,style:{bold:!0}}]},{type:"rich_text_section",elements:[{type:"text",text:"Mensagem do erro: "},{type:"text",text:e.message,style:{bold:!0}}]}]}]},{type:"divider"},{type:"rich_text",elements:[{type:"rich_text_section",elements:[{type:"text",text:"Metadados:",style:{bold:!0}}]},{type:"rich_text_list",style:"bullet",elements:Object.entries(e.metadata).map((([e,t])=>({type:"rich_text_section",elements:[{type:"text",text:`${e}: `},{type:"text",text:JSON.stringify(t,null,2),style:{bold:!0}}]})))}]},{type:"divider"},{type:"rich_text",elements:[{type:"rich_text_section",elements:[{type:"text",text:"Stack trace:",style:{bold:!0}}]},{type:"rich_text_preformatted",elements:[{type:"text",text:e.stack}]}]}]}}};const R=class{static convert(e){const t=e.freight?{label:"Frete",amount:{currency:"BRL",value:e.freight.toFixed(2)}}:null,n=e.discount?{label:"Desconto",amount:{currency:"BRL",value:e.discount.toFixed(2)}}:null;return{displayItems:[...e.products?e.products.map((e=>({label:e.name,amount:{currency:"BRL",value:(e.price*e.quantity).toFixed(2)}}))):[],...t?[t]:[],...n?[n]:[]],total:{label:"Total",amount:{currency:"BRL",value:e.total.toFixed(2)}}}}},D=class{static get webhookUrl(){return""}static get merchantSessionUrl(){return"https://api-checkout-max-develop-k8s.sandboxappmax.com.br/api/v1/integrations/apple-pay/merchant-session"}static get isApplePayEnabled(){return!0}static get isLocalhost(){return!("undefined"==typeof window||!window.location||"localhost"!==window.location.hostname&&"127.0.0.1"!==window.location.hostname)}static get merchantIdentifier(){return"platformintegrator.br.com.appmax.local"}};var N;!function(e){e.supports3DS="supports3DS",e.supportsCredit="supportsCredit",e.supportsDebit="supportsDebit"}(N||(N={}));const H=class{checkoutDataToDetails;updatedCheckoutData;onPaymentAuthorized;constructor(e,t){this.checkoutDataToDetails=R,this.updatedCheckoutData=e,this.onPaymentAuthorized=t}getInstance(){const e=new I,t=new T(D.webhookUrl),n=new M,a=D.isLocalhost?n:t;return new _({merchantSession:{url:D.merchantSessionUrl,payload:{store_url:"codepen.io"}},merchantIdentifier:D.merchantIdentifier,merchantCapabilities:[N.supports3DS,N.supportsCredit,N.supportsDebit],supportedNetworks:["visa","masterCard","amex","elo"],countryCode:"BR",onPaymentAuthorized:async e=>{try{return await this.onPaymentAuthorized(e).then((()=>!0)).catch((()=>!1))}catch{return!1}}},{eventTracker:e,errorReporter:a})}isSupported(){try{return this.getInstance().applePay().isApplePaySupported()}catch(e){return!1}}async pay(){try{const e=this.checkoutDataToDetails.convert(this.updatedCheckoutData);return await this.getInstance().applePay().execute(e)}catch(e){throw new Error("Error processing payment")}}};class U{onSuccess;onError;onUpdate;externalId;expressCheckoutHandler=H;static APPLE_PAY_SELECTOR="[data-appmax-apple-pay]";constructor(e){this.onSuccess=e.onSuccess,this.onError=e.onError,this.onUpdate=e.onUpdate,this.externalId=e.externalId}async initialize(){try{this.isApplePaySupported()&&D.isApplePayEnabled?(this.injectApplePayStyles(),this.replaceApplePayButton(),this.setupFormSubmission(),this.setupApplePayClick()):this.hideApplePayElements()}catch(e){console.error(">>> ERROR initializing ApplePayPaymentFormHandler",e)}}replaceApplePayButton(){const e=document.querySelector(".appmax-apple-pay-btn");e&&(e.innerHTML='\n <button data-appmax-apple-pay class="applepay-button">\n <span class="applepay-button__label">Pagar com</span>\n <svg class="applepay-button__logo" x="87.5" y="7.92" height="15" width="35" viewBox="0 0 105 43" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g fill="#fff"><path d="M19.4028,5.5674 C20.6008,4.0684 21.4138,2.0564 21.1998,0.0004 C19.4458,0.0874 17.3058,1.1574 16.0668,2.6564 C14.9538,3.9414 13.9688,6.0374 14.2258,8.0074 C16.1948,8.1784 18.1618,7.0244 19.4028,5.5674"></path><path d="M21.1772,8.3926 C18.3182,8.2226 15.8872,10.0156 14.5212,10.0156 C13.1552,10.0156 11.0642,8.4786 8.8022,8.5196 C5.8592,8.5626 3.1282,10.2276 1.6342,12.8746 C-1.4378,18.1696 0.8232,26.0246 3.8112,30.3376 C5.2622,32.4716 7.0102,34.8206 9.3142,34.7366 C11.4912,34.6506 12.3442,33.3266 14.9902,33.3266 C17.6352,33.3266 18.4042,34.7366 20.7082,34.6936 C23.0972,34.6506 24.5922,32.5586 26.0422,30.4226 C27.7072,27.9906 28.3882,25.6426 28.4312,25.5126 C28.3882,25.4706 23.8232,23.7186 23.7812,18.4676 C23.7382,14.0706 27.3652,11.9786 27.5362,11.8496 C25.4882,8.8196 22.2872,8.4786 21.1772,8.3926"></path><path d="M85.5508,43.0381 L85.5508,39.1991 C85.8628,39.2421 86.6158,39.2871 87.0158,39.2871 C89.2138,39.2871 90.4558,38.3551 91.2108,35.9581 L91.6548,34.5371 L83.2428,11.2321 L88.4368,11.2321 L94.2958,30.1421 L94.4068,30.1421 L100.2668,11.2321 L105.3278,11.2321 L96.6048,35.7141 C94.6078,41.3291 92.3208,43.1721 87.4828,43.1721 C87.1048,43.1721 85.8838,43.1271 85.5508,43.0381"></path><path d="M42.6499,19.3555 L48.3549,19.3555 C52.6829,19.3555 55.1469,17.0255 55.1469,12.9855 C55.1469,8.9455 52.6829,6.6375 48.3769,6.6375 L42.6499,6.6375 L42.6499,19.3555 Z M49.6869,2.4425 C55.9009,2.4425 60.2289,6.7265 60.2289,12.9625 C60.2289,19.2225 55.8129,23.5285 49.5309,23.5285 L42.6499,23.5285 L42.6499,34.4705 L37.6779,34.4705 L37.6779,2.4425 L49.6869,2.4425 Z"></path><path d="M76.5547,25.7705 L76.5547,23.9715 L71.0287,24.3275 C67.9207,24.5275 66.3007,25.6815 66.3007,27.7015 C66.3007,29.6545 67.9887,30.9195 70.6287,30.9195 C74.0027,30.9195 76.5547,28.7665 76.5547,25.7705 M61.4617,27.8345 C61.4617,23.7285 64.5917,21.3755 70.3627,21.0205 L76.5547,20.6425 L76.5547,18.8675 C76.5547,16.2705 74.8457,14.8495 71.8057,14.8495 C69.2967,14.8495 67.4777,16.1375 67.0997,18.1125 L62.6167,18.1125 C62.7497,13.9615 66.6567,10.9435 71.9387,10.9435 C77.6207,10.9435 81.3267,13.9175 81.3267,18.5345 L81.3267,34.4705 L76.7327,34.4705 L76.7327,30.6305 L76.6217,30.6305 C75.3127,33.1395 72.4267,34.7145 69.2967,34.7145 C64.6807,34.7145 61.4617,31.9625 61.4617,27.8345"></path></g></g></svg>\n </button>\n')}hideApplePayElements(){const e=document.querySelector(U.APPLE_PAY_SELECTOR),t=document.querySelector("[data-appmax-apple-pay-wrapper]");e&&(e.style.display="none"),t&&(t.style.display="none")}injectApplePayStyles(){const e="applepay-button-styles";if(document.getElementById(e))return;const t=document.createElement("style");t.id=e,t.textContent="\n .applepay-button[disabled] { \n background-color: rgba(0,0,0,.75); \n cursor: not-allowed; \n }\n .applepay-button { \n font-family: -apple-system,apple-pay-btn-en-US,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,sans-serif;\n background-color: #000;\n color: #fff;\n border: none;\n padding: 10px 20px;\n border-radius: 8px;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n width: 100%;\n font-size: 20px;\n height: 52px;\n margin-top: auto;\n letter-spacing: .22px;\n margin-bottom: 10px; \n }\n .applepay-button__label { \n margin-right: 10px; \n }\n .applepay-button__logo { \n width: auto; \n height: 22px; \n margin-top: 2px; \n }\n",document.head.appendChild(t)}setupFormSubmission(){const e=document.querySelector("[data-appmax-checkout]");e&&this.isApplePaySupported()&&e.addEventListener("submit",(e=>e.preventDefault()))}setupApplePayClick(){const e=document.querySelector(U.APPLE_PAY_SELECTOR);e&&this.isApplePaySupported()&&e.addEventListener("click",(()=>this.handleApplePayClick()))}isApplePaySupported(){return new this.expressCheckoutHandler(this.buildEmptyData(),this.onSuccess).isSupported()}async handleApplePayClick(){this.validateExternalId();const e=await this.onUpdate();try{const t=new this.expressCheckoutHandler(e,this.onSuccess);await t.pay()}catch(e){this.onError(String(e))}}buildEmptyData(){return{total:0,freight:0,discount:0,installments:0,products:[]}}validateExternalId(){if(!this.externalId)throw new Error("External ID is required.")}}const O=U,z=function(e,t,n,a=null){new O({onSuccess:e,onError:t,onUpdate:n,externalId:a}).initialize()},B={init(e,t,n=null,a=null){new u({onSuccess:e,onError:t,externalId:n}).initialize(),"function"==typeof a&&z(e,t,a,n)}};window.AppCheckout=B,window.AppmaxScripts=B})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment