@ikas/storefront 0.0.110 → 0.0.112

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.js CHANGED
@@ -10912,6 +10912,8 @@ var IkasStorefrontConfig = /** @class */ (function () {
10912
10912
  priceListId: IkasStorefrontConfig.priceListId || null,
10913
10913
  stockLocationIds: IkasStorefrontConfig.stockLocationIds || null,
10914
10914
  routings: JSON.parse(JSON.stringify(IkasStorefrontConfig.routings)) || null,
10915
+ paymentGateways: JSON.parse(JSON.stringify(IkasStorefrontConfig.paymentGateways)) ||
10916
+ null,
10915
10917
  gtmId: IkasStorefrontConfig.gtmId || null,
10916
10918
  fbpId: IkasStorefrontConfig.fbpId || null,
10917
10919
  };
@@ -10920,6 +10922,7 @@ var IkasStorefrontConfig = /** @class */ (function () {
10920
10922
  IkasStorefrontConfig.config = {};
10921
10923
  IkasStorefrontConfig.apiUrlOverride = null;
10922
10924
  IkasStorefrontConfig.routings = [];
10925
+ IkasStorefrontConfig.paymentGateways = [];
10923
10926
  return IkasStorefrontConfig;
10924
10927
  }());
10925
10928
 
@@ -15843,1952 +15846,20 @@ function cloneDeep$1(value) {
15843
15846
 
15844
15847
  var cloneDeep_1 = cloneDeep$1;
15845
15848
 
15846
- var IkasPaymentMethodType;
15847
- (function (IkasPaymentMethodType) {
15848
- IkasPaymentMethodType["BUY_ONLINE_PAY_AT_STORE"] = "BUY_ONLINE_PAY_AT_STORE";
15849
- IkasPaymentMethodType["CASH"] = "CASH";
15850
- IkasPaymentMethodType["CASH_ON_DELIVERY"] = "CASH_ON_DELIVERY";
15851
- IkasPaymentMethodType["CREDIT_CARD"] = "CREDIT_CARD";
15852
- IkasPaymentMethodType["GIFT_CARD"] = "GIFT_CARD";
15853
- IkasPaymentMethodType["MONEY_ORDER"] = "MONEY_ORDER";
15854
- IkasPaymentMethodType["OTHER"] = "OTHER";
15855
- })(IkasPaymentMethodType || (IkasPaymentMethodType = {}));
15849
+ /** Built-in value references. */
15850
+ var spreadableSymbol = _Symbol ? _Symbol.isConcatSpreadable : undefined;
15856
15851
 
15857
- var CreditCardData = /** @class */ (function () {
15858
- function CreditCardData(data) {
15859
- var _this = this;
15860
- if (data === void 0) { data = {}; }
15861
- this.installmentCount = 1;
15862
- this.toInput = function () {
15863
- var dateParts = _this.expirationDate.split(" / ");
15864
- var expiredMonth = parseInt(dateParts[0]);
15865
- var expiredYear = parseInt(dateParts[1]);
15866
- return {
15867
- cardNumber: _this.cardNumber.split(" ").join(""),
15868
- cardHolderName: _this.cardHolderName,
15869
- cvv: _this.cvv,
15870
- expiredMonth: expiredMonth,
15871
- expiredYear: expiredYear,
15872
- installmentCount: _this.installmentCount,
15873
- threeDSecure: _this.threeDSecure,
15874
- };
15875
- };
15876
- this.cardNumber = data.cardNumber || "";
15877
- this.cardHolderName = data.cardHolderName || "";
15878
- this.expirationDate = data.expirationDate || "";
15879
- this.cvv = data.cvv || "";
15880
- this.installmentCount = data.installmentCount || 1;
15881
- this.threeDSecure = data.threeDSecure || false;
15882
- mobx.makeAutoObservable(this);
15883
- }
15884
- Object.defineProperty(CreditCardData.prototype, "validationResult", {
15885
- get: function () {
15886
- return {
15887
- cardNumber: !!this.cardNumber && this.cardNumber.length === 19,
15888
- cardHolderName: !!this.cardHolderName,
15889
- expirationDate: !!this.expirationDate && this.expirationDate.length === 7,
15890
- cvv: !!this.cvv,
15891
- };
15892
- },
15893
- enumerable: false,
15894
- configurable: true
15895
- });
15896
- Object.defineProperty(CreditCardData.prototype, "isValid", {
15897
- get: function () {
15898
- return Object.values(this.validationResult).every(function (result) { return result; });
15899
- },
15900
- enumerable: false,
15901
- configurable: true
15902
- });
15903
- return CreditCardData;
15904
- }());
15905
-
15906
- var NUMBER_ONLY_REGEX = /^\d+$/;
15907
- var MAX_CARD_NUMBER_LENGTH = 16;
15908
- var MAX_CVC_LENGTH = 4;
15909
- var USE_DIFFERENT_ADDRESS_KEY = "sAddr";
15910
- var isServer$1 = typeof localStorage === "undefined";
15911
- var CheckoutViewModel = /** @class */ (function () {
15912
- function CheckoutViewModel(checkout, checkoutSettings, queryParams, router, returnPolicy, privacyPolicy, termsOfService) {
15913
- var _this = this;
15914
- this.checkout = new IkasCheckout();
15915
- this.checkoutSettings = new IkasCheckoutSettings();
15916
- this.storefront = null;
15917
- this.customerStore = new IkasCustomerStore();
15918
- this.isCheckoutLoaded = false;
15919
- this.isErrorsVisible = false;
15920
- this.isStepLoading = false;
15921
- this.isTermsAndConditionsChecked = false;
15922
- this.step = CheckoutStep.INFO;
15923
- this.cardData = null;
15924
- this.paymentGatewayId = null;
15925
- this.paymentGateways = [];
15926
- this.installmentInfo = null;
15927
- this.useDifferentAddress = false;
15928
- this.shouldSaveAddress = false;
15929
- this.addressTitle = "";
15930
- this.shippingCountryIds = null;
15931
- this.selectedShippingAddressId = "-1";
15932
- this.selectedBillingAddressId = "-1";
15933
- this.policyModalTitle = "";
15934
- this.policyModalText = "";
15935
- this.error = null;
15936
- this.init = function (queryParams) { return __awaiter(_this, void 0, void 0, function () {
15937
- var merchantId, _a;
15938
- return __generator(this, function (_b) {
15939
- switch (_b.label) {
15940
- case 0:
15941
- this.createCustomer();
15942
- this.createShippingAddress();
15943
- this.createBillingAddress();
15944
- if (typeof queryParams.step === "string") {
15945
- this.step = queryParams.step;
15946
- if (this.step === CheckoutStep.SHIPPING && !this.canProceedToShipping) {
15947
- this.changeStep(CheckoutStep.INFO);
15948
- return [2 /*return*/];
15949
- }
15950
- else if (this.step === CheckoutStep.PAYMENT &&
15951
- !this.canProceedToPayment) {
15952
- this.changeStep(CheckoutStep.INFO);
15953
- return [2 /*return*/];
15954
- }
15955
- else if (![
15956
- CheckoutStep.INFO,
15957
- CheckoutStep.SUCCESS,
15958
- CheckoutStep.SHIPPING,
15959
- CheckoutStep.PAYMENT,
15960
- ].includes(this.step)) {
15961
- this.changeStep(CheckoutStep.INFO);
15962
- return [2 /*return*/];
15963
- }
15964
- }
15965
- if (typeof queryParams.failed === "string") {
15966
- this.error = {
15967
- type: ErrorType.PAYMENT_ERROR,
15968
- data: queryParams.error || null,
15969
- };
15970
- }
15971
- merchantId = decodeBase64(IkasStorefrontConfig.config.apiKey || "");
15972
- _a = this;
15973
- return [4 /*yield*/, IkasMerchantAPI.listMerchantSettings(merchantId)];
15974
- case 1:
15975
- _a.merchantSettings = _b.sent();
15976
- if (!(this.step === CheckoutStep.INFO)) return [3 /*break*/, 3];
15977
- return [4 /*yield*/, this.getShippingCountries()];
15978
- case 2:
15979
- _b.sent();
15980
- this.checkShippingCountries();
15981
- _b.label = 3;
15982
- case 3:
15983
- if (!(this.step === CheckoutStep.PAYMENT)) return [3 /*break*/, 5];
15984
- return [4 /*yield*/, this.listPaymentGateways()];
15985
- case 4:
15986
- _b.sent();
15987
- _b.label = 5;
15988
- case 5:
15989
- this.isCheckoutLoaded = true;
15990
- return [2 /*return*/];
15991
- }
15992
- });
15993
- }); };
15994
- // VALIDATIONS END
15995
- this.saveCheckout = function () { return __awaiter(_this, void 0, void 0, function () {
15996
- var updatedCheckoutId;
15997
- return __generator(this, function (_a) {
15998
- switch (_a.label) {
15999
- case 0: return [4 /*yield*/, IkasCheckoutAPI.saveCheckout(this.checkout)];
16000
- case 1:
16001
- updatedCheckoutId = _a.sent();
16002
- if (!updatedCheckoutId)
16003
- throw {
16004
- type: ErrorType.API_ERROR,
16005
- };
16006
- return [2 /*return*/];
16007
- }
16008
- });
16009
- }); };
16010
- this.checkStocks = function () { return __awaiter(_this, void 0, void 0, function () {
16011
- var lines, result, unavailableItems, data;
16012
- var _this = this;
16013
- var _a;
16014
- return __generator(this, function (_b) {
16015
- switch (_b.label) {
16016
- case 0:
16017
- lines = this.cart.items.map(function (i) { return ({
16018
- quantity: i.quantity,
16019
- variantId: i.variant.id,
16020
- productId: i.variant.productId,
16021
- }); });
16022
- return [4 /*yield*/, IkasCheckoutAPI.checkStocks(lines, IkasStorefrontConfig.stockLocationIds || [])];
16023
- case 1:
16024
- result = _b.sent();
16025
- if (!result) {
16026
- throw {
16027
- type: ErrorType.API_ERROR,
16028
- };
16029
- }
16030
- unavailableItems = (_a = result.lines) === null || _a === void 0 ? void 0 : _a.filter(function (i) { return !i.isAvailable; });
16031
- if (unavailableItems === null || unavailableItems === void 0 ? void 0 : unavailableItems.length) {
16032
- data = unavailableItems.map(function (item) { return ({
16033
- variant: _this.cart.items.find(function (i) { return i.variant.id === item.variantId; })
16034
- .variant,
16035
- availableQuantity: item.stockCount,
16036
- }); });
16037
- throw {
16038
- type: ErrorType.STOCK_ERROR,
16039
- data: data,
16040
- };
16041
- }
16042
- return [2 /*return*/];
16043
- }
16044
- });
16045
- }); };
16046
- this.getShippingCountries = function () { return __awaiter(_this, void 0, void 0, function () {
16047
- var _a;
16048
- return __generator(this, function (_b) {
16049
- switch (_b.label) {
16050
- case 0:
16051
- _a = this;
16052
- return [4 /*yield*/, IkasCountryAPI.listShippingCountries(IkasStorefrontConfig.salesChannelId)];
16053
- case 1:
16054
- _a.shippingCountryIds = _b.sent();
16055
- return [2 /*return*/];
16056
- }
16057
- });
16058
- }); };
16059
- this.checkShippingCountries = function () {
16060
- var _a;
16061
- if (!((_a = _this.shippingCountryIds) === null || _a === void 0 ? void 0 : _a.length)) {
16062
- _this.error = {
16063
- type: ErrorType.NO_SHIPPING_ERROR,
16064
- };
16065
- }
16066
- };
16067
- this.initialStockCheck = function () { return __awaiter(_this, void 0, void 0, function () {
16068
- var err_1;
16069
- return __generator(this, function (_a) {
16070
- switch (_a.label) {
16071
- case 0:
16072
- _a.trys.push([0, 2, , 3]);
16073
- return [4 /*yield*/, this.checkStocks()];
16074
- case 1:
16075
- _a.sent();
16076
- return [3 /*break*/, 3];
16077
- case 2:
16078
- err_1 = _a.sent();
16079
- if (err_1.type) {
16080
- this.error = err_1;
16081
- }
16082
- else {
16083
- console.log(err_1);
16084
- this.error = {
16085
- type: ErrorType.UNKNOWN,
16086
- };
16087
- }
16088
- return [3 /*break*/, 3];
16089
- case 3: return [2 /*return*/];
16090
- }
16091
- });
16092
- }); };
16093
- this.listPaymentGateways = function () { return __awaiter(_this, void 0, void 0, function () {
16094
- var paymentGateways;
16095
- return __generator(this, function (_a) {
16096
- switch (_a.label) {
16097
- case 0: return [4 /*yield*/, IkasCheckoutAPI.listPaymentGateway()];
16098
- case 1:
16099
- paymentGateways = _a.sent();
16100
- if (!paymentGateways) {
16101
- this.error = {
16102
- type: ErrorType.API_ERROR,
16103
- };
16104
- return [2 /*return*/];
16105
- }
16106
- this.paymentGateways = paymentGateways;
16107
- if (!this.paymentGatewayId)
16108
- this.setPaymentGateway(0);
16109
- return [2 /*return*/];
16110
- }
16111
- });
16112
- }); };
16113
- this.retrieveInstallmentInfo = function (input) { return __awaiter(_this, void 0, void 0, function () {
16114
- var installmentInfo;
16115
- return __generator(this, function (_a) {
16116
- switch (_a.label) {
16117
- case 0: return [4 /*yield*/, IkasCheckoutAPI.retrieveInstallmentInfo(input)];
16118
- case 1:
16119
- installmentInfo = _a.sent();
16120
- installmentInfo === null || installmentInfo === void 0 ? void 0 : installmentInfo.installmentPrices.sort(function (a, b) {
16121
- return (a.installmentCount || -1) > (b.installmentCount || -1) ? 1 : -1;
16122
- });
16123
- this.installmentInfo = installmentInfo;
16124
- return [2 /*return*/];
16125
- }
16126
- });
16127
- }); };
16128
- this.createCustomer = function () {
16129
- if (_this.customerStore.customer) {
16130
- _this.checkout.customer = _this.customerStore.customer;
16131
- }
16132
- else if (!_this.checkout.customer)
16133
- _this.checkout.customer = new IkasCustomer({});
16134
- };
16135
- this.createShippingAddress = function () {
16136
- if (!_this.checkout.shippingAddress)
16137
- _this.checkout.shippingAddress = new IkasOrderAddress();
16138
- _this.checkout.shippingAddress.checkoutSettings = _this.checkoutSettings;
16139
- };
16140
- this.createBillingAddress = function () {
16141
- if (typeof localStorage !== "undefined") {
16142
- _this.useDifferentAddress = !!localStorage.getItem(USE_DIFFERENT_ADDRESS_KEY);
16143
- if (_this.useDifferentAddress) {
16144
- _this.checkout.billingAddress =
16145
- _this.checkout.billingAddress || new IkasOrderAddress();
16146
- }
16147
- else {
16148
- _this.checkout.billingAddress = new IkasOrderAddress(cloneDeep_1(_this.checkout.shippingAddress) || {});
16149
- }
16150
- }
16151
- };
16152
- this.onEmailChange = function (value) {
16153
- _this.checkout.customer.email = value;
16154
- };
16155
- this.onShippingMethodChange = function (shippingMethod) { return __awaiter(_this, void 0, void 0, function () {
16156
- var newCheckout;
16157
- return __generator(this, function (_a) {
16158
- switch (_a.label) {
16159
- case 0:
16160
- this.checkout.shippingSettingsId = shippingMethod.shippingSettingsId;
16161
- this.checkout.shippingZoneRateId = shippingMethod.shippingZoneRateId;
16162
- return [4 /*yield*/, this.saveCheckout()];
16163
- case 1:
16164
- _a.sent();
16165
- return [4 /*yield*/, IkasCheckoutAPI.getCheckoutById(this.checkout.id)];
16166
- case 2:
16167
- newCheckout = _a.sent();
16168
- if (newCheckout)
16169
- this.checkout = newCheckout;
16170
- return [2 /*return*/];
16171
- }
16172
- });
16173
- }); };
16174
- this.onCouponCodeChange = function (value) {
16175
- _this.checkout.couponCode = value;
16176
- };
16177
- this.onSelectedShippingAddressIdChange = function (value) {
16178
- var _a;
16179
- _this.selectedShippingAddressId = value;
16180
- if (value === "-1") {
16181
- _this.checkout.shippingAddress = new IkasOrderAddress();
16182
- }
16183
- else {
16184
- var address = (_a = _this.customerStore.customer) === null || _a === void 0 ? void 0 : _a.addresses.find(function (a) { return a.id === value; });
16185
- if (address)
16186
- _this.checkout.shippingAddress = new IkasOrderAddress(address);
16187
- }
16188
- };
16189
- this.onSelectedBillingAddressIdChange = function (value) {
16190
- var _a;
16191
- _this.selectedBillingAddressId = value;
16192
- if (value === "-1") {
16193
- _this.checkout.billingAddress = new IkasOrderAddress();
16194
- }
16195
- else {
16196
- var address = (_a = _this.customerStore.customer) === null || _a === void 0 ? void 0 : _a.addresses.find(function (a) { return a.id === value; });
16197
- if (address)
16198
- _this.checkout.billingAddress = new IkasOrderAddress(address);
16199
- }
16200
- };
16201
- this.onTermsAndConditionsCheckedChange = function (value) {
16202
- _this.isTermsAndConditionsChecked = value;
16203
- };
16204
- // CREDIT CARD START
16205
- this.onCardNumberChange = function (value) {
16206
- if (!_this.cardData)
16207
- return;
16208
- if (value.length > _this.cardData.cardNumber.length &&
16209
- !isLastCharNumber(value))
16210
- return;
16211
- var oldOriginalValue = (_this.cardData.cardNumber || "")
16212
- .split(" ")
16213
- .join("");
16214
- var originalValue = value.split(" ").join("");
16215
- if (originalValue.length > MAX_CARD_NUMBER_LENGTH)
16216
- return;
16217
- if (oldOriginalValue.length < 6 && originalValue.length >= 6) {
16218
- _this.retrieveInstallmentInfo({
16219
- binNumber: originalValue.slice(0, 6),
16220
- paymentGatewayId: _this.paymentGatewayId,
16221
- price: _this.checkout.totalFinalPrice,
16222
- });
16223
- }
16224
- // Deleting characters below 6
16225
- else if (originalValue.length < 6 &&
16226
- oldOriginalValue.length > originalValue.length) {
16227
- _this.cardData.installmentCount = 1;
16228
- _this.installmentInfo = undefined;
16229
- }
16230
- _this.cardData.cardNumber = chunkString(originalValue, 4).join(" ");
16231
- };
16232
- this.onCardHolderNameChange = function (value) {
16233
- if (!_this.cardData)
16234
- return;
16235
- _this.cardData.cardHolderName = value;
16236
- };
16237
- this.onExpirationDateChange = function (value) {
16238
- if (!_this.cardData)
16239
- return;
16240
- if (value.length > _this.cardData.expirationDate.length &&
16241
- !isLastCharNumber(value)) {
16242
- return;
16243
- }
16244
- var originalValue = value.split(" / ").join("");
16245
- if (originalValue.length > 4)
16246
- return;
16247
- _this.cardData.expirationDate = chunkString(originalValue, 2).join(" / ");
16248
- };
16249
- this.onCvcChange = function (value) {
16250
- if (!_this.cardData)
16251
- return;
16252
- if (value.length > _this.cardData.cvv.length && !isLastCharNumber(value))
16253
- return;
16254
- if (value.length > MAX_CVC_LENGTH)
16255
- return;
16256
- _this.cardData.cvv = value;
16257
- };
16258
- // CREDIT CARD END
16259
- this.onBackToShoppingClick = function () {
16260
- _this.router.push("/");
16261
- };
16262
- this.onProceedToShippingClick = function () { return __awaiter(_this, void 0, void 0, function () {
16263
- var newAddress, customer, err_2;
16264
- return __generator(this, function (_a) {
16265
- switch (_a.label) {
16266
- case 0:
16267
- if (!this.canProceedToShipping) {
16268
- this.isErrorsVisible = true;
16269
- return [2 /*return*/];
16270
- }
16271
- this.isErrorsVisible = false;
16272
- _a.label = 1;
16273
- case 1:
16274
- _a.trys.push([1, 6, , 7]);
16275
- this.isStepLoading = true;
16276
- if (!this.shouldSaveAddress) return [3 /*break*/, 3];
16277
- newAddress = new IkasCustomerAddress(__assign(__assign({}, this.checkout.shippingAddress), { title: this.addressTitle || "Yeni Adres" }));
16278
- customer = cloneDeep_1(this.customerStore.customer);
16279
- customer.addresses.push(newAddress);
16280
- return [4 /*yield*/, this.customerStore.saveCustomer(customer)];
16281
- case 2:
16282
- _a.sent();
16283
- _a.label = 3;
16284
- case 3: return [4 /*yield*/, this.checkStocks()];
16285
- case 4:
16286
- _a.sent();
16287
- return [4 /*yield*/, this.saveCheckout()];
16288
- case 5:
16289
- _a.sent();
16290
- this.changeStep(CheckoutStep.SHIPPING);
16291
- return [3 /*break*/, 7];
16292
- case 6:
16293
- err_2 = _a.sent();
16294
- if (err_2.type) {
16295
- this.error = err_2;
16296
- }
16297
- else {
16298
- console.log(err_2);
16299
- this.error = {
16300
- type: ErrorType.UNKNOWN,
16301
- };
16302
- }
16303
- this.isStepLoading = false;
16304
- return [3 /*break*/, 7];
16305
- case 7: return [2 /*return*/];
16306
- }
16307
- });
16308
- }); };
16309
- this.onProceedToPaymentClick = function () { return __awaiter(_this, void 0, void 0, function () {
16310
- var err_3;
16311
- return __generator(this, function (_a) {
16312
- switch (_a.label) {
16313
- case 0:
16314
- if (!this.canProceedToPayment) {
16315
- this.isErrorsVisible = true;
16316
- return [2 /*return*/];
16317
- }
16318
- this.isErrorsVisible = false;
16319
- _a.label = 1;
16320
- case 1:
16321
- _a.trys.push([1, 3, , 4]);
16322
- this.isStepLoading = true;
16323
- return [4 /*yield*/, this.checkStocks()];
16324
- case 2:
16325
- _a.sent();
16326
- this.error = undefined;
16327
- this.changeStep(CheckoutStep.PAYMENT);
16328
- return [3 /*break*/, 4];
16329
- case 3:
16330
- err_3 = _a.sent();
16331
- if (err_3.type) {
16332
- this.error = err_3;
16333
- }
16334
- else {
16335
- console.log(err_3);
16336
- this.error = {
16337
- type: ErrorType.UNKNOWN,
16338
- };
16339
- }
16340
- this.isStepLoading = false;
16341
- return [3 /*break*/, 4];
16342
- case 4: return [2 /*return*/];
16343
- }
16344
- });
16345
- }); };
16346
- this.performPayment = function () { return __awaiter(_this, void 0, void 0, function () {
16347
- var response, transactionStatus, err_4;
16348
- return __generator(this, function (_a) {
16349
- switch (_a.label) {
16350
- case 0:
16351
- if (!this.useDifferentAddress) {
16352
- this.checkout.billingAddress = this.checkout.shippingAddress;
16353
- }
16354
- if (!this.canPerformPayment) {
16355
- this.isErrorsVisible = true;
16356
- return [2 /*return*/];
16357
- }
16358
- _a.label = 1;
16359
- case 1:
16360
- _a.trys.push([1, 5, , 6]);
16361
- this.isErrorsVisible = false;
16362
- this.isStepLoading = true;
16363
- return [4 /*yield*/, this.checkStocks()];
16364
- case 2:
16365
- _a.sent();
16366
- return [4 /*yield*/, this.saveCheckout()];
16367
- case 3:
16368
- _a.sent();
16369
- return [4 /*yield*/, IkasCheckoutAPI.createSaleTransactionWithCheckout(this.checkout.id, this.paymentGatewayId, this.cardData ? this.cardData.toInput() : undefined)];
16370
- case 4:
16371
- response = _a.sent();
16372
- transactionStatus = response === null || response === void 0 ? void 0 : response.transactionStatus;
16373
- if (transactionStatus &&
16374
- [
16375
- exports.IkasTransactionStatusEnum.SUCCESS,
16376
- exports.IkasTransactionStatusEnum.AUTHORIZED,
16377
- ].includes(transactionStatus)) {
16378
- localStorage.removeItem(USE_DIFFERENT_ADDRESS_KEY);
16379
- this.changeStep(CheckoutStep.SUCCESS);
16380
- }
16381
- else if (transactionStatus === exports.IkasTransactionStatusEnum.PENDING &&
16382
- !!(response === null || response === void 0 ? void 0 : response.returnSlug)) {
16383
- window.location.href =
16384
- process.env.NEXT_PUBLIC_BASE_URL + response.returnSlug;
16385
- }
16386
- else {
16387
- this.isStepLoading = false;
16388
- throw {
16389
- type: ErrorType.UNKNOWN,
16390
- };
16391
- }
16392
- return [3 /*break*/, 6];
16393
- case 5:
16394
- err_4 = _a.sent();
16395
- if (err_4.type) {
16396
- console.log(err_4);
16397
- this.error = err_4;
16398
- }
16399
- else {
16400
- this.error = {
16401
- type: ErrorType.UNKNOWN,
16402
- };
16403
- }
16404
- this.isStepLoading = false;
16405
- return [3 /*break*/, 6];
16406
- case 6: return [2 /*return*/];
16407
- }
16408
- });
16409
- }); };
16410
- this.onBackToInfoClick = function () {
16411
- _this.changeStep(CheckoutStep.INFO);
16412
- };
16413
- this.onBackToShippingClick = function () {
16414
- _this.changeStep(CheckoutStep.SHIPPING);
16415
- };
16416
- this.setUseDifferentAddress = function (value) {
16417
- _this.useDifferentAddress = value;
16418
- if (_this.useDifferentAddress) {
16419
- localStorage.setItem(USE_DIFFERENT_ADDRESS_KEY, "1");
16420
- _this.checkout.billingAddress =
16421
- _this.checkout.billingAddress || new IkasOrderAddress();
16422
- }
16423
- else {
16424
- localStorage.removeItem(USE_DIFFERENT_ADDRESS_KEY);
16425
- }
16426
- };
16427
- this.setShouldSaveAddress = function (value) {
16428
- _this.shouldSaveAddress = value;
16429
- };
16430
- this.setAddressTitle = function (value) {
16431
- _this.addressTitle = value;
16432
- };
16433
- this.setPaymentGateway = function (index) {
16434
- var paymentGateway = _this.paymentGateways[index];
16435
- _this.paymentGatewayId = paymentGateway.id;
16436
- if (paymentGateway.paymentMethodType === IkasPaymentMethodType.CREDIT_CARD) {
16437
- _this.cardData = new CreditCardData();
16438
- }
16439
- _this.installmentInfo = undefined;
16440
- };
16441
- this.setInstallmentCount = function (count) {
16442
- if (!_this.cardData)
16443
- return;
16444
- _this.cardData.installmentCount = count;
16445
- };
16446
- this.changeStep = function (step) {
16447
- if (!isServer$1) {
16448
- window.location.href = "/checkout/" + _this.checkout.id + "?step=" + step;
16449
- // this.router.push(`/checkout/${this.checkout.id}?step=${step}`);
16450
- }
16451
- };
16452
- this.logout = function () { return __awaiter(_this, void 0, void 0, function () {
16453
- return __generator(this, function (_a) {
16454
- switch (_a.label) {
16455
- case 0:
16456
- this.checkout.customer = undefined;
16457
- this.customerStore.logout();
16458
- _a.label = 1;
16459
- case 1:
16460
- _a.trys.push([1, 3, , 4]);
16461
- return [4 /*yield*/, this.saveCheckout()];
16462
- case 2:
16463
- _a.sent();
16464
- return [3 /*break*/, 4];
16465
- case 3:
16466
- _a.sent();
16467
- return [3 /*break*/, 4];
16468
- case 4:
16469
- this.createCustomer();
16470
- return [2 /*return*/];
16471
- }
16472
- });
16473
- }); };
16474
- this.checkout = checkout;
16475
- this.checkoutSettings = checkoutSettings;
16476
- this.router = router;
16477
- this.returnPolicy = returnPolicy;
16478
- this.privacyPolicy = privacyPolicy;
16479
- this.termsOfService = termsOfService;
16480
- this.isTermsAndConditionsChecked = this.checkoutSettings.isTermsAndConditionsDefaultChecked;
16481
- this.init(queryParams);
16482
- mobx.makeAutoObservable(this);
16483
- }
16484
- Object.defineProperty(CheckoutViewModel.prototype, "cart", {
16485
- get: function () {
16486
- return this.checkout.cart;
16487
- },
16488
- enumerable: false,
16489
- configurable: true
16490
- });
16491
- Object.defineProperty(CheckoutViewModel.prototype, "selectedPaymentGatewayIndex", {
16492
- get: function () {
16493
- var _this = this;
16494
- return this.paymentGateways.findIndex(function (pg) { return pg.id === _this.paymentGatewayId; });
16495
- },
16496
- enumerable: false,
16497
- configurable: true
16498
- });
16499
- Object.defineProperty(CheckoutViewModel.prototype, "selectedPaymentGateway", {
16500
- get: function () {
16501
- var _this = this;
16502
- return this.paymentGateways.find(function (pg) { return pg.id === _this.paymentGatewayId; });
16503
- },
16504
- enumerable: false,
16505
- configurable: true
16506
- });
16507
- Object.defineProperty(CheckoutViewModel.prototype, "selectedInstallmentIndex", {
16508
- get: function () {
16509
- var _this = this;
16510
- var _a;
16511
- return (((_a = this.installmentInfo) === null || _a === void 0 ? void 0 : _a.installmentPrices.findIndex(function (ip) { var _a; return ip.installmentCount === ((_a = _this.cardData) === null || _a === void 0 ? void 0 : _a.installmentCount); })) || 0);
16512
- },
16513
- enumerable: false,
16514
- configurable: true
16515
- });
16516
- Object.defineProperty(CheckoutViewModel.prototype, "checkoutUrl", {
16517
- get: function () {
16518
- return "/checkout/" + this.checkout.id + "?step=info";
16519
- },
16520
- enumerable: false,
16521
- configurable: true
16522
- });
16523
- Object.defineProperty(CheckoutViewModel.prototype, "customerAddressOptions", {
16524
- get: function () {
16525
- var _a;
16526
- var defaultOption = {
16527
- label: "Yeni adres",
16528
- value: "-1",
16529
- };
16530
- var addressOptions = ((_a = this.customerStore.customer) === null || _a === void 0 ? void 0 : _a.addresses.map(function (a) { return ({
16531
- label: a.title + " - " + a.addressText,
16532
- value: a.id,
16533
- }); })) || [];
16534
- return [defaultOption].concat(addressOptions);
16535
- },
16536
- enumerable: false,
16537
- configurable: true
16538
- });
16539
- Object.defineProperty(CheckoutViewModel.prototype, "installmentPrice", {
16540
- get: function () {
16541
- var _this = this;
16542
- var _a, _b;
16543
- if (this.installmentInfo && ((_a = this.cardData) === null || _a === void 0 ? void 0 : _a.installmentCount)) {
16544
- return (_b = this.installmentInfo.installmentPrices.find(function (ip) { var _a; return ip.installmentCount === ((_a = _this.cardData) === null || _a === void 0 ? void 0 : _a.installmentCount); })) === null || _b === void 0 ? void 0 : _b.totalPrice;
16545
- }
16546
- },
16547
- enumerable: false,
16548
- configurable: true
16549
- });
16550
- Object.defineProperty(CheckoutViewModel.prototype, "installmentExtraPrice", {
16551
- get: function () {
16552
- if (this.installmentPrice && this.checkout.totalFinalPrice) {
16553
- return this.installmentPrice - this.checkout.totalFinalPrice;
16554
- }
16555
- },
16556
- enumerable: false,
16557
- configurable: true
16558
- });
16559
- Object.defineProperty(CheckoutViewModel.prototype, "canProceedToShipping", {
16560
- // VALIDATIONS
16561
- get: function () {
16562
- var _a;
16563
- return (this.checkout.shippingAddress.isValid &&
16564
- this.checkout.hasValidCustomer &&
16565
- ((_a = this.error) === null || _a === void 0 ? void 0 : _a.type) !== ErrorType.NO_SHIPPING_ERROR);
16566
- },
16567
- enumerable: false,
16568
- configurable: true
16569
- });
16570
- Object.defineProperty(CheckoutViewModel.prototype, "canProceedToPayment", {
16571
- get: function () {
16572
- // TODO might add something here later not sure
16573
- return this.canProceedToShipping;
16574
- },
16575
- enumerable: false,
16576
- configurable: true
16577
- });
16578
- Object.defineProperty(CheckoutViewModel.prototype, "canPerformPayment", {
16579
- get: function () {
16580
- var _a, _b, _c;
16581
- if (this.checkoutSettings.showTermsAndConditionsCheckbox &&
16582
- !this.isTermsAndConditionsChecked)
16583
- return false;
16584
- return (this.canProceedToShipping &&
16585
- !!((_a = this.checkout.billingAddress) === null || _a === void 0 ? void 0 : _a.isValid) &&
16586
- (((_b = this.selectedPaymentGateway) === null || _b === void 0 ? void 0 : _b.paymentMethodType) ===
16587
- IkasPaymentMethodType.CREDIT_CARD
16588
- ? (_c = this.cardData) === null || _c === void 0 ? void 0 : _c.isValid : true));
16589
- },
16590
- enumerable: false,
16591
- configurable: true
16592
- });
16593
- return CheckoutViewModel;
16594
- }());
16595
- function chunkString(str, length) {
16596
- return str.match(new RegExp(".{1," + length + "}", "g")) || [];
16597
- }
16598
- function isLastCharNumber(str) {
16599
- return str && NUMBER_ONLY_REGEX.test(str.charAt(str.length - 1));
16600
- }
16601
- var CheckoutStep;
16602
- (function (CheckoutStep) {
16603
- CheckoutStep["INFO"] = "info";
16604
- CheckoutStep["SHIPPING"] = "shipping";
16605
- CheckoutStep["PAYMENT"] = "payment";
16606
- CheckoutStep["SUCCESS"] = "success";
16607
- })(CheckoutStep || (CheckoutStep = {}));
16608
- var ErrorType;
16609
- (function (ErrorType) {
16610
- ErrorType[ErrorType["UNKNOWN"] = 0] = "UNKNOWN";
16611
- ErrorType[ErrorType["API_ERROR"] = 1] = "API_ERROR";
16612
- ErrorType[ErrorType["STOCK_ERROR"] = 2] = "STOCK_ERROR";
16613
- ErrorType[ErrorType["PAYMENT_ERROR"] = 3] = "PAYMENT_ERROR";
16614
- ErrorType[ErrorType["NO_SHIPPING_ERROR"] = 4] = "NO_SHIPPING_ERROR";
16615
- })(ErrorType || (ErrorType = {}));
16616
-
16617
- var isServer$2 = typeof window === "undefined";
16618
- var GoogleTagManager = /** @class */ (function () {
16619
- function GoogleTagManager() {
16620
- mobx.makeAutoObservable(this);
16621
- }
16622
- GoogleTagManager.pageView = function (url) {
16623
- try {
16624
- var event_1 = {
16625
- event: "page-view",
16626
- page: url,
16627
- };
16628
- //@ts-ignore
16629
- !isServer$2 && window.dataLayer && window.dataLayer.push(event_1);
16630
- return event_1;
16631
- }
16632
- catch (err) {
16633
- console.error(err);
16634
- }
16635
- };
16636
- GoogleTagManager.productView = function (productDetail) {
16637
- try {
16638
- var event_2 = {
16639
- event: "view_item",
16640
- ecommerce: {
16641
- items: [productToGTMItem(productDetail)],
16642
- },
16643
- };
16644
- //@ts-ignore
16645
- !isServer$2 && window.dataLayer && window.dataLayer.push(event_2);
16646
- return event_2;
16647
- }
16648
- catch (err) {
16649
- console.error(err);
16650
- }
16651
- };
16652
- GoogleTagManager.addToCart = function (item, quantity) {
16653
- try {
16654
- var event_3 = {
16655
- event: "add_to_cart",
16656
- ecommerce: {
16657
- items: [
16658
- item instanceof IkasProductDetail
16659
- ? productToGTMItem(item, quantity)
16660
- : orderLineItemToGTMItem(item, quantity),
16661
- ],
16662
- },
16663
- };
16664
- //@ts-ignore
16665
- !isServer$2 && window.dataLayer && window.dataLayer.push(event_3);
16666
- return event_3;
16667
- }
16668
- catch (err) {
16669
- console.error(err);
16670
- }
16671
- };
16672
- GoogleTagManager.removeFromCart = function (item, quantity) {
16673
- try {
16674
- var event_4 = {
16675
- event: "remove_from_cart",
16676
- ecommerce: {
16677
- items: [
16678
- item instanceof IkasProductDetail
16679
- ? productToGTMItem(item, quantity)
16680
- : orderLineItemToGTMItem(item, quantity),
16681
- ],
16682
- },
16683
- };
16684
- //@ts-ignore
16685
- !isServer$2 && window.dataLayer && window.dataLayer.push(event_4);
16686
- return event_4;
16687
- }
16688
- catch (err) {
16689
- console.error(err);
16690
- }
16691
- };
16692
- GoogleTagManager.beginCheckout = function (checkout) {
16693
- var _a;
16694
- try {
16695
- var event_5 = {
16696
- event: "begin_checkout",
16697
- ecommerce: {
16698
- items: (_a = checkout.cart) === null || _a === void 0 ? void 0 : _a.items.map(function (item) {
16699
- return orderLineItemToGTMItem(item, item.quantity);
16700
- }),
16701
- },
16702
- };
16703
- //@ts-ignore
16704
- !isServer$2 && window.dataLayer && window.dataLayer.push(event_5);
16705
- return event_5;
16706
- }
16707
- catch (err) {
16708
- console.error(err);
16709
- }
16710
- };
16711
- GoogleTagManager.purchase = function (checkout, orderId) {
16712
- var _a, _b, _c;
16713
- try {
16714
- var event_6 = {
16715
- event: "purchase",
16716
- ecommerce: {
16717
- purchase: {
16718
- transaction_id: orderId,
16719
- affiliation: window.location.hostname,
16720
- value: "" + checkout.totalFinalPrice,
16721
- tax: "" + ((_a = checkout.cart) === null || _a === void 0 ? void 0 : _a.totalTax),
16722
- shipping: "" + checkout.shippingTotal,
16723
- currency: (_b = checkout.cart) === null || _b === void 0 ? void 0 : _b.currencyCode,
16724
- coupon: checkout.couponCode,
16725
- items: (_c = checkout.cart) === null || _c === void 0 ? void 0 : _c.items.map(function (item) {
16726
- return orderLineItemToGTMItem(item, item.quantity);
16727
- }),
16728
- },
16729
- },
16730
- };
16731
- //@ts-ignore
16732
- !isServer$2 && window.dataLayer && window.dataLayer.push(event_6);
16733
- return event_6;
16734
- }
16735
- catch (err) {
16736
- console.error(err);
16737
- }
16738
- };
16739
- GoogleTagManager.checkoutStep = function (checkout, step) {
16740
- var _a;
16741
- var eventName = "";
16742
- if (step === CheckoutStep.INFO)
16743
- eventName = "checkout_info";
16744
- else if (step === CheckoutStep.SHIPPING)
16745
- eventName = "checkout_shipping";
16746
- else if (step === CheckoutStep.PAYMENT)
16747
- eventName = "checkout_payment";
16748
- else if (step === CheckoutStep.SUCCESS)
16749
- eventName = "checkout_success";
16750
- try {
16751
- var event_7 = {
16752
- event: eventName,
16753
- ecommerce: {
16754
- items: (_a = checkout.cart) === null || _a === void 0 ? void 0 : _a.items.map(function (item) {
16755
- return orderLineItemToGTMItem(item, item.quantity);
16756
- }),
16757
- },
16758
- };
16759
- //@ts-ignore
16760
- !isServer$2 && window.dataLayer && window.dataLayer.push(event_7);
16761
- return event_7;
16762
- }
16763
- catch (err) {
16764
- console.error(err);
16765
- }
16766
- };
16767
- GoogleTagManager.disableHTML = function () {
16768
- try {
16769
- var data = {
16770
- "gtm.blocklist": [
16771
- "html",
16772
- "customScripts",
16773
- "customPixels",
16774
- "nonGoogleScripts",
16775
- ],
16776
- };
16777
- //@ts-ignore
16778
- !isServer$2 && window.dataLayer && window.dataLayer.push(data);
16779
- }
16780
- catch (err) {
16781
- console.error(err);
16782
- }
16783
- };
16784
- return GoogleTagManager;
16785
- }());
16786
- function productToGTMItem(productDetail, quantity) {
16787
- var _a;
16788
- if (quantity === void 0) { quantity = 1; }
16789
- return {
16790
- item_name: productDetail.product.name,
16791
- item_id: productDetail.selectedVariant.id,
16792
- price: productDetail.selectedVariant.price.finalPrice,
16793
- item_brand: ((_a = productDetail.product.brand) === null || _a === void 0 ? void 0 : _a.name) || "",
16794
- item_category: productDetail.product.categories.length
16795
- ? productDetail.product.categories[0].name
16796
- : "",
16797
- item_category_2: productDetail.product.categories.length > 1
16798
- ? productDetail.product.categories[1].name
16799
- : "",
16800
- item_category_3: productDetail.product.categories.length > 2
16801
- ? productDetail.product.categories[2].name
16802
- : "",
16803
- item_category_4: productDetail.product.categories.length > 3
16804
- ? productDetail.product.categories[3].name
16805
- : "",
16806
- item_variant: productDetail.selectedVariant.variantValues
16807
- .map(function (vv) { return vv.name; })
16808
- .join(" / "),
16809
- item_list_name: "",
16810
- item_list_id: "",
16811
- index: 1,
16812
- quantity: quantity,
16813
- };
16814
- }
16815
- function orderLineItemToGTMItem(orderLineItem, quantity) {
16816
- if (quantity === void 0) { quantity = 1; }
16817
- return {
16818
- item_name: orderLineItem.variant.name,
16819
- item_id: orderLineItem.variant.id,
16820
- price: "" + orderLineItem.finalPrice,
16821
- item_brand: "",
16822
- item_category: "",
16823
- item_category_2: "",
16824
- item_category_3: "",
16825
- item_category_4: "",
16826
- item_variant: orderLineItem.variant.variantValues
16827
- .map(function (vv) { return vv.variantValueName; })
16828
- .join(" / "),
16829
- item_list_name: "",
16830
- item_list_id: "",
16831
- index: 1,
16832
- quantity: quantity,
16833
- };
16834
- }
16835
-
16836
- var LS_BEGIN_CHECKOUT_KEY = "gtmBeginCheckout";
16837
- var Analytics = /** @class */ (function () {
16838
- function Analytics() {
16839
- mobx.makeAutoObservable(this);
16840
- }
16841
- Analytics.pageView = function (url) {
16842
- try {
16843
- GoogleTagManager.pageView(url);
16844
- }
16845
- catch (err) {
16846
- console.error(err);
16847
- }
16848
- };
16849
- Analytics.productView = function (productDetail) {
16850
- try {
16851
- FacebookPixel.productView(productDetail);
16852
- GoogleTagManager.productView(productDetail);
16853
- }
16854
- catch (err) {
16855
- console.error(err);
16856
- }
16857
- };
16858
- Analytics.addToCart = function (item, quantity) {
16859
- try {
16860
- FacebookPixel.addToCart(item, quantity);
16861
- GoogleTagManager.addToCart(item, quantity);
16862
- }
16863
- catch (err) {
16864
- console.error(err);
16865
- }
16866
- };
16867
- Analytics.removeFromCart = function (item, quantity) {
16868
- try {
16869
- GoogleTagManager.removeFromCart(item, quantity);
16870
- }
16871
- catch (err) {
16872
- console.error(err);
16873
- }
16874
- };
16875
- Analytics.beginCheckout = function (checkout) {
16876
- try {
16877
- var beginCheckout = localStorage.getItem(LS_BEGIN_CHECKOUT_KEY);
16878
- if (beginCheckout && checkout.id === beginCheckout)
16879
- return;
16880
- localStorage.setItem(LS_BEGIN_CHECKOUT_KEY, checkout.id);
16881
- FacebookPixel.beginCheckout(checkout);
16882
- GoogleTagManager.beginCheckout(checkout);
16883
- }
16884
- catch (err) {
16885
- console.error(err);
16886
- }
16887
- };
16888
- Analytics.purchase = function (checkout, orderId) {
16889
- try {
16890
- localStorage.removeItem(LS_BEGIN_CHECKOUT_KEY);
16891
- FacebookPixel.purchase(checkout, orderId);
16892
- GoogleTagManager.purchase(checkout, orderId);
16893
- }
16894
- catch (err) {
16895
- console.error(err);
16896
- }
16897
- };
16898
- Analytics.checkoutStep = function (checkout, step) {
16899
- try {
16900
- GoogleTagManager.checkoutStep(checkout, step);
16901
- }
16902
- catch (err) {
16903
- console.error(err);
16904
- }
16905
- };
16906
- Analytics.disableHTML = function () {
16907
- try {
16908
- GoogleTagManager.disableHTML();
16909
- }
16910
- catch (err) {
16911
- console.error(err);
16912
- }
16913
- };
16914
- Analytics.addToWishlist = function (id) {
16915
- try {
16916
- FacebookPixel.addToWishlist(id);
16917
- }
16918
- catch (err) {
16919
- console.error(err);
16920
- }
16921
- };
16922
- Analytics.search = function (searchKeyword) {
16923
- try {
16924
- FacebookPixel.search(searchKeyword);
16925
- }
16926
- catch (err) {
16927
- console.error(err);
16928
- }
16929
- };
16930
- Analytics.completeRegistration = function () {
16931
- try {
16932
- FacebookPixel.completeRegistration();
16933
- }
16934
- catch (err) {
16935
- console.error(err);
16936
- }
16937
- };
16938
- Analytics.viewCart = function (cart) {
16939
- try {
16940
- if (cart) {
16941
- FacebookPixel.viewCart(cart);
16942
- }
16943
- }
16944
- catch (err) {
16945
- console.error(err);
16946
- }
16947
- };
16948
- Analytics.viewCategory = function (categoryPath) {
16949
- try {
16950
- FacebookPixel.viewCategory(categoryPath);
16951
- }
16952
- catch (err) {
16953
- console.error(err);
16954
- }
16955
- };
16956
- Analytics.contactForm = function () {
16957
- try {
16958
- FacebookPixel.contactForm();
16959
- }
16960
- catch (err) {
16961
- console.error(err);
16962
- }
16963
- };
16964
- return Analytics;
16965
- }());
16966
-
16967
- var AnalyticsHead = function (_a) {
16968
- var blockHTML = _a.blockHTML;
16969
- var gtmId = IkasStorefrontConfig.gtmId;
16970
- var fbpId = IkasStorefrontConfig.fbpId;
16971
- return (React.createElement(React.Fragment, null,
16972
- blockHTML && (React.createElement("script", { dangerouslySetInnerHTML: {
16973
- __html: "dataLayer = [{'gtm.blocklist': ['html']}];",
16974
- } })),
16975
- gtmId && (React.createElement("script", { dangerouslySetInnerHTML: {
16976
- __html: "(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\n new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\n j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=\n 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);\n })(window,document,'script','dataLayer','" + gtmId + "');",
16977
- } })),
16978
- fbpId && (React.createElement("script", { dangerouslySetInnerHTML: {
16979
- __html: "!function(f,b,e,v,n,t,s)\n {if(f.fbq)return;n=f.fbq=function(){n.callMethod?\n n.callMethod.apply(n,arguments):n.queue.push(arguments)};\n if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';\n n.queue=[];t=b.createElement(e);t.async=!0;\n t.src=v;s=b.getElementsByTagName(e)[0];\n s.parentNode.insertBefore(t,s)}(window, document,'script',\n 'https://connect.facebook.net/en_US/fbevents.js');\n fbq('init', '" + fbpId + "');\n fbq('track', 'PageView');",
16980
- } }))));
16981
- };
16982
- var AnalyticsBody = function () {
16983
- var gtmId = IkasStorefrontConfig.gtmId;
16984
- var fbpId = IkasStorefrontConfig.fbpId;
16985
- return (React.createElement(React.Fragment, null,
16986
- gtmId && (React.createElement("noscript", { dangerouslySetInnerHTML: {
16987
- __html: "<iframe src=\"https://www.googletagmanager.com/ns.html?id=" + gtmId + "\" height=\"0\" width=\"0\" style=\"display:none;visibility:hidden\"></iframe>",
16988
- } })),
16989
- fbpId && (React.createElement("noscript", { dangerouslySetInnerHTML: {
16990
- __html: "<img height=\"1\" width=\"1\" style=\"display:none\" \n src=\"https://www.facebook.com/tr?id=" + fbpId + "&ev=PageView&noscript=1\"/>",
16991
- } }))));
16992
- };
16993
-
16994
- var isServer$3 = typeof localStorage === "undefined";
16995
- var LS_TOKEN_KEY = "customerToken";
16996
- var LS_TOKEN_EXPIRY = "customerTokenExpiry";
16997
- var LS_CUSTOMER_KEY = "customer";
16998
- var IkasCustomerStore = /** @class */ (function () {
16999
- function IkasCustomerStore(baseStore) {
17000
- var _this = this;
17001
- this.customer = null;
17002
- this.token = null;
17003
- this.tokenExpiry = null;
17004
- this.baseStore = null;
17005
- this._initialized = false;
17006
- this.login = function (email, password) { return __awaiter(_this, void 0, void 0, function () {
17007
- var response, cart;
17008
- var _a;
17009
- return __generator(this, function (_b) {
17010
- switch (_b.label) {
17011
- case 0: return [4 /*yield*/, IkasCustomerAPI.login(email, password)];
17012
- case 1:
17013
- response = _b.sent();
17014
- if (!response) return [3 /*break*/, 4];
17015
- this.setToken(response.token, response.tokenExpiry);
17016
- this.setCustomer(response.customer);
17017
- cart = (_a = this.baseStore) === null || _a === void 0 ? void 0 : _a.cartStore.cart;
17018
- if (!cart) return [3 /*break*/, 3];
17019
- return [4 /*yield*/, this.baseStore.cartStore.changeItemQuantity(cart.items[0], cart.items[0].quantity)];
17020
- case 2:
17021
- _b.sent();
17022
- _b.label = 3;
17023
- case 3: return [2 /*return*/, true];
17024
- case 4: return [2 /*return*/, false];
17025
- }
17026
- });
17027
- }); };
17028
- this.register = function (firstName, lastName, email, password) { return __awaiter(_this, void 0, void 0, function () {
17029
- var response;
17030
- return __generator(this, function (_a) {
17031
- switch (_a.label) {
17032
- case 0: return [4 /*yield*/, IkasCustomerAPI.register(email, password, firstName, lastName)];
17033
- case 1:
17034
- response = _a.sent();
17035
- if (response) {
17036
- this.setToken(response.token, response.tokenExpiry);
17037
- this.setCustomer(response.customer);
17038
- return [2 /*return*/, true];
17039
- }
17040
- return [2 /*return*/, false];
17041
- }
17042
- });
17043
- }); };
17044
- this.saveContactForm = function (input) { return __awaiter(_this, void 0, void 0, function () {
17045
- return __generator(this, function (_a) {
17046
- switch (_a.label) {
17047
- case 0:
17048
- Analytics.contactForm();
17049
- return [4 /*yield*/, IkasContactFormAPI.sendContactFormToMerchant(input)];
17050
- case 1: return [2 /*return*/, _a.sent()];
17051
- }
17052
- });
17053
- }); };
17054
- this.checkEmail = function (email) { return __awaiter(_this, void 0, void 0, function () {
17055
- return __generator(this, function (_a) {
17056
- switch (_a.label) {
17057
- case 0: return [4 /*yield*/, IkasCustomerAPI.checkEmail(email)];
17058
- case 1: return [2 /*return*/, _a.sent()];
17059
- }
17060
- });
17061
- }); };
17062
- this.forgotPassword = function (email) { return __awaiter(_this, void 0, void 0, function () {
17063
- return __generator(this, function (_a) {
17064
- switch (_a.label) {
17065
- case 0: return [4 /*yield*/, IkasCustomerAPI.forgotPassword(email)];
17066
- case 1: return [2 /*return*/, _a.sent()];
17067
- }
17068
- });
17069
- }); };
17070
- this.recoverPassword = function (password, passwordAgain, token) { return __awaiter(_this, void 0, void 0, function () {
17071
- return __generator(this, function (_a) {
17072
- switch (_a.label) {
17073
- case 0: return [4 /*yield*/, IkasCustomerAPI.recoverPassword(password, passwordAgain, token)];
17074
- case 1: return [2 /*return*/, _a.sent()];
17075
- }
17076
- });
17077
- }); };
17078
- this.logout = function () {
17079
- var _a;
17080
- localStorage.removeItem(LS_TOKEN_KEY);
17081
- localStorage.removeItem(LS_TOKEN_EXPIRY);
17082
- localStorage.removeItem(LS_CUSTOMER_KEY);
17083
- _this.customer = undefined;
17084
- _this.token = undefined;
17085
- _this.tokenExpiry = undefined;
17086
- (_a = _this.baseStore) === null || _a === void 0 ? void 0 : _a.cartStore.removeCart();
17087
- };
17088
- this.saveCustomer = function (customer) { return __awaiter(_this, void 0, void 0, function () {
17089
- var savedCustomer;
17090
- return __generator(this, function (_a) {
17091
- switch (_a.label) {
17092
- case 0: return [4 /*yield*/, IkasCustomerAPI.saveCustomer(customer)];
17093
- case 1:
17094
- savedCustomer = _a.sent();
17095
- if (savedCustomer) {
17096
- this.setCustomer(savedCustomer);
17097
- return [2 /*return*/, true];
17098
- }
17099
- return [2 /*return*/, false];
17100
- }
17101
- });
17102
- }); };
17103
- this.getOrders = function () { return __awaiter(_this, void 0, void 0, function () {
17104
- return __generator(this, function (_a) {
17105
- switch (_a.label) {
17106
- case 0: return [4 /*yield*/, IkasCustomerAPI.getOrders()];
17107
- case 1: return [2 /*return*/, _a.sent()];
17108
- }
17109
- });
17110
- }); };
17111
- this.getOrder = function (id) { return __awaiter(_this, void 0, void 0, function () {
17112
- var orders;
17113
- return __generator(this, function (_a) {
17114
- switch (_a.label) {
17115
- case 0: return [4 /*yield*/, IkasCustomerAPI.getOrders(id)];
17116
- case 1:
17117
- orders = _a.sent();
17118
- if (!Array.isArray(orders) || !orders.length)
17119
- return [2 /*return*/, null];
17120
- return [2 /*return*/, orders[0]];
17121
- }
17122
- });
17123
- }); };
17124
- this.getOrderTransactions = function (params) {
17125
- if (params === void 0) { params = {}; }
17126
- return __awaiter(_this, void 0, void 0, function () {
17127
- return __generator(this, function (_a) {
17128
- switch (_a.label) {
17129
- case 0: return [4 /*yield*/, IkasCustomerAPI.getOrderTransactions(params)];
17130
- case 1: return [2 /*return*/, _a.sent()];
17131
- }
17132
- });
17133
- });
17134
- };
17135
- this.getFavoriteProductsIds = function () { return __awaiter(_this, void 0, void 0, function () {
17136
- var favoriteProductsResult;
17137
- return __generator(this, function (_b) {
17138
- switch (_b.label) {
17139
- case 0:
17140
- _b.trys.push([0, 2, , 3]);
17141
- return [4 /*yield*/, IkasFavoriteProductAPI.listFavoriteProducts()];
17142
- case 1:
17143
- favoriteProductsResult = _b.sent();
17144
- return [2 /*return*/, favoriteProductsResult];
17145
- case 2:
17146
- _b.sent();
17147
- return [2 /*return*/, []];
17148
- case 3: return [2 /*return*/];
17149
- }
17150
- });
17151
- }); };
17152
- this.getFavoriteProducts = function () { return __awaiter(_this, void 0, void 0, function () {
17153
- var favoriteProductsResult, productsResult;
17154
- return __generator(this, function (_b) {
17155
- switch (_b.label) {
17156
- case 0:
17157
- _b.trys.push([0, 3, , 4]);
17158
- return [4 /*yield*/, IkasFavoriteProductAPI.listFavoriteProducts()];
17159
- case 1:
17160
- favoriteProductsResult = _b.sent();
17161
- if (!favoriteProductsResult.length)
17162
- return [2 /*return*/, []];
17163
- return [4 /*yield*/, IkasProductSearchAPI.searchProducts({
17164
- productIdList: favoriteProductsResult.map(function (fP) { return fP.productId; }),
17165
- priceListId: IkasStorefrontConfig.priceListId,
17166
- })];
17167
- case 2:
17168
- productsResult = _b.sent();
17169
- return [2 /*return*/, (productsResult === null || productsResult === void 0 ? void 0 : productsResult.data) || []];
17170
- case 3:
17171
- _b.sent();
17172
- return [2 /*return*/, []];
17173
- case 4: return [2 /*return*/];
17174
- }
17175
- });
17176
- }); };
17177
- this.addItemToFavorite = function (productId) { return __awaiter(_this, void 0, void 0, function () {
17178
- var customerId, result;
17179
- var _b;
17180
- return __generator(this, function (_c) {
17181
- switch (_c.label) {
17182
- case 0:
17183
- customerId = (_b = this.customer) === null || _b === void 0 ? void 0 : _b.id;
17184
- if (!customerId)
17185
- throw Error("Unauthorized");
17186
- _c.label = 1;
17187
- case 1:
17188
- _c.trys.push([1, 3, , 4]);
17189
- return [4 /*yield*/, IkasFavoriteProductAPI.saveFavoriteProduct(true, productId)];
17190
- case 2:
17191
- result = _c.sent();
17192
- Analytics.addToWishlist(productId);
17193
- return [2 /*return*/, result];
17194
- case 3:
17195
- _c.sent();
17196
- return [2 /*return*/, false];
17197
- case 4: return [2 /*return*/];
17198
- }
17199
- });
17200
- }); };
17201
- this.removeItemFromFavorite = function (productId) { return __awaiter(_this, void 0, void 0, function () {
17202
- var customerId, result;
17203
- var _b;
17204
- return __generator(this, function (_c) {
17205
- switch (_c.label) {
17206
- case 0:
17207
- customerId = (_b = this.customer) === null || _b === void 0 ? void 0 : _b.id;
17208
- if (!customerId)
17209
- throw Error("Unauthorized");
17210
- _c.label = 1;
17211
- case 1:
17212
- _c.trys.push([1, 3, , 4]);
17213
- return [4 /*yield*/, IkasFavoriteProductAPI.saveFavoriteProduct(false, productId)];
17214
- case 2:
17215
- result = _c.sent();
17216
- return [2 /*return*/, result];
17217
- case 3:
17218
- _c.sent();
17219
- return [2 /*return*/, false];
17220
- case 4: return [2 /*return*/];
17221
- }
17222
- });
17223
- }); };
17224
- this.isProductFavorite = function (productId) { return __awaiter(_this, void 0, void 0, function () {
17225
- var customerId;
17226
- var _a;
17227
- return __generator(this, function (_b) {
17228
- switch (_b.label) {
17229
- case 0:
17230
- customerId = (_a = this.customer) === null || _a === void 0 ? void 0 : _a.id;
17231
- if (!customerId)
17232
- throw Error("Unauthorized");
17233
- return [4 /*yield*/, IkasFavoriteProductAPI.isFavoriteProduct(productId)];
17234
- case 1: return [2 /*return*/, _b.sent()];
17235
- }
17236
- });
17237
- }); };
17238
- this.baseStore = baseStore;
17239
- this.init();
17240
- mobx.makeAutoObservable(this);
17241
- }
17242
- Object.defineProperty(IkasCustomerStore.prototype, "initialized", {
17243
- get: function () {
17244
- return this._initialized;
17245
- },
17246
- enumerable: false,
17247
- configurable: true
17248
- });
17249
- IkasCustomerStore.prototype.init = function () {
17250
- return __awaiter(this, void 0, void 0, function () {
17251
- return __generator(this, function (_a) {
17252
- switch (_a.label) {
17253
- case 0:
17254
- this.loadToken();
17255
- this.loadCustomer();
17256
- return [4 /*yield*/, this.refreshToken()];
17257
- case 1:
17258
- _a.sent();
17259
- return [4 /*yield*/, this.getCustomer()];
17260
- case 2:
17261
- _a.sent();
17262
- this._initialized = true;
17263
- return [2 /*return*/];
17264
- }
17265
- });
17266
- });
17267
- };
17268
- IkasCustomerStore.prototype.getCustomer = function () {
17269
- return __awaiter(this, void 0, void 0, function () {
17270
- var customer;
17271
- return __generator(this, function (_a) {
17272
- switch (_a.label) {
17273
- case 0:
17274
- if (isServer$3 || !this.token)
17275
- return [2 /*return*/];
17276
- return [4 /*yield*/, IkasCustomerAPI.getCustomer()];
17277
- case 1:
17278
- customer = _a.sent();
17279
- if (customer)
17280
- this.setCustomer(customer);
17281
- return [2 /*return*/];
17282
- }
17283
- });
17284
- });
17285
- };
17286
- IkasCustomerStore.prototype.refreshToken = function () {
17287
- return __awaiter(this, void 0, void 0, function () {
17288
- var response;
17289
- return __generator(this, function (_a) {
17290
- switch (_a.label) {
17291
- case 0:
17292
- if (!this.token)
17293
- return [2 /*return*/];
17294
- return [4 /*yield*/, IkasCustomerAPI.refreshToken(this.token)];
17295
- case 1:
17296
- response = _a.sent();
17297
- if ((response === null || response === void 0 ? void 0 : response.token) || (response === null || response === void 0 ? void 0 : response.tokenExpiry))
17298
- this.setToken(response.token, response.tokenExpiry);
17299
- return [2 /*return*/];
17300
- }
17301
- });
17302
- });
17303
- };
17304
- IkasCustomerStore.prototype.setCustomer = function (customer) {
17305
- if (!isServer$3) {
17306
- localStorage.setItem(LS_CUSTOMER_KEY, JSON.stringify(customer));
17307
- }
17308
- this.customer = new IkasCustomer(customer);
17309
- };
17310
- IkasCustomerStore.prototype.loadCustomer = function () {
17311
- if (isServer$3)
17312
- return;
17313
- try {
17314
- var customerStr = localStorage.getItem(LS_CUSTOMER_KEY);
17315
- if (customerStr) {
17316
- this.customer = new IkasCustomer(JSON.parse(customerStr));
17317
- }
17318
- }
17319
- catch (err) { }
17320
- };
17321
- IkasCustomerStore.prototype.setToken = function (token, tokenExpiry) {
17322
- if (isServer$3)
17323
- return;
17324
- this.token = token;
17325
- this.tokenExpiry = tokenExpiry;
17326
- localStorage.setItem(LS_TOKEN_KEY, token);
17327
- localStorage.setItem(LS_TOKEN_EXPIRY, tokenExpiry + "");
17328
- apollo.setCustomerToken(token);
17329
- };
17330
- IkasCustomerStore.prototype.loadToken = function () {
17331
- if (isServer$3)
17332
- return;
17333
- var token = localStorage.getItem(LS_TOKEN_KEY);
17334
- var tokenExpiry = localStorage.getItem(LS_TOKEN_EXPIRY);
17335
- if (token && tokenExpiry) {
17336
- this.setToken(token, parseInt(tokenExpiry));
17337
- }
17338
- };
17339
- return IkasCustomerStore;
17340
- }());
17341
-
17342
- var IkasOrder = /** @class */ (function () {
17343
- function IkasOrder(data) {
17344
- var _this = this;
17345
- this.customerStore = new IkasCustomerStore();
17346
- this.refund = function () { return __awaiter(_this, void 0, void 0, function () {
17347
- var refundOrderLineItems_1, result;
17348
- var _this = this;
17349
- return __generator(this, function (_a) {
17350
- switch (_a.label) {
17351
- case 0:
17352
- _a.trys.push([0, 2, , 3]);
17353
- refundOrderLineItems_1 = [];
17354
- this.orderLineItems.map(function (item) {
17355
- if (item.refundQuantity !== null) {
17356
- refundOrderLineItems_1 === null || refundOrderLineItems_1 === void 0 ? void 0 : refundOrderLineItems_1.push({
17357
- orderLineItemId: item.id,
17358
- quantity: item.refundQuantity ? item.refundQuantity : 0,
17359
- });
17360
- }
17361
- });
17362
- return [4 /*yield*/, IkasCustomerAPI.saveIkasOrderRefund({
17363
- orderId: this.id,
17364
- orderLineItems: refundOrderLineItems_1,
17365
- })];
17366
- case 1:
17367
- result = _a.sent();
17368
- if (result) {
17369
- // Set the new order object to this
17370
- Object.entries(result).forEach(function (_a) {
17371
- var key = _a[0], value = _a[1];
17372
- _this[key] = value;
17373
- });
17374
- return [2 /*return*/, true];
17375
- }
17376
- return [3 /*break*/, 3];
17377
- case 2:
17378
- _a.sent();
17379
- return [3 /*break*/, 3];
17380
- case 3: return [2 /*return*/, false];
17381
- }
17382
- });
17383
- }); };
17384
- this.id = data.id;
17385
- this.orderNumber = data.orderNumber;
17386
- this.note = data.note;
17387
- this.totalPrice = data.totalPrice;
17388
- this.totalFinalPrice = data.totalFinalPrice;
17389
- // this.totalDiscountPrice = data.totalDiscountPrice;
17390
- // this.totalWeight = data.totalWeight;
17391
- this.currencyCode = data.currencyCode;
17392
- this.orderedAt = data.orderedAt;
17393
- this.cancelledAt = data.cancelledAt;
17394
- this.status = data.status;
17395
- this.cancelReason = data.cancelReason;
17396
- this.orderPaymentStatus = data.orderPaymentStatus;
17397
- this.orderPackageStatus = data.orderPackageStatus;
17398
- this.shippingMethod = data.shippingMethod;
17399
- this.shippingAddress = data.shippingAddress
17400
- ? new IkasOrderAddress(data.shippingAddress)
17401
- : null;
17402
- this.billingAddress = data.billingAddress
17403
- ? new IkasOrderAddress(data.billingAddress)
17404
- : null;
17405
- this.orderLineItems = data.orderLineItems
17406
- ? data.orderLineItems.map(function (o) { return new IkasOrderLineItem(o); })
17407
- : [];
17408
- this.orderAdjustments = data.orderAdjustments;
17409
- this.shippingLines = data.shippingLines;
17410
- this.customer = data.customer;
17411
- this.taxLines = data.taxLines;
17412
- this.orderPackages = data.orderPackages;
17413
- this.currencyRates = data.currencyRates;
17414
- mobx.makeAutoObservable(this);
17415
- }
17416
- Object.defineProperty(IkasOrder.prototype, "refundableItems", {
17417
- get: function () {
17418
- return this.orderLineItems.filter(function (item) { return item.status === exports.OrderLineItemStatusEnum.FULFILLED; });
17419
- },
17420
- enumerable: false,
17421
- configurable: true
17422
- });
17423
- Object.defineProperty(IkasOrder.prototype, "unfullfilledItems", {
17424
- get: function () {
17425
- var _this = this;
17426
- return this.orderLineItems.filter(function (item) {
17427
- var _a;
17428
- var isInAPackage = (_a = _this.orderPackages) === null || _a === void 0 ? void 0 : _a.some(function (op) {
17429
- return op.orderLineItemIds.includes(item.id);
17430
- });
17431
- return !isInAPackage;
17432
- });
17433
- },
17434
- enumerable: false,
17435
- configurable: true
17436
- });
17437
- Object.defineProperty(IkasOrder.prototype, "refundedItems", {
17438
- get: function () {
17439
- return this.orderLineItems.filter(function (item) {
17440
- return item.status === exports.OrderLineItemStatusEnum.REFUNDED ||
17441
- item.status === exports.OrderLineItemStatusEnum.REFUND_REQUESTED ||
17442
- item.status === exports.OrderLineItemStatusEnum.REFUND_REQUEST_ACCEPTED ||
17443
- item.status === exports.OrderLineItemStatusEnum.REFUND_REJECTED;
17444
- });
17445
- },
17446
- enumerable: false,
17447
- configurable: true
17448
- });
17449
- return IkasOrder;
17450
- }());
17451
- (function (IkasOrderStatus) {
17452
- IkasOrderStatus["DRAFT"] = "DRAFT";
17453
- IkasOrderStatus["CREATED"] = "CREATED";
17454
- IkasOrderStatus["CANCELLED"] = "CANCELLED";
17455
- IkasOrderStatus["REFUNDED"] = "REFUNDED";
17456
- })(exports.IkasOrderStatus || (exports.IkasOrderStatus = {}));
17457
- (function (IkasOrderCancelledReason) {
17458
- IkasOrderCancelledReason["CUSTOMER"] = "CUSTOMER";
17459
- IkasOrderCancelledReason["INVENTORY"] = "INVENTORY";
17460
- IkasOrderCancelledReason["DECLINED"] = "DECLINED";
17461
- IkasOrderCancelledReason["OTHER"] = "OTHER";
17462
- })(exports.IkasOrderCancelledReason || (exports.IkasOrderCancelledReason = {}));
17463
- (function (IkasAmountTypeEnum) {
17464
- IkasAmountTypeEnum["AMOUNT"] = "AMOUNT";
17465
- IkasAmountTypeEnum["RATIO"] = "RATIO";
17466
- })(exports.IkasAmountTypeEnum || (exports.IkasAmountTypeEnum = {}));
17467
- var IkasAdjustmentEnum;
17468
- (function (IkasAdjustmentEnum) {
17469
- IkasAdjustmentEnum["DECREMENT"] = "DECREMENT";
17470
- IkasAdjustmentEnum["INCREMENT"] = "INCREMENT";
17471
- })(IkasAdjustmentEnum || (IkasAdjustmentEnum = {}));
17472
- (function (IkasOrderPaymentStatus) {
17473
- IkasOrderPaymentStatus["WAITING"] = "WAITING";
17474
- IkasOrderPaymentStatus["PAID"] = "PAID";
17475
- IkasOrderPaymentStatus["PARTIALLY_PAID"] = "PARTIALLY_PAID";
17476
- })(exports.IkasOrderPaymentStatus || (exports.IkasOrderPaymentStatus = {}));
17477
- (function (IkasOrderPackageStatus) {
17478
- IkasOrderPackageStatus["UNFULFILLED"] = "UNFULFILLED";
17479
- IkasOrderPackageStatus["PARTIALLY_FULFILLED"] = "PARTIALLY_FULFILLED";
17480
- IkasOrderPackageStatus["FULFILLED"] = "FULFILLED";
17481
- })(exports.IkasOrderPackageStatus || (exports.IkasOrderPackageStatus = {}));
17482
- (function (IkasOrderPackageFulfillStatus) {
17483
- IkasOrderPackageFulfillStatus["DELIVERED"] = "DELIVERED";
17484
- IkasOrderPackageFulfillStatus["FULFILLED"] = "FULFILLED";
17485
- IkasOrderPackageFulfillStatus["SHIPPED"] = "SHIPPED";
17486
- })(exports.IkasOrderPackageFulfillStatus || (exports.IkasOrderPackageFulfillStatus = {}));
17487
- (function (IkasOrderShippingMethod) {
17488
- IkasOrderShippingMethod["CLICK_AND_COLLECT"] = "CLICK_AND_COLLECT";
17489
- IkasOrderShippingMethod["SHIPMENT"] = "SHIPMENT";
17490
- IkasOrderShippingMethod["NO_SHIPMENT"] = "NO_SHIPMENT";
17491
- })(exports.IkasOrderShippingMethod || (exports.IkasOrderShippingMethod = {}));
17492
- (function (OrderLineItemStatusEnum) {
17493
- OrderLineItemStatusEnum["FULFILLED"] = "FULFILLED";
17494
- OrderLineItemStatusEnum["UNFULFILLED"] = "UNFULFILLED";
17495
- OrderLineItemStatusEnum["DELIVERED"] = "DELIVERED";
17496
- // Cancel Enums
17497
- OrderLineItemStatusEnum["CANCELLED"] = "CANCELLED";
17498
- OrderLineItemStatusEnum["CANCEL_REQUESTED"] = "CANCEL_REQUESTED";
17499
- OrderLineItemStatusEnum["CANCEL_REJECTED"] = "CANCEL_REJECTED";
17500
- // Refund Enums
17501
- OrderLineItemStatusEnum["REFUND_REQUESTED"] = "REFUND_REQUESTED";
17502
- OrderLineItemStatusEnum["REFUND_REQUEST_ACCEPTED"] = "REFUND_REQUEST_ACCEPTED";
17503
- OrderLineItemStatusEnum["REFUNDED"] = "REFUNDED";
17504
- OrderLineItemStatusEnum["REFUND_REJECTED"] = "REFUND_REJECTED";
17505
- })(exports.OrderLineItemStatusEnum || (exports.OrderLineItemStatusEnum = {}));
17506
-
17507
- var IkasProductPrice = /** @class */ (function () {
17508
- function IkasProductPrice(data) {
17509
- if (data === void 0) { data = {}; }
17510
- this.sellPrice = data.sellPrice || 0;
17511
- this.discountPrice =
17512
- data.discountPrice !== undefined ? data.discountPrice : null;
17513
- this.currency = data.currency || "";
17514
- mobx.makeAutoObservable(this);
17515
- }
17516
- Object.defineProperty(IkasProductPrice.prototype, "finalPrice", {
17517
- get: function () {
17518
- return this.discountPrice !== null ? this.discountPrice : this.sellPrice;
17519
- },
17520
- enumerable: false,
17521
- configurable: true
17522
- });
17523
- Object.defineProperty(IkasProductPrice.prototype, "hasDiscount", {
17524
- get: function () {
17525
- return this.discountPrice !== null;
17526
- },
17527
- enumerable: false,
17528
- configurable: true
17529
- });
17530
- Object.defineProperty(IkasProductPrice.prototype, "discountAmount", {
17531
- get: function () {
17532
- if (this.hasDiscount)
17533
- return this.sellPrice - this.discountPrice;
17534
- return 0;
17535
- },
17536
- enumerable: false,
17537
- configurable: true
17538
- });
17539
- Object.defineProperty(IkasProductPrice.prototype, "discountPercentage", {
17540
- get: function () {
17541
- if (this.hasDiscount)
17542
- return (100 - (this.finalPrice * 100) / this.sellPrice).toFixed(0);
17543
- return 0;
17544
- },
17545
- enumerable: false,
17546
- configurable: true
17547
- });
17548
- return IkasProductPrice;
17549
- }());
17550
-
17551
- var IkasVariantValue = /** @class */ (function () {
17552
- function IkasVariantValue(data) {
17553
- this.id = data.id || "";
17554
- this.name = data.name || "";
17555
- this.colorCode = data.colorCode || null;
17556
- this.thumbnailImageId = data.thumbnailImageId || null;
17557
- this.variantTypeId = data.variantTypeId || "";
17558
- mobx.makeAutoObservable(this);
17559
- }
17560
- Object.defineProperty(IkasVariantValue.prototype, "slug", {
17561
- get: function () {
17562
- return stringToSlug(this.name);
17563
- },
17564
- enumerable: false,
17565
- configurable: true
17566
- });
17567
- Object.defineProperty(IkasVariantValue.prototype, "thumbnailImage", {
17568
- get: function () {
17569
- if (this.thumbnailImageId)
17570
- return new IkasImage(this.thumbnailImageId);
17571
- },
17572
- enumerable: false,
17573
- configurable: true
17574
- });
17575
- return IkasVariantValue;
17576
- }());
17577
-
17578
- var IkasProductAttributeOption = /** @class */ (function () {
17579
- function IkasProductAttributeOption(data) {
17580
- if (data === void 0) { data = {}; }
17581
- this.id = data.id || "";
17582
- this.name = data.name || "";
17583
- mobx.makeAutoObservable(this);
17584
- }
17585
- return IkasProductAttributeOption;
17586
- }());
17587
-
17588
- var IkasProductAttribute = /** @class */ (function () {
17589
- function IkasProductAttribute(data) {
17590
- this.id = data.id || "";
17591
- this.name = data.name || "";
17592
- this.type = data.type || IkasProductAttributeType.TEXT;
17593
- this.options = data.options || null;
17594
- mobx.makeAutoObservable(this);
17595
- }
17596
- return IkasProductAttribute;
17597
- }());
17598
- var IkasProductAttributeType;
17599
- (function (IkasProductAttributeType) {
17600
- IkasProductAttributeType["CHOICE"] = "CHOICE";
17601
- IkasProductAttributeType["MULTIPLE_CHOICE"] = "MULTIPLE_CHOICE";
17602
- IkasProductAttributeType["TEXT"] = "TEXT";
17603
- IkasProductAttributeType["BOOLEAN"] = "BOOLEAN";
17604
- IkasProductAttributeType["NUMERIC"] = "NUMERIC";
17605
- IkasProductAttributeType["DATETIME"] = "DATETIME";
17606
- IkasProductAttributeType["HTML"] = "HTML";
17607
- })(IkasProductAttributeType || (IkasProductAttributeType = {}));
17608
-
17609
- var IkasProductAttributeValue = /** @class */ (function () {
17610
- function IkasProductAttributeValue(data) {
17611
- this.value = data.value || null;
17612
- this.productAttributeId = data.productAttributeId || "";
17613
- this.productAttributeOptionId = data.productAttributeOptionId || null;
17614
- this.productAttribute = data.productAttribute
17615
- ? new IkasProductAttribute(data.productAttribute)
17616
- : null;
17617
- this.productAttributeOption = data.productAttributeOption
17618
- ? new IkasProductAttributeOption(data.productAttributeOption)
17619
- : null;
17620
- mobx.makeAutoObservable(this);
17621
- }
17622
- return IkasProductAttributeValue;
17623
- }());
17624
-
17625
- var IkasProductVariant = /** @class */ (function () {
17626
- function IkasProductVariant(data) {
17627
- if (data === void 0) { data = {}; }
17628
- this.id = data.id || "";
17629
- this.sku = data.sku || null;
17630
- this.barcodeList = data.barcodeList || [];
17631
- this.variantValues = data.variantValues
17632
- ? data.variantValues.map(function (vv) { return new IkasVariantValue(vv); })
17633
- : [];
17634
- this.images = data.images
17635
- ? data.images.map(function (i) { return new IkasImage(i.id); })
17636
- : [];
17637
- this.attributes = data.attributes
17638
- ? data.attributes.map(function (a) { return new IkasProductAttributeValue(a); })
17639
- : [];
17640
- this.price = data.price
17641
- ? new IkasProductPrice(data.price)
17642
- : new IkasProductPrice();
17643
- this.stock = data.stock || 0;
17644
- mobx.makeAutoObservable(this);
17645
- }
17646
- Object.defineProperty(IkasProductVariant.prototype, "mainImage", {
17647
- get: function () {
17648
- return this.images.length ? this.images[0] : undefined;
17649
- },
17650
- enumerable: false,
17651
- configurable: true
17652
- });
17653
- return IkasProductVariant;
17654
- }());
17655
-
17656
- var IkasVariantType = /** @class */ (function () {
17657
- function IkasVariantType(data) {
17658
- var _this = this;
17659
- if (data === void 0) { data = {}; }
17660
- this.id = data.id || "";
17661
- this.name = data.name || "";
17662
- this.selectionType = data.selectionType || exports.IkasVariantSelectionType.CHOICE;
17663
- this.values = data.values
17664
- ? data.values.map(function (v) {
17665
- return new IkasVariantValue(__assign(__assign({}, v), { variantTypeId: _this.id }));
17666
- })
17667
- : [];
17668
- mobx.makeAutoObservable(this);
17669
- }
17670
- Object.defineProperty(IkasVariantType.prototype, "isColorSelection", {
17671
- get: function () {
17672
- return this.selectionType === exports.IkasVariantSelectionType.COLOR;
17673
- },
17674
- enumerable: false,
17675
- configurable: true
17676
- });
17677
- Object.defineProperty(IkasVariantType.prototype, "slug", {
17678
- get: function () {
17679
- return stringToSlug(this.name);
17680
- },
17681
- enumerable: false,
17682
- configurable: true
17683
- });
17684
- return IkasVariantType;
17685
- }());
17686
- (function (IkasVariantSelectionType) {
17687
- IkasVariantSelectionType["CHOICE"] = "CHOICE";
17688
- IkasVariantSelectionType["COLOR"] = "COLOR";
17689
- })(exports.IkasVariantSelectionType || (exports.IkasVariantSelectionType = {}));
17690
-
17691
- var IkasProductVariantType = /** @class */ (function () {
17692
- function IkasProductVariantType(data) {
17693
- var _this = this;
17694
- this.variantType = data.variantType
17695
- ? new IkasVariantType(data.variantType)
17696
- : new IkasVariantType();
17697
- this.variantValueIds = data.variantValueIds || [];
17698
- this.variantType.values = this.variantType.values.filter(function (v) {
17699
- return _this.variantValueIds.includes(v.id);
17700
- });
17701
- mobx.makeAutoObservable(this);
17702
- }
17703
- return IkasProductVariantType;
17704
- }());
17705
-
17706
- var IkasProductTag = /** @class */ (function () {
17707
- function IkasProductTag(data) {
17708
- this.id = data.id || "";
17709
- this.name = data.name || "";
17710
- mobx.makeAutoObservable(this);
17711
- }
17712
- return IkasProductTag;
17713
- }());
17714
-
17715
- var IkasProduct = /** @class */ (function () {
17716
- function IkasProduct(data) {
17717
- if (data === void 0) { data = {}; }
17718
- this.id = data.id || "";
17719
- this.name = data.name || "";
17720
- this.type = data.type || exports.IkasProductType.PHYSICAL;
17721
- this.description = data.description || "";
17722
- this.shortDescription = data.shortDescription || "";
17723
- this.metaData = data.metaData
17724
- ? new IkasHTMLMetaData(data.metaData)
17725
- : undefined;
17726
- this.brand = data.brand ? new IkasBrand(data.brand) : null;
17727
- this.categories = data.categories
17728
- ? data.categories.map(function (c) { return new IkasCategory(c); })
17729
- : [];
17730
- this.tags = data.tags
17731
- ? data.tags.map(function (tag) { return new IkasProductTag(tag); })
17732
- : [];
17733
- this.variants = data.variants
17734
- ? data.variants.map(function (v) { return new IkasProductVariant(v); })
17735
- : [];
17736
- this.attributes = data.attributes
17737
- ? data.attributes.map(function (a) { return new IkasProductAttributeValue(a); })
17738
- : [];
17739
- this.variantTypes = data.variantTypes
17740
- ? data.variantTypes.map(function (v) { return new IkasProductVariantType(v); })
17741
- : [];
17742
- mobx.makeAutoObservable(this);
17743
- }
17744
- Object.defineProperty(IkasProduct.prototype, "hasVariant", {
17745
- get: function () {
17746
- return !!this.variantTypes.length;
17747
- },
17748
- enumerable: false,
17749
- configurable: true
17750
- });
17751
- Object.defineProperty(IkasProduct.prototype, "mainVariantType", {
17752
- get: function () {
17753
- if (!this.hasVariant)
17754
- return;
17755
- return this.variantTypes[0].variantType;
17756
- },
17757
- enumerable: false,
17758
- configurable: true
17759
- });
17760
- Object.defineProperty(IkasProduct.prototype, "href", {
17761
- get: function () {
17762
- var _a;
17763
- if (!((_a = this.metaData) === null || _a === void 0 ? void 0 : _a.slug))
17764
- return "";
17765
- return "/" + this.metaData.slug;
17766
- },
17767
- enumerable: false,
17768
- configurable: true
17769
- });
17770
- return IkasProduct;
17771
- }());
17772
- (function (IkasProductType) {
17773
- IkasProductType["PHYSICAL"] = "PHYSICAL";
17774
- IkasProductType["DIGITAL"] = "DIGITAL";
17775
- IkasProductType["MEMBERSHIP"] = "MEMBERSHIP";
17776
- })(exports.IkasProductType || (exports.IkasProductType = {}));
17777
-
17778
- /** Built-in value references. */
17779
- var spreadableSymbol = _Symbol ? _Symbol.isConcatSpreadable : undefined;
17780
-
17781
- /**
17782
- * Checks if `value` is a flattenable `arguments` object or array.
17783
- *
17784
- * @private
17785
- * @param {*} value The value to check.
17786
- * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
17787
- */
17788
- function isFlattenable(value) {
17789
- return isArray_1(value) || isArguments_1(value) ||
17790
- !!(spreadableSymbol && value && value[spreadableSymbol]);
17791
- }
15852
+ /**
15853
+ * Checks if `value` is a flattenable `arguments` object or array.
15854
+ *
15855
+ * @private
15856
+ * @param {*} value The value to check.
15857
+ * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
15858
+ */
15859
+ function isFlattenable(value) {
15860
+ return isArray_1(value) || isArguments_1(value) ||
15861
+ !!(spreadableSymbol && value && value[spreadableSymbol]);
15862
+ }
17792
15863
 
17793
15864
  var _isFlattenable = isFlattenable;
17794
15865
 
@@ -19355,187 +17426,2130 @@ function overRest(func, start, transform) {
19355
17426
  };
19356
17427
  }
19357
17428
 
19358
- var _overRest = overRest;
17429
+ var _overRest = overRest;
17430
+
17431
+ /**
17432
+ * Creates a function that returns `value`.
17433
+ *
17434
+ * @static
17435
+ * @memberOf _
17436
+ * @since 2.4.0
17437
+ * @category Util
17438
+ * @param {*} value The value to return from the new function.
17439
+ * @returns {Function} Returns the new constant function.
17440
+ * @example
17441
+ *
17442
+ * var objects = _.times(2, _.constant({ 'a': 1 }));
17443
+ *
17444
+ * console.log(objects);
17445
+ * // => [{ 'a': 1 }, { 'a': 1 }]
17446
+ *
17447
+ * console.log(objects[0] === objects[1]);
17448
+ * // => true
17449
+ */
17450
+ function constant(value) {
17451
+ return function() {
17452
+ return value;
17453
+ };
17454
+ }
17455
+
17456
+ var constant_1 = constant;
17457
+
17458
+ /**
17459
+ * The base implementation of `setToString` without support for hot loop shorting.
17460
+ *
17461
+ * @private
17462
+ * @param {Function} func The function to modify.
17463
+ * @param {Function} string The `toString` result.
17464
+ * @returns {Function} Returns `func`.
17465
+ */
17466
+ var baseSetToString = !_defineProperty ? identity_1 : function(func, string) {
17467
+ return _defineProperty(func, 'toString', {
17468
+ 'configurable': true,
17469
+ 'enumerable': false,
17470
+ 'value': constant_1(string),
17471
+ 'writable': true
17472
+ });
17473
+ };
17474
+
17475
+ var _baseSetToString = baseSetToString;
17476
+
17477
+ /** Used to detect hot functions by number of calls within a span of milliseconds. */
17478
+ var HOT_COUNT = 800,
17479
+ HOT_SPAN = 16;
17480
+
17481
+ /* Built-in method references for those with the same name as other `lodash` methods. */
17482
+ var nativeNow = Date.now;
17483
+
17484
+ /**
17485
+ * Creates a function that'll short out and invoke `identity` instead
17486
+ * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
17487
+ * milliseconds.
17488
+ *
17489
+ * @private
17490
+ * @param {Function} func The function to restrict.
17491
+ * @returns {Function} Returns the new shortable function.
17492
+ */
17493
+ function shortOut(func) {
17494
+ var count = 0,
17495
+ lastCalled = 0;
17496
+
17497
+ return function() {
17498
+ var stamp = nativeNow(),
17499
+ remaining = HOT_SPAN - (stamp - lastCalled);
17500
+
17501
+ lastCalled = stamp;
17502
+ if (remaining > 0) {
17503
+ if (++count >= HOT_COUNT) {
17504
+ return arguments[0];
17505
+ }
17506
+ } else {
17507
+ count = 0;
17508
+ }
17509
+ return func.apply(undefined, arguments);
17510
+ };
17511
+ }
17512
+
17513
+ var _shortOut = shortOut;
17514
+
17515
+ /**
17516
+ * Sets the `toString` method of `func` to return `string`.
17517
+ *
17518
+ * @private
17519
+ * @param {Function} func The function to modify.
17520
+ * @param {Function} string The `toString` result.
17521
+ * @returns {Function} Returns `func`.
17522
+ */
17523
+ var setToString = _shortOut(_baseSetToString);
17524
+
17525
+ var _setToString = setToString;
17526
+
17527
+ /**
17528
+ * The base implementation of `_.rest` which doesn't validate or coerce arguments.
17529
+ *
17530
+ * @private
17531
+ * @param {Function} func The function to apply a rest parameter to.
17532
+ * @param {number} [start=func.length-1] The start position of the rest parameter.
17533
+ * @returns {Function} Returns the new function.
17534
+ */
17535
+ function baseRest(func, start) {
17536
+ return _setToString(_overRest(func, start, identity_1), func + '');
17537
+ }
17538
+
17539
+ var _baseRest = baseRest;
17540
+
17541
+ /**
17542
+ * Checks if the given arguments are from an iteratee call.
17543
+ *
17544
+ * @private
17545
+ * @param {*} value The potential iteratee value argument.
17546
+ * @param {*} index The potential iteratee index or key argument.
17547
+ * @param {*} object The potential iteratee object argument.
17548
+ * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
17549
+ * else `false`.
17550
+ */
17551
+ function isIterateeCall(value, index, object) {
17552
+ if (!isObject_1(object)) {
17553
+ return false;
17554
+ }
17555
+ var type = typeof index;
17556
+ if (type == 'number'
17557
+ ? (isArrayLike_1(object) && _isIndex(index, object.length))
17558
+ : (type == 'string' && index in object)
17559
+ ) {
17560
+ return eq_1(object[index], value);
17561
+ }
17562
+ return false;
17563
+ }
17564
+
17565
+ var _isIterateeCall = isIterateeCall;
17566
+
17567
+ /**
17568
+ * Creates an array of elements, sorted in ascending order by the results of
17569
+ * running each element in a collection thru each iteratee. This method
17570
+ * performs a stable sort, that is, it preserves the original sort order of
17571
+ * equal elements. The iteratees are invoked with one argument: (value).
17572
+ *
17573
+ * @static
17574
+ * @memberOf _
17575
+ * @since 0.1.0
17576
+ * @category Collection
17577
+ * @param {Array|Object} collection The collection to iterate over.
17578
+ * @param {...(Function|Function[])} [iteratees=[_.identity]]
17579
+ * The iteratees to sort by.
17580
+ * @returns {Array} Returns the new sorted array.
17581
+ * @example
17582
+ *
17583
+ * var users = [
17584
+ * { 'user': 'fred', 'age': 48 },
17585
+ * { 'user': 'barney', 'age': 36 },
17586
+ * { 'user': 'fred', 'age': 30 },
17587
+ * { 'user': 'barney', 'age': 34 }
17588
+ * ];
17589
+ *
17590
+ * _.sortBy(users, [function(o) { return o.user; }]);
17591
+ * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 30]]
17592
+ *
17593
+ * _.sortBy(users, ['user', 'age']);
17594
+ * // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 48]]
17595
+ */
17596
+ var sortBy = _baseRest(function(collection, iteratees) {
17597
+ if (collection == null) {
17598
+ return [];
17599
+ }
17600
+ var length = iteratees.length;
17601
+ if (length > 1 && _isIterateeCall(collection, iteratees[0], iteratees[1])) {
17602
+ iteratees = [];
17603
+ } else if (length > 2 && _isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
17604
+ iteratees = [iteratees[0]];
17605
+ }
17606
+ return _baseOrderBy(collection, _baseFlatten(iteratees, 1), []);
17607
+ });
17608
+
17609
+ var sortBy_1 = sortBy;
17610
+
17611
+ var IkasPaymentMethodType;
17612
+ (function (IkasPaymentMethodType) {
17613
+ IkasPaymentMethodType["BUY_ONLINE_PAY_AT_STORE"] = "BUY_ONLINE_PAY_AT_STORE";
17614
+ IkasPaymentMethodType["CASH"] = "CASH";
17615
+ IkasPaymentMethodType["CASH_ON_DELIVERY"] = "CASH_ON_DELIVERY";
17616
+ IkasPaymentMethodType["CREDIT_CARD"] = "CREDIT_CARD";
17617
+ IkasPaymentMethodType["GIFT_CARD"] = "GIFT_CARD";
17618
+ IkasPaymentMethodType["MONEY_ORDER"] = "MONEY_ORDER";
17619
+ IkasPaymentMethodType["OTHER"] = "OTHER";
17620
+ })(IkasPaymentMethodType || (IkasPaymentMethodType = {}));
17621
+
17622
+ var CreditCardData = /** @class */ (function () {
17623
+ function CreditCardData(data) {
17624
+ var _this = this;
17625
+ if (data === void 0) { data = {}; }
17626
+ this.installmentCount = 1;
17627
+ this.toInput = function () {
17628
+ var dateParts = _this.expirationDate.split(" / ");
17629
+ var expiredMonth = parseInt(dateParts[0]);
17630
+ var expiredYear = parseInt(dateParts[1]);
17631
+ return {
17632
+ cardNumber: _this.cardNumber.split(" ").join(""),
17633
+ cardHolderName: _this.cardHolderName,
17634
+ cvv: _this.cvv,
17635
+ expiredMonth: expiredMonth,
17636
+ expiredYear: expiredYear,
17637
+ installmentCount: _this.installmentCount,
17638
+ threeDSecure: _this.threeDSecure,
17639
+ };
17640
+ };
17641
+ this.cardNumber = data.cardNumber || "";
17642
+ this.cardHolderName = data.cardHolderName || "";
17643
+ this.expirationDate = data.expirationDate || "";
17644
+ this.cvv = data.cvv || "";
17645
+ this.installmentCount = data.installmentCount || 1;
17646
+ this.threeDSecure = data.threeDSecure || false;
17647
+ mobx.makeAutoObservable(this);
17648
+ }
17649
+ Object.defineProperty(CreditCardData.prototype, "validationResult", {
17650
+ get: function () {
17651
+ return {
17652
+ cardNumber: !!this.cardNumber && this.cardNumber.length === 19,
17653
+ cardHolderName: !!this.cardHolderName,
17654
+ expirationDate: !!this.expirationDate && this.expirationDate.length === 7,
17655
+ cvv: !!this.cvv,
17656
+ };
17657
+ },
17658
+ enumerable: false,
17659
+ configurable: true
17660
+ });
17661
+ Object.defineProperty(CreditCardData.prototype, "isValid", {
17662
+ get: function () {
17663
+ return Object.values(this.validationResult).every(function (result) { return result; });
17664
+ },
17665
+ enumerable: false,
17666
+ configurable: true
17667
+ });
17668
+ return CreditCardData;
17669
+ }());
17670
+
17671
+ var NUMBER_ONLY_REGEX = /^\d+$/;
17672
+ var MAX_CARD_NUMBER_LENGTH = 16;
17673
+ var MAX_CVC_LENGTH = 4;
17674
+ var USE_DIFFERENT_ADDRESS_KEY = "sAddr";
17675
+ var isServer$1 = typeof localStorage === "undefined";
17676
+ var CheckoutViewModel = /** @class */ (function () {
17677
+ function CheckoutViewModel(checkout, checkoutSettings, queryParams, router, returnPolicy, privacyPolicy, termsOfService) {
17678
+ var _this = this;
17679
+ this.checkout = new IkasCheckout();
17680
+ this.checkoutSettings = new IkasCheckoutSettings();
17681
+ this.storefront = null;
17682
+ this.customerStore = new IkasCustomerStore();
17683
+ this.isCheckoutLoaded = false;
17684
+ this.isErrorsVisible = false;
17685
+ this.isStepLoading = false;
17686
+ this.isTermsAndConditionsChecked = false;
17687
+ this.step = CheckoutStep.INFO;
17688
+ this.cardData = null;
17689
+ this.paymentGatewayId = null;
17690
+ this.paymentGateways = [];
17691
+ this.installmentInfo = null;
17692
+ this.useDifferentAddress = false;
17693
+ this.shouldSaveAddress = false;
17694
+ this.addressTitle = "";
17695
+ this.shippingCountryIds = null;
17696
+ this.selectedShippingAddressId = "-1";
17697
+ this.selectedBillingAddressId = "-1";
17698
+ this.policyModalTitle = "";
17699
+ this.policyModalText = "";
17700
+ this.error = null;
17701
+ this.init = function (queryParams) { return __awaiter(_this, void 0, void 0, function () {
17702
+ var merchantId, _a;
17703
+ return __generator(this, function (_b) {
17704
+ switch (_b.label) {
17705
+ case 0:
17706
+ console.log(IkasStorefrontConfig);
17707
+ this.createCustomer();
17708
+ this.createShippingAddress();
17709
+ this.createBillingAddress();
17710
+ if (typeof queryParams.step === "string") {
17711
+ this.step = queryParams.step;
17712
+ if (this.step === CheckoutStep.SHIPPING && !this.canProceedToShipping) {
17713
+ this.changeStep(CheckoutStep.INFO);
17714
+ return [2 /*return*/];
17715
+ }
17716
+ else if (this.step === CheckoutStep.PAYMENT &&
17717
+ !this.canProceedToPayment) {
17718
+ this.changeStep(CheckoutStep.INFO);
17719
+ return [2 /*return*/];
17720
+ }
17721
+ else if (![
17722
+ CheckoutStep.INFO,
17723
+ CheckoutStep.SUCCESS,
17724
+ CheckoutStep.SHIPPING,
17725
+ CheckoutStep.PAYMENT,
17726
+ ].includes(this.step)) {
17727
+ this.changeStep(CheckoutStep.INFO);
17728
+ return [2 /*return*/];
17729
+ }
17730
+ }
17731
+ if (typeof queryParams.failed === "string") {
17732
+ this.error = {
17733
+ type: ErrorType.PAYMENT_ERROR,
17734
+ data: queryParams.error || null,
17735
+ };
17736
+ }
17737
+ merchantId = decodeBase64(IkasStorefrontConfig.config.apiKey || "");
17738
+ _a = this;
17739
+ return [4 /*yield*/, IkasMerchantAPI.listMerchantSettings(merchantId)];
17740
+ case 1:
17741
+ _a.merchantSettings = _b.sent();
17742
+ if (!(this.step === CheckoutStep.INFO)) return [3 /*break*/, 3];
17743
+ return [4 /*yield*/, this.getShippingCountries()];
17744
+ case 2:
17745
+ _b.sent();
17746
+ this.checkShippingCountries();
17747
+ _b.label = 3;
17748
+ case 3:
17749
+ if (!(this.step === CheckoutStep.PAYMENT)) return [3 /*break*/, 5];
17750
+ return [4 /*yield*/, this.listPaymentGateways()];
17751
+ case 4:
17752
+ _b.sent();
17753
+ _b.label = 5;
17754
+ case 5:
17755
+ this.isCheckoutLoaded = true;
17756
+ return [2 /*return*/];
17757
+ }
17758
+ });
17759
+ }); };
17760
+ // VALIDATIONS END
17761
+ this.saveCheckout = function () { return __awaiter(_this, void 0, void 0, function () {
17762
+ var updatedCheckoutId;
17763
+ return __generator(this, function (_a) {
17764
+ switch (_a.label) {
17765
+ case 0: return [4 /*yield*/, IkasCheckoutAPI.saveCheckout(this.checkout)];
17766
+ case 1:
17767
+ updatedCheckoutId = _a.sent();
17768
+ if (!updatedCheckoutId)
17769
+ throw {
17770
+ type: ErrorType.API_ERROR,
17771
+ };
17772
+ return [2 /*return*/];
17773
+ }
17774
+ });
17775
+ }); };
17776
+ this.checkStocks = function () { return __awaiter(_this, void 0, void 0, function () {
17777
+ var lines, result, unavailableItems, data;
17778
+ var _this = this;
17779
+ var _a;
17780
+ return __generator(this, function (_b) {
17781
+ switch (_b.label) {
17782
+ case 0:
17783
+ lines = this.cart.items.map(function (i) { return ({
17784
+ quantity: i.quantity,
17785
+ variantId: i.variant.id,
17786
+ productId: i.variant.productId,
17787
+ }); });
17788
+ return [4 /*yield*/, IkasCheckoutAPI.checkStocks(lines, IkasStorefrontConfig.stockLocationIds || [])];
17789
+ case 1:
17790
+ result = _b.sent();
17791
+ if (!result) {
17792
+ throw {
17793
+ type: ErrorType.API_ERROR,
17794
+ };
17795
+ }
17796
+ unavailableItems = (_a = result.lines) === null || _a === void 0 ? void 0 : _a.filter(function (i) { return !i.isAvailable; });
17797
+ if (unavailableItems === null || unavailableItems === void 0 ? void 0 : unavailableItems.length) {
17798
+ data = unavailableItems.map(function (item) { return ({
17799
+ variant: _this.cart.items.find(function (i) { return i.variant.id === item.variantId; })
17800
+ .variant,
17801
+ availableQuantity: item.stockCount,
17802
+ }); });
17803
+ throw {
17804
+ type: ErrorType.STOCK_ERROR,
17805
+ data: data,
17806
+ };
17807
+ }
17808
+ return [2 /*return*/];
17809
+ }
17810
+ });
17811
+ }); };
17812
+ this.getShippingCountries = function () { return __awaiter(_this, void 0, void 0, function () {
17813
+ var _a;
17814
+ return __generator(this, function (_b) {
17815
+ switch (_b.label) {
17816
+ case 0:
17817
+ _a = this;
17818
+ return [4 /*yield*/, IkasCountryAPI.listShippingCountries(IkasStorefrontConfig.salesChannelId)];
17819
+ case 1:
17820
+ _a.shippingCountryIds = _b.sent();
17821
+ return [2 /*return*/];
17822
+ }
17823
+ });
17824
+ }); };
17825
+ this.checkShippingCountries = function () {
17826
+ var _a;
17827
+ if (!((_a = _this.shippingCountryIds) === null || _a === void 0 ? void 0 : _a.length)) {
17828
+ _this.error = {
17829
+ type: ErrorType.NO_SHIPPING_ERROR,
17830
+ };
17831
+ }
17832
+ };
17833
+ this.initialStockCheck = function () { return __awaiter(_this, void 0, void 0, function () {
17834
+ var err_1;
17835
+ return __generator(this, function (_a) {
17836
+ switch (_a.label) {
17837
+ case 0:
17838
+ _a.trys.push([0, 2, , 3]);
17839
+ return [4 /*yield*/, this.checkStocks()];
17840
+ case 1:
17841
+ _a.sent();
17842
+ return [3 /*break*/, 3];
17843
+ case 2:
17844
+ err_1 = _a.sent();
17845
+ if (err_1.type) {
17846
+ this.error = err_1;
17847
+ }
17848
+ else {
17849
+ console.log(err_1);
17850
+ this.error = {
17851
+ type: ErrorType.UNKNOWN,
17852
+ };
17853
+ }
17854
+ return [3 /*break*/, 3];
17855
+ case 3: return [2 /*return*/];
17856
+ }
17857
+ });
17858
+ }); };
17859
+ this.listPaymentGateways = function () { return __awaiter(_this, void 0, void 0, function () {
17860
+ var isLocal, idList, paymentGateways, orderedPaymentGateways;
17861
+ return __generator(this, function (_a) {
17862
+ switch (_a.label) {
17863
+ case 0:
17864
+ isLocal = process.env.NEXT_PUBLIC_ENV === "local";
17865
+ idList = IkasStorefrontConfig.paymentGateways.map(function (pg) { return pg.id; });
17866
+ return [4 /*yield*/, IkasCheckoutAPI.listPaymentGateway(isLocal ? undefined : idList)];
17867
+ case 1:
17868
+ paymentGateways = _a.sent();
17869
+ if (!paymentGateways) {
17870
+ this.error = {
17871
+ type: ErrorType.API_ERROR,
17872
+ };
17873
+ return [2 /*return*/];
17874
+ }
17875
+ orderedPaymentGateways = [];
17876
+ sortBy_1(IkasStorefrontConfig.paymentGateways, "order").forEach(function (pg) {
17877
+ var _pg = paymentGateways.find(function (p) { return p.id === pg.id; });
17878
+ if (_pg)
17879
+ orderedPaymentGateways.push(_pg);
17880
+ });
17881
+ this.paymentGateways = orderedPaymentGateways;
17882
+ if (!this.paymentGatewayId)
17883
+ this.setPaymentGateway(0);
17884
+ return [2 /*return*/];
17885
+ }
17886
+ });
17887
+ }); };
17888
+ this.retrieveInstallmentInfo = function (input) { return __awaiter(_this, void 0, void 0, function () {
17889
+ var installmentInfo;
17890
+ return __generator(this, function (_a) {
17891
+ switch (_a.label) {
17892
+ case 0: return [4 /*yield*/, IkasCheckoutAPI.retrieveInstallmentInfo(input)];
17893
+ case 1:
17894
+ installmentInfo = _a.sent();
17895
+ installmentInfo === null || installmentInfo === void 0 ? void 0 : installmentInfo.installmentPrices.sort(function (a, b) {
17896
+ return (a.installmentCount || -1) > (b.installmentCount || -1) ? 1 : -1;
17897
+ });
17898
+ this.installmentInfo = installmentInfo;
17899
+ return [2 /*return*/];
17900
+ }
17901
+ });
17902
+ }); };
17903
+ this.createCustomer = function () {
17904
+ if (_this.customerStore.customer) {
17905
+ _this.checkout.customer = _this.customerStore.customer;
17906
+ }
17907
+ else if (!_this.checkout.customer)
17908
+ _this.checkout.customer = new IkasCustomer({});
17909
+ };
17910
+ this.createShippingAddress = function () {
17911
+ if (!_this.checkout.shippingAddress)
17912
+ _this.checkout.shippingAddress = new IkasOrderAddress();
17913
+ _this.checkout.shippingAddress.checkoutSettings = _this.checkoutSettings;
17914
+ };
17915
+ this.createBillingAddress = function () {
17916
+ if (typeof localStorage !== "undefined") {
17917
+ _this.useDifferentAddress = !!localStorage.getItem(USE_DIFFERENT_ADDRESS_KEY);
17918
+ if (_this.useDifferentAddress) {
17919
+ _this.checkout.billingAddress =
17920
+ _this.checkout.billingAddress || new IkasOrderAddress();
17921
+ }
17922
+ else {
17923
+ _this.checkout.billingAddress = new IkasOrderAddress(cloneDeep_1(_this.checkout.shippingAddress) || {});
17924
+ }
17925
+ _this.checkout.billingAddress.checkoutSettings = _this.checkoutSettings;
17926
+ }
17927
+ };
17928
+ this.onEmailChange = function (value) {
17929
+ _this.checkout.customer.email = value;
17930
+ };
17931
+ this.onShippingMethodChange = function (shippingMethod) { return __awaiter(_this, void 0, void 0, function () {
17932
+ var newCheckout;
17933
+ return __generator(this, function (_a) {
17934
+ switch (_a.label) {
17935
+ case 0:
17936
+ this.checkout.shippingSettingsId = shippingMethod.shippingSettingsId;
17937
+ this.checkout.shippingZoneRateId = shippingMethod.shippingZoneRateId;
17938
+ return [4 /*yield*/, this.saveCheckout()];
17939
+ case 1:
17940
+ _a.sent();
17941
+ return [4 /*yield*/, IkasCheckoutAPI.getCheckoutById(this.checkout.id)];
17942
+ case 2:
17943
+ newCheckout = _a.sent();
17944
+ if (newCheckout)
17945
+ this.checkout = newCheckout;
17946
+ return [2 /*return*/];
17947
+ }
17948
+ });
17949
+ }); };
17950
+ this.onCouponCodeChange = function (value) {
17951
+ _this.checkout.couponCode = value;
17952
+ };
17953
+ this.onSelectedShippingAddressIdChange = function (value) {
17954
+ var _a;
17955
+ _this.selectedShippingAddressId = value;
17956
+ if (value === "-1") {
17957
+ _this.checkout.shippingAddress = new IkasOrderAddress();
17958
+ }
17959
+ else {
17960
+ var address = (_a = _this.customerStore.customer) === null || _a === void 0 ? void 0 : _a.addresses.find(function (a) { return a.id === value; });
17961
+ if (address)
17962
+ _this.checkout.shippingAddress = new IkasOrderAddress(address);
17963
+ }
17964
+ };
17965
+ this.onSelectedBillingAddressIdChange = function (value) {
17966
+ var _a;
17967
+ _this.selectedBillingAddressId = value;
17968
+ if (value === "-1") {
17969
+ _this.checkout.billingAddress = new IkasOrderAddress();
17970
+ }
17971
+ else {
17972
+ var address = (_a = _this.customerStore.customer) === null || _a === void 0 ? void 0 : _a.addresses.find(function (a) { return a.id === value; });
17973
+ if (address)
17974
+ _this.checkout.billingAddress = new IkasOrderAddress(address);
17975
+ }
17976
+ };
17977
+ this.onTermsAndConditionsCheckedChange = function (value) {
17978
+ _this.isTermsAndConditionsChecked = value;
17979
+ };
17980
+ // CREDIT CARD START
17981
+ this.onCardNumberChange = function (value) {
17982
+ if (!_this.cardData)
17983
+ return;
17984
+ if (value.length > _this.cardData.cardNumber.length &&
17985
+ !isLastCharNumber(value))
17986
+ return;
17987
+ var oldOriginalValue = (_this.cardData.cardNumber || "")
17988
+ .split(" ")
17989
+ .join("");
17990
+ var originalValue = value.split(" ").join("");
17991
+ if (originalValue.length > MAX_CARD_NUMBER_LENGTH)
17992
+ return;
17993
+ if (oldOriginalValue.length < 6 && originalValue.length >= 6) {
17994
+ _this.retrieveInstallmentInfo({
17995
+ binNumber: originalValue.slice(0, 6),
17996
+ paymentGatewayId: _this.paymentGatewayId,
17997
+ price: _this.checkout.totalFinalPrice,
17998
+ });
17999
+ }
18000
+ // Deleting characters below 6
18001
+ else if (originalValue.length < 6 &&
18002
+ oldOriginalValue.length > originalValue.length) {
18003
+ _this.cardData.installmentCount = 1;
18004
+ _this.installmentInfo = undefined;
18005
+ }
18006
+ _this.cardData.cardNumber = chunkString(originalValue, 4).join(" ");
18007
+ };
18008
+ this.onCardHolderNameChange = function (value) {
18009
+ if (!_this.cardData)
18010
+ return;
18011
+ _this.cardData.cardHolderName = value;
18012
+ };
18013
+ this.onExpirationDateChange = function (value) {
18014
+ if (!_this.cardData)
18015
+ return;
18016
+ if (value.length > _this.cardData.expirationDate.length &&
18017
+ !isLastCharNumber(value)) {
18018
+ return;
18019
+ }
18020
+ var originalValue = value.split(" / ").join("");
18021
+ if (originalValue.length > 4)
18022
+ return;
18023
+ _this.cardData.expirationDate = chunkString(originalValue, 2).join(" / ");
18024
+ };
18025
+ this.onCvcChange = function (value) {
18026
+ if (!_this.cardData)
18027
+ return;
18028
+ if (value.length > _this.cardData.cvv.length && !isLastCharNumber(value))
18029
+ return;
18030
+ if (value.length > MAX_CVC_LENGTH)
18031
+ return;
18032
+ _this.cardData.cvv = value;
18033
+ };
18034
+ // CREDIT CARD END
18035
+ this.onBackToShoppingClick = function () {
18036
+ _this.router.push("/");
18037
+ };
18038
+ this.onProceedToShippingClick = function () { return __awaiter(_this, void 0, void 0, function () {
18039
+ var newAddress, customer, err_2;
18040
+ return __generator(this, function (_a) {
18041
+ switch (_a.label) {
18042
+ case 0:
18043
+ if (!this.canProceedToShipping) {
18044
+ this.isErrorsVisible = true;
18045
+ return [2 /*return*/];
18046
+ }
18047
+ this.isErrorsVisible = false;
18048
+ _a.label = 1;
18049
+ case 1:
18050
+ _a.trys.push([1, 6, , 7]);
18051
+ this.isStepLoading = true;
18052
+ if (!this.shouldSaveAddress) return [3 /*break*/, 3];
18053
+ newAddress = new IkasCustomerAddress(__assign(__assign({}, this.checkout.shippingAddress), { title: this.addressTitle || "Yeni Adres" }));
18054
+ customer = cloneDeep_1(this.customerStore.customer);
18055
+ customer.addresses.push(newAddress);
18056
+ return [4 /*yield*/, this.customerStore.saveCustomer(customer)];
18057
+ case 2:
18058
+ _a.sent();
18059
+ _a.label = 3;
18060
+ case 3: return [4 /*yield*/, this.checkStocks()];
18061
+ case 4:
18062
+ _a.sent();
18063
+ return [4 /*yield*/, this.saveCheckout()];
18064
+ case 5:
18065
+ _a.sent();
18066
+ this.changeStep(CheckoutStep.SHIPPING);
18067
+ return [3 /*break*/, 7];
18068
+ case 6:
18069
+ err_2 = _a.sent();
18070
+ if (err_2.type) {
18071
+ this.error = err_2;
18072
+ }
18073
+ else {
18074
+ console.log(err_2);
18075
+ this.error = {
18076
+ type: ErrorType.UNKNOWN,
18077
+ };
18078
+ }
18079
+ this.isStepLoading = false;
18080
+ return [3 /*break*/, 7];
18081
+ case 7: return [2 /*return*/];
18082
+ }
18083
+ });
18084
+ }); };
18085
+ this.onProceedToPaymentClick = function () { return __awaiter(_this, void 0, void 0, function () {
18086
+ var err_3;
18087
+ return __generator(this, function (_a) {
18088
+ switch (_a.label) {
18089
+ case 0:
18090
+ if (!this.canProceedToPayment) {
18091
+ this.isErrorsVisible = true;
18092
+ return [2 /*return*/];
18093
+ }
18094
+ this.isErrorsVisible = false;
18095
+ _a.label = 1;
18096
+ case 1:
18097
+ _a.trys.push([1, 3, , 4]);
18098
+ this.isStepLoading = true;
18099
+ return [4 /*yield*/, this.checkStocks()];
18100
+ case 2:
18101
+ _a.sent();
18102
+ this.error = undefined;
18103
+ this.changeStep(CheckoutStep.PAYMENT);
18104
+ return [3 /*break*/, 4];
18105
+ case 3:
18106
+ err_3 = _a.sent();
18107
+ if (err_3.type) {
18108
+ this.error = err_3;
18109
+ }
18110
+ else {
18111
+ console.log(err_3);
18112
+ this.error = {
18113
+ type: ErrorType.UNKNOWN,
18114
+ };
18115
+ }
18116
+ this.isStepLoading = false;
18117
+ return [3 /*break*/, 4];
18118
+ case 4: return [2 /*return*/];
18119
+ }
18120
+ });
18121
+ }); };
18122
+ this.performPayment = function () { return __awaiter(_this, void 0, void 0, function () {
18123
+ var response, transactionStatus, err_4;
18124
+ return __generator(this, function (_a) {
18125
+ switch (_a.label) {
18126
+ case 0:
18127
+ if (!this.useDifferentAddress) {
18128
+ this.checkout.billingAddress = this.checkout.shippingAddress;
18129
+ }
18130
+ if (!this.canPerformPayment) {
18131
+ this.isErrorsVisible = true;
18132
+ return [2 /*return*/];
18133
+ }
18134
+ _a.label = 1;
18135
+ case 1:
18136
+ _a.trys.push([1, 5, , 6]);
18137
+ this.isErrorsVisible = false;
18138
+ this.isStepLoading = true;
18139
+ return [4 /*yield*/, this.checkStocks()];
18140
+ case 2:
18141
+ _a.sent();
18142
+ return [4 /*yield*/, this.saveCheckout()];
18143
+ case 3:
18144
+ _a.sent();
18145
+ return [4 /*yield*/, IkasCheckoutAPI.createSaleTransactionWithCheckout(this.checkout.id, this.paymentGatewayId, this.cardData ? this.cardData.toInput() : undefined)];
18146
+ case 4:
18147
+ response = _a.sent();
18148
+ transactionStatus = response === null || response === void 0 ? void 0 : response.transactionStatus;
18149
+ if (transactionStatus &&
18150
+ [
18151
+ exports.IkasTransactionStatusEnum.SUCCESS,
18152
+ exports.IkasTransactionStatusEnum.AUTHORIZED,
18153
+ ].includes(transactionStatus)) {
18154
+ localStorage.removeItem(USE_DIFFERENT_ADDRESS_KEY);
18155
+ this.changeStep(CheckoutStep.SUCCESS);
18156
+ }
18157
+ else if (transactionStatus === exports.IkasTransactionStatusEnum.PENDING &&
18158
+ !!(response === null || response === void 0 ? void 0 : response.returnSlug)) {
18159
+ window.location.href =
18160
+ process.env.NEXT_PUBLIC_BASE_URL + response.returnSlug;
18161
+ }
18162
+ else {
18163
+ this.isStepLoading = false;
18164
+ throw {
18165
+ type: ErrorType.UNKNOWN,
18166
+ };
18167
+ }
18168
+ return [3 /*break*/, 6];
18169
+ case 5:
18170
+ err_4 = _a.sent();
18171
+ if (err_4.type) {
18172
+ console.log(err_4);
18173
+ this.error = err_4;
18174
+ }
18175
+ else {
18176
+ this.error = {
18177
+ type: ErrorType.UNKNOWN,
18178
+ };
18179
+ }
18180
+ this.isStepLoading = false;
18181
+ return [3 /*break*/, 6];
18182
+ case 6: return [2 /*return*/];
18183
+ }
18184
+ });
18185
+ }); };
18186
+ this.onBackToInfoClick = function () {
18187
+ _this.changeStep(CheckoutStep.INFO);
18188
+ };
18189
+ this.onBackToShippingClick = function () {
18190
+ _this.changeStep(CheckoutStep.SHIPPING);
18191
+ };
18192
+ this.setUseDifferentAddress = function (value) {
18193
+ _this.useDifferentAddress = value;
18194
+ if (_this.useDifferentAddress) {
18195
+ localStorage.setItem(USE_DIFFERENT_ADDRESS_KEY, "1");
18196
+ _this.checkout.billingAddress =
18197
+ _this.checkout.billingAddress || new IkasOrderAddress();
18198
+ }
18199
+ else {
18200
+ localStorage.removeItem(USE_DIFFERENT_ADDRESS_KEY);
18201
+ }
18202
+ };
18203
+ this.setShouldSaveAddress = function (value) {
18204
+ _this.shouldSaveAddress = value;
18205
+ };
18206
+ this.setAddressTitle = function (value) {
18207
+ _this.addressTitle = value;
18208
+ };
18209
+ this.setPaymentGateway = function (index) {
18210
+ var paymentGateway = _this.paymentGateways[index];
18211
+ _this.paymentGatewayId = paymentGateway.id;
18212
+ if (paymentGateway.paymentMethodType === IkasPaymentMethodType.CREDIT_CARD) {
18213
+ _this.cardData = new CreditCardData();
18214
+ }
18215
+ _this.installmentInfo = undefined;
18216
+ };
18217
+ this.setInstallmentCount = function (count) {
18218
+ if (!_this.cardData)
18219
+ return;
18220
+ _this.cardData.installmentCount = count;
18221
+ };
18222
+ this.changeStep = function (step) {
18223
+ if (!isServer$1) {
18224
+ window.location.href = "/checkout/" + _this.checkout.id + "?step=" + step;
18225
+ // this.router.push(`/checkout/${this.checkout.id}?step=${step}`);
18226
+ }
18227
+ };
18228
+ this.logout = function () { return __awaiter(_this, void 0, void 0, function () {
18229
+ return __generator(this, function (_a) {
18230
+ switch (_a.label) {
18231
+ case 0:
18232
+ this.checkout.customer = undefined;
18233
+ this.customerStore.logout();
18234
+ _a.label = 1;
18235
+ case 1:
18236
+ _a.trys.push([1, 3, , 4]);
18237
+ return [4 /*yield*/, this.saveCheckout()];
18238
+ case 2:
18239
+ _a.sent();
18240
+ return [3 /*break*/, 4];
18241
+ case 3:
18242
+ _a.sent();
18243
+ return [3 /*break*/, 4];
18244
+ case 4:
18245
+ this.createCustomer();
18246
+ return [2 /*return*/];
18247
+ }
18248
+ });
18249
+ }); };
18250
+ this.checkout = checkout;
18251
+ this.checkoutSettings = checkoutSettings;
18252
+ this.router = router;
18253
+ this.returnPolicy = returnPolicy;
18254
+ this.privacyPolicy = privacyPolicy;
18255
+ this.termsOfService = termsOfService;
18256
+ this.isTermsAndConditionsChecked = this.checkoutSettings.isTermsAndConditionsDefaultChecked;
18257
+ this.init(queryParams);
18258
+ mobx.makeAutoObservable(this);
18259
+ }
18260
+ Object.defineProperty(CheckoutViewModel.prototype, "cart", {
18261
+ get: function () {
18262
+ return this.checkout.cart;
18263
+ },
18264
+ enumerable: false,
18265
+ configurable: true
18266
+ });
18267
+ Object.defineProperty(CheckoutViewModel.prototype, "selectedPaymentGatewayIndex", {
18268
+ get: function () {
18269
+ var _this = this;
18270
+ return this.paymentGateways.findIndex(function (pg) { return pg.id === _this.paymentGatewayId; });
18271
+ },
18272
+ enumerable: false,
18273
+ configurable: true
18274
+ });
18275
+ Object.defineProperty(CheckoutViewModel.prototype, "selectedPaymentGateway", {
18276
+ get: function () {
18277
+ var _this = this;
18278
+ return this.paymentGateways.find(function (pg) { return pg.id === _this.paymentGatewayId; });
18279
+ },
18280
+ enumerable: false,
18281
+ configurable: true
18282
+ });
18283
+ Object.defineProperty(CheckoutViewModel.prototype, "selectedInstallmentIndex", {
18284
+ get: function () {
18285
+ var _this = this;
18286
+ var _a;
18287
+ return (((_a = this.installmentInfo) === null || _a === void 0 ? void 0 : _a.installmentPrices.findIndex(function (ip) { var _a; return ip.installmentCount === ((_a = _this.cardData) === null || _a === void 0 ? void 0 : _a.installmentCount); })) || 0);
18288
+ },
18289
+ enumerable: false,
18290
+ configurable: true
18291
+ });
18292
+ Object.defineProperty(CheckoutViewModel.prototype, "checkoutUrl", {
18293
+ get: function () {
18294
+ return "/checkout/" + this.checkout.id + "?step=info";
18295
+ },
18296
+ enumerable: false,
18297
+ configurable: true
18298
+ });
18299
+ Object.defineProperty(CheckoutViewModel.prototype, "customerAddressOptions", {
18300
+ get: function () {
18301
+ var _a;
18302
+ var defaultOption = {
18303
+ label: "Yeni adres",
18304
+ value: "-1",
18305
+ };
18306
+ var addressOptions = ((_a = this.customerStore.customer) === null || _a === void 0 ? void 0 : _a.addresses.map(function (a) { return ({
18307
+ label: a.title + " - " + a.addressText,
18308
+ value: a.id,
18309
+ }); })) || [];
18310
+ return [defaultOption].concat(addressOptions);
18311
+ },
18312
+ enumerable: false,
18313
+ configurable: true
18314
+ });
18315
+ Object.defineProperty(CheckoutViewModel.prototype, "installmentPrice", {
18316
+ get: function () {
18317
+ var _this = this;
18318
+ var _a, _b;
18319
+ if (this.installmentInfo && ((_a = this.cardData) === null || _a === void 0 ? void 0 : _a.installmentCount)) {
18320
+ return (_b = this.installmentInfo.installmentPrices.find(function (ip) { var _a; return ip.installmentCount === ((_a = _this.cardData) === null || _a === void 0 ? void 0 : _a.installmentCount); })) === null || _b === void 0 ? void 0 : _b.totalPrice;
18321
+ }
18322
+ },
18323
+ enumerable: false,
18324
+ configurable: true
18325
+ });
18326
+ Object.defineProperty(CheckoutViewModel.prototype, "installmentExtraPrice", {
18327
+ get: function () {
18328
+ if (this.installmentPrice && this.checkout.totalFinalPrice) {
18329
+ return this.installmentPrice - this.checkout.totalFinalPrice;
18330
+ }
18331
+ },
18332
+ enumerable: false,
18333
+ configurable: true
18334
+ });
18335
+ Object.defineProperty(CheckoutViewModel.prototype, "canProceedToShipping", {
18336
+ // VALIDATIONS
18337
+ get: function () {
18338
+ var _a;
18339
+ return (this.checkout.shippingAddress.isValid &&
18340
+ this.checkout.hasValidCustomer &&
18341
+ ((_a = this.error) === null || _a === void 0 ? void 0 : _a.type) !== ErrorType.NO_SHIPPING_ERROR);
18342
+ },
18343
+ enumerable: false,
18344
+ configurable: true
18345
+ });
18346
+ Object.defineProperty(CheckoutViewModel.prototype, "canProceedToPayment", {
18347
+ get: function () {
18348
+ // TODO might add something here later not sure
18349
+ return this.canProceedToShipping;
18350
+ },
18351
+ enumerable: false,
18352
+ configurable: true
18353
+ });
18354
+ Object.defineProperty(CheckoutViewModel.prototype, "canPerformPayment", {
18355
+ get: function () {
18356
+ var _a, _b, _c;
18357
+ if (this.checkoutSettings.showTermsAndConditionsCheckbox &&
18358
+ !this.isTermsAndConditionsChecked)
18359
+ return false;
18360
+ return (this.canProceedToShipping &&
18361
+ !!((_a = this.checkout.billingAddress) === null || _a === void 0 ? void 0 : _a.isValid) &&
18362
+ (((_b = this.selectedPaymentGateway) === null || _b === void 0 ? void 0 : _b.paymentMethodType) ===
18363
+ IkasPaymentMethodType.CREDIT_CARD
18364
+ ? (_c = this.cardData) === null || _c === void 0 ? void 0 : _c.isValid : true));
18365
+ },
18366
+ enumerable: false,
18367
+ configurable: true
18368
+ });
18369
+ return CheckoutViewModel;
18370
+ }());
18371
+ function chunkString(str, length) {
18372
+ return str.match(new RegExp(".{1," + length + "}", "g")) || [];
18373
+ }
18374
+ function isLastCharNumber(str) {
18375
+ return str && NUMBER_ONLY_REGEX.test(str.charAt(str.length - 1));
18376
+ }
18377
+ var CheckoutStep;
18378
+ (function (CheckoutStep) {
18379
+ CheckoutStep["INFO"] = "info";
18380
+ CheckoutStep["SHIPPING"] = "shipping";
18381
+ CheckoutStep["PAYMENT"] = "payment";
18382
+ CheckoutStep["SUCCESS"] = "success";
18383
+ })(CheckoutStep || (CheckoutStep = {}));
18384
+ var ErrorType;
18385
+ (function (ErrorType) {
18386
+ ErrorType[ErrorType["UNKNOWN"] = 0] = "UNKNOWN";
18387
+ ErrorType[ErrorType["API_ERROR"] = 1] = "API_ERROR";
18388
+ ErrorType[ErrorType["STOCK_ERROR"] = 2] = "STOCK_ERROR";
18389
+ ErrorType[ErrorType["PAYMENT_ERROR"] = 3] = "PAYMENT_ERROR";
18390
+ ErrorType[ErrorType["NO_SHIPPING_ERROR"] = 4] = "NO_SHIPPING_ERROR";
18391
+ })(ErrorType || (ErrorType = {}));
19359
18392
 
19360
- /**
19361
- * Creates a function that returns `value`.
19362
- *
19363
- * @static
19364
- * @memberOf _
19365
- * @since 2.4.0
19366
- * @category Util
19367
- * @param {*} value The value to return from the new function.
19368
- * @returns {Function} Returns the new constant function.
19369
- * @example
19370
- *
19371
- * var objects = _.times(2, _.constant({ 'a': 1 }));
19372
- *
19373
- * console.log(objects);
19374
- * // => [{ 'a': 1 }, { 'a': 1 }]
19375
- *
19376
- * console.log(objects[0] === objects[1]);
19377
- * // => true
19378
- */
19379
- function constant(value) {
19380
- return function() {
19381
- return value;
19382
- };
18393
+ var isServer$2 = typeof window === "undefined";
18394
+ var GoogleTagManager = /** @class */ (function () {
18395
+ function GoogleTagManager() {
18396
+ mobx.makeAutoObservable(this);
18397
+ }
18398
+ GoogleTagManager.pageView = function (url) {
18399
+ try {
18400
+ var event_1 = {
18401
+ event: "page-view",
18402
+ page: url,
18403
+ };
18404
+ //@ts-ignore
18405
+ !isServer$2 && window.dataLayer && window.dataLayer.push(event_1);
18406
+ return event_1;
18407
+ }
18408
+ catch (err) {
18409
+ console.error(err);
18410
+ }
18411
+ };
18412
+ GoogleTagManager.productView = function (productDetail) {
18413
+ try {
18414
+ var event_2 = {
18415
+ event: "view_item",
18416
+ ecommerce: {
18417
+ items: [productToGTMItem(productDetail)],
18418
+ },
18419
+ };
18420
+ //@ts-ignore
18421
+ !isServer$2 && window.dataLayer && window.dataLayer.push(event_2);
18422
+ return event_2;
18423
+ }
18424
+ catch (err) {
18425
+ console.error(err);
18426
+ }
18427
+ };
18428
+ GoogleTagManager.addToCart = function (item, quantity) {
18429
+ try {
18430
+ var event_3 = {
18431
+ event: "add_to_cart",
18432
+ ecommerce: {
18433
+ items: [
18434
+ item instanceof IkasProductDetail
18435
+ ? productToGTMItem(item, quantity)
18436
+ : orderLineItemToGTMItem(item, quantity),
18437
+ ],
18438
+ },
18439
+ };
18440
+ //@ts-ignore
18441
+ !isServer$2 && window.dataLayer && window.dataLayer.push(event_3);
18442
+ return event_3;
18443
+ }
18444
+ catch (err) {
18445
+ console.error(err);
18446
+ }
18447
+ };
18448
+ GoogleTagManager.removeFromCart = function (item, quantity) {
18449
+ try {
18450
+ var event_4 = {
18451
+ event: "remove_from_cart",
18452
+ ecommerce: {
18453
+ items: [
18454
+ item instanceof IkasProductDetail
18455
+ ? productToGTMItem(item, quantity)
18456
+ : orderLineItemToGTMItem(item, quantity),
18457
+ ],
18458
+ },
18459
+ };
18460
+ //@ts-ignore
18461
+ !isServer$2 && window.dataLayer && window.dataLayer.push(event_4);
18462
+ return event_4;
18463
+ }
18464
+ catch (err) {
18465
+ console.error(err);
18466
+ }
18467
+ };
18468
+ GoogleTagManager.beginCheckout = function (checkout) {
18469
+ var _a;
18470
+ try {
18471
+ var event_5 = {
18472
+ event: "begin_checkout",
18473
+ ecommerce: {
18474
+ items: (_a = checkout.cart) === null || _a === void 0 ? void 0 : _a.items.map(function (item) {
18475
+ return orderLineItemToGTMItem(item, item.quantity);
18476
+ }),
18477
+ },
18478
+ };
18479
+ //@ts-ignore
18480
+ !isServer$2 && window.dataLayer && window.dataLayer.push(event_5);
18481
+ return event_5;
18482
+ }
18483
+ catch (err) {
18484
+ console.error(err);
18485
+ }
18486
+ };
18487
+ GoogleTagManager.purchase = function (checkout, orderId) {
18488
+ var _a, _b, _c;
18489
+ try {
18490
+ var event_6 = {
18491
+ event: "purchase",
18492
+ ecommerce: {
18493
+ purchase: {
18494
+ transaction_id: orderId,
18495
+ affiliation: window.location.hostname,
18496
+ value: "" + checkout.totalFinalPrice,
18497
+ tax: "" + ((_a = checkout.cart) === null || _a === void 0 ? void 0 : _a.totalTax),
18498
+ shipping: "" + checkout.shippingTotal,
18499
+ currency: (_b = checkout.cart) === null || _b === void 0 ? void 0 : _b.currencyCode,
18500
+ coupon: checkout.couponCode,
18501
+ items: (_c = checkout.cart) === null || _c === void 0 ? void 0 : _c.items.map(function (item) {
18502
+ return orderLineItemToGTMItem(item, item.quantity);
18503
+ }),
18504
+ },
18505
+ },
18506
+ };
18507
+ //@ts-ignore
18508
+ !isServer$2 && window.dataLayer && window.dataLayer.push(event_6);
18509
+ return event_6;
18510
+ }
18511
+ catch (err) {
18512
+ console.error(err);
18513
+ }
18514
+ };
18515
+ GoogleTagManager.checkoutStep = function (checkout, step) {
18516
+ var _a;
18517
+ var eventName = "";
18518
+ if (step === CheckoutStep.INFO)
18519
+ eventName = "checkout_info";
18520
+ else if (step === CheckoutStep.SHIPPING)
18521
+ eventName = "checkout_shipping";
18522
+ else if (step === CheckoutStep.PAYMENT)
18523
+ eventName = "checkout_payment";
18524
+ else if (step === CheckoutStep.SUCCESS)
18525
+ eventName = "checkout_success";
18526
+ try {
18527
+ var event_7 = {
18528
+ event: eventName,
18529
+ ecommerce: {
18530
+ items: (_a = checkout.cart) === null || _a === void 0 ? void 0 : _a.items.map(function (item) {
18531
+ return orderLineItemToGTMItem(item, item.quantity);
18532
+ }),
18533
+ },
18534
+ };
18535
+ //@ts-ignore
18536
+ !isServer$2 && window.dataLayer && window.dataLayer.push(event_7);
18537
+ return event_7;
18538
+ }
18539
+ catch (err) {
18540
+ console.error(err);
18541
+ }
18542
+ };
18543
+ GoogleTagManager.disableHTML = function () {
18544
+ try {
18545
+ var data = {
18546
+ "gtm.blocklist": [
18547
+ "html",
18548
+ "customScripts",
18549
+ "customPixels",
18550
+ "nonGoogleScripts",
18551
+ ],
18552
+ };
18553
+ //@ts-ignore
18554
+ !isServer$2 && window.dataLayer && window.dataLayer.push(data);
18555
+ }
18556
+ catch (err) {
18557
+ console.error(err);
18558
+ }
18559
+ };
18560
+ return GoogleTagManager;
18561
+ }());
18562
+ function productToGTMItem(productDetail, quantity) {
18563
+ var _a;
18564
+ if (quantity === void 0) { quantity = 1; }
18565
+ return {
18566
+ item_name: productDetail.product.name,
18567
+ item_id: productDetail.selectedVariant.id,
18568
+ price: productDetail.selectedVariant.price.finalPrice,
18569
+ item_brand: ((_a = productDetail.product.brand) === null || _a === void 0 ? void 0 : _a.name) || "",
18570
+ item_category: productDetail.product.categories.length
18571
+ ? productDetail.product.categories[0].name
18572
+ : "",
18573
+ item_category_2: productDetail.product.categories.length > 1
18574
+ ? productDetail.product.categories[1].name
18575
+ : "",
18576
+ item_category_3: productDetail.product.categories.length > 2
18577
+ ? productDetail.product.categories[2].name
18578
+ : "",
18579
+ item_category_4: productDetail.product.categories.length > 3
18580
+ ? productDetail.product.categories[3].name
18581
+ : "",
18582
+ item_variant: productDetail.selectedVariant.variantValues
18583
+ .map(function (vv) { return vv.name; })
18584
+ .join(" / "),
18585
+ item_list_name: "",
18586
+ item_list_id: "",
18587
+ index: 1,
18588
+ quantity: quantity,
18589
+ };
18590
+ }
18591
+ function orderLineItemToGTMItem(orderLineItem, quantity) {
18592
+ if (quantity === void 0) { quantity = 1; }
18593
+ return {
18594
+ item_name: orderLineItem.variant.name,
18595
+ item_id: orderLineItem.variant.id,
18596
+ price: "" + orderLineItem.finalPrice,
18597
+ item_brand: "",
18598
+ item_category: "",
18599
+ item_category_2: "",
18600
+ item_category_3: "",
18601
+ item_category_4: "",
18602
+ item_variant: orderLineItem.variant.variantValues
18603
+ .map(function (vv) { return vv.variantValueName; })
18604
+ .join(" / "),
18605
+ item_list_name: "",
18606
+ item_list_id: "",
18607
+ index: 1,
18608
+ quantity: quantity,
18609
+ };
19383
18610
  }
19384
18611
 
19385
- var constant_1 = constant;
18612
+ var LS_BEGIN_CHECKOUT_KEY = "gtmBeginCheckout";
18613
+ var Analytics = /** @class */ (function () {
18614
+ function Analytics() {
18615
+ mobx.makeAutoObservable(this);
18616
+ }
18617
+ Analytics.pageView = function (url) {
18618
+ try {
18619
+ GoogleTagManager.pageView(url);
18620
+ }
18621
+ catch (err) {
18622
+ console.error(err);
18623
+ }
18624
+ };
18625
+ Analytics.productView = function (productDetail) {
18626
+ try {
18627
+ FacebookPixel.productView(productDetail);
18628
+ GoogleTagManager.productView(productDetail);
18629
+ }
18630
+ catch (err) {
18631
+ console.error(err);
18632
+ }
18633
+ };
18634
+ Analytics.addToCart = function (item, quantity) {
18635
+ try {
18636
+ FacebookPixel.addToCart(item, quantity);
18637
+ GoogleTagManager.addToCart(item, quantity);
18638
+ }
18639
+ catch (err) {
18640
+ console.error(err);
18641
+ }
18642
+ };
18643
+ Analytics.removeFromCart = function (item, quantity) {
18644
+ try {
18645
+ GoogleTagManager.removeFromCart(item, quantity);
18646
+ }
18647
+ catch (err) {
18648
+ console.error(err);
18649
+ }
18650
+ };
18651
+ Analytics.beginCheckout = function (checkout) {
18652
+ try {
18653
+ var beginCheckout = localStorage.getItem(LS_BEGIN_CHECKOUT_KEY);
18654
+ if (beginCheckout && checkout.id === beginCheckout)
18655
+ return;
18656
+ localStorage.setItem(LS_BEGIN_CHECKOUT_KEY, checkout.id);
18657
+ FacebookPixel.beginCheckout(checkout);
18658
+ GoogleTagManager.beginCheckout(checkout);
18659
+ }
18660
+ catch (err) {
18661
+ console.error(err);
18662
+ }
18663
+ };
18664
+ Analytics.purchase = function (checkout, orderId) {
18665
+ try {
18666
+ localStorage.removeItem(LS_BEGIN_CHECKOUT_KEY);
18667
+ FacebookPixel.purchase(checkout, orderId);
18668
+ GoogleTagManager.purchase(checkout, orderId);
18669
+ }
18670
+ catch (err) {
18671
+ console.error(err);
18672
+ }
18673
+ };
18674
+ Analytics.checkoutStep = function (checkout, step) {
18675
+ try {
18676
+ GoogleTagManager.checkoutStep(checkout, step);
18677
+ }
18678
+ catch (err) {
18679
+ console.error(err);
18680
+ }
18681
+ };
18682
+ Analytics.disableHTML = function () {
18683
+ try {
18684
+ GoogleTagManager.disableHTML();
18685
+ }
18686
+ catch (err) {
18687
+ console.error(err);
18688
+ }
18689
+ };
18690
+ Analytics.addToWishlist = function (id) {
18691
+ try {
18692
+ FacebookPixel.addToWishlist(id);
18693
+ }
18694
+ catch (err) {
18695
+ console.error(err);
18696
+ }
18697
+ };
18698
+ Analytics.search = function (searchKeyword) {
18699
+ try {
18700
+ FacebookPixel.search(searchKeyword);
18701
+ }
18702
+ catch (err) {
18703
+ console.error(err);
18704
+ }
18705
+ };
18706
+ Analytics.completeRegistration = function () {
18707
+ try {
18708
+ FacebookPixel.completeRegistration();
18709
+ }
18710
+ catch (err) {
18711
+ console.error(err);
18712
+ }
18713
+ };
18714
+ Analytics.viewCart = function (cart) {
18715
+ try {
18716
+ if (cart) {
18717
+ FacebookPixel.viewCart(cart);
18718
+ }
18719
+ }
18720
+ catch (err) {
18721
+ console.error(err);
18722
+ }
18723
+ };
18724
+ Analytics.viewCategory = function (categoryPath) {
18725
+ try {
18726
+ FacebookPixel.viewCategory(categoryPath);
18727
+ }
18728
+ catch (err) {
18729
+ console.error(err);
18730
+ }
18731
+ };
18732
+ Analytics.contactForm = function () {
18733
+ try {
18734
+ FacebookPixel.contactForm();
18735
+ }
18736
+ catch (err) {
18737
+ console.error(err);
18738
+ }
18739
+ };
18740
+ return Analytics;
18741
+ }());
19386
18742
 
19387
- /**
19388
- * The base implementation of `setToString` without support for hot loop shorting.
19389
- *
19390
- * @private
19391
- * @param {Function} func The function to modify.
19392
- * @param {Function} string The `toString` result.
19393
- * @returns {Function} Returns `func`.
19394
- */
19395
- var baseSetToString = !_defineProperty ? identity_1 : function(func, string) {
19396
- return _defineProperty(func, 'toString', {
19397
- 'configurable': true,
19398
- 'enumerable': false,
19399
- 'value': constant_1(string),
19400
- 'writable': true
19401
- });
18743
+ var AnalyticsHead = function (_a) {
18744
+ var blockHTML = _a.blockHTML;
18745
+ var gtmId = IkasStorefrontConfig.gtmId;
18746
+ var fbpId = IkasStorefrontConfig.fbpId;
18747
+ return (React.createElement(React.Fragment, null,
18748
+ blockHTML && (React.createElement("script", { dangerouslySetInnerHTML: {
18749
+ __html: "dataLayer = [{'gtm.blocklist': ['html']}];",
18750
+ } })),
18751
+ gtmId && (React.createElement("script", { dangerouslySetInnerHTML: {
18752
+ __html: "(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\n new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\n j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=\n 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);\n })(window,document,'script','dataLayer','" + gtmId + "');",
18753
+ } })),
18754
+ fbpId && (React.createElement("script", { dangerouslySetInnerHTML: {
18755
+ __html: "!function(f,b,e,v,n,t,s)\n {if(f.fbq)return;n=f.fbq=function(){n.callMethod?\n n.callMethod.apply(n,arguments):n.queue.push(arguments)};\n if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';\n n.queue=[];t=b.createElement(e);t.async=!0;\n t.src=v;s=b.getElementsByTagName(e)[0];\n s.parentNode.insertBefore(t,s)}(window, document,'script',\n 'https://connect.facebook.net/en_US/fbevents.js');\n fbq('init', '" + fbpId + "');\n fbq('track', 'PageView');",
18756
+ } }))));
18757
+ };
18758
+ var AnalyticsBody = function () {
18759
+ var gtmId = IkasStorefrontConfig.gtmId;
18760
+ var fbpId = IkasStorefrontConfig.fbpId;
18761
+ return (React.createElement(React.Fragment, null,
18762
+ gtmId && (React.createElement("noscript", { dangerouslySetInnerHTML: {
18763
+ __html: "<iframe src=\"https://www.googletagmanager.com/ns.html?id=" + gtmId + "\" height=\"0\" width=\"0\" style=\"display:none;visibility:hidden\"></iframe>",
18764
+ } })),
18765
+ fbpId && (React.createElement("noscript", { dangerouslySetInnerHTML: {
18766
+ __html: "<img height=\"1\" width=\"1\" style=\"display:none\" \n src=\"https://www.facebook.com/tr?id=" + fbpId + "&ev=PageView&noscript=1\"/>",
18767
+ } }))));
19402
18768
  };
19403
18769
 
19404
- var _baseSetToString = baseSetToString;
19405
-
19406
- /** Used to detect hot functions by number of calls within a span of milliseconds. */
19407
- var HOT_COUNT = 800,
19408
- HOT_SPAN = 16;
19409
-
19410
- /* Built-in method references for those with the same name as other `lodash` methods. */
19411
- var nativeNow = Date.now;
19412
-
19413
- /**
19414
- * Creates a function that'll short out and invoke `identity` instead
19415
- * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
19416
- * milliseconds.
19417
- *
19418
- * @private
19419
- * @param {Function} func The function to restrict.
19420
- * @returns {Function} Returns the new shortable function.
19421
- */
19422
- function shortOut(func) {
19423
- var count = 0,
19424
- lastCalled = 0;
18770
+ var isServer$3 = typeof localStorage === "undefined";
18771
+ var LS_TOKEN_KEY = "customerToken";
18772
+ var LS_TOKEN_EXPIRY = "customerTokenExpiry";
18773
+ var LS_CUSTOMER_KEY = "customer";
18774
+ var IkasCustomerStore = /** @class */ (function () {
18775
+ function IkasCustomerStore(baseStore) {
18776
+ var _this = this;
18777
+ this.customer = null;
18778
+ this.token = null;
18779
+ this.tokenExpiry = null;
18780
+ this.baseStore = null;
18781
+ this._initialized = false;
18782
+ this.login = function (email, password) { return __awaiter(_this, void 0, void 0, function () {
18783
+ var response, cart;
18784
+ var _a;
18785
+ return __generator(this, function (_b) {
18786
+ switch (_b.label) {
18787
+ case 0: return [4 /*yield*/, IkasCustomerAPI.login(email, password)];
18788
+ case 1:
18789
+ response = _b.sent();
18790
+ if (!response) return [3 /*break*/, 4];
18791
+ this.setToken(response.token, response.tokenExpiry);
18792
+ this.setCustomer(response.customer);
18793
+ cart = (_a = this.baseStore) === null || _a === void 0 ? void 0 : _a.cartStore.cart;
18794
+ if (!cart) return [3 /*break*/, 3];
18795
+ return [4 /*yield*/, this.baseStore.cartStore.changeItemQuantity(cart.items[0], cart.items[0].quantity)];
18796
+ case 2:
18797
+ _b.sent();
18798
+ _b.label = 3;
18799
+ case 3: return [2 /*return*/, true];
18800
+ case 4: return [2 /*return*/, false];
18801
+ }
18802
+ });
18803
+ }); };
18804
+ this.register = function (firstName, lastName, email, password) { return __awaiter(_this, void 0, void 0, function () {
18805
+ var response;
18806
+ return __generator(this, function (_a) {
18807
+ switch (_a.label) {
18808
+ case 0: return [4 /*yield*/, IkasCustomerAPI.register(email, password, firstName, lastName)];
18809
+ case 1:
18810
+ response = _a.sent();
18811
+ if (response) {
18812
+ this.setToken(response.token, response.tokenExpiry);
18813
+ this.setCustomer(response.customer);
18814
+ return [2 /*return*/, true];
18815
+ }
18816
+ return [2 /*return*/, false];
18817
+ }
18818
+ });
18819
+ }); };
18820
+ this.saveContactForm = function (input) { return __awaiter(_this, void 0, void 0, function () {
18821
+ return __generator(this, function (_a) {
18822
+ switch (_a.label) {
18823
+ case 0:
18824
+ Analytics.contactForm();
18825
+ return [4 /*yield*/, IkasContactFormAPI.sendContactFormToMerchant(input)];
18826
+ case 1: return [2 /*return*/, _a.sent()];
18827
+ }
18828
+ });
18829
+ }); };
18830
+ this.checkEmail = function (email) { return __awaiter(_this, void 0, void 0, function () {
18831
+ return __generator(this, function (_a) {
18832
+ switch (_a.label) {
18833
+ case 0: return [4 /*yield*/, IkasCustomerAPI.checkEmail(email)];
18834
+ case 1: return [2 /*return*/, _a.sent()];
18835
+ }
18836
+ });
18837
+ }); };
18838
+ this.forgotPassword = function (email) { return __awaiter(_this, void 0, void 0, function () {
18839
+ return __generator(this, function (_a) {
18840
+ switch (_a.label) {
18841
+ case 0: return [4 /*yield*/, IkasCustomerAPI.forgotPassword(email)];
18842
+ case 1: return [2 /*return*/, _a.sent()];
18843
+ }
18844
+ });
18845
+ }); };
18846
+ this.recoverPassword = function (password, passwordAgain, token) { return __awaiter(_this, void 0, void 0, function () {
18847
+ return __generator(this, function (_a) {
18848
+ switch (_a.label) {
18849
+ case 0: return [4 /*yield*/, IkasCustomerAPI.recoverPassword(password, passwordAgain, token)];
18850
+ case 1: return [2 /*return*/, _a.sent()];
18851
+ }
18852
+ });
18853
+ }); };
18854
+ this.logout = function () {
18855
+ var _a;
18856
+ localStorage.removeItem(LS_TOKEN_KEY);
18857
+ localStorage.removeItem(LS_TOKEN_EXPIRY);
18858
+ localStorage.removeItem(LS_CUSTOMER_KEY);
18859
+ _this.customer = undefined;
18860
+ _this.token = undefined;
18861
+ _this.tokenExpiry = undefined;
18862
+ (_a = _this.baseStore) === null || _a === void 0 ? void 0 : _a.cartStore.removeCart();
18863
+ };
18864
+ this.saveCustomer = function (customer) { return __awaiter(_this, void 0, void 0, function () {
18865
+ var savedCustomer;
18866
+ return __generator(this, function (_a) {
18867
+ switch (_a.label) {
18868
+ case 0: return [4 /*yield*/, IkasCustomerAPI.saveCustomer(customer)];
18869
+ case 1:
18870
+ savedCustomer = _a.sent();
18871
+ if (savedCustomer) {
18872
+ this.setCustomer(savedCustomer);
18873
+ return [2 /*return*/, true];
18874
+ }
18875
+ return [2 /*return*/, false];
18876
+ }
18877
+ });
18878
+ }); };
18879
+ this.getOrders = function () { return __awaiter(_this, void 0, void 0, function () {
18880
+ return __generator(this, function (_a) {
18881
+ switch (_a.label) {
18882
+ case 0: return [4 /*yield*/, IkasCustomerAPI.getOrders()];
18883
+ case 1: return [2 /*return*/, _a.sent()];
18884
+ }
18885
+ });
18886
+ }); };
18887
+ this.getOrder = function (id) { return __awaiter(_this, void 0, void 0, function () {
18888
+ var orders;
18889
+ return __generator(this, function (_a) {
18890
+ switch (_a.label) {
18891
+ case 0: return [4 /*yield*/, IkasCustomerAPI.getOrders(id)];
18892
+ case 1:
18893
+ orders = _a.sent();
18894
+ if (!Array.isArray(orders) || !orders.length)
18895
+ return [2 /*return*/, null];
18896
+ return [2 /*return*/, orders[0]];
18897
+ }
18898
+ });
18899
+ }); };
18900
+ this.getOrderTransactions = function (params) {
18901
+ if (params === void 0) { params = {}; }
18902
+ return __awaiter(_this, void 0, void 0, function () {
18903
+ return __generator(this, function (_a) {
18904
+ switch (_a.label) {
18905
+ case 0: return [4 /*yield*/, IkasCustomerAPI.getOrderTransactions(params)];
18906
+ case 1: return [2 /*return*/, _a.sent()];
18907
+ }
18908
+ });
18909
+ });
18910
+ };
18911
+ this.getFavoriteProductsIds = function () { return __awaiter(_this, void 0, void 0, function () {
18912
+ var favoriteProductsResult;
18913
+ return __generator(this, function (_b) {
18914
+ switch (_b.label) {
18915
+ case 0:
18916
+ _b.trys.push([0, 2, , 3]);
18917
+ return [4 /*yield*/, IkasFavoriteProductAPI.listFavoriteProducts()];
18918
+ case 1:
18919
+ favoriteProductsResult = _b.sent();
18920
+ return [2 /*return*/, favoriteProductsResult];
18921
+ case 2:
18922
+ _b.sent();
18923
+ return [2 /*return*/, []];
18924
+ case 3: return [2 /*return*/];
18925
+ }
18926
+ });
18927
+ }); };
18928
+ this.getFavoriteProducts = function () { return __awaiter(_this, void 0, void 0, function () {
18929
+ var favoriteProductsResult, productsResult;
18930
+ return __generator(this, function (_b) {
18931
+ switch (_b.label) {
18932
+ case 0:
18933
+ _b.trys.push([0, 3, , 4]);
18934
+ return [4 /*yield*/, IkasFavoriteProductAPI.listFavoriteProducts()];
18935
+ case 1:
18936
+ favoriteProductsResult = _b.sent();
18937
+ if (!favoriteProductsResult.length)
18938
+ return [2 /*return*/, []];
18939
+ return [4 /*yield*/, IkasProductSearchAPI.searchProducts({
18940
+ productIdList: favoriteProductsResult.map(function (fP) { return fP.productId; }),
18941
+ priceListId: IkasStorefrontConfig.priceListId,
18942
+ })];
18943
+ case 2:
18944
+ productsResult = _b.sent();
18945
+ return [2 /*return*/, (productsResult === null || productsResult === void 0 ? void 0 : productsResult.data) || []];
18946
+ case 3:
18947
+ _b.sent();
18948
+ return [2 /*return*/, []];
18949
+ case 4: return [2 /*return*/];
18950
+ }
18951
+ });
18952
+ }); };
18953
+ this.addItemToFavorite = function (productId) { return __awaiter(_this, void 0, void 0, function () {
18954
+ var customerId, result;
18955
+ var _b;
18956
+ return __generator(this, function (_c) {
18957
+ switch (_c.label) {
18958
+ case 0:
18959
+ customerId = (_b = this.customer) === null || _b === void 0 ? void 0 : _b.id;
18960
+ if (!customerId)
18961
+ throw Error("Unauthorized");
18962
+ _c.label = 1;
18963
+ case 1:
18964
+ _c.trys.push([1, 3, , 4]);
18965
+ return [4 /*yield*/, IkasFavoriteProductAPI.saveFavoriteProduct(true, productId)];
18966
+ case 2:
18967
+ result = _c.sent();
18968
+ Analytics.addToWishlist(productId);
18969
+ return [2 /*return*/, result];
18970
+ case 3:
18971
+ _c.sent();
18972
+ return [2 /*return*/, false];
18973
+ case 4: return [2 /*return*/];
18974
+ }
18975
+ });
18976
+ }); };
18977
+ this.removeItemFromFavorite = function (productId) { return __awaiter(_this, void 0, void 0, function () {
18978
+ var customerId, result;
18979
+ var _b;
18980
+ return __generator(this, function (_c) {
18981
+ switch (_c.label) {
18982
+ case 0:
18983
+ customerId = (_b = this.customer) === null || _b === void 0 ? void 0 : _b.id;
18984
+ if (!customerId)
18985
+ throw Error("Unauthorized");
18986
+ _c.label = 1;
18987
+ case 1:
18988
+ _c.trys.push([1, 3, , 4]);
18989
+ return [4 /*yield*/, IkasFavoriteProductAPI.saveFavoriteProduct(false, productId)];
18990
+ case 2:
18991
+ result = _c.sent();
18992
+ return [2 /*return*/, result];
18993
+ case 3:
18994
+ _c.sent();
18995
+ return [2 /*return*/, false];
18996
+ case 4: return [2 /*return*/];
18997
+ }
18998
+ });
18999
+ }); };
19000
+ this.isProductFavorite = function (productId) { return __awaiter(_this, void 0, void 0, function () {
19001
+ var customerId;
19002
+ var _a;
19003
+ return __generator(this, function (_b) {
19004
+ switch (_b.label) {
19005
+ case 0:
19006
+ customerId = (_a = this.customer) === null || _a === void 0 ? void 0 : _a.id;
19007
+ if (!customerId)
19008
+ throw Error("Unauthorized");
19009
+ return [4 /*yield*/, IkasFavoriteProductAPI.isFavoriteProduct(productId)];
19010
+ case 1: return [2 /*return*/, _b.sent()];
19011
+ }
19012
+ });
19013
+ }); };
19014
+ this.baseStore = baseStore;
19015
+ this.init();
19016
+ mobx.makeAutoObservable(this);
19017
+ }
19018
+ Object.defineProperty(IkasCustomerStore.prototype, "initialized", {
19019
+ get: function () {
19020
+ return this._initialized;
19021
+ },
19022
+ enumerable: false,
19023
+ configurable: true
19024
+ });
19025
+ IkasCustomerStore.prototype.init = function () {
19026
+ return __awaiter(this, void 0, void 0, function () {
19027
+ return __generator(this, function (_a) {
19028
+ switch (_a.label) {
19029
+ case 0:
19030
+ this.loadToken();
19031
+ this.loadCustomer();
19032
+ return [4 /*yield*/, this.refreshToken()];
19033
+ case 1:
19034
+ _a.sent();
19035
+ return [4 /*yield*/, this.getCustomer()];
19036
+ case 2:
19037
+ _a.sent();
19038
+ this._initialized = true;
19039
+ return [2 /*return*/];
19040
+ }
19041
+ });
19042
+ });
19043
+ };
19044
+ IkasCustomerStore.prototype.getCustomer = function () {
19045
+ return __awaiter(this, void 0, void 0, function () {
19046
+ var customer;
19047
+ return __generator(this, function (_a) {
19048
+ switch (_a.label) {
19049
+ case 0:
19050
+ if (isServer$3 || !this.token)
19051
+ return [2 /*return*/];
19052
+ return [4 /*yield*/, IkasCustomerAPI.getCustomer()];
19053
+ case 1:
19054
+ customer = _a.sent();
19055
+ if (customer)
19056
+ this.setCustomer(customer);
19057
+ return [2 /*return*/];
19058
+ }
19059
+ });
19060
+ });
19061
+ };
19062
+ IkasCustomerStore.prototype.refreshToken = function () {
19063
+ return __awaiter(this, void 0, void 0, function () {
19064
+ var response;
19065
+ return __generator(this, function (_a) {
19066
+ switch (_a.label) {
19067
+ case 0:
19068
+ if (!this.token)
19069
+ return [2 /*return*/];
19070
+ return [4 /*yield*/, IkasCustomerAPI.refreshToken(this.token)];
19071
+ case 1:
19072
+ response = _a.sent();
19073
+ if ((response === null || response === void 0 ? void 0 : response.token) || (response === null || response === void 0 ? void 0 : response.tokenExpiry))
19074
+ this.setToken(response.token, response.tokenExpiry);
19075
+ return [2 /*return*/];
19076
+ }
19077
+ });
19078
+ });
19079
+ };
19080
+ IkasCustomerStore.prototype.setCustomer = function (customer) {
19081
+ if (!isServer$3) {
19082
+ localStorage.setItem(LS_CUSTOMER_KEY, JSON.stringify(customer));
19083
+ }
19084
+ this.customer = new IkasCustomer(customer);
19085
+ };
19086
+ IkasCustomerStore.prototype.loadCustomer = function () {
19087
+ if (isServer$3)
19088
+ return;
19089
+ try {
19090
+ var customerStr = localStorage.getItem(LS_CUSTOMER_KEY);
19091
+ if (customerStr) {
19092
+ this.customer = new IkasCustomer(JSON.parse(customerStr));
19093
+ }
19094
+ }
19095
+ catch (err) { }
19096
+ };
19097
+ IkasCustomerStore.prototype.setToken = function (token, tokenExpiry) {
19098
+ if (isServer$3)
19099
+ return;
19100
+ this.token = token;
19101
+ this.tokenExpiry = tokenExpiry;
19102
+ localStorage.setItem(LS_TOKEN_KEY, token);
19103
+ localStorage.setItem(LS_TOKEN_EXPIRY, tokenExpiry + "");
19104
+ apollo.setCustomerToken(token);
19105
+ };
19106
+ IkasCustomerStore.prototype.loadToken = function () {
19107
+ if (isServer$3)
19108
+ return;
19109
+ var token = localStorage.getItem(LS_TOKEN_KEY);
19110
+ var tokenExpiry = localStorage.getItem(LS_TOKEN_EXPIRY);
19111
+ if (token && tokenExpiry) {
19112
+ this.setToken(token, parseInt(tokenExpiry));
19113
+ }
19114
+ };
19115
+ return IkasCustomerStore;
19116
+ }());
19425
19117
 
19426
- return function() {
19427
- var stamp = nativeNow(),
19428
- remaining = HOT_SPAN - (stamp - lastCalled);
19118
+ var IkasOrder = /** @class */ (function () {
19119
+ function IkasOrder(data) {
19120
+ var _this = this;
19121
+ this.customerStore = new IkasCustomerStore();
19122
+ this.refund = function () { return __awaiter(_this, void 0, void 0, function () {
19123
+ var refundOrderLineItems_1, result;
19124
+ var _this = this;
19125
+ return __generator(this, function (_a) {
19126
+ switch (_a.label) {
19127
+ case 0:
19128
+ _a.trys.push([0, 2, , 3]);
19129
+ refundOrderLineItems_1 = [];
19130
+ this.orderLineItems.map(function (item) {
19131
+ if (item.refundQuantity !== null) {
19132
+ refundOrderLineItems_1 === null || refundOrderLineItems_1 === void 0 ? void 0 : refundOrderLineItems_1.push({
19133
+ orderLineItemId: item.id,
19134
+ quantity: item.refundQuantity ? item.refundQuantity : 0,
19135
+ });
19136
+ }
19137
+ });
19138
+ return [4 /*yield*/, IkasCustomerAPI.saveIkasOrderRefund({
19139
+ orderId: this.id,
19140
+ orderLineItems: refundOrderLineItems_1,
19141
+ })];
19142
+ case 1:
19143
+ result = _a.sent();
19144
+ if (result) {
19145
+ // Set the new order object to this
19146
+ Object.entries(result).forEach(function (_a) {
19147
+ var key = _a[0], value = _a[1];
19148
+ _this[key] = value;
19149
+ });
19150
+ return [2 /*return*/, true];
19151
+ }
19152
+ return [3 /*break*/, 3];
19153
+ case 2:
19154
+ _a.sent();
19155
+ return [3 /*break*/, 3];
19156
+ case 3: return [2 /*return*/, false];
19157
+ }
19158
+ });
19159
+ }); };
19160
+ this.id = data.id;
19161
+ this.orderNumber = data.orderNumber;
19162
+ this.note = data.note;
19163
+ this.totalPrice = data.totalPrice;
19164
+ this.totalFinalPrice = data.totalFinalPrice;
19165
+ // this.totalDiscountPrice = data.totalDiscountPrice;
19166
+ // this.totalWeight = data.totalWeight;
19167
+ this.currencyCode = data.currencyCode;
19168
+ this.orderedAt = data.orderedAt;
19169
+ this.cancelledAt = data.cancelledAt;
19170
+ this.status = data.status;
19171
+ this.cancelReason = data.cancelReason;
19172
+ this.orderPaymentStatus = data.orderPaymentStatus;
19173
+ this.orderPackageStatus = data.orderPackageStatus;
19174
+ this.shippingMethod = data.shippingMethod;
19175
+ this.shippingAddress = data.shippingAddress
19176
+ ? new IkasOrderAddress(data.shippingAddress)
19177
+ : null;
19178
+ this.billingAddress = data.billingAddress
19179
+ ? new IkasOrderAddress(data.billingAddress)
19180
+ : null;
19181
+ this.orderLineItems = data.orderLineItems
19182
+ ? data.orderLineItems.map(function (o) { return new IkasOrderLineItem(o); })
19183
+ : [];
19184
+ this.orderAdjustments = data.orderAdjustments;
19185
+ this.shippingLines = data.shippingLines;
19186
+ this.customer = data.customer;
19187
+ this.taxLines = data.taxLines;
19188
+ this.orderPackages = data.orderPackages;
19189
+ this.currencyRates = data.currencyRates;
19190
+ mobx.makeAutoObservable(this);
19191
+ }
19192
+ Object.defineProperty(IkasOrder.prototype, "refundableItems", {
19193
+ get: function () {
19194
+ return this.orderLineItems.filter(function (item) { return item.status === exports.OrderLineItemStatusEnum.FULFILLED; });
19195
+ },
19196
+ enumerable: false,
19197
+ configurable: true
19198
+ });
19199
+ Object.defineProperty(IkasOrder.prototype, "unfullfilledItems", {
19200
+ get: function () {
19201
+ var _this = this;
19202
+ return this.orderLineItems.filter(function (item) {
19203
+ var _a;
19204
+ var isInAPackage = (_a = _this.orderPackages) === null || _a === void 0 ? void 0 : _a.some(function (op) {
19205
+ return op.orderLineItemIds.includes(item.id);
19206
+ });
19207
+ return !isInAPackage;
19208
+ });
19209
+ },
19210
+ enumerable: false,
19211
+ configurable: true
19212
+ });
19213
+ Object.defineProperty(IkasOrder.prototype, "refundedItems", {
19214
+ get: function () {
19215
+ return this.orderLineItems.filter(function (item) {
19216
+ return item.status === exports.OrderLineItemStatusEnum.REFUNDED ||
19217
+ item.status === exports.OrderLineItemStatusEnum.REFUND_REQUESTED ||
19218
+ item.status === exports.OrderLineItemStatusEnum.REFUND_REQUEST_ACCEPTED ||
19219
+ item.status === exports.OrderLineItemStatusEnum.REFUND_REJECTED;
19220
+ });
19221
+ },
19222
+ enumerable: false,
19223
+ configurable: true
19224
+ });
19225
+ return IkasOrder;
19226
+ }());
19227
+ (function (IkasOrderStatus) {
19228
+ IkasOrderStatus["DRAFT"] = "DRAFT";
19229
+ IkasOrderStatus["CREATED"] = "CREATED";
19230
+ IkasOrderStatus["CANCELLED"] = "CANCELLED";
19231
+ IkasOrderStatus["REFUNDED"] = "REFUNDED";
19232
+ })(exports.IkasOrderStatus || (exports.IkasOrderStatus = {}));
19233
+ (function (IkasOrderCancelledReason) {
19234
+ IkasOrderCancelledReason["CUSTOMER"] = "CUSTOMER";
19235
+ IkasOrderCancelledReason["INVENTORY"] = "INVENTORY";
19236
+ IkasOrderCancelledReason["DECLINED"] = "DECLINED";
19237
+ IkasOrderCancelledReason["OTHER"] = "OTHER";
19238
+ })(exports.IkasOrderCancelledReason || (exports.IkasOrderCancelledReason = {}));
19239
+ (function (IkasAmountTypeEnum) {
19240
+ IkasAmountTypeEnum["AMOUNT"] = "AMOUNT";
19241
+ IkasAmountTypeEnum["RATIO"] = "RATIO";
19242
+ })(exports.IkasAmountTypeEnum || (exports.IkasAmountTypeEnum = {}));
19243
+ var IkasAdjustmentEnum;
19244
+ (function (IkasAdjustmentEnum) {
19245
+ IkasAdjustmentEnum["DECREMENT"] = "DECREMENT";
19246
+ IkasAdjustmentEnum["INCREMENT"] = "INCREMENT";
19247
+ })(IkasAdjustmentEnum || (IkasAdjustmentEnum = {}));
19248
+ (function (IkasOrderPaymentStatus) {
19249
+ IkasOrderPaymentStatus["WAITING"] = "WAITING";
19250
+ IkasOrderPaymentStatus["PAID"] = "PAID";
19251
+ IkasOrderPaymentStatus["PARTIALLY_PAID"] = "PARTIALLY_PAID";
19252
+ })(exports.IkasOrderPaymentStatus || (exports.IkasOrderPaymentStatus = {}));
19253
+ (function (IkasOrderPackageStatus) {
19254
+ IkasOrderPackageStatus["UNFULFILLED"] = "UNFULFILLED";
19255
+ IkasOrderPackageStatus["PARTIALLY_FULFILLED"] = "PARTIALLY_FULFILLED";
19256
+ IkasOrderPackageStatus["FULFILLED"] = "FULFILLED";
19257
+ })(exports.IkasOrderPackageStatus || (exports.IkasOrderPackageStatus = {}));
19258
+ (function (IkasOrderPackageFulfillStatus) {
19259
+ IkasOrderPackageFulfillStatus["DELIVERED"] = "DELIVERED";
19260
+ IkasOrderPackageFulfillStatus["FULFILLED"] = "FULFILLED";
19261
+ IkasOrderPackageFulfillStatus["SHIPPED"] = "SHIPPED";
19262
+ })(exports.IkasOrderPackageFulfillStatus || (exports.IkasOrderPackageFulfillStatus = {}));
19263
+ (function (IkasOrderShippingMethod) {
19264
+ IkasOrderShippingMethod["CLICK_AND_COLLECT"] = "CLICK_AND_COLLECT";
19265
+ IkasOrderShippingMethod["SHIPMENT"] = "SHIPMENT";
19266
+ IkasOrderShippingMethod["NO_SHIPMENT"] = "NO_SHIPMENT";
19267
+ })(exports.IkasOrderShippingMethod || (exports.IkasOrderShippingMethod = {}));
19268
+ (function (OrderLineItemStatusEnum) {
19269
+ OrderLineItemStatusEnum["FULFILLED"] = "FULFILLED";
19270
+ OrderLineItemStatusEnum["UNFULFILLED"] = "UNFULFILLED";
19271
+ OrderLineItemStatusEnum["DELIVERED"] = "DELIVERED";
19272
+ // Cancel Enums
19273
+ OrderLineItemStatusEnum["CANCELLED"] = "CANCELLED";
19274
+ OrderLineItemStatusEnum["CANCEL_REQUESTED"] = "CANCEL_REQUESTED";
19275
+ OrderLineItemStatusEnum["CANCEL_REJECTED"] = "CANCEL_REJECTED";
19276
+ // Refund Enums
19277
+ OrderLineItemStatusEnum["REFUND_REQUESTED"] = "REFUND_REQUESTED";
19278
+ OrderLineItemStatusEnum["REFUND_REQUEST_ACCEPTED"] = "REFUND_REQUEST_ACCEPTED";
19279
+ OrderLineItemStatusEnum["REFUNDED"] = "REFUNDED";
19280
+ OrderLineItemStatusEnum["REFUND_REJECTED"] = "REFUND_REJECTED";
19281
+ })(exports.OrderLineItemStatusEnum || (exports.OrderLineItemStatusEnum = {}));
19429
19282
 
19430
- lastCalled = stamp;
19431
- if (remaining > 0) {
19432
- if (++count >= HOT_COUNT) {
19433
- return arguments[0];
19434
- }
19435
- } else {
19436
- count = 0;
19437
- }
19438
- return func.apply(undefined, arguments);
19439
- };
19440
- }
19283
+ var IkasProductPrice = /** @class */ (function () {
19284
+ function IkasProductPrice(data) {
19285
+ if (data === void 0) { data = {}; }
19286
+ this.sellPrice = data.sellPrice || 0;
19287
+ this.discountPrice =
19288
+ data.discountPrice !== undefined ? data.discountPrice : null;
19289
+ this.currency = data.currency || "";
19290
+ mobx.makeAutoObservable(this);
19291
+ }
19292
+ Object.defineProperty(IkasProductPrice.prototype, "finalPrice", {
19293
+ get: function () {
19294
+ return this.discountPrice !== null ? this.discountPrice : this.sellPrice;
19295
+ },
19296
+ enumerable: false,
19297
+ configurable: true
19298
+ });
19299
+ Object.defineProperty(IkasProductPrice.prototype, "hasDiscount", {
19300
+ get: function () {
19301
+ return this.discountPrice !== null;
19302
+ },
19303
+ enumerable: false,
19304
+ configurable: true
19305
+ });
19306
+ Object.defineProperty(IkasProductPrice.prototype, "discountAmount", {
19307
+ get: function () {
19308
+ if (this.hasDiscount)
19309
+ return this.sellPrice - this.discountPrice;
19310
+ return 0;
19311
+ },
19312
+ enumerable: false,
19313
+ configurable: true
19314
+ });
19315
+ Object.defineProperty(IkasProductPrice.prototype, "discountPercentage", {
19316
+ get: function () {
19317
+ if (this.hasDiscount)
19318
+ return (100 - (this.finalPrice * 100) / this.sellPrice).toFixed(0);
19319
+ return 0;
19320
+ },
19321
+ enumerable: false,
19322
+ configurable: true
19323
+ });
19324
+ return IkasProductPrice;
19325
+ }());
19441
19326
 
19442
- var _shortOut = shortOut;
19327
+ var IkasVariantValue = /** @class */ (function () {
19328
+ function IkasVariantValue(data) {
19329
+ this.id = data.id || "";
19330
+ this.name = data.name || "";
19331
+ this.colorCode = data.colorCode || null;
19332
+ this.thumbnailImageId = data.thumbnailImageId || null;
19333
+ this.variantTypeId = data.variantTypeId || "";
19334
+ mobx.makeAutoObservable(this);
19335
+ }
19336
+ Object.defineProperty(IkasVariantValue.prototype, "slug", {
19337
+ get: function () {
19338
+ return stringToSlug(this.name);
19339
+ },
19340
+ enumerable: false,
19341
+ configurable: true
19342
+ });
19343
+ Object.defineProperty(IkasVariantValue.prototype, "thumbnailImage", {
19344
+ get: function () {
19345
+ if (this.thumbnailImageId)
19346
+ return new IkasImage(this.thumbnailImageId);
19347
+ },
19348
+ enumerable: false,
19349
+ configurable: true
19350
+ });
19351
+ return IkasVariantValue;
19352
+ }());
19443
19353
 
19444
- /**
19445
- * Sets the `toString` method of `func` to return `string`.
19446
- *
19447
- * @private
19448
- * @param {Function} func The function to modify.
19449
- * @param {Function} string The `toString` result.
19450
- * @returns {Function} Returns `func`.
19451
- */
19452
- var setToString = _shortOut(_baseSetToString);
19354
+ var IkasProductAttributeOption = /** @class */ (function () {
19355
+ function IkasProductAttributeOption(data) {
19356
+ if (data === void 0) { data = {}; }
19357
+ this.id = data.id || "";
19358
+ this.name = data.name || "";
19359
+ mobx.makeAutoObservable(this);
19360
+ }
19361
+ return IkasProductAttributeOption;
19362
+ }());
19453
19363
 
19454
- var _setToString = setToString;
19364
+ var IkasProductAttribute = /** @class */ (function () {
19365
+ function IkasProductAttribute(data) {
19366
+ this.id = data.id || "";
19367
+ this.name = data.name || "";
19368
+ this.type = data.type || IkasProductAttributeType.TEXT;
19369
+ this.options = data.options || null;
19370
+ mobx.makeAutoObservable(this);
19371
+ }
19372
+ return IkasProductAttribute;
19373
+ }());
19374
+ var IkasProductAttributeType;
19375
+ (function (IkasProductAttributeType) {
19376
+ IkasProductAttributeType["CHOICE"] = "CHOICE";
19377
+ IkasProductAttributeType["MULTIPLE_CHOICE"] = "MULTIPLE_CHOICE";
19378
+ IkasProductAttributeType["TEXT"] = "TEXT";
19379
+ IkasProductAttributeType["BOOLEAN"] = "BOOLEAN";
19380
+ IkasProductAttributeType["NUMERIC"] = "NUMERIC";
19381
+ IkasProductAttributeType["DATETIME"] = "DATETIME";
19382
+ IkasProductAttributeType["HTML"] = "HTML";
19383
+ })(IkasProductAttributeType || (IkasProductAttributeType = {}));
19455
19384
 
19456
- /**
19457
- * The base implementation of `_.rest` which doesn't validate or coerce arguments.
19458
- *
19459
- * @private
19460
- * @param {Function} func The function to apply a rest parameter to.
19461
- * @param {number} [start=func.length-1] The start position of the rest parameter.
19462
- * @returns {Function} Returns the new function.
19463
- */
19464
- function baseRest(func, start) {
19465
- return _setToString(_overRest(func, start, identity_1), func + '');
19466
- }
19385
+ var IkasProductAttributeValue = /** @class */ (function () {
19386
+ function IkasProductAttributeValue(data) {
19387
+ this.value = data.value || null;
19388
+ this.productAttributeId = data.productAttributeId || "";
19389
+ this.productAttributeOptionId = data.productAttributeOptionId || null;
19390
+ this.productAttribute = data.productAttribute
19391
+ ? new IkasProductAttribute(data.productAttribute)
19392
+ : null;
19393
+ this.productAttributeOption = data.productAttributeOption
19394
+ ? new IkasProductAttributeOption(data.productAttributeOption)
19395
+ : null;
19396
+ mobx.makeAutoObservable(this);
19397
+ }
19398
+ return IkasProductAttributeValue;
19399
+ }());
19467
19400
 
19468
- var _baseRest = baseRest;
19401
+ var IkasProductVariant = /** @class */ (function () {
19402
+ function IkasProductVariant(data) {
19403
+ if (data === void 0) { data = {}; }
19404
+ this.id = data.id || "";
19405
+ this.sku = data.sku || null;
19406
+ this.barcodeList = data.barcodeList || [];
19407
+ this.variantValues = data.variantValues
19408
+ ? data.variantValues.map(function (vv) { return new IkasVariantValue(vv); })
19409
+ : [];
19410
+ this.images = data.images
19411
+ ? data.images.map(function (i) { return new IkasImage(i.id); })
19412
+ : [];
19413
+ this.attributes = data.attributes
19414
+ ? data.attributes.map(function (a) { return new IkasProductAttributeValue(a); })
19415
+ : [];
19416
+ this.price = data.price
19417
+ ? new IkasProductPrice(data.price)
19418
+ : new IkasProductPrice();
19419
+ this.stock = data.stock || 0;
19420
+ mobx.makeAutoObservable(this);
19421
+ }
19422
+ Object.defineProperty(IkasProductVariant.prototype, "mainImage", {
19423
+ get: function () {
19424
+ return this.images.length ? this.images[0] : undefined;
19425
+ },
19426
+ enumerable: false,
19427
+ configurable: true
19428
+ });
19429
+ return IkasProductVariant;
19430
+ }());
19469
19431
 
19470
- /**
19471
- * Checks if the given arguments are from an iteratee call.
19472
- *
19473
- * @private
19474
- * @param {*} value The potential iteratee value argument.
19475
- * @param {*} index The potential iteratee index or key argument.
19476
- * @param {*} object The potential iteratee object argument.
19477
- * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
19478
- * else `false`.
19479
- */
19480
- function isIterateeCall(value, index, object) {
19481
- if (!isObject_1(object)) {
19482
- return false;
19483
- }
19484
- var type = typeof index;
19485
- if (type == 'number'
19486
- ? (isArrayLike_1(object) && _isIndex(index, object.length))
19487
- : (type == 'string' && index in object)
19488
- ) {
19489
- return eq_1(object[index], value);
19490
- }
19491
- return false;
19492
- }
19432
+ var IkasVariantType = /** @class */ (function () {
19433
+ function IkasVariantType(data) {
19434
+ var _this = this;
19435
+ if (data === void 0) { data = {}; }
19436
+ this.id = data.id || "";
19437
+ this.name = data.name || "";
19438
+ this.selectionType = data.selectionType || exports.IkasVariantSelectionType.CHOICE;
19439
+ this.values = data.values
19440
+ ? data.values.map(function (v) {
19441
+ return new IkasVariantValue(__assign(__assign({}, v), { variantTypeId: _this.id }));
19442
+ })
19443
+ : [];
19444
+ mobx.makeAutoObservable(this);
19445
+ }
19446
+ Object.defineProperty(IkasVariantType.prototype, "isColorSelection", {
19447
+ get: function () {
19448
+ return this.selectionType === exports.IkasVariantSelectionType.COLOR;
19449
+ },
19450
+ enumerable: false,
19451
+ configurable: true
19452
+ });
19453
+ Object.defineProperty(IkasVariantType.prototype, "slug", {
19454
+ get: function () {
19455
+ return stringToSlug(this.name);
19456
+ },
19457
+ enumerable: false,
19458
+ configurable: true
19459
+ });
19460
+ return IkasVariantType;
19461
+ }());
19462
+ (function (IkasVariantSelectionType) {
19463
+ IkasVariantSelectionType["CHOICE"] = "CHOICE";
19464
+ IkasVariantSelectionType["COLOR"] = "COLOR";
19465
+ })(exports.IkasVariantSelectionType || (exports.IkasVariantSelectionType = {}));
19493
19466
 
19494
- var _isIterateeCall = isIterateeCall;
19467
+ var IkasProductVariantType = /** @class */ (function () {
19468
+ function IkasProductVariantType(data) {
19469
+ var _this = this;
19470
+ this.variantType = data.variantType
19471
+ ? new IkasVariantType(data.variantType)
19472
+ : new IkasVariantType();
19473
+ this.variantValueIds = data.variantValueIds || [];
19474
+ this.variantType.values = this.variantType.values.filter(function (v) {
19475
+ return _this.variantValueIds.includes(v.id);
19476
+ });
19477
+ mobx.makeAutoObservable(this);
19478
+ }
19479
+ return IkasProductVariantType;
19480
+ }());
19495
19481
 
19496
- /**
19497
- * Creates an array of elements, sorted in ascending order by the results of
19498
- * running each element in a collection thru each iteratee. This method
19499
- * performs a stable sort, that is, it preserves the original sort order of
19500
- * equal elements. The iteratees are invoked with one argument: (value).
19501
- *
19502
- * @static
19503
- * @memberOf _
19504
- * @since 0.1.0
19505
- * @category Collection
19506
- * @param {Array|Object} collection The collection to iterate over.
19507
- * @param {...(Function|Function[])} [iteratees=[_.identity]]
19508
- * The iteratees to sort by.
19509
- * @returns {Array} Returns the new sorted array.
19510
- * @example
19511
- *
19512
- * var users = [
19513
- * { 'user': 'fred', 'age': 48 },
19514
- * { 'user': 'barney', 'age': 36 },
19515
- * { 'user': 'fred', 'age': 30 },
19516
- * { 'user': 'barney', 'age': 34 }
19517
- * ];
19518
- *
19519
- * _.sortBy(users, [function(o) { return o.user; }]);
19520
- * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 30]]
19521
- *
19522
- * _.sortBy(users, ['user', 'age']);
19523
- * // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 48]]
19524
- */
19525
- var sortBy = _baseRest(function(collection, iteratees) {
19526
- if (collection == null) {
19527
- return [];
19528
- }
19529
- var length = iteratees.length;
19530
- if (length > 1 && _isIterateeCall(collection, iteratees[0], iteratees[1])) {
19531
- iteratees = [];
19532
- } else if (length > 2 && _isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
19533
- iteratees = [iteratees[0]];
19534
- }
19535
- return _baseOrderBy(collection, _baseFlatten(iteratees, 1), []);
19536
- });
19482
+ var IkasProductTag = /** @class */ (function () {
19483
+ function IkasProductTag(data) {
19484
+ this.id = data.id || "";
19485
+ this.name = data.name || "";
19486
+ mobx.makeAutoObservable(this);
19487
+ }
19488
+ return IkasProductTag;
19489
+ }());
19537
19490
 
19538
- var sortBy_1 = sortBy;
19491
+ var IkasProduct = /** @class */ (function () {
19492
+ function IkasProduct(data) {
19493
+ if (data === void 0) { data = {}; }
19494
+ this.id = data.id || "";
19495
+ this.name = data.name || "";
19496
+ this.type = data.type || exports.IkasProductType.PHYSICAL;
19497
+ this.description = data.description || "";
19498
+ this.shortDescription = data.shortDescription || "";
19499
+ this.metaData = data.metaData
19500
+ ? new IkasHTMLMetaData(data.metaData)
19501
+ : undefined;
19502
+ this.brand = data.brand ? new IkasBrand(data.brand) : null;
19503
+ this.categories = data.categories
19504
+ ? data.categories.map(function (c) { return new IkasCategory(c); })
19505
+ : [];
19506
+ this.tags = data.tags
19507
+ ? data.tags.map(function (tag) { return new IkasProductTag(tag); })
19508
+ : [];
19509
+ this.variants = data.variants
19510
+ ? data.variants.map(function (v) { return new IkasProductVariant(v); })
19511
+ : [];
19512
+ this.attributes = data.attributes
19513
+ ? data.attributes.map(function (a) { return new IkasProductAttributeValue(a); })
19514
+ : [];
19515
+ this.variantTypes = data.variantTypes
19516
+ ? data.variantTypes.map(function (v) { return new IkasProductVariantType(v); })
19517
+ : [];
19518
+ mobx.makeAutoObservable(this);
19519
+ }
19520
+ Object.defineProperty(IkasProduct.prototype, "hasVariant", {
19521
+ get: function () {
19522
+ return !!this.variantTypes.length;
19523
+ },
19524
+ enumerable: false,
19525
+ configurable: true
19526
+ });
19527
+ Object.defineProperty(IkasProduct.prototype, "mainVariantType", {
19528
+ get: function () {
19529
+ if (!this.hasVariant)
19530
+ return;
19531
+ return this.variantTypes[0].variantType;
19532
+ },
19533
+ enumerable: false,
19534
+ configurable: true
19535
+ });
19536
+ Object.defineProperty(IkasProduct.prototype, "href", {
19537
+ get: function () {
19538
+ var _a;
19539
+ if (!((_a = this.metaData) === null || _a === void 0 ? void 0 : _a.slug))
19540
+ return "";
19541
+ return "/" + this.metaData.slug;
19542
+ },
19543
+ enumerable: false,
19544
+ configurable: true
19545
+ });
19546
+ return IkasProduct;
19547
+ }());
19548
+ (function (IkasProductType) {
19549
+ IkasProductType["PHYSICAL"] = "PHYSICAL";
19550
+ IkasProductType["DIGITAL"] = "DIGITAL";
19551
+ IkasProductType["MEMBERSHIP"] = "MEMBERSHIP";
19552
+ })(exports.IkasProductType || (exports.IkasProductType = {}));
19539
19553
 
19540
19554
  var IkasProductFilter = /** @class */ (function () {
19541
19555
  function IkasProductFilter(data, productList) {
@@ -24778,13 +24792,13 @@ var IkasCheckoutAPI = /** @class */ (function () {
24778
24792
  });
24779
24793
  });
24780
24794
  };
24781
- IkasCheckoutAPI.listPaymentGateway = function () {
24795
+ IkasCheckoutAPI.listPaymentGateway = function (idList) {
24782
24796
  return __awaiter(this, void 0, void 0, function () {
24783
24797
  var QUERY, _a, data, errors, err_5;
24784
24798
  return __generator(this, function (_b) {
24785
24799
  switch (_b.label) {
24786
24800
  case 0:
24787
- QUERY = src(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n query listPaymentGateway {\n listPaymentGateway {\n paymentMethods {\n name\n logoUrl\n }\n paymentMethodType\n id\n name\n description\n testMode\n }\n }\n "], ["\n query listPaymentGateway {\n listPaymentGateway {\n paymentMethods {\n name\n logoUrl\n }\n paymentMethodType\n id\n name\n description\n testMode\n }\n }\n "])));
24801
+ QUERY = src(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n query listPaymentGateway($id: StringFilterInput) {\n listPaymentGateway(id: $id) {\n paymentMethods {\n name\n logoUrl\n }\n paymentMethodType\n id\n name\n description\n testMode\n }\n }\n "], ["\n query listPaymentGateway($id: StringFilterInput) {\n listPaymentGateway(id: $id) {\n paymentMethods {\n name\n logoUrl\n }\n paymentMethodType\n id\n name\n description\n testMode\n }\n }\n "])));
24788
24802
  _b.label = 1;
24789
24803
  case 1:
24790
24804
  _b.trys.push([1, 3, , 4]);
@@ -24792,6 +24806,9 @@ var IkasCheckoutAPI = /** @class */ (function () {
24792
24806
  .getClient()
24793
24807
  .query({
24794
24808
  query: QUERY,
24809
+ variables: {
24810
+ id: idList ? { in: idList } : undefined,
24811
+ },
24795
24812
  })];
24796
24813
  case 2:
24797
24814
  _a = _b.sent(), data = _a.data, errors = _a.errors;
@@ -26989,6 +27006,7 @@ var CheckoutStepPayment = mobxReactLite.observer(function (_a) {
26989
27006
  var vm = _a.vm;
26990
27007
  var onShowTermsClick = function (e) {
26991
27008
  e.stopPropagation();
27009
+ vm.policyModalTitle = "Mesafeli Satış Sözleşmesi";
26992
27010
  vm.policyModalText = vm.termsOfService;
26993
27011
  };
26994
27012
  return (React.createElement("div", { className: [styles$d.StepPayment, commonStyles.FormContainer].join(" ") },
@@ -28482,13 +28500,15 @@ var IkasStorefront = /** @class */ (function () {
28482
28500
  var IkasSalesChannel = /** @class */ (function () {
28483
28501
  function IkasSalesChannel(data) {
28484
28502
  if (data === void 0) { data = {}; }
28485
- var _a;
28503
+ var _a, _b;
28486
28504
  this.id = data.id || "";
28487
28505
  this.name = data.name || "";
28488
28506
  this.priceListId = data.priceListId || "";
28489
28507
  this.stockLocations =
28490
28508
  ((_a = data.stockLocations) === null || _a === void 0 ? void 0 : _a.map(function (sl) { return new IkasSalesChannelStockLocation(sl); })) ||
28491
28509
  [];
28510
+ this.paymentGateways =
28511
+ ((_b = data.paymentGateways) === null || _b === void 0 ? void 0 : _b.map(function (pg) { return new IkasSalesChannelPaymentGateway(pg); })) || [];
28492
28512
  }
28493
28513
  return IkasSalesChannel;
28494
28514
  }());
@@ -28498,6 +28518,13 @@ var IkasSalesChannelStockLocation = /** @class */ (function () {
28498
28518
  this.order = data.order || 0;
28499
28519
  }
28500
28520
  return IkasSalesChannelStockLocation;
28521
+ }());
28522
+ var IkasSalesChannelPaymentGateway = /** @class */ (function () {
28523
+ function IkasSalesChannelPaymentGateway(data) {
28524
+ this.id = data.id || "";
28525
+ this.order = data.order || 0;
28526
+ }
28527
+ return IkasSalesChannelPaymentGateway;
28501
28528
  }());
28502
28529
 
28503
28530
  var IkasStorefrontThemeLocalization = /** @class */ (function () {
@@ -28697,6 +28724,7 @@ var SettingsHelper = /** @class */ (function () {
28697
28724
  IkasStorefrontConfig.priceListId = routing.priceListId || undefined;
28698
28725
  IkasStorefrontConfig.stockLocationIds = (_a = salesChannel.stockLocations) === null || _a === void 0 ? void 0 : _a.map(function (sl) { return sl.id; });
28699
28726
  IkasStorefrontConfig.routings = storefront.routings;
28727
+ IkasStorefrontConfig.paymentGateways = salesChannel.paymentGateways || [];
28700
28728
  IkasStorefrontConfig.gtmId = storefront.gtmId || undefined;
28701
28729
  IkasStorefrontConfig.fbpId = storefront.fbpId || undefined;
28702
28730
  provider = new IkasPageDataProvider(themeLocalization.themeJson, context.params, pageType);
@@ -29345,7 +29373,7 @@ var IkasBaseStore = /** @class */ (function () {
29345
29373
  }
29346
29374
  IkasBaseStore.prototype.checkLocalization = function () {
29347
29375
  return __awaiter(this, void 0, void 0, function () {
29348
- var myCountryCode, currentRouting, correctRouting, isCorrectLocale, countries_1, localeOptions_1;
29376
+ var myCountryCode, currentRouting, correctRouting, isCorrectLocale, hasNoSpecificCountry, countries_1, localeOptions_1;
29349
29377
  return __generator(this, function (_a) {
29350
29378
  switch (_a.label) {
29351
29379
  case 0:
@@ -29359,12 +29387,15 @@ var IkasBaseStore = /** @class */ (function () {
29359
29387
  case 1:
29360
29388
  myCountryCode = _a.sent();
29361
29389
  currentRouting = IkasStorefrontConfig.routings.find(function (r) { return r.id === IkasStorefrontConfig.storefrontRoutingId; });
29362
- console.log("storefrontRoutingId", IkasStorefrontConfig.storefrontRoutingId);
29363
- console.log("currentRouting", currentRouting);
29364
- console.log(IkasStorefrontConfig.routings);
29365
29390
  if (!(currentRouting && myCountryCode)) return [3 /*break*/, 3];
29366
29391
  correctRouting = IkasStorefrontConfig.routings.find(function (r) { var _a; return (_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.includes(myCountryCode); });
29367
29392
  isCorrectLocale = IkasStorefrontConfig.storefrontRoutingId === (correctRouting === null || correctRouting === void 0 ? void 0 : correctRouting.id);
29393
+ if (!isCorrectLocale) {
29394
+ hasNoSpecificCountry = IkasStorefrontConfig.routings.length === 0 ||
29395
+ IkasStorefrontConfig.routings.every(function (r) { var _a; return !((_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.length); });
29396
+ if (hasNoSpecificCountry)
29397
+ isCorrectLocale = true;
29398
+ }
29368
29399
  return [4 /*yield*/, IkasCountryAPI.listCountries()];
29369
29400
  case 2:
29370
29401
  countries_1 = _a.sent();
@@ -29393,7 +29424,6 @@ var IkasBaseStore = /** @class */ (function () {
29393
29424
  });
29394
29425
  this.localeOptions = localeOptions_1;
29395
29426
  if (!isCorrectLocale) {
29396
- console.log("showing locale options");
29397
29427
  this.showLocaleOptions = true;
29398
29428
  }
29399
29429
  this.localeChecked = true;
@@ -29404,7 +29434,6 @@ var IkasBaseStore = /** @class */ (function () {
29404
29434
  });
29405
29435
  };
29406
29436
  IkasBaseStore.prototype.setLocalization = function (localeOption) {
29407
- document.cookie = "NEXT_LOCALE=" + (localeOption.routing.path || localeOption.routing.id) + "; expires=Thu, 1 Dec 2050 12:00:00 UTC";
29408
29437
  if (localeOption.routing.domain) {
29409
29438
  window.location.replace("https://" + localeOption.routing.domain);
29410
29439
  }