@ikas/storefront 4.9.0 → 4.10.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as e,__generator as t,__assign as i}from'./../../ext/tslib/tslib.es6.js';import{makeAutoObservable as s}from"mobx";import n from"lodash/cloneDeep";import r from"lodash/sortBy";import"../../models/data/blog/category/index.js";import"../../models/data/blog/content/index.js";import"../../models/data/blog/meta-data/index.js";import"../../models/data/blog/tag/index.js";import"../../models/data/blog/index.js";import"../../models/data/brand/index.js";import{IkasCouponCodeRequirement as o,IkasPaymentMethodType as a,IkasPaymentGatewayType as c,IkasOrderShippingMethod as d,IkasCartCreatedBy as u,IkasTransactionStatus as l,IkasCartCampaignOfferStatus as h,IkasCampaignOfferTargetPageType as p}from"@ikas/storefront-models";import"../../models/data/campaign-offer/index.js";import"../../models/data/cart/campaign-offer/index.js";import"../../models/data/cart/index.js";import"../../models/data/category/path-item/index.js";import"../../models/data/category/index.js";import{IkasCheckout as m}from"../../models/data/checkout/index.js";import{IkasCheckoutSettings as f}from"../../models/data/checkout-settings/index.js";import"../../models/data/city/index.js";import"../../models/data/country/index.js";import"../../models/data/customer/address/region/index.js";import{IkasCustomerAddress as g}from"../../models/data/customer/address/index.js";import{IkasLocalizedCustomerAddress as v}from"../../models/data/customer/address/ikas-localized-customer-address.js";import"../../models/data/customer/attribute/index.js";import"../../models/data/customer/review/summary/index.js";import"../../models/data/customer/review/index.js";import"../../models/data/customer/index.js";import"../../models/data/district/index.js";import"../../models/data/favorite-product/index.js";import"../../models/data/filter-category/index.js";import"../../models/data/html-meta-data/index.js";import"../../models/data/image/index.js";import{IkasMerchantSettings as y}from"../../models/data/merchant-settings/index.js";import"../../models/data/order/address/region/index.js";import"../../models/data/order/address/index.js";import{IkasOrderCustomer as S}from"../../models/data/order/customer/index.js";import"../../models/data/order/line-item/option/value/index.js";import"../../models/data/order/line-item/variant/value/index.js";import"../../models/data/order/line-item/variant/index.js";import"../../models/data/order/line-item/index.js";import"../../models/data/order/package/index.js";import"../../models/data/order/transaction/index.js";import"../../models/data/order/index.js";import"../../models/data/payment-gateway/index.js";import"../../models/data/product/attribute-value/index.js";import"../../models/data/product/filter/index.js";import"../../models/data/product/option-set/option/index.js";import"../../models/data/product/option-set/index.js";import"../../models/data/product/stock-location/index.js";import"../../models/data/product/variant/price/index.js";import"../../models/data/product/variant/index.js";import"../../models/data/variant-type/index.js";import{IkasProduct as k}from"../../models/data/product/index.js";import"../../models/data/raffle/index.js";import"../../models/data/shipping-zone/state/city/district/region/index.js";import"../../models/data/state/index.js";import"../../models/data/theme-json/index.js";import"../../models/data/theme-json/component/index.js";import"../../models/data/theme-json/custom-data/index.js";import"../../models/data/variant-type/variant-value/index.js";import{LocalizedAddressModel as b}from"@ikas/localized-address";import"../../models/ui/blog-list/index.js";import"../../models/ui/blog-category-list/index.js";import"../../models/ui/brand-list/index.js";import"../../models/ui/category-list/index.js";import"../../models/ui/product-list/index.js";import"../../models/ui/product-attribute-detail/index.js";import"../../models/ui/product-attribute-list/index.js";import"../../models/ui/customer-review-list/index.js";import"../../models/ui/customer-review-summary-list/index.js";import"../../models/ui/validator/index.js";import"../../models/ui/validator/rules/index.js";import"../../models/ui/validator/form/login.js";import"../../models/ui/validator/form/address.js";import"../../models/ui/validator/form/ikas-address.js";import"../../models/ui/validator/form/register.js";import"../../models/ui/validator/form/contact-form.js";import"../../models/ui/validator/form/forgot-password.js";import"../../models/ui/validator/form/recover-password.js";import"../../models/ui/validator/form/account-info.js";import"../../models/ui/validator/form/raffle-form.js";import"../../models/ui/validator/form/customer-review.js";import"../../models/ui/raffle-list/index.js";import C from"./components/credit-card-form/model.js";import P from"../../store/customer/api.js";import I from"../../store/checkout/index.js";import A from"../../store/cart/api.js";import w,{MFS_ELEMENT_ID as N,MFS_SCRIPT_URL as j}from"./modelMasterPass.js";import O from"../../store/product/index.js";import{IkasBaseStore as E}from"../../store/base.js";import"../../store/customer/index.js";import"../../store/cart/index.js";import{IkasStorefrontConfig as R}from"@ikas/storefront-config";import{Analytics as x}from"../../analytics/analytics.js";import"../../analytics/head/index.js";import{SaveCartInput as D,CheckStocksLineInput as T}from"@ikas/storefront-api";import G from"../../models/data/order/address/ikas-localized-order-address.js";import L from"../../store/location/index.js";import{getCookieValue as M}from"../../utils/helper.js";var V,_,U=/^\d+$/,F="undefined"==typeof localStorage,K=function(){function U(d,u,v,y,U,K,Y,H,q,W){var Q=this;this.storefront=null,this.isCheckoutLoaded=!1,this.isErrorsVisible=!1,this.isStepLoading=!1,this.isTermsAndConditionsChecked=!1,this.isChangingShippingMethod=!1,this.isContactModalVisible=!1,this.isEPayKolayPayment=!1,this.step=V.INFO,this.customizationProps=null,this.cardData=null,this.paymentGateways=[],this.installmentInfo=null,this.useDifferentAddress=!1,this.shouldSaveAddress=!0,this.addressTitle="",this.shippingCountryIds=null,this.selectedShippingAddressId="-1",this.selectedBillingAddressId="-1",this.stockLocations=[],this.availableStockLocations=[],this.deliveryMethod="address",this.stripeResponse=null,this.klarnaResponse=null,this.isKlarnaPaymentCompleted=!1,this.adyenResponse=null,this.payPalClientIdResponse=null,this.paypalOrderResponse=null,this.shippingZones=null,this.policyModalTitle="",this.policyModalText="",this.error=null,this.couponError=null,this.showTestModal=!1,this.init=function(){return e(Q,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return[4,this.countrySettings.waitUntilInitialized()];case 1:return e.sent(),[4,E.getInstance().customerStore.waitUntilInitialized()];case 2:return e.sent(),this.createCustomer(),this.createShippingAddress(),this.createBillingAddress(),[4,this.getCampaignOffer()];case 3:return e.sent(),[4,this.initStep()];case 4:return e.sent(),[2]}}))}))},this.initStep=function(){return e(Q,void 0,void 0,(function(){var e,s,n,r,a,c,d;return t(this,(function(t){switch(t.label){case 0:if(R.getIsEditor())return this.step=V.INFO,this.isCheckoutLoaded=!0,[2];if(e=new URLSearchParams(window.location.search),s=e.get("step"),n=e.get("failed"),r=e.get("error"),s){if(this.step=s,this.step===V.SHIPPING&&!this.canProceedToShipping)return[2,this.changeStep(V.INFO)];if(this.step!==V.PAYMENT||this.canProceedToPayment){if(this.step===V.SUCCESS&&!this.canProceedToPayment)return[2,this.changeStep(V.INFO)];if(![V.INFO,V.SUCCESS,V.SHIPPING,V.PAYMENT].includes(this.step))return[2,this.changeStep(V.INFO)]}else{if(!this.isInStoreDelivery)return this.isValidShippingSettings?[2,this.changeStep(V.INFO)]:[2,this.changeStep(V.SHIPPING)];this.deliveryMethod="in-store"}}return n&&(this.error={type:_.PAYMENT_ERROR,data:r||null}),this.step!==V.SHIPPING&&this.step!==V.PAYMENT||this.isCouponCodeRequirementInvisible||(this.checkoutSettings=new f(i(i({},this.checkoutSettings),{couponCodeRequirement:o.DEFAULT}))),this.step!==V.INFO?[3,6]:this.isDigitalOnly?[3,3]:[4,this.getAvailableShippingZones()];case 1:return t.sent(),this.createCustomer(),this.createShippingAddress(),this.createBillingAddress(),[4,this.getShippingCountries()];case 2:t.sent(),this.checkShippingCountries(),t.label=3;case 3:return[4,this.getStockLocations()];case 4:return t.sent(),[4,this.getAvailableStockLocations()];case 5:t.sent(),this.isInStoreDelivery&&(this.deliveryMethod="in-store"),t.label=6;case 6:return this.step!==V.SHIPPING||1!==(null===(c=this.checkout.availableShippingMethods)||void 0===c?void 0:c.length)||this.checkoutSettings.isGiftPackageEnabled||(this.step=V.PAYMENT,this.router.replace("/checkout?id=".concat(this.checkout.id,"&step=").concat(this.step),void 0,{shallow:!0})),this.step!==V.SHIPPING||(null===(d=this.checkout.availableShippingMethods)||void 0===d?void 0:d.length)?this.step!==V.PAYMENT&&this.step!==V.SUCCESS?[3,10]:[4,this.listPaymentGateways()]:(this.error={type:_.NO_SHIPPING_ERROR},this.isCheckoutLoaded=!0,[2]);case 7:return t.sent(),this.isInStoreDelivery?(this.deliveryMethod="in-store",[4,this.getStockLocations()]):[3,9];case 8:t.sent(),t.label=9;case 9:if(!this.paymentGateways.length)return this.error={type:_.NO_SHIPPING_ERROR},this.isCheckoutLoaded=!0,[2];t.label=10;case 10:return this.step===V.SUCCESS?[3,14]:this.checkout.isComplete?[2,this.changeStep(V.SUCCESS)]:[3,11];case 11:return[4,this.initialStockCheck()];case 12:t.sent(),t.label=13;case 13:return[3,16];case 14:return[4,this.getSuccessTransaction()];case 15:t.sent(),this.successTransaction&&(a=this.successTransaction.paymentGatewayId,this.checkout.selectedPaymentGateway=this.paymentGateways.find((function(e){return e.id===a}))),t.label=16;case 16:return this.isCheckoutLoaded=!0,x.checkoutStep(this.checkout,this.step),[2]}}))}))},this.getSuccessTransaction=function(){return e(Q,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return[4,P.listOrderTransactions({orderId:{eq:this.checkout.id}})];case 1:return e=t.sent(),this.successTransaction=e.isSuccess&&(null===(i=e.data)||void 0===i?void 0:i.length)?e.data[e.data.length-1]:void 0,[2]}}))}))},this.saveCart=function(){return e(Q,void 0,void 0,(function(){var e,i,s,n;return t(this,(function(t){switch(t.label){case 0:return e=new D(this.checkout),"in-store"!==this.deliveryMethod?[3,2]:[4,this.inStockDeliveryInputData(e)];case 1:e=t.sent(),t.label=2;case 2:return this.step!==V.INFO&&this.step!==V.SHIPPING||this.isDigitalOnly||(e.billingAddress=null),this.isDigitalOnly&&(e.shippingAddress=null),[4,A.saveCart({input:e})];case 3:if((null==(i=t.sent())?void 0:i.graphQLErrors)&&i.graphQLErrors.length)throw s=i.graphQLErrors[0],"CUSTOMER_LOGIN_REQUIRED"===(null===(n=s.extensions)||void 0===n?void 0:n.code)?{type:_.CUSTOMER_LOGIN_REQUIRED_ERROR}:{type:_.API_ERROR,data:i.firstErrorMessage};return[2,i.data]}}))}))},this.inStockDeliveryInputData=function(i){return e(Q,void 0,void 0,(function(){var e,s,n=this;return t(this,(function(t){return e=i,(s=this.stockLocations.find((function(e){return e.id===n.checkout.stockLocationId})))&&e.shippingAddress&&s.address&&(e.shippingAddress.country=s.address.country,e.shippingAddress.city=s.address.city,e.shippingAddress.state=s.address.state,e.shippingAddress.district=s.address.district,e.shippingAddress.postalCode=s.address.postalCode,e.shippingAddress.addressLine1=s.address.address||"",e.shippingAddress.addressLine2=null),[2,e]}))}))},this.checkStocks=function(){return e(Q,void 0,void 0,(function(){var e,i,s,n,r,o,a,c,d,u,l,h;return t(this,(function(t){switch(t.label){case 0:return this.isManualOrder?[2]:(e=this.checkout.items.map((function(e){return{quantity:e.quantity,variantId:e.variant.id,productId:e.variant.productId}})),[4,I.checkStocks({lines:e.map((function(e){return new T(e)})),stockLocationIdList:(null===(u=R.getStockLocationIds())||void 0===u?void 0:u.length)?R.getStockLocationIds():null})]);case 1:if(!(i=t.sent()).isSuccess)throw{type:_.API_ERROR,data:i.firstErrorMessage};if(null==(s=null===(h=null===(l=i.data)||void 0===l?void 0:l.lines)||void 0===h?void 0:h.filter((function(e){return!e.isAvailable})))?void 0:s.length){for(n=[],r=function(e){var t=o.checkout.items.find((function(t){return t.variant.id===e.variantId}));t&&n.push({item:t,stockCount:e.stockCount})},o=this,a=0,c=s;a<c.length;a++)d=c[a],r(d);throw{type:_.STOCK_ERROR,data:n}}return[2]}}))}))},this.setIsKlarnaPaymentCompleted=function(i){return e(Q,void 0,void 0,(function(){return t(this,(function(e){return this.isKlarnaPaymentCompleted=i,[2]}))}))},this.removeUnavailableItems=function(i){return e(Q,void 0,void 0,(function(){var e,s,n;return t(this,(function(t){switch(t.label){case 0:e=0,s=i,t.label=1;case 1:return e<s.length?(n=s[e],[4,E.getInstance().cartStore.changeItemQuantity(n.item,n.stockCount<0?0:n.stockCount)]):[3,4];case 2:t.sent(),t.label=3;case 3:return e++,[3,1];case 4:return[2]}}))}))},this.getShippingCountries=function(){return e(Q,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,I.getAvailableShippingCountries({salesChannelId:R.getSalesChannelId()})];case 1:return e=t.sent(),this.shippingCountryIds=e.data,[2]}}))}))},this.getStockLocations=function(){return e(Q,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return R.getPickupStockLocationIds()?[4,I.listStockLocation({id:{in:R.getPickupStockLocationIds()}})]:[3,2];case 1:if(!(e=t.sent()).isSuccess||!(null===(i=e.data)||void 0===i?void 0:i.length))return this.error={type:_.API_ERROR,data:e.firstErrorMessage},[2];this.stockLocations=e.data,t.label=2;case 2:return[2]}}))}))},this.getAvailableStockLocations=function(){return e(Q,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return R.getPickupStockLocationIds()?(e=this.checkout.items.map((function(e){return{quantity:e.quantity,variantId:e.variant.id,productId:e.variant.productId}})),[4,I.getAvailableStockLocations({lines:e.map((function(e){return new T(e)})),stockLocationIdList:R.getPickupStockLocationIds()})]):[3,2];case 1:if(!(i=t.sent()).isSuccess)return this.error={type:_.API_ERROR},[2];this.availableStockLocations=i.data||[],t.label=2;case 2:return[2]}}))}))},this.checkShippingCountries=function(){var e;(null===(e=Q.shippingCountryIds)||void 0===e?void 0:e.length)||(Q.error={type:_.NO_SHIPPING_ERROR})},this.onDeliveryMethodChange=function(e){"address"===e&&(Q.checkout.stockLocationId=null),Q.deliveryMethod=e,Q.isErrorsVisible=!1},this.initialStockCheck=function(){return e(Q,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,this.checkStocks()];case 1:return t.sent(),[3,3];case 2:return void 0!==typeof(e=t.sent()).type?this.error=e:(console.log(e),this.error={type:_.UNKNOWN}),[3,3];case 3:return[2]}}))}))},this.listPaymentGateways=function(){return e(Q,void 0,void 0,(function(){var e,i,s,n,o,a,c,d,u,l,h=this;return t(this,(function(t){switch(t.label){case 0:return e="local"===process.env.NEXT_PUBLIC_ENV,i=R.getPaymentGateways().map((function(e){return e.id})),[4,I.listPaymentGateway({id:e?void 0:{in:i},locale:R.getCurrentLocale(),transactionAmount:this.checkout.totalFinalPrice})];case 1:return(s=t.sent()).isSuccess&&(null===(u=s.data)||void 0===u?void 0:u.length)?(n=s.data,this.step===V.PAYMENT&&(n=n.filter((function(e){var t;return!(null===(t=e.supportedCurrencies)||void 0===t?void 0:t.length)||e.supportedCurrencies.includes(h.checkout.currencyCode)})),(o=null===(l=this.checkout.shippingAddress)||void 0===l?void 0:l.country)&&o.iso2&&(n=n.filter((function(e){var t;return!(null===(t=e.availableCountries)||void 0===t?void 0:t.length)||e.availableCountries.includes(o.iso2||"")})))),a=[],r(R.getPaymentGateways(),"order").forEach((function(e){var t=null==n?void 0:n.find((function(t){return t.id===e.id}));t&&a.push(t)})),this.paymentGateways=e?n:a,this.checkout.selectedPaymentGateway||this.setPaymentGateway(0),this.step===V.PAYMENT&&(c=n.find((function(e){return!!e.masterPassClientId})))&&(this.checkout.masterPassPaymentGateway=c,(d=document.createElement("script")).id=N,d.src=j,d.onload=function(){h.mpVM.checkMasterPass({checkout:h.checkout,store:E.getInstance()})},document.head.appendChild(d)),[2]):(this.error={type:_.API_ERROR,data:s.firstErrorMessage},[2])}}))}))},this.retrieveInstallmentInfo=function(i){return e(Q,void 0,void 0,(function(){var e,s,n;return t(this,(function(t){switch(t.label){case 0:return[4,I.retrieveInstallmentInfo(i)];case 1:return e=t.sent(),s=e.data,null===(n=null==s?void 0:s.installmentPrices)||void 0===n||n.sort((function(e,t){return(e.installmentCount||-1)>(t.installmentCount||-1)?1:-1})),this.installmentInfo=s,[2]}}))}))},this.createCustomer=function(){var e;Q.store.customerStore.customer?(null===(e=Q.customerAddresses)||void 0===e||e.forEach((function(e){e.checkoutSettings=Q.checkoutSettings,e.shippingZones=Q.shippingZones})),Q.checkout.customer=new S(Q.store.customerStore.customer)):Q.checkout.customer=new S(Q.checkout.customer||{})},this.setCheckoutShippingAddressSettings=function(){Q.checkout.shippingAddress&&(Q.checkout.shippingAddress.checkoutSettings=Q.checkoutSettings,Q.checkout.shippingAddress.shippingZones=Q.shippingZones,Q.checkout.shippingAddress.countrySettings=Q.countrySettings,Q.checkout.shippingAddress.getValidatedCustomerAddress())},this.setCheckoutBillingAddressSettings=function(){Q.checkout.billingAddress&&(Q.checkout.billingAddress.checkoutSettings=Q.checkoutSettings,Q.checkout.billingAddress.shippingZones=Q.shippingZones,Q.checkout.billingAddress.countrySettings=Q.countrySettings,Q.checkout.billingAddress.getValidatedCustomerAddress())},this.createShippingAddress=function(){if(!Q.isDigitalOnly)if(Q.isInStoreDelivery)Q.setCheckoutShippingAddressSettings();else if(Q.checkout.shippingAddress){if(Q.store.customerStore.customer){var e=null==(t=Q.customerAddresses)?void 0:t.find((function(e){var t;return e.id===(null===(t=Q.checkout.shippingAddress)||void 0===t?void 0:t.id)}));if(e)return Q.onSelectedShippingAddressIdChange(e.id||"-1"),void Q.setCheckoutShippingAddressSettings()}Q.checkout.shippingAddress=new G(n(Q.checkout.shippingAddress)||{}),Q.setCheckoutShippingAddressSettings()}else if(Q.store.customerStore.customer){var t=Q.customerAddresses;Q.onSelectedShippingAddressIdChange((null==t?void 0:t.length)?t[0].id:"-1")}else Q.onSelectedShippingAddressIdChange("-1")},this.createBillingAddress=function(){if("undefined"!=typeof localStorage)if(Q.useDifferentAddress=!!localStorage.getItem("sAddr"),Q.checkout.billingAddress){if(Q.store.customerStore.customer){var e=null==(t=Q.customerAddresses)?void 0:t.find((function(e){var t;return e.id===(null===(t=Q.checkout.billingAddress)||void 0===t?void 0:t.id)}));if(e)return Q.onSelectedBillingAddressIdChange(e.id||"-1"),void Q.setCheckoutBillingAddressSettings()}Q.checkout.billingAddress=new G(n(Q.checkout.billingAddress)||{}),Q.setCheckoutBillingAddressSettings()}else if(Q.store.customerStore.customer){var t=Q.customerAddresses;Q.onSelectedBillingAddressIdChange((null==t?void 0:t.length)?t[0].id:"-1"),(null==t?void 0:t.length)||Q.useDifferentAddress||!Q.checkout.shippingAddress||Q.isInStoreDelivery||(Q.checkout.billingAddress=new G(n(Q.checkout.shippingAddress)),Q.setCheckoutBillingAddressSettings())}else Q.onSelectedBillingAddressIdChange("-1"),Q.useDifferentAddress||!Q.checkout.shippingAddress||Q.isInStoreDelivery||(Q.checkout.billingAddress=new G(n(Q.checkout.shippingAddress)),Q.setCheckoutBillingAddressSettings())},this.onShippingMethodChange=function(i){return e(Q,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return this.isChangingShippingMethod?[2]:(this.isChangingShippingMethod=!0,this.checkout.shippingSettingsId=i.shippingSettingsId,this.checkout.shippingZoneRateId=i.shippingZoneRateId,[4,this.saveCart()]);case 1:return(e=t.sent())&&(this.checkout=new m(e,this.countrySettings)),this.checkout.shippingAddress&&(this.checkout.shippingAddress.checkoutSettings=this.checkoutSettings,this.checkout.shippingAddress.shippingZones=this.shippingZones),this.isChangingShippingMethod=!1,[2]}}))}))},this.onStockLocationChange=function(i){return e(Q,void 0,void 0,(function(){return t(this,(function(e){return this.checkout.stockLocationId=i.id,[2]}))}))},this.onCouponCodeApply=function(){return e(Q,void 0,void 0,(function(){var e,s,n,r,o,a;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,5,,6]),[4,A.saveCartCouponCode({cartId:this.checkout.id,couponCode:this.checkout.couponCode||null})];case 1:return(e=t.sent()).isSuccess&&e.data?(s=e.data,n=null===(a=null===(o=this.cardData)||void 0===o?void 0:o.cardNumber)||void 0===a?void 0:a.split(" ").join(""),this.couponError=null,this.step===V.PAYMENT&&(null==n?void 0:n.length)&&n.length>=6&&this.retrieveInstallmentInfo({input:{binNumber:n.slice(0,6),paymentGatewayId:this.checkout.selectedPaymentGateway.id,price:s.totalFinalPrice}}),this.mpVM.selectedCard&&this.mpVM.selectedCard.Value1?[4,this.retrieveInstallmentInfo({input:{binNumber:this.mpVM.selectedCard.Value1.slice(0,6),paymentGatewayId:this.mpVM.selectedCard.paymentGatewayId,price:s.totalFinalPrice}})]:[3,3]):[3,4];case 2:t.sent(),t.label=3;case 3:s&&(r=this.checkout,this.checkout=new m(i(i({},s),{shippingAddress:r.shippingAddress,billingAddress:r.billingAddress,customer:r.customer,selectedPaymentGateway:r.selectedPaymentGateway}),this.countrySettings)),t.label=4;case 4:return e.isSuccess||(this.couponError=e.errorCodes[0]),[3,6];case 5:return t.sent(),[3,6];case 6:return[2]}}))}))},this.getAvailableShippingZones=function(){return e(Q,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,L.getAvailableShippingZones({salesChannelId:R.getSalesChannelId()})];case 1:return e=t.sent(),this.shippingZones=e.data||null,[3,3];case 2:return t.sent(),[3,3];case 3:return[2]}}))}))},this.onSelectedShippingAddressIdChange=function(e){var t;if(Q.selectedShippingAddressId=e,"-1"===e)Q.checkout.shippingAddress=new G,Q.checkout.shippingAddress.countrySettings=Q.countrySettings;else{var i=null===(t=Q.customerAddresses)||void 0===t?void 0:t.find((function(t){return t.id===e}));i&&(Q.checkout.shippingAddress=new G(i),Q.checkout.shippingAddress.countrySettings=Q.countrySettings)}Q.checkout.shippingAddress&&(Q.checkout.shippingAddress.checkoutSettings=Q.checkoutSettings,Q.checkout.shippingAddress.shippingZones=Q.shippingZones)},this.onSelectedBillingAddressIdChange=function(e){var t;if(Q.selectedBillingAddressId=e,"-1"===e)Q.checkout.billingAddress=new G,Q.checkout.billingAddress.countrySettings=Q.countrySettings;else{var i=null===(t=Q.customerAddresses)||void 0===t?void 0:t.find((function(t){return t.id===e}));i&&(Q.checkout.billingAddress=new G(i),Q.checkout.billingAddress.countrySettings=Q.countrySettings)}Q.checkout.billingAddress&&(Q.checkout.billingAddress.checkoutSettings=Q.checkoutSettings,Q.checkout.billingAddress.shippingZones=Q.shippingZones)},this.onTermsAndConditionsCheckedChange=function(e){Q.isTermsAndConditionsChecked=e},this.onCardNumberChange=function(e){if(Q.cardData&&(!(e.length>Q.cardData.cardNumber.length)||Z(e))){var t=(Q.cardData.cardNumber||"").split(" ").join(""),i=e.split(" ").join("");i.length>16||(t.length<6&&i.length>=6&&!Q.installmentInfo?Q.retrieveInstallmentInfo({input:{binNumber:i.slice(0,6),paymentGatewayId:Q.checkout.selectedPaymentGateway.id,price:Q.checkout.totalFinalPrice}}):i.length<6&&t.length>i.length&&(Q.cardData.installmentCount=1,Q.installmentInfo=void 0),Q.cardData.cardNumber=B(i,4).join(" "))}},this.onCardHolderNameChange=function(e){Q.cardData&&(Q.cardData.cardHolderName=e)},this.onExpirationDateChange=function(e){var t;if(Q.cardData&&(!(e.length>Q.cardData.expirationDate.length)||Z(e))){if(0===(null===(t=Q.cardData.expirationDate)||void 0===t?void 0:t.length)){var i=e.replace(".","/").split("/");if(2===i.length){var s=i[0].trim(),n=i[1].trim();if(4===s.length&&2===n.length){var r=parseInt(s.slice(2)),o=parseInt(n);if(!isNaN(r)&&!isNaN(o))return void(Q.cardData.expirationDate="".concat(o<10?"0"+o:o," / ").concat(r<10?"0"+r:r))}if(2===s.length&&4===n.length){o=parseInt(s),r=parseInt(n.slice(2));if(!isNaN(r)&&!isNaN(o))return void(Q.cardData.expirationDate="".concat(o<10?"0"+o:o," / ").concat(r<10?"0"+r:r))}if(2===s.length&&2===n.length){var a=parseInt(s),c=parseInt(n);o=a<=12?a:c,r=c>12?c:a;if(!isNaN(r)&&!isNaN(o))return void(Q.cardData.expirationDate="".concat(o<10?"0"+o:o," / ").concat(r<10?"0"+r:r))}}}var d=e.split(" / ").join("");d.length>4||(Q.cardData.expirationDate=B(d,2).join(" / "))}},this.onCvcChange=function(e){Q.cardData&&(e.length>Q.cardData.cvv.length&&!Z(e)||e.length>4||(Q.cardData.cvv=e))},this.saveAddress=function(s){return e(Q,void 0,void 0,(function(){var e,r,o,a,c,d,u,l,h,p,m,f,v=this;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,3,,4]),this.shouldSaveAddress&&this.store.customerStore.customer?(e="shipping"===s?this.checkout.shippingAddress:this.checkout.billingAddress,(null===(h=this.customerAddresses)||void 0===h?void 0:h.find((function(t){return t.id===(null==e?void 0:e.id)})))?[2]:(r=null===(p=this.customerAddresses)||void 0===p?void 0:p.map((function(e){return e.id})),o=new g(i(i({},e),{title:this.addressTitle||this.t("checkout-page:newAddress")})),(a=n(this.store.customerStore.customer)).addresses||(a.addresses=[]),a.addresses.push(o),[4,this.store.customerStore.saveCustomer(a)])):[3,2];case 1:t.sent(),null===(m=this.customerAddresses)||void 0===m||m.forEach((function(e){e.checkoutSettings=v.checkoutSettings,e.shippingZones=v.shippingZones})),c=null===(f=this.customerAddresses)||void 0===f?void 0:f.map((function(e){return e.id})),d=null==c?void 0:c.filter((function(e){return!(null==r?void 0:r.includes(e))})),u=(null==d?void 0:d.length)?d[0]:void 0,"shipping"===s?(this.checkout.shippingAddress.id=u||"",this.selectedShippingAddressId=u||"-1"):(this.checkout.billingAddress.id=u||"",this.selectedBillingAddressId=u||"-1"),t.label=2;case 2:return[3,4];case 3:return l=t.sent(),console.error(l),[3,4];case 4:return[2]}}))}))},this.onGoToCartClick=function(){Q.router.push("/cart")},this.onBackToShoppingClick=function(){Q.router.push("/")},this.onGoToLoginClick=function(){Q.router.push("/account/login")},this.onProceedToShippingClick=function(){return e(Q,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:if("address"===this.deliveryMethod){if(!this.canProceedToShipping)return this.isErrorsVisible=!0,[2]}else if(!this.canProceedToInStoreDelivery)return this.isErrorsVisible=!0,[2];this.isErrorsVisible=!1,t.label=1;case 1:return t.trys.push([1,6,,7]),this.isStepLoading=!0,"address"!==this.deliveryMethod?[3,3]:[4,this.saveAddress("shipping")];case 2:t.sent(),t.label=3;case 3:return[4,this.checkStocks()];case 4:return t.sent(),[4,this.saveCart()];case 5:return t.sent(),"address"===this.deliveryMethod?this.changeStep(V.SHIPPING):this.changeStep(V.PAYMENT),[3,7];case 6:return void 0!==typeof(e=t.sent()).type?this.error=e:(console.log(e),this.error={type:_.UNKNOWN}),this.isStepLoading=!1,[3,7];case 7:return[2]}}))}))},this.onProceedToDigitalOnlyPaymentClick=function(){return e(Q,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:if(!this.canProceedToPayment)return this.isErrorsVisible=!0,[2];this.isErrorsVisible=!1,t.label=1;case 1:return t.trys.push([1,4,,5]),this.isStepLoading=!0,[4,this.checkStocks()];case 2:return t.sent(),[4,this.saveCart()];case 3:return t.sent(),this.changeStep(V.PAYMENT),[3,5];case 4:return(e=t.sent()).type?this.error=e:(console.log(e),this.error={type:_.UNKNOWN}),this.isStepLoading=!1,[3,5];case 5:return[2]}}))}))},this.onProceedToPaymentClick=function(){return e(Q,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:if(!this.canProceedToPayment)return this.isErrorsVisible=!0,[2];this.isErrorsVisible=!1,t.label=1;case 1:return t.trys.push([1,4,,5]),this.isStepLoading=!0,[4,this.checkStocks()];case 2:return t.sent(),[4,this.saveCart()];case 3:return t.sent(),this.error=void 0,this.changeStep(V.PAYMENT),[3,5];case 4:return void 0!==typeof(e=t.sent()).type?this.error=e:(console.log(e),this.error={type:_.UNKNOWN}),this.isStepLoading=!1,[3,5];case 5:return[2]}}))}))},this.checkPaypalButtonAvailable=function(){return!!Q.canPerformPayment||(Q.isErrorsVisible=!0,!1)},this.onCompletePaymentClick=function(){return e(Q,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return this.canPerformPayment?(this.useDifferentAddress||(this.checkout.billingAddress=this.checkout.shippingAddress),this.isFree||!this.isKlarna?[3,2]:[4,this.saveCart()]):(this.isErrorsVisible=!0,[2]);case 1:return t.sent(),this.setIsKlarnaPaymentCompleted(!0),[2];case 2:return t.trys.push([2,8,,9]),this.isErrorsVisible=!1,this.isStepLoading=!0,[4,this.checkStocks()];case 3:return t.sent(),"address"===this.deliveryMethod&&this.useDifferentAddress?[4,this.saveAddress("billing")]:[3,5];case 4:t.sent(),t.label=5;case 5:return[4,this.saveCart()];case 6:return t.sent(),!this.isFree&&this.isCustomFlowStripe?((e=document.querySelector("#stripe-form-btn"))&&e.click(),[2]):!this.isFree&&this.isAdyen?(this.adyenDropinElement.submit(),this.adyenDropinElement.isValid||(this.isStepLoading=!1),[2]):!this.isFree&&this.isPayPal?[2]:[4,this.createSaleTransaction()];case 7:return t.sent(),[3,9];case 8:return void 0!==typeof(i=t.sent()).type?this.error=i:this.error={type:_.UNKNOWN},this.isStepLoading=!1,[3,9];case 9:return[2]}}))}))},this.onCompleteDigitalOnlyPaymentClick=function(){return e(Q,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return!this.canProceedToPayment||this.checkoutSettings.showTermsAndConditionsCheckbox&&!this.isTermsAndConditionsChecked?(this.isErrorsVisible=!0,[2]):this.isKlarna?[4,this.saveCart()]:[3,2];case 1:return t.sent(),this.setIsKlarnaPaymentCompleted(!0),[2];case 2:return t.trys.push([2,6,,7]),this.isErrorsVisible=!1,this.isStepLoading=!0,[4,this.checkStocks()];case 3:return t.sent(),[4,this.saveCart()];case 4:return t.sent(),this.isCustomFlowStripe?((e=document.querySelector("#stripe-form-btn"))&&e.click(),[2]):this.isAdyen?(this.adyenDropinElement.submit(),this.adyenDropinElement.isValid||(this.isStepLoading=!1),[2]):this.isPayPal?[2]:[4,this.createSaleTransaction()];case 5:return t.sent(),[3,7];case 6:return(i=t.sent()).type?this.error=i:this.error={type:_.UNKNOWN},this.isStepLoading=!1,[3,7];case 7:return[2]}}))}))},this.createSaleTransaction=function(){return e(Q,void 0,void 0,(function(){var e,i,s,n,r,o,d,u,h,p,m,f,g,v,y;return t(this,(function(t){switch(t.label){case 0:return i=this.mpVM.selectedCard,!this.isFree&&i&&(null===(u=this.mpVM.selectedCard)||void 0===u?void 0:u.Name)?((n=this.mpVM.phoneNumber({store:this.store,checkout:this.checkout}))&&(e=n),void 0===(null===(h=this.cardData)||void 0===h?void 0:h.installmentCount)?[2]:[4,I.createSaleTransactionWithCart({input:{cartId:this.checkout.id,masterPassDetail:{phoneNumber:e,savedCardName:null===(p=this.mpVM.selectedCard)||void 0===p?void 0:p.Name},paymentGatewayId:null===(m=this.mpVM.selectedCard)||void 0===m?void 0:m.paymentGatewayId,paymentMethodDetail:{cardNumber:this.mpVM.selectedCard.Value1,cardHolderName:this.mpVM.selectedCard.Name,cvv:this.mpVM.selectedCard.Value2,expiredMonth:11,expiredYear:11,installmentCount:this.cardData.installmentCount,threeDSecure:!!(null===(f=this.cardData)||void 0===f?void 0:f.threeDSecure)},metadata:{_fbp:M("_fbp"),_fbc:M("_fbc")}}})]):[3,2];case 1:return s=t.sent(),[3,4];case 2:return this.checkout.selectedPaymentGateway?[4,I.createSaleTransactionWithCart({input:{cartId:this.checkout.id,masterPassDetail:this.isFree?void 0:i&&e?{phoneNumber:e,savedCardName:null===(g=this.mpVM.selectedCard)||void 0===g?void 0:g.Name}:void 0,paymentGatewayId:this.checkout.selectedPaymentGateway.id,paymentMethodDetail:this.isFree||i?void 0:this.checkout.selectedPaymentGateway.paymentMethodType===a.CREDIT_CARD&&this.checkout.selectedPaymentGateway.type===c.INTERNAL&&this.cardData?this.cardData.toInput():void 0}})]:[2];case 3:s=t.sent(),t.label=4;case 4:return r=null===(v=null==s?void 0:s.data)||void 0===v?void 0:v.transactionStatus,o=r&&[l.SUCCESS,l.AUTHORIZED].includes(r),d=r===l.PENDING,o?[4,this.getSuccessTransaction()]:[3,7];case 5:return t.sent(),[4,this.onCheckoutTransactionSuccess()];case 6:return t.sent(),[3,8];case 7:if(!d||!(null===(y=null==s?void 0:s.data)||void 0===y?void 0:y.returnSlug))throw{data:s.firstErrorMessage,type:_.UNKNOWN};window.location.href=process.env.NEXT_PUBLIC_BASE_URL+s.data.returnSlug,t.label=8;case 8:return[2]}}))}))},this.onCheckoutTransactionSuccess=function(){return e(Q,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return localStorage.removeItem("sAddr"),(null===(e=this.checkout.customer)||void 0===e?void 0:e.notificationsAccepted)?[4,this.store.customerStore.createEmailSubscription((null===(i=this.checkout.customer)||void 0===i?void 0:i.email)||"")]:[3,2];case 1:t.sent(),t.label=2;case 2:return this.changeStep(V.SUCCESS),[2]}}))}))},this.onBackToInfoClick=function(){Q.changeStep(V.INFO)},this.onBackToShippingClick=function(){Q.changeStep(V.SHIPPING)},this.setCustomerConsentGranted=function(e){Q.checkout.customer&&(Q.checkout.customer.notificationsAccepted=e)},this.setUseDifferentAddress=function(e){Q.useDifferentAddress=e,Q.useDifferentAddress?(localStorage.setItem("sAddr","1"),Q.checkout.billingAddress=Q.checkout.billingAddress||new G,Q.checkout.billingAddress.countrySettings=Q.countrySettings):(localStorage.removeItem("sAddr"),Q.checkout.billingAddress=Q.checkout.shippingAddress)},this.setShouldSaveAddress=function(e){Q.shouldSaveAddress=e},this.setAddressTitle=function(e){Q.addressTitle=e},this.reInitPaymentMethod=function(){return e(Q,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return this.checkout.selectedPaymentGateway?this.isCustomFlowStripe?[4,this.createStripePaymentIntent(this.checkout.selectedPaymentGateway)]:[3,2]:[3,6];case 1:e.sent(),e.label=2;case 2:return this.isKlarna&&window.location.reload(),this.isAdyen?[4,this.createAdyenClientToken(this.checkout.selectedPaymentGateway)]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.isPayPal?[4,this.getPayPalClientId(this.checkout.selectedPaymentGateway)]:[3,6];case 5:e.sent(),e.label=6;case 6:return[2]}}))}))},this.createStripePaymentIntent=function(i){return e(Q,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,I.createStripePaymentIntent({input:{cartId:this.checkout.id,paymentGatewayId:i.id||""}})];case 1:return(e=t.sent()).isSuccess&&e.data&&(this.stripeResponse=e.data),[2]}}))}))},this.createKlarnaClientToken=function(i){return e(Q,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,I.createKlarnaClientToken({input:{cartId:this.checkout.id,paymentGatewayId:i.id||""}})];case 1:return(e=t.sent()).isSuccess&&e.data&&(this.klarnaResponse=e.data),[2]}}))}))},this.createAdyenClientToken=function(i){return e(Q,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,I.createAdyenClientToken({input:{cartId:this.checkout.id,paymentGatewayId:i.id||""}})];case 1:return(e=t.sent()).isSuccess&&e.data&&(this.adyenResponse=e.data),[2]}}))}))},this.getPayPalClientId=function(i){return e(Q,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,I.getPayPalClientId({input:{cartId:this.checkout.id,paymentGatewayId:i.id||""}})];case 1:return(e=t.sent()).isSuccess&&e.data&&(this.payPalClientIdResponse=e.data),[2]}}))}))},this.setPaymentGateway=function(i){return e(Q,void 0,void 0,(function(){var e,s;return t(this,(function(t){switch(t.label){case 0:return this.paymentGateways.length?"STRIPE"!==(e=this.paymentGateways[i]).code||!(null===(s=e.settings)||void 0===s?void 0:s.find((function(e){return"allow_custom_flow"===e.label&&"1"===e.value})))||this.stripeResponse?[3,2]:[4,this.createStripePaymentIntent(e)]:[2];case 1:t.sent(),t.label=2;case 2:return"KLARNA"!==e.code||this.klarnaResponse?[3,4]:[4,this.createKlarnaClientToken(e)];case 3:t.sent(),t.label=4;case 4:return"ADYEN"!==e.code||this.adyenResponse?[3,6]:[4,this.createAdyenClientToken(e)];case 5:t.sent(),t.label=6;case 6:return"PAYPAL"!==e.code||this.payPalClientIdResponse?[3,8]:[4,this.getPayPalClientId(e)];case 7:t.sent(),t.label=8;case 8:return this.checkout.selectedPaymentGateway=e,this.step!==V.SUCCESS&&(e.paymentMethodType===a.CREDIT_CARD&&e.type===c.INTERNAL&&(this.cardData=new C,e.masterPassClientId&&(console.log("called 1511 ikas log"),this.mpVM.checkMasterPass({checkout:this.checkout,store:this.store}))),this.installmentInfo=void 0),[2]}}))}))},this.setInstallmentCount=function(e){Q.cardData&&(Q.cardData.installmentCount=e)},this.changeStep=function(i){return e(Q,void 0,void 0,(function(){return t(this,(function(e){return F||window.location.replace("".concat(window.location.pathname,"?id=").concat(this.checkout.id,"&step=").concat(i)),[2]}))}))},this.logout=function(){return e(Q,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:this.checkout.customer=null,this.store.customerStore.logout(),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.saveCart()];case 2:case 3:return e.sent(),[3,4];case 4:return this.createCustomer(),[2]}}))}))},this.setContactModalVisible=function(e){Q.isContactModalVisible=e},this.getCampaignOfferProducts=function(i){return e(Q,void 0,void 0,(function(){var e,s,n,r;return t(this,(function(o){switch(o.label){case 0:if(!this.checkout.campaignOffers||!this.checkout.campaignOffers.length)return[3,4];if(e=this.checkout.campaignOffers.filter((function(e){var t;return e.status===h.WAITING_FOR_ACTION&&(null===(t=e.campaignOffer)||void 0===t?void 0:t.targetPageTypes.some((function(e){return e===i})))})),!e.length)return[3,4];s=function(i){var s,n,r,o,a;return t(this,(function(t){switch(t.label){case 0:return(s=e[i]).campaignOffer&&(n=s.campaignOffer.offers.find((function(e){return e.id===s.campaignOfferProductId})))?[4,O.searchProducts({input:{productIdList:[n.productId]}})]:[3,2];case 1:if((r=t.sent()).isSuccess&&r.data&&r.data.data&&r.data.data.length&&(o=r.data.data[0],a=[],n.excludedVariantIdList&&n.excludedVariantIdList.length?o.variants.map((function(e){var t;e.hasStock&&!(null===(t=n.excludedVariantIdList)||void 0===t?void 0:t.some((function(t){return t===e.id})))&&a.push(e)})):a.push.apply(a,o.variants.filter((function(e){return e.hasStock}))),a.length))return[2,{value:{product:new k(o),variants:a,campaignOffer:s,offer:n}}];t.label=2;case 2:return[2]}}))},n=0,o.label=1;case 1:return n<e.length?[5,s(n)]:[3,4];case 2:if("object"==typeof(r=o.sent()))return[2,r.value];o.label=3;case 3:return n++,[3,1];case 4:return[2,void 0]}}))}))},this.getCampaignOffer=function(){return e(Q,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return e=this,[4,this.getCampaignOfferProducts(p.CHECKOUT)];case 1:return e.checkoutCampaignOffer=t.sent(),i=this,[4,this.getCampaignOfferProducts(p.POST_CHECKOUT)];case 2:return i.postCheckoutCampaignOffer=t.sent(),[2]}}))}))},this.updateCartCampaignOffer=function(i){return e(Q,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return this.isCheckoutLoaded=!1,[4,A.updateCartCampaignOffer({input:i})];case 1:return(e=t.sent())&&e.isSuccess&&e.data&&(this.checkout=new m(e.data,this.countrySettings),i.accepted&&this.step===V.SUCCESS?this.changeStep(V.INFO):this.changeStep(this.step)),[2]}}))}))},this.registerCustomer=function(i){return e(Q,void 0,void 0,(function(){var e,s,n,r;return t(this,(function(t){switch(t.label){case 0:return this.checkout.customer?(e=this.checkout.customer,s=e.firstName,n=e.lastName,r=e.email,s&&n&&r?[4,P.register({orderId:this.checkout.id,firstName:s,lastName:n,email:r,password:i})]:[3,2]):[3,2];case 1:return[2,t.sent()];case 2:return[2]}}))}))},this.checkout=d,this.checkoutSettings=u,this.router=v,this.returnPolicy=y,this.privacyPolicy=U,this.termsOfService=K,this.imprint=Y,this.shippingPolicy=H,this.t=q,this.customizationProps=W,this.mpVM=new w,this.isTermsAndConditionsChecked=this.checkoutSettings.isTermsAndConditionsDefaultChecked||!1,this.countrySettings=new b({currentLocale:R.getCurrentLocale()}),this.init(),s(this)}return Object.defineProperty(U.prototype,"merchantSettings",{get:function(){return new y(R.getMerchantSettings())},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"selectedPaymentGatewayIndex",{get:function(){var e=this;return this.paymentGateways.findIndex((function(t){var i;return t.id===(null===(i=e.checkout.selectedPaymentGateway)||void 0===i?void 0:i.id)}))},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"selectedInstallmentIndex",{get:function(){var e,t,i=this;return(null===(t=null===(e=this.installmentInfo)||void 0===e?void 0:e.installmentPrices)||void 0===t?void 0:t.findIndex((function(e){var t;return e.installmentCount===(null===(t=i.cardData)||void 0===t?void 0:t.installmentCount)})))||0},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"checkoutUrl",{get:function(){return"/checkout?id=".concat(this.checkout.id,"&step=info")},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"customerAddressOptions",{get:function(){var e,t,i={label:this.t("checkout-page:newAddress"),value:"-1"},s=(null===(t=null===(e=E.getInstance().customerStore.customer)||void 0===e?void 0:e.addresses)||void 0===t?void 0:t.map((function(e){return{label:e.title+" - "+e.addressText,value:e.id}})))||[];return[i].concat(s)},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"installmentPrice",{get:function(){var e,t,i,s=this;if(this.installmentInfo&&(null===(e=this.cardData)||void 0===e?void 0:e.installmentCount))return null===(i=null===(t=this.installmentInfo.installmentPrices)||void 0===t?void 0:t.find((function(e){var t;return e.installmentCount===(null===(t=s.cardData)||void 0===t?void 0:t.installmentCount)})))||void 0===i?void 0:i.totalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"installmentExtraPrice",{get:function(){if(this.installmentPrice&&this.checkout.totalFinalPrice)return this.installmentPrice-this.checkout.totalFinalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"finalPrice",{get:function(){return this.step===V.SUCCESS?this.checkout.totalFinalPrice:this.installmentPrice||this.checkout.$totalFinalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"hasStockError",{get:function(){var e;return(null===(e=this.error)||void 0===e?void 0:e.type)===_.STOCK_ERROR},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"isPaymentGatewayHasMasterPass",{get:function(){return-1!==this.selectedPaymentGatewayIndex&&(!!this.paymentGateways.length&&!!this.paymentGateways[this.selectedPaymentGatewayIndex].masterPassClientId)},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"hasQuickRegistration",{get:function(){return this.checkoutSettings.isQuickRegistrationEnabled&&this.checkout.customer&&this.checkout.customer.isGuestCheckout},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"canProceedToShipping",{get:function(){var e,t,i;return(this.isDigitalOnly?null===(e=this.checkout.billingAddress)||void 0===e?void 0:e.isValidAddress:null===(t=this.checkout.shippingAddress)||void 0===t?void 0:t.isValidAddress)&&this.checkout.hasValidCustomerEmail&&(null===(i=this.error)||void 0===i?void 0:i.type)!==_.NO_SHIPPING_ERROR},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"canProceedToInStoreDelivery",{get:function(){var e,t,i;return!!((null===(e=this.checkout.shippingAddress)||void 0===e?void 0:e.firstName)&&(null===(t=this.checkout.shippingAddress)||void 0===t?void 0:t.lastName)&&(null===(i=this.checkout.customer)||void 0===i?void 0:i.email)&&this.checkout.stockLocationId)},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"canProceedToPayment",{get:function(){return this.canProceedToShipping&&this.isValidShippingSettings},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"isValidShippingSettings",{get:function(){var e,t=this;return!(!this.isInStoreDelivery&&!this.isDigitalOnly)||this.checkout.shippingSettingsId&&this.checkout.shippingZoneRateId&&(null===(e=this.checkout.shippingLines)||void 0===e?void 0:e.some((function(e){return e.shippingSettingsId===t.checkout.shippingSettingsId&&e.shippingZoneRateId===t.checkout.shippingZoneRateId})))},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"isInStoreDelivery",{get:function(){return!!this.checkout.stockLocationId},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"klarnaPaymentGateway",{get:function(){var e=this.paymentGateways.findIndex((function(e){return"KLARNA"===e.code}));if(-1!==e)return this.paymentGateways[e]},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"klarnaPaymentGatewayIndex",{get:function(){return this.paymentGateways.findIndex((function(e){return"KLARNA"===e.code}))},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"adyenPaymentGateway",{get:function(){var e=this.paymentGateways.findIndex((function(e){return"ADYEN"===e.code}));if(-1!==e)return this.paymentGateways[e]},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"adyenPaymentGatewayIndex",{get:function(){return this.paymentGateways.findIndex((function(e){return"ADYEN"===e.code}))},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"payPalPaymentGateway",{get:function(){var e=this.paymentGateways.findIndex((function(e){return"PAYPAL"===e.code}));if(-1!==e)return this.paymentGateways[e]},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"payPalPaymentGatewayIndex",{get:function(){return this.paymentGateways.findIndex((function(e){return"PAYPAL"===e.code}))},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"isCustomFlowStripe",{get:function(){var e,t=this.checkout.selectedPaymentGateway;return t&&"STRIPE"===t.code&&(null===(e=t.settings)||void 0===e?void 0:e.find((function(e){return"allow_custom_flow"===e.label&&"1"===e.value})))},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"isKlarna",{get:function(){var e=this.checkout.selectedPaymentGateway;return e&&"KLARNA"===e.code},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"isAdyen",{get:function(){var e=this.checkout.selectedPaymentGateway;return e&&"ADYEN"===e.code},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"isPayPal",{get:function(){var e=this.checkout.selectedPaymentGateway;return e&&"PAYPAL"===e.code},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"isFree",{get:function(){return 0===this.checkout.totalFinalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"store",{get:function(){return E.getInstance()},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"isCouponCodeRequirementDefult",{get:function(){return this.checkoutSettings.couponCodeRequirement===o.DEFAULT||null===this.checkoutSettings.couponCodeRequirement},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"isCouponCodeRequirementOpen",{get:function(){return this.checkoutSettings.couponCodeRequirement===o.OPEN},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"isCouponCodeRequirementInvisible",{get:function(){return this.checkoutSettings.couponCodeRequirement===o.INVISIBLE},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"isCouponCodeVisible",{get:function(){return this.isCouponCodeRequirementDefult&&!this.isCouponCodeRequirementInvisible},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"canPerformPayment",{get:function(){var e,t;if(this.checkoutSettings.showTermsAndConditionsCheckbox&&!this.isTermsAndConditionsChecked)return!1;var i=this.checkout.selectedPaymentGateway,s=!!("in-store"===this.deliveryMethod)||!!this.canProceedToShipping,n=!!(null===(e=this.checkout.billingAddress)||void 0===e?void 0:e.isValidAddress),r=!!this.isFree||(!!this.mpVM.selectedCard||((null==i?void 0:i.paymentMethodType)===a.CREDIT_CARD&&i.type===c.INTERNAL?!!this.isCustomFlowStripe||(!(!this.isKlarna&&!this.isPayPal)||(null===(t=this.cardData)||void 0===t?void 0:t.isValid)):!!i));return s&&n&&r},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"isDigitalOnly",{get:function(){return this.checkout.shippingMethod===d.DIGITAL_DELIVERY},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"customerAddresses",{get:function(){var e,t,s=this;return null===(t=null===(e=this.store.customerStore.customer)||void 0===e?void 0:e.addresses)||void 0===t?void 0:t.map((function(e){var t=new v(i({countrySettings:s.countrySettings},e));return t.checkoutSettings=s.checkoutSettings,t.shippingZones=s.shippingZones,t.getValidatedCustomerAddress(),t}))},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"isManualOrder",{get:function(){return this.checkout.createdBy===u.ADMIN},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"isEPayKolayEnabled",{get:function(){var e=R.getCustom();return!!e&&!!e.isEPayKolayEnabled},enumerable:!1,configurable:!0}),Object.defineProperty(U.prototype,"isPoweredByHidden",{get:function(){var e=R.getCustom();return!!e&&!!e.hidePoweredBy},enumerable:!1,configurable:!0}),U.prototype.setAdyenDropinElement=function(e){this.adyenDropinElement=e},U}();function B(e,t){return e.match(new RegExp(".{1,"+t+"}","g"))||[]}function Z(e){return e&&U.test(e.charAt(e.length-1))}!function(e){e.INFO="info",e.SHIPPING="shipping",e.PAYMENT="payment",e.SUCCESS="success"}(V||(V={})),function(e){e[e.UNKNOWN=0]="UNKNOWN",e[e.API_ERROR=1]="API_ERROR",e[e.STOCK_ERROR=2]="STOCK_ERROR",e[e.PAYMENT_ERROR=3]="PAYMENT_ERROR",e[e.NO_SHIPPING_ERROR=4]="NO_SHIPPING_ERROR",e[e.CUSTOMER_LOGIN_REQUIRED_ERROR=5]="CUSTOMER_LOGIN_REQUIRED_ERROR"}(_||(_={}));export{V as CheckoutStep,_ as ErrorType,K as default};
|
|
1
|
+
import{__awaiter as e,__generator as t,__assign as i}from'./../../ext/tslib/tslib.es6.js';import{makeAutoObservable as s}from"mobx";import n from"lodash/cloneDeep";import r from"lodash/sortBy";import"../../models/data/blog/category/index.js";import"../../models/data/blog/content/index.js";import"../../models/data/blog/meta-data/index.js";import"../../models/data/blog/tag/index.js";import"../../models/data/blog/index.js";import"../../models/data/brand/index.js";import{IkasCouponCodeRequirement as o,IkasPaymentMethodType as a,IkasPaymentGatewayType as c,IkasOrderShippingMethod as d,IkasCartCreatedBy as u,IkasTransactionStatus as l,IkasCartCampaignOfferStatus as h,IkasCampaignOfferTargetPageType as p,IkasCustomerEmailSubscriptionStatus as m}from"@ikas/storefront-models";import"../../models/data/campaign-offer/index.js";import"../../models/data/cart/campaign-offer/index.js";import"../../models/data/cart/index.js";import"../../models/data/category/path-item/index.js";import"../../models/data/category/index.js";import{IkasCheckout as f}from"../../models/data/checkout/index.js";import{IkasCheckoutSettings as g}from"../../models/data/checkout-settings/index.js";import"../../models/data/city/index.js";import"../../models/data/country/index.js";import"../../models/data/customer/address/region/index.js";import{IkasCustomerAddress as v}from"../../models/data/customer/address/index.js";import{IkasLocalizedCustomerAddress as y}from"../../models/data/customer/address/ikas-localized-customer-address.js";import"../../models/data/customer/attribute/index.js";import"../../models/data/customer/review/summary/index.js";import"../../models/data/customer/review/index.js";import"../../models/data/customer/index.js";import"../../models/data/district/index.js";import"../../models/data/favorite-product/index.js";import"../../models/data/filter-category/index.js";import"../../models/data/html-meta-data/index.js";import"../../models/data/image/index.js";import{IkasMerchantSettings as S}from"../../models/data/merchant-settings/index.js";import"../../models/data/order/address/region/index.js";import"../../models/data/order/address/index.js";import{IkasOrderCustomer as k}from"../../models/data/order/customer/index.js";import"../../models/data/order/line-item/option/value/index.js";import"../../models/data/order/line-item/variant/value/index.js";import"../../models/data/order/line-item/variant/index.js";import"../../models/data/order/line-item/index.js";import"../../models/data/order/package/index.js";import"../../models/data/order/transaction/index.js";import"../../models/data/order/index.js";import"../../models/data/payment-gateway/index.js";import"../../models/data/product/attribute-value/index.js";import"../../models/data/product/filter/index.js";import"../../models/data/product/option-set/option/index.js";import"../../models/data/product/option-set/index.js";import"../../models/data/product/stock-location/index.js";import"../../models/data/product/variant/price/index.js";import"../../models/data/product/variant/index.js";import"../../models/data/variant-type/index.js";import{IkasProduct as b}from"../../models/data/product/index.js";import"../../models/data/raffle/index.js";import"../../models/data/shipping-zone/state/city/district/region/index.js";import"../../models/data/state/index.js";import"../../models/data/theme-json/index.js";import"../../models/data/theme-json/component/index.js";import"../../models/data/theme-json/custom-data/index.js";import"../../models/data/variant-type/variant-value/index.js";import{LocalizedAddressModel as C}from"@ikas/localized-address";import"../../models/ui/blog-list/index.js";import"../../models/ui/blog-category-list/index.js";import"../../models/ui/brand-list/index.js";import"../../models/ui/category-list/index.js";import"../../models/ui/product-list/index.js";import"../../models/ui/product-attribute-detail/index.js";import"../../models/ui/product-attribute-list/index.js";import"../../models/ui/customer-review-list/index.js";import"../../models/ui/customer-review-summary-list/index.js";import"../../models/ui/validator/index.js";import"../../models/ui/validator/rules/index.js";import"../../models/ui/validator/form/login.js";import"../../models/ui/validator/form/address.js";import"../../models/ui/validator/form/ikas-address.js";import"../../models/ui/validator/form/register.js";import"../../models/ui/validator/form/contact-form.js";import"../../models/ui/validator/form/forgot-password.js";import"../../models/ui/validator/form/recover-password.js";import"../../models/ui/validator/form/account-info.js";import"../../models/ui/validator/form/raffle-form.js";import"../../models/ui/validator/form/customer-review.js";import"../../models/ui/raffle-list/index.js";import P from"./components/credit-card-form/model.js";import I from"../../store/customer/api.js";import A from"../../store/checkout/index.js";import w from"../../store/cart/api.js";import N,{MFS_ELEMENT_ID as j,MFS_SCRIPT_URL as O}from"./modelMasterPass.js";import E from"../../store/product/index.js";import{IkasBaseStore as R}from"../../store/base.js";import"../../store/customer/index.js";import"../../store/cart/index.js";import{IkasStorefrontConfig as D}from"@ikas/storefront-config";import{Analytics as x}from"../../analytics/analytics.js";import"../../analytics/head/index.js";import{SaveCartInput as T,CheckStocksLineInput as G}from"@ikas/storefront-api";import L from"../../models/data/order/address/ikas-localized-order-address.js";import M from"../../store/location/index.js";import{getCookieValue as V}from"../../utils/helper.js";var _,U,F=/^\d+$/,K="undefined"==typeof localStorage,B=function(){function F(d,u,y,S,F,B,H,q,W,Q){var z=this;this.storefront=null,this.isCheckoutLoaded=!1,this.isErrorsVisible=!1,this.isStepLoading=!1,this.isTermsAndConditionsChecked=!1,this.isChangingShippingMethod=!1,this.isContactModalVisible=!1,this.isEPayKolayPayment=!1,this.step=_.INFO,this.customizationProps=null,this.cardData=null,this.paymentGateways=[],this.installmentInfo=null,this.useDifferentAddress=!1,this.shouldSaveAddress=!0,this.addressTitle="",this.shippingCountryIds=null,this.selectedShippingAddressId="-1",this.selectedBillingAddressId="-1",this.stockLocations=[],this.availableStockLocations=[],this.deliveryMethod="address",this.stripeResponse=null,this.klarnaResponse=null,this.isKlarnaPaymentCompleted=!1,this.adyenResponse=null,this.payPalClientIdResponse=null,this.paypalOrderResponse=null,this.shippingZones=null,this.policyModalTitle="",this.policyModalText="",this.error=null,this.couponError=null,this.showTestModal=!1,this.init=function(){return e(z,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return[4,this.countrySettings.waitUntilInitialized()];case 1:return e.sent(),[4,R.getInstance().customerStore.waitUntilInitialized()];case 2:return e.sent(),this.createCustomer(),this.createShippingAddress(),this.createBillingAddress(),[4,this.getCampaignOffer()];case 3:return e.sent(),[4,this.initStep()];case 4:return e.sent(),[2]}}))}))},this.initStep=function(){return e(z,void 0,void 0,(function(){var e,s,n,r,a,c,d;return t(this,(function(t){switch(t.label){case 0:if(D.getIsEditor())return this.step=_.INFO,this.isCheckoutLoaded=!0,[2];if(e=new URLSearchParams(window.location.search),s=e.get("step"),n=e.get("failed"),r=e.get("error"),s){if(this.step=s,this.step===_.SHIPPING&&!this.canProceedToShipping)return[2,this.changeStep(_.INFO)];if(this.step!==_.PAYMENT||this.canProceedToPayment){if(this.step===_.SUCCESS&&!this.canProceedToPayment)return[2,this.changeStep(_.INFO)];if(![_.INFO,_.SUCCESS,_.SHIPPING,_.PAYMENT].includes(this.step))return[2,this.changeStep(_.INFO)]}else{if(!this.isInStoreDelivery)return this.isValidShippingSettings?[2,this.changeStep(_.INFO)]:[2,this.changeStep(_.SHIPPING)];this.deliveryMethod="in-store"}}return n&&(this.error={type:U.PAYMENT_ERROR,data:r||null}),this.step!==_.SHIPPING&&this.step!==_.PAYMENT||this.isCouponCodeRequirementInvisible||(this.checkoutSettings=new g(i(i({},this.checkoutSettings),{couponCodeRequirement:o.DEFAULT}))),this.step!==_.INFO?[3,6]:this.isDigitalOnly?[3,3]:[4,this.getAvailableShippingZones()];case 1:return t.sent(),this.createCustomer(),this.createShippingAddress(),this.createBillingAddress(),[4,this.getShippingCountries()];case 2:t.sent(),this.checkShippingCountries(),t.label=3;case 3:return[4,this.getStockLocations()];case 4:return t.sent(),[4,this.getAvailableStockLocations()];case 5:t.sent(),this.isInStoreDelivery&&(this.deliveryMethod="in-store"),t.label=6;case 6:return this.step!==_.SHIPPING||1!==(null===(c=this.checkout.availableShippingMethods)||void 0===c?void 0:c.length)||this.checkoutSettings.isGiftPackageEnabled||(this.step=_.PAYMENT,this.router.replace("/checkout?id=".concat(this.checkout.id,"&step=").concat(this.step),void 0,{shallow:!0})),this.step!==_.SHIPPING||(null===(d=this.checkout.availableShippingMethods)||void 0===d?void 0:d.length)?this.step!==_.PAYMENT&&this.step!==_.SUCCESS?[3,10]:[4,this.listPaymentGateways()]:(this.error={type:U.NO_SHIPPING_ERROR},this.isCheckoutLoaded=!0,[2]);case 7:return t.sent(),this.isInStoreDelivery?(this.deliveryMethod="in-store",[4,this.getStockLocations()]):[3,9];case 8:t.sent(),t.label=9;case 9:if(!this.paymentGateways.length)return this.error={type:U.NO_SHIPPING_ERROR},this.isCheckoutLoaded=!0,[2];t.label=10;case 10:return this.step===_.SUCCESS?[3,14]:this.checkout.isComplete?[2,this.changeStep(_.SUCCESS)]:[3,11];case 11:return[4,this.initialStockCheck()];case 12:t.sent(),t.label=13;case 13:return[3,16];case 14:return[4,this.getSuccessTransaction()];case 15:t.sent(),this.successTransaction&&(a=this.successTransaction.paymentGatewayId,this.checkout.selectedPaymentGateway=this.paymentGateways.find((function(e){return e.id===a}))),t.label=16;case 16:return this.isCheckoutLoaded=!0,x.checkoutStep(this.checkout,this.step),[2]}}))}))},this.getSuccessTransaction=function(){return e(z,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return[4,I.listOrderTransactions({orderId:{eq:this.checkout.id}})];case 1:return e=t.sent(),this.successTransaction=e.isSuccess&&(null===(i=e.data)||void 0===i?void 0:i.length)?e.data[e.data.length-1]:void 0,[2]}}))}))},this.saveCart=function(){return e(z,void 0,void 0,(function(){var e,i,s,n;return t(this,(function(t){switch(t.label){case 0:return e=new T(this.checkout),"in-store"!==this.deliveryMethod?[3,2]:[4,this.inStockDeliveryInputData(e)];case 1:e=t.sent(),t.label=2;case 2:return this.step!==_.INFO&&this.step!==_.SHIPPING||this.isDigitalOnly||(e.billingAddress=null),this.isDigitalOnly&&(e.shippingAddress=null),e.customer&&(this.store.customerStore.customer?e.customer.notificationsAccepted=this.store.customerStore.customer.subscriptionStatus===m.SUBSCRIBED:this.checkout.customer&&(e.customer.notificationsAccepted=this.checkout.customer.notificationsAccepted||!1)),[4,w.saveCart({input:e})];case 3:if((null==(i=t.sent())?void 0:i.graphQLErrors)&&i.graphQLErrors.length)throw s=i.graphQLErrors[0],"CUSTOMER_LOGIN_REQUIRED"===(null===(n=s.extensions)||void 0===n?void 0:n.code)?{type:U.CUSTOMER_LOGIN_REQUIRED_ERROR}:{type:U.API_ERROR,data:i.firstErrorMessage};return[2,i.data]}}))}))},this.inStockDeliveryInputData=function(i){return e(z,void 0,void 0,(function(){var e,s,n=this;return t(this,(function(t){return e=i,(s=this.stockLocations.find((function(e){return e.id===n.checkout.stockLocationId})))&&e.shippingAddress&&s.address&&(e.shippingAddress.country=s.address.country,e.shippingAddress.city=s.address.city,e.shippingAddress.state=s.address.state,e.shippingAddress.district=s.address.district,e.shippingAddress.postalCode=s.address.postalCode,e.shippingAddress.addressLine1=s.address.address||"",e.shippingAddress.addressLine2=null),[2,e]}))}))},this.checkStocks=function(){return e(z,void 0,void 0,(function(){var e,i,s,n,r,o,a,c,d,u,l,h;return t(this,(function(t){switch(t.label){case 0:return this.isManualOrder?[2]:(e=this.checkout.items.map((function(e){return{quantity:e.quantity,variantId:e.variant.id,productId:e.variant.productId}})),[4,A.checkStocks({lines:e.map((function(e){return new G(e)})),stockLocationIdList:(null===(u=D.getStockLocationIds())||void 0===u?void 0:u.length)?D.getStockLocationIds():null})]);case 1:if(!(i=t.sent()).isSuccess)throw{type:U.API_ERROR,data:i.firstErrorMessage};if(null==(s=null===(h=null===(l=i.data)||void 0===l?void 0:l.lines)||void 0===h?void 0:h.filter((function(e){return!e.isAvailable})))?void 0:s.length){for(n=[],r=function(e){var t=o.checkout.items.find((function(t){return t.variant.id===e.variantId}));t&&n.push({item:t,stockCount:e.stockCount})},o=this,a=0,c=s;a<c.length;a++)d=c[a],r(d);throw{type:U.STOCK_ERROR,data:n}}return[2]}}))}))},this.setIsKlarnaPaymentCompleted=function(i){return e(z,void 0,void 0,(function(){return t(this,(function(e){return this.isKlarnaPaymentCompleted=i,[2]}))}))},this.removeUnavailableItems=function(i){return e(z,void 0,void 0,(function(){var e,s,n;return t(this,(function(t){switch(t.label){case 0:e=0,s=i,t.label=1;case 1:return e<s.length?(n=s[e],[4,R.getInstance().cartStore.changeItemQuantity(n.item,n.stockCount<0?0:n.stockCount)]):[3,4];case 2:t.sent(),t.label=3;case 3:return e++,[3,1];case 4:return[2]}}))}))},this.getShippingCountries=function(){return e(z,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,A.getAvailableShippingCountries({salesChannelId:D.getSalesChannelId()})];case 1:return e=t.sent(),this.shippingCountryIds=e.data,[2]}}))}))},this.getStockLocations=function(){return e(z,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return D.getPickupStockLocationIds()?[4,A.listStockLocation({id:{in:D.getPickupStockLocationIds()}})]:[3,2];case 1:if(!(e=t.sent()).isSuccess||!(null===(i=e.data)||void 0===i?void 0:i.length))return this.error={type:U.API_ERROR,data:e.firstErrorMessage},[2];this.stockLocations=e.data,t.label=2;case 2:return[2]}}))}))},this.getAvailableStockLocations=function(){return e(z,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return D.getPickupStockLocationIds()?(e=this.checkout.items.map((function(e){return{quantity:e.quantity,variantId:e.variant.id,productId:e.variant.productId}})),[4,A.getAvailableStockLocations({lines:e.map((function(e){return new G(e)})),stockLocationIdList:D.getPickupStockLocationIds()})]):[3,2];case 1:if(!(i=t.sent()).isSuccess)return this.error={type:U.API_ERROR},[2];this.availableStockLocations=i.data||[],t.label=2;case 2:return[2]}}))}))},this.checkShippingCountries=function(){var e;(null===(e=z.shippingCountryIds)||void 0===e?void 0:e.length)||(z.error={type:U.NO_SHIPPING_ERROR})},this.onDeliveryMethodChange=function(e){"address"===e&&(z.checkout.stockLocationId=null),z.deliveryMethod=e,z.isErrorsVisible=!1},this.initialStockCheck=function(){return e(z,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,this.checkStocks()];case 1:return t.sent(),[3,3];case 2:return void 0!==typeof(e=t.sent()).type?this.error=e:(console.log(e),this.error={type:U.UNKNOWN}),[3,3];case 3:return[2]}}))}))},this.listPaymentGateways=function(){return e(z,void 0,void 0,(function(){var e,i,s,n,o,a,c,d,u,l,h=this;return t(this,(function(t){switch(t.label){case 0:return e="local"===process.env.NEXT_PUBLIC_ENV,i=D.getPaymentGateways().map((function(e){return e.id})),[4,A.listPaymentGateway({id:e?void 0:{in:i},locale:D.getCurrentLocale(),transactionAmount:this.checkout.totalFinalPrice})];case 1:return(s=t.sent()).isSuccess&&(null===(u=s.data)||void 0===u?void 0:u.length)?(n=s.data,this.step===_.PAYMENT&&(n=n.filter((function(e){var t;return!(null===(t=e.supportedCurrencies)||void 0===t?void 0:t.length)||e.supportedCurrencies.includes(h.checkout.currencyCode)})),(o=null===(l=this.checkout.shippingAddress)||void 0===l?void 0:l.country)&&o.iso2&&(n=n.filter((function(e){var t;return!(null===(t=e.availableCountries)||void 0===t?void 0:t.length)||e.availableCountries.includes(o.iso2||"")})))),a=[],r(D.getPaymentGateways(),"order").forEach((function(e){var t=null==n?void 0:n.find((function(t){return t.id===e.id}));t&&a.push(t)})),this.paymentGateways=e?n:a,this.checkout.selectedPaymentGateway||this.setPaymentGateway(0),this.step===_.PAYMENT&&(c=n.find((function(e){return!!e.masterPassClientId})))&&(this.checkout.masterPassPaymentGateway=c,(d=document.createElement("script")).id=j,d.src=O,d.onload=function(){h.mpVM.checkMasterPass({checkout:h.checkout,store:R.getInstance()})},document.head.appendChild(d)),[2]):(this.error={type:U.API_ERROR,data:s.firstErrorMessage},[2])}}))}))},this.retrieveInstallmentInfo=function(i){return e(z,void 0,void 0,(function(){var e,s,n;return t(this,(function(t){switch(t.label){case 0:return[4,A.retrieveInstallmentInfo(i)];case 1:return e=t.sent(),s=e.data,null===(n=null==s?void 0:s.installmentPrices)||void 0===n||n.sort((function(e,t){return(e.installmentCount||-1)>(t.installmentCount||-1)?1:-1})),this.installmentInfo=s,[2]}}))}))},this.createCustomer=function(){var e;z.store.customerStore.customer?(null===(e=z.customerAddresses)||void 0===e||e.forEach((function(e){e.checkoutSettings=z.checkoutSettings,e.shippingZones=z.shippingZones})),z.checkout.customer=new k(z.store.customerStore.customer)):z.checkout.customer=new k(z.checkout.customer||{})},this.setCheckoutShippingAddressSettings=function(){z.checkout.shippingAddress&&(z.checkout.shippingAddress.checkoutSettings=z.checkoutSettings,z.checkout.shippingAddress.shippingZones=z.shippingZones,z.checkout.shippingAddress.countrySettings=z.countrySettings,z.checkout.shippingAddress.getValidatedCustomerAddress())},this.setCheckoutBillingAddressSettings=function(){z.checkout.billingAddress&&(z.checkout.billingAddress.checkoutSettings=z.checkoutSettings,z.checkout.billingAddress.shippingZones=z.shippingZones,z.checkout.billingAddress.countrySettings=z.countrySettings,z.checkout.billingAddress.getValidatedCustomerAddress())},this.createShippingAddress=function(){if(!z.isDigitalOnly)if(z.isInStoreDelivery)z.setCheckoutShippingAddressSettings();else if(z.checkout.shippingAddress){if(z.store.customerStore.customer){var e=null==(t=z.customerAddresses)?void 0:t.find((function(e){var t;return e.id===(null===(t=z.checkout.shippingAddress)||void 0===t?void 0:t.id)}));if(e)return z.onSelectedShippingAddressIdChange(e.id||"-1"),void z.setCheckoutShippingAddressSettings()}z.checkout.shippingAddress=new L(n(z.checkout.shippingAddress)||{}),z.setCheckoutShippingAddressSettings()}else if(z.store.customerStore.customer){var t=z.customerAddresses;z.onSelectedShippingAddressIdChange((null==t?void 0:t.length)?t[0].id:"-1")}else z.onSelectedShippingAddressIdChange("-1")},this.createBillingAddress=function(){if("undefined"!=typeof localStorage)if(z.useDifferentAddress=!!localStorage.getItem("sAddr"),z.checkout.billingAddress){if(z.store.customerStore.customer){var e=null==(t=z.customerAddresses)?void 0:t.find((function(e){var t;return e.id===(null===(t=z.checkout.billingAddress)||void 0===t?void 0:t.id)}));if(e)return z.onSelectedBillingAddressIdChange(e.id||"-1"),void z.setCheckoutBillingAddressSettings()}z.checkout.billingAddress=new L(n(z.checkout.billingAddress)||{}),z.setCheckoutBillingAddressSettings()}else if(z.store.customerStore.customer){var t=z.customerAddresses;z.onSelectedBillingAddressIdChange((null==t?void 0:t.length)?t[0].id:"-1"),(null==t?void 0:t.length)||z.useDifferentAddress||!z.checkout.shippingAddress||z.isInStoreDelivery||(z.checkout.billingAddress=new L(n(z.checkout.shippingAddress)),z.setCheckoutBillingAddressSettings())}else z.onSelectedBillingAddressIdChange("-1"),z.useDifferentAddress||!z.checkout.shippingAddress||z.isInStoreDelivery||(z.checkout.billingAddress=new L(n(z.checkout.shippingAddress)),z.setCheckoutBillingAddressSettings())},this.onShippingMethodChange=function(i){return e(z,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return this.isChangingShippingMethod?[2]:(this.isChangingShippingMethod=!0,this.checkout.shippingSettingsId=i.shippingSettingsId,this.checkout.shippingZoneRateId=i.shippingZoneRateId,[4,this.saveCart()]);case 1:return(e=t.sent())&&(this.checkout=new f(e,this.countrySettings)),this.checkout.shippingAddress&&(this.checkout.shippingAddress.checkoutSettings=this.checkoutSettings,this.checkout.shippingAddress.shippingZones=this.shippingZones),this.isChangingShippingMethod=!1,[2]}}))}))},this.onStockLocationChange=function(i){return e(z,void 0,void 0,(function(){return t(this,(function(e){return this.checkout.stockLocationId=i.id,[2]}))}))},this.onCouponCodeApply=function(){return e(z,void 0,void 0,(function(){var e,s,n,r,o,a;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,5,,6]),[4,w.saveCartCouponCode({cartId:this.checkout.id,couponCode:this.checkout.couponCode||null})];case 1:return(e=t.sent()).isSuccess&&e.data?(s=e.data,n=null===(a=null===(o=this.cardData)||void 0===o?void 0:o.cardNumber)||void 0===a?void 0:a.split(" ").join(""),this.couponError=null,this.step===_.PAYMENT&&(null==n?void 0:n.length)&&n.length>=6&&this.retrieveInstallmentInfo({input:{binNumber:n.slice(0,6),paymentGatewayId:this.checkout.selectedPaymentGateway.id,price:s.totalFinalPrice}}),this.mpVM.selectedCard&&this.mpVM.selectedCard.Value1?[4,this.retrieveInstallmentInfo({input:{binNumber:this.mpVM.selectedCard.Value1.slice(0,6),paymentGatewayId:this.mpVM.selectedCard.paymentGatewayId,price:s.totalFinalPrice}})]:[3,3]):[3,4];case 2:t.sent(),t.label=3;case 3:s&&(r=this.checkout,this.checkout=new f(i(i({},s),{shippingAddress:r.shippingAddress,billingAddress:r.billingAddress,customer:r.customer,selectedPaymentGateway:r.selectedPaymentGateway}),this.countrySettings)),t.label=4;case 4:return e.isSuccess||(this.couponError=e.errorCodes[0]),[3,6];case 5:return t.sent(),[3,6];case 6:return[2]}}))}))},this.getAvailableShippingZones=function(){return e(z,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,M.getAvailableShippingZones({salesChannelId:D.getSalesChannelId()})];case 1:return e=t.sent(),this.shippingZones=e.data||null,[3,3];case 2:return t.sent(),[3,3];case 3:return[2]}}))}))},this.onSelectedShippingAddressIdChange=function(e){var t;if(z.selectedShippingAddressId=e,"-1"===e)z.checkout.shippingAddress=new L,z.checkout.shippingAddress.countrySettings=z.countrySettings;else{var i=null===(t=z.customerAddresses)||void 0===t?void 0:t.find((function(t){return t.id===e}));i&&(z.checkout.shippingAddress=new L(i),z.checkout.shippingAddress.countrySettings=z.countrySettings)}z.checkout.shippingAddress&&(z.checkout.shippingAddress.checkoutSettings=z.checkoutSettings,z.checkout.shippingAddress.shippingZones=z.shippingZones)},this.onSelectedBillingAddressIdChange=function(e){var t;if(z.selectedBillingAddressId=e,"-1"===e)z.checkout.billingAddress=new L,z.checkout.billingAddress.countrySettings=z.countrySettings;else{var i=null===(t=z.customerAddresses)||void 0===t?void 0:t.find((function(t){return t.id===e}));i&&(z.checkout.billingAddress=new L(i),z.checkout.billingAddress.countrySettings=z.countrySettings)}z.checkout.billingAddress&&(z.checkout.billingAddress.checkoutSettings=z.checkoutSettings,z.checkout.billingAddress.shippingZones=z.shippingZones)},this.onTermsAndConditionsCheckedChange=function(e){z.isTermsAndConditionsChecked=e},this.onCardNumberChange=function(e){if(z.cardData&&(!(e.length>z.cardData.cardNumber.length)||Y(e))){var t=(z.cardData.cardNumber||"").split(" ").join(""),i=e.split(" ").join("");i.length>16||(t.length<6&&i.length>=6&&!z.installmentInfo?z.retrieveInstallmentInfo({input:{binNumber:i.slice(0,6),paymentGatewayId:z.checkout.selectedPaymentGateway.id,price:z.checkout.totalFinalPrice}}):i.length<6&&t.length>i.length&&(z.cardData.installmentCount=1,z.installmentInfo=void 0),z.cardData.cardNumber=Z(i,4).join(" "))}},this.onCardHolderNameChange=function(e){z.cardData&&(z.cardData.cardHolderName=e)},this.onExpirationDateChange=function(e){var t;if(z.cardData&&(!(e.length>z.cardData.expirationDate.length)||Y(e))){if(0===(null===(t=z.cardData.expirationDate)||void 0===t?void 0:t.length)){var i=e.replace(".","/").split("/");if(2===i.length){var s=i[0].trim(),n=i[1].trim();if(4===s.length&&2===n.length){var r=parseInt(s.slice(2)),o=parseInt(n);if(!isNaN(r)&&!isNaN(o))return void(z.cardData.expirationDate="".concat(o<10?"0"+o:o," / ").concat(r<10?"0"+r:r))}if(2===s.length&&4===n.length){o=parseInt(s),r=parseInt(n.slice(2));if(!isNaN(r)&&!isNaN(o))return void(z.cardData.expirationDate="".concat(o<10?"0"+o:o," / ").concat(r<10?"0"+r:r))}if(2===s.length&&2===n.length){var a=parseInt(s),c=parseInt(n);o=a<=12?a:c,r=c>12?c:a;if(!isNaN(r)&&!isNaN(o))return void(z.cardData.expirationDate="".concat(o<10?"0"+o:o," / ").concat(r<10?"0"+r:r))}}}var d=e.split(" / ").join("");d.length>4||(z.cardData.expirationDate=Z(d,2).join(" / "))}},this.onCvcChange=function(e){z.cardData&&(e.length>z.cardData.cvv.length&&!Y(e)||e.length>4||(z.cardData.cvv=e))},this.saveAddress=function(s){return e(z,void 0,void 0,(function(){var e,r,o,a,c,d,u,l,h,p,m,f,g=this;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,3,,4]),this.shouldSaveAddress&&this.store.customerStore.customer?(e="shipping"===s?this.checkout.shippingAddress:this.checkout.billingAddress,(null===(h=this.customerAddresses)||void 0===h?void 0:h.find((function(t){return t.id===(null==e?void 0:e.id)})))?[2]:(r=null===(p=this.customerAddresses)||void 0===p?void 0:p.map((function(e){return e.id})),o=new v(i(i({},e),{title:this.addressTitle||this.t("checkout-page:newAddress")})),(a=n(this.store.customerStore.customer)).addresses||(a.addresses=[]),a.addresses.push(o),[4,this.store.customerStore.saveCustomer(a)])):[3,2];case 1:t.sent(),null===(m=this.customerAddresses)||void 0===m||m.forEach((function(e){e.checkoutSettings=g.checkoutSettings,e.shippingZones=g.shippingZones})),c=null===(f=this.customerAddresses)||void 0===f?void 0:f.map((function(e){return e.id})),d=null==c?void 0:c.filter((function(e){return!(null==r?void 0:r.includes(e))})),u=(null==d?void 0:d.length)?d[0]:void 0,"shipping"===s?(this.checkout.shippingAddress.id=u||"",this.selectedShippingAddressId=u||"-1"):(this.checkout.billingAddress.id=u||"",this.selectedBillingAddressId=u||"-1"),t.label=2;case 2:return[3,4];case 3:return l=t.sent(),console.error(l),[3,4];case 4:return[2]}}))}))},this.onGoToCartClick=function(){z.router.push("/cart")},this.onBackToShoppingClick=function(){z.router.push("/")},this.onGoToLoginClick=function(){z.router.push("/account/login")},this.onProceedToShippingClick=function(){return e(z,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:if("address"===this.deliveryMethod){if(!this.canProceedToShipping)return this.isErrorsVisible=!0,[2]}else if(!this.canProceedToInStoreDelivery)return this.isErrorsVisible=!0,[2];this.isErrorsVisible=!1,t.label=1;case 1:return t.trys.push([1,6,,7]),this.isStepLoading=!0,"address"!==this.deliveryMethod?[3,3]:[4,this.saveAddress("shipping")];case 2:t.sent(),t.label=3;case 3:return[4,this.checkStocks()];case 4:return t.sent(),[4,this.saveCart()];case 5:return t.sent(),"address"===this.deliveryMethod?this.changeStep(_.SHIPPING):this.changeStep(_.PAYMENT),[3,7];case 6:return void 0!==typeof(e=t.sent()).type?this.error=e:(console.log(e),this.error={type:U.UNKNOWN}),this.isStepLoading=!1,[3,7];case 7:return[2]}}))}))},this.onProceedToDigitalOnlyPaymentClick=function(){return e(z,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:if(!this.canProceedToPayment)return this.isErrorsVisible=!0,[2];this.isErrorsVisible=!1,t.label=1;case 1:return t.trys.push([1,4,,5]),this.isStepLoading=!0,[4,this.checkStocks()];case 2:return t.sent(),[4,this.saveCart()];case 3:return t.sent(),this.changeStep(_.PAYMENT),[3,5];case 4:return(e=t.sent()).type?this.error=e:(console.log(e),this.error={type:U.UNKNOWN}),this.isStepLoading=!1,[3,5];case 5:return[2]}}))}))},this.onProceedToPaymentClick=function(){return e(z,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:if(!this.canProceedToPayment)return this.isErrorsVisible=!0,[2];this.isErrorsVisible=!1,t.label=1;case 1:return t.trys.push([1,4,,5]),this.isStepLoading=!0,[4,this.checkStocks()];case 2:return t.sent(),[4,this.saveCart()];case 3:return t.sent(),this.error=void 0,this.changeStep(_.PAYMENT),[3,5];case 4:return void 0!==typeof(e=t.sent()).type?this.error=e:(console.log(e),this.error={type:U.UNKNOWN}),this.isStepLoading=!1,[3,5];case 5:return[2]}}))}))},this.checkPaypalButtonAvailable=function(){return!!z.canPerformPayment||(z.isErrorsVisible=!0,!1)},this.onCompletePaymentClick=function(){return e(z,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return this.canPerformPayment?(this.useDifferentAddress||(this.checkout.billingAddress=this.checkout.shippingAddress),this.isFree||!this.isKlarna?[3,2]:[4,this.saveCart()]):(this.isErrorsVisible=!0,[2]);case 1:return t.sent(),this.setIsKlarnaPaymentCompleted(!0),[2];case 2:return t.trys.push([2,8,,9]),this.isErrorsVisible=!1,this.isStepLoading=!0,[4,this.checkStocks()];case 3:return t.sent(),"address"===this.deliveryMethod&&this.useDifferentAddress?[4,this.saveAddress("billing")]:[3,5];case 4:t.sent(),t.label=5;case 5:return[4,this.saveCart()];case 6:return t.sent(),!this.isFree&&this.isCustomFlowStripe?((e=document.querySelector("#stripe-form-btn"))&&e.click(),[2]):!this.isFree&&this.isAdyen?(this.adyenDropinElement.submit(),this.adyenDropinElement.isValid||(this.isStepLoading=!1),[2]):!this.isFree&&this.isPayPal?[2]:[4,this.createSaleTransaction()];case 7:return t.sent(),[3,9];case 8:return void 0!==typeof(i=t.sent()).type?this.error=i:this.error={type:U.UNKNOWN},this.isStepLoading=!1,[3,9];case 9:return[2]}}))}))},this.onCompleteDigitalOnlyPaymentClick=function(){return e(z,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return!this.canProceedToPayment||this.checkoutSettings.showTermsAndConditionsCheckbox&&!this.isTermsAndConditionsChecked?(this.isErrorsVisible=!0,[2]):this.isKlarna?[4,this.saveCart()]:[3,2];case 1:return t.sent(),this.setIsKlarnaPaymentCompleted(!0),[2];case 2:return t.trys.push([2,6,,7]),this.isErrorsVisible=!1,this.isStepLoading=!0,[4,this.checkStocks()];case 3:return t.sent(),[4,this.saveCart()];case 4:return t.sent(),this.isCustomFlowStripe?((e=document.querySelector("#stripe-form-btn"))&&e.click(),[2]):this.isAdyen?(this.adyenDropinElement.submit(),this.adyenDropinElement.isValid||(this.isStepLoading=!1),[2]):this.isPayPal?[2]:[4,this.createSaleTransaction()];case 5:return t.sent(),[3,7];case 6:return(i=t.sent()).type?this.error=i:this.error={type:U.UNKNOWN},this.isStepLoading=!1,[3,7];case 7:return[2]}}))}))},this.createSaleTransaction=function(){return e(z,void 0,void 0,(function(){var e,i,s,n,r,o,d,u,h,p,m,f,g,v,y;return t(this,(function(t){switch(t.label){case 0:return i=this.mpVM.selectedCard,!this.isFree&&i&&(null===(u=this.mpVM.selectedCard)||void 0===u?void 0:u.Name)?((n=this.mpVM.phoneNumber({store:this.store,checkout:this.checkout}))&&(e=n),void 0===(null===(h=this.cardData)||void 0===h?void 0:h.installmentCount)?[2]:[4,A.createSaleTransactionWithCart({input:{cartId:this.checkout.id,masterPassDetail:{phoneNumber:e,savedCardName:null===(p=this.mpVM.selectedCard)||void 0===p?void 0:p.Name},paymentGatewayId:null===(m=this.mpVM.selectedCard)||void 0===m?void 0:m.paymentGatewayId,paymentMethodDetail:{cardNumber:this.mpVM.selectedCard.Value1,cardHolderName:this.mpVM.selectedCard.Name,cvv:this.mpVM.selectedCard.Value2,expiredMonth:11,expiredYear:11,installmentCount:this.cardData.installmentCount,threeDSecure:!!(null===(f=this.cardData)||void 0===f?void 0:f.threeDSecure)},metadata:{_fbp:V("_fbp"),_fbc:V("_fbc")}}})]):[3,2];case 1:return s=t.sent(),[3,4];case 2:return this.checkout.selectedPaymentGateway?[4,A.createSaleTransactionWithCart({input:{cartId:this.checkout.id,masterPassDetail:this.isFree?void 0:i&&e?{phoneNumber:e,savedCardName:null===(g=this.mpVM.selectedCard)||void 0===g?void 0:g.Name}:void 0,paymentGatewayId:this.checkout.selectedPaymentGateway.id,paymentMethodDetail:this.isFree||i?void 0:this.checkout.selectedPaymentGateway.paymentMethodType===a.CREDIT_CARD&&this.checkout.selectedPaymentGateway.type===c.INTERNAL&&this.cardData?this.cardData.toInput():void 0}})]:[2];case 3:s=t.sent(),t.label=4;case 4:return r=null===(v=null==s?void 0:s.data)||void 0===v?void 0:v.transactionStatus,o=r&&[l.SUCCESS,l.AUTHORIZED].includes(r),d=r===l.PENDING,o?[4,this.getSuccessTransaction()]:[3,7];case 5:return t.sent(),[4,this.onCheckoutTransactionSuccess()];case 6:return t.sent(),[3,8];case 7:if(!d||!(null===(y=null==s?void 0:s.data)||void 0===y?void 0:y.returnSlug))throw{data:s.firstErrorMessage,type:U.UNKNOWN};window.location.href=process.env.NEXT_PUBLIC_BASE_URL+s.data.returnSlug,t.label=8;case 8:return[2]}}))}))},this.onCheckoutTransactionSuccess=function(){return e(z,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return localStorage.removeItem("sAddr"),(null===(e=this.checkout.customer)||void 0===e?void 0:e.notificationsAccepted)?[4,this.store.customerStore.createEmailSubscription((null===(i=this.checkout.customer)||void 0===i?void 0:i.email)||"")]:[3,2];case 1:t.sent(),t.label=2;case 2:return this.changeStep(_.SUCCESS),[2]}}))}))},this.onBackToInfoClick=function(){z.changeStep(_.INFO)},this.onBackToShippingClick=function(){z.changeStep(_.SHIPPING)},this.setCustomerConsentGranted=function(e){z.checkout.customer&&(z.checkout.customer.notificationsAccepted=e)},this.setUseDifferentAddress=function(e){z.useDifferentAddress=e,z.useDifferentAddress?(localStorage.setItem("sAddr","1"),z.checkout.billingAddress=z.checkout.billingAddress||new L,z.checkout.billingAddress.countrySettings=z.countrySettings):(localStorage.removeItem("sAddr"),z.checkout.billingAddress=z.checkout.shippingAddress)},this.setShouldSaveAddress=function(e){z.shouldSaveAddress=e},this.setAddressTitle=function(e){z.addressTitle=e},this.reInitPaymentMethod=function(){return e(z,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return this.checkout.selectedPaymentGateway?this.isCustomFlowStripe?[4,this.createStripePaymentIntent(this.checkout.selectedPaymentGateway)]:[3,2]:[3,6];case 1:e.sent(),e.label=2;case 2:return this.isKlarna&&window.location.reload(),this.isAdyen?[4,this.createAdyenClientToken(this.checkout.selectedPaymentGateway)]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.isPayPal?[4,this.getPayPalClientId(this.checkout.selectedPaymentGateway)]:[3,6];case 5:e.sent(),e.label=6;case 6:return[2]}}))}))},this.createStripePaymentIntent=function(i){return e(z,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,A.createStripePaymentIntent({input:{cartId:this.checkout.id,paymentGatewayId:i.id||""}})];case 1:return(e=t.sent()).isSuccess&&e.data&&(this.stripeResponse=e.data),[2]}}))}))},this.createKlarnaClientToken=function(i){return e(z,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,A.createKlarnaClientToken({input:{cartId:this.checkout.id,paymentGatewayId:i.id||""}})];case 1:return(e=t.sent()).isSuccess&&e.data&&(this.klarnaResponse=e.data),[2]}}))}))},this.createAdyenClientToken=function(i){return e(z,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,A.createAdyenClientToken({input:{cartId:this.checkout.id,paymentGatewayId:i.id||""}})];case 1:return(e=t.sent()).isSuccess&&e.data&&(this.adyenResponse=e.data),[2]}}))}))},this.getPayPalClientId=function(i){return e(z,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,A.getPayPalClientId({input:{cartId:this.checkout.id,paymentGatewayId:i.id||""}})];case 1:return(e=t.sent()).isSuccess&&e.data&&(this.payPalClientIdResponse=e.data),[2]}}))}))},this.setPaymentGateway=function(i){return e(z,void 0,void 0,(function(){var e,s;return t(this,(function(t){switch(t.label){case 0:return this.paymentGateways.length?"STRIPE"!==(e=this.paymentGateways[i]).code||!(null===(s=e.settings)||void 0===s?void 0:s.find((function(e){return"allow_custom_flow"===e.label&&"1"===e.value})))||this.stripeResponse?[3,2]:[4,this.createStripePaymentIntent(e)]:[2];case 1:t.sent(),t.label=2;case 2:return"KLARNA"!==e.code||this.klarnaResponse?[3,4]:[4,this.createKlarnaClientToken(e)];case 3:t.sent(),t.label=4;case 4:return"ADYEN"!==e.code||this.adyenResponse?[3,6]:[4,this.createAdyenClientToken(e)];case 5:t.sent(),t.label=6;case 6:return"PAYPAL"!==e.code||this.payPalClientIdResponse?[3,8]:[4,this.getPayPalClientId(e)];case 7:t.sent(),t.label=8;case 8:return this.checkout.selectedPaymentGateway=e,this.step!==_.SUCCESS&&(e.paymentMethodType===a.CREDIT_CARD&&e.type===c.INTERNAL&&(this.cardData=new P,e.masterPassClientId&&(console.log("called 1511 ikas log"),this.mpVM.checkMasterPass({checkout:this.checkout,store:this.store}))),this.installmentInfo=void 0),[2]}}))}))},this.setInstallmentCount=function(e){z.cardData&&(z.cardData.installmentCount=e)},this.changeStep=function(i){return e(z,void 0,void 0,(function(){return t(this,(function(e){return K||window.location.replace("".concat(window.location.pathname,"?id=").concat(this.checkout.id,"&step=").concat(i)),[2]}))}))},this.logout=function(){return e(z,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:this.checkout.customer=null,this.store.customerStore.logout(),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.saveCart()];case 2:case 3:return e.sent(),[3,4];case 4:return this.createCustomer(),[2]}}))}))},this.setContactModalVisible=function(e){z.isContactModalVisible=e},this.getCampaignOfferProducts=function(i){return e(z,void 0,void 0,(function(){var e,s,n,r;return t(this,(function(o){switch(o.label){case 0:if(!this.checkout.campaignOffers||!this.checkout.campaignOffers.length)return[3,4];if(e=this.checkout.campaignOffers.filter((function(e){var t;return e.status===h.WAITING_FOR_ACTION&&(null===(t=e.campaignOffer)||void 0===t?void 0:t.targetPageTypes.some((function(e){return e===i})))})),!e.length)return[3,4];s=function(i){var s,n,r,o,a;return t(this,(function(t){switch(t.label){case 0:return(s=e[i]).campaignOffer&&(n=s.campaignOffer.offers.find((function(e){return e.id===s.campaignOfferProductId})))?[4,E.searchProducts({input:{productIdList:[n.productId]}})]:[3,2];case 1:if((r=t.sent()).isSuccess&&r.data&&r.data.data&&r.data.data.length&&(o=r.data.data[0],a=[],n.excludedVariantIdList&&n.excludedVariantIdList.length?o.variants.map((function(e){var t;e.hasStock&&!(null===(t=n.excludedVariantIdList)||void 0===t?void 0:t.some((function(t){return t===e.id})))&&a.push(e)})):a.push.apply(a,o.variants.filter((function(e){return e.hasStock}))),a.length))return[2,{value:{product:new b(o),variants:a,campaignOffer:s,offer:n}}];t.label=2;case 2:return[2]}}))},n=0,o.label=1;case 1:return n<e.length?[5,s(n)]:[3,4];case 2:if("object"==typeof(r=o.sent()))return[2,r.value];o.label=3;case 3:return n++,[3,1];case 4:return[2,void 0]}}))}))},this.getCampaignOffer=function(){return e(z,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return e=this,[4,this.getCampaignOfferProducts(p.CHECKOUT)];case 1:return e.checkoutCampaignOffer=t.sent(),i=this,[4,this.getCampaignOfferProducts(p.POST_CHECKOUT)];case 2:return i.postCheckoutCampaignOffer=t.sent(),[2]}}))}))},this.updateCartCampaignOffer=function(i){return e(z,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return this.isCheckoutLoaded=!1,[4,w.updateCartCampaignOffer({input:i})];case 1:return(e=t.sent())&&e.isSuccess&&e.data&&(this.checkout=new f(e.data,this.countrySettings),i.accepted&&this.step===_.SUCCESS?this.changeStep(_.INFO):this.changeStep(this.step)),[2]}}))}))},this.registerCustomer=function(i){return e(z,void 0,void 0,(function(){var e,s,n,r;return t(this,(function(t){switch(t.label){case 0:return this.checkout.customer?(e=this.checkout.customer,s=e.firstName,n=e.lastName,r=e.email,s&&n&&r?[4,I.register({orderId:this.checkout.id,firstName:s,lastName:n,email:r,password:i})]:[3,2]):[3,2];case 1:return[2,t.sent()];case 2:return[2]}}))}))},this.checkout=d,this.checkoutSettings=u,this.router=y,this.returnPolicy=S,this.privacyPolicy=F,this.termsOfService=B,this.imprint=H,this.shippingPolicy=q,this.t=W,this.customizationProps=Q,this.mpVM=new N,this.isTermsAndConditionsChecked=this.checkoutSettings.isTermsAndConditionsDefaultChecked||!1,this.countrySettings=new C({currentLocale:D.getCurrentLocale()}),this.init(),s(this)}return Object.defineProperty(F.prototype,"merchantSettings",{get:function(){return new S(D.getMerchantSettings())},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"selectedPaymentGatewayIndex",{get:function(){var e=this;return this.paymentGateways.findIndex((function(t){var i;return t.id===(null===(i=e.checkout.selectedPaymentGateway)||void 0===i?void 0:i.id)}))},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"selectedInstallmentIndex",{get:function(){var e,t,i=this;return(null===(t=null===(e=this.installmentInfo)||void 0===e?void 0:e.installmentPrices)||void 0===t?void 0:t.findIndex((function(e){var t;return e.installmentCount===(null===(t=i.cardData)||void 0===t?void 0:t.installmentCount)})))||0},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"checkoutUrl",{get:function(){return"/checkout?id=".concat(this.checkout.id,"&step=info")},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"customerAddressOptions",{get:function(){var e,t,i={label:this.t("checkout-page:newAddress"),value:"-1"},s=(null===(t=null===(e=R.getInstance().customerStore.customer)||void 0===e?void 0:e.addresses)||void 0===t?void 0:t.map((function(e){return{label:e.title+" - "+e.addressText,value:e.id}})))||[];return[i].concat(s)},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"installmentPrice",{get:function(){var e,t,i,s=this;if(this.installmentInfo&&(null===(e=this.cardData)||void 0===e?void 0:e.installmentCount))return null===(i=null===(t=this.installmentInfo.installmentPrices)||void 0===t?void 0:t.find((function(e){var t;return e.installmentCount===(null===(t=s.cardData)||void 0===t?void 0:t.installmentCount)})))||void 0===i?void 0:i.totalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"installmentExtraPrice",{get:function(){if(this.installmentPrice&&this.checkout.totalFinalPrice)return this.installmentPrice-this.checkout.totalFinalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"finalPrice",{get:function(){return this.step===_.SUCCESS?this.checkout.totalFinalPrice:this.installmentPrice||this.checkout.$totalFinalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"hasStockError",{get:function(){var e;return(null===(e=this.error)||void 0===e?void 0:e.type)===U.STOCK_ERROR},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"isPaymentGatewayHasMasterPass",{get:function(){return-1!==this.selectedPaymentGatewayIndex&&(!!this.paymentGateways.length&&!!this.paymentGateways[this.selectedPaymentGatewayIndex].masterPassClientId)},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"hasQuickRegistration",{get:function(){return this.checkoutSettings.isQuickRegistrationEnabled&&this.checkout.customer&&this.checkout.customer.isGuestCheckout},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"canProceedToShipping",{get:function(){var e,t,i;return(this.isDigitalOnly?null===(e=this.checkout.billingAddress)||void 0===e?void 0:e.isValidAddress:null===(t=this.checkout.shippingAddress)||void 0===t?void 0:t.isValidAddress)&&this.checkout.hasValidCustomerEmail&&(null===(i=this.error)||void 0===i?void 0:i.type)!==U.NO_SHIPPING_ERROR},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"canProceedToInStoreDelivery",{get:function(){var e,t,i;return!!((null===(e=this.checkout.shippingAddress)||void 0===e?void 0:e.firstName)&&(null===(t=this.checkout.shippingAddress)||void 0===t?void 0:t.lastName)&&(null===(i=this.checkout.customer)||void 0===i?void 0:i.email)&&this.checkout.stockLocationId)},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"canProceedToPayment",{get:function(){return this.canProceedToShipping&&this.isValidShippingSettings},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"isValidShippingSettings",{get:function(){var e,t=this;return!(!this.isInStoreDelivery&&!this.isDigitalOnly)||this.checkout.shippingSettingsId&&this.checkout.shippingZoneRateId&&(null===(e=this.checkout.shippingLines)||void 0===e?void 0:e.some((function(e){return e.shippingSettingsId===t.checkout.shippingSettingsId&&e.shippingZoneRateId===t.checkout.shippingZoneRateId})))},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"isInStoreDelivery",{get:function(){return!!this.checkout.stockLocationId},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"klarnaPaymentGateway",{get:function(){var e=this.paymentGateways.findIndex((function(e){return"KLARNA"===e.code}));if(-1!==e)return this.paymentGateways[e]},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"klarnaPaymentGatewayIndex",{get:function(){return this.paymentGateways.findIndex((function(e){return"KLARNA"===e.code}))},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"adyenPaymentGateway",{get:function(){var e=this.paymentGateways.findIndex((function(e){return"ADYEN"===e.code}));if(-1!==e)return this.paymentGateways[e]},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"adyenPaymentGatewayIndex",{get:function(){return this.paymentGateways.findIndex((function(e){return"ADYEN"===e.code}))},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"payPalPaymentGateway",{get:function(){var e=this.paymentGateways.findIndex((function(e){return"PAYPAL"===e.code}));if(-1!==e)return this.paymentGateways[e]},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"payPalPaymentGatewayIndex",{get:function(){return this.paymentGateways.findIndex((function(e){return"PAYPAL"===e.code}))},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"isCustomFlowStripe",{get:function(){var e,t=this.checkout.selectedPaymentGateway;return t&&"STRIPE"===t.code&&(null===(e=t.settings)||void 0===e?void 0:e.find((function(e){return"allow_custom_flow"===e.label&&"1"===e.value})))},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"isKlarna",{get:function(){var e=this.checkout.selectedPaymentGateway;return e&&"KLARNA"===e.code},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"isAdyen",{get:function(){var e=this.checkout.selectedPaymentGateway;return e&&"ADYEN"===e.code},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"isPayPal",{get:function(){var e=this.checkout.selectedPaymentGateway;return e&&"PAYPAL"===e.code},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"isFree",{get:function(){return 0===this.checkout.totalFinalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"store",{get:function(){return R.getInstance()},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"isCouponCodeRequirementDefult",{get:function(){return this.checkoutSettings.couponCodeRequirement===o.DEFAULT||null===this.checkoutSettings.couponCodeRequirement},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"isCouponCodeRequirementOpen",{get:function(){return this.checkoutSettings.couponCodeRequirement===o.OPEN},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"isCouponCodeRequirementInvisible",{get:function(){return this.checkoutSettings.couponCodeRequirement===o.INVISIBLE},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"isCouponCodeVisible",{get:function(){return this.isCouponCodeRequirementDefult&&!this.isCouponCodeRequirementInvisible},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"canPerformPayment",{get:function(){var e,t;if(this.checkoutSettings.showTermsAndConditionsCheckbox&&!this.isTermsAndConditionsChecked)return!1;var i=this.checkout.selectedPaymentGateway,s=!!("in-store"===this.deliveryMethod)||!!this.canProceedToShipping,n=!!(null===(e=this.checkout.billingAddress)||void 0===e?void 0:e.isValidAddress),r=!!this.isFree||(!!this.mpVM.selectedCard||((null==i?void 0:i.paymentMethodType)===a.CREDIT_CARD&&i.type===c.INTERNAL?!!this.isCustomFlowStripe||(!(!this.isKlarna&&!this.isPayPal)||(null===(t=this.cardData)||void 0===t?void 0:t.isValid)):!!i));return s&&n&&r},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"isDigitalOnly",{get:function(){return this.checkout.shippingMethod===d.DIGITAL_DELIVERY},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"customerAddresses",{get:function(){var e,t,s=this;return null===(t=null===(e=this.store.customerStore.customer)||void 0===e?void 0:e.addresses)||void 0===t?void 0:t.map((function(e){var t=new y(i({countrySettings:s.countrySettings},e));return t.checkoutSettings=s.checkoutSettings,t.shippingZones=s.shippingZones,t.getValidatedCustomerAddress(),t}))},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"isManualOrder",{get:function(){return this.checkout.createdBy===u.ADMIN},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"isEPayKolayEnabled",{get:function(){var e=D.getCustom();return!!e&&!!e.isEPayKolayEnabled},enumerable:!1,configurable:!0}),Object.defineProperty(F.prototype,"isPoweredByHidden",{get:function(){var e=D.getCustom();return!!e&&!!e.hidePoweredBy},enumerable:!1,configurable:!0}),F.prototype.setAdyenDropinElement=function(e){this.adyenDropinElement=e},F}();function Z(e,t){return e.match(new RegExp(".{1,"+t+"}","g"))||[]}function Y(e){return e&&F.test(e.charAt(e.length-1))}!function(e){e.INFO="info",e.SHIPPING="shipping",e.PAYMENT="payment",e.SUCCESS="success"}(_||(_={})),function(e){e[e.UNKNOWN=0]="UNKNOWN",e[e.API_ERROR=1]="API_ERROR",e[e.STOCK_ERROR=2]="STOCK_ERROR",e[e.PAYMENT_ERROR=3]="PAYMENT_ERROR",e[e.NO_SHIPPING_ERROR=4]="NO_SHIPPING_ERROR",e[e.CUSTOMER_LOGIN_REQUIRED_ERROR=5]="CUSTOMER_LOGIN_REQUIRED_ERROR"}(U||(U={}));export{_ as CheckoutStep,U as ErrorType,B as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as t,__generator as e}from'./../../ext/tslib/tslib.es6.js';import{makeAutoObservable as i}from"mobx";import r from"./api.js";import{IkasStorefrontConfig as n}from"@ikas/storefront-config";import{Analytics as o}from"../../analytics/analytics.js";import"../../analytics/head/index.js";import{SaveCartInput as s}from"@ikas/storefront-api";import{getCookieValue as a}from"../../utils/helper.js";var c,u="cartId",d=function(){function u(u){var d=this;this.cart=null,this._isLoadingCart=!1,this._isCartLoadFinished=!1,this.addItem=function(i,s,u){return void 0===u&&(u=1),t(d,void 0,void 0,(function(){var t,d,l,h,f,v,p,I,m,C;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,5,,6]),s.hasValidProductOptionValues?i.hasStock||i.sellIfOutOfStock?[4,this.beforeCartOperationCheck()]:[2,{success:!1,validationError:c.INSUFFICIENT_STOCK}]:[2,{success:!1,validationError:c.INVALID_PRODUCT_OPTION_VALUES}];case 1:return e.sent(),this.cart&&(t=this.findExistingItem(i,s))?(null===(I=s.productOptionSet)||void 0===I||I.initOptionValues(),[2,this.changeItemQuantity(t,t.quantity+1)]):(d=this.getOptionValues(s),l=(null===(m=this.cart)||void 0===m?void 0:m.id)||localStorage.getItem("cartId"),[4,r.addItemToCart({input:{cartId:l,item:{id:null,quantity:u,variant:{id:i.id,name:s.name}},options:d.length?d:null,priceListId:n.getPriceListId()||null,salesChannelId:n.getSalesChannelId(),storefrontThemeId:n.getStorefrontThemeId(),metadata:{_fbp:a("_fbp"),_fbc:a("_fbc")}}})]);case 2:return(h=e.sent()).isSuccess&&h.data?[4,this.setCart(h.data)]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.cart&&(f="".concat(this.cart.id,"-").concat(this.cart.updatedAt),(v=this.cart.items.find((function(t){return t.variant.id===i.id})))&&o.addToCart(v,u,f,this.cart)),null===(C=s.productOptionSet)||void 0===C||C.initOptionValues(),[2,{success:h.isSuccess,response:h}];case 5:return p=e.sent(),console.log(p),[2,{success:!1}];case 6:return[2]}}))}))},this.changeItemQuantity=function(i,s){return t(d,void 0,void 0,(function(){var t,c,u,d,l;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,5,,6]),[4,this.beforeCartOperationCheck()];case 1:return e.sent(),[4,r.addItemToCart({input:{cartId:(null===(l=this.cart)||void 0===l?void 0:l.id)||null,item:{id:i.id,quantity:s,variant:{id:i.variant.id,name:i.variant.name}},options:this.createCartLineOptions(i),priceListId:n.getPriceListId()||null,salesChannelId:n.getSalesChannelId(),storefrontThemeId:n.getStorefrontThemeId(),metadata:{_fbp:a("_fbp"),_fbc:a("_fbc")}}})];case 2:return(t=e.sent()).isSuccess&&t.data?[4,this.setCart(t.data)]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.removeCardIfEmpty(),this.cart&&(c="".concat(this.cart.id,"-").concat(this.cart.updatedAt),(u=i.quantity)>s?o.removeFromCart(i,u-s,this.cart):o.addToCart(i,s-u,c,this.cart)),[2,{success:t.isSuccess,response:t}];case 5:return d=e.sent(),console.log(d),[2,{success:!1}];case 6:return[2]}}))}))},this.removeItem=function(i){return t(d,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,this.changeItemQuantity(i,0)];case 1:return[2,t.sent()]}}))}))},this.removeCart=function(){localStorage.removeItem("cartId"),d.cart=void 0},this.waitUntilInitialized=function(){return new Promise((function(t){var e=setInterval((function(){d.isCartLoadFinished&&(clearInterval(e),t(null))}),100)}))},this.findExistingItem=function(t,e){var i,r,n,o,s;if(!e.productOptionSetId)return null===(i=d.cart)||void 0===i?void 0:i.orderLineItems.find((function(e){return e.variant.id===t.id}));for(var a=d.getOptionValues(e),c=(null===(r=d.cart)||void 0===r?void 0:r.orderLineItems.filter((function(e){var i;return e.variant.id===t.id&&(null===(i=e.options)||void 0===i?void 0:i.length)===a.length})))||[],u=0,l=c;u<l.length;u++){var h=l[u];if(h.options){for(var f=!0,v=function(t){var i=t.values.map((function(t){return t.value})),r=null===(s=null===(o=null===(n=e.productOptionSet)||void 0===n?void 0:n.options)||void 0===o?void 0:o.find((function(e){return e.id===t.productOptionId})))||void 0===s?void 0:s.values;if(!(f=f&&i.length===(null==r?void 0:r.length)&&i.every((function(t){return null==r?void 0:r.includes(t)}))))return"break"},p=0,I=h.options;p<I.length;p++){if("break"===v(I[p]))break}if(f)return h}}},this.saveCouponCode=function(i){return t(d,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.cart?[4,r.saveCartCouponCode({cartId:this.cart.id,couponCode:i})]:[2,{success:!1,validationError:c.EMPTY_CART}];case 1:return(t=e.sent()).isSuccess&&t.data&&(this.cart=t.data),[2,{success:t.isSuccess,response:t}]}}))}))},this.removeCouponCode=function(){return t(d,void 0,void 0,(function(){return e(this,(function(t){return[2,this.saveCouponCode(null)]}))}))},this.saveCart=function(i){return t(d,void 0,void 0,(function(){var t,n;return e(this,(function(e){switch(e.label){case 0:return t=new s(i),[4,r.saveCart({input:t})];case 1:return[2,{success:(n=e.sent()).isSuccess,response:n}]}}))}))},this.removeCardIfEmpty=function(){var t;0===(null===(t=d.cart)||void 0===t?void 0:t.itemCount)&&d.removeCart()},this.getCart=function(){return t(d,void 0,void 0,(function(){var t,i,n,o,s,a;return e(this,(function(e){switch(e.label){case 0:if(!("undefined"!=typeof localStorage))return[2];e.label=1;case 1:return e.trys.push([1,6,7,8]),this._isLoadingCart=!0,t=null===(s=this.baseStore.customerStore.customer)||void 0===s?void 0:s.id,(i=(null===(a=this.cart)||void 0===a?void 0:a.id)||localStorage.getItem("cartId"))||t?[4,r.getCartById({id:i})]:[2];case 2:return(n=e.sent()).isSuccess&&n.data?[4,this.setCart(n.data)]:[3,4];case 3:return e.sent(),[3,5];case 4:this.removeCart(),e.label=5;case 5:return[3,8];case 6:return o=e.sent(),console.log(o),[3,8];case 7:return this._isLoadingCart=!1,this._isCartLoadFinished=!0,[7];case 8:return[2]}}))}))},this.setCart=function(i){return t(d,void 0,void 0,(function(){return e(this,(function(t){return localStorage.setItem("cartId",i.id),this.cart=i,[2]}))}))},this.beforeCartOperationCheck=function(){return t(d,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return t=localStorage.getItem("cartId"),!this.cart||t?[3,1]:(this.removeCart(),[3,3]);case 1:return this.cart||!t?[3,3]:[4,this.getCart()];case 2:e.sent(),e.label=3;case 3:return[2]}}))}))},this.createCartLineOptions=function(t){if(t&&t.options){for(var e=[],i=0,r=t.options;i<r.length;i++){var n=r[i],o={productOptionId:n.productOptionId,productOptionsSetId:n.productOptionsSetId,values:n.values.map((function(t){return t.value}))};e.push(o)}return e}return null},this.getOptionValues=function(t){var e,i=[];return null===(e=t.productOptionSet)||void 0===e||e.options.forEach((function(t){t.values.length&&i.push({productOptionId:t.id,productOptionsSetId:t.productOptionSetId,values:t.values})})),i},this.baseStore=u,i(this)}return Object.defineProperty(u.prototype,"isLoadingCart",{get:function(){return this._isLoadingCart},enumerable:!1,configurable:!0}),Object.defineProperty(u.prototype,"isCartLoadFinished",{get:function(){return this._isCartLoadFinished},enumerable:!1,configurable:!0}),Object.defineProperty(u.prototype,"checkoutId",{get:function(){var t;return null===(t=this.cart)||void 0===t?void 0:t.id},enumerable:!1,configurable:!0}),Object.defineProperty(u.prototype,"checkoutUrl",{get:function(){if(this.checkoutId)return"/checkout?id=".concat(this.checkoutId,"&step=info")},enumerable:!1,configurable:!0}),u}();!function(t){t.INSUFFICIENT_STOCK="INSUFFICIENT_STOCK",t.INVALID_PRODUCT_OPTION_VALUES="INVALID_PRODUCT_OPTION_VALUES",t.EMPTY_CART="EMPTY_CART"}(c||(c={}));export{u as CART_LS_KEY,c as IkasCartOperationValidationError,d as IkasCartStore};
|
|
1
|
+
import{__awaiter as t,__generator as e}from'./../../ext/tslib/tslib.es6.js';import{makeAutoObservable as i}from"mobx";import r from"./api.js";import"../../models/data/blog/category/index.js";import"../../models/data/blog/content/index.js";import"../../models/data/blog/meta-data/index.js";import"../../models/data/blog/tag/index.js";import"../../models/data/blog/index.js";import"../../models/data/brand/index.js";import{IkasCustomerEmailSubscriptionStatus as o}from"@ikas/storefront-models";import"../../models/data/campaign-offer/index.js";import"../../models/data/cart/campaign-offer/index.js";import"../../models/data/cart/index.js";import"../../models/data/category/path-item/index.js";import"../../models/data/category/index.js";import"../../models/data/checkout/index.js";import"../../models/data/checkout-settings/index.js";import"../../models/data/city/index.js";import"../../models/data/country/index.js";import"../../models/data/customer/address/region/index.js";import"../../models/data/customer/address/index.js";import"../../models/data/customer/address/ikas-localized-customer-address.js";import"../../models/data/customer/attribute/index.js";import"../../models/data/customer/review/summary/index.js";import"../../models/data/customer/review/index.js";import"../../models/data/customer/index.js";import"../../models/data/district/index.js";import"../../models/data/favorite-product/index.js";import"../../models/data/filter-category/index.js";import"../../models/data/html-meta-data/index.js";import"../../models/data/image/index.js";import"../../models/data/order/address/region/index.js";import"../../models/data/order/address/index.js";import"../../models/data/order/line-item/option/value/index.js";import"../../models/data/order/line-item/variant/value/index.js";import"../../models/data/order/line-item/variant/index.js";import"../../models/data/order/line-item/index.js";import"../../models/data/order/package/index.js";import"../../models/data/order/transaction/index.js";import"../../models/data/order/index.js";import"../../models/data/payment-gateway/index.js";import"../../models/data/product/attribute-value/index.js";import"../../models/data/product/filter/index.js";import"../../models/data/product/option-set/option/index.js";import"../../models/data/product/option-set/index.js";import"../../models/data/product/stock-location/index.js";import"../../models/data/product/variant/price/index.js";import"../../models/data/product/variant/index.js";import"../../models/data/variant-type/index.js";import"../../models/data/product/index.js";import"../../models/data/raffle/index.js";import"../../models/data/shipping-zone/state/city/district/region/index.js";import"../../models/data/state/index.js";import"../../models/data/theme-json/index.js";import"../../models/data/theme-json/component/index.js";import"../../models/data/theme-json/custom-data/index.js";import"../../models/data/variant-type/variant-value/index.js";import"@ikas/localized-address";import{IkasStorefrontConfig as a}from"@ikas/storefront-config";import{Analytics as s}from"../../analytics/analytics.js";import"../../analytics/head/index.js";import{SaveCartInput as n}from"@ikas/storefront-api";import{getCookieValue as d}from"../../utils/helper.js";var c,u="cartId",l=function(){function u(u){var l=this;this.cart=null,this._isLoadingCart=!1,this._isCartLoadFinished=!1,this.addItem=function(i,o,n){return void 0===n&&(n=1),t(l,void 0,void 0,(function(){var t,u,l,m,p,h,f,v,I,g;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,5,,6]),o.hasValidProductOptionValues?i.hasStock||i.sellIfOutOfStock?[4,this.beforeCartOperationCheck()]:[2,{success:!1,validationError:c.INSUFFICIENT_STOCK}]:[2,{success:!1,validationError:c.INVALID_PRODUCT_OPTION_VALUES}];case 1:return e.sent(),this.cart&&(t=this.findExistingItem(i,o))?(null===(v=o.productOptionSet)||void 0===v||v.initOptionValues(),[2,this.changeItemQuantity(t,t.quantity+1)]):(u=this.getOptionValues(o),l=(null===(I=this.cart)||void 0===I?void 0:I.id)||localStorage.getItem("cartId"),[4,r.addItemToCart({input:{cartId:l,item:{id:null,quantity:n,variant:{id:i.id,name:o.name}},options:u.length?u:null,priceListId:a.getPriceListId()||null,salesChannelId:a.getSalesChannelId(),storefrontThemeId:a.getStorefrontThemeId(),metadata:{_fbp:d("_fbp"),_fbc:d("_fbc")}}})]);case 2:return(m=e.sent()).isSuccess&&m.data?[4,this.setCart(m.data)]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.cart&&(p="".concat(this.cart.id,"-").concat(this.cart.updatedAt),(h=this.cart.items.find((function(t){return t.variant.id===i.id})))&&s.addToCart(h,n,p,this.cart)),null===(g=o.productOptionSet)||void 0===g||g.initOptionValues(),[2,{success:m.isSuccess,response:m}];case 5:return f=e.sent(),console.log(f),[2,{success:!1}];case 6:return[2]}}))}))},this.changeItemQuantity=function(i,o){return t(l,void 0,void 0,(function(){var t,n,c,u,l;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,5,,6]),[4,this.beforeCartOperationCheck()];case 1:return e.sent(),[4,r.addItemToCart({input:{cartId:(null===(l=this.cart)||void 0===l?void 0:l.id)||null,item:{id:i.id,quantity:o,variant:{id:i.variant.id,name:i.variant.name}},options:this.createCartLineOptions(i),priceListId:a.getPriceListId()||null,salesChannelId:a.getSalesChannelId(),storefrontThemeId:a.getStorefrontThemeId(),metadata:{_fbp:d("_fbp"),_fbc:d("_fbc")}}})];case 2:return(t=e.sent()).isSuccess&&t.data?[4,this.setCart(t.data)]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.removeCardIfEmpty(),this.cart&&(n="".concat(this.cart.id,"-").concat(this.cart.updatedAt),(c=i.quantity)>o?s.removeFromCart(i,c-o,this.cart):s.addToCart(i,o-c,n,this.cart)),[2,{success:t.isSuccess,response:t}];case 5:return u=e.sent(),console.log(u),[2,{success:!1}];case 6:return[2]}}))}))},this.removeItem=function(i){return t(l,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,this.changeItemQuantity(i,0)];case 1:return[2,t.sent()]}}))}))},this.removeCart=function(){localStorage.removeItem("cartId"),l.cart=void 0},this.waitUntilInitialized=function(){return new Promise((function(t){var e=setInterval((function(){l.isCartLoadFinished&&(clearInterval(e),t(null))}),100)}))},this.findExistingItem=function(t,e){var i,r,o,a,s;if(!e.productOptionSetId)return null===(i=l.cart)||void 0===i?void 0:i.orderLineItems.find((function(e){return e.variant.id===t.id}));for(var n=l.getOptionValues(e),d=(null===(r=l.cart)||void 0===r?void 0:r.orderLineItems.filter((function(e){var i;return e.variant.id===t.id&&(null===(i=e.options)||void 0===i?void 0:i.length)===n.length})))||[],c=0,u=d;c<u.length;c++){var m=u[c];if(m.options){for(var p=!0,h=function(t){var i=t.values.map((function(t){return t.value})),r=null===(s=null===(a=null===(o=e.productOptionSet)||void 0===o?void 0:o.options)||void 0===a?void 0:a.find((function(e){return e.id===t.productOptionId})))||void 0===s?void 0:s.values;if(!(p=p&&i.length===(null==r?void 0:r.length)&&i.every((function(t){return null==r?void 0:r.includes(t)}))))return"break"},f=0,v=m.options;f<v.length;f++){if("break"===h(v[f]))break}if(p)return m}}},this.saveCouponCode=function(i){return t(l,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.cart?[4,r.saveCartCouponCode({cartId:this.cart.id,couponCode:i})]:[2,{success:!1,validationError:c.EMPTY_CART}];case 1:return(t=e.sent()).isSuccess&&t.data&&(this.cart=t.data),[2,{success:t.isSuccess,response:t}]}}))}))},this.removeCouponCode=function(){return t(l,void 0,void 0,(function(){return e(this,(function(t){return[2,this.saveCouponCode(null)]}))}))},this.saveCart=function(i){return t(l,void 0,void 0,(function(){var t,a;return e(this,(function(e){switch(e.label){case 0:return(t=new n(i)).customer&&this.baseStore.customerStore.customer&&(t.customer.notificationsAccepted=this.baseStore.customerStore.customer.subscriptionStatus===o.SUBSCRIBED),[4,r.saveCart({input:t})];case 1:return[2,{success:(a=e.sent()).isSuccess,response:a}]}}))}))},this.removeCardIfEmpty=function(){var t;0===(null===(t=l.cart)||void 0===t?void 0:t.itemCount)&&l.removeCart()},this.getCart=function(){return t(l,void 0,void 0,(function(){var t,i,o,a,s,n;return e(this,(function(e){switch(e.label){case 0:if(!("undefined"!=typeof localStorage))return[2];e.label=1;case 1:return e.trys.push([1,6,7,8]),this._isLoadingCart=!0,t=null===(s=this.baseStore.customerStore.customer)||void 0===s?void 0:s.id,(i=(null===(n=this.cart)||void 0===n?void 0:n.id)||localStorage.getItem("cartId"))||t?[4,r.getCartById({id:i})]:[2];case 2:return(o=e.sent()).isSuccess&&o.data?[4,this.setCart(o.data)]:[3,4];case 3:return e.sent(),[3,5];case 4:this.removeCart(),e.label=5;case 5:return[3,8];case 6:return a=e.sent(),console.log(a),[3,8];case 7:return this._isLoadingCart=!1,this._isCartLoadFinished=!0,[7];case 8:return[2]}}))}))},this.setCart=function(i){return t(l,void 0,void 0,(function(){return e(this,(function(t){return localStorage.setItem("cartId",i.id),this.cart=i,[2]}))}))},this.beforeCartOperationCheck=function(){return t(l,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return t=localStorage.getItem("cartId"),!this.cart||t?[3,1]:(this.removeCart(),[3,3]);case 1:return this.cart||!t?[3,3]:[4,this.getCart()];case 2:e.sent(),e.label=3;case 3:return[2]}}))}))},this.createCartLineOptions=function(t){if(t&&t.options){for(var e=[],i=0,r=t.options;i<r.length;i++){var o=r[i],a={productOptionId:o.productOptionId,productOptionsSetId:o.productOptionsSetId,values:o.values.map((function(t){return t.value}))};e.push(a)}return e}return null},this.getOptionValues=function(t){var e,i=[];return null===(e=t.productOptionSet)||void 0===e||e.options.forEach((function(t){t.values.length&&i.push({productOptionId:t.id,productOptionsSetId:t.productOptionSetId,values:t.values})})),i},this.baseStore=u,i(this)}return Object.defineProperty(u.prototype,"isLoadingCart",{get:function(){return this._isLoadingCart},enumerable:!1,configurable:!0}),Object.defineProperty(u.prototype,"isCartLoadFinished",{get:function(){return this._isCartLoadFinished},enumerable:!1,configurable:!0}),Object.defineProperty(u.prototype,"checkoutId",{get:function(){var t;return null===(t=this.cart)||void 0===t?void 0:t.id},enumerable:!1,configurable:!0}),Object.defineProperty(u.prototype,"checkoutUrl",{get:function(){if(this.checkoutId)return"/checkout?id=".concat(this.checkoutId,"&step=info")},enumerable:!1,configurable:!0}),u}();!function(t){t.INSUFFICIENT_STOCK="INSUFFICIENT_STOCK",t.INVALID_PRODUCT_OPTION_VALUES="INVALID_PRODUCT_OPTION_VALUES",t.EMPTY_CART="EMPTY_CART"}(c||(c={}));export{u as CART_LS_KEY,c as IkasCartOperationValidationError,l as IkasCartStore};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ikas/storefront",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.10.0-beta.2",
|
|
4
4
|
"description": "Storefront functionality for ikas storefront themes.",
|
|
5
5
|
"author": "ikas",
|
|
6
6
|
"license": "ISC",
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
"build": "rm -rf build && rollup -c"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@ikas/storefront-api": "^4.
|
|
21
|
-
"@ikas/storefront-config": "^4.
|
|
22
|
-
"@ikas/storefront-model-functions": "^4.
|
|
23
|
-
"@ikas/storefront-models": "^4.
|
|
24
|
-
"@ikas/storefront-providers": "^4.
|
|
20
|
+
"@ikas/storefront-api": "^4.10.0-beta.2",
|
|
21
|
+
"@ikas/storefront-config": "^4.10.0-beta.2",
|
|
22
|
+
"@ikas/storefront-model-functions": "^4.10.0-beta.2",
|
|
23
|
+
"@ikas/storefront-models": "^4.10.0-beta.2",
|
|
24
|
+
"@ikas/storefront-providers": "^4.10.0-beta.2",
|
|
25
25
|
"@ikas/localized-address": "^1.0.0-beta.3",
|
|
26
26
|
"@adyen/adyen-web": "^5.28.2",
|
|
27
27
|
"@rollup/plugin-commonjs": "^22.0.0",
|
|
@@ -55,11 +55,11 @@
|
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"@ikas/localized-address": "^1.0.0-beta.3",
|
|
58
|
-
"@ikas/storefront-api": "^4.
|
|
59
|
-
"@ikas/storefront-config": "^4.
|
|
60
|
-
"@ikas/storefront-model-functions": "^4.
|
|
61
|
-
"@ikas/storefront-models": "^4.
|
|
62
|
-
"@ikas/storefront-providers": "^4.
|
|
58
|
+
"@ikas/storefront-api": "^4.10.0-beta.2",
|
|
59
|
+
"@ikas/storefront-config": "^4.10.0-beta.2",
|
|
60
|
+
"@ikas/storefront-model-functions": "^4.10.0-beta.2",
|
|
61
|
+
"@ikas/storefront-models": "^4.10.0-beta.2",
|
|
62
|
+
"@ikas/storefront-providers": "^4.10.0-beta.2",
|
|
63
63
|
"mobx": "^6.1.3",
|
|
64
64
|
"mobx-react-lite": "^3.1.5",
|
|
65
65
|
"next": "12.2.0",
|