@ikas/storefront 1.0.21 → 2.0.0-alpha.1
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.
- package/build/ikas +12055 -0
- package/package.json +22 -21
- package/src/.DS_Store +0 -0
- package/src/__generated__/global-types.ts +753 -0
- package/src/analytics/analytics.ts +497 -0
- package/src/analytics/events.ts +115 -0
- package/src/analytics/facebookPixel.ts +226 -0
- package/src/analytics/googleTagManager.ts +334 -0
- package/src/analytics/head/index.tsx +81 -0
- package/src/analytics/ikas.ts +545 -0
- package/{build/analytics/index.d.ts → src/analytics/index.ts} +2 -2
- package/src/api/.DS_Store +0 -0
- package/src/api/apollo.ts +91 -0
- package/src/api/back-in-stock-reminder/__generated__/listProductBackInStockRemind.ts +36 -0
- package/src/api/back-in-stock-reminder/__generated__/saveProductBackInStockRemind.ts +31 -0
- package/src/api/back-in-stock-reminder/index.ts +131 -0
- package/src/api/blog/__generated__/getBlog.ts +101 -0
- package/src/api/blog/__generated__/listBlog.ts +104 -0
- package/src/api/blog/__generated__/listBlogCategory.ts +52 -0
- package/src/api/blog/__generated__/listBlogMetaData.ts +42 -0
- package/src/api/blog/index.ts +415 -0
- package/src/api/brand/__generated__/listProductBrand.ts +63 -0
- package/src/api/brand/index.ts +127 -0
- package/src/api/cart/__generated__/getCart.ts +104 -0
- package/src/api/cart/__generated__/saveItemToCart.ts +91 -0
- package/src/api/cart/index.ts +213 -0
- package/src/api/category/__generated__/listCategory.ts +68 -0
- package/src/api/category/__generated__/listCategoryPaths.ts +37 -0
- package/src/api/category/index.ts +223 -0
- package/src/api/checkout/__generated__/addCouponCodeToCheckout.ts +22 -0
- package/src/api/checkout/__generated__/checkStocks.ts +31 -0
- package/src/api/checkout/__generated__/createSaleTransactionWithCheckout.ts +35 -0
- package/src/api/checkout/__generated__/getCheckoutByCartId.ts +21 -0
- package/src/api/checkout/__generated__/getCheckoutById.ts +270 -0
- package/src/api/checkout/__generated__/getOrder.ts +248 -0
- package/src/api/checkout/__generated__/listCheckoutSettings.ts +48 -0
- package/src/api/checkout/__generated__/listPaymentGateway.ts +57 -0
- package/src/api/checkout/__generated__/retrieveInstallmentInfo.ts +36 -0
- package/src/api/checkout/__generated__/saveCheckout.ts +23 -0
- package/src/api/checkout/index.ts +884 -0
- package/src/api/city/__generated__/listCity.ts +26 -0
- package/src/api/city/index.ts +56 -0
- package/src/api/contact-form/__generated__/sendContactFormToMerchant.ts +19 -0
- package/src/api/contact-form/index.ts +54 -0
- package/src/api/country/__generated__/getAvailableShippingCountries.ts +16 -0
- package/src/api/country/__generated__/getMyCountry.ts +12 -0
- package/src/api/country/__generated__/listCountry.ts +36 -0
- package/src/api/country/index.ts +129 -0
- package/src/api/customer/__generated__/checkCustomerEmail.ts +21 -0
- package/src/api/customer/__generated__/createCustomerEmailSubscription.ts +23 -0
- package/src/api/customer/__generated__/createOrderRefundRequest.ts +248 -0
- package/src/api/customer/__generated__/customerForgotPassword.ts +17 -0
- package/src/api/customer/__generated__/customerLogin.ts +88 -0
- package/src/api/customer/__generated__/customerRecoverPassword.ts +18 -0
- package/src/api/customer/__generated__/customerRefreshToken.ts +22 -0
- package/src/api/customer/__generated__/getCustomerOrders.ts +248 -0
- package/src/api/customer/__generated__/getLastViewedProducts.ts +27 -0
- package/src/api/customer/__generated__/getMyCustomer.ts +75 -0
- package/src/api/customer/__generated__/listOrderRefundSettings.ts +25 -0
- package/src/api/customer/__generated__/listOrderTransactions.ts +68 -0
- package/src/api/customer/__generated__/registerCustomer.ts +90 -0
- package/src/api/customer/__generated__/saveLastViewedProducts.ts +23 -0
- package/src/api/customer/__generated__/saveMyCustomer.ts +80 -0
- package/src/api/customer/index.ts +1147 -0
- package/src/api/customer-review/__generated__/createCustomerReview.ts +23 -0
- package/src/api/customer-review/__generated__/listCustomerReviews.ts +38 -0
- package/src/api/customer-review/index.ts +122 -0
- package/src/api/district/__generated__/listDistrict.ts +25 -0
- package/src/api/district/index.ts +59 -0
- package/src/api/favorite-product/__generated__/isFavoriteProduct.ts +16 -0
- package/src/api/favorite-product/__generated__/listFavoriteProducts.ts +22 -0
- package/src/api/favorite-product/__generated__/saveFavoriteProduct.ts +17 -0
- package/src/api/favorite-product/index.ts +100 -0
- package/src/api/html-meta-data/__generated__/listHTMLMetaData.ts +30 -0
- package/src/api/html-meta-data/index.ts +72 -0
- package/src/api/index.ts +23 -0
- package/src/api/merchant/__generated__/listMerchantSettings.ts +19 -0
- package/src/api/merchant/index.ts +43 -0
- package/src/api/product-attribute/__generated__/listProductAttribute.ts +54 -0
- package/src/api/product-attribute/index.ts +69 -0
- package/src/api/product-option-set/__generated__/ListProductOptionSet.ts +111 -0
- package/src/api/product-option-set/index.ts +114 -0
- package/src/api/product-search/__generated__/getProductFilterData.ts +69 -0
- package/src/api/product-search/__generated__/searchProducts.ts +40 -0
- package/src/api/product-search/index.ts +329 -0
- package/src/api/raffle/__generated__/getRafflesByCustomerId.ts +55 -0
- package/src/api/raffle/__generated__/listRaffle.ts +74 -0
- package/src/api/raffle/__generated__/listRaffleMetaData.ts +33 -0
- package/src/api/raffle/__generated__/saveRaffleParticipant.ts +43 -0
- package/src/api/raffle/index.ts +369 -0
- package/src/api/state/__generated__/listState.ts +25 -0
- package/src/api/state/index.ts +45 -0
- package/src/api/stock-location/__generated__/listStockLocation.ts +17 -0
- package/src/api/stock-location/index.ts +30 -0
- package/src/api/storefront/__generated__/getStorefront.ts +67 -0
- package/src/api/storefront/index.ts +76 -0
- package/src/api/variant-type/__generated__/listVariantType.ts +54 -0
- package/src/api/variant-type/index.ts +86 -0
- package/{build → src}/assets/translations/checkout/en.js +0 -0
- package/{build → src}/assets/translations/checkout/tr.js +0 -0
- package/src/components/.DS_Store +0 -0
- package/src/components/checkout/components/address-form/index.tsx +360 -0
- package/src/components/checkout/components/address-form/model.ts +366 -0
- package/src/components/checkout/components/button/index.tsx +34 -0
- package/src/components/checkout/components/button/style.module.scss +103 -0
- package/src/components/checkout/components/cart-summary/cart-item/index.tsx +146 -0
- package/src/components/checkout/components/cart-summary/cart-item/style.module.scss +107 -0
- package/src/components/checkout/components/cart-summary/index.tsx +458 -0
- package/src/components/checkout/components/cart-summary/style.module.scss +237 -0
- package/src/components/checkout/components/checkbox/check.tsx +23 -0
- package/src/components/checkout/components/checkbox/index.tsx +50 -0
- package/src/components/checkout/components/checkbox/style.module.scss +72 -0
- package/src/components/checkout/components/credit-card-form/index.tsx +121 -0
- package/src/components/checkout/components/credit-card-form/model.ts +56 -0
- package/src/components/checkout/components/credit-card-form/style.module.scss +6 -0
- package/src/components/checkout/components/credit-card-form/svg/amex.tsx +30 -0
- package/src/components/checkout/components/credit-card-form/svg/master-card.tsx +38 -0
- package/src/components/checkout/components/credit-card-form/svg/troy.tsx +54 -0
- package/src/components/checkout/components/credit-card-form/svg/visa.tsx +46 -0
- package/src/components/checkout/components/customer-addresses/index.tsx +167 -0
- package/src/components/checkout/components/customer-addresses/model.ts +126 -0
- package/src/components/checkout/components/customer-addresses/style.module.scss +20 -0
- package/src/components/checkout/components/error/customer-login-required-error/index.tsx +23 -0
- package/src/components/checkout/components/error/index.tsx +54 -0
- package/src/components/checkout/components/error/no-shipping-error/index.tsx +19 -0
- package/src/components/checkout/components/error/payment-error/index.tsx +21 -0
- package/src/components/checkout/components/error/stock-error/index.tsx +72 -0
- package/src/components/checkout/components/error/stock-error/style.module.scss +11 -0
- package/src/components/checkout/components/error/unknown-error/index.tsx +19 -0
- package/src/components/checkout/components/expandable-section/index.tsx +37 -0
- package/src/components/checkout/components/expandable-section/style.module.scss +29 -0
- package/src/components/checkout/components/form-item/caret-down.tsx +20 -0
- package/src/components/checkout/components/form-item/index.tsx +205 -0
- package/src/components/checkout/components/form-item/model.ts +131 -0
- package/src/components/checkout/components/form-item/style.module.scss +213 -0
- package/src/components/checkout/components/fullscreen-loading/index.tsx +10 -0
- package/src/components/checkout/components/fullscreen-loading/style.module.scss +56 -0
- package/src/components/checkout/components/input-with-button/index.tsx +53 -0
- package/src/components/checkout/components/input-with-button/style.module.scss +104 -0
- package/src/components/checkout/components/modal/index.tsx +50 -0
- package/src/components/checkout/components/modal/style.module.scss +68 -0
- package/src/components/checkout/components/notification-box/index.tsx +70 -0
- package/src/components/checkout/components/notification-box/style.module.scss +69 -0
- package/src/components/checkout/components/select-box/index.tsx +60 -0
- package/src/components/checkout/components/select-box/style.module.scss +55 -0
- package/src/components/checkout/components/step-container/index.tsx +107 -0
- package/src/components/checkout/components/step-container/style.module.scss +86 -0
- package/src/components/checkout/components/svg/arrow-down.tsx +23 -0
- package/src/components/checkout/components/svg/arrow-left.tsx +23 -0
- package/src/components/checkout/components/svg/arrow-right.tsx +23 -0
- package/src/components/checkout/components/svg/cross.tsx +23 -0
- package/src/components/checkout/components/svg/discount.tsx +34 -0
- package/src/components/checkout/components/svg/external.tsx +101 -0
- package/src/components/checkout/components/svg/gift.tsx +40 -0
- package/src/components/checkout/components/svg/ikas.tsx +39 -0
- package/src/components/checkout/components/svg/lock.tsx +23 -0
- package/src/components/checkout/components/svg/shopping-cart.tsx +23 -0
- package/src/components/checkout/components/svg/success-circle.tsx +26 -0
- package/src/components/checkout/components/svg/tag.tsx +23 -0
- package/src/components/checkout/components/svg/warning.tsx +30 -0
- package/src/components/checkout/components/toggle/index.tsx +51 -0
- package/src/components/checkout/components/toggle/style.module.scss +75 -0
- package/src/components/checkout/components/tooltip/index.tsx +27 -0
- package/src/components/checkout/components/tooltip/style.module.scss +86 -0
- package/src/components/checkout/index.tsx +476 -0
- package/src/components/checkout/model.ts +1007 -0
- package/src/components/checkout/steps/step-info/index.tsx +84 -0
- package/src/components/checkout/steps/step-payment/billing-address/index.tsx +40 -0
- package/src/components/checkout/steps/step-payment/index.tsx +105 -0
- package/src/components/checkout/steps/step-payment/payment-gateways/index.tsx +116 -0
- package/src/components/checkout/steps/step-payment/payment-gateways/installments/index.tsx +51 -0
- package/src/components/checkout/steps/step-payment/payment-gateways/installments/style.module.scss +50 -0
- package/src/components/checkout/steps/step-payment/payment-gateways/style.module.scss +15 -0
- package/src/components/checkout/steps/step-payment/style.module.scss +32 -0
- package/src/components/checkout/steps/step-shipping/index.tsx +127 -0
- package/src/components/checkout/steps/step-shipping/style.module.scss +44 -0
- package/src/components/checkout/steps/step-success/index.tsx +437 -0
- package/src/components/checkout/steps/step-success/style.module.scss +160 -0
- package/src/components/checkout/style.module.scss +358 -0
- package/src/components/checkout/styles/common.module.scss +59 -0
- package/src/components/checkout/styles/variables.scss +40 -0
- package/src/components/image/index.tsx +79 -0
- package/src/components/index.ts +4 -0
- package/src/components/page/ThemeComponent.tsx +89 -0
- package/src/components/page/head.tsx +294 -0
- package/src/components/page/index.tsx +216 -0
- package/src/components/page-editor/ThemeComponentEditor.tsx +236 -0
- package/src/components/page-editor/error/index.tsx +18 -0
- package/src/components/page-editor/index.tsx +70 -0
- package/src/components/page-editor/loader/index.tsx +10 -0
- package/src/components/page-editor/loader/style.module.scss +55 -0
- package/src/components/page-editor/model.ts +505 -0
- package/src/index.ts +8 -0
- package/src/models/.DS_Store +0 -0
- package/src/models/data/blog/index.ts +154 -0
- package/src/models/data/brand/index.ts +58 -0
- package/src/models/data/cart/index.ts +82 -0
- package/src/models/data/category/index.ts +130 -0
- package/src/models/data/checkout/index.ts +222 -0
- package/src/models/data/checkout-settings/index.ts +48 -0
- package/src/models/data/city/index.ts +4 -0
- package/src/models/data/contact-form/index.ts +17 -0
- package/src/models/data/country/index.ts +8 -0
- package/src/models/data/customer/address/index.tsx +135 -0
- package/src/models/data/customer/index.ts +65 -0
- package/src/models/data/customer-review/index.ts +43 -0
- package/src/models/data/customer-review-settings/index.ts +4 -0
- package/src/models/data/district/index.ts +4 -0
- package/src/models/data/favorite-product/index.ts +15 -0
- package/src/models/data/html-meta-data/index.ts +56 -0
- package/src/models/data/image/index.ts +34 -0
- package/src/models/data/index.ts +55 -0
- package/src/models/data/installment-info/index.ts +34 -0
- package/src/models/data/merchant-settings/index.ts +14 -0
- package/src/models/data/order/address/index.ts +138 -0
- package/src/models/data/order/adjustment/index.ts +17 -0
- package/src/models/data/order/gift-line/index.ts +4 -0
- package/src/models/data/order/index.ts +289 -0
- package/src/models/data/order/line-item/discount/index.ts +15 -0
- package/src/models/data/order/line-item/index.ts +123 -0
- package/src/models/data/order/line-item/options/index.ts +18 -0
- package/src/models/data/order/line-item/options/options-value/index.ts +11 -0
- package/src/models/data/order/line-item/variant/index.ts +75 -0
- package/src/models/data/order/refund/index.ts +18 -0
- package/src/models/data/order/refund/refund-line-item/index.ts +13 -0
- package/src/models/data/order/refund/settings.ts +15 -0
- package/src/models/data/order/shipping-line/index.ts +7 -0
- package/src/models/data/order-transaction/index.ts +105 -0
- package/src/models/data/payment-gateway/index.ts +150 -0
- package/src/models/data/product/attribute-value/index.ts +42 -0
- package/src/models/data/product/index.ts +95 -0
- package/src/models/data/product/variant/index.ts +93 -0
- package/src/models/data/product/variant/price/index.ts +38 -0
- package/src/models/data/product/variant-type/index.ts +24 -0
- package/src/models/data/product-attribute/index.ts +75 -0
- package/src/models/data/product-attribute/product-attribute-option/index.ts +13 -0
- package/src/models/data/product-attribute/product-attribute-table-cell/index.ts +13 -0
- package/src/models/data/product-attribute/product-attribute-table-template/index.ts +18 -0
- package/src/models/data/product-back-in-stock-settings/index.ts +3 -0
- package/src/models/data/product-cart-item-options/index.ts +15 -0
- package/src/models/data/product-filter/index.ts +412 -0
- package/src/models/data/product-option-set/index.ts +392 -0
- package/src/models/data/product-tag/index.ts +13 -0
- package/src/models/data/raffle/index.ts +159 -0
- package/src/models/data/sales-channel/index.ts +41 -0
- package/src/models/data/simple-product/index.ts +154 -0
- package/src/models/data/state/index.ts +5 -0
- package/src/models/data/storefront/domain/index.ts +19 -0
- package/src/models/data/storefront/index.ts +56 -0
- package/src/models/data/storefront/localization/index.tsx +13 -0
- package/src/models/data/storefront/routing/index.tsx +17 -0
- package/src/models/data/storefront/theme/index.tsx +22 -0
- package/src/models/data/storefront/theme-localization/index.tsx +26 -0
- package/src/models/data/variant-type/index.ts +77 -0
- package/src/models/data/variant-type/variant-value/index.ts +29 -0
- package/src/models/index.ts +3 -0
- package/src/models/theme/component/index.ts +24 -0
- package/src/models/theme/component/prop/index.ts +56 -0
- package/src/models/theme/custom-data/index.ts +71 -0
- package/{build/models/theme/index.d.ts → src/models/theme/index.ts} +26 -18
- package/src/models/theme/page/component/index.ts +21 -0
- package/src/models/theme/page/component/prop-value/attribute-list.ts +18 -0
- package/src/models/theme/page/component/prop-value/attribute.ts +18 -0
- package/src/models/theme/page/component/prop-value/blog-category-list.ts +19 -0
- package/src/models/theme/page/component/prop-value/blog-category.ts +15 -0
- package/src/models/theme/page/component/prop-value/blog-list.ts +25 -0
- package/src/models/theme/page/component/prop-value/blog.ts +15 -0
- package/src/models/theme/page/component/prop-value/brand-list.ts +26 -0
- package/src/models/theme/page/component/prop-value/brand.ts +15 -0
- package/src/models/theme/page/component/prop-value/category-list.ts +26 -0
- package/src/models/theme/page/component/prop-value/category.ts +15 -0
- package/src/models/theme/page/component/prop-value/link.ts +38 -0
- package/src/models/theme/page/component/prop-value/product-detail.ts +17 -0
- package/src/models/theme/page/component/prop-value/product-list.ts +41 -0
- package/src/models/theme/page/component/prop-value/raffle-list.ts +16 -0
- package/src/models/theme/page/component/prop-value/raffle.ts +15 -0
- package/src/models/theme/page/index.ts +71 -0
- package/src/models/theme/settings/.DS_Store +0 -0
- package/src/models/theme/settings/index.ts +27 -0
- package/src/models/theme/settings/prop/color/index.ts +18 -0
- package/src/models/theme/settings/prop/favicon/index.ts +11 -0
- package/src/models/theme/theme.ts +202 -0
- package/src/models/ui/blog-category-list/index.ts +199 -0
- package/src/models/ui/blog-list/index.ts +202 -0
- package/src/models/ui/brand-list/index.ts +239 -0
- package/src/models/ui/category-list/index.ts +239 -0
- package/src/models/ui/component-renderer/index.ts +9 -0
- package/src/models/ui/customer-review-list/index.ts +171 -0
- package/src/models/ui/index.ts +41 -0
- package/src/models/ui/navigation-link/index.ts +22 -0
- package/src/models/ui/product-attribute-detail/index.ts +29 -0
- package/src/models/ui/product-attribute-list/index.ts +53 -0
- package/src/models/ui/product-detail/index.ts +269 -0
- package/src/models/ui/product-list/index.ts +959 -0
- package/src/models/ui/raffle-list/index.ts +208 -0
- package/src/models/ui/validator/form/account-info.ts +155 -0
- package/src/models/ui/validator/form/address.ts +436 -0
- package/src/models/ui/validator/form/contact-form.ts +180 -0
- package/src/models/ui/validator/form/customer-review.ts +134 -0
- package/src/models/ui/validator/form/forgot-password.ts +98 -0
- package/src/models/ui/validator/form/login.ts +130 -0
- package/src/models/ui/validator/form/raffle-form.ts +271 -0
- package/src/models/ui/validator/form/recover-password.ts +150 -0
- package/src/models/ui/validator/form/register.ts +200 -0
- package/src/models/ui/validator/index.ts +121 -0
- package/src/models/ui/validator/rules/index.ts +309 -0
- package/src/pages/.DS_Store +0 -0
- package/src/pages/404.tsx +29 -0
- package/src/pages/[slug]/index.tsx +28 -0
- package/src/pages/account/addresses.tsx +20 -0
- package/src/pages/account/favorite-products.tsx +20 -0
- package/src/pages/account/forgot-password.tsx +20 -0
- package/src/pages/account/index.tsx +20 -0
- package/src/pages/account/login.tsx +20 -0
- package/src/pages/account/orders/[id].tsx +20 -0
- package/src/pages/account/orders/index.tsx +20 -0
- package/src/pages/account/raffles.tsx +20 -0
- package/src/pages/account/recover-password.tsx +20 -0
- package/src/pages/account/register.tsx +20 -0
- package/src/pages/api/getComponentDirs.ts +39 -0
- package/src/pages/api/getTheme.ts +22 -0
- package/src/pages/api/index.ts +14 -0
- package/src/pages/api/middleware.ts +24 -0
- package/src/pages/api/updateTheme.ts +31 -0
- package/src/pages/api/uploadTheme.ts +276 -0
- package/src/pages/blog/[slug].tsx +27 -0
- package/src/pages/blog/index.tsx +20 -0
- package/src/pages/cart.tsx +20 -0
- package/src/pages/checkout.tsx +172 -0
- package/src/pages/editor.tsx +40 -0
- package/src/pages/home.tsx +20 -0
- package/src/pages/index.ts +22 -0
- package/src/pages/pages/[slug].tsx +82 -0
- package/src/pages/raffle/[slug].tsx +27 -0
- package/src/pages/raffle/index.tsx +20 -0
- package/src/pages/search.tsx +20 -0
- package/src/providers/helpers/raffles.ts +68 -0
- package/src/providers/page-data-get.ts +569 -0
- package/src/providers/page-data-init.ts +956 -0
- package/src/providers/page-data-next.ts +422 -0
- package/src/providers/placeholders.ts +39 -0
- package/src/providers/prop-value/attribute-list.ts +73 -0
- package/src/providers/prop-value/attribute.ts +73 -0
- package/src/providers/prop-value/blog-category-list.ts +25 -0
- package/src/providers/prop-value/blog-category.ts +40 -0
- package/src/providers/prop-value/blog-list.ts +56 -0
- package/src/providers/prop-value/blog.ts +37 -0
- package/src/providers/prop-value/boolean.ts +14 -0
- package/src/providers/prop-value/brand-list.ts +21 -0
- package/src/providers/prop-value/brand.ts +47 -0
- package/src/providers/prop-value/category-list.ts +21 -0
- package/src/providers/prop-value/category.ts +47 -0
- package/src/providers/prop-value/color.ts +14 -0
- package/src/providers/prop-value/custom.ts +548 -0
- package/src/providers/prop-value/image-list.ts +15 -0
- package/src/providers/prop-value/image.ts +15 -0
- package/{build/providers/prop-value/index.d.ts → src/providers/prop-value/index.ts} +3 -3
- package/src/providers/prop-value/link.ts +214 -0
- package/src/providers/prop-value/product-detail.ts +87 -0
- package/src/providers/prop-value/product-list.ts +69 -0
- package/src/providers/prop-value/raffle-list.ts +14 -0
- package/src/providers/prop-value/raffle.ts +43 -0
- package/src/providers/prop-value/rich-text.ts +14 -0
- package/src/providers/prop-value/text.ts +14 -0
- package/src/scripts/generators/api/index.ts +24 -0
- package/src/scripts/generators/api/info.ts +47 -0
- package/src/scripts/generators/components/index.ts +235 -0
- package/src/scripts/generators/config/content.ts +125 -0
- package/src/scripts/generators/config/index.ts +93 -0
- package/src/scripts/generators/pages/index.ts +95 -0
- package/src/scripts/generators/pages/info.ts +156 -0
- package/src/scripts/generators/store/content.ts +14 -0
- package/src/scripts/generators/store/index.ts +22 -0
- package/src/scripts/generators/theme/index.ts +37 -0
- package/src/scripts/ikas.ts +47 -0
- package/src/store/base.ts +143 -0
- package/src/store/cart.ts +311 -0
- package/src/store/customer.ts +510 -0
- package/{build/store/index.d.ts → src/store/index.ts} +1 -1
- package/src/storefront/index.ts +96 -0
- package/src/typings/global.d.ts +7 -0
- package/src/utils/currency.ts +229 -0
- package/src/utils/fs.ts +84 -0
- package/src/utils/helper.ts +133 -0
- package/src/utils/i18n.ts +204 -0
- package/{build/utils/index.d.ts → src/utils/index.ts} +3 -3
- package/build/__generated__/global-types.d.ts +0 -632
- package/build/analytics/analytics.d.ts +0 -37
- package/build/analytics/events.d.ts +0 -36
- package/build/analytics/facebookPixel.d.ts +0 -15
- package/build/analytics/googleTagManager.d.ts +0 -201
- package/build/analytics/head/index.d.ts +0 -7
- package/build/analytics/ikas.d.ts +0 -133
- package/build/api/apollo.d.ts +0 -10
- package/build/api/back-in-stock-reminder/__generated__/listProductBackInStockRemind.d.ts +0 -24
- package/build/api/back-in-stock-reminder/__generated__/saveProductBackInStockRemind.d.ts +0 -19
- package/build/api/back-in-stock-reminder/index.d.ts +0 -23
- package/build/api/blog/__generated__/getBlog.d.ts +0 -106
- package/build/api/blog/__generated__/listBlog.d.ts +0 -109
- package/build/api/blog/__generated__/listBlogCategory.d.ts +0 -61
- package/build/api/blog/__generated__/listBlogMetaData.d.ts +0 -53
- package/build/api/blog/index.d.ts +0 -32
- package/build/api/brand/__generated__/listProductBrand.d.ts +0 -88
- package/build/api/brand/index.d.ts +0 -16
- package/build/api/cart/__generated__/getCart.d.ts +0 -176
- package/build/api/cart/__generated__/saveItemToCart.d.ts +0 -185
- package/build/api/cart/index.d.ts +0 -5
- package/build/api/category/__generated__/listCategory.d.ts +0 -99
- package/build/api/category/__generated__/listCategoryPaths.d.ts +0 -32
- package/build/api/category/index.d.ts +0 -18
- package/build/api/checkout/__generated__/addCouponCodeToCheckout.d.ts +0 -11
- package/build/api/checkout/__generated__/checkStocks.d.ts +0 -18
- package/build/api/checkout/__generated__/createSaleTransactionWithCheckout.d.ts +0 -22
- package/build/api/checkout/__generated__/getCheckoutByCartId.d.ts +0 -10
- package/build/api/checkout/__generated__/getCheckoutById.d.ts +0 -572
- package/build/api/checkout/__generated__/getOrder.d.ts +0 -614
- package/build/api/checkout/__generated__/listCheckoutSettings.d.ts +0 -34
- package/build/api/checkout/__generated__/listPaymentGateway.d.ts +0 -42
- package/build/api/checkout/__generated__/retrieveInstallmentInfo.d.ts +0 -23
- package/build/api/checkout/__generated__/saveCheckout.d.ts +0 -11
- package/build/api/checkout/index.d.ts +0 -29
- package/build/api/city/__generated__/listCity.d.ts +0 -20
- package/build/api/city/index.d.ts +0 -4
- package/build/api/contact-form/__generated__/sendContactFormToMerchant.d.ts +0 -9
- package/build/api/contact-form/index.d.ts +0 -10
- package/build/api/country/__generated__/getAvailableShippingCountries.d.ts +0 -6
- package/build/api/country/__generated__/getMyCountry.d.ts +0 -3
- package/build/api/country/__generated__/listCountry.d.ts +0 -41
- package/build/api/country/index.d.ts +0 -6
- package/build/api/customer/__generated__/checkCustomerEmail.d.ts +0 -10
- package/build/api/customer/__generated__/createCustomerEmailSubscription.d.ts +0 -11
- package/build/api/customer/__generated__/createOrderRefundRequest.d.ts +0 -584
- package/build/api/customer/__generated__/customerForgotPassword.d.ts +0 -7
- package/build/api/customer/__generated__/customerLogin.d.ts +0 -162
- package/build/api/customer/__generated__/customerRecoverPassword.d.ts +0 -8
- package/build/api/customer/__generated__/customerRefreshToken.d.ts +0 -11
- package/build/api/customer/__generated__/customerSocialLogin.d.ts +0 -161
- package/build/api/customer/__generated__/getCustomerOrders.d.ts +0 -614
- package/build/api/customer/__generated__/getLastViewedProducts.d.ts +0 -15
- package/build/api/customer/__generated__/getMyCustomer.d.ts +0 -140
- package/build/api/customer/__generated__/listOrderRefundSettings.d.ts +0 -13
- package/build/api/customer/__generated__/listOrderTransactions.d.ts +0 -53
- package/build/api/customer/__generated__/registerCustomer.d.ts +0 -158
- package/build/api/customer/__generated__/saveLastViewedProducts.d.ts +0 -11
- package/build/api/customer/__generated__/saveMyCustomer.d.ts +0 -155
- package/build/api/customer/index.d.ts +0 -49
- package/build/api/customer-review/__generated__/createCustomerReview.d.ts +0 -11
- package/build/api/customer-review/__generated__/listCustomerReviews.d.ts +0 -48
- package/build/api/customer-review/index.d.ts +0 -24
- package/build/api/district/__generated__/listDistrict.d.ts +0 -16
- package/build/api/district/index.d.ts +0 -4
- package/build/api/favorite-product/__generated__/isFavoriteProduct.d.ts +0 -6
- package/build/api/favorite-product/__generated__/listFavoriteProducts.d.ts +0 -12
- package/build/api/favorite-product/__generated__/saveFavoriteProduct.d.ts +0 -7
- package/build/api/favorite-product/index.d.ts +0 -6
- package/build/api/html-meta-data/__generated__/listHTMLMetaData.d.ts +0 -28
- package/build/api/html-meta-data/index.d.ts +0 -4
- package/build/api/index.d.ts +0 -21
- package/build/api/merchant/__generated__/listMerchantSettings.d.ts +0 -9
- package/build/api/merchant/index.d.ts +0 -4
- package/build/api/product-attribute/__generated__/listProductAttribute.d.ts +0 -72
- package/build/api/product-attribute/index.d.ts +0 -4
- package/build/api/product-option-set/__generated__/ListProductOptionSet.d.ts +0 -90
- package/build/api/product-option-set/index.d.ts +0 -6
- package/build/api/product-search/__generated__/getProductFilterData.d.ts +0 -61
- package/build/api/product-search/__generated__/searchProducts.d.ts +0 -26
- package/build/api/product-search/index.d.ts +0 -20
- package/build/api/state/__generated__/listState.d.ts +0 -19
- package/build/api/state/index.d.ts +0 -4
- package/build/api/stock-location/__generated__/listStockLocation.d.ts +0 -7
- package/build/api/stock-location/index.d.ts +0 -4
- package/build/api/storefront/__generated__/getStorefront.d.ts +0 -52
- package/build/api/storefront/index.d.ts +0 -4
- package/build/api/variant-type/__generated__/listVariantType.d.ts +0 -72
- package/build/api/variant-type/index.d.ts +0 -4
- package/build/components/checkout/components/address-form/index.d.ts +0 -3
- package/build/components/checkout/components/address-form/model.d.ts +0 -131
- package/build/components/checkout/components/button/index.d.ts +0 -12
- package/build/components/checkout/components/cart-summary/cart-item/index.d.ts +0 -10
- package/build/components/checkout/components/cart-summary/index.d.ts +0 -8
- package/build/components/checkout/components/checkbox/check.d.ts +0 -6
- package/build/components/checkout/components/checkbox/index.d.ts +0 -10
- package/build/components/checkout/components/credit-card-form/index.d.ts +0 -7
- package/build/components/checkout/components/credit-card-form/model.d.ts +0 -26
- package/build/components/checkout/components/credit-card-form/svg/amex.d.ts +0 -6
- package/build/components/checkout/components/credit-card-form/svg/master-card.d.ts +0 -6
- package/build/components/checkout/components/credit-card-form/svg/troy.d.ts +0 -6
- package/build/components/checkout/components/credit-card-form/svg/visa.d.ts +0 -6
- package/build/components/checkout/components/customer-addresses/index.d.ts +0 -15
- package/build/components/checkout/components/customer-addresses/model.d.ts +0 -21
- package/build/components/checkout/components/error/customer-login-required-error/index.d.ts +0 -8
- package/build/components/checkout/components/error/index.d.ts +0 -7
- package/build/components/checkout/components/error/no-shipping-error/index.d.ts +0 -6
- package/build/components/checkout/components/error/payment-error/index.d.ts +0 -8
- package/build/components/checkout/components/error/stock-error/index.d.ts +0 -8
- package/build/components/checkout/components/error/unknown-error/index.d.ts +0 -6
- package/build/components/checkout/components/expandable-section/index.d.ts +0 -6
- package/build/components/checkout/components/form-item/caret-down.d.ts +0 -6
- package/build/components/checkout/components/form-item/index.d.ts +0 -3
- package/build/components/checkout/components/form-item/model.d.ts +0 -59
- package/build/components/checkout/components/fullscreen-loading/index.d.ts +0 -2
- package/build/components/checkout/components/input-with-button/index.d.ts +0 -11
- package/build/components/checkout/components/modal/index.d.ts +0 -8
- package/build/components/checkout/components/notification-box/index.d.ts +0 -9
- package/build/components/checkout/components/select-box/index.d.ts +0 -13
- package/build/components/checkout/components/step-container/index.d.ts +0 -15
- package/build/components/checkout/components/svg/arrow-down.d.ts +0 -6
- package/build/components/checkout/components/svg/arrow-left.d.ts +0 -6
- package/build/components/checkout/components/svg/arrow-right.d.ts +0 -6
- package/build/components/checkout/components/svg/cross.d.ts +0 -6
- package/build/components/checkout/components/svg/discount.d.ts +0 -6
- package/build/components/checkout/components/svg/external.d.ts +0 -6
- package/build/components/checkout/components/svg/gift.d.ts +0 -7
- package/build/components/checkout/components/svg/ikas.d.ts +0 -6
- package/build/components/checkout/components/svg/lock.d.ts +0 -6
- package/build/components/checkout/components/svg/shopping-cart.d.ts +0 -6
- package/build/components/checkout/components/svg/success-circle.d.ts +0 -6
- package/build/components/checkout/components/svg/tag.d.ts +0 -6
- package/build/components/checkout/components/svg/warning.d.ts +0 -6
- package/build/components/checkout/components/toggle/index.d.ts +0 -10
- package/build/components/checkout/components/tooltip/index.d.ts +0 -8
- package/build/components/checkout/index.d.ts +0 -32
- package/build/components/checkout/model.d.ts +0 -122
- package/build/components/checkout/steps/step-info/index.d.ts +0 -7
- package/build/components/checkout/steps/step-payment/billing-address/index.d.ts +0 -7
- package/build/components/checkout/steps/step-payment/index.d.ts +0 -7
- package/build/components/checkout/steps/step-payment/payment-gateways/index.d.ts +0 -7
- package/build/components/checkout/steps/step-payment/payment-gateways/installments/index.d.ts +0 -7
- package/build/components/checkout/steps/step-shipping/index.d.ts +0 -7
- package/build/components/checkout/steps/step-success/index.d.ts +0 -7
- package/build/components/error/index.d.ts +0 -5
- package/build/components/image/index.d.ts +0 -36
- package/build/components/index.d.ts +0 -4
- package/build/components/page/ThemeComponent.d.ts +0 -10
- package/build/components/page/head.d.ts +0 -12
- package/build/components/page/index.d.ts +0 -17
- package/build/components/page-editor/ThemeComponentEditor.d.ts +0 -9
- package/build/components/page-editor/index.d.ts +0 -2
- package/build/components/page-editor/model.d.ts +0 -65
- package/build/index.css +0 -1521
- package/build/index.d.ts +0 -8
- package/build/index.es.css +0 -1521
- package/build/index.es.js +0 -74627
- package/build/index.js +0 -74756
- package/build/models/data/blog/index.d.ts +0 -67
- package/build/models/data/brand/index.d.ts +0 -21
- package/build/models/data/cart/index.d.ts +0 -47
- package/build/models/data/category/index.d.ts +0 -52
- package/build/models/data/checkout/index.d.ts +0 -103
- package/build/models/data/checkout-settings/index.d.ts +0 -25
- package/build/models/data/city/index.d.ts +0 -4
- package/build/models/data/contact-form/index.d.ts +0 -7
- package/build/models/data/country/index.d.ts +0 -8
- package/build/models/data/customer/address/index.d.ts +0 -52
- package/build/models/data/customer/index.d.ts +0 -33
- package/build/models/data/customer-review/index.d.ts +0 -23
- package/build/models/data/customer-review-settings/index.d.ts +0 -4
- package/build/models/data/district/index.d.ts +0 -4
- package/build/models/data/favorite-product/index.d.ts +0 -6
- package/build/models/data/html-meta-data/index.d.ts +0 -23
- package/build/models/data/image/index.d.ts +0 -8
- package/build/models/data/index.d.ts +0 -33
- package/build/models/data/installment-info/index.d.ts +0 -30
- package/build/models/data/merchant-settings/index.d.ts +0 -8
- package/build/models/data/order/address/index.d.ts +0 -51
- package/build/models/data/order/adjustment/index.d.ts +0 -16
- package/build/models/data/order/gift-line/index.d.ts +0 -4
- package/build/models/data/order/index.d.ts +0 -146
- package/build/models/data/order/line-item/discount/index.d.ts +0 -11
- package/build/models/data/order/line-item/index.d.ts +0 -43
- package/build/models/data/order/line-item/options/index.d.ts +0 -10
- package/build/models/data/order/line-item/options/options-value/index.d.ts +0 -6
- package/build/models/data/order/line-item/variant/index.d.ts +0 -25
- package/build/models/data/order/refund/index.d.ts +0 -6
- package/build/models/data/order/refund/refund-line-item/index.d.ts +0 -5
- package/build/models/data/order/refund/settings.d.ts +0 -6
- package/build/models/data/order/shipping-line/index.d.ts +0 -7
- package/build/models/data/order-transaction/index.d.ts +0 -74
- package/build/models/data/payment-gateway/index.d.ts +0 -61
- package/build/models/data/product/attribute-value/index.d.ts +0 -20
- package/build/models/data/product/index.d.ts +0 -35
- package/build/models/data/product/variant/index.d.ts +0 -24
- package/build/models/data/product/variant/price/index.d.ts +0 -11
- package/build/models/data/product/variant-type/index.d.ts +0 -6
- package/build/models/data/product-attribute/index.d.ts +0 -34
- package/build/models/data/product-attribute/product-attribute-option/index.d.ts +0 -5
- package/build/models/data/product-attribute/product-attribute-table-cell/index.d.ts +0 -5
- package/build/models/data/product-attribute/product-attribute-table-template/index.d.ts +0 -6
- package/build/models/data/product-back-in-stock-settings/index.d.ts +0 -3
- package/build/models/data/product-cart-item-options/index.d.ts +0 -6
- package/build/models/data/product-filter/index.d.ts +0 -109
- package/build/models/data/product-option-set/index.d.ts +0 -104
- package/build/models/data/product-tag/index.d.ts +0 -5
- package/build/models/data/sales-channel/index.d.ts +0 -18
- package/build/models/data/simple-product/index.d.ts +0 -136
- package/build/models/data/state/index.d.ts +0 -5
- package/build/models/data/storefront/domain/index.d.ts +0 -8
- package/build/models/data/storefront/index.d.ts +0 -23
- package/build/models/data/storefront/localization/index.d.ts +0 -7
- package/build/models/data/storefront/routing/index.d.ts +0 -9
- package/build/models/data/storefront/theme/index.d.ts +0 -13
- package/build/models/data/storefront/theme-localization/index.d.ts +0 -12
- package/build/models/data/variant-type/index.d.ts +0 -26
- package/build/models/data/variant-type/variant-value/index.d.ts +0 -11
- package/build/models/index.d.ts +0 -3
- package/build/models/theme/component/index.d.ts +0 -10
- package/build/models/theme/component/prop/index.d.ts +0 -40
- package/build/models/theme/custom-data/index.d.ts +0 -24
- package/build/models/theme/page/component/index.d.ts +0 -6
- package/build/models/theme/page/component/prop-value/attribute-list.d.ts +0 -7
- package/build/models/theme/page/component/prop-value/attribute.d.ts +0 -7
- package/build/models/theme/page/component/prop-value/blog-category-list.d.ts +0 -7
- package/build/models/theme/page/component/prop-value/blog-category.d.ts +0 -5
- package/build/models/theme/page/component/prop-value/blog-list.d.ts +0 -9
- package/build/models/theme/page/component/prop-value/blog.d.ts +0 -5
- package/build/models/theme/page/component/prop-value/brand-list.d.ts +0 -9
- package/build/models/theme/page/component/prop-value/brand.d.ts +0 -5
- package/build/models/theme/page/component/prop-value/category-list.d.ts +0 -9
- package/build/models/theme/page/component/prop-value/category.d.ts +0 -5
- package/build/models/theme/page/component/prop-value/link.d.ts +0 -19
- package/build/models/theme/page/component/prop-value/product-detail.d.ts +0 -6
- package/build/models/theme/page/component/prop-value/product-list.d.ts +0 -17
- package/build/models/theme/page/index.d.ts +0 -40
- package/build/models/theme/settings/index.d.ts +0 -13
- package/build/models/theme/settings/prop/color/index.d.ts +0 -7
- package/build/models/theme/settings/prop/favicon/index.d.ts +0 -4
- package/build/models/theme/theme.d.ts +0 -16
- package/build/models/ui/blog-category-list/index.d.ts +0 -52
- package/build/models/ui/blog-list/index.d.ts +0 -56
- package/build/models/ui/brand-list/index.d.ts +0 -61
- package/build/models/ui/category-list/index.d.ts +0 -61
- package/build/models/ui/component-renderer/index.d.ts +0 -7
- package/build/models/ui/customer-review-list/index.d.ts +0 -43
- package/build/models/ui/index.d.ts +0 -22
- package/build/models/ui/navigation-link/index.d.ts +0 -8
- package/build/models/ui/product-attribute-detail/index.d.ts +0 -8
- package/build/models/ui/product-attribute-list/index.d.ts +0 -9
- package/build/models/ui/product-detail/index.d.ts +0 -28
- package/build/models/ui/product-list/index.d.ts +0 -132
- package/build/models/ui/validator/form/account-info.d.ts +0 -40
- package/build/models/ui/validator/form/address.d.ts +0 -75
- package/build/models/ui/validator/form/contact-form.d.ts +0 -45
- package/build/models/ui/validator/form/customer-review.d.ts +0 -37
- package/build/models/ui/validator/form/forgot-password.d.ts +0 -29
- package/build/models/ui/validator/form/login.d.ts +0 -35
- package/build/models/ui/validator/form/recover-password.d.ts +0 -36
- package/build/models/ui/validator/form/register.d.ts +0 -48
- package/build/models/ui/validator/index.d.ts +0 -27
- package/build/models/ui/validator/rules/index.d.ts +0 -87
- package/build/pages/404.d.ts +0 -6
- package/build/pages/[slug]/index.d.ts +0 -7
- package/build/pages/account/addresses.d.ts +0 -6
- package/build/pages/account/favorite-products.d.ts +0 -6
- package/build/pages/account/forgot-password.d.ts +0 -6
- package/build/pages/account/index.d.ts +0 -6
- package/build/pages/account/login.d.ts +0 -6
- package/build/pages/account/orders/[id].d.ts +0 -6
- package/build/pages/account/orders/index.d.ts +0 -6
- package/build/pages/account/recover-password.d.ts +0 -6
- package/build/pages/account/register.d.ts +0 -6
- package/build/pages/blog/[slug].d.ts +0 -7
- package/build/pages/blog/index.d.ts +0 -6
- package/build/pages/cart.d.ts +0 -6
- package/build/pages/checkout.d.ts +0 -18
- package/build/pages/editor.d.ts +0 -8
- package/build/pages/home.d.ts +0 -6
- package/build/pages/index.d.ts +0 -20
- package/build/pages/pages/[slug].d.ts +0 -7
- package/build/pages/search.d.ts +0 -6
- package/build/providers/page-data-get.d.ts +0 -61
- package/build/providers/page-data-init.d.ts +0 -58
- package/build/providers/page-data-next.d.ts +0 -243
- package/build/providers/placeholders.d.ts +0 -6
- package/build/providers/prop-value/attribute-list.d.ts +0 -12
- package/build/providers/prop-value/attribute.d.ts +0 -12
- package/build/providers/prop-value/blog-category-list.d.ts +0 -7
- package/build/providers/prop-value/blog-category.d.ts +0 -11
- package/build/providers/prop-value/blog-list.d.ts +0 -9
- package/build/providers/prop-value/blog.d.ts +0 -11
- package/build/providers/prop-value/boolean.d.ts +0 -6
- package/build/providers/prop-value/brand-list.d.ts +0 -7
- package/build/providers/prop-value/brand.d.ts +0 -11
- package/build/providers/prop-value/category-list.d.ts +0 -7
- package/build/providers/prop-value/category.d.ts +0 -11
- package/build/providers/prop-value/checkout.d.ts +0 -4
- package/build/providers/prop-value/color.d.ts +0 -6
- package/build/providers/prop-value/custom.d.ts +0 -42
- package/build/providers/prop-value/image-list.d.ts +0 -7
- package/build/providers/prop-value/image.d.ts +0 -7
- package/build/providers/prop-value/link.d.ts +0 -16
- package/build/providers/prop-value/product-detail.d.ts +0 -11
- package/build/providers/prop-value/product-list.d.ts +0 -9
- package/build/providers/prop-value/rich-text.d.ts +0 -6
- package/build/providers/prop-value/text.d.ts +0 -6
- package/build/store/base.d.ts +0 -25
- package/build/store/cart.d.ts +0 -30
- package/build/store/customer.d.ts +0 -91
- package/build/storefront/index.d.ts +0 -55
- package/build/utils/currency.d.ts +0 -7
- package/build/utils/helper.d.ts +0 -8
- package/build/utils/i18n.d.ts +0 -20
|
@@ -0,0 +1,1007 @@
|
|
|
1
|
+
import { makeAutoObservable } from "mobx";
|
|
2
|
+
import { NextRouter } from "next/router";
|
|
3
|
+
import _cloneDeep from "lodash/cloneDeep";
|
|
4
|
+
import _sortBy from "lodash/sortBy";
|
|
5
|
+
import { v4 as uuidv4 } from "uuid";
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
IkasCheckout,
|
|
9
|
+
IkasInstallmentInfo,
|
|
10
|
+
IkasInstallmentInfoInput,
|
|
11
|
+
IkasCustomerAddress,
|
|
12
|
+
IkasMerchantSettings,
|
|
13
|
+
IkasAvailableShippingMethod,
|
|
14
|
+
IkasTransactionStatusEnum,
|
|
15
|
+
IkasOrderLineItem,
|
|
16
|
+
IkasOrderTransaction,
|
|
17
|
+
IkasOrder,
|
|
18
|
+
IkasCheckoutCustomer,
|
|
19
|
+
} from "../../models";
|
|
20
|
+
import { IkasOrderAddress } from "../../models/data/order/address";
|
|
21
|
+
import {
|
|
22
|
+
IkasPaymentGateway,
|
|
23
|
+
IkasPaymentGatewayType,
|
|
24
|
+
IkasPaymentMethodType,
|
|
25
|
+
} from "../../models/data/payment-gateway";
|
|
26
|
+
import { IkasOrderLineVariant } from "../../models/data/order/line-item/variant";
|
|
27
|
+
import { IkasStorefront } from "../../models/data/storefront";
|
|
28
|
+
import { IkasCheckoutAPI, IkasCountryAPI, IkasCustomerAPI } from "../../api";
|
|
29
|
+
import { IkasMerchantAPI } from "../../api";
|
|
30
|
+
import CreditCardData from "./components/credit-card-form/model";
|
|
31
|
+
import { IkasStorefrontConfig } from "../../storefront";
|
|
32
|
+
import { IkasCheckoutSettings } from "../../models/data/checkout-settings";
|
|
33
|
+
import { TFunction } from "../../utils/i18n";
|
|
34
|
+
import { Analytics } from "../../analytics";
|
|
35
|
+
|
|
36
|
+
const NUMBER_ONLY_REGEX = /^\d+$/;
|
|
37
|
+
const MAX_CARD_NUMBER_LENGTH = 16;
|
|
38
|
+
const MAX_CVC_LENGTH = 4;
|
|
39
|
+
const USE_DIFFERENT_ADDRESS_KEY = "sAddr";
|
|
40
|
+
const isServer = typeof localStorage === "undefined";
|
|
41
|
+
|
|
42
|
+
export default class CheckoutViewModel {
|
|
43
|
+
checkout = new IkasCheckout();
|
|
44
|
+
checkoutSettings = new IkasCheckoutSettings();
|
|
45
|
+
storefront?: IkasStorefront | null = null;
|
|
46
|
+
store = IkasStorefrontConfig.store;
|
|
47
|
+
router: NextRouter;
|
|
48
|
+
isCheckoutLoaded = false;
|
|
49
|
+
isErrorsVisible = false;
|
|
50
|
+
isStepLoading = false;
|
|
51
|
+
isTermsAndConditionsChecked = false;
|
|
52
|
+
isChangingShippingMethod = false;
|
|
53
|
+
step: CheckoutStep = CheckoutStep.INFO;
|
|
54
|
+
|
|
55
|
+
merchantSettings?: IkasMerchantSettings;
|
|
56
|
+
cardData?: CreditCardData | null = null;
|
|
57
|
+
paymentGateways: IkasPaymentGateway[] = [];
|
|
58
|
+
installmentInfo?: IkasInstallmentInfo | null = null;
|
|
59
|
+
useDifferentAddress = false;
|
|
60
|
+
shouldSaveAddress = false;
|
|
61
|
+
addressTitle = "";
|
|
62
|
+
|
|
63
|
+
shippingCountryIds?: string[] | null = null;
|
|
64
|
+
selectedShippingAddressId?: string = "-1";
|
|
65
|
+
selectedBillingAddressId?: string = "-1";
|
|
66
|
+
|
|
67
|
+
returnPolicy: string;
|
|
68
|
+
privacyPolicy: string;
|
|
69
|
+
termsOfService: string;
|
|
70
|
+
|
|
71
|
+
policyModalTitle = "";
|
|
72
|
+
policyModalText = "";
|
|
73
|
+
|
|
74
|
+
error?: CheckoutError | null = null;
|
|
75
|
+
|
|
76
|
+
// For success step
|
|
77
|
+
order?: IkasOrder;
|
|
78
|
+
successTransaction?: IkasOrderTransaction;
|
|
79
|
+
|
|
80
|
+
t: TFunction;
|
|
81
|
+
|
|
82
|
+
constructor(
|
|
83
|
+
checkout: IkasCheckout,
|
|
84
|
+
checkoutSettings: IkasCheckoutSettings,
|
|
85
|
+
merchantSettings: IkasMerchantSettings | null,
|
|
86
|
+
router: NextRouter,
|
|
87
|
+
returnPolicy: string,
|
|
88
|
+
privacyPolicy: string,
|
|
89
|
+
termsOfService: string,
|
|
90
|
+
t: TFunction
|
|
91
|
+
) {
|
|
92
|
+
this.checkout = checkout;
|
|
93
|
+
this.checkoutSettings = checkoutSettings;
|
|
94
|
+
this.router = router;
|
|
95
|
+
this.returnPolicy = returnPolicy;
|
|
96
|
+
this.privacyPolicy = privacyPolicy;
|
|
97
|
+
this.termsOfService = termsOfService;
|
|
98
|
+
this.t = t;
|
|
99
|
+
|
|
100
|
+
if (merchantSettings) this.merchantSettings = merchantSettings;
|
|
101
|
+
|
|
102
|
+
this.isTermsAndConditionsChecked = this.checkoutSettings.isTermsAndConditionsDefaultChecked;
|
|
103
|
+
this.store.cartStore.cart = this.checkout.cart;
|
|
104
|
+
|
|
105
|
+
this.init();
|
|
106
|
+
makeAutoObservable(this);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
init = async () => {
|
|
110
|
+
await this.store.customerStore.waitUntilInitialized();
|
|
111
|
+
this.createCustomer();
|
|
112
|
+
this.createShippingAddress();
|
|
113
|
+
this.createBillingAddress();
|
|
114
|
+
await this.getMerchantSettings();
|
|
115
|
+
await this.initStep();
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
initStep = async () => {
|
|
119
|
+
if (IkasStorefrontConfig.isEditor) {
|
|
120
|
+
this.step = CheckoutStep.INFO;
|
|
121
|
+
this.isCheckoutLoaded = true;
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const queryParams = new URLSearchParams(window.location.search);
|
|
126
|
+
const queryStep = queryParams.get("step");
|
|
127
|
+
const queryFailed = queryParams.get("failed");
|
|
128
|
+
const queryError = queryParams.get("error");
|
|
129
|
+
|
|
130
|
+
if (queryStep) {
|
|
131
|
+
this.step = queryStep as CheckoutStep;
|
|
132
|
+
|
|
133
|
+
if (this.step === CheckoutStep.SHIPPING && !this.canProceedToShipping) {
|
|
134
|
+
return this.changeStep(CheckoutStep.INFO);
|
|
135
|
+
} else if (
|
|
136
|
+
this.step === CheckoutStep.PAYMENT &&
|
|
137
|
+
!this.canProceedToPayment
|
|
138
|
+
) {
|
|
139
|
+
return this.changeStep(CheckoutStep.INFO);
|
|
140
|
+
} else if (
|
|
141
|
+
![
|
|
142
|
+
CheckoutStep.INFO,
|
|
143
|
+
CheckoutStep.SUCCESS,
|
|
144
|
+
CheckoutStep.SHIPPING,
|
|
145
|
+
CheckoutStep.PAYMENT,
|
|
146
|
+
].includes(this.step)
|
|
147
|
+
) {
|
|
148
|
+
return this.changeStep(CheckoutStep.INFO);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (queryFailed) {
|
|
153
|
+
this.error = {
|
|
154
|
+
type: ErrorType.PAYMENT_ERROR,
|
|
155
|
+
data: queryError || null,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (this.step === CheckoutStep.INFO) {
|
|
160
|
+
await this.getShippingCountries();
|
|
161
|
+
this.checkShippingCountries();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Skip shipping if there is only 1 shipping method
|
|
165
|
+
if (
|
|
166
|
+
this.step === CheckoutStep.SHIPPING &&
|
|
167
|
+
this.checkout.availableShippingMethods.length === 1 &&
|
|
168
|
+
!this.checkoutSettings.isGiftPackageEnabled
|
|
169
|
+
) {
|
|
170
|
+
this.step = CheckoutStep.PAYMENT;
|
|
171
|
+
this.router.replace(
|
|
172
|
+
`/checkout?id=${this.checkout.id}&step=${this.step}`,
|
|
173
|
+
undefined,
|
|
174
|
+
{
|
|
175
|
+
shallow: true,
|
|
176
|
+
}
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Check if there are available shipping methods for the shipping address
|
|
181
|
+
if (
|
|
182
|
+
this.step === CheckoutStep.SHIPPING &&
|
|
183
|
+
!this.checkout.availableShippingMethods.length
|
|
184
|
+
) {
|
|
185
|
+
this.error = {
|
|
186
|
+
type: ErrorType.NO_SHIPPING_ERROR,
|
|
187
|
+
};
|
|
188
|
+
this.isCheckoutLoaded = true;
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (
|
|
193
|
+
this.step === CheckoutStep.PAYMENT ||
|
|
194
|
+
this.step === CheckoutStep.SUCCESS
|
|
195
|
+
) {
|
|
196
|
+
await this.listPaymentGateways();
|
|
197
|
+
|
|
198
|
+
if (!this.paymentGateways.length) {
|
|
199
|
+
this.error = {
|
|
200
|
+
type: ErrorType.NO_SHIPPING_ERROR,
|
|
201
|
+
};
|
|
202
|
+
this.isCheckoutLoaded = true;
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (this.step !== CheckoutStep.SUCCESS) {
|
|
208
|
+
if (this.checkout.isComplete) {
|
|
209
|
+
return this.changeStep(CheckoutStep.SUCCESS);
|
|
210
|
+
} else {
|
|
211
|
+
await this.initialStockCheck();
|
|
212
|
+
}
|
|
213
|
+
} else {
|
|
214
|
+
this.order = await IkasCheckoutAPI.getOrder(this.checkout.orderId!);
|
|
215
|
+
|
|
216
|
+
const transactions = await IkasCustomerAPI.getOrderTransactions({
|
|
217
|
+
orderId: this.checkout.orderId!,
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
this.successTransaction = transactions.length
|
|
221
|
+
? transactions[0]
|
|
222
|
+
: undefined;
|
|
223
|
+
|
|
224
|
+
if (this.successTransaction) {
|
|
225
|
+
const paymentGatewayId = this.successTransaction.paymentGatewayId;
|
|
226
|
+
this.checkout.selectedPaymentGateway = this.paymentGateways.find(
|
|
227
|
+
(pg) => pg.id === paymentGatewayId
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
this.isCheckoutLoaded = true;
|
|
233
|
+
Analytics.checkoutStep(this.checkout, this.step);
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
getMerchantSettings = async () => {
|
|
237
|
+
if (!this.merchantSettings) {
|
|
238
|
+
this.merchantSettings = await IkasMerchantAPI.listMerchantSettings();
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
get cart() {
|
|
243
|
+
return this.checkout.cart;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
get selectedPaymentGatewayIndex() {
|
|
247
|
+
return this.paymentGateways.findIndex(
|
|
248
|
+
(pg) => pg.id === this.checkout.selectedPaymentGateway?.id
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
get selectedInstallmentIndex() {
|
|
253
|
+
return (
|
|
254
|
+
this.installmentInfo?.installmentPrices.findIndex(
|
|
255
|
+
(ip) => ip.installmentCount === this.cardData?.installmentCount
|
|
256
|
+
) || 0
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
get checkoutUrl() {
|
|
261
|
+
return `/checkout?id=${this.checkout.id}&step=info`;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
get customerAddressOptions() {
|
|
265
|
+
const defaultOption = {
|
|
266
|
+
label: this.t("checkout-page:newAddress"),
|
|
267
|
+
value: "-1",
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
const addressOptions =
|
|
271
|
+
this.store.customerStore.customer?.addresses.map((a) => ({
|
|
272
|
+
label: a.title + " - " + a.addressText,
|
|
273
|
+
value: a.id!,
|
|
274
|
+
})) || [];
|
|
275
|
+
|
|
276
|
+
return [defaultOption].concat(addressOptions);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
get installmentPrice() {
|
|
280
|
+
if (this.installmentInfo && this.cardData?.installmentCount) {
|
|
281
|
+
return this.installmentInfo.installmentPrices.find(
|
|
282
|
+
(ip) => ip.installmentCount === this.cardData?.installmentCount
|
|
283
|
+
)?.totalPrice;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
get installmentExtraPrice() {
|
|
288
|
+
if (this.installmentPrice && this.checkout.totalFinalPrice) {
|
|
289
|
+
return this.installmentPrice - this.checkout.totalFinalPrice;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
get finalPrice() {
|
|
294
|
+
if (this.step === CheckoutStep.SUCCESS)
|
|
295
|
+
return this.checkout.totalFinalPrice!;
|
|
296
|
+
return this.installmentPrice || this.checkout.$totalFinalPrice;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
get hasStockError() {
|
|
300
|
+
return this.error?.type === ErrorType.STOCK_ERROR;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// VALIDATIONS
|
|
304
|
+
|
|
305
|
+
get canProceedToShipping() {
|
|
306
|
+
return (
|
|
307
|
+
this.checkout.shippingAddress?.isValid &&
|
|
308
|
+
this.checkout.hasValidCustomer &&
|
|
309
|
+
this.error?.type !== ErrorType.NO_SHIPPING_ERROR
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
get canProceedToPayment() {
|
|
314
|
+
// TODO might add something here later not sure
|
|
315
|
+
return this.canProceedToShipping;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
get canPerformPayment() {
|
|
319
|
+
if (
|
|
320
|
+
this.checkoutSettings.showTermsAndConditionsCheckbox &&
|
|
321
|
+
!this.isTermsAndConditionsChecked
|
|
322
|
+
)
|
|
323
|
+
return false;
|
|
324
|
+
|
|
325
|
+
const pg = this.checkout.selectedPaymentGateway;
|
|
326
|
+
return (
|
|
327
|
+
this.canProceedToShipping &&
|
|
328
|
+
!!this.checkout.billingAddress?.isValid &&
|
|
329
|
+
(pg?.paymentMethodType === IkasPaymentMethodType.CREDIT_CARD &&
|
|
330
|
+
pg.type === IkasPaymentGatewayType.INTERNAL
|
|
331
|
+
? this.cardData?.isValid
|
|
332
|
+
: true)
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// VALIDATIONS END
|
|
337
|
+
|
|
338
|
+
saveCheckout = async () => {
|
|
339
|
+
const response = await IkasCheckoutAPI.saveCheckout(this.checkout);
|
|
340
|
+
|
|
341
|
+
if (response?.errors && response.errors.length) {
|
|
342
|
+
const firstError = response.errors[0];
|
|
343
|
+
|
|
344
|
+
if (firstError.extensions?.code === "CUSTOMER_LOGIN_REQUIRED") {
|
|
345
|
+
throw {
|
|
346
|
+
type: ErrorType.CUSTOMER_LOGIN_REQUIRED_ERROR,
|
|
347
|
+
};
|
|
348
|
+
} else {
|
|
349
|
+
throw {
|
|
350
|
+
type: ErrorType.API_ERROR,
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
checkStocks = async () => {
|
|
357
|
+
const lines = this.cart!.items.map((i) => ({
|
|
358
|
+
quantity: i.quantity,
|
|
359
|
+
variantId: i.variant.id,
|
|
360
|
+
productId: i.variant.productId,
|
|
361
|
+
}));
|
|
362
|
+
|
|
363
|
+
const result = await IkasCheckoutAPI.checkStocks(
|
|
364
|
+
lines,
|
|
365
|
+
IkasStorefrontConfig.stockLocationIds || []
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
if (!result) {
|
|
369
|
+
throw {
|
|
370
|
+
type: ErrorType.API_ERROR,
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const unavailableItems = result.lines?.filter((i) => !i.isAvailable);
|
|
375
|
+
if (unavailableItems?.length) {
|
|
376
|
+
const _unavailableItems: IkasOrderLineItem[] = [];
|
|
377
|
+
|
|
378
|
+
for (const item of unavailableItems) {
|
|
379
|
+
const cartItem = this.store.cartStore.cart?.items.find(
|
|
380
|
+
(i) => i.variant.id === item.variantId
|
|
381
|
+
);
|
|
382
|
+
if (cartItem) _unavailableItems.push(cartItem);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
throw {
|
|
386
|
+
type: ErrorType.STOCK_ERROR,
|
|
387
|
+
data: _unavailableItems,
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
removeUnavailableItems = async (items: IkasOrderLineItem[]) => {
|
|
393
|
+
for (const item of items) {
|
|
394
|
+
await this.store.cartStore.removeItem(item);
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
getShippingCountries = async () => {
|
|
399
|
+
this.shippingCountryIds = await IkasCountryAPI.listShippingCountries(
|
|
400
|
+
IkasStorefrontConfig.salesChannelId!
|
|
401
|
+
);
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
checkShippingCountries = () => {
|
|
405
|
+
if (!this.shippingCountryIds?.length) {
|
|
406
|
+
this.error = {
|
|
407
|
+
type: ErrorType.NO_SHIPPING_ERROR,
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
initialStockCheck = async () => {
|
|
413
|
+
try {
|
|
414
|
+
await this.checkStocks();
|
|
415
|
+
} catch (err) {
|
|
416
|
+
if (err.type) {
|
|
417
|
+
this.error = err;
|
|
418
|
+
} else {
|
|
419
|
+
console.log(err);
|
|
420
|
+
this.error = {
|
|
421
|
+
type: ErrorType.UNKNOWN,
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
listPaymentGateways = async () => {
|
|
428
|
+
const isLocal = process.env.NEXT_PUBLIC_ENV === "local";
|
|
429
|
+
const idList = IkasStorefrontConfig.paymentGateways.map((pg) => pg.id);
|
|
430
|
+
let paymentGateways = await IkasCheckoutAPI.listPaymentGateway(
|
|
431
|
+
isLocal ? undefined : idList
|
|
432
|
+
);
|
|
433
|
+
|
|
434
|
+
if (!paymentGateways || !paymentGateways.length) {
|
|
435
|
+
this.error = {
|
|
436
|
+
type: ErrorType.API_ERROR,
|
|
437
|
+
};
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
if (this.step === CheckoutStep.PAYMENT) {
|
|
442
|
+
paymentGateways = paymentGateways.filter((pg) =>
|
|
443
|
+
pg.supportedCurrencies.length
|
|
444
|
+
? pg.supportedCurrencies.includes(this.checkout.cart!.currencyCode)
|
|
445
|
+
: true
|
|
446
|
+
);
|
|
447
|
+
|
|
448
|
+
const shippingCountry = this.checkout.shippingAddress?.country;
|
|
449
|
+
if (shippingCountry) {
|
|
450
|
+
paymentGateways = paymentGateways.filter((pg) =>
|
|
451
|
+
pg.availableCountries.length
|
|
452
|
+
? pg.availableCountries.includes(shippingCountry.iso2 || "")
|
|
453
|
+
: true
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
const orderedPaymentGateways: IkasPaymentGateway[] = [];
|
|
459
|
+
|
|
460
|
+
_sortBy(IkasStorefrontConfig.paymentGateways, "order").forEach((pg) => {
|
|
461
|
+
const _pg = paymentGateways?.find((p) => p.id === pg.id);
|
|
462
|
+
if (_pg) orderedPaymentGateways.push(_pg);
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
this.paymentGateways = isLocal ? paymentGateways : orderedPaymentGateways;
|
|
466
|
+
if (!this.checkout.selectedPaymentGateway) this.setPaymentGateway(0);
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
retrieveInstallmentInfo = async (input: IkasInstallmentInfoInput) => {
|
|
470
|
+
const installmentInfo = await IkasCheckoutAPI.retrieveInstallmentInfo(
|
|
471
|
+
input
|
|
472
|
+
);
|
|
473
|
+
installmentInfo?.installmentPrices.sort((a, b) =>
|
|
474
|
+
(a.installmentCount || -1) > (b.installmentCount || -1) ? 1 : -1
|
|
475
|
+
);
|
|
476
|
+
this.installmentInfo = installmentInfo;
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
createCustomer = () => {
|
|
480
|
+
if (this.store.customerStore.customer) {
|
|
481
|
+
this.store.customerStore.customer.addresses.forEach(
|
|
482
|
+
(address) => (address.checkoutSettings = this.checkoutSettings)
|
|
483
|
+
);
|
|
484
|
+
this.checkout.customer = new IkasCheckoutCustomer(
|
|
485
|
+
this.store.customerStore.customer
|
|
486
|
+
);
|
|
487
|
+
} else if (!this.checkout.customer)
|
|
488
|
+
this.checkout.customer = new IkasCheckoutCustomer({});
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
createShippingAddress = () => {
|
|
492
|
+
if (!this.checkout.shippingAddress) {
|
|
493
|
+
const customerAddresses = this.store.customerStore.customer?.addresses;
|
|
494
|
+
this.onSelectedShippingAddressIdChange(
|
|
495
|
+
customerAddresses?.length ? customerAddresses[0].id! : "-1"
|
|
496
|
+
);
|
|
497
|
+
} else {
|
|
498
|
+
this.selectedShippingAddressId = this.checkout.shippingAddress.id || "-1";
|
|
499
|
+
this.checkout.shippingAddress.checkoutSettings = this.checkoutSettings;
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
createBillingAddress = () => {
|
|
504
|
+
if (typeof localStorage !== "undefined") {
|
|
505
|
+
this.useDifferentAddress = !!localStorage.getItem(
|
|
506
|
+
USE_DIFFERENT_ADDRESS_KEY
|
|
507
|
+
);
|
|
508
|
+
|
|
509
|
+
if (this.useDifferentAddress) {
|
|
510
|
+
if (this.checkout.billingAddress) {
|
|
511
|
+
this.selectedBillingAddressId =
|
|
512
|
+
this.checkout.billingAddress.id || "-1";
|
|
513
|
+
}
|
|
514
|
+
this.checkout.billingAddress =
|
|
515
|
+
this.checkout.billingAddress || new IkasOrderAddress();
|
|
516
|
+
} else {
|
|
517
|
+
this.checkout.billingAddress = new IkasOrderAddress(
|
|
518
|
+
_cloneDeep(this.checkout.shippingAddress) || {}
|
|
519
|
+
);
|
|
520
|
+
}
|
|
521
|
+
this.checkout.billingAddress.checkoutSettings = this.checkoutSettings;
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
onShippingMethodChange = async (
|
|
526
|
+
shippingMethod: IkasAvailableShippingMethod
|
|
527
|
+
) => {
|
|
528
|
+
if (this.isChangingShippingMethod) return;
|
|
529
|
+
|
|
530
|
+
this.isChangingShippingMethod = true;
|
|
531
|
+
this.checkout.shippingSettingsId = shippingMethod.shippingSettingsId;
|
|
532
|
+
this.checkout.shippingZoneRateId = shippingMethod.shippingZoneRateId;
|
|
533
|
+
await this.saveCheckout();
|
|
534
|
+
const newCheckout = await IkasCheckoutAPI.getCheckoutById(
|
|
535
|
+
this.checkout.id!
|
|
536
|
+
);
|
|
537
|
+
if (newCheckout) this.checkout = newCheckout;
|
|
538
|
+
this.isChangingShippingMethod = false;
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
onCouponCodeApply = async () => {
|
|
542
|
+
if (!this.checkout.couponCode) return;
|
|
543
|
+
|
|
544
|
+
try {
|
|
545
|
+
const isCouponSaveSuccess = await IkasCheckoutAPI.addCouponCodeToCheckout(
|
|
546
|
+
this.checkout.id!,
|
|
547
|
+
this.checkout.couponCode
|
|
548
|
+
);
|
|
549
|
+
|
|
550
|
+
if (isCouponSaveSuccess) {
|
|
551
|
+
const newCheckout = await IkasCheckoutAPI.getCheckoutById(
|
|
552
|
+
this.checkout.id!
|
|
553
|
+
);
|
|
554
|
+
|
|
555
|
+
if (newCheckout) {
|
|
556
|
+
const oldCheckout = this.checkout;
|
|
557
|
+
|
|
558
|
+
this.checkout = new IkasCheckout({
|
|
559
|
+
...newCheckout,
|
|
560
|
+
shippingAddress: oldCheckout.shippingAddress,
|
|
561
|
+
billingAddress: oldCheckout.billingAddress,
|
|
562
|
+
customer: oldCheckout.customer,
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
} catch (err) {}
|
|
567
|
+
};
|
|
568
|
+
|
|
569
|
+
onCouponCodeDelete = async () => {
|
|
570
|
+
try {
|
|
571
|
+
await this.saveCheckout();
|
|
572
|
+
const newCheckout = await IkasCheckoutAPI.getCheckoutById(
|
|
573
|
+
this.checkout.id!
|
|
574
|
+
);
|
|
575
|
+
if (newCheckout) this.checkout = newCheckout;
|
|
576
|
+
} catch {}
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
onSelectedShippingAddressIdChange = (value: string) => {
|
|
580
|
+
this.selectedShippingAddressId = value;
|
|
581
|
+
if (value === "-1") {
|
|
582
|
+
this.checkout.shippingAddress = new IkasOrderAddress();
|
|
583
|
+
} else {
|
|
584
|
+
const address = this.store.customerStore.customer?.addresses.find(
|
|
585
|
+
(a) => a.id === value
|
|
586
|
+
);
|
|
587
|
+
if (address)
|
|
588
|
+
this.checkout.shippingAddress = new IkasOrderAddress(address as any);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
if (this.checkout.shippingAddress)
|
|
592
|
+
this.checkout.shippingAddress.checkoutSettings = this.checkoutSettings;
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
onSelectedBillingAddressIdChange = (value: string) => {
|
|
596
|
+
this.selectedBillingAddressId = value;
|
|
597
|
+
if (value === "-1") {
|
|
598
|
+
this.checkout.billingAddress = new IkasOrderAddress();
|
|
599
|
+
} else {
|
|
600
|
+
const address = this.store.customerStore.customer?.addresses.find(
|
|
601
|
+
(a) => a.id === value
|
|
602
|
+
);
|
|
603
|
+
if (address)
|
|
604
|
+
this.checkout.billingAddress = new IkasOrderAddress(address as any);
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
if (this.checkout.billingAddress)
|
|
608
|
+
this.checkout.billingAddress.checkoutSettings = this.checkoutSettings;
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
onTermsAndConditionsCheckedChange = (value: boolean) => {
|
|
612
|
+
this.isTermsAndConditionsChecked = value;
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
// CREDIT CARD START
|
|
616
|
+
|
|
617
|
+
onCardNumberChange = (value: string) => {
|
|
618
|
+
if (!this.cardData) return;
|
|
619
|
+
if (
|
|
620
|
+
value.length > this.cardData.cardNumber!.length &&
|
|
621
|
+
!isLastCharNumber(value)
|
|
622
|
+
)
|
|
623
|
+
return;
|
|
624
|
+
|
|
625
|
+
const oldOriginalValue = (this.cardData.cardNumber || "")
|
|
626
|
+
.split(" ")
|
|
627
|
+
.join("");
|
|
628
|
+
const originalValue = value.split(" ").join("");
|
|
629
|
+
|
|
630
|
+
if (originalValue.length > MAX_CARD_NUMBER_LENGTH) return;
|
|
631
|
+
if (
|
|
632
|
+
oldOriginalValue.length < 6 &&
|
|
633
|
+
originalValue.length >= 6 &&
|
|
634
|
+
!this.installmentInfo
|
|
635
|
+
) {
|
|
636
|
+
this.retrieveInstallmentInfo({
|
|
637
|
+
binNumber: originalValue.slice(0, 6),
|
|
638
|
+
paymentGatewayId: this.checkout.selectedPaymentGateway!.id!,
|
|
639
|
+
price: this.checkout.totalFinalPrice!,
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
// Deleting characters below 6
|
|
643
|
+
else if (
|
|
644
|
+
originalValue.length < 6 &&
|
|
645
|
+
oldOriginalValue.length > originalValue.length
|
|
646
|
+
) {
|
|
647
|
+
this.cardData.installmentCount = 1;
|
|
648
|
+
this.installmentInfo = undefined;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
this.cardData.cardNumber = chunkString(originalValue, 4).join(" ");
|
|
652
|
+
};
|
|
653
|
+
|
|
654
|
+
onCardHolderNameChange = (value: string) => {
|
|
655
|
+
if (!this.cardData) return;
|
|
656
|
+
this.cardData.cardHolderName = value;
|
|
657
|
+
};
|
|
658
|
+
|
|
659
|
+
onExpirationDateChange = (value: string) => {
|
|
660
|
+
if (!this.cardData) return;
|
|
661
|
+
if (
|
|
662
|
+
value.length > this.cardData.expirationDate!.length &&
|
|
663
|
+
!isLastCharNumber(value)
|
|
664
|
+
) {
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
// Check autocomplete
|
|
669
|
+
if (this.cardData.expirationDate?.length === 0) {
|
|
670
|
+
const splitValues = value.split("/");
|
|
671
|
+
|
|
672
|
+
if (splitValues.length === 2) {
|
|
673
|
+
const firstPart = splitValues[0].trim();
|
|
674
|
+
const lastPart = splitValues[1].trim();
|
|
675
|
+
|
|
676
|
+
// YYYY-MM format
|
|
677
|
+
if (firstPart.length === 4 && lastPart.length === 2) {
|
|
678
|
+
const year = parseInt(firstPart.slice(2));
|
|
679
|
+
const month = parseInt(lastPart);
|
|
680
|
+
|
|
681
|
+
if (!isNaN(year) && !isNaN(month)) {
|
|
682
|
+
this.cardData.expirationDate = `${
|
|
683
|
+
month < 10 ? "0" + month : month
|
|
684
|
+
} / ${year < 10 ? "0" + year : year}`;
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
// MM-YYYY format
|
|
690
|
+
if (firstPart.length === 2 && lastPart.length === 4) {
|
|
691
|
+
const month = parseInt(firstPart);
|
|
692
|
+
const year = parseInt(lastPart.slice(2));
|
|
693
|
+
|
|
694
|
+
if (!isNaN(year) && !isNaN(month)) {
|
|
695
|
+
this.cardData.expirationDate = `${
|
|
696
|
+
month < 10 ? "0" + month : month
|
|
697
|
+
} / ${year < 10 ? "0" + year : year}`;
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// const autoCompleteValue = value.split("/").join("");
|
|
704
|
+
// if (
|
|
705
|
+
// autoCompleteValue.length === 4 &&
|
|
706
|
+
// !isNaN(parseInt(autoCompleteValue))
|
|
707
|
+
// ) {
|
|
708
|
+
// this.cardData.expirationDate = chunkString(autoCompleteValue, 2).join(
|
|
709
|
+
// " / "
|
|
710
|
+
// );
|
|
711
|
+
// return;
|
|
712
|
+
// }
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
const originalValue = value.split(" / ").join("");
|
|
716
|
+
if (originalValue.length > 4) return;
|
|
717
|
+
|
|
718
|
+
this.cardData.expirationDate = chunkString(originalValue, 2).join(" / ");
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
onCvcChange = (value: string) => {
|
|
722
|
+
if (!this.cardData) return;
|
|
723
|
+
if (value.length > this.cardData.cvv!.length && !isLastCharNumber(value))
|
|
724
|
+
return;
|
|
725
|
+
if (value.length > MAX_CVC_LENGTH) return;
|
|
726
|
+
this.cardData.cvv = value;
|
|
727
|
+
};
|
|
728
|
+
|
|
729
|
+
// CREDIT CARD END
|
|
730
|
+
|
|
731
|
+
saveAddress = async (type: "billing" | "shipping") => {
|
|
732
|
+
if (this.shouldSaveAddress) {
|
|
733
|
+
const newAddress = new IkasCustomerAddress({
|
|
734
|
+
...(type === "shipping"
|
|
735
|
+
? this.checkout.shippingAddress
|
|
736
|
+
: this.checkout.billingAddress),
|
|
737
|
+
title: this.addressTitle || this.t("checkout-page:newAddress"),
|
|
738
|
+
id: uuidv4(),
|
|
739
|
+
});
|
|
740
|
+
const customer = _cloneDeep(this.store.customerStore.customer!);
|
|
741
|
+
customer.addresses.push(newAddress);
|
|
742
|
+
|
|
743
|
+
await this.store.customerStore.saveCustomer(customer);
|
|
744
|
+
|
|
745
|
+
if (type === "shipping") {
|
|
746
|
+
this.checkout.shippingAddress!.id = newAddress.id;
|
|
747
|
+
this.selectedShippingAddressId = newAddress.id || "-1";
|
|
748
|
+
} else {
|
|
749
|
+
this.checkout.billingAddress!.id = newAddress.id;
|
|
750
|
+
this.selectedBillingAddressId = newAddress.id || "-1";
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
};
|
|
754
|
+
|
|
755
|
+
onGoToCartClick = () => {
|
|
756
|
+
this.router.push("/cart");
|
|
757
|
+
};
|
|
758
|
+
|
|
759
|
+
onBackToShoppingClick = () => {
|
|
760
|
+
this.router.push("/");
|
|
761
|
+
};
|
|
762
|
+
|
|
763
|
+
onProceedToShippingClick = async () => {
|
|
764
|
+
if (!this.canProceedToShipping) {
|
|
765
|
+
this.isErrorsVisible = true;
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
768
|
+
this.isErrorsVisible = false;
|
|
769
|
+
|
|
770
|
+
try {
|
|
771
|
+
this.isStepLoading = true;
|
|
772
|
+
|
|
773
|
+
await this.saveAddress("shipping");
|
|
774
|
+
await this.checkStocks();
|
|
775
|
+
await this.saveCheckout();
|
|
776
|
+
this.changeStep(CheckoutStep.SHIPPING);
|
|
777
|
+
} catch (err) {
|
|
778
|
+
if (err.type) {
|
|
779
|
+
this.error = err;
|
|
780
|
+
} else {
|
|
781
|
+
console.log(err);
|
|
782
|
+
this.error = {
|
|
783
|
+
type: ErrorType.UNKNOWN,
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
this.isStepLoading = false;
|
|
787
|
+
}
|
|
788
|
+
};
|
|
789
|
+
|
|
790
|
+
onProceedToPaymentClick = async () => {
|
|
791
|
+
if (!this.canProceedToPayment) {
|
|
792
|
+
this.isErrorsVisible = true;
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
this.isErrorsVisible = false;
|
|
796
|
+
|
|
797
|
+
try {
|
|
798
|
+
this.isStepLoading = true;
|
|
799
|
+
await this.checkStocks();
|
|
800
|
+
await this.saveCheckout();
|
|
801
|
+
|
|
802
|
+
this.error = undefined;
|
|
803
|
+
this.changeStep(CheckoutStep.PAYMENT);
|
|
804
|
+
} catch (err) {
|
|
805
|
+
if (err.type) {
|
|
806
|
+
this.error = err;
|
|
807
|
+
} else {
|
|
808
|
+
console.log(err);
|
|
809
|
+
this.error = {
|
|
810
|
+
type: ErrorType.UNKNOWN,
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
this.isStepLoading = false;
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
|
|
817
|
+
onCompletePaymentClick = async () => {
|
|
818
|
+
if (!this.canPerformPayment) {
|
|
819
|
+
this.isErrorsVisible = true;
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
if (!this.useDifferentAddress) {
|
|
824
|
+
this.checkout.billingAddress = this.checkout.shippingAddress;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
try {
|
|
828
|
+
this.isErrorsVisible = false;
|
|
829
|
+
this.isStepLoading = true;
|
|
830
|
+
|
|
831
|
+
await this.checkStocks();
|
|
832
|
+
await this.saveAddress("billing");
|
|
833
|
+
await this.saveCheckout();
|
|
834
|
+
await this.createSaleTransaction();
|
|
835
|
+
} catch (err) {
|
|
836
|
+
if (err.type) {
|
|
837
|
+
this.error = err;
|
|
838
|
+
} else {
|
|
839
|
+
this.error = {
|
|
840
|
+
type: ErrorType.UNKNOWN,
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
this.isStepLoading = false;
|
|
844
|
+
}
|
|
845
|
+
};
|
|
846
|
+
|
|
847
|
+
createSaleTransaction = async () => {
|
|
848
|
+
if (!this.checkout.selectedPaymentGateway) return;
|
|
849
|
+
|
|
850
|
+
const response = await IkasCheckoutAPI.createSaleTransactionWithCheckout(
|
|
851
|
+
this.checkout.id!,
|
|
852
|
+
this.checkout.selectedPaymentGateway.id!,
|
|
853
|
+
this.checkout.selectedPaymentGateway.paymentMethodType ===
|
|
854
|
+
IkasPaymentMethodType.CREDIT_CARD &&
|
|
855
|
+
this.checkout.selectedPaymentGateway.type ===
|
|
856
|
+
IkasPaymentGatewayType.INTERNAL &&
|
|
857
|
+
this.cardData
|
|
858
|
+
? this.cardData.toInput()
|
|
859
|
+
: undefined
|
|
860
|
+
);
|
|
861
|
+
|
|
862
|
+
const transactionStatus = (response?.transactionStatus as unknown) as
|
|
863
|
+
| IkasTransactionStatusEnum
|
|
864
|
+
| undefined;
|
|
865
|
+
|
|
866
|
+
const transactionSuccess =
|
|
867
|
+
transactionStatus &&
|
|
868
|
+
[
|
|
869
|
+
IkasTransactionStatusEnum.SUCCESS,
|
|
870
|
+
IkasTransactionStatusEnum.AUTHORIZED,
|
|
871
|
+
].includes(transactionStatus);
|
|
872
|
+
|
|
873
|
+
const transactionPending =
|
|
874
|
+
transactionStatus === IkasTransactionStatusEnum.PENDING;
|
|
875
|
+
|
|
876
|
+
if (transactionSuccess) {
|
|
877
|
+
await this.onCheckoutTransactionSuccess();
|
|
878
|
+
} else if (transactionPending && !!response?.returnSlug) {
|
|
879
|
+
window.location.href =
|
|
880
|
+
process.env.NEXT_PUBLIC_BASE_URL + response.returnSlug;
|
|
881
|
+
} else {
|
|
882
|
+
throw {
|
|
883
|
+
type: ErrorType.UNKNOWN,
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
};
|
|
887
|
+
|
|
888
|
+
onCheckoutTransactionSuccess = async () => {
|
|
889
|
+
localStorage.removeItem(USE_DIFFERENT_ADDRESS_KEY);
|
|
890
|
+
|
|
891
|
+
if (this.checkout.customer?.notificationsAccepted) {
|
|
892
|
+
await this.store.customerStore.createEmailSubscription(
|
|
893
|
+
this.checkout.customer?.email || ""
|
|
894
|
+
);
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
this.changeStep(CheckoutStep.SUCCESS);
|
|
898
|
+
};
|
|
899
|
+
|
|
900
|
+
onBackToInfoClick = () => {
|
|
901
|
+
this.changeStep(CheckoutStep.INFO);
|
|
902
|
+
};
|
|
903
|
+
|
|
904
|
+
onBackToShippingClick = () => {
|
|
905
|
+
this.changeStep(CheckoutStep.SHIPPING);
|
|
906
|
+
};
|
|
907
|
+
|
|
908
|
+
setCustomerConsentGranted = (value: boolean) => {
|
|
909
|
+
if (this.checkout.customer)
|
|
910
|
+
this.checkout.customer.notificationsAccepted = value;
|
|
911
|
+
};
|
|
912
|
+
|
|
913
|
+
setUseDifferentAddress = (value: boolean) => {
|
|
914
|
+
this.useDifferentAddress = value;
|
|
915
|
+
if (this.useDifferentAddress) {
|
|
916
|
+
localStorage.setItem(USE_DIFFERENT_ADDRESS_KEY, "1");
|
|
917
|
+
this.checkout.billingAddress =
|
|
918
|
+
this.checkout.billingAddress || new IkasOrderAddress();
|
|
919
|
+
} else {
|
|
920
|
+
localStorage.removeItem(USE_DIFFERENT_ADDRESS_KEY);
|
|
921
|
+
this.checkout.billingAddress = this.checkout.shippingAddress;
|
|
922
|
+
}
|
|
923
|
+
};
|
|
924
|
+
|
|
925
|
+
setShouldSaveAddress = (value: boolean) => {
|
|
926
|
+
this.shouldSaveAddress = value;
|
|
927
|
+
};
|
|
928
|
+
|
|
929
|
+
setAddressTitle = (value: string) => {
|
|
930
|
+
this.addressTitle = value;
|
|
931
|
+
};
|
|
932
|
+
|
|
933
|
+
setPaymentGateway = (index: number) => {
|
|
934
|
+
if (!this.paymentGateways.length) return;
|
|
935
|
+
|
|
936
|
+
const paymentGateway = this.paymentGateways[index];
|
|
937
|
+
this.checkout.selectedPaymentGateway = paymentGateway;
|
|
938
|
+
|
|
939
|
+
if (this.step !== CheckoutStep.SUCCESS) {
|
|
940
|
+
if (
|
|
941
|
+
paymentGateway.paymentMethodType ===
|
|
942
|
+
IkasPaymentMethodType.CREDIT_CARD &&
|
|
943
|
+
paymentGateway.type === IkasPaymentGatewayType.INTERNAL
|
|
944
|
+
) {
|
|
945
|
+
this.cardData = new CreditCardData();
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
this.installmentInfo = undefined;
|
|
949
|
+
}
|
|
950
|
+
};
|
|
951
|
+
|
|
952
|
+
setInstallmentCount = (count: number) => {
|
|
953
|
+
if (!this.cardData) return;
|
|
954
|
+
this.cardData.installmentCount = count;
|
|
955
|
+
};
|
|
956
|
+
|
|
957
|
+
changeStep = async (step: CheckoutStep) => {
|
|
958
|
+
if (!isServer) {
|
|
959
|
+
window.location.replace(
|
|
960
|
+
`${window.location.pathname}?id=${this.checkout.id}&step=${step}`
|
|
961
|
+
);
|
|
962
|
+
}
|
|
963
|
+
};
|
|
964
|
+
|
|
965
|
+
logout = async () => {
|
|
966
|
+
this.checkout.customer = undefined;
|
|
967
|
+
this.store.customerStore.logout();
|
|
968
|
+
try {
|
|
969
|
+
await this.saveCheckout();
|
|
970
|
+
} catch (err) {}
|
|
971
|
+
this.createCustomer();
|
|
972
|
+
};
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
function chunkString(str: string, length: number) {
|
|
976
|
+
return str.match(new RegExp(".{1," + length + "}", "g")) || [];
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
function isLastCharNumber(str: string) {
|
|
980
|
+
return str && NUMBER_ONLY_REGEX.test(str.charAt(str.length - 1));
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
export enum CheckoutStep {
|
|
984
|
+
INFO = "info",
|
|
985
|
+
SHIPPING = "shipping",
|
|
986
|
+
PAYMENT = "payment",
|
|
987
|
+
SUCCESS = "success",
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
export enum ErrorType {
|
|
991
|
+
UNKNOWN,
|
|
992
|
+
API_ERROR,
|
|
993
|
+
STOCK_ERROR,
|
|
994
|
+
PAYMENT_ERROR,
|
|
995
|
+
NO_SHIPPING_ERROR,
|
|
996
|
+
CUSTOMER_LOGIN_REQUIRED_ERROR,
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
export type CheckoutError = {
|
|
1000
|
+
type: ErrorType;
|
|
1001
|
+
data?: any;
|
|
1002
|
+
};
|
|
1003
|
+
|
|
1004
|
+
export type StockErrorData = {
|
|
1005
|
+
variant: IkasOrderLineVariant;
|
|
1006
|
+
availableQuantity: number;
|
|
1007
|
+
};
|