@ikas/storefront 3.0.0-alpha.22 → 3.0.0-alpha.23

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 e from'../ext/decode-uri-component/index.js';export{default}from"../node_modules/decode-uri-component/index.js";
1
+ import o from'../ext/split-on-first/index.js';export{default}from"../node_modules/split-on-first/index.js";
@@ -1 +1 @@
1
- import o from'../ext/split-on-first/index.js';export{default}from"../node_modules/split-on-first/index.js";
1
+ import e from'../ext/decode-uri-component/index.js';export{default}from"../node_modules/decode-uri-component/index.js";
@@ -1 +1 @@
1
- import{__awaiter as t,__generator as e,__assign as i}from'../../ext/tslib/tslib.es6.js';import{makeAutoObservable as s}from"mobx";import n from'../../ext/lodash/cloneDeep.js';import r from'../../ext/lodash/sortBy.js';import"../../models/data/blog/index.js";import"../../models/data/brand/index.js";import"../../models/data/cart/campaign-offer/index.js";import"../../models/data/cart/index.js";import"../../models/data/category/index.js";import"../../models/data/city/index.js";import"../../models/data/country/index.js";import{IkasCustomerAddress as o}from"../../models/data/customer/address/index.js";import"../../models/data/customer/attribute-value/index.js";import"../../models/data/customer/index.js";import"../../models/data/customer-attribute/customer-attribute-option/index.js";import"../../models/data/customer-attribute/customer-attribute-sales-channel/index.js";import"../../models/data/customer-attribute/index.js";import"../../models/data/customer-review/index.js";import"../../models/data/customer-review-summary/index.js";import"../../models/data/district/index.js";import"../../models/data/favorite-product/index.js";import"../../models/data/html-meta-data/index.js";import"../../models/data/image/index.js";import"../../models/data/merchant-settings/index.js";import{IkasOrderAddress as a}from"../../models/data/order/address/index.js";import"../../models/data/order/adjustment/index.js";import{IkasOrderCustomer as d}from"../../models/data/order/customer/index.js";import"../../models/data/order/gift-line/index.js";import"../../models/data/order/invoice/index.js";import"../../models/data/order/line-item/discount/index.js";import"../../models/data/order/line-item/option/value/index.js";import"../../models/data/order/line-item/option/index.js";import"../../models/data/order/line-item/variant/index.js";import"../../models/data/order/line-item/index.js";import"../../models/data/order/package/tracking-info/index.js";import"../../models/data/order/package/index.js";import"../../models/data/order/payment-method/index.js";import"../../models/data/order/refund/line-item/index.js";import"../../models/data/order/shipping-line/index.js";import"../../models/data/order/tax-line/index.js";import"../../models/data/order/transaction/index.js";import"../../models/data/order/index.js";import"../../models/data/product/attribute-value/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/product-attribute/index.js";import"../../models/data/product-filter/index.js";import"../../models/data/product-campaign/campaign/index.js";import"../../models/data/product-campaign/filter/index.js";import"../../models/data/product-option-set/index.js";import"../../models/data/raffle/index.js";import"../../models/data/state/index.js";import"../../models/data/variant-type/variant-value/index.js";import"../../models/theme/theme.js";import"../../models/theme/page/index.js";import"../../models/theme/component/prop/index.js";import"../../models/theme/page/component/prop-value/link.js";import"../../models/ui/brand-list/index.js";import"../../models/ui/blog-list/index.js";import"../../models/ui/blog-category-list/index.js";import"../../models/ui/category-list/index.js";import"../../models/ui/product-detail/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/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"../../models/theme/settings/index.js";import"../../models/theme/custom-data/index.js";import"../../models/data/payment-gateway/index.js";import c from"./components/credit-card-form/model.js";import{IkasStorefrontConfig as l}from"../../storefront/index.js";import{IkasCheckoutSettings as u}from"../../models/data/checkout-settings/index.js";import{Analytics as h}from"../../analytics/analytics.js";import"../../analytics/head/index.js";import p from"../../models/data/checkout/index.js";import m from"../../store/customer/api.js";import f from"../../store/merchant/index.js";import v from"../../store/checkout/index.js";import{CheckStocksLineInput as g}from"../../__api/models/CheckStocksLineInput.js";import y from"../../store/cart/api.js";import{SaveCartInput as S}from"../../__api/models/SaveCartInput.js";import{PaymentMethodEnum as k,PaymentGatewayTypeEnum as b,TransactionStatusEnum as I}from"../../__api/types/index.js";import C from'../../ext/uuid/dist/esm-node/v4.js';var A,P,j=/^\d+$/,w="undefined"==typeof localStorage,x=function(){function j(j,x,E,O,T,D,G,_){var M=this;this.checkout=new p,this.checkoutSettings=new u,this.storefront=null,this.store=l.store,this.isCheckoutLoaded=!1,this.isErrorsVisible=!1,this.isStepLoading=!1,this.isTermsAndConditionsChecked=!1,this.isChangingShippingMethod=!1,this.isContactModalVisible=!1,this.step=A.INFO,this.cardData=null,this.paymentGateways=[],this.installmentInfo=null,this.useDifferentAddress=!1,this.shouldSaveAddress=!1,this.addressTitle="",this.shippingCountryIds=null,this.selectedShippingAddressId="-1",this.selectedBillingAddressId="-1",this.stockLocations=[],this.deliveryMethod="address",this.policyModalTitle="",this.policyModalText="",this.error=null,this.init=function(){return t(M,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,this.store.customerStore.waitUntilInitialized()];case 1:return t.sent(),this.createCustomer(),this.createShippingAddress(),this.createBillingAddress(),[4,this.getMerchantSettings()];case 2:return t.sent(),[4,this.initStep()];case 3:return t.sent(),[2]}}))}))},this.initStep=function(){return t(M,void 0,void 0,(function(){var t,i,s,n,r,o,a,d,c;return e(this,(function(e){switch(e.label){case 0:if(l.isEditor)return this.step=A.INFO,this.isCheckoutLoaded=!0,[2];if(t=new URLSearchParams(window.location.search),i=t.get("step"),s=t.get("failed"),n=t.get("error"),i){if(this.step=i,this.step===A.SHIPPING&&!this.canProceedToShipping)return[2,this.changeStep(A.INFO)];if(this.step!==A.PAYMENT||this.canProceedToPayment){if(![A.INFO,A.SUCCESS,A.SHIPPING,A.PAYMENT].includes(this.step))return[2,this.changeStep(A.INFO)]}else{if(!this.isInStoreDelivery)return[2,this.changeStep(A.INFO)];this.deliveryMethod="in-store"}}return s&&(this.error={type:P.PAYMENT_ERROR,data:n||null}),this.step!==A.INFO?[3,3]:[4,this.getShippingCountries()];case 1:return e.sent(),this.checkShippingCountries(),[4,this.getStockLocations()];case 2:e.sent(),this.isInStoreDelivery&&(this.deliveryMethod="in-store"),e.label=3;case 3:return this.step!==A.SHIPPING||1!==(null===(a=this.checkout.availableShippingMethods)||void 0===a?void 0:a.length)||this.checkoutSettings.isGiftPackageEnabled||(this.step=A.PAYMENT,this.router.replace("/checkout?id=".concat(this.checkout.id,"&step=").concat(this.step),void 0,{shallow:!0})),this.step!==A.SHIPPING||(null===(d=this.checkout.availableShippingMethods)||void 0===d?void 0:d.length)?this.step!==A.PAYMENT&&this.step!==A.SUCCESS?[3,7]:[4,this.listPaymentGateways()]:(this.error={type:P.NO_SHIPPING_ERROR},this.isCheckoutLoaded=!0,[2]);case 4:return e.sent(),this.isInStoreDelivery?(this.deliveryMethod="in-store",[4,this.getStockLocations()]):[3,6];case 5:e.sent(),e.label=6;case 6:if(!this.paymentGateways.length)return this.error={type:P.NO_SHIPPING_ERROR},this.isCheckoutLoaded=!0,[2];e.label=7;case 7:return this.step===A.SUCCESS?[3,11]:this.checkout.isComplete?[2,this.changeStep(A.SUCCESS)]:[3,8];case 8:return[4,this.initialStockCheck()];case 9:e.sent(),e.label=10;case 10:return[3,13];case 11:return[4,m.listOrderTransactions({orderId:{eq:this.checkout.id}})];case 12:r=e.sent(),this.successTransaction=r.isSuccess&&(null===(c=r.data)||void 0===c?void 0:c.length)?r.data[0]:void 0,this.successTransaction&&(o=this.successTransaction.paymentGatewayId,this.checkout.selectedPaymentGateway=this.paymentGateways.find((function(t){return t.id===o}))),e.label=13;case 13:return this.isCheckoutLoaded=!0,h.checkoutStep(this.checkout,this.step),[2]}}))}))},this.getMerchantSettings=function(){return t(M,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.merchantSettings?[3,2]:[4,f.listMerchantSettings({})];case 1:t=e.sent(),this.merchantSettings=t.data||void 0,e.label=2;case 2:return[2]}}))}))},this.saveCart=function(){return t(M,void 0,void 0,(function(){var t,i,s,n;return e(this,(function(e){switch(e.label){case 0:return(t=new S(this.checkout)).cartId=this.checkout.id,"in-store"!==this.deliveryMethod?[3,2]:[4,this.inStockDeliveryInputData(t)];case 1:t=e.sent(),e.label=2;case 2:return[4,y.saveCart({input:t})];case 3:if((null==(i=e.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:P.CUSTOMER_LOGIN_REQUIRED_ERROR}:{type:P.API_ERROR};return[2,i.data]}}))}))},this.inStockDeliveryInputData=function(i){return t(M,void 0,void 0,(function(){var t,s,n=this;return e(this,(function(e){return t=i,(s=this.stockLocations.find((function(t){return t.id===n.checkout.stockLocationId})))&&t.shippingAddress&&s.address&&(t.shippingAddress.country=s.address.country,t.shippingAddress.city=s.address.city,t.shippingAddress.state=s.address.state,t.shippingAddress.district=s.address.district,t.shippingAddress.postalCode=s.address.postalCode,t.shippingAddress.addressLine1=s.address.address||""),t.billingAddress=null,[2,t]}))}))},this.checkStocks=function(){return t(M,void 0,void 0,(function(){var t,i,s,n,r,o,a,d,c,u,h,p;return e(this,(function(e){switch(e.label){case 0:return t=this.checkout.items.map((function(t){return{quantity:t.quantity,variantId:t.variant.id,productId:t.variant.productId}})),[4,v.checkStocks({lines:t.map((function(t){return new g(t)})),stockLocationIdList:l.stockLocationIds||[]})];case 1:if(!(i=e.sent()).isSuccess)throw{type:P.API_ERROR};if(null==(s=null===(h=null===(u=i.data)||void 0===u?void 0:u.lines)||void 0===h?void 0:h.filter((function(t){return!t.isAvailable})))?void 0:s.length){for(n=[],r=function(t){var e=null===(p=o.store.cartStore.cart)||void 0===p?void 0:p.items.find((function(e){return e.variant.id===t.variantId}));e&&n.push(e)},o=this,a=0,d=s;a<d.length;a++)c=d[a],r(c);throw{type:P.STOCK_ERROR,data:n}}return[2]}}))}))},this.removeUnavailableItems=function(i){return t(M,void 0,void 0,(function(){var t,s,n;return e(this,(function(e){switch(e.label){case 0:t=0,s=i,e.label=1;case 1:return t<s.length?(n=s[t],[4,this.store.cartStore.removeItem(n)]):[3,4];case 2:e.sent(),e.label=3;case 3:return t++,[3,1];case 4:return[2]}}))}))},this.getShippingCountries=function(){return t(M,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,v.getAvailableShippingCountries({salesChannelId:l.salesChannelId})];case 1:return t=e.sent(),this.shippingCountryIds=t.data,[2]}}))}))},this.getStockLocations=function(){return t(M,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return l.pickUpStockLocationIds?[4,v.listStockLocation({id:{in:l.pickUpStockLocationIds}})]:[3,2];case 1:if(!(t=e.sent()).isSuccess||!(null===(i=t.data)||void 0===i?void 0:i.length))return this.error={type:P.API_ERROR},[2];this.stockLocations=t.data,e.label=2;case 2:return[2]}}))}))},this.checkShippingCountries=function(){var t;(null===(t=M.shippingCountryIds)||void 0===t?void 0:t.length)||(M.error={type:P.NO_SHIPPING_ERROR})},this.onDeliveryMethodChange=function(t){"address"===t&&(M.checkout.stockLocationId=null),M.deliveryMethod=t,M.isErrorsVisible=!1},this.initialStockCheck=function(){return t(M,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this.checkStocks()];case 1:return e.sent(),[3,3];case 2:return(t=e.sent()).type?this.error=t:(console.log(t),this.error={type:P.UNKNOWN}),[3,3];case 3:return[2]}}))}))},this.listPaymentGateways=function(){return t(M,void 0,void 0,(function(){var t,i,s,n,o,a,d,c,u=this;return e(this,(function(e){switch(e.label){case 0:return t="local"===process.env.NEXT_PUBLIC_ENV,i=l.paymentGateways.map((function(t){return t.id})),[4,v.listPaymentGateway({id:t?void 0:{in:i}})];case 1:return(s=e.sent()).isSuccess&&(null===(d=s.data)||void 0===d?void 0:d.length)?(n=s.data,this.step===A.PAYMENT&&(n=n.filter((function(t){return!t.supportedCurrencies.length||t.supportedCurrencies.includes(u.checkout.currencyCode)})),(o=null===(c=this.checkout.shippingAddress)||void 0===c?void 0:c.country)&&o.iso2&&(n=n.filter((function(t){return!t.availableCountries.length||t.availableCountries.includes(o.iso2||"")})))),a=[],r(l.paymentGateways,"order").forEach((function(t){var e=null==n?void 0:n.find((function(e){return e.id===t.id}));e&&a.push(e)})),this.paymentGateways=t?n:a,this.checkout.selectedPaymentGateway||this.setPaymentGateway(0),[2]):(this.error={type:P.API_ERROR},[2])}}))}))},this.retrieveInstallmentInfo=function(i){return t(M,void 0,void 0,(function(){var t,s,n;return e(this,(function(e){switch(e.label){case 0:return[4,v.retrieveInstallmentInfo(i)];case 1:return t=e.sent(),s=t.data,null===(n=null==s?void 0:s.installmentPrices)||void 0===n||n.sort((function(t,e){return(t.installmentCount||-1)>(e.installmentCount||-1)?1:-1})),this.installmentInfo=s,[2]}}))}))},this.createCustomer=function(){var t;M.store.customerStore.customer?(null===(t=M.store.customerStore.customer.addresses)||void 0===t||t.forEach((function(t){return t.checkoutSettings=M.checkoutSettings})),M.checkout.customer=new d(M.store.customerStore.customer)):M.checkout.customer||(M.checkout.customer=new d({}))},this.createShippingAddress=function(){var t;if(M.checkout.shippingAddress)M.selectedShippingAddressId=M.checkout.shippingAddress.id||"-1",M.checkout.shippingAddress.checkoutSettings=M.checkoutSettings;else{var e=null===(t=M.store.customerStore.customer)||void 0===t?void 0:t.addresses;M.onSelectedShippingAddressIdChange((null==e?void 0:e.length)?e[0].id:"-1")}},this.createBillingAddress=function(){"undefined"!=typeof localStorage&&(M.useDifferentAddress=!!localStorage.getItem("sAddr"),M.useDifferentAddress?(M.checkout.billingAddress&&(M.selectedBillingAddressId=M.checkout.billingAddress.id||"-1"),M.checkout.billingAddress=M.checkout.billingAddress||new a):M.checkout.billingAddress=new a(n(M.checkout.shippingAddress)||{}),M.checkout.billingAddress.checkoutSettings=M.checkoutSettings)},this.onShippingMethodChange=function(i){return t(M,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.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(t=e.sent())&&(this.checkout=new p(t)),this.isChangingShippingMethod=!1,[2]}}))}))},this.onStockLocationChange=function(i){return t(M,void 0,void 0,(function(){return e(this,(function(t){return this.checkout.stockLocationId=i.id,[2]}))}))},this.onCouponCodeApply=function(){return t(M,void 0,void 0,(function(){var t,s,n,r,o,a;return e(this,(function(e){switch(e.label){case 0:if(!this.checkout.couponCode)return[2];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,y.saveCartCouponCode({cartId:this.checkout.id,couponCode:this.checkout.couponCode})];case 2:return(t=e.sent()).isSuccess&&t.data&&(s=t.data,n=null===(a=null===(o=this.cardData)||void 0===o?void 0:o.cardNumber)||void 0===a?void 0:a.split(" ").join(""),this.step===A.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}}),s&&(r=this.checkout,this.checkout=new p(i(i({},s),{shippingAddress:r.shippingAddress,billingAddress:r.billingAddress,customer:r.customer,selectedPaymentGateway:r.selectedPaymentGateway})))),[3,4];case 3:return e.sent(),[3,4];case 4:return[2]}}))}))},this.onCouponCodeDelete=function(){return t(M,void 0,void 0,(function(){var t,s;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this.saveCart()];case 1:return(t=e.sent())&&(s=this.checkout,this.checkout=new p(i(i({},t),{shippingAddress:s.shippingAddress,billingAddress:s.billingAddress,customer:s.customer,selectedPaymentGateway:s.selectedPaymentGateway}))),[3,3];case 2:return e.sent(),[3,3];case 3:return[2]}}))}))},this.onSelectedShippingAddressIdChange=function(t){var e,i;if(M.selectedShippingAddressId=t,"-1"===t)M.checkout.shippingAddress=new a;else{var s=null===(i=null===(e=M.store.customerStore.customer)||void 0===e?void 0:e.addresses)||void 0===i?void 0:i.find((function(e){return e.id===t}));s&&(M.checkout.shippingAddress=new a(s))}M.checkout.shippingAddress&&(M.checkout.shippingAddress.checkoutSettings=M.checkoutSettings)},this.onSelectedBillingAddressIdChange=function(t){var e,i;if(M.selectedBillingAddressId=t,"-1"===t)M.checkout.billingAddress=new a;else{var s=null===(i=null===(e=M.store.customerStore.customer)||void 0===e?void 0:e.addresses)||void 0===i?void 0:i.find((function(e){return e.id===t}));s&&(M.checkout.billingAddress=new a(s))}M.checkout.billingAddress&&(M.checkout.billingAddress.checkoutSettings=M.checkoutSettings)},this.onTermsAndConditionsCheckedChange=function(t){M.isTermsAndConditionsChecked=t},this.onCardNumberChange=function(t){if(M.cardData&&(!(t.length>M.cardData.cardNumber.length)||R(t))){var e=(M.cardData.cardNumber||"").split(" ").join(""),i=t.split(" ").join("");i.length>16||(e.length<6&&i.length>=6&&!M.installmentInfo?M.retrieveInstallmentInfo({input:{binNumber:i.slice(0,6),paymentGatewayId:M.checkout.selectedPaymentGateway.id,price:M.checkout.totalFinalPrice}}):i.length<6&&e.length>i.length&&(M.cardData.installmentCount=1,M.installmentInfo=void 0),M.cardData.cardNumber=N(i,4).join(" "))}},this.onCardHolderNameChange=function(t){M.cardData&&(M.cardData.cardHolderName=t)},this.onExpirationDateChange=function(t){var e;if(M.cardData&&(!(t.length>M.cardData.expirationDate.length)||R(t))){if(0===(null===(e=M.cardData.expirationDate)||void 0===e?void 0:e.length)){var i=t.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(M.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(M.cardData.expirationDate="".concat(o<10?"0"+o:o," / ").concat(r<10?"0"+r:r))}}}var a=t.split(" / ").join("");a.length>4||(M.cardData.expirationDate=N(a,2).join(" / "))}},this.onCvcChange=function(t){M.cardData&&(t.length>M.cardData.cvv.length&&!R(t)||t.length>4||(M.cardData.cvv=t))},this.saveAddress=function(s){return t(M,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return this.shouldSaveAddress?(t=new o(i(i({},"shipping"===s?this.checkout.shippingAddress:this.checkout.billingAddress),{title:this.addressTitle||this.t("checkout-page:newAddress"),id:C()})),(r=n(this.store.customerStore.customer)).addresses||(r.addresses=[]),r.addresses.push(t),[4,this.store.customerStore.saveCustomer(r)]):[3,2];case 1:e.sent(),"shipping"===s?(this.checkout.shippingAddress.id=t.id,this.selectedShippingAddressId=t.id||"-1"):(this.checkout.billingAddress.id=t.id,this.selectedBillingAddressId=t.id||"-1"),e.label=2;case 2:return[2]}}))}))},this.onGoToCartClick=function(){M.router.push("/cart")},this.onBackToShoppingClick=function(){M.router.push("/")},this.onProceedToShippingClick=function(){return t(M,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.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,e.label=1;case 1:return e.trys.push([1,6,,7]),this.isStepLoading=!0,"address"!==this.deliveryMethod?[3,3]:[4,this.saveAddress("shipping")];case 2:e.sent(),e.label=3;case 3:return[4,this.checkStocks()];case 4:return e.sent(),[4,this.saveCart()];case 5:return e.sent(),"address"===this.deliveryMethod?this.changeStep(A.SHIPPING):this.changeStep(A.PAYMENT),[3,7];case 6:return(t=e.sent()).type?this.error=t:(console.log(t),this.error={type:P.UNKNOWN}),this.isStepLoading=!1,[3,7];case 7:return[2]}}))}))},this.onProceedToPaymentClick=function(){return t(M,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:if(!this.canProceedToPayment)return this.isErrorsVisible=!0,[2];this.isErrorsVisible=!1,e.label=1;case 1:return e.trys.push([1,4,,5]),this.isStepLoading=!0,[4,this.checkStocks()];case 2:return e.sent(),[4,this.saveCart()];case 3:return e.sent(),this.error=void 0,this.changeStep(A.PAYMENT),[3,5];case 4:return(t=e.sent()).type?this.error=t:(console.log(t),this.error={type:P.UNKNOWN}),this.isStepLoading=!1,[3,5];case 5:return[2]}}))}))},this.onCompletePaymentClick=function(){return t(M,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:if(!this.canPerformPayment)return this.isErrorsVisible=!0,[2];this.useDifferentAddress||(this.checkout.billingAddress=this.checkout.shippingAddress),e.label=1;case 1:return e.trys.push([1,7,,8]),this.isErrorsVisible=!1,this.isStepLoading=!0,[4,this.checkStocks()];case 2:return e.sent(),"address"!==this.deliveryMethod?[3,4]:[4,this.saveAddress("billing")];case 3:e.sent(),e.label=4;case 4:return[4,this.saveCart()];case 5:return e.sent(),[4,this.createSaleTransaction()];case 6:return e.sent(),[3,8];case 7:return(t=e.sent()).type?this.error=t:this.error={type:P.UNKNOWN},this.isStepLoading=!1,[3,8];case 8:return[2]}}))}))},this.createSaleTransaction=function(){return t(M,void 0,void 0,(function(){var t,i,s,n,r,o;return e(this,(function(e){switch(e.label){case 0:return this.checkout.selectedPaymentGateway?[4,v.createSaleTransactionWithCart({input:{cartId:this.checkout.id,paymentGatewayId:this.checkout.selectedPaymentGateway.id,paymentMethodDetail:this.checkout.selectedPaymentGateway.paymentMethodType===k.CREDIT_CARD&&this.checkout.selectedPaymentGateway.type===b.INTERNAL&&this.cardData?this.cardData.toInput():void 0}})]:[2];case 1:return t=e.sent(),i=null===(r=null==t?void 0:t.data)||void 0===r?void 0:r.transactionStatus,s=i&&[I.SUCCESS,I.AUTHORIZED].includes(i),n=i===I.PENDING,s?[4,this.onCheckoutTransactionSuccess()]:[3,3];case 2:return e.sent(),[3,4];case 3:if(!n||!(null===(o=null==t?void 0:t.data)||void 0===o?void 0:o.returnSlug))throw{type:P.UNKNOWN};window.location.href=process.env.NEXT_PUBLIC_BASE_URL+t.data.returnSlug,e.label=4;case 4:return[2]}}))}))},this.onCheckoutTransactionSuccess=function(){return t(M,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return localStorage.removeItem("sAddr"),(null===(t=this.checkout.customer)||void 0===t?void 0:t.notificationsAccepted)?[4,this.store.customerStore.createEmailSubscription((null===(i=this.checkout.customer)||void 0===i?void 0:i.email)||"")]:[3,2];case 1:e.sent(),e.label=2;case 2:return this.changeStep(A.SUCCESS),[2]}}))}))},this.onBackToInfoClick=function(){M.changeStep(A.INFO)},this.onBackToShippingClick=function(){M.changeStep(A.SHIPPING)},this.setCustomerConsentGranted=function(t){M.checkout.customer&&(M.checkout.customer.notificationsAccepted=t)},this.setUseDifferentAddress=function(t){M.useDifferentAddress=t,M.useDifferentAddress?(localStorage.setItem("sAddr","1"),M.checkout.billingAddress=M.checkout.billingAddress||new a):(localStorage.removeItem("sAddr"),M.checkout.billingAddress=M.checkout.shippingAddress)},this.setShouldSaveAddress=function(t){M.shouldSaveAddress=t},this.setAddressTitle=function(t){M.addressTitle=t},this.setPaymentGateway=function(t){if(M.paymentGateways.length){var e=M.paymentGateways[t];M.checkout.selectedPaymentGateway=e,M.step!==A.SUCCESS&&(e.paymentMethodType===k.CREDIT_CARD&&e.type===b.INTERNAL&&(M.cardData=new c),M.installmentInfo=void 0)}},this.setInstallmentCount=function(t){M.cardData&&(M.cardData.installmentCount=t)},this.changeStep=function(i){return t(M,void 0,void 0,(function(){return e(this,(function(t){return w||window.location.replace("".concat(window.location.pathname,"?id=").concat(this.checkout.id,"&step=").concat(i)),[2]}))}))},this.logout=function(){return t(M,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:this.checkout.customer=null,this.store.customerStore.logout(),t.label=1;case 1:return t.trys.push([1,3,,4]),[4,this.saveCart()];case 2:case 3:return t.sent(),[3,4];case 4:return this.createCustomer(),[2]}}))}))},this.setContactModalVisible=function(t){M.isContactModalVisible=t},this.checkout=j,this.checkoutSettings=x,this.router=O,this.returnPolicy=T,this.privacyPolicy=D,this.termsOfService=G,this.t=_,E&&(this.merchantSettings=E),this.isTermsAndConditionsChecked=this.checkoutSettings.isTermsAndConditionsDefaultChecked||!1,this.init(),s(this)}return Object.defineProperty(j.prototype,"selectedPaymentGatewayIndex",{get:function(){var t=this;return this.paymentGateways.findIndex((function(e){var i;return e.id===(null===(i=t.checkout.selectedPaymentGateway)||void 0===i?void 0:i.id)}))},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"selectedInstallmentIndex",{get:function(){var t,e,i=this;return(null===(e=null===(t=this.installmentInfo)||void 0===t?void 0:t.installmentPrices)||void 0===e?void 0:e.findIndex((function(t){var e;return t.installmentCount===(null===(e=i.cardData)||void 0===e?void 0:e.installmentCount)})))||0},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"checkoutUrl",{get:function(){return"/checkout?id=".concat(this.checkout.id,"&step=info")},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"customerAddressOptions",{get:function(){var t,e,i={label:this.t("checkout-page:newAddress"),value:"-1"},s=(null===(e=null===(t=this.store.customerStore.customer)||void 0===t?void 0:t.addresses)||void 0===e?void 0:e.map((function(t){return{label:t.title+" - "+t.addressText,value:t.id}})))||[];return[i].concat(s)},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"installmentPrice",{get:function(){var t,e,i,s=this;if(this.installmentInfo&&(null===(t=this.cardData)||void 0===t?void 0:t.installmentCount))return null===(i=null===(e=this.installmentInfo.installmentPrices)||void 0===e?void 0:e.find((function(t){var e;return t.installmentCount===(null===(e=s.cardData)||void 0===e?void 0:e.installmentCount)})))||void 0===i?void 0:i.totalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"installmentExtraPrice",{get:function(){if(this.installmentPrice&&this.checkout.totalFinalPrice)return this.installmentPrice-this.checkout.totalFinalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"finalPrice",{get:function(){return this.step===A.SUCCESS?this.checkout.totalFinalPrice:this.installmentPrice||this.checkout.$totalFinalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"hasStockError",{get:function(){var t;return(null===(t=this.error)||void 0===t?void 0:t.type)===P.STOCK_ERROR},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"canProceedToShipping",{get:function(){var t,e;return(null===(t=this.checkout.shippingAddress)||void 0===t?void 0:t.isValid)&&this.checkout.hasValidCustomerEmail&&(null===(e=this.error)||void 0===e?void 0:e.type)!==P.NO_SHIPPING_ERROR},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"canProceedToInStoreDelivery",{get:function(){var t,e,i;return!!((null===(t=this.checkout.customer)||void 0===t?void 0:t.firstName)&&(null===(e=this.checkout.customer)||void 0===e?void 0:e.lastName)&&(null===(i=this.checkout.customer)||void 0===i?void 0:i.email)&&this.checkout.stockLocationId)},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"canProceedToPayment",{get:function(){return this.canProceedToShipping},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"isInStoreDelivery",{get:function(){return!!this.checkout.stockLocationId},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"canPerformPayment",{get:function(){var t,e;if(this.checkoutSettings.showTermsAndConditionsCheckbox&&!this.isTermsAndConditionsChecked)return!1;var i=this.checkout.selectedPaymentGateway;return("in-store"===this.deliveryMethod||this.canProceedToShipping)&&("in-store"===this.deliveryMethod||!!(null===(t=this.checkout.billingAddress)||void 0===t?void 0:t.isValid))&&((null==i?void 0:i.paymentMethodType)===k.CREDIT_CARD&&i.type===b.INTERNAL?null===(e=this.cardData)||void 0===e?void 0:e.isValid:!!i)},enumerable:!1,configurable:!0}),j}();function N(t,e){return t.match(new RegExp(".{1,"+e+"}","g"))||[]}function R(t){return t&&j.test(t.charAt(t.length-1))}!function(t){t.INFO="info",t.SHIPPING="shipping",t.PAYMENT="payment",t.SUCCESS="success"}(A||(A={})),function(t){t[t.UNKNOWN=0]="UNKNOWN",t[t.API_ERROR=1]="API_ERROR",t[t.STOCK_ERROR=2]="STOCK_ERROR",t[t.PAYMENT_ERROR=3]="PAYMENT_ERROR",t[t.NO_SHIPPING_ERROR=4]="NO_SHIPPING_ERROR",t[t.CUSTOMER_LOGIN_REQUIRED_ERROR=5]="CUSTOMER_LOGIN_REQUIRED_ERROR"}(P||(P={}));export{A as CheckoutStep,P as ErrorType,x as default};
1
+ import{__awaiter as t,__generator as e,__assign as i}from'../../ext/tslib/tslib.es6.js';import{makeAutoObservable as s}from"mobx";import n from'../../ext/lodash/cloneDeep.js';import r from'../../ext/lodash/sortBy.js';import"../../models/data/blog/index.js";import"../../models/data/brand/index.js";import"../../models/data/cart/campaign-offer/index.js";import"../../models/data/cart/index.js";import"../../models/data/category/index.js";import"../../models/data/city/index.js";import"../../models/data/country/index.js";import{IkasCustomerAddress as o}from"../../models/data/customer/address/index.js";import"../../models/data/customer/attribute-value/index.js";import"../../models/data/customer/index.js";import"../../models/data/customer-attribute/customer-attribute-option/index.js";import"../../models/data/customer-attribute/customer-attribute-sales-channel/index.js";import"../../models/data/customer-attribute/index.js";import"../../models/data/customer-review/index.js";import"../../models/data/customer-review-summary/index.js";import"../../models/data/district/index.js";import"../../models/data/favorite-product/index.js";import"../../models/data/html-meta-data/index.js";import"../../models/data/image/index.js";import"../../models/data/merchant-settings/index.js";import{IkasOrderAddress as a}from"../../models/data/order/address/index.js";import"../../models/data/order/adjustment/index.js";import{IkasOrderCustomer as d}from"../../models/data/order/customer/index.js";import"../../models/data/order/gift-line/index.js";import"../../models/data/order/invoice/index.js";import"../../models/data/order/line-item/discount/index.js";import"../../models/data/order/line-item/option/value/index.js";import"../../models/data/order/line-item/option/index.js";import"../../models/data/order/line-item/variant/index.js";import"../../models/data/order/line-item/index.js";import"../../models/data/order/package/tracking-info/index.js";import"../../models/data/order/package/index.js";import"../../models/data/order/payment-method/index.js";import"../../models/data/order/refund/line-item/index.js";import"../../models/data/order/shipping-line/index.js";import"../../models/data/order/tax-line/index.js";import"../../models/data/order/transaction/index.js";import"../../models/data/order/index.js";import"../../models/data/product/attribute-value/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/product-attribute/index.js";import"../../models/data/product-filter/index.js";import"../../models/data/product-campaign/campaign/index.js";import"../../models/data/product-campaign/filter/index.js";import"../../models/data/product-option-set/index.js";import"../../models/data/raffle/index.js";import"../../models/data/state/index.js";import"../../models/data/variant-type/variant-value/index.js";import"../../models/theme/theme.js";import"../../models/theme/page/index.js";import"../../models/theme/component/prop/index.js";import"../../models/theme/page/component/prop-value/link.js";import"../../models/ui/brand-list/index.js";import"../../models/ui/blog-list/index.js";import"../../models/ui/blog-category-list/index.js";import"../../models/ui/category-list/index.js";import"../../models/ui/product-detail/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/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"../../models/theme/settings/index.js";import"../../models/theme/custom-data/index.js";import"../../models/data/payment-gateway/index.js";import c from"./components/credit-card-form/model.js";import{IkasStorefrontConfig as l}from"../../storefront/index.js";import{IkasCheckoutSettings as u}from"../../models/data/checkout-settings/index.js";import{Analytics as h}from"../../analytics/analytics.js";import"../../analytics/head/index.js";import p from"../../models/data/checkout/index.js";import m from"../../store/customer/api.js";import f from"../../store/merchant/index.js";import v from"../../store/checkout/index.js";import{CheckStocksLineInput as g}from"../../__api/models/CheckStocksLineInput.js";import y from"../../store/cart/api.js";import{SaveCartInput as S}from"../../__api/models/SaveCartInput.js";import{PaymentMethodEnum as k,PaymentGatewayTypeEnum as b,TransactionStatusEnum as I}from"../../__api/types/index.js";import C from'../../ext/uuid/dist/esm-node/v4.js';var A,P,j=/^\d+$/,w="undefined"==typeof localStorage,x=function(){function j(j,x,E,O,T,D,G,_){var M=this;this.checkout=new p,this.checkoutSettings=new u,this.storefront=null,this.store=l.store,this.isCheckoutLoaded=!1,this.isErrorsVisible=!1,this.isStepLoading=!1,this.isTermsAndConditionsChecked=!1,this.isChangingShippingMethod=!1,this.isContactModalVisible=!1,this.step=A.INFO,this.cardData=null,this.paymentGateways=[],this.installmentInfo=null,this.useDifferentAddress=!1,this.shouldSaveAddress=!1,this.addressTitle="",this.shippingCountryIds=null,this.selectedShippingAddressId="-1",this.selectedBillingAddressId="-1",this.stockLocations=[],this.deliveryMethod="address",this.policyModalTitle="",this.policyModalText="",this.error=null,this.init=function(){return t(M,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,this.store.customerStore.waitUntilInitialized()];case 1:return t.sent(),this.createCustomer(),this.createShippingAddress(),this.createBillingAddress(),[4,this.getMerchantSettings()];case 2:return t.sent(),[4,this.initStep()];case 3:return t.sent(),[2]}}))}))},this.initStep=function(){return t(M,void 0,void 0,(function(){var t,i,s,n,r,o,a,d,c;return e(this,(function(e){switch(e.label){case 0:if(l.isEditor)return this.step=A.INFO,this.isCheckoutLoaded=!0,[2];if(t=new URLSearchParams(window.location.search),i=t.get("step"),s=t.get("failed"),n=t.get("error"),i){if(this.step=i,this.step===A.SHIPPING&&!this.canProceedToShipping)return[2,this.changeStep(A.INFO)];if(this.step!==A.PAYMENT||this.canProceedToPayment){if(![A.INFO,A.SUCCESS,A.SHIPPING,A.PAYMENT].includes(this.step))return[2,this.changeStep(A.INFO)]}else{if(!this.isInStoreDelivery)return[2,this.changeStep(A.INFO)];this.deliveryMethod="in-store"}}return s&&(this.error={type:P.PAYMENT_ERROR,data:n||null}),this.step!==A.INFO?[3,3]:[4,this.getShippingCountries()];case 1:return e.sent(),this.checkShippingCountries(),[4,this.getStockLocations()];case 2:e.sent(),this.isInStoreDelivery&&(this.deliveryMethod="in-store"),e.label=3;case 3:return this.step!==A.SHIPPING||1!==(null===(a=this.checkout.availableShippingMethods)||void 0===a?void 0:a.length)||this.checkoutSettings.isGiftPackageEnabled||(this.step=A.PAYMENT,this.router.replace("/checkout?id=".concat(this.checkout.id,"&step=").concat(this.step),void 0,{shallow:!0})),this.step!==A.SHIPPING||(null===(d=this.checkout.availableShippingMethods)||void 0===d?void 0:d.length)?this.step!==A.PAYMENT&&this.step!==A.SUCCESS?[3,7]:[4,this.listPaymentGateways()]:(this.error={type:P.NO_SHIPPING_ERROR},this.isCheckoutLoaded=!0,[2]);case 4:return e.sent(),this.isInStoreDelivery?(this.deliveryMethod="in-store",[4,this.getStockLocations()]):[3,6];case 5:e.sent(),e.label=6;case 6:if(!this.paymentGateways.length)return this.error={type:P.NO_SHIPPING_ERROR},this.isCheckoutLoaded=!0,[2];e.label=7;case 7:return this.step===A.SUCCESS?[3,11]:this.checkout.isComplete?[2,this.changeStep(A.SUCCESS)]:[3,8];case 8:return[4,this.initialStockCheck()];case 9:e.sent(),e.label=10;case 10:return[3,13];case 11:return[4,m.listOrderTransactions({orderId:{eq:this.checkout.id}})];case 12:r=e.sent(),this.successTransaction=r.isSuccess&&(null===(c=r.data)||void 0===c?void 0:c.length)?r.data[0]:void 0,this.successTransaction&&(o=this.successTransaction.paymentGatewayId,this.checkout.selectedPaymentGateway=this.paymentGateways.find((function(t){return t.id===o}))),e.label=13;case 13:return this.isCheckoutLoaded=!0,h.checkoutStep(this.checkout,this.step),[2]}}))}))},this.getMerchantSettings=function(){return t(M,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.merchantSettings?[3,2]:[4,f.listMerchantSettings({})];case 1:t=e.sent(),this.merchantSettings=t.data||void 0,e.label=2;case 2:return[2]}}))}))},this.saveCart=function(){return t(M,void 0,void 0,(function(){var t,i,s,n;return e(this,(function(e){switch(e.label){case 0:return(t=new S(this.checkout)).cartId=this.checkout.id,"in-store"!==this.deliveryMethod?[3,2]:[4,this.inStockDeliveryInputData(t)];case 1:t=e.sent(),e.label=2;case 2:return[4,y.saveCart({input:t})];case 3:if((null==(i=e.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:P.CUSTOMER_LOGIN_REQUIRED_ERROR}:{type:P.API_ERROR};return[2,i.data]}}))}))},this.inStockDeliveryInputData=function(i){return t(M,void 0,void 0,(function(){var t,s,n=this;return e(this,(function(e){return t=i,(s=this.stockLocations.find((function(t){return t.id===n.checkout.stockLocationId})))&&t.shippingAddress&&s.address&&(t.shippingAddress.country=s.address.country,t.shippingAddress.city=s.address.city,t.shippingAddress.state=s.address.state,t.shippingAddress.district=s.address.district,t.shippingAddress.postalCode=s.address.postalCode,t.shippingAddress.addressLine1=s.address.address||"",t.shippingAddress.addressLine2=null),t.billingAddress=null,[2,t]}))}))},this.checkStocks=function(){return t(M,void 0,void 0,(function(){var t,i,s,n,r,o,a,d,c,u,h,p;return e(this,(function(e){switch(e.label){case 0:return t=this.checkout.items.map((function(t){return{quantity:t.quantity,variantId:t.variant.id,productId:t.variant.productId}})),[4,v.checkStocks({lines:t.map((function(t){return new g(t)})),stockLocationIdList:l.stockLocationIds||[]})];case 1:if(!(i=e.sent()).isSuccess)throw{type:P.API_ERROR};if(null==(s=null===(h=null===(u=i.data)||void 0===u?void 0:u.lines)||void 0===h?void 0:h.filter((function(t){return!t.isAvailable})))?void 0:s.length){for(n=[],r=function(t){var e=null===(p=o.store.cartStore.cart)||void 0===p?void 0:p.items.find((function(e){return e.variant.id===t.variantId}));e&&n.push(e)},o=this,a=0,d=s;a<d.length;a++)c=d[a],r(c);throw{type:P.STOCK_ERROR,data:n}}return[2]}}))}))},this.removeUnavailableItems=function(i){return t(M,void 0,void 0,(function(){var t,s,n;return e(this,(function(e){switch(e.label){case 0:t=0,s=i,e.label=1;case 1:return t<s.length?(n=s[t],[4,this.store.cartStore.removeItem(n)]):[3,4];case 2:e.sent(),e.label=3;case 3:return t++,[3,1];case 4:return[2]}}))}))},this.getShippingCountries=function(){return t(M,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,v.getAvailableShippingCountries({salesChannelId:l.salesChannelId})];case 1:return t=e.sent(),this.shippingCountryIds=t.data,[2]}}))}))},this.getStockLocations=function(){return t(M,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return l.pickUpStockLocationIds?[4,v.listStockLocation({id:{in:l.pickUpStockLocationIds}})]:[3,2];case 1:if(!(t=e.sent()).isSuccess||!(null===(i=t.data)||void 0===i?void 0:i.length))return this.error={type:P.API_ERROR},[2];this.stockLocations=t.data,e.label=2;case 2:return[2]}}))}))},this.checkShippingCountries=function(){var t;(null===(t=M.shippingCountryIds)||void 0===t?void 0:t.length)||(M.error={type:P.NO_SHIPPING_ERROR})},this.onDeliveryMethodChange=function(t){"address"===t&&(M.checkout.stockLocationId=null),M.deliveryMethod=t,M.isErrorsVisible=!1},this.initialStockCheck=function(){return t(M,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this.checkStocks()];case 1:return e.sent(),[3,3];case 2:return(t=e.sent()).type?this.error=t:(console.log(t),this.error={type:P.UNKNOWN}),[3,3];case 3:return[2]}}))}))},this.listPaymentGateways=function(){return t(M,void 0,void 0,(function(){var t,i,s,n,o,a,d,c,u=this;return e(this,(function(e){switch(e.label){case 0:return t="local"===process.env.NEXT_PUBLIC_ENV,i=l.paymentGateways.map((function(t){return t.id})),[4,v.listPaymentGateway({id:t?void 0:{in:i}})];case 1:return(s=e.sent()).isSuccess&&(null===(d=s.data)||void 0===d?void 0:d.length)?(n=s.data,this.step===A.PAYMENT&&(n=n.filter((function(t){return!t.supportedCurrencies.length||t.supportedCurrencies.includes(u.checkout.currencyCode)})),(o=null===(c=this.checkout.shippingAddress)||void 0===c?void 0:c.country)&&o.iso2&&(n=n.filter((function(t){return!t.availableCountries.length||t.availableCountries.includes(o.iso2||"")})))),a=[],r(l.paymentGateways,"order").forEach((function(t){var e=null==n?void 0:n.find((function(e){return e.id===t.id}));e&&a.push(e)})),this.paymentGateways=t?n:a,this.checkout.selectedPaymentGateway||this.setPaymentGateway(0),[2]):(this.error={type:P.API_ERROR},[2])}}))}))},this.retrieveInstallmentInfo=function(i){return t(M,void 0,void 0,(function(){var t,s,n;return e(this,(function(e){switch(e.label){case 0:return[4,v.retrieveInstallmentInfo(i)];case 1:return t=e.sent(),s=t.data,null===(n=null==s?void 0:s.installmentPrices)||void 0===n||n.sort((function(t,e){return(t.installmentCount||-1)>(e.installmentCount||-1)?1:-1})),this.installmentInfo=s,[2]}}))}))},this.createCustomer=function(){var t;M.store.customerStore.customer?(null===(t=M.store.customerStore.customer.addresses)||void 0===t||t.forEach((function(t){return t.checkoutSettings=M.checkoutSettings})),M.checkout.customer=new d(M.store.customerStore.customer)):M.checkout.customer||(M.checkout.customer=new d({}))},this.createShippingAddress=function(){var t;if(M.checkout.shippingAddress)M.selectedShippingAddressId=M.checkout.shippingAddress.id||"-1",M.checkout.shippingAddress.checkoutSettings=M.checkoutSettings;else{var e=null===(t=M.store.customerStore.customer)||void 0===t?void 0:t.addresses;M.onSelectedShippingAddressIdChange((null==e?void 0:e.length)?e[0].id:"-1")}},this.createBillingAddress=function(){"undefined"!=typeof localStorage&&(M.useDifferentAddress=!!localStorage.getItem("sAddr"),M.useDifferentAddress?(M.checkout.billingAddress&&(M.selectedBillingAddressId=M.checkout.billingAddress.id||"-1"),M.checkout.billingAddress=M.checkout.billingAddress||new a):M.checkout.billingAddress=new a(n(M.checkout.shippingAddress)||{}),M.checkout.billingAddress.checkoutSettings=M.checkoutSettings)},this.onShippingMethodChange=function(i){return t(M,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.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(t=e.sent())&&(this.checkout=new p(t)),this.isChangingShippingMethod=!1,[2]}}))}))},this.onStockLocationChange=function(i){return t(M,void 0,void 0,(function(){return e(this,(function(t){return this.checkout.stockLocationId=i.id,[2]}))}))},this.onCouponCodeApply=function(){return t(M,void 0,void 0,(function(){var t,s,n,r,o,a;return e(this,(function(e){switch(e.label){case 0:if(!this.checkout.couponCode)return[2];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,y.saveCartCouponCode({cartId:this.checkout.id,couponCode:this.checkout.couponCode})];case 2:return(t=e.sent()).isSuccess&&t.data&&(s=t.data,n=null===(a=null===(o=this.cardData)||void 0===o?void 0:o.cardNumber)||void 0===a?void 0:a.split(" ").join(""),this.step===A.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}}),s&&(r=this.checkout,this.checkout=new p(i(i({},s),{shippingAddress:r.shippingAddress,billingAddress:r.billingAddress,customer:r.customer,selectedPaymentGateway:r.selectedPaymentGateway})))),[3,4];case 3:return e.sent(),[3,4];case 4:return[2]}}))}))},this.onCouponCodeDelete=function(){return t(M,void 0,void 0,(function(){var t,s;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this.saveCart()];case 1:return(t=e.sent())&&(s=this.checkout,this.checkout=new p(i(i({},t),{shippingAddress:s.shippingAddress,billingAddress:s.billingAddress,customer:s.customer,selectedPaymentGateway:s.selectedPaymentGateway}))),[3,3];case 2:return e.sent(),[3,3];case 3:return[2]}}))}))},this.onSelectedShippingAddressIdChange=function(t){var e,i;if(M.selectedShippingAddressId=t,"-1"===t)M.checkout.shippingAddress=new a;else{var s=null===(i=null===(e=M.store.customerStore.customer)||void 0===e?void 0:e.addresses)||void 0===i?void 0:i.find((function(e){return e.id===t}));s&&(M.checkout.shippingAddress=new a(s))}M.checkout.shippingAddress&&(M.checkout.shippingAddress.checkoutSettings=M.checkoutSettings)},this.onSelectedBillingAddressIdChange=function(t){var e,i;if(M.selectedBillingAddressId=t,"-1"===t)M.checkout.billingAddress=new a;else{var s=null===(i=null===(e=M.store.customerStore.customer)||void 0===e?void 0:e.addresses)||void 0===i?void 0:i.find((function(e){return e.id===t}));s&&(M.checkout.billingAddress=new a(s))}M.checkout.billingAddress&&(M.checkout.billingAddress.checkoutSettings=M.checkoutSettings)},this.onTermsAndConditionsCheckedChange=function(t){M.isTermsAndConditionsChecked=t},this.onCardNumberChange=function(t){if(M.cardData&&(!(t.length>M.cardData.cardNumber.length)||R(t))){var e=(M.cardData.cardNumber||"").split(" ").join(""),i=t.split(" ").join("");i.length>16||(e.length<6&&i.length>=6&&!M.installmentInfo?M.retrieveInstallmentInfo({input:{binNumber:i.slice(0,6),paymentGatewayId:M.checkout.selectedPaymentGateway.id,price:M.checkout.totalFinalPrice}}):i.length<6&&e.length>i.length&&(M.cardData.installmentCount=1,M.installmentInfo=void 0),M.cardData.cardNumber=N(i,4).join(" "))}},this.onCardHolderNameChange=function(t){M.cardData&&(M.cardData.cardHolderName=t)},this.onExpirationDateChange=function(t){var e;if(M.cardData&&(!(t.length>M.cardData.expirationDate.length)||R(t))){if(0===(null===(e=M.cardData.expirationDate)||void 0===e?void 0:e.length)){var i=t.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(M.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(M.cardData.expirationDate="".concat(o<10?"0"+o:o," / ").concat(r<10?"0"+r:r))}}}var a=t.split(" / ").join("");a.length>4||(M.cardData.expirationDate=N(a,2).join(" / "))}},this.onCvcChange=function(t){M.cardData&&(t.length>M.cardData.cvv.length&&!R(t)||t.length>4||(M.cardData.cvv=t))},this.saveAddress=function(s){return t(M,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return this.shouldSaveAddress?(t=new o(i(i({},"shipping"===s?this.checkout.shippingAddress:this.checkout.billingAddress),{title:this.addressTitle||this.t("checkout-page:newAddress"),id:C()})),(r=n(this.store.customerStore.customer)).addresses||(r.addresses=[]),r.addresses.push(t),[4,this.store.customerStore.saveCustomer(r)]):[3,2];case 1:e.sent(),"shipping"===s?(this.checkout.shippingAddress.id=t.id,this.selectedShippingAddressId=t.id||"-1"):(this.checkout.billingAddress.id=t.id,this.selectedBillingAddressId=t.id||"-1"),e.label=2;case 2:return[2]}}))}))},this.onGoToCartClick=function(){M.router.push("/cart")},this.onBackToShoppingClick=function(){M.router.push("/")},this.onProceedToShippingClick=function(){return t(M,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.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,e.label=1;case 1:return e.trys.push([1,6,,7]),this.isStepLoading=!0,"address"!==this.deliveryMethod?[3,3]:[4,this.saveAddress("shipping")];case 2:e.sent(),e.label=3;case 3:return[4,this.checkStocks()];case 4:return e.sent(),[4,this.saveCart()];case 5:return e.sent(),"address"===this.deliveryMethod?this.changeStep(A.SHIPPING):this.changeStep(A.PAYMENT),[3,7];case 6:return(t=e.sent()).type?this.error=t:(console.log(t),this.error={type:P.UNKNOWN}),this.isStepLoading=!1,[3,7];case 7:return[2]}}))}))},this.onProceedToPaymentClick=function(){return t(M,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:if(!this.canProceedToPayment)return this.isErrorsVisible=!0,[2];this.isErrorsVisible=!1,e.label=1;case 1:return e.trys.push([1,4,,5]),this.isStepLoading=!0,[4,this.checkStocks()];case 2:return e.sent(),[4,this.saveCart()];case 3:return e.sent(),this.error=void 0,this.changeStep(A.PAYMENT),[3,5];case 4:return(t=e.sent()).type?this.error=t:(console.log(t),this.error={type:P.UNKNOWN}),this.isStepLoading=!1,[3,5];case 5:return[2]}}))}))},this.onCompletePaymentClick=function(){return t(M,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:if(!this.canPerformPayment)return this.isErrorsVisible=!0,[2];this.useDifferentAddress||(this.checkout.billingAddress=this.checkout.shippingAddress),e.label=1;case 1:return e.trys.push([1,7,,8]),this.isErrorsVisible=!1,this.isStepLoading=!0,[4,this.checkStocks()];case 2:return e.sent(),"address"!==this.deliveryMethod?[3,4]:[4,this.saveAddress("billing")];case 3:e.sent(),e.label=4;case 4:return[4,this.saveCart()];case 5:return e.sent(),[4,this.createSaleTransaction()];case 6:return e.sent(),[3,8];case 7:return(t=e.sent()).type?this.error=t:this.error={type:P.UNKNOWN},this.isStepLoading=!1,[3,8];case 8:return[2]}}))}))},this.createSaleTransaction=function(){return t(M,void 0,void 0,(function(){var t,i,s,n,r,o;return e(this,(function(e){switch(e.label){case 0:return this.checkout.selectedPaymentGateway?[4,v.createSaleTransactionWithCart({input:{cartId:this.checkout.id,paymentGatewayId:this.checkout.selectedPaymentGateway.id,paymentMethodDetail:this.checkout.selectedPaymentGateway.paymentMethodType===k.CREDIT_CARD&&this.checkout.selectedPaymentGateway.type===b.INTERNAL&&this.cardData?this.cardData.toInput():void 0}})]:[2];case 1:return t=e.sent(),i=null===(r=null==t?void 0:t.data)||void 0===r?void 0:r.transactionStatus,s=i&&[I.SUCCESS,I.AUTHORIZED].includes(i),n=i===I.PENDING,s?[4,this.onCheckoutTransactionSuccess()]:[3,3];case 2:return e.sent(),[3,4];case 3:if(!n||!(null===(o=null==t?void 0:t.data)||void 0===o?void 0:o.returnSlug))throw{type:P.UNKNOWN};window.location.href=process.env.NEXT_PUBLIC_BASE_URL+t.data.returnSlug,e.label=4;case 4:return[2]}}))}))},this.onCheckoutTransactionSuccess=function(){return t(M,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return localStorage.removeItem("sAddr"),(null===(t=this.checkout.customer)||void 0===t?void 0:t.notificationsAccepted)?[4,this.store.customerStore.createEmailSubscription((null===(i=this.checkout.customer)||void 0===i?void 0:i.email)||"")]:[3,2];case 1:e.sent(),e.label=2;case 2:return this.changeStep(A.SUCCESS),[2]}}))}))},this.onBackToInfoClick=function(){M.changeStep(A.INFO)},this.onBackToShippingClick=function(){M.changeStep(A.SHIPPING)},this.setCustomerConsentGranted=function(t){M.checkout.customer&&(M.checkout.customer.notificationsAccepted=t)},this.setUseDifferentAddress=function(t){M.useDifferentAddress=t,M.useDifferentAddress?(localStorage.setItem("sAddr","1"),M.checkout.billingAddress=M.checkout.billingAddress||new a):(localStorage.removeItem("sAddr"),M.checkout.billingAddress=M.checkout.shippingAddress)},this.setShouldSaveAddress=function(t){M.shouldSaveAddress=t},this.setAddressTitle=function(t){M.addressTitle=t},this.setPaymentGateway=function(t){if(M.paymentGateways.length){var e=M.paymentGateways[t];M.checkout.selectedPaymentGateway=e,M.step!==A.SUCCESS&&(e.paymentMethodType===k.CREDIT_CARD&&e.type===b.INTERNAL&&(M.cardData=new c),M.installmentInfo=void 0)}},this.setInstallmentCount=function(t){M.cardData&&(M.cardData.installmentCount=t)},this.changeStep=function(i){return t(M,void 0,void 0,(function(){return e(this,(function(t){return w||window.location.replace("".concat(window.location.pathname,"?id=").concat(this.checkout.id,"&step=").concat(i)),[2]}))}))},this.logout=function(){return t(M,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:this.checkout.customer=null,this.store.customerStore.logout(),t.label=1;case 1:return t.trys.push([1,3,,4]),[4,this.saveCart()];case 2:case 3:return t.sent(),[3,4];case 4:return this.createCustomer(),[2]}}))}))},this.setContactModalVisible=function(t){M.isContactModalVisible=t},this.checkout=j,this.checkoutSettings=x,this.router=O,this.returnPolicy=T,this.privacyPolicy=D,this.termsOfService=G,this.t=_,E&&(this.merchantSettings=E),this.isTermsAndConditionsChecked=this.checkoutSettings.isTermsAndConditionsDefaultChecked||!1,this.init(),s(this)}return Object.defineProperty(j.prototype,"selectedPaymentGatewayIndex",{get:function(){var t=this;return this.paymentGateways.findIndex((function(e){var i;return e.id===(null===(i=t.checkout.selectedPaymentGateway)||void 0===i?void 0:i.id)}))},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"selectedInstallmentIndex",{get:function(){var t,e,i=this;return(null===(e=null===(t=this.installmentInfo)||void 0===t?void 0:t.installmentPrices)||void 0===e?void 0:e.findIndex((function(t){var e;return t.installmentCount===(null===(e=i.cardData)||void 0===e?void 0:e.installmentCount)})))||0},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"checkoutUrl",{get:function(){return"/checkout?id=".concat(this.checkout.id,"&step=info")},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"customerAddressOptions",{get:function(){var t,e,i={label:this.t("checkout-page:newAddress"),value:"-1"},s=(null===(e=null===(t=this.store.customerStore.customer)||void 0===t?void 0:t.addresses)||void 0===e?void 0:e.map((function(t){return{label:t.title+" - "+t.addressText,value:t.id}})))||[];return[i].concat(s)},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"installmentPrice",{get:function(){var t,e,i,s=this;if(this.installmentInfo&&(null===(t=this.cardData)||void 0===t?void 0:t.installmentCount))return null===(i=null===(e=this.installmentInfo.installmentPrices)||void 0===e?void 0:e.find((function(t){var e;return t.installmentCount===(null===(e=s.cardData)||void 0===e?void 0:e.installmentCount)})))||void 0===i?void 0:i.totalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"installmentExtraPrice",{get:function(){if(this.installmentPrice&&this.checkout.totalFinalPrice)return this.installmentPrice-this.checkout.totalFinalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"finalPrice",{get:function(){return this.step===A.SUCCESS?this.checkout.totalFinalPrice:this.installmentPrice||this.checkout.$totalFinalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"hasStockError",{get:function(){var t;return(null===(t=this.error)||void 0===t?void 0:t.type)===P.STOCK_ERROR},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"canProceedToShipping",{get:function(){var t,e;return(null===(t=this.checkout.shippingAddress)||void 0===t?void 0:t.isValid)&&this.checkout.hasValidCustomerEmail&&(null===(e=this.error)||void 0===e?void 0:e.type)!==P.NO_SHIPPING_ERROR},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"canProceedToInStoreDelivery",{get:function(){var t,e,i;return!!((null===(t=this.checkout.customer)||void 0===t?void 0:t.firstName)&&(null===(e=this.checkout.customer)||void 0===e?void 0:e.lastName)&&(null===(i=this.checkout.customer)||void 0===i?void 0:i.email)&&this.checkout.stockLocationId)},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"canProceedToPayment",{get:function(){return this.canProceedToShipping},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"isInStoreDelivery",{get:function(){return!!this.checkout.stockLocationId},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"canPerformPayment",{get:function(){var t,e;if(this.checkoutSettings.showTermsAndConditionsCheckbox&&!this.isTermsAndConditionsChecked)return!1;var i=this.checkout.selectedPaymentGateway;return("in-store"===this.deliveryMethod||this.canProceedToShipping)&&("in-store"===this.deliveryMethod||!!(null===(t=this.checkout.billingAddress)||void 0===t?void 0:t.isValid))&&((null==i?void 0:i.paymentMethodType)===k.CREDIT_CARD&&i.type===b.INTERNAL?null===(e=this.cardData)||void 0===e?void 0:e.isValid:!!i)},enumerable:!1,configurable:!0}),j}();function N(t,e){return t.match(new RegExp(".{1,"+e+"}","g"))||[]}function R(t){return t&&j.test(t.charAt(t.length-1))}!function(t){t.INFO="info",t.SHIPPING="shipping",t.PAYMENT="payment",t.SUCCESS="success"}(A||(A={})),function(t){t[t.UNKNOWN=0]="UNKNOWN",t[t.API_ERROR=1]="API_ERROR",t[t.STOCK_ERROR=2]="STOCK_ERROR",t[t.PAYMENT_ERROR=3]="PAYMENT_ERROR",t[t.NO_SHIPPING_ERROR=4]="NO_SHIPPING_ERROR",t[t.CUSTOMER_LOGIN_REQUIRED_ERROR=5]="CUSTOMER_LOGIN_REQUIRED_ERROR"}(P||(P={}));export{A as CheckoutStep,P as ErrorType,x as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/storefront",
3
- "version": "3.0.0-alpha.22",
3
+ "version": "3.0.0-alpha.23",
4
4
  "main": "./build/index.js",
5
5
  "module": "./build/index.js",
6
6
  "author": "Umut Ozan Yıldırım",