@ikas/storefront 3.0.0-alpha.30 → 3.0.0-alpha.31

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.
Files changed (133) hide show
  1. package/build/__api/models/{MasterpassTokenResponse.d.ts → MasterPassTokenResponse.d.ts} +0 -0
  2. package/build/__api/mutations/addCouponCodeToCheckout.d.ts +1 -1
  3. package/build/__api/mutations/addItemToCart.d.ts +1 -1
  4. package/build/__api/mutations/createCustomerEmailSubscription.d.ts +1 -1
  5. package/build/__api/mutations/createCustomerReview.d.ts +1 -1
  6. package/build/__api/mutations/createOrderRefundRequest.d.ts +1 -1
  7. package/build/__api/mutations/createSaleTransactionWithCart.d.ts +1 -1
  8. package/build/__api/mutations/createSaleTransactionWithCheckout.d.ts +1 -1
  9. package/build/__api/mutations/createStripePaymentIntent.d.ts +1 -1
  10. package/build/__api/mutations/customerLogin.d.ts +1 -1
  11. package/build/__api/mutations/customerRefreshToken.d.ts +1 -1
  12. package/build/__api/mutations/getOrderLineFile.d.ts +1 -1
  13. package/build/__api/mutations/registerCustomer.d.ts +1 -1
  14. package/build/__api/mutations/retrieveInstallmentInfo.d.ts +1 -1
  15. package/build/__api/mutations/saveCart.d.ts +1 -1
  16. package/build/__api/mutations/saveCartCouponCode.d.ts +1 -1
  17. package/build/__api/mutations/saveCheckout.d.ts +1 -1
  18. package/build/__api/mutations/saveItemToCart.d.ts +1 -1
  19. package/build/__api/mutations/saveLastViewedProducts.d.ts +1 -1
  20. package/build/__api/mutations/saveMyCustomer.d.ts +1 -1
  21. package/build/__api/mutations/saveProductBackInStockRemind.d.ts +1 -1
  22. package/build/__api/mutations/saveRaffleParticipant.d.ts +1 -1
  23. package/build/__api/mutations/updateRaffleParticipant.d.ts +1 -1
  24. package/build/__api/queries/checkCustomerEmail.d.ts +1 -1
  25. package/build/__api/queries/checkStocks.d.ts +1 -1
  26. package/build/__api/queries/customerSocialLogin.d.ts +1 -1
  27. package/build/__api/queries/getAvailableShippingCountries.d.ts +1 -1
  28. package/build/__api/queries/getAvailableStockLocations.d.ts +1 -1
  29. package/build/__api/queries/getCart.d.ts +1 -1
  30. package/build/__api/queries/getCartById.d.ts +1 -1
  31. package/build/__api/queries/getCheckoutByCartId.d.ts +1 -1
  32. package/build/__api/queries/getCheckoutById.d.ts +1 -1
  33. package/build/__api/queries/getCurrencyRate.d.ts +1 -1
  34. package/build/__api/queries/getCustomerOrders.d.ts +1 -1
  35. package/build/__api/queries/getLastViewedProducts.d.ts +1 -1
  36. package/build/__api/queries/getMasterpassRequestToken.d.ts +1 -1
  37. package/build/__api/queries/getMasterpassRequestToken.js +1 -0
  38. package/build/__api/queries/getMyCountry.d.ts +1 -1
  39. package/build/__api/queries/getMyCustomer.d.ts +1 -1
  40. package/build/__api/queries/getOrder.d.ts +1 -1
  41. package/build/__api/queries/getOrderByEmail.d.ts +1 -1
  42. package/build/__api/queries/getProductCampaigns.d.ts +1 -1
  43. package/build/__api/queries/getProductFilterData.d.ts +1 -1
  44. package/build/__api/queries/getProductOptionFileUrl.d.ts +1 -1
  45. package/build/__api/queries/getRaffleParticipants.d.ts +1 -1
  46. package/build/__api/queries/getRafflesByCustomerId.d.ts +1 -1
  47. package/build/__api/queries/getStorefront.d.ts +1 -1
  48. package/build/__api/queries/getVariantStockLocations.d.ts +1 -1
  49. package/build/__api/queries/listBlog.d.ts +1 -1
  50. package/build/__api/queries/listBlogCategory.d.ts +1 -1
  51. package/build/__api/queries/listBlogMetadata.d.ts +1 -1
  52. package/build/__api/queries/listCampaignOffer.d.ts +1 -1
  53. package/build/__api/queries/listCategory.d.ts +1 -1
  54. package/build/__api/queries/listCheckoutSettings.d.ts +1 -1
  55. package/build/__api/queries/listCity.d.ts +1 -1
  56. package/build/__api/queries/listCountry.d.ts +1 -1
  57. package/build/__api/queries/listCustomerAttribute.d.ts +1 -1
  58. package/build/__api/queries/listCustomerReviewSummary.d.ts +1 -1
  59. package/build/__api/queries/listCustomerReviews.d.ts +1 -1
  60. package/build/__api/queries/listDistrict.d.ts +1 -1
  61. package/build/__api/queries/listFavoriteProducts.d.ts +1 -1
  62. package/build/__api/queries/listHTMLMetaData.d.ts +1 -1
  63. package/build/__api/queries/listMerchantSettings.d.ts +1 -1
  64. package/build/__api/queries/listOrderRefundSettings.d.ts +1 -1
  65. package/build/__api/queries/listOrderTransactions.d.ts +1 -1
  66. package/build/__api/queries/listPaymentGateway.d.ts +1 -1
  67. package/build/__api/queries/listProduct.d.ts +1 -1
  68. package/build/__api/queries/listProductAttribute.d.ts +1 -1
  69. package/build/__api/queries/listProductBackInStockRemind.d.ts +1 -1
  70. package/build/__api/queries/listProductBrand.d.ts +1 -1
  71. package/build/__api/queries/listProductOptionSet.d.ts +1 -1
  72. package/build/__api/queries/listProductStockLocation.d.ts +1 -1
  73. package/build/__api/queries/listRaffle.d.ts +1 -1
  74. package/build/__api/queries/listRaffleMetadata.d.ts +1 -1
  75. package/build/__api/queries/listState.d.ts +1 -1
  76. package/build/__api/queries/listStockLocation.d.ts +1 -1
  77. package/build/__api/queries/listTown.d.ts +1 -1
  78. package/build/__api/queries/listVariantType.d.ts +1 -1
  79. package/build/__api/queries/searchProducts.d.ts +1 -1
  80. package/build/assets/translations/checkout/en.js +1 -1
  81. package/build/assets/translations/checkout/tr.js +1 -1
  82. package/build/components/checkout/components/button/index.d.ts +1 -1
  83. package/build/components/checkout/components/checkbox/index.d.ts +1 -1
  84. package/build/components/checkout/components/credit-card-form/index.js +1 -1
  85. package/build/components/checkout/components/master-pass/index.d.ts +9 -0
  86. package/build/components/checkout/components/master-pass/index.js +1 -0
  87. package/build/components/checkout/components/master-pass/modal/index.d.ts +11 -0
  88. package/build/components/checkout/components/master-pass/modal/index.js +1 -0
  89. package/build/components/checkout/components/master-pass/modal/style.module.scss.js +1 -0
  90. package/build/components/checkout/components/master-pass/modal/svg/modal-close.d.ts +3 -0
  91. package/build/components/checkout/components/master-pass/modal/svg/modal-close.js +1 -0
  92. package/build/components/checkout/components/master-pass/modal-link-card-to-client/index.d.ts +10 -0
  93. package/build/components/checkout/components/master-pass/modal-link-card-to-client/index.js +1 -0
  94. package/build/components/checkout/components/master-pass/modal-link-card-to-client/style.module.scss.js +1 -0
  95. package/build/components/checkout/components/master-pass/modal-link-card-to-client/svg/info-mark.d.ts +3 -0
  96. package/build/components/checkout/components/master-pass/modal-link-card-to-client/svg/info-mark.js +1 -0
  97. package/build/components/checkout/components/master-pass/modal-link-card-to-client/svg/master-pass-by-master-card-big.d.ts +3 -0
  98. package/build/components/checkout/components/master-pass/modal-link-card-to-client/svg/master-pass-by-master-card-big.js +1 -0
  99. package/build/components/checkout/components/master-pass/modal-otp/index.d.ts +10 -0
  100. package/build/components/checkout/components/master-pass/modal-otp/index.js +1 -0
  101. package/build/components/checkout/components/master-pass/modal-otp/style.module.scss.js +1 -0
  102. package/build/components/checkout/components/master-pass/modal-otp/svg/master-pass-by-master-card-small.d.ts +3 -0
  103. package/build/components/checkout/components/master-pass/modal-otp/svg/master-pass-by-master-card-small.js +1 -0
  104. package/build/components/checkout/components/master-pass/modal-otp/svg/master-pass.d.ts +3 -0
  105. package/build/components/checkout/components/master-pass/modal-otp/svg/master-pass.js +1 -0
  106. package/build/components/checkout/components/master-pass/modal-otp/svg/success.d.ts +3 -0
  107. package/build/components/checkout/components/master-pass/modal-otp/svg/success.js +1 -0
  108. package/build/components/checkout/components/master-pass/payment-gateway/svg/master-card.d.ts +3 -0
  109. package/build/components/checkout/components/master-pass/payment-gateway/svg/master-card.js +1 -0
  110. package/build/components/checkout/components/master-pass/style.module.scss.js +1 -0
  111. package/build/components/checkout/components/master-pass/svg/master-pass-by-master-card.d.ts +3 -0
  112. package/build/components/checkout/components/master-pass/svg/master-pass-by-master-card.js +1 -0
  113. package/build/components/checkout/components/modal/index.js +1 -1
  114. package/build/components/checkout/components/modal/useEscape.d.ts +5 -0
  115. package/build/components/checkout/components/modal/useEscape.js +1 -0
  116. package/build/components/checkout/components/select-box/index.d.ts +1 -1
  117. package/build/components/checkout/components/toggle/index.d.ts +1 -1
  118. package/build/components/checkout/model.d.ts +3 -0
  119. package/build/components/checkout/model.js +1 -1
  120. package/build/components/checkout/modelMasterPass.d.ts +124 -0
  121. package/build/components/checkout/modelMasterPass.js +1 -0
  122. package/build/components/checkout/steps/step-payment/payment-gateways/index.js +1 -1
  123. package/build/components/checkout/steps/step-payment/payment-gateways/style.module.scss.js +1 -1
  124. package/build/ikas.cjs +1 -1
  125. package/build/models/data/payment-gateway/index.d.ts +1 -0
  126. package/build/models/data/payment-gateway/index.js +1 -1
  127. package/build/models/ui/product-list/index.d.ts +1 -1
  128. package/build/scripts/generators/config/content.js +1 -1
  129. package/build/store/checkout/index.d.ts +1 -1
  130. package/build/store/customer/api.d.ts +5 -5
  131. package/build/store/location/index.d.ts +1 -1
  132. package/build/store/product/index.d.ts +1 -1
  133. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  declare type Props = {
3
3
  value: boolean;
4
- label?: string | React.ReactElement;
4
+ label?: string | React.ReactNode;
5
5
  hasError?: boolean;
6
6
  removePadding?: boolean;
7
7
  onChange?: (value: boolean) => void;
@@ -14,6 +14,7 @@ import { StockLocation } from "../../__api/models/StockLocation";
14
14
  import { GetAvailableStockLocation } from "../../__api/models/GetAvailableStockLocation";
15
15
  import { CreateStripePaymentIntentResponse } from "../../__api/models/CreateStripePaymentIntentResponse";
16
16
  import { IkasCheckoutCustomizationProps } from ".";
17
+ import MasterPassModel from "./modelMasterPass";
17
18
  export default class CheckoutViewModel {
18
19
  checkout: IkasCheckout;
19
20
  checkoutSettings: IkasCheckoutSettings;
@@ -49,6 +50,7 @@ export default class CheckoutViewModel {
49
50
  policyModalText: string;
50
51
  error?: CheckoutError | null;
51
52
  successTransaction?: IkasOrderTransaction;
53
+ mpVM: MasterPassModel;
52
54
  t: TFunction;
53
55
  constructor(checkout: IkasCheckout, checkoutSettings: IkasCheckoutSettings, merchantSettings: IkasMerchantSettings | null, router: NextRouter, returnPolicy: string, privacyPolicy: string, termsOfService: string, t: TFunction, customizationProps: IkasCheckoutCustomizationProps);
54
56
  init: () => Promise<void>;
@@ -66,6 +68,7 @@ export default class CheckoutViewModel {
66
68
  get installmentExtraPrice(): number | undefined;
67
69
  get finalPrice(): number;
68
70
  get hasStockError(): boolean;
71
+ get isPaymentGatewayHasMasterPass(): boolean;
69
72
  get canProceedToShipping(): boolean | undefined;
70
73
  get canProceedToInStoreDelivery(): boolean;
71
74
  get canProceedToPayment(): boolean | undefined;
@@ -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 u}from"../../storefront/index.js";import{IkasCheckoutSettings as l}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 v from"../../store/merchant/index.js";import f from"../../store/checkout/index.js";import{CheckStocksLineInput as g}from"../../__api/models/CheckStocksLineInput.js";import S from"../../store/cart/api.js";import{SaveCartInput as y}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 P,A,j=/^\d+$/,w="undefined"==typeof localStorage,R=function(){function j(j,R,E,T,O,D,L,G,_){var M=this;this.checkout=new p,this.checkoutSettings=new l,this.storefront=null,this.store=u.store,this.isCheckoutLoaded=!1,this.isErrorsVisible=!1,this.isStepLoading=!1,this.isTermsAndConditionsChecked=!1,this.isChangingShippingMethod=!1,this.isContactModalVisible=!1,this.step=P.INFO,this.customizationProps=null,this.cardData=null,this.paymentGateways=[],this.installmentInfo=null,this.useDifferentAddress=!1,this.shouldSaveAddress=!0,this.addressTitle="",this.shippingCountryIds=null,this.selectedShippingAddressId="-1",this.selectedBillingAddressId="-1",this.stockLocations=[],this.availableStockLocations=[],this.deliveryMethod="address",this.stripeResponse=null,this.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;return e(this,(function(e){switch(e.label){case 0:if(u.isEditor)return this.step=P.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===P.SHIPPING&&!this.canProceedToShipping)return[2,this.changeStep(P.INFO)];if(this.step!==P.PAYMENT||this.canProceedToPayment){if(![P.INFO,P.SUCCESS,P.SHIPPING,P.PAYMENT].includes(this.step))return[2,this.changeStep(P.INFO)]}else{if(!this.isInStoreDelivery)return[2,this.changeStep(P.INFO)];this.deliveryMethod="in-store"}}return s&&(this.error={type:A.PAYMENT_ERROR,data:n||null}),this.step!==P.INFO?[3,4]:[4,this.getShippingCountries()];case 1:return e.sent(),this.checkShippingCountries(),[4,this.getStockLocations()];case 2:return e.sent(),[4,this.getAvailableStockLocations()];case 3:e.sent(),this.isInStoreDelivery&&(this.deliveryMethod="in-store"),e.label=4;case 4:return this.step!==P.SHIPPING||1!==(null===(o=this.checkout.availableShippingMethods)||void 0===o?void 0:o.length)||this.checkoutSettings.isGiftPackageEnabled||(this.step=P.PAYMENT,this.router.replace("/checkout?id=".concat(this.checkout.id,"&step=").concat(this.step),void 0,{shallow:!0})),this.step!==P.SHIPPING||(null===(a=this.checkout.availableShippingMethods)||void 0===a?void 0:a.length)?this.step!==P.PAYMENT&&this.step!==P.SUCCESS?[3,8]:[4,this.listPaymentGateways()]:(this.error={type:A.NO_SHIPPING_ERROR},this.isCheckoutLoaded=!0,[2]);case 5:return e.sent(),this.isInStoreDelivery?(this.deliveryMethod="in-store",[4,this.getStockLocations()]):[3,7];case 6:e.sent(),e.label=7;case 7:if(!this.paymentGateways.length)return this.error={type:A.NO_SHIPPING_ERROR},this.isCheckoutLoaded=!0,[2];e.label=8;case 8:return this.step===P.SUCCESS?[3,12]:this.checkout.isComplete?[2,this.changeStep(P.SUCCESS)]:[3,9];case 9:return[4,this.initialStockCheck()];case 10:e.sent(),e.label=11;case 11:return[3,14];case 12:return[4,this.getSuccessTransaction()];case 13:e.sent(),this.successTransaction&&(r=this.successTransaction.paymentGatewayId,this.checkout.selectedPaymentGateway=this.paymentGateways.find((function(t){return t.id===r}))),e.label=14;case 14: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,v.listMerchantSettings({})];case 1:t=e.sent(),this.merchantSettings=t.data||void 0,e.label=2;case 2:return[2]}}))}))},this.getSuccessTransaction=function(){return t(M,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return[4,m.listOrderTransactions({orderId:{eq:this.checkout.id}})];case 1:return t=e.sent(),this.successTransaction=t.isSuccess&&(null===(i=t.data)||void 0===i?void 0:i.length)?t.data[0]:void 0,[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 y(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,S.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:A.CUSTOMER_LOGIN_REQUIRED_ERROR}:{type:A.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,l,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,f.checkStocks({lines:t.map((function(t){return new g(t)})),stockLocationIdList:u.stockLocationIds||[]})];case 1:if(!(i=e.sent()).isSuccess)throw{type:A.API_ERROR};if(null==(s=null===(h=null===(l=i.data)||void 0===l?void 0:l.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:A.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,f.getAvailableShippingCountries({salesChannelId:u.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 u.pickUpStockLocationIds?[4,f.listStockLocation({id:{in:u.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:A.API_ERROR},[2];this.stockLocations=t.data,e.label=2;case 2:return[2]}}))}))},this.getAvailableStockLocations=function(){return t(M,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return u.pickUpStockLocationIds?(t=this.checkout.items.map((function(t){return{quantity:t.quantity,variantId:t.variant.id,productId:t.variant.productId}})),[4,f.getAvailableStockLocations({lines:t.map((function(t){return new g(t)})),stockLocationIdList:u.pickUpStockLocationIds})]):[3,2];case 1:if(!(i=e.sent()).isSuccess)return this.error={type:A.API_ERROR},[2];this.availableStockLocations=i.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:A.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:A.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,l=this;return e(this,(function(e){switch(e.label){case 0:return t="local"===process.env.NEXT_PUBLIC_ENV,i=u.paymentGateways.map((function(t){return t.id})),[4,f.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===P.PAYMENT&&(n=n.filter((function(t){return!t.supportedCurrencies.length||t.supportedCurrencies.includes(l.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(u.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:A.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,f.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:return e.trys.push([0,2,,3]),[4,S.saveCartCouponCode({cartId:this.checkout.id,couponCode:this.checkout.couponCode||null})];case 1: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===P.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,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)||N(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=x(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)||N(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=x(a,2).join(" / "))}},this.onCvcChange=function(t){M.cardData&&(t.length>M.cardData.cvv.length&&!N(t)||t.length>4||(M.cardData.cvv=t))},this.saveAddress=function(s){return t(M,void 0,void 0,(function(){var t,r,a,d,c;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,3,,4]),this.shouldSaveAddress&&this.store.customerStore.customer?(t="shipping"===s?this.checkout.shippingAddress:this.checkout.billingAddress,(null===(c=this.store.customerStore.customer.addresses)||void 0===c?void 0:c.find((function(e){return e.id===(null==t?void 0:t.id)})))?[2]:(r=new o(i(i({},t),{title:this.addressTitle||this.t("checkout-page:newAddress"),id:C()})),(a=n(this.store.customerStore.customer)).addresses||(a.addresses=[]),a.addresses.push(r),[4,this.store.customerStore.saveCustomer(a)])):[3,2];case 1:e.sent(),"shipping"===s?(this.checkout.shippingAddress.id=r.id,this.selectedShippingAddressId=r.id||"-1"):(this.checkout.billingAddress.id=r.id,this.selectedBillingAddressId=r.id||"-1"),e.label=2;case 2:return[3,4];case 3:return d=e.sent(),console.error(d),[3,4];case 4: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(P.SHIPPING):this.changeStep(P.PAYMENT),[3,7];case 6:return(t=e.sent()).type?this.error=t:(console.log(t),this.error={type:A.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(P.PAYMENT),[3,5];case 4:return(t=e.sent()).type?this.error=t:(console.log(t),this.error={type:A.UNKNOWN}),this.isStepLoading=!1,[3,5];case 5:return[2]}}))}))},this.onCompletePaymentClick=function(){return t(M,void 0,void 0,(function(){var t,i,s;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(),"STRIPE"===(null===(s=this.checkout.selectedPaymentGateway)||void 0===s?void 0:s.code)?((t=document.querySelector("#stripe-form-btn"))&&t.click(),[2]):[4,this.createSaleTransaction()];case 6:return e.sent(),[3,8];case 7:return(i=e.sent()).type?this.error=i:this.error={type:A.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,f.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.getSuccessTransaction()]:[3,4];case 2:return e.sent(),[4,this.onCheckoutTransactionSuccess()];case 3:return e.sent(),[3,5];case 4:if(!n||!(null===(o=null==t?void 0:t.data)||void 0===o?void 0:o.returnSlug))throw{type:A.UNKNOWN};window.location.href=process.env.NEXT_PUBLIC_BASE_URL+t.data.returnSlug,e.label=5;case 5: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(P.SUCCESS),[2]}}))}))},this.onBackToInfoClick=function(){M.changeStep(P.INFO)},this.onBackToShippingClick=function(){M.changeStep(P.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(i){return t(M,void 0,void 0,(function(){var t,s;return e(this,(function(e){switch(e.label){case 0:return this.paymentGateways.length?"STRIPE"!==(t=this.paymentGateways[i]).code||this.stripeResponse?[3,2]:[4,f.createStripePaymentIntent({input:{cartId:this.checkout.id,paymentGatewayId:t.id||""}})]:[2];case 1:(s=e.sent()).isSuccess&&s.data&&(this.stripeResponse=s.data),e.label=2;case 2:return this.checkout.selectedPaymentGateway=t,this.step!==P.SUCCESS&&(t.paymentMethodType===k.CREDIT_CARD&&t.type===b.INTERNAL&&(this.cardData=new c),this.installmentInfo=void 0),[2]}}))}))},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=R,this.router=T,this.returnPolicy=O,this.privacyPolicy=D,this.termsOfService=L,this.t=G,this.customizationProps=_,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===P.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)===A.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)!==A.NO_SHIPPING_ERROR},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"canProceedToInStoreDelivery",{get:function(){var t,e,i;return!!((null===(t=this.checkout.shippingAddress)||void 0===t?void 0:t.firstName)&&(null===(e=this.checkout.shippingAddress)||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?"STRIPE"===i.code||(null===(e=this.cardData)||void 0===e?void 0:e.isValid):!!i)},enumerable:!1,configurable:!0}),j}();function x(t,e){return t.match(new RegExp(".{1,"+e+"}","g"))||[]}function N(t){return t&&j.test(t.charAt(t.length-1))}!function(t){t.INFO="info",t.SHIPPING="shipping",t.PAYMENT="payment",t.SUCCESS="success"}(P||(P={})),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"}(A||(A={}));export{P as CheckoutStep,A as ErrorType,R 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 v from"../../store/merchant/index.js";import f 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"./modelMasterPass.js";import P from'../../ext/uuid/dist/esm-node/v4.js';var A,j,w=/^\d+$/,R="undefined"==typeof localStorage,N=function(){function w(w,N,T,O,D,G,M,L,_){var U=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.customizationProps=null,this.cardData=null,this.paymentGateways=[],this.installmentInfo=null,this.useDifferentAddress=!1,this.shouldSaveAddress=!0,this.addressTitle="",this.shippingCountryIds=null,this.selectedShippingAddressId="-1",this.selectedBillingAddressId="-1",this.stockLocations=[],this.availableStockLocations=[],this.deliveryMethod="address",this.stripeResponse=null,this.policyModalTitle="",this.policyModalText="",this.error=null,this.init=function(){return t(U,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(U,void 0,void 0,(function(){var t,i,s,n,r,o,a;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:j.PAYMENT_ERROR,data:n||null}),this.step!==A.INFO?[3,4]:[4,this.getShippingCountries()];case 1:return e.sent(),this.checkShippingCountries(),[4,this.getStockLocations()];case 2:return e.sent(),[4,this.getAvailableStockLocations()];case 3:e.sent(),this.isInStoreDelivery&&(this.deliveryMethod="in-store"),e.label=4;case 4:return this.step!==A.SHIPPING||1!==(null===(o=this.checkout.availableShippingMethods)||void 0===o?void 0:o.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===(a=this.checkout.availableShippingMethods)||void 0===a?void 0:a.length)?this.step!==A.PAYMENT&&this.step!==A.SUCCESS?[3,8]:[4,this.listPaymentGateways()]:(this.error={type:j.NO_SHIPPING_ERROR},this.isCheckoutLoaded=!0,[2]);case 5:return e.sent(),this.isInStoreDelivery?(this.deliveryMethod="in-store",[4,this.getStockLocations()]):[3,7];case 6:e.sent(),e.label=7;case 7:if(!this.paymentGateways.length)return this.error={type:j.NO_SHIPPING_ERROR},this.isCheckoutLoaded=!0,[2];e.label=8;case 8:return this.step===A.SUCCESS?[3,12]:this.checkout.isComplete?[2,this.changeStep(A.SUCCESS)]:[3,9];case 9:return[4,this.initialStockCheck()];case 10:e.sent(),e.label=11;case 11:return[3,14];case 12:return[4,this.getSuccessTransaction()];case 13:e.sent(),this.successTransaction&&(r=this.successTransaction.paymentGatewayId,this.checkout.selectedPaymentGateway=this.paymentGateways.find((function(t){return t.id===r}))),e.label=14;case 14:return this.isCheckoutLoaded=!0,h.checkoutStep(this.checkout,this.step),[2]}}))}))},this.getMerchantSettings=function(){return t(U,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.merchantSettings?[3,2]:[4,v.listMerchantSettings({})];case 1:t=e.sent(),this.merchantSettings=t.data||void 0,e.label=2;case 2:return[2]}}))}))},this.getSuccessTransaction=function(){return t(U,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return[4,m.listOrderTransactions({orderId:{eq:this.checkout.id}})];case 1:return t=e.sent(),this.successTransaction=t.isSuccess&&(null===(i=t.data)||void 0===i?void 0:i.length)?t.data[0]:void 0,[2]}}))}))},this.saveCart=function(){return t(U,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:j.CUSTOMER_LOGIN_REQUIRED_ERROR}:{type:j.API_ERROR};return[2,i.data]}}))}))},this.inStockDeliveryInputData=function(i){return t(U,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(U,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,f.checkStocks({lines:t.map((function(t){return new g(t)})),stockLocationIdList:l.stockLocationIds||[]})];case 1:if(!(i=e.sent()).isSuccess)throw{type:j.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:j.STOCK_ERROR,data:n}}return[2]}}))}))},this.removeUnavailableItems=function(i){return t(U,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(U,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,f.getAvailableShippingCountries({salesChannelId:l.salesChannelId})];case 1:return t=e.sent(),this.shippingCountryIds=t.data,[2]}}))}))},this.getStockLocations=function(){return t(U,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return l.pickUpStockLocationIds?[4,f.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:j.API_ERROR},[2];this.stockLocations=t.data,e.label=2;case 2:return[2]}}))}))},this.getAvailableStockLocations=function(){return t(U,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return l.pickUpStockLocationIds?(t=this.checkout.items.map((function(t){return{quantity:t.quantity,variantId:t.variant.id,productId:t.variant.productId}})),[4,f.getAvailableStockLocations({lines:t.map((function(t){return new g(t)})),stockLocationIdList:l.pickUpStockLocationIds})]):[3,2];case 1:if(!(i=e.sent()).isSuccess)return this.error={type:j.API_ERROR},[2];this.availableStockLocations=i.data||[],e.label=2;case 2:return[2]}}))}))},this.checkShippingCountries=function(){var t;(null===(t=U.shippingCountryIds)||void 0===t?void 0:t.length)||(U.error={type:j.NO_SHIPPING_ERROR})},this.onDeliveryMethodChange=function(t){"address"===t&&(U.checkout.stockLocationId=null),U.deliveryMethod=t,U.isErrorsVisible=!1},this.initialStockCheck=function(){return t(U,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:j.UNKNOWN}),[3,3];case 3:return[2]}}))}))},this.listPaymentGateways=function(){return t(U,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,f.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),console.log("1"),this.step===A.PAYMENT&&(console.log("2",{paymentGateways:n}),n.find((function(t){return!!t.masterPassClientId}))&&(console.log("3"),this.mpVM.checkMasterPass({checkout:this.checkout,store:this.store}))),[2]):(this.error={type:j.API_ERROR},[2])}}))}))},this.retrieveInstallmentInfo=function(i){return t(U,void 0,void 0,(function(){var t,s,n;return e(this,(function(e){switch(e.label){case 0:return[4,f.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;U.store.customerStore.customer?(null===(t=U.store.customerStore.customer.addresses)||void 0===t||t.forEach((function(t){return t.checkoutSettings=U.checkoutSettings})),U.checkout.customer=new d(U.store.customerStore.customer)):U.checkout.customer||(U.checkout.customer=new d({}))},this.createShippingAddress=function(){var t;if(U.checkout.shippingAddress)U.selectedShippingAddressId=U.checkout.shippingAddress.id||"-1",U.checkout.shippingAddress.checkoutSettings=U.checkoutSettings;else{var e=null===(t=U.store.customerStore.customer)||void 0===t?void 0:t.addresses;U.onSelectedShippingAddressIdChange((null==e?void 0:e.length)?e[0].id:"-1")}},this.createBillingAddress=function(){"undefined"!=typeof localStorage&&(U.useDifferentAddress=!!localStorage.getItem("sAddr"),U.useDifferentAddress?(U.checkout.billingAddress&&(U.selectedBillingAddressId=U.checkout.billingAddress.id||"-1"),U.checkout.billingAddress=U.checkout.billingAddress||new a):U.checkout.billingAddress=new a(n(U.checkout.shippingAddress)||{}),U.checkout.billingAddress.checkoutSettings=U.checkoutSettings)},this.onShippingMethodChange=function(i){return t(U,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(U,void 0,void 0,(function(){return e(this,(function(t){return this.checkout.stockLocationId=i.id,[2]}))}))},this.onCouponCodeApply=function(){return t(U,void 0,void 0,(function(){var t,s,n,r,o,a;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,y.saveCartCouponCode({cartId:this.checkout.id,couponCode:this.checkout.couponCode||null})];case 1: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,3];case 2:return e.sent(),[3,3];case 3:return[2]}}))}))},this.onSelectedShippingAddressIdChange=function(t){var e,i;if(U.selectedShippingAddressId=t,"-1"===t)U.checkout.shippingAddress=new a;else{var s=null===(i=null===(e=U.store.customerStore.customer)||void 0===e?void 0:e.addresses)||void 0===i?void 0:i.find((function(e){return e.id===t}));s&&(U.checkout.shippingAddress=new a(s))}U.checkout.shippingAddress&&(U.checkout.shippingAddress.checkoutSettings=U.checkoutSettings)},this.onSelectedBillingAddressIdChange=function(t){var e,i;if(U.selectedBillingAddressId=t,"-1"===t)U.checkout.billingAddress=new a;else{var s=null===(i=null===(e=U.store.customerStore.customer)||void 0===e?void 0:e.addresses)||void 0===i?void 0:i.find((function(e){return e.id===t}));s&&(U.checkout.billingAddress=new a(s))}U.checkout.billingAddress&&(U.checkout.billingAddress.checkoutSettings=U.checkoutSettings)},this.onTermsAndConditionsCheckedChange=function(t){U.isTermsAndConditionsChecked=t},this.onCardNumberChange=function(t){if(U.cardData&&(!(t.length>U.cardData.cardNumber.length)||E(t))){var e=(U.cardData.cardNumber||"").split(" ").join(""),i=t.split(" ").join("");i.length>16||(e.length<6&&i.length>=6&&!U.installmentInfo?U.retrieveInstallmentInfo({input:{binNumber:i.slice(0,6),paymentGatewayId:U.checkout.selectedPaymentGateway.id,price:U.checkout.totalFinalPrice}}):i.length<6&&e.length>i.length&&(U.cardData.installmentCount=1,U.installmentInfo=void 0),U.cardData.cardNumber=x(i,4).join(" "))}},this.onCardHolderNameChange=function(t){U.cardData&&(U.cardData.cardHolderName=t)},this.onExpirationDateChange=function(t){var e;if(U.cardData&&(!(t.length>U.cardData.expirationDate.length)||E(t))){if(0===(null===(e=U.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(U.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(U.cardData.expirationDate="".concat(o<10?"0"+o:o," / ").concat(r<10?"0"+r:r))}}}var a=t.split(" / ").join("");a.length>4||(U.cardData.expirationDate=x(a,2).join(" / "))}},this.onCvcChange=function(t){U.cardData&&(t.length>U.cardData.cvv.length&&!E(t)||t.length>4||(U.cardData.cvv=t))},this.saveAddress=function(s){return t(U,void 0,void 0,(function(){var t,r,a,d,c;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,3,,4]),this.shouldSaveAddress&&this.store.customerStore.customer?(t="shipping"===s?this.checkout.shippingAddress:this.checkout.billingAddress,(null===(c=this.store.customerStore.customer.addresses)||void 0===c?void 0:c.find((function(e){return e.id===(null==t?void 0:t.id)})))?[2]:(r=new o(i(i({},t),{title:this.addressTitle||this.t("checkout-page:newAddress"),id:P()})),(a=n(this.store.customerStore.customer)).addresses||(a.addresses=[]),a.addresses.push(r),[4,this.store.customerStore.saveCustomer(a)])):[3,2];case 1:e.sent(),"shipping"===s?(this.checkout.shippingAddress.id=r.id,this.selectedShippingAddressId=r.id||"-1"):(this.checkout.billingAddress.id=r.id,this.selectedBillingAddressId=r.id||"-1"),e.label=2;case 2:return[3,4];case 3:return d=e.sent(),console.error(d),[3,4];case 4:return[2]}}))}))},this.onGoToCartClick=function(){U.router.push("/cart")},this.onBackToShoppingClick=function(){U.router.push("/")},this.onProceedToShippingClick=function(){return t(U,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:j.UNKNOWN}),this.isStepLoading=!1,[3,7];case 7:return[2]}}))}))},this.onProceedToPaymentClick=function(){return t(U,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:j.UNKNOWN}),this.isStepLoading=!1,[3,5];case 5:return[2]}}))}))},this.onCompletePaymentClick=function(){return t(U,void 0,void 0,(function(){var t,i,s;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(),"STRIPE"===(null===(s=this.checkout.selectedPaymentGateway)||void 0===s?void 0:s.code)?((t=document.querySelector("#stripe-form-btn"))&&t.click(),[2]):[4,this.createSaleTransaction()];case 6:return e.sent(),[3,8];case 7:return(i=e.sent()).type?this.error=i:this.error={type:j.UNKNOWN},this.isStepLoading=!1,[3,8];case 8:return[2]}}))}))},this.createSaleTransaction=function(){return t(U,void 0,void 0,(function(){var t,i,s,n,r,o,a,d,c,l;return e(this,(function(e){switch(e.label){case 0:return this.checkout.selectedPaymentGateway?((i=this.isPaymentGatewayHasMasterPass&&this.mpVM.selectedCard)&&(s=this.mpVM.phoneNumber({store:this.store,checkout:this.checkout}))&&(t=s),[4,f.createSaleTransactionWithCart({input:{cartId:this.checkout.id,masterPassDetail:i&&t?{phoneNumber:t,savedCardName:null===(d=this.mpVM.selectedCard)||void 0===d?void 0:d.cardName}:void 0,paymentGatewayId:this.checkout.selectedPaymentGateway.id,paymentMethodDetail:i?void 0:this.checkout.selectedPaymentGateway.paymentMethodType===k.CREDIT_CARD&&this.checkout.selectedPaymentGateway.type===b.INTERNAL&&this.cardData?this.cardData.toInput():void 0}})]):[2];case 1:return n=e.sent(),r=null===(c=null==n?void 0:n.data)||void 0===c?void 0:c.transactionStatus,o=r&&[I.SUCCESS,I.AUTHORIZED].includes(r),a=r===I.PENDING,o?[4,this.getSuccessTransaction()]:[3,4];case 2:return e.sent(),[4,this.onCheckoutTransactionSuccess()];case 3:return e.sent(),[3,5];case 4:if(!a||!(null===(l=null==n?void 0:n.data)||void 0===l?void 0:l.returnSlug))throw{type:j.UNKNOWN};window.location.href=process.env.NEXT_PUBLIC_BASE_URL+n.data.returnSlug,e.label=5;case 5:return[2]}}))}))},this.onCheckoutTransactionSuccess=function(){return t(U,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(){U.changeStep(A.INFO)},this.onBackToShippingClick=function(){U.changeStep(A.SHIPPING)},this.setCustomerConsentGranted=function(t){U.checkout.customer&&(U.checkout.customer.notificationsAccepted=t)},this.setUseDifferentAddress=function(t){U.useDifferentAddress=t,U.useDifferentAddress?(localStorage.setItem("sAddr","1"),U.checkout.billingAddress=U.checkout.billingAddress||new a):(localStorage.removeItem("sAddr"),U.checkout.billingAddress=U.checkout.shippingAddress)},this.setShouldSaveAddress=function(t){U.shouldSaveAddress=t},this.setAddressTitle=function(t){U.addressTitle=t},this.setPaymentGateway=function(i){return t(U,void 0,void 0,(function(){var t,s;return e(this,(function(e){switch(e.label){case 0:return this.paymentGateways.length?"STRIPE"!==(t=this.paymentGateways[i]).code||this.stripeResponse?[3,2]:[4,f.createStripePaymentIntent({input:{cartId:this.checkout.id,paymentGatewayId:t.id||""}})]:[2];case 1:(s=e.sent()).isSuccess&&s.data&&(this.stripeResponse=s.data),e.label=2;case 2:return this.checkout.selectedPaymentGateway=t,this.step!==A.SUCCESS&&(t.paymentMethodType===k.CREDIT_CARD&&t.type===b.INTERNAL&&(this.cardData=new c),this.installmentInfo=void 0),[2]}}))}))},this.setInstallmentCount=function(t){U.cardData&&(U.cardData.installmentCount=t)},this.changeStep=function(i){return t(U,void 0,void 0,(function(){return e(this,(function(t){return R||window.location.replace("".concat(window.location.pathname,"?id=").concat(this.checkout.id,"&step=").concat(i)),[2]}))}))},this.logout=function(){return t(U,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){U.isContactModalVisible=t},this.checkout=w,this.checkoutSettings=N,this.router=O,this.returnPolicy=D,this.privacyPolicy=G,this.termsOfService=M,this.t=L,this.customizationProps=_,this.mpVM=new C,T&&(this.merchantSettings=T),this.isTermsAndConditionsChecked=this.checkoutSettings.isTermsAndConditionsDefaultChecked||!1,this.init(),s(this)}return Object.defineProperty(w.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(w.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(w.prototype,"checkoutUrl",{get:function(){return"/checkout?id=".concat(this.checkout.id,"&step=info")},enumerable:!1,configurable:!0}),Object.defineProperty(w.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(w.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(w.prototype,"installmentExtraPrice",{get:function(){if(this.installmentPrice&&this.checkout.totalFinalPrice)return this.installmentPrice-this.checkout.totalFinalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(w.prototype,"finalPrice",{get:function(){return this.step===A.SUCCESS?this.checkout.totalFinalPrice:this.installmentPrice||this.checkout.$totalFinalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(w.prototype,"hasStockError",{get:function(){var t;return(null===(t=this.error)||void 0===t?void 0:t.type)===j.STOCK_ERROR},enumerable:!1,configurable:!0}),Object.defineProperty(w.prototype,"isPaymentGatewayHasMasterPass",{get:function(){return-1!==this.selectedPaymentGatewayIndex&&(!!this.paymentGateways.length&&!!this.paymentGateways[this.selectedPaymentGatewayIndex].masterPassClientId)},enumerable:!1,configurable:!0}),Object.defineProperty(w.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)!==j.NO_SHIPPING_ERROR},enumerable:!1,configurable:!0}),Object.defineProperty(w.prototype,"canProceedToInStoreDelivery",{get:function(){var t,e,i;return!!((null===(t=this.checkout.shippingAddress)||void 0===t?void 0:t.firstName)&&(null===(e=this.checkout.shippingAddress)||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(w.prototype,"canProceedToPayment",{get:function(){return this.canProceedToShipping},enumerable:!1,configurable:!0}),Object.defineProperty(w.prototype,"isInStoreDelivery",{get:function(){return!!this.checkout.stockLocationId},enumerable:!1,configurable:!0}),Object.defineProperty(w.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?"STRIPE"===i.code||(null===(e=this.cardData)||void 0===e?void 0:e.isValid):!!i)},enumerable:!1,configurable:!0}),w}();function x(t,e){return t.match(new RegExp(".{1,"+e+"}","g"))||[]}function E(t){return t&&w.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"}(j||(j={}));export{A as CheckoutStep,j as ErrorType,N as default};
@@ -0,0 +1,124 @@
1
+ import IkasCheckout from "src/models/data/checkout";
2
+ import { IkasPaymentGateway } from "src/models/data/payment-gateway";
3
+ import { IkasBaseStore } from "src/store";
4
+ import { MasterPassOperationTypeEnum } from "src/__api/types";
5
+ import { OtpModalType } from "./components/master-pass/modal-otp";
6
+ declare type MFS_CB_HOC_TYPE = (params: {
7
+ store: IkasBaseStore;
8
+ checkout: IkasCheckout;
9
+ }) => MFS_CB_TYPE;
10
+ declare type MFS_CB_TYPE = (status: any, response: {
11
+ responseCode: "0000" | /* register success */ "" | /* register success */ "5001" | /* banka tarafindan otp dogrulamasi yapilir */ "5008" | /* masterpass tarafindan otp dogrulamasi yapilir*/ string;
12
+ transactionId: string;
13
+ accountStatus: any;
14
+ responseDescription: any;
15
+ url3D: string;
16
+ cards: number | Array<{
17
+ Name: string;
18
+ Value1: string;
19
+ }>;
20
+ }) => void;
21
+ declare type MFS = {
22
+ checkMasterPass: (formData: FormData, cb: MFS_CB_TYPE) => void;
23
+ setClientId: (a: string) => void;
24
+ register: (formData: FormData, cb: MFS_CB_TYPE) => void;
25
+ resendOtp: (token: string, lang: string, cb: MFS_CB_TYPE) => void;
26
+ validateTransaction: (formData: FormData, cb: MFS_CB_TYPE) => void;
27
+ getLastToken: () => string;
28
+ linkCardToClient: (formData: FormData, cb: MFS_CB_TYPE) => void;
29
+ listCards: (phoneNumber: string, token: string, cb: MFS_CB_TYPE) => void;
30
+ deleteCard: (formData: FormData, cb: MFS_CB_TYPE) => void;
31
+ };
32
+ declare type Card = {
33
+ cardName: string;
34
+ value: string;
35
+ };
36
+ export default class MasterPassModel {
37
+ checkMasterPassData: {
38
+ status: "" | "noMasterPassAccount" | "hasMasterPassAccountButDoesNotHaveAnyOperation" | "hasMasterPassAccountAndHasRelation";
39
+ };
40
+ saveCardToMasterPass: {
41
+ isCheckboxChecked: boolean;
42
+ isSendConfirmationButtonPending: boolean;
43
+ cardName: string;
44
+ phoneNumber: string;
45
+ };
46
+ otpModalType: "" | OtpModalType;
47
+ isOtpModalVisible: boolean;
48
+ isLinkCardToClientModalVisible: boolean;
49
+ cards: Card[];
50
+ selectedCard?: Card;
51
+ constructor();
52
+ get isSendConfirmationButtonDisabled(): boolean;
53
+ onSaveCardToMasterPassCheckedChange: (value: boolean) => void;
54
+ onSaveCardToMasterPassCardNameChange: (value: string) => void;
55
+ onSaveCardToMasterPassPhoneNumberChange: (value: string) => void;
56
+ onSaveCardToMasterPassSendConfirmationButtonClick: ({ creditCard, store, checkout, paymentGateway, }: RegisterParams) => void;
57
+ showLinkCardToClientModal: () => void;
58
+ hideLinkCardToClientModal: () => void;
59
+ showOtpModal: (modalType: OtpModalType) => void;
60
+ hideOtpModal: () => void;
61
+ onLinkCardToClientButtonClick: (params: LinkCardToClientParams) => void;
62
+ onOtpFormSubmit: (params: ValidateTransactionParams) => void;
63
+ MFS: () => MFS | undefined;
64
+ getToken: ({ cartId, paymentGatewayId, operationType, phoneNumber, }: {
65
+ cartId: string;
66
+ paymentGatewayId: string;
67
+ operationType: MasterPassOperationTypeEnum;
68
+ phoneNumber: string;
69
+ }) => Promise<import("src/__api/types").MasterPassTokenResponse | undefined>;
70
+ phoneNumber: ({ store, checkout, }: {
71
+ store: IkasBaseStore;
72
+ checkout: IkasCheckout;
73
+ }) => string | null | undefined;
74
+ sendSmsLanguage: (store: IkasBaseStore) => string;
75
+ prepareFormData<T>(data: T): FormData;
76
+ mfsResponseHandler: MFS_CB_HOC_TYPE;
77
+ checkMasterPass: ({ checkout, store }: CheckMasterPassParams) => Promise<void>;
78
+ register: ({ creditCard, store, checkout, paymentGateway, }: RegisterParams) => Promise<void>;
79
+ resendOtp: ({ store, checkout, }: {
80
+ store: IkasBaseStore;
81
+ checkout: IkasCheckout;
82
+ }) => Promise<void>;
83
+ linkCardToClient: ({ store, checkout }: LinkCardToClientParams) => Promise<void>;
84
+ validateTransaction: ({ validationCode, store, cartId, paymentGateway, checkout, }: ValidateTransactionParams) => Promise<void>;
85
+ listCards: ({ store, checkout }: ListCardsParams) => Promise<void>;
86
+ deleteCard: ({ store, checkout, cardName }: DeleteCardParams) => Promise<void>;
87
+ }
88
+ declare type RegisterParams = {
89
+ creditCard: {
90
+ rtaPan: string;
91
+ expiryDate: string;
92
+ cvc: string;
93
+ accountAliasName: string;
94
+ };
95
+ paymentGateway: IkasPaymentGateway;
96
+ store: IkasBaseStore;
97
+ checkout: IkasCheckout;
98
+ };
99
+ declare type CheckMasterPassParams = {
100
+ checkout: IkasCheckout;
101
+ store: IkasBaseStore;
102
+ };
103
+ declare type LinkCardToClientParams = {
104
+ cartId: string;
105
+ checkout: IkasCheckout;
106
+ store: IkasBaseStore;
107
+ };
108
+ declare type ValidateTransactionParams = {
109
+ cartId: string;
110
+ validationCode: string;
111
+ paymentGateway: IkasPaymentGateway;
112
+ store: IkasBaseStore;
113
+ checkout: IkasCheckout;
114
+ };
115
+ declare type ListCardsParams = {
116
+ store: IkasBaseStore;
117
+ checkout: IkasCheckout;
118
+ };
119
+ declare type DeleteCardParams = {
120
+ store: IkasBaseStore;
121
+ checkout: IkasCheckout;
122
+ cardName: string;
123
+ };
124
+ export {};
@@ -0,0 +1 @@
1
+ import{__awaiter as e,__generator as t}from'../../ext/tslib/tslib.es6.js';import{makeAutoObservable as n}from"mobx";import{IkasStorefrontConfig as s}from"../../storefront/index.js";import o from"../../__api/queries/getMasterpassRequestToken.js";import{MasterPassOperationTypeEnum as a}from"../../__api/types/index.js";var r="undefined"==typeof localStorage,i="/000000[0|1]{10}/g",c="/[0|1]1100[0|1]{11}/g",d="/[0|1]11100[0|1]{10}/g",u=function(){function u(){var u=this;this.checkMasterPassData={status:""},this.saveCardToMasterPass={isCheckboxChecked:!1,cardName:"",phoneNumber:"",isSendConfirmationButtonPending:!1},this.otpModalType="",this.isOtpModalVisible=!1,this.isLinkCardToClientModalVisible=!1,this.cards=[],this.onSaveCardToMasterPassCheckedChange=function(e){u.saveCardToMasterPass.isCheckboxChecked=e},this.onSaveCardToMasterPassCardNameChange=function(e){u.saveCardToMasterPass.cardName=e},this.onSaveCardToMasterPassPhoneNumberChange=function(e){u.saveCardToMasterPass.phoneNumber=e},this.onSaveCardToMasterPassSendConfirmationButtonClick=function(e){var t=e.creditCard,n=e.store,s=e.checkout,o=e.paymentGateway;u.register({creditCard:t,store:n,checkout:s,paymentGateway:o})},this.showLinkCardToClientModal=function(){u.isLinkCardToClientModalVisible=!0},this.hideLinkCardToClientModal=function(){u.isLinkCardToClientModalVisible=!1},this.showOtpModal=function(e){u.isOtpModalVisible=!0,u.otpModalType=e},this.hideOtpModal=function(){u.isOtpModalVisible=!1,u.otpModalType=""},this.onLinkCardToClientButtonClick=function(e){u.linkCardToClient(e)},this.onOtpFormSubmit=function(e){u.validateTransaction(e)},this.MFS=function(){var e;if(!r){if(window.MFS&&(null===(e=window.MFS)||void 0===e?void 0:e.setClientId))return window.MFS;console.error("MFS can not use.")}},this.getToken=function(n){var s=n.cartId,a=n.paymentGatewayId,r=n.operationType,i=n.phoneNumber;return e(u,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,o({cartId:s,paymentGatewayId:a,operationType:r,phoneNumber:i})];case 1:return(e=t.sent()).data&&e.isSuccess&&!e.errors.length?[2,e.data]:[2]}}))}))},this.phoneNumber=function(e){var t,n,s=e.store,o=e.checkout;return(null===(t=s.customerStore.customer)||void 0===t?void 0:t.phone)||(null===(n=o.shippingAddress)||void 0===n?void 0:n.phone)},this.sendSmsLanguage=function(e){var t,n="eng";if(e.localeOptions.length){var o=e.localeOptions.find((function(e){return e.routing.locale===s.getCurrentLocale()}));o&&o.iso3&&(n=null===(t=o.iso3)||void 0===t?void 0:t.toLowerCase())}return n},this.mfsResponseHandler=function(e){return function(t,n){var s=function(e){return n.accountStatus.match(e)};if(s(i)&&(u.checkMasterPassData.status="noMasterPassAccount"),s(c)&&(u.checkMasterPassData.status="hasMasterPassAccountButDoesNotHaveAnyOperation",u.showLinkCardToClientModal()),s(d)&&(u.checkMasterPassData.status="hasMasterPassAccountAndHasRelation",(null==e?void 0:e.checkout)&&e.store&&u.listCards({store:e.store,checkout:e.checkout}),console.log("call listcards")),"0000"!=n.responseCode&&""!=n.responseCode)if("5001"!=n.responseCode&&"5008"!=n.responseCode)"5010"!=n.responseCode||"undefined"==typeof window?console.error("MFS response.responseDescription",n.responseDescription):window.location.assign(n.url3D+"&returnUrl="+window.location.href);else{var o="5001"===n.responseCode?"bankOtp":"masterPassOtp";u.showOtpModal(o)}else console.log("Register Success")}},this.checkMasterPass=function(n){var s=n.checkout,o=n.store;return e(u,void 0,void 0,(function(){var e,n,r,i,c,d,u;return t(this,(function(t){switch(t.label){case 0:return(e=this.MFS())&&((n=this.phoneNumber({store:o,checkout:s}))&&(null===(d=s.selectedPaymentGateway)||void 0===d?void 0:d.id)&&(null===(u=s.selectedPaymentGateway)||void 0===u?void 0:u.masterPassClientId))?[4,this.getToken({cartId:s.id,paymentGatewayId:s.selectedPaymentGateway.id,operationType:a.CHECK_MASTER_PASS_USER,phoneNumber:n})]:[2];case 1:return(r=t.sent())?(e.setClientId(s.selectedPaymentGateway.masterPassClientId),i=this.sendSmsLanguage(o),c=this.prepareFormData({sendSmsLanguage:i,sendSms:"N",referenceNo:r.requestReferenceNumber,token:r.token,userId:n}),e.checkMasterPass(c,this.mfsResponseHandler({checkout:s,store:o})),[2]):[2]}}))}))},this.register=function(n){var s=n.creditCard,o=n.store,r=n.checkout,i=n.paymentGateway;return e(u,void 0,void 0,(function(){var e,n,c,d;return t(this,(function(t){switch(t.label){case 0:return(e=this.MFS())&&(n=this.phoneNumber({store:o,checkout:r}))?[4,this.getToken({cartId:r.id,paymentGatewayId:i.id,operationType:a.REGISTER_CARD,phoneNumber:n})]:[2];case 1:return(null==(c=t.sent())?void 0:c.token)?(d=this.prepareFormData({msisdn:n,token:null==c?void 0:c.token,referenceNo:c.requestReferenceNumber,sendSmsLanguage:this.sendSmsLanguage(o),rtaPan:s.rtaPan,expiryDate:s.expiryDate,cvc:s.cvc,accountAliasName:s.accountAliasName,timeZone:c.timeZone,sendSms:"Y",actionType:"A",clientIp:"",delinkReason:"",eActionType:"A",cardTypeFlag:"05",cpinFlag:"Y",defaultAccount:"Y",mmrpConfig:"110010",identityVerificationFlag:"Y",mobileAccountConfig:"MWA",uiChannelType:"6"}),e.register(d,this.mfsResponseHandler({store:o,checkout:r})),[2]):[2]}}))}))},this.resendOtp=function(n){var s=n.store,o=n.checkout;return e(u,void 0,void 0,(function(){var e,n,a;return t(this,(function(t){return(e=this.MFS())?(n=e.getLastToken(),a=this.sendSmsLanguage(s),e.resendOtp(n,a,this.mfsResponseHandler({store:s,checkout:o})),[2]):[2]}))}))},this.linkCardToClient=function(n){var s=n.store,o=n.checkout;return e(u,void 0,void 0,(function(){var e,n,r,i;return t(this,(function(t){switch(t.label){case 0:return(e=this.MFS())&&((n=this.phoneNumber({store:s,checkout:o}))&&o.selectedPaymentGateway)?[4,this.getToken({cartId:o.id,paymentGatewayId:o.selectedPaymentGateway.id,operationType:a.REGISTER_CARD,phoneNumber:n})]:[2];case 1:return(r=t.sent())?(i=this.prepareFormData({sendSms:"Y",sendSmsLanguage:this.sendSmsLanguage(s),token:r.token,referenceNo:r.requestReferenceNumber,cardAliasName:"",msisdn:n}),e.linkCardToClient(i,this.mfsResponseHandler({store:s,checkout:o})),[2]):[2]}}))}))},this.validateTransaction=function(n){var s=n.validationCode,o=n.store,r=n.cartId,i=n.paymentGateway,c=n.checkout;return e(u,void 0,void 0,(function(){var e,n,d,u;return t(this,(function(t){switch(t.label){case 0:return(e=this.MFS())&&(n=this.phoneNumber({store:o,checkout:c}))?[4,this.getToken({cartId:r,paymentGatewayId:i.id,operationType:a.REGISTER_CARD,phoneNumber:n})]:[2];case 1:return(d=t.sent())?(u=this.prepareFormData({pinType:"otp",validationCode:s,sendSms:"Y",sendSmsLanguage:this.sendSmsLanguage(o),token:d.token,referenceNo:d.requestReferenceNumber}),e.validateTransaction(u,this.mfsResponseHandler({store:o,checkout:c})),[2]):[2]}}))}))},this.listCards=function(n){var s=n.store,o=n.checkout;return e(u,void 0,void 0,(function(){var e,n,r,i,c,d=this;return t(this,(function(t){switch(t.label){case 0:return(e=this.MFS())&&((n=this.phoneNumber({store:s,checkout:o}))&&(r=o.selectedPaymentGateway))?[4,this.getToken({cartId:o.id,paymentGatewayId:r.id,operationType:a.LIST_CARDS,phoneNumber:n})]:[2];case 1:return(i=t.sent())?(c=function(e,t){if("0000"!=t.responseCode&&""!=t.responseCode)return console.error("mfs response.responseDescription",t.responseDescription),void console.log("TransactionID->",t.transactionId);var n=[];if(Array.isArray(t.cards))for(var s=0;s<t.cards.length;s++){var o=t.cards[s];n.push({cardName:o.Name,value:o.Value1})}d.cards=n,console.log("list_card response->",t),console.log("Cards",n),console.log("TransactionID->",t.transactionId)},e.listCards(n,i.token,c),[2]):[2]}}))}))},this.deleteCard=function(n){var s=n.store,o=n.checkout,r=n.cardName;return e(u,void 0,void 0,(function(){var e,n,i,c,d,u;return t(this,(function(t){switch(t.label){case 0:return(e=this.MFS())&&((n=this.phoneNumber({store:s,checkout:o}))&&(null===(d=o.selectedPaymentGateway)||void 0===d?void 0:d.id))?[4,this.getToken({cartId:o.id,paymentGatewayId:null===(u=o.selectedPaymentGateway)||void 0===u?void 0:u.id,operationType:a.DELETE_CARD,phoneNumber:n})]:[2];case 1:return(i=t.sent())?(c=this.prepareFormData({sendSms:"N",msisdn:n,token:i.token,referenceNo:i.requestReferenceNumber,sendSmsLanguage:this.sendSmsLanguage(s),accountAliasName:r}),e.deleteCard(c,this.mfsResponseHandler({store:s,checkout:o})),[2]):[2]}}))}))},n(this)}return Object.defineProperty(u.prototype,"isSendConfirmationButtonDisabled",{get:function(){return!(!this.saveCardToMasterPass.cardName||!this.saveCardToMasterPass.phoneNumber)},enumerable:!1,configurable:!0}),u.prototype.prepareFormData=function(e){var t=new FormData;return Object.entries(e).forEach((function(e){var n=e[0],s=e[1];return t.append(n,s)})),t},u}();export{u as default};
@@ -1 +1 @@
1
- import*as e from"react";import{observer as t}from"mobx-react-lite";import"../../../../../models/data/payment-gateway/index.js";import{CreditCardForm as n}from"../../../components/credit-card-form/index.js";import{Installments as o}from"./installments/index.js";import r from"../../../components/select-box/index.js";import a from"./style.module.scss.js";import"../../../../../storefront/index.js";import'../../../../../ext/lodash/isArguments.js';import'../../../../../ext/lodash/isBuffer.js';import'../../../../../ext/lodash/isTypedArray.js';import'../../../../../ext/lodash/_baseGetTag.js';import{formatMoney as l}from"../../../../../utils/currency.js";import{useTranslation as m}from"../../../../../utils/i18n.js";import i from"../../../components/svg/external.js";import{StripeForm as s}from"../../../components/stripe/index.js";import{PaymentMethodEnum as c,PaymentGatewayTypeEnum as d,PaymentGatewayTransactionFeeTypeEnum as p,PaymentGatewayAdditionalPriceTypeEnum as u}from"../../../../../__api/types/index.js";var y=t((function(t){var y=t.vm,f=m().t,E=function(t){return e.createElement("div",{style:{display:"flex",justifyContent:"flex-end",alignItems:"center",flexWrap:"wrap"}},t.children)},g=function(t){return e.createElement("div",{className:a.AdditionalPrice},t.children)};return e.createElement(e.Fragment,null,y.paymentGateways.map((function(t,m){var v,h,x;return e.createElement(r,{key:t.id,label:t.paymentMethodType===c.CREDIT_CARD&&t.type===d.INTERNAL?f("checkout-page:creditCard"):t.name,isSelected:y.selectedPaymentGatewayIndex===m,rightContent:(null===(v=t.additionalPrices)||void 0===v?void 0:v.length)?e.createElement(g,null,(x=t.additionalPrices[0],0===x.amount?"":"".concat(x.amountType===p.AMOUNT?l(x.amount,y.checkout.currencyCode):" %"+x.amount).concat(x.type===u.DECREMENT?" "+f("checkout-page:paymentMethodDiscount"):" "+f("checkout-page:paymentMethodAdditionalPrice")))):e.createElement(E,null,!!t.logoUrl&&e.createElement("div",{className:a.PaymentLogoContainer},e.createElement("img",{src:t.logoUrl}))),bottomContent:t.paymentMethodType===c.CREDIT_CARD&&t.type===d.INTERNAL?e.createElement(e.Fragment,null,"STRIPE"===t.code&&(null===(h=t.settings)||void 0===h?void 0:h.find((function(e){return"allow_custom_flow"===e.label&&"true"===e.value})))?e.createElement(s,{vm:y,pg:t}):e.createElement("div",null,e.createElement(n,{vm:y}),y.installmentInfo&&e.createElement(o,{vm:y}))):t.description?e.createElement(e.Fragment,null,t.type===d.EXTERNAL&&e.createElement("div",{style:{height:"52px",display:"flex",justifyContent:"center",margin:"24px 0"}},e.createElement(i,null)),e.createElement("div",{dangerouslySetInnerHTML:{__html:t.description}})):void 0,onClick:function(){return y.selectedPaymentGatewayIndex!==m&&y.setPaymentGateway(m)}})})))}));export{y as PaymentGateways};
1
+ import*as e from"react";import{observer as t}from"mobx-react-lite";import"../../../../../models/data/payment-gateway/index.js";import{CreditCardForm as n}from"../../../components/credit-card-form/index.js";import{Installments as a}from"./installments/index.js";import r from"../../../components/select-box/index.js";import o from"./style.module.scss.js";import"../../../../../storefront/index.js";import'../../../../../ext/lodash/isArguments.js';import'../../../../../ext/lodash/isBuffer.js';import'../../../../../ext/lodash/isTypedArray.js';import'../../../../../ext/lodash/_baseGetTag.js';import{formatMoney as l}from"../../../../../utils/currency.js";import{useTranslation as m}from"../../../../../utils/i18n.js";import s from"../../../components/svg/external.js";import c from"../../../components/master-pass/payment-gateway/svg/master-card.js";import{StripeForm as i}from"../../../components/stripe/index.js";import{PaymentMethodEnum as d,PaymentGatewayTypeEnum as p,PaymentGatewayTransactionFeeTypeEnum as u,PaymentGatewayAdditionalPriceTypeEnum as y}from"../../../../../__api/types/index.js";var f=t((function(t){var f=t.vm,E=m().t,g=function(t){return e.createElement("div",{style:{display:"flex",justifyContent:"flex-end",alignItems:"center",flexWrap:"wrap"}},t.children)},v=function(t){return e.createElement("div",{className:o.AdditionalPrice},t.children)};return e.createElement(e.Fragment,null,f.isPaymentGatewayHasMasterPass&&f.mpVM.cards.map((function(t,n){var a;return e.createElement(r,{key:n,label:e.createElement("div",null,e.createElement("span",{className:o.MasterPassSelectBoxLabelLogo},e.createElement(c,null)),t.cardName," ",t.value),rightContent:e.createElement("button",{className:o.MasterPassSelectBoxDeleteButton,onClick:function(){return f.mpVM.deleteCard({store:f.store,checkout:f.checkout,cardName:t.cardName})}},E("checkout-page:masterPass.paymentGatewaySelectBox.delete")),isSelected:(null===(a=f.mpVM.selectedCard)||void 0===a?void 0:a.cardName)===t.cardName})})),f.paymentGateways.map((function(t,m){var c,h,x;return e.createElement(r,{key:t.id,label:t.paymentMethodType===d.CREDIT_CARD&&t.type===p.INTERNAL?E("checkout-page:creditCard"):t.name,isSelected:f.selectedPaymentGatewayIndex===m,rightContent:(null===(c=t.additionalPrices)||void 0===c?void 0:c.length)?e.createElement(v,null,(x=t.additionalPrices[0],0===x.amount?"":"".concat(x.amountType===u.AMOUNT?l(x.amount,f.checkout.currencyCode):" %"+x.amount).concat(x.type===y.DECREMENT?" "+E("checkout-page:paymentMethodDiscount"):" "+E("checkout-page:paymentMethodAdditionalPrice")))):e.createElement(g,null,!!t.logoUrl&&e.createElement("div",{className:o.PaymentLogoContainer},e.createElement("img",{src:t.logoUrl}))),bottomContent:t.paymentMethodType===d.CREDIT_CARD&&t.type===p.INTERNAL?e.createElement(e.Fragment,null,"STRIPE"===t.code&&(null===(h=t.settings)||void 0===h?void 0:h.find((function(e){return"allow_custom_flow"===e.label&&"true"===e.value})))?e.createElement(i,{vm:f,pg:t}):e.createElement("div",null,e.createElement(n,{vm:f}),f.installmentInfo&&e.createElement(a,{vm:f}))):t.description?e.createElement(e.Fragment,null,t.type===p.EXTERNAL&&e.createElement("div",{style:{height:"52px",display:"flex",justifyContent:"center",margin:"24px 0"}},e.createElement(s,null)),e.createElement("div",{dangerouslySetInnerHTML:{__html:t.description}})):void 0,onClick:function(){return f.selectedPaymentGatewayIndex!==m&&f.setPaymentGateway(m)}})})))}));export{f as PaymentGateways};
@@ -1 +1 @@
1
- import e from'../../../../../ext/style-inject/dist/style-inject.es.js';var n={PaymentLogoContainer:"style-module_PaymentLogoContainer__224HZ",AdditionalPrice:"style-module_AdditionalPrice__gW28c"};e(".style-module_PaymentLogoContainer__224HZ {\n margin-left: 10px;\n font-size: 0.7em;\n}\n.style-module_PaymentLogoContainer__224HZ img {\n height: 20px;\n}\n\n.style-module_AdditionalPrice__gW28c {\n color: var(--checkout-primary-text-color);\n font-weight: 600;\n}");export{n as default};
1
+ import e from'../../../../../ext/style-inject/dist/style-inject.es.js';var t={PaymentLogoContainer:"style-module_PaymentLogoContainer__224HZ",AdditionalPrice:"style-module_AdditionalPrice__gW28c",MasterPassSelectBoxDeleteButton:"style-module_MasterPassSelectBoxDeleteButton__3ACqy",MasterPassSelectBoxLabelLogo:"style-module_MasterPassSelectBoxLabelLogo__2AcTF"};e(".style-module_PaymentLogoContainer__224HZ {\n margin-left: 10px;\n font-size: 0.7em;\n}\n.style-module_PaymentLogoContainer__224HZ img {\n height: 20px;\n}\n\n.style-module_AdditionalPrice__gW28c {\n color: var(--checkout-primary-text-color);\n font-weight: 600;\n}\n\n.style-module_MasterPassSelectBoxDeleteButton__3ACqy {\n font-size: 14px;\n line-height: 20px;\n color: var(--checkout-primary-text-color);\n}\n\n.style-module_MasterPassSelectBoxLabelLogo__2AcTF {\n display: inline-block;\n margin-right: 12px;\n}");export{t as default};