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