@ikas/storefront 0.0.109 → 0.0.111

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,2139 @@ 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
+ this.createCustomer();
17701
+ this.createShippingAddress();
17702
+ this.createBillingAddress();
17703
+ if (typeof queryParams.step === "string") {
17704
+ this.step = queryParams.step;
17705
+ if (this.step === CheckoutStep.SHIPPING && !this.canProceedToShipping) {
17706
+ this.changeStep(CheckoutStep.INFO);
17707
+ return [2 /*return*/];
17708
+ }
17709
+ else if (this.step === CheckoutStep.PAYMENT &&
17710
+ !this.canProceedToPayment) {
17711
+ this.changeStep(CheckoutStep.INFO);
17712
+ return [2 /*return*/];
17713
+ }
17714
+ else if (![
17715
+ CheckoutStep.INFO,
17716
+ CheckoutStep.SUCCESS,
17717
+ CheckoutStep.SHIPPING,
17718
+ CheckoutStep.PAYMENT,
17719
+ ].includes(this.step)) {
17720
+ this.changeStep(CheckoutStep.INFO);
17721
+ return [2 /*return*/];
17722
+ }
17723
+ }
17724
+ if (typeof queryParams.failed === "string") {
17725
+ this.error = {
17726
+ type: ErrorType.PAYMENT_ERROR,
17727
+ data: queryParams.error || null,
17728
+ };
17729
+ }
17730
+ merchantId = decodeBase64(IkasStorefrontConfig.config.apiKey || "");
17731
+ _a = this;
17732
+ return [4 /*yield*/, IkasMerchantAPI.listMerchantSettings(merchantId)];
17733
+ case 1:
17734
+ _a.merchantSettings = _b.sent();
17735
+ if (!(this.step === CheckoutStep.INFO)) return [3 /*break*/, 3];
17736
+ return [4 /*yield*/, this.getShippingCountries()];
17737
+ case 2:
17738
+ _b.sent();
17739
+ this.checkShippingCountries();
17740
+ _b.label = 3;
17741
+ case 3:
17742
+ if (!(this.step === CheckoutStep.PAYMENT)) return [3 /*break*/, 5];
17743
+ return [4 /*yield*/, this.listPaymentGateways()];
17744
+ case 4:
17745
+ _b.sent();
17746
+ _b.label = 5;
17747
+ case 5:
17748
+ this.isCheckoutLoaded = true;
17749
+ return [2 /*return*/];
17750
+ }
17751
+ });
17752
+ }); };
17753
+ // VALIDATIONS END
17754
+ this.saveCheckout = function () { return __awaiter(_this, void 0, void 0, function () {
17755
+ var updatedCheckoutId;
17756
+ return __generator(this, function (_a) {
17757
+ switch (_a.label) {
17758
+ case 0: return [4 /*yield*/, IkasCheckoutAPI.saveCheckout(this.checkout)];
17759
+ case 1:
17760
+ updatedCheckoutId = _a.sent();
17761
+ if (!updatedCheckoutId)
17762
+ throw {
17763
+ type: ErrorType.API_ERROR,
17764
+ };
17765
+ return [2 /*return*/];
17766
+ }
17767
+ });
17768
+ }); };
17769
+ this.checkStocks = function () { return __awaiter(_this, void 0, void 0, function () {
17770
+ var lines, result, unavailableItems, data;
17771
+ var _this = this;
17772
+ var _a;
17773
+ return __generator(this, function (_b) {
17774
+ switch (_b.label) {
17775
+ case 0:
17776
+ lines = this.cart.items.map(function (i) { return ({
17777
+ quantity: i.quantity,
17778
+ variantId: i.variant.id,
17779
+ productId: i.variant.productId,
17780
+ }); });
17781
+ return [4 /*yield*/, IkasCheckoutAPI.checkStocks(lines, IkasStorefrontConfig.stockLocationIds || [])];
17782
+ case 1:
17783
+ result = _b.sent();
17784
+ if (!result) {
17785
+ throw {
17786
+ type: ErrorType.API_ERROR,
17787
+ };
17788
+ }
17789
+ unavailableItems = (_a = result.lines) === null || _a === void 0 ? void 0 : _a.filter(function (i) { return !i.isAvailable; });
17790
+ if (unavailableItems === null || unavailableItems === void 0 ? void 0 : unavailableItems.length) {
17791
+ data = unavailableItems.map(function (item) { return ({
17792
+ variant: _this.cart.items.find(function (i) { return i.variant.id === item.variantId; })
17793
+ .variant,
17794
+ availableQuantity: item.stockCount,
17795
+ }); });
17796
+ throw {
17797
+ type: ErrorType.STOCK_ERROR,
17798
+ data: data,
17799
+ };
17800
+ }
17801
+ return [2 /*return*/];
17802
+ }
17803
+ });
17804
+ }); };
17805
+ this.getShippingCountries = function () { return __awaiter(_this, void 0, void 0, function () {
17806
+ var _a;
17807
+ return __generator(this, function (_b) {
17808
+ switch (_b.label) {
17809
+ case 0:
17810
+ _a = this;
17811
+ return [4 /*yield*/, IkasCountryAPI.listShippingCountries(IkasStorefrontConfig.salesChannelId)];
17812
+ case 1:
17813
+ _a.shippingCountryIds = _b.sent();
17814
+ return [2 /*return*/];
17815
+ }
17816
+ });
17817
+ }); };
17818
+ this.checkShippingCountries = function () {
17819
+ var _a;
17820
+ if (!((_a = _this.shippingCountryIds) === null || _a === void 0 ? void 0 : _a.length)) {
17821
+ _this.error = {
17822
+ type: ErrorType.NO_SHIPPING_ERROR,
17823
+ };
17824
+ }
17825
+ };
17826
+ this.initialStockCheck = function () { return __awaiter(_this, void 0, void 0, function () {
17827
+ var err_1;
17828
+ return __generator(this, function (_a) {
17829
+ switch (_a.label) {
17830
+ case 0:
17831
+ _a.trys.push([0, 2, , 3]);
17832
+ return [4 /*yield*/, this.checkStocks()];
17833
+ case 1:
17834
+ _a.sent();
17835
+ return [3 /*break*/, 3];
17836
+ case 2:
17837
+ err_1 = _a.sent();
17838
+ if (err_1.type) {
17839
+ this.error = err_1;
17840
+ }
17841
+ else {
17842
+ console.log(err_1);
17843
+ this.error = {
17844
+ type: ErrorType.UNKNOWN,
17845
+ };
17846
+ }
17847
+ return [3 /*break*/, 3];
17848
+ case 3: return [2 /*return*/];
17849
+ }
17850
+ });
17851
+ }); };
17852
+ this.listPaymentGateways = function () { return __awaiter(_this, void 0, void 0, function () {
17853
+ var isLocal, idList, paymentGateways, orderedPaymentGateways;
17854
+ return __generator(this, function (_a) {
17855
+ switch (_a.label) {
17856
+ case 0:
17857
+ isLocal = process.env.NEXT_PUBLIC_ENV === "local";
17858
+ idList = IkasStorefrontConfig.paymentGateways.map(function (pg) { return pg.id; });
17859
+ return [4 /*yield*/, IkasCheckoutAPI.listPaymentGateway(isLocal ? undefined : idList)];
17860
+ case 1:
17861
+ paymentGateways = _a.sent();
17862
+ if (!paymentGateways) {
17863
+ this.error = {
17864
+ type: ErrorType.API_ERROR,
17865
+ };
17866
+ return [2 /*return*/];
17867
+ }
17868
+ orderedPaymentGateways = [];
17869
+ sortBy_1(IkasStorefrontConfig.paymentGateways, "order").forEach(function (pg) {
17870
+ var _pg = paymentGateways.find(function (p) { return p.id === pg.id; });
17871
+ if (_pg)
17872
+ orderedPaymentGateways.push(_pg);
17873
+ });
17874
+ this.paymentGateways = orderedPaymentGateways;
17875
+ if (!this.paymentGatewayId)
17876
+ this.setPaymentGateway(0);
17877
+ return [2 /*return*/];
17878
+ }
17879
+ });
17880
+ }); };
17881
+ this.retrieveInstallmentInfo = function (input) { return __awaiter(_this, void 0, void 0, function () {
17882
+ var installmentInfo;
17883
+ return __generator(this, function (_a) {
17884
+ switch (_a.label) {
17885
+ case 0: return [4 /*yield*/, IkasCheckoutAPI.retrieveInstallmentInfo(input)];
17886
+ case 1:
17887
+ installmentInfo = _a.sent();
17888
+ installmentInfo === null || installmentInfo === void 0 ? void 0 : installmentInfo.installmentPrices.sort(function (a, b) {
17889
+ return (a.installmentCount || -1) > (b.installmentCount || -1) ? 1 : -1;
17890
+ });
17891
+ this.installmentInfo = installmentInfo;
17892
+ return [2 /*return*/];
17893
+ }
17894
+ });
17895
+ }); };
17896
+ this.createCustomer = function () {
17897
+ if (_this.customerStore.customer) {
17898
+ _this.checkout.customer = _this.customerStore.customer;
17899
+ }
17900
+ else if (!_this.checkout.customer)
17901
+ _this.checkout.customer = new IkasCustomer({});
17902
+ };
17903
+ this.createShippingAddress = function () {
17904
+ if (!_this.checkout.shippingAddress)
17905
+ _this.checkout.shippingAddress = new IkasOrderAddress();
17906
+ _this.checkout.shippingAddress.checkoutSettings = _this.checkoutSettings;
17907
+ };
17908
+ this.createBillingAddress = function () {
17909
+ if (typeof localStorage !== "undefined") {
17910
+ _this.useDifferentAddress = !!localStorage.getItem(USE_DIFFERENT_ADDRESS_KEY);
17911
+ if (_this.useDifferentAddress) {
17912
+ _this.checkout.billingAddress =
17913
+ _this.checkout.billingAddress || new IkasOrderAddress();
17914
+ }
17915
+ else {
17916
+ _this.checkout.billingAddress = new IkasOrderAddress(cloneDeep_1(_this.checkout.shippingAddress) || {});
17917
+ }
17918
+ _this.checkout.billingAddress.checkoutSettings = _this.checkoutSettings;
17919
+ }
17920
+ };
17921
+ this.onEmailChange = function (value) {
17922
+ _this.checkout.customer.email = value;
17923
+ };
17924
+ this.onShippingMethodChange = function (shippingMethod) { return __awaiter(_this, void 0, void 0, function () {
17925
+ var newCheckout;
17926
+ return __generator(this, function (_a) {
17927
+ switch (_a.label) {
17928
+ case 0:
17929
+ this.checkout.shippingSettingsId = shippingMethod.shippingSettingsId;
17930
+ this.checkout.shippingZoneRateId = shippingMethod.shippingZoneRateId;
17931
+ return [4 /*yield*/, this.saveCheckout()];
17932
+ case 1:
17933
+ _a.sent();
17934
+ return [4 /*yield*/, IkasCheckoutAPI.getCheckoutById(this.checkout.id)];
17935
+ case 2:
17936
+ newCheckout = _a.sent();
17937
+ if (newCheckout)
17938
+ this.checkout = newCheckout;
17939
+ return [2 /*return*/];
17940
+ }
17941
+ });
17942
+ }); };
17943
+ this.onCouponCodeChange = function (value) {
17944
+ _this.checkout.couponCode = value;
17945
+ };
17946
+ this.onSelectedShippingAddressIdChange = function (value) {
17947
+ var _a;
17948
+ _this.selectedShippingAddressId = value;
17949
+ if (value === "-1") {
17950
+ _this.checkout.shippingAddress = new IkasOrderAddress();
17951
+ }
17952
+ else {
17953
+ var address = (_a = _this.customerStore.customer) === null || _a === void 0 ? void 0 : _a.addresses.find(function (a) { return a.id === value; });
17954
+ if (address)
17955
+ _this.checkout.shippingAddress = new IkasOrderAddress(address);
17956
+ }
17957
+ };
17958
+ this.onSelectedBillingAddressIdChange = function (value) {
17959
+ var _a;
17960
+ _this.selectedBillingAddressId = value;
17961
+ if (value === "-1") {
17962
+ _this.checkout.billingAddress = new IkasOrderAddress();
17963
+ }
17964
+ else {
17965
+ var address = (_a = _this.customerStore.customer) === null || _a === void 0 ? void 0 : _a.addresses.find(function (a) { return a.id === value; });
17966
+ if (address)
17967
+ _this.checkout.billingAddress = new IkasOrderAddress(address);
17968
+ }
17969
+ };
17970
+ this.onTermsAndConditionsCheckedChange = function (value) {
17971
+ _this.isTermsAndConditionsChecked = value;
17972
+ };
17973
+ // CREDIT CARD START
17974
+ this.onCardNumberChange = function (value) {
17975
+ if (!_this.cardData)
17976
+ return;
17977
+ if (value.length > _this.cardData.cardNumber.length &&
17978
+ !isLastCharNumber(value))
17979
+ return;
17980
+ var oldOriginalValue = (_this.cardData.cardNumber || "")
17981
+ .split(" ")
17982
+ .join("");
17983
+ var originalValue = value.split(" ").join("");
17984
+ if (originalValue.length > MAX_CARD_NUMBER_LENGTH)
17985
+ return;
17986
+ if (oldOriginalValue.length < 6 && originalValue.length >= 6) {
17987
+ _this.retrieveInstallmentInfo({
17988
+ binNumber: originalValue.slice(0, 6),
17989
+ paymentGatewayId: _this.paymentGatewayId,
17990
+ price: _this.checkout.totalFinalPrice,
17991
+ });
17992
+ }
17993
+ // Deleting characters below 6
17994
+ else if (originalValue.length < 6 &&
17995
+ oldOriginalValue.length > originalValue.length) {
17996
+ _this.cardData.installmentCount = 1;
17997
+ _this.installmentInfo = undefined;
17998
+ }
17999
+ _this.cardData.cardNumber = chunkString(originalValue, 4).join(" ");
18000
+ };
18001
+ this.onCardHolderNameChange = function (value) {
18002
+ if (!_this.cardData)
18003
+ return;
18004
+ _this.cardData.cardHolderName = value;
18005
+ };
18006
+ this.onExpirationDateChange = function (value) {
18007
+ if (!_this.cardData)
18008
+ return;
18009
+ if (value.length > _this.cardData.expirationDate.length &&
18010
+ !isLastCharNumber(value)) {
18011
+ return;
18012
+ }
18013
+ var originalValue = value.split(" / ").join("");
18014
+ if (originalValue.length > 4)
18015
+ return;
18016
+ _this.cardData.expirationDate = chunkString(originalValue, 2).join(" / ");
18017
+ };
18018
+ this.onCvcChange = function (value) {
18019
+ if (!_this.cardData)
18020
+ return;
18021
+ if (value.length > _this.cardData.cvv.length && !isLastCharNumber(value))
18022
+ return;
18023
+ if (value.length > MAX_CVC_LENGTH)
18024
+ return;
18025
+ _this.cardData.cvv = value;
18026
+ };
18027
+ // CREDIT CARD END
18028
+ this.onBackToShoppingClick = function () {
18029
+ _this.router.push("/");
18030
+ };
18031
+ this.onProceedToShippingClick = function () { return __awaiter(_this, void 0, void 0, function () {
18032
+ var newAddress, customer, err_2;
18033
+ return __generator(this, function (_a) {
18034
+ switch (_a.label) {
18035
+ case 0:
18036
+ if (!this.canProceedToShipping) {
18037
+ this.isErrorsVisible = true;
18038
+ return [2 /*return*/];
18039
+ }
18040
+ this.isErrorsVisible = false;
18041
+ _a.label = 1;
18042
+ case 1:
18043
+ _a.trys.push([1, 6, , 7]);
18044
+ this.isStepLoading = true;
18045
+ if (!this.shouldSaveAddress) return [3 /*break*/, 3];
18046
+ newAddress = new IkasCustomerAddress(__assign(__assign({}, this.checkout.shippingAddress), { title: this.addressTitle || "Yeni Adres" }));
18047
+ customer = cloneDeep_1(this.customerStore.customer);
18048
+ customer.addresses.push(newAddress);
18049
+ return [4 /*yield*/, this.customerStore.saveCustomer(customer)];
18050
+ case 2:
18051
+ _a.sent();
18052
+ _a.label = 3;
18053
+ case 3: return [4 /*yield*/, this.checkStocks()];
18054
+ case 4:
18055
+ _a.sent();
18056
+ return [4 /*yield*/, this.saveCheckout()];
18057
+ case 5:
18058
+ _a.sent();
18059
+ this.changeStep(CheckoutStep.SHIPPING);
18060
+ return [3 /*break*/, 7];
18061
+ case 6:
18062
+ err_2 = _a.sent();
18063
+ if (err_2.type) {
18064
+ this.error = err_2;
18065
+ }
18066
+ else {
18067
+ console.log(err_2);
18068
+ this.error = {
18069
+ type: ErrorType.UNKNOWN,
18070
+ };
18071
+ }
18072
+ this.isStepLoading = false;
18073
+ return [3 /*break*/, 7];
18074
+ case 7: return [2 /*return*/];
18075
+ }
18076
+ });
18077
+ }); };
18078
+ this.onProceedToPaymentClick = function () { return __awaiter(_this, void 0, void 0, function () {
18079
+ var err_3;
18080
+ return __generator(this, function (_a) {
18081
+ switch (_a.label) {
18082
+ case 0:
18083
+ if (!this.canProceedToPayment) {
18084
+ this.isErrorsVisible = true;
18085
+ return [2 /*return*/];
18086
+ }
18087
+ this.isErrorsVisible = false;
18088
+ _a.label = 1;
18089
+ case 1:
18090
+ _a.trys.push([1, 3, , 4]);
18091
+ this.isStepLoading = true;
18092
+ return [4 /*yield*/, this.checkStocks()];
18093
+ case 2:
18094
+ _a.sent();
18095
+ this.error = undefined;
18096
+ this.changeStep(CheckoutStep.PAYMENT);
18097
+ return [3 /*break*/, 4];
18098
+ case 3:
18099
+ err_3 = _a.sent();
18100
+ if (err_3.type) {
18101
+ this.error = err_3;
18102
+ }
18103
+ else {
18104
+ console.log(err_3);
18105
+ this.error = {
18106
+ type: ErrorType.UNKNOWN,
18107
+ };
18108
+ }
18109
+ this.isStepLoading = false;
18110
+ return [3 /*break*/, 4];
18111
+ case 4: return [2 /*return*/];
18112
+ }
18113
+ });
18114
+ }); };
18115
+ this.performPayment = function () { return __awaiter(_this, void 0, void 0, function () {
18116
+ var response, transactionStatus, err_4;
18117
+ return __generator(this, function (_a) {
18118
+ switch (_a.label) {
18119
+ case 0:
18120
+ if (!this.useDifferentAddress) {
18121
+ this.checkout.billingAddress = this.checkout.shippingAddress;
18122
+ }
18123
+ if (!this.canPerformPayment) {
18124
+ this.isErrorsVisible = true;
18125
+ return [2 /*return*/];
18126
+ }
18127
+ _a.label = 1;
18128
+ case 1:
18129
+ _a.trys.push([1, 5, , 6]);
18130
+ this.isErrorsVisible = false;
18131
+ this.isStepLoading = true;
18132
+ return [4 /*yield*/, this.checkStocks()];
18133
+ case 2:
18134
+ _a.sent();
18135
+ return [4 /*yield*/, this.saveCheckout()];
18136
+ case 3:
18137
+ _a.sent();
18138
+ return [4 /*yield*/, IkasCheckoutAPI.createSaleTransactionWithCheckout(this.checkout.id, this.paymentGatewayId, this.cardData ? this.cardData.toInput() : undefined)];
18139
+ case 4:
18140
+ response = _a.sent();
18141
+ transactionStatus = response === null || response === void 0 ? void 0 : response.transactionStatus;
18142
+ if (transactionStatus &&
18143
+ [
18144
+ IkasTransactionStatusEnum.SUCCESS,
18145
+ IkasTransactionStatusEnum.AUTHORIZED,
18146
+ ].includes(transactionStatus)) {
18147
+ localStorage.removeItem(USE_DIFFERENT_ADDRESS_KEY);
18148
+ this.changeStep(CheckoutStep.SUCCESS);
18149
+ }
18150
+ else if (transactionStatus === IkasTransactionStatusEnum.PENDING &&
18151
+ !!(response === null || response === void 0 ? void 0 : response.returnSlug)) {
18152
+ window.location.href =
18153
+ process.env.NEXT_PUBLIC_BASE_URL + response.returnSlug;
18154
+ }
18155
+ else {
18156
+ this.isStepLoading = false;
18157
+ throw {
18158
+ type: ErrorType.UNKNOWN,
18159
+ };
18160
+ }
18161
+ return [3 /*break*/, 6];
18162
+ case 5:
18163
+ err_4 = _a.sent();
18164
+ if (err_4.type) {
18165
+ console.log(err_4);
18166
+ this.error = err_4;
18167
+ }
18168
+ else {
18169
+ this.error = {
18170
+ type: ErrorType.UNKNOWN,
18171
+ };
18172
+ }
18173
+ this.isStepLoading = false;
18174
+ return [3 /*break*/, 6];
18175
+ case 6: return [2 /*return*/];
18176
+ }
18177
+ });
18178
+ }); };
18179
+ this.onBackToInfoClick = function () {
18180
+ _this.changeStep(CheckoutStep.INFO);
18181
+ };
18182
+ this.onBackToShippingClick = function () {
18183
+ _this.changeStep(CheckoutStep.SHIPPING);
18184
+ };
18185
+ this.setUseDifferentAddress = function (value) {
18186
+ _this.useDifferentAddress = value;
18187
+ if (_this.useDifferentAddress) {
18188
+ localStorage.setItem(USE_DIFFERENT_ADDRESS_KEY, "1");
18189
+ _this.checkout.billingAddress =
18190
+ _this.checkout.billingAddress || new IkasOrderAddress();
18191
+ }
18192
+ else {
18193
+ localStorage.removeItem(USE_DIFFERENT_ADDRESS_KEY);
18194
+ }
18195
+ };
18196
+ this.setShouldSaveAddress = function (value) {
18197
+ _this.shouldSaveAddress = value;
18198
+ };
18199
+ this.setAddressTitle = function (value) {
18200
+ _this.addressTitle = value;
18201
+ };
18202
+ this.setPaymentGateway = function (index) {
18203
+ var paymentGateway = _this.paymentGateways[index];
18204
+ _this.paymentGatewayId = paymentGateway.id;
18205
+ if (paymentGateway.paymentMethodType === IkasPaymentMethodType.CREDIT_CARD) {
18206
+ _this.cardData = new CreditCardData();
18207
+ }
18208
+ _this.installmentInfo = undefined;
18209
+ };
18210
+ this.setInstallmentCount = function (count) {
18211
+ if (!_this.cardData)
18212
+ return;
18213
+ _this.cardData.installmentCount = count;
18214
+ };
18215
+ this.changeStep = function (step) {
18216
+ if (!isServer$1) {
18217
+ window.location.href = "/checkout/" + _this.checkout.id + "?step=" + step;
18218
+ // this.router.push(`/checkout/${this.checkout.id}?step=${step}`);
18219
+ }
18220
+ };
18221
+ this.logout = function () { return __awaiter(_this, void 0, void 0, function () {
18222
+ return __generator(this, function (_a) {
18223
+ switch (_a.label) {
18224
+ case 0:
18225
+ this.checkout.customer = undefined;
18226
+ this.customerStore.logout();
18227
+ _a.label = 1;
18228
+ case 1:
18229
+ _a.trys.push([1, 3, , 4]);
18230
+ return [4 /*yield*/, this.saveCheckout()];
18231
+ case 2:
18232
+ _a.sent();
18233
+ return [3 /*break*/, 4];
18234
+ case 3:
18235
+ _a.sent();
18236
+ return [3 /*break*/, 4];
18237
+ case 4:
18238
+ this.createCustomer();
18239
+ return [2 /*return*/];
18240
+ }
18241
+ });
18242
+ }); };
18243
+ this.checkout = checkout;
18244
+ this.checkoutSettings = checkoutSettings;
18245
+ this.router = router;
18246
+ this.returnPolicy = returnPolicy;
18247
+ this.privacyPolicy = privacyPolicy;
18248
+ this.termsOfService = termsOfService;
18249
+ this.isTermsAndConditionsChecked = this.checkoutSettings.isTermsAndConditionsDefaultChecked;
18250
+ this.init(queryParams);
18251
+ makeAutoObservable(this);
18252
+ }
18253
+ Object.defineProperty(CheckoutViewModel.prototype, "cart", {
18254
+ get: function () {
18255
+ return this.checkout.cart;
18256
+ },
18257
+ enumerable: false,
18258
+ configurable: true
18259
+ });
18260
+ Object.defineProperty(CheckoutViewModel.prototype, "selectedPaymentGatewayIndex", {
18261
+ get: function () {
18262
+ var _this = this;
18263
+ return this.paymentGateways.findIndex(function (pg) { return pg.id === _this.paymentGatewayId; });
18264
+ },
18265
+ enumerable: false,
18266
+ configurable: true
18267
+ });
18268
+ Object.defineProperty(CheckoutViewModel.prototype, "selectedPaymentGateway", {
18269
+ get: function () {
18270
+ var _this = this;
18271
+ return this.paymentGateways.find(function (pg) { return pg.id === _this.paymentGatewayId; });
18272
+ },
18273
+ enumerable: false,
18274
+ configurable: true
18275
+ });
18276
+ Object.defineProperty(CheckoutViewModel.prototype, "selectedInstallmentIndex", {
18277
+ get: function () {
18278
+ var _this = this;
18279
+ var _a;
18280
+ 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);
18281
+ },
18282
+ enumerable: false,
18283
+ configurable: true
18284
+ });
18285
+ Object.defineProperty(CheckoutViewModel.prototype, "checkoutUrl", {
18286
+ get: function () {
18287
+ return "/checkout/" + this.checkout.id + "?step=info";
18288
+ },
18289
+ enumerable: false,
18290
+ configurable: true
18291
+ });
18292
+ Object.defineProperty(CheckoutViewModel.prototype, "customerAddressOptions", {
18293
+ get: function () {
18294
+ var _a;
18295
+ var defaultOption = {
18296
+ label: "Yeni adres",
18297
+ value: "-1",
18298
+ };
18299
+ var addressOptions = ((_a = this.customerStore.customer) === null || _a === void 0 ? void 0 : _a.addresses.map(function (a) { return ({
18300
+ label: a.title + " - " + a.addressText,
18301
+ value: a.id,
18302
+ }); })) || [];
18303
+ return [defaultOption].concat(addressOptions);
18304
+ },
18305
+ enumerable: false,
18306
+ configurable: true
18307
+ });
18308
+ Object.defineProperty(CheckoutViewModel.prototype, "installmentPrice", {
18309
+ get: function () {
18310
+ var _this = this;
18311
+ var _a, _b;
18312
+ if (this.installmentInfo && ((_a = this.cardData) === null || _a === void 0 ? void 0 : _a.installmentCount)) {
18313
+ 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;
18314
+ }
18315
+ },
18316
+ enumerable: false,
18317
+ configurable: true
18318
+ });
18319
+ Object.defineProperty(CheckoutViewModel.prototype, "installmentExtraPrice", {
18320
+ get: function () {
18321
+ if (this.installmentPrice && this.checkout.totalFinalPrice) {
18322
+ return this.installmentPrice - this.checkout.totalFinalPrice;
18323
+ }
18324
+ },
18325
+ enumerable: false,
18326
+ configurable: true
18327
+ });
18328
+ Object.defineProperty(CheckoutViewModel.prototype, "canProceedToShipping", {
18329
+ // VALIDATIONS
18330
+ get: function () {
18331
+ var _a;
18332
+ return (this.checkout.shippingAddress.isValid &&
18333
+ this.checkout.hasValidCustomer &&
18334
+ ((_a = this.error) === null || _a === void 0 ? void 0 : _a.type) !== ErrorType.NO_SHIPPING_ERROR);
18335
+ },
18336
+ enumerable: false,
18337
+ configurable: true
18338
+ });
18339
+ Object.defineProperty(CheckoutViewModel.prototype, "canProceedToPayment", {
18340
+ get: function () {
18341
+ // TODO might add something here later not sure
18342
+ return this.canProceedToShipping;
18343
+ },
18344
+ enumerable: false,
18345
+ configurable: true
18346
+ });
18347
+ Object.defineProperty(CheckoutViewModel.prototype, "canPerformPayment", {
18348
+ get: function () {
18349
+ var _a, _b, _c;
18350
+ if (this.checkoutSettings.showTermsAndConditionsCheckbox &&
18351
+ !this.isTermsAndConditionsChecked)
18352
+ return false;
18353
+ return (this.canProceedToShipping &&
18354
+ !!((_a = this.checkout.billingAddress) === null || _a === void 0 ? void 0 : _a.isValid) &&
18355
+ (((_b = this.selectedPaymentGateway) === null || _b === void 0 ? void 0 : _b.paymentMethodType) ===
18356
+ IkasPaymentMethodType.CREDIT_CARD
18357
+ ? (_c = this.cardData) === null || _c === void 0 ? void 0 : _c.isValid : true));
18358
+ },
18359
+ enumerable: false,
18360
+ configurable: true
18361
+ });
18362
+ return CheckoutViewModel;
18363
+ }());
18364
+ function chunkString(str, length) {
18365
+ return str.match(new RegExp(".{1," + length + "}", "g")) || [];
18366
+ }
18367
+ function isLastCharNumber(str) {
18368
+ return str && NUMBER_ONLY_REGEX.test(str.charAt(str.length - 1));
18369
+ }
18370
+ var CheckoutStep;
18371
+ (function (CheckoutStep) {
18372
+ CheckoutStep["INFO"] = "info";
18373
+ CheckoutStep["SHIPPING"] = "shipping";
18374
+ CheckoutStep["PAYMENT"] = "payment";
18375
+ CheckoutStep["SUCCESS"] = "success";
18376
+ })(CheckoutStep || (CheckoutStep = {}));
18377
+ var ErrorType;
18378
+ (function (ErrorType) {
18379
+ ErrorType[ErrorType["UNKNOWN"] = 0] = "UNKNOWN";
18380
+ ErrorType[ErrorType["API_ERROR"] = 1] = "API_ERROR";
18381
+ ErrorType[ErrorType["STOCK_ERROR"] = 2] = "STOCK_ERROR";
18382
+ ErrorType[ErrorType["PAYMENT_ERROR"] = 3] = "PAYMENT_ERROR";
18383
+ ErrorType[ErrorType["NO_SHIPPING_ERROR"] = 4] = "NO_SHIPPING_ERROR";
18384
+ })(ErrorType || (ErrorType = {}));
19363
18385
 
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
- };
18386
+ var isServer$2 = typeof window === "undefined";
18387
+ var GoogleTagManager = /** @class */ (function () {
18388
+ function GoogleTagManager() {
18389
+ makeAutoObservable(this);
18390
+ }
18391
+ GoogleTagManager.pageView = function (url) {
18392
+ try {
18393
+ var event_1 = {
18394
+ event: "page-view",
18395
+ page: url,
18396
+ };
18397
+ //@ts-ignore
18398
+ !isServer$2 && window.dataLayer && window.dataLayer.push(event_1);
18399
+ return event_1;
18400
+ }
18401
+ catch (err) {
18402
+ console.error(err);
18403
+ }
18404
+ };
18405
+ GoogleTagManager.productView = function (productDetail) {
18406
+ try {
18407
+ var event_2 = {
18408
+ event: "view_item",
18409
+ ecommerce: {
18410
+ items: [productToGTMItem(productDetail)],
18411
+ },
18412
+ };
18413
+ //@ts-ignore
18414
+ !isServer$2 && window.dataLayer && window.dataLayer.push(event_2);
18415
+ return event_2;
18416
+ }
18417
+ catch (err) {
18418
+ console.error(err);
18419
+ }
18420
+ };
18421
+ GoogleTagManager.addToCart = function (item, quantity) {
18422
+ try {
18423
+ var event_3 = {
18424
+ event: "add_to_cart",
18425
+ ecommerce: {
18426
+ items: [
18427
+ item instanceof IkasProductDetail
18428
+ ? productToGTMItem(item, quantity)
18429
+ : orderLineItemToGTMItem(item, quantity),
18430
+ ],
18431
+ },
18432
+ };
18433
+ //@ts-ignore
18434
+ !isServer$2 && window.dataLayer && window.dataLayer.push(event_3);
18435
+ return event_3;
18436
+ }
18437
+ catch (err) {
18438
+ console.error(err);
18439
+ }
18440
+ };
18441
+ GoogleTagManager.removeFromCart = function (item, quantity) {
18442
+ try {
18443
+ var event_4 = {
18444
+ event: "remove_from_cart",
18445
+ ecommerce: {
18446
+ items: [
18447
+ item instanceof IkasProductDetail
18448
+ ? productToGTMItem(item, quantity)
18449
+ : orderLineItemToGTMItem(item, quantity),
18450
+ ],
18451
+ },
18452
+ };
18453
+ //@ts-ignore
18454
+ !isServer$2 && window.dataLayer && window.dataLayer.push(event_4);
18455
+ return event_4;
18456
+ }
18457
+ catch (err) {
18458
+ console.error(err);
18459
+ }
18460
+ };
18461
+ GoogleTagManager.beginCheckout = function (checkout) {
18462
+ var _a;
18463
+ try {
18464
+ var event_5 = {
18465
+ event: "begin_checkout",
18466
+ ecommerce: {
18467
+ items: (_a = checkout.cart) === null || _a === void 0 ? void 0 : _a.items.map(function (item) {
18468
+ return orderLineItemToGTMItem(item, item.quantity);
18469
+ }),
18470
+ },
18471
+ };
18472
+ //@ts-ignore
18473
+ !isServer$2 && window.dataLayer && window.dataLayer.push(event_5);
18474
+ return event_5;
18475
+ }
18476
+ catch (err) {
18477
+ console.error(err);
18478
+ }
18479
+ };
18480
+ GoogleTagManager.purchase = function (checkout, orderId) {
18481
+ var _a, _b, _c;
18482
+ try {
18483
+ var event_6 = {
18484
+ event: "purchase",
18485
+ ecommerce: {
18486
+ purchase: {
18487
+ transaction_id: orderId,
18488
+ affiliation: window.location.hostname,
18489
+ value: "" + checkout.totalFinalPrice,
18490
+ tax: "" + ((_a = checkout.cart) === null || _a === void 0 ? void 0 : _a.totalTax),
18491
+ shipping: "" + checkout.shippingTotal,
18492
+ currency: (_b = checkout.cart) === null || _b === void 0 ? void 0 : _b.currencyCode,
18493
+ coupon: checkout.couponCode,
18494
+ items: (_c = checkout.cart) === null || _c === void 0 ? void 0 : _c.items.map(function (item) {
18495
+ return orderLineItemToGTMItem(item, item.quantity);
18496
+ }),
18497
+ },
18498
+ },
18499
+ };
18500
+ //@ts-ignore
18501
+ !isServer$2 && window.dataLayer && window.dataLayer.push(event_6);
18502
+ return event_6;
18503
+ }
18504
+ catch (err) {
18505
+ console.error(err);
18506
+ }
18507
+ };
18508
+ GoogleTagManager.checkoutStep = function (checkout, step) {
18509
+ var _a;
18510
+ var eventName = "";
18511
+ if (step === CheckoutStep.INFO)
18512
+ eventName = "checkout_info";
18513
+ else if (step === CheckoutStep.SHIPPING)
18514
+ eventName = "checkout_shipping";
18515
+ else if (step === CheckoutStep.PAYMENT)
18516
+ eventName = "checkout_payment";
18517
+ else if (step === CheckoutStep.SUCCESS)
18518
+ eventName = "checkout_success";
18519
+ try {
18520
+ var event_7 = {
18521
+ event: eventName,
18522
+ ecommerce: {
18523
+ items: (_a = checkout.cart) === null || _a === void 0 ? void 0 : _a.items.map(function (item) {
18524
+ return orderLineItemToGTMItem(item, item.quantity);
18525
+ }),
18526
+ },
18527
+ };
18528
+ //@ts-ignore
18529
+ !isServer$2 && window.dataLayer && window.dataLayer.push(event_7);
18530
+ return event_7;
18531
+ }
18532
+ catch (err) {
18533
+ console.error(err);
18534
+ }
18535
+ };
18536
+ GoogleTagManager.disableHTML = function () {
18537
+ try {
18538
+ var data = {
18539
+ "gtm.blocklist": [
18540
+ "html",
18541
+ "customScripts",
18542
+ "customPixels",
18543
+ "nonGoogleScripts",
18544
+ ],
18545
+ };
18546
+ //@ts-ignore
18547
+ !isServer$2 && window.dataLayer && window.dataLayer.push(data);
18548
+ }
18549
+ catch (err) {
18550
+ console.error(err);
18551
+ }
18552
+ };
18553
+ return GoogleTagManager;
18554
+ }());
18555
+ function productToGTMItem(productDetail, quantity) {
18556
+ var _a;
18557
+ if (quantity === void 0) { quantity = 1; }
18558
+ return {
18559
+ item_name: productDetail.product.name,
18560
+ item_id: productDetail.selectedVariant.id,
18561
+ price: productDetail.selectedVariant.price.finalPrice,
18562
+ item_brand: ((_a = productDetail.product.brand) === null || _a === void 0 ? void 0 : _a.name) || "",
18563
+ item_category: productDetail.product.categories.length
18564
+ ? productDetail.product.categories[0].name
18565
+ : "",
18566
+ item_category_2: productDetail.product.categories.length > 1
18567
+ ? productDetail.product.categories[1].name
18568
+ : "",
18569
+ item_category_3: productDetail.product.categories.length > 2
18570
+ ? productDetail.product.categories[2].name
18571
+ : "",
18572
+ item_category_4: productDetail.product.categories.length > 3
18573
+ ? productDetail.product.categories[3].name
18574
+ : "",
18575
+ item_variant: productDetail.selectedVariant.variantValues
18576
+ .map(function (vv) { return vv.name; })
18577
+ .join(" / "),
18578
+ item_list_name: "",
18579
+ item_list_id: "",
18580
+ index: 1,
18581
+ quantity: quantity,
18582
+ };
18583
+ }
18584
+ function orderLineItemToGTMItem(orderLineItem, quantity) {
18585
+ if (quantity === void 0) { quantity = 1; }
18586
+ return {
18587
+ item_name: orderLineItem.variant.name,
18588
+ item_id: orderLineItem.variant.id,
18589
+ price: "" + orderLineItem.finalPrice,
18590
+ item_brand: "",
18591
+ item_category: "",
18592
+ item_category_2: "",
18593
+ item_category_3: "",
18594
+ item_category_4: "",
18595
+ item_variant: orderLineItem.variant.variantValues
18596
+ .map(function (vv) { return vv.variantValueName; })
18597
+ .join(" / "),
18598
+ item_list_name: "",
18599
+ item_list_id: "",
18600
+ index: 1,
18601
+ quantity: quantity,
18602
+ };
19387
18603
  }
19388
18604
 
19389
- var constant_1 = constant;
18605
+ var LS_BEGIN_CHECKOUT_KEY = "gtmBeginCheckout";
18606
+ var Analytics = /** @class */ (function () {
18607
+ function Analytics() {
18608
+ makeAutoObservable(this);
18609
+ }
18610
+ Analytics.pageView = function (url) {
18611
+ try {
18612
+ GoogleTagManager.pageView(url);
18613
+ }
18614
+ catch (err) {
18615
+ console.error(err);
18616
+ }
18617
+ };
18618
+ Analytics.productView = function (productDetail) {
18619
+ try {
18620
+ FacebookPixel.productView(productDetail);
18621
+ GoogleTagManager.productView(productDetail);
18622
+ }
18623
+ catch (err) {
18624
+ console.error(err);
18625
+ }
18626
+ };
18627
+ Analytics.addToCart = function (item, quantity) {
18628
+ try {
18629
+ FacebookPixel.addToCart(item, quantity);
18630
+ GoogleTagManager.addToCart(item, quantity);
18631
+ }
18632
+ catch (err) {
18633
+ console.error(err);
18634
+ }
18635
+ };
18636
+ Analytics.removeFromCart = function (item, quantity) {
18637
+ try {
18638
+ GoogleTagManager.removeFromCart(item, quantity);
18639
+ }
18640
+ catch (err) {
18641
+ console.error(err);
18642
+ }
18643
+ };
18644
+ Analytics.beginCheckout = function (checkout) {
18645
+ try {
18646
+ var beginCheckout = localStorage.getItem(LS_BEGIN_CHECKOUT_KEY);
18647
+ if (beginCheckout && checkout.id === beginCheckout)
18648
+ return;
18649
+ localStorage.setItem(LS_BEGIN_CHECKOUT_KEY, checkout.id);
18650
+ FacebookPixel.beginCheckout(checkout);
18651
+ GoogleTagManager.beginCheckout(checkout);
18652
+ }
18653
+ catch (err) {
18654
+ console.error(err);
18655
+ }
18656
+ };
18657
+ Analytics.purchase = function (checkout, orderId) {
18658
+ try {
18659
+ localStorage.removeItem(LS_BEGIN_CHECKOUT_KEY);
18660
+ FacebookPixel.purchase(checkout, orderId);
18661
+ GoogleTagManager.purchase(checkout, orderId);
18662
+ }
18663
+ catch (err) {
18664
+ console.error(err);
18665
+ }
18666
+ };
18667
+ Analytics.checkoutStep = function (checkout, step) {
18668
+ try {
18669
+ GoogleTagManager.checkoutStep(checkout, step);
18670
+ }
18671
+ catch (err) {
18672
+ console.error(err);
18673
+ }
18674
+ };
18675
+ Analytics.disableHTML = function () {
18676
+ try {
18677
+ GoogleTagManager.disableHTML();
18678
+ }
18679
+ catch (err) {
18680
+ console.error(err);
18681
+ }
18682
+ };
18683
+ Analytics.addToWishlist = function (id) {
18684
+ try {
18685
+ FacebookPixel.addToWishlist(id);
18686
+ }
18687
+ catch (err) {
18688
+ console.error(err);
18689
+ }
18690
+ };
18691
+ Analytics.search = function (searchKeyword) {
18692
+ try {
18693
+ FacebookPixel.search(searchKeyword);
18694
+ }
18695
+ catch (err) {
18696
+ console.error(err);
18697
+ }
18698
+ };
18699
+ Analytics.completeRegistration = function () {
18700
+ try {
18701
+ FacebookPixel.completeRegistration();
18702
+ }
18703
+ catch (err) {
18704
+ console.error(err);
18705
+ }
18706
+ };
18707
+ Analytics.viewCart = function (cart) {
18708
+ try {
18709
+ if (cart) {
18710
+ FacebookPixel.viewCart(cart);
18711
+ }
18712
+ }
18713
+ catch (err) {
18714
+ console.error(err);
18715
+ }
18716
+ };
18717
+ Analytics.viewCategory = function (categoryPath) {
18718
+ try {
18719
+ FacebookPixel.viewCategory(categoryPath);
18720
+ }
18721
+ catch (err) {
18722
+ console.error(err);
18723
+ }
18724
+ };
18725
+ Analytics.contactForm = function () {
18726
+ try {
18727
+ FacebookPixel.contactForm();
18728
+ }
18729
+ catch (err) {
18730
+ console.error(err);
18731
+ }
18732
+ };
18733
+ return Analytics;
18734
+ }());
19390
18735
 
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
- });
18736
+ var AnalyticsHead = function (_a) {
18737
+ var blockHTML = _a.blockHTML;
18738
+ var gtmId = IkasStorefrontConfig.gtmId;
18739
+ var fbpId = IkasStorefrontConfig.fbpId;
18740
+ return (createElement(Fragment, null,
18741
+ blockHTML && (createElement("script", { dangerouslySetInnerHTML: {
18742
+ __html: "dataLayer = [{'gtm.blocklist': ['html']}];",
18743
+ } })),
18744
+ gtmId && (createElement("script", { dangerouslySetInnerHTML: {
18745
+ __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 + "');",
18746
+ } })),
18747
+ fbpId && (createElement("script", { dangerouslySetInnerHTML: {
18748
+ __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');",
18749
+ } }))));
18750
+ };
18751
+ var AnalyticsBody = function () {
18752
+ var gtmId = IkasStorefrontConfig.gtmId;
18753
+ var fbpId = IkasStorefrontConfig.fbpId;
18754
+ return (createElement(Fragment, null,
18755
+ gtmId && (createElement("noscript", { dangerouslySetInnerHTML: {
18756
+ __html: "<iframe src=\"https://www.googletagmanager.com/ns.html?id=" + gtmId + "\" height=\"0\" width=\"0\" style=\"display:none;visibility:hidden\"></iframe>",
18757
+ } })),
18758
+ fbpId && (createElement("noscript", { dangerouslySetInnerHTML: {
18759
+ __html: "<img height=\"1\" width=\"1\" style=\"display:none\" \n src=\"https://www.facebook.com/tr?id=" + fbpId + "&ev=PageView&noscript=1\"/>",
18760
+ } }))));
19406
18761
  };
19407
18762
 
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;
18763
+ var isServer$3 = typeof localStorage === "undefined";
18764
+ var LS_TOKEN_KEY = "customerToken";
18765
+ var LS_TOKEN_EXPIRY = "customerTokenExpiry";
18766
+ var LS_CUSTOMER_KEY = "customer";
18767
+ var IkasCustomerStore = /** @class */ (function () {
18768
+ function IkasCustomerStore(baseStore) {
18769
+ var _this = this;
18770
+ this.customer = null;
18771
+ this.token = null;
18772
+ this.tokenExpiry = null;
18773
+ this.baseStore = null;
18774
+ this._initialized = false;
18775
+ this.login = function (email, password) { return __awaiter(_this, void 0, void 0, function () {
18776
+ var response, cart;
18777
+ var _a;
18778
+ return __generator(this, function (_b) {
18779
+ switch (_b.label) {
18780
+ case 0: return [4 /*yield*/, IkasCustomerAPI.login(email, password)];
18781
+ case 1:
18782
+ response = _b.sent();
18783
+ if (!response) return [3 /*break*/, 4];
18784
+ this.setToken(response.token, response.tokenExpiry);
18785
+ this.setCustomer(response.customer);
18786
+ cart = (_a = this.baseStore) === null || _a === void 0 ? void 0 : _a.cartStore.cart;
18787
+ if (!cart) return [3 /*break*/, 3];
18788
+ return [4 /*yield*/, this.baseStore.cartStore.changeItemQuantity(cart.items[0], cart.items[0].quantity)];
18789
+ case 2:
18790
+ _b.sent();
18791
+ _b.label = 3;
18792
+ case 3: return [2 /*return*/, true];
18793
+ case 4: return [2 /*return*/, false];
18794
+ }
18795
+ });
18796
+ }); };
18797
+ this.register = function (firstName, lastName, email, password) { return __awaiter(_this, void 0, void 0, function () {
18798
+ var response;
18799
+ return __generator(this, function (_a) {
18800
+ switch (_a.label) {
18801
+ case 0: return [4 /*yield*/, IkasCustomerAPI.register(email, password, firstName, lastName)];
18802
+ case 1:
18803
+ response = _a.sent();
18804
+ if (response) {
18805
+ this.setToken(response.token, response.tokenExpiry);
18806
+ this.setCustomer(response.customer);
18807
+ return [2 /*return*/, true];
18808
+ }
18809
+ return [2 /*return*/, false];
18810
+ }
18811
+ });
18812
+ }); };
18813
+ this.saveContactForm = function (input) { return __awaiter(_this, void 0, void 0, function () {
18814
+ return __generator(this, function (_a) {
18815
+ switch (_a.label) {
18816
+ case 0:
18817
+ Analytics.contactForm();
18818
+ return [4 /*yield*/, IkasContactFormAPI.sendContactFormToMerchant(input)];
18819
+ case 1: return [2 /*return*/, _a.sent()];
18820
+ }
18821
+ });
18822
+ }); };
18823
+ this.checkEmail = function (email) { return __awaiter(_this, void 0, void 0, function () {
18824
+ return __generator(this, function (_a) {
18825
+ switch (_a.label) {
18826
+ case 0: return [4 /*yield*/, IkasCustomerAPI.checkEmail(email)];
18827
+ case 1: return [2 /*return*/, _a.sent()];
18828
+ }
18829
+ });
18830
+ }); };
18831
+ this.forgotPassword = function (email) { return __awaiter(_this, void 0, void 0, function () {
18832
+ return __generator(this, function (_a) {
18833
+ switch (_a.label) {
18834
+ case 0: return [4 /*yield*/, IkasCustomerAPI.forgotPassword(email)];
18835
+ case 1: return [2 /*return*/, _a.sent()];
18836
+ }
18837
+ });
18838
+ }); };
18839
+ this.recoverPassword = function (password, passwordAgain, token) { return __awaiter(_this, void 0, void 0, function () {
18840
+ return __generator(this, function (_a) {
18841
+ switch (_a.label) {
18842
+ case 0: return [4 /*yield*/, IkasCustomerAPI.recoverPassword(password, passwordAgain, token)];
18843
+ case 1: return [2 /*return*/, _a.sent()];
18844
+ }
18845
+ });
18846
+ }); };
18847
+ this.logout = function () {
18848
+ var _a;
18849
+ localStorage.removeItem(LS_TOKEN_KEY);
18850
+ localStorage.removeItem(LS_TOKEN_EXPIRY);
18851
+ localStorage.removeItem(LS_CUSTOMER_KEY);
18852
+ _this.customer = undefined;
18853
+ _this.token = undefined;
18854
+ _this.tokenExpiry = undefined;
18855
+ (_a = _this.baseStore) === null || _a === void 0 ? void 0 : _a.cartStore.removeCart();
18856
+ };
18857
+ this.saveCustomer = function (customer) { return __awaiter(_this, void 0, void 0, function () {
18858
+ var savedCustomer;
18859
+ return __generator(this, function (_a) {
18860
+ switch (_a.label) {
18861
+ case 0: return [4 /*yield*/, IkasCustomerAPI.saveCustomer(customer)];
18862
+ case 1:
18863
+ savedCustomer = _a.sent();
18864
+ if (savedCustomer) {
18865
+ this.setCustomer(savedCustomer);
18866
+ return [2 /*return*/, true];
18867
+ }
18868
+ return [2 /*return*/, false];
18869
+ }
18870
+ });
18871
+ }); };
18872
+ this.getOrders = function () { return __awaiter(_this, void 0, void 0, function () {
18873
+ return __generator(this, function (_a) {
18874
+ switch (_a.label) {
18875
+ case 0: return [4 /*yield*/, IkasCustomerAPI.getOrders()];
18876
+ case 1: return [2 /*return*/, _a.sent()];
18877
+ }
18878
+ });
18879
+ }); };
18880
+ this.getOrder = function (id) { return __awaiter(_this, void 0, void 0, function () {
18881
+ var orders;
18882
+ return __generator(this, function (_a) {
18883
+ switch (_a.label) {
18884
+ case 0: return [4 /*yield*/, IkasCustomerAPI.getOrders(id)];
18885
+ case 1:
18886
+ orders = _a.sent();
18887
+ if (!Array.isArray(orders) || !orders.length)
18888
+ return [2 /*return*/, null];
18889
+ return [2 /*return*/, orders[0]];
18890
+ }
18891
+ });
18892
+ }); };
18893
+ this.getOrderTransactions = function (params) {
18894
+ if (params === void 0) { params = {}; }
18895
+ return __awaiter(_this, void 0, void 0, function () {
18896
+ return __generator(this, function (_a) {
18897
+ switch (_a.label) {
18898
+ case 0: return [4 /*yield*/, IkasCustomerAPI.getOrderTransactions(params)];
18899
+ case 1: return [2 /*return*/, _a.sent()];
18900
+ }
18901
+ });
18902
+ });
18903
+ };
18904
+ this.getFavoriteProductsIds = function () { return __awaiter(_this, void 0, void 0, function () {
18905
+ var favoriteProductsResult;
18906
+ return __generator(this, function (_b) {
18907
+ switch (_b.label) {
18908
+ case 0:
18909
+ _b.trys.push([0, 2, , 3]);
18910
+ return [4 /*yield*/, IkasFavoriteProductAPI.listFavoriteProducts()];
18911
+ case 1:
18912
+ favoriteProductsResult = _b.sent();
18913
+ return [2 /*return*/, favoriteProductsResult];
18914
+ case 2:
18915
+ _b.sent();
18916
+ return [2 /*return*/, []];
18917
+ case 3: return [2 /*return*/];
18918
+ }
18919
+ });
18920
+ }); };
18921
+ this.getFavoriteProducts = function () { return __awaiter(_this, void 0, void 0, function () {
18922
+ var favoriteProductsResult, productsResult;
18923
+ return __generator(this, function (_b) {
18924
+ switch (_b.label) {
18925
+ case 0:
18926
+ _b.trys.push([0, 3, , 4]);
18927
+ return [4 /*yield*/, IkasFavoriteProductAPI.listFavoriteProducts()];
18928
+ case 1:
18929
+ favoriteProductsResult = _b.sent();
18930
+ if (!favoriteProductsResult.length)
18931
+ return [2 /*return*/, []];
18932
+ return [4 /*yield*/, IkasProductSearchAPI.searchProducts({
18933
+ productIdList: favoriteProductsResult.map(function (fP) { return fP.productId; }),
18934
+ priceListId: IkasStorefrontConfig.priceListId,
18935
+ })];
18936
+ case 2:
18937
+ productsResult = _b.sent();
18938
+ return [2 /*return*/, (productsResult === null || productsResult === void 0 ? void 0 : productsResult.data) || []];
18939
+ case 3:
18940
+ _b.sent();
18941
+ return [2 /*return*/, []];
18942
+ case 4: return [2 /*return*/];
18943
+ }
18944
+ });
18945
+ }); };
18946
+ this.addItemToFavorite = function (productId) { return __awaiter(_this, void 0, void 0, function () {
18947
+ var customerId, result;
18948
+ var _b;
18949
+ return __generator(this, function (_c) {
18950
+ switch (_c.label) {
18951
+ case 0:
18952
+ customerId = (_b = this.customer) === null || _b === void 0 ? void 0 : _b.id;
18953
+ if (!customerId)
18954
+ throw Error("Unauthorized");
18955
+ _c.label = 1;
18956
+ case 1:
18957
+ _c.trys.push([1, 3, , 4]);
18958
+ return [4 /*yield*/, IkasFavoriteProductAPI.saveFavoriteProduct(true, productId)];
18959
+ case 2:
18960
+ result = _c.sent();
18961
+ Analytics.addToWishlist(productId);
18962
+ return [2 /*return*/, result];
18963
+ case 3:
18964
+ _c.sent();
18965
+ return [2 /*return*/, false];
18966
+ case 4: return [2 /*return*/];
18967
+ }
18968
+ });
18969
+ }); };
18970
+ this.removeItemFromFavorite = function (productId) { return __awaiter(_this, void 0, void 0, function () {
18971
+ var customerId, result;
18972
+ var _b;
18973
+ return __generator(this, function (_c) {
18974
+ switch (_c.label) {
18975
+ case 0:
18976
+ customerId = (_b = this.customer) === null || _b === void 0 ? void 0 : _b.id;
18977
+ if (!customerId)
18978
+ throw Error("Unauthorized");
18979
+ _c.label = 1;
18980
+ case 1:
18981
+ _c.trys.push([1, 3, , 4]);
18982
+ return [4 /*yield*/, IkasFavoriteProductAPI.saveFavoriteProduct(false, productId)];
18983
+ case 2:
18984
+ result = _c.sent();
18985
+ return [2 /*return*/, result];
18986
+ case 3:
18987
+ _c.sent();
18988
+ return [2 /*return*/, false];
18989
+ case 4: return [2 /*return*/];
18990
+ }
18991
+ });
18992
+ }); };
18993
+ this.isProductFavorite = function (productId) { return __awaiter(_this, void 0, void 0, function () {
18994
+ var customerId;
18995
+ var _a;
18996
+ return __generator(this, function (_b) {
18997
+ switch (_b.label) {
18998
+ case 0:
18999
+ customerId = (_a = this.customer) === null || _a === void 0 ? void 0 : _a.id;
19000
+ if (!customerId)
19001
+ throw Error("Unauthorized");
19002
+ return [4 /*yield*/, IkasFavoriteProductAPI.isFavoriteProduct(productId)];
19003
+ case 1: return [2 /*return*/, _b.sent()];
19004
+ }
19005
+ });
19006
+ }); };
19007
+ this.baseStore = baseStore;
19008
+ this.init();
19009
+ makeAutoObservable(this);
19010
+ }
19011
+ Object.defineProperty(IkasCustomerStore.prototype, "initialized", {
19012
+ get: function () {
19013
+ return this._initialized;
19014
+ },
19015
+ enumerable: false,
19016
+ configurable: true
19017
+ });
19018
+ IkasCustomerStore.prototype.init = function () {
19019
+ return __awaiter(this, void 0, void 0, function () {
19020
+ return __generator(this, function (_a) {
19021
+ switch (_a.label) {
19022
+ case 0:
19023
+ this.loadToken();
19024
+ this.loadCustomer();
19025
+ return [4 /*yield*/, this.refreshToken()];
19026
+ case 1:
19027
+ _a.sent();
19028
+ return [4 /*yield*/, this.getCustomer()];
19029
+ case 2:
19030
+ _a.sent();
19031
+ this._initialized = true;
19032
+ return [2 /*return*/];
19033
+ }
19034
+ });
19035
+ });
19036
+ };
19037
+ IkasCustomerStore.prototype.getCustomer = function () {
19038
+ return __awaiter(this, void 0, void 0, function () {
19039
+ var customer;
19040
+ return __generator(this, function (_a) {
19041
+ switch (_a.label) {
19042
+ case 0:
19043
+ if (isServer$3 || !this.token)
19044
+ return [2 /*return*/];
19045
+ return [4 /*yield*/, IkasCustomerAPI.getCustomer()];
19046
+ case 1:
19047
+ customer = _a.sent();
19048
+ if (customer)
19049
+ this.setCustomer(customer);
19050
+ return [2 /*return*/];
19051
+ }
19052
+ });
19053
+ });
19054
+ };
19055
+ IkasCustomerStore.prototype.refreshToken = function () {
19056
+ return __awaiter(this, void 0, void 0, function () {
19057
+ var response;
19058
+ return __generator(this, function (_a) {
19059
+ switch (_a.label) {
19060
+ case 0:
19061
+ if (!this.token)
19062
+ return [2 /*return*/];
19063
+ return [4 /*yield*/, IkasCustomerAPI.refreshToken(this.token)];
19064
+ case 1:
19065
+ response = _a.sent();
19066
+ if ((response === null || response === void 0 ? void 0 : response.token) || (response === null || response === void 0 ? void 0 : response.tokenExpiry))
19067
+ this.setToken(response.token, response.tokenExpiry);
19068
+ return [2 /*return*/];
19069
+ }
19070
+ });
19071
+ });
19072
+ };
19073
+ IkasCustomerStore.prototype.setCustomer = function (customer) {
19074
+ if (!isServer$3) {
19075
+ localStorage.setItem(LS_CUSTOMER_KEY, JSON.stringify(customer));
19076
+ }
19077
+ this.customer = new IkasCustomer(customer);
19078
+ };
19079
+ IkasCustomerStore.prototype.loadCustomer = function () {
19080
+ if (isServer$3)
19081
+ return;
19082
+ try {
19083
+ var customerStr = localStorage.getItem(LS_CUSTOMER_KEY);
19084
+ if (customerStr) {
19085
+ this.customer = new IkasCustomer(JSON.parse(customerStr));
19086
+ }
19087
+ }
19088
+ catch (err) { }
19089
+ };
19090
+ IkasCustomerStore.prototype.setToken = function (token, tokenExpiry) {
19091
+ if (isServer$3)
19092
+ return;
19093
+ this.token = token;
19094
+ this.tokenExpiry = tokenExpiry;
19095
+ localStorage.setItem(LS_TOKEN_KEY, token);
19096
+ localStorage.setItem(LS_TOKEN_EXPIRY, tokenExpiry + "");
19097
+ apollo.setCustomerToken(token);
19098
+ };
19099
+ IkasCustomerStore.prototype.loadToken = function () {
19100
+ if (isServer$3)
19101
+ return;
19102
+ var token = localStorage.getItem(LS_TOKEN_KEY);
19103
+ var tokenExpiry = localStorage.getItem(LS_TOKEN_EXPIRY);
19104
+ if (token && tokenExpiry) {
19105
+ this.setToken(token, parseInt(tokenExpiry));
19106
+ }
19107
+ };
19108
+ return IkasCustomerStore;
19109
+ }());
19429
19110
 
19430
- return function() {
19431
- var stamp = nativeNow(),
19432
- remaining = HOT_SPAN - (stamp - lastCalled);
19111
+ var IkasOrder = /** @class */ (function () {
19112
+ function IkasOrder(data) {
19113
+ var _this = this;
19114
+ this.customerStore = new IkasCustomerStore();
19115
+ this.refund = function () { return __awaiter(_this, void 0, void 0, function () {
19116
+ var refundOrderLineItems_1, result;
19117
+ var _this = this;
19118
+ return __generator(this, function (_a) {
19119
+ switch (_a.label) {
19120
+ case 0:
19121
+ _a.trys.push([0, 2, , 3]);
19122
+ refundOrderLineItems_1 = [];
19123
+ this.orderLineItems.map(function (item) {
19124
+ if (item.refundQuantity !== null) {
19125
+ refundOrderLineItems_1 === null || refundOrderLineItems_1 === void 0 ? void 0 : refundOrderLineItems_1.push({
19126
+ orderLineItemId: item.id,
19127
+ quantity: item.refundQuantity ? item.refundQuantity : 0,
19128
+ });
19129
+ }
19130
+ });
19131
+ return [4 /*yield*/, IkasCustomerAPI.saveIkasOrderRefund({
19132
+ orderId: this.id,
19133
+ orderLineItems: refundOrderLineItems_1,
19134
+ })];
19135
+ case 1:
19136
+ result = _a.sent();
19137
+ if (result) {
19138
+ // Set the new order object to this
19139
+ Object.entries(result).forEach(function (_a) {
19140
+ var key = _a[0], value = _a[1];
19141
+ _this[key] = value;
19142
+ });
19143
+ return [2 /*return*/, true];
19144
+ }
19145
+ return [3 /*break*/, 3];
19146
+ case 2:
19147
+ _a.sent();
19148
+ return [3 /*break*/, 3];
19149
+ case 3: return [2 /*return*/, false];
19150
+ }
19151
+ });
19152
+ }); };
19153
+ this.id = data.id;
19154
+ this.orderNumber = data.orderNumber;
19155
+ this.note = data.note;
19156
+ this.totalPrice = data.totalPrice;
19157
+ this.totalFinalPrice = data.totalFinalPrice;
19158
+ // this.totalDiscountPrice = data.totalDiscountPrice;
19159
+ // this.totalWeight = data.totalWeight;
19160
+ this.currencyCode = data.currencyCode;
19161
+ this.orderedAt = data.orderedAt;
19162
+ this.cancelledAt = data.cancelledAt;
19163
+ this.status = data.status;
19164
+ this.cancelReason = data.cancelReason;
19165
+ this.orderPaymentStatus = data.orderPaymentStatus;
19166
+ this.orderPackageStatus = data.orderPackageStatus;
19167
+ this.shippingMethod = data.shippingMethod;
19168
+ this.shippingAddress = data.shippingAddress
19169
+ ? new IkasOrderAddress(data.shippingAddress)
19170
+ : null;
19171
+ this.billingAddress = data.billingAddress
19172
+ ? new IkasOrderAddress(data.billingAddress)
19173
+ : null;
19174
+ this.orderLineItems = data.orderLineItems
19175
+ ? data.orderLineItems.map(function (o) { return new IkasOrderLineItem(o); })
19176
+ : [];
19177
+ this.orderAdjustments = data.orderAdjustments;
19178
+ this.shippingLines = data.shippingLines;
19179
+ this.customer = data.customer;
19180
+ this.taxLines = data.taxLines;
19181
+ this.orderPackages = data.orderPackages;
19182
+ this.currencyRates = data.currencyRates;
19183
+ makeAutoObservable(this);
19184
+ }
19185
+ Object.defineProperty(IkasOrder.prototype, "refundableItems", {
19186
+ get: function () {
19187
+ return this.orderLineItems.filter(function (item) { return item.status === OrderLineItemStatusEnum$1.FULFILLED; });
19188
+ },
19189
+ enumerable: false,
19190
+ configurable: true
19191
+ });
19192
+ Object.defineProperty(IkasOrder.prototype, "unfullfilledItems", {
19193
+ get: function () {
19194
+ var _this = this;
19195
+ return this.orderLineItems.filter(function (item) {
19196
+ var _a;
19197
+ var isInAPackage = (_a = _this.orderPackages) === null || _a === void 0 ? void 0 : _a.some(function (op) {
19198
+ return op.orderLineItemIds.includes(item.id);
19199
+ });
19200
+ return !isInAPackage;
19201
+ });
19202
+ },
19203
+ enumerable: false,
19204
+ configurable: true
19205
+ });
19206
+ Object.defineProperty(IkasOrder.prototype, "refundedItems", {
19207
+ get: function () {
19208
+ return this.orderLineItems.filter(function (item) {
19209
+ return item.status === OrderLineItemStatusEnum$1.REFUNDED ||
19210
+ item.status === OrderLineItemStatusEnum$1.REFUND_REQUESTED ||
19211
+ item.status === OrderLineItemStatusEnum$1.REFUND_REQUEST_ACCEPTED ||
19212
+ item.status === OrderLineItemStatusEnum$1.REFUND_REJECTED;
19213
+ });
19214
+ },
19215
+ enumerable: false,
19216
+ configurable: true
19217
+ });
19218
+ return IkasOrder;
19219
+ }());
19220
+ var IkasOrderStatus;
19221
+ (function (IkasOrderStatus) {
19222
+ IkasOrderStatus["DRAFT"] = "DRAFT";
19223
+ IkasOrderStatus["CREATED"] = "CREATED";
19224
+ IkasOrderStatus["CANCELLED"] = "CANCELLED";
19225
+ IkasOrderStatus["REFUNDED"] = "REFUNDED";
19226
+ })(IkasOrderStatus || (IkasOrderStatus = {}));
19227
+ var IkasOrderCancelledReason;
19228
+ (function (IkasOrderCancelledReason) {
19229
+ IkasOrderCancelledReason["CUSTOMER"] = "CUSTOMER";
19230
+ IkasOrderCancelledReason["INVENTORY"] = "INVENTORY";
19231
+ IkasOrderCancelledReason["DECLINED"] = "DECLINED";
19232
+ IkasOrderCancelledReason["OTHER"] = "OTHER";
19233
+ })(IkasOrderCancelledReason || (IkasOrderCancelledReason = {}));
19234
+ var IkasAmountTypeEnum$1;
19235
+ (function (IkasAmountTypeEnum) {
19236
+ IkasAmountTypeEnum["AMOUNT"] = "AMOUNT";
19237
+ IkasAmountTypeEnum["RATIO"] = "RATIO";
19238
+ })(IkasAmountTypeEnum$1 || (IkasAmountTypeEnum$1 = {}));
19239
+ var IkasAdjustmentEnum;
19240
+ (function (IkasAdjustmentEnum) {
19241
+ IkasAdjustmentEnum["DECREMENT"] = "DECREMENT";
19242
+ IkasAdjustmentEnum["INCREMENT"] = "INCREMENT";
19243
+ })(IkasAdjustmentEnum || (IkasAdjustmentEnum = {}));
19244
+ var IkasOrderPaymentStatus;
19245
+ (function (IkasOrderPaymentStatus) {
19246
+ IkasOrderPaymentStatus["WAITING"] = "WAITING";
19247
+ IkasOrderPaymentStatus["PAID"] = "PAID";
19248
+ IkasOrderPaymentStatus["PARTIALLY_PAID"] = "PARTIALLY_PAID";
19249
+ })(IkasOrderPaymentStatus || (IkasOrderPaymentStatus = {}));
19250
+ var IkasOrderPackageStatus;
19251
+ (function (IkasOrderPackageStatus) {
19252
+ IkasOrderPackageStatus["UNFULFILLED"] = "UNFULFILLED";
19253
+ IkasOrderPackageStatus["PARTIALLY_FULFILLED"] = "PARTIALLY_FULFILLED";
19254
+ IkasOrderPackageStatus["FULFILLED"] = "FULFILLED";
19255
+ })(IkasOrderPackageStatus || (IkasOrderPackageStatus = {}));
19256
+ var IkasOrderPackageFulfillStatus;
19257
+ (function (IkasOrderPackageFulfillStatus) {
19258
+ IkasOrderPackageFulfillStatus["DELIVERED"] = "DELIVERED";
19259
+ IkasOrderPackageFulfillStatus["FULFILLED"] = "FULFILLED";
19260
+ IkasOrderPackageFulfillStatus["SHIPPED"] = "SHIPPED";
19261
+ })(IkasOrderPackageFulfillStatus || (IkasOrderPackageFulfillStatus = {}));
19262
+ var IkasOrderShippingMethod;
19263
+ (function (IkasOrderShippingMethod) {
19264
+ IkasOrderShippingMethod["CLICK_AND_COLLECT"] = "CLICK_AND_COLLECT";
19265
+ IkasOrderShippingMethod["SHIPMENT"] = "SHIPMENT";
19266
+ IkasOrderShippingMethod["NO_SHIPMENT"] = "NO_SHIPMENT";
19267
+ })(IkasOrderShippingMethod || (IkasOrderShippingMethod = {}));
19268
+ var OrderLineItemStatusEnum$1;
19269
+ (function (OrderLineItemStatusEnum) {
19270
+ OrderLineItemStatusEnum["FULFILLED"] = "FULFILLED";
19271
+ OrderLineItemStatusEnum["UNFULFILLED"] = "UNFULFILLED";
19272
+ OrderLineItemStatusEnum["DELIVERED"] = "DELIVERED";
19273
+ // Cancel Enums
19274
+ OrderLineItemStatusEnum["CANCELLED"] = "CANCELLED";
19275
+ OrderLineItemStatusEnum["CANCEL_REQUESTED"] = "CANCEL_REQUESTED";
19276
+ OrderLineItemStatusEnum["CANCEL_REJECTED"] = "CANCEL_REJECTED";
19277
+ // Refund Enums
19278
+ OrderLineItemStatusEnum["REFUND_REQUESTED"] = "REFUND_REQUESTED";
19279
+ OrderLineItemStatusEnum["REFUND_REQUEST_ACCEPTED"] = "REFUND_REQUEST_ACCEPTED";
19280
+ OrderLineItemStatusEnum["REFUNDED"] = "REFUNDED";
19281
+ OrderLineItemStatusEnum["REFUND_REJECTED"] = "REFUND_REJECTED";
19282
+ })(OrderLineItemStatusEnum$1 || (OrderLineItemStatusEnum$1 = {}));
19433
19283
 
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
- }
19284
+ var IkasProductPrice = /** @class */ (function () {
19285
+ function IkasProductPrice(data) {
19286
+ if (data === void 0) { data = {}; }
19287
+ this.sellPrice = data.sellPrice || 0;
19288
+ this.discountPrice =
19289
+ data.discountPrice !== undefined ? data.discountPrice : null;
19290
+ this.currency = data.currency || "";
19291
+ makeAutoObservable(this);
19292
+ }
19293
+ Object.defineProperty(IkasProductPrice.prototype, "finalPrice", {
19294
+ get: function () {
19295
+ return this.discountPrice !== null ? this.discountPrice : this.sellPrice;
19296
+ },
19297
+ enumerable: false,
19298
+ configurable: true
19299
+ });
19300
+ Object.defineProperty(IkasProductPrice.prototype, "hasDiscount", {
19301
+ get: function () {
19302
+ return this.discountPrice !== null;
19303
+ },
19304
+ enumerable: false,
19305
+ configurable: true
19306
+ });
19307
+ Object.defineProperty(IkasProductPrice.prototype, "discountAmount", {
19308
+ get: function () {
19309
+ if (this.hasDiscount)
19310
+ return this.sellPrice - this.discountPrice;
19311
+ return 0;
19312
+ },
19313
+ enumerable: false,
19314
+ configurable: true
19315
+ });
19316
+ Object.defineProperty(IkasProductPrice.prototype, "discountPercentage", {
19317
+ get: function () {
19318
+ if (this.hasDiscount)
19319
+ return (100 - (this.finalPrice * 100) / this.sellPrice).toFixed(0);
19320
+ return 0;
19321
+ },
19322
+ enumerable: false,
19323
+ configurable: true
19324
+ });
19325
+ return IkasProductPrice;
19326
+ }());
19445
19327
 
19446
- var _shortOut = shortOut;
19328
+ var IkasVariantValue = /** @class */ (function () {
19329
+ function IkasVariantValue(data) {
19330
+ this.id = data.id || "";
19331
+ this.name = data.name || "";
19332
+ this.colorCode = data.colorCode || null;
19333
+ this.thumbnailImageId = data.thumbnailImageId || null;
19334
+ this.variantTypeId = data.variantTypeId || "";
19335
+ makeAutoObservable(this);
19336
+ }
19337
+ Object.defineProperty(IkasVariantValue.prototype, "slug", {
19338
+ get: function () {
19339
+ return stringToSlug(this.name);
19340
+ },
19341
+ enumerable: false,
19342
+ configurable: true
19343
+ });
19344
+ Object.defineProperty(IkasVariantValue.prototype, "thumbnailImage", {
19345
+ get: function () {
19346
+ if (this.thumbnailImageId)
19347
+ return new IkasImage(this.thumbnailImageId);
19348
+ },
19349
+ enumerable: false,
19350
+ configurable: true
19351
+ });
19352
+ return IkasVariantValue;
19353
+ }());
19447
19354
 
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);
19355
+ var IkasProductAttributeOption = /** @class */ (function () {
19356
+ function IkasProductAttributeOption(data) {
19357
+ if (data === void 0) { data = {}; }
19358
+ this.id = data.id || "";
19359
+ this.name = data.name || "";
19360
+ makeAutoObservable(this);
19361
+ }
19362
+ return IkasProductAttributeOption;
19363
+ }());
19457
19364
 
19458
- var _setToString = setToString;
19365
+ var IkasProductAttribute = /** @class */ (function () {
19366
+ function IkasProductAttribute(data) {
19367
+ this.id = data.id || "";
19368
+ this.name = data.name || "";
19369
+ this.type = data.type || IkasProductAttributeType.TEXT;
19370
+ this.options = data.options || null;
19371
+ makeAutoObservable(this);
19372
+ }
19373
+ return IkasProductAttribute;
19374
+ }());
19375
+ var IkasProductAttributeType;
19376
+ (function (IkasProductAttributeType) {
19377
+ IkasProductAttributeType["CHOICE"] = "CHOICE";
19378
+ IkasProductAttributeType["MULTIPLE_CHOICE"] = "MULTIPLE_CHOICE";
19379
+ IkasProductAttributeType["TEXT"] = "TEXT";
19380
+ IkasProductAttributeType["BOOLEAN"] = "BOOLEAN";
19381
+ IkasProductAttributeType["NUMERIC"] = "NUMERIC";
19382
+ IkasProductAttributeType["DATETIME"] = "DATETIME";
19383
+ IkasProductAttributeType["HTML"] = "HTML";
19384
+ })(IkasProductAttributeType || (IkasProductAttributeType = {}));
19459
19385
 
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
- }
19386
+ var IkasProductAttributeValue = /** @class */ (function () {
19387
+ function IkasProductAttributeValue(data) {
19388
+ this.value = data.value || null;
19389
+ this.productAttributeId = data.productAttributeId || "";
19390
+ this.productAttributeOptionId = data.productAttributeOptionId || null;
19391
+ this.productAttribute = data.productAttribute
19392
+ ? new IkasProductAttribute(data.productAttribute)
19393
+ : null;
19394
+ this.productAttributeOption = data.productAttributeOption
19395
+ ? new IkasProductAttributeOption(data.productAttributeOption)
19396
+ : null;
19397
+ makeAutoObservable(this);
19398
+ }
19399
+ return IkasProductAttributeValue;
19400
+ }());
19471
19401
 
19472
- var _baseRest = baseRest;
19402
+ var IkasProductVariant = /** @class */ (function () {
19403
+ function IkasProductVariant(data) {
19404
+ if (data === void 0) { data = {}; }
19405
+ this.id = data.id || "";
19406
+ this.sku = data.sku || null;
19407
+ this.barcodeList = data.barcodeList || [];
19408
+ this.variantValues = data.variantValues
19409
+ ? data.variantValues.map(function (vv) { return new IkasVariantValue(vv); })
19410
+ : [];
19411
+ this.images = data.images
19412
+ ? data.images.map(function (i) { return new IkasImage(i.id); })
19413
+ : [];
19414
+ this.attributes = data.attributes
19415
+ ? data.attributes.map(function (a) { return new IkasProductAttributeValue(a); })
19416
+ : [];
19417
+ this.price = data.price
19418
+ ? new IkasProductPrice(data.price)
19419
+ : new IkasProductPrice();
19420
+ this.stock = data.stock || 0;
19421
+ makeAutoObservable(this);
19422
+ }
19423
+ Object.defineProperty(IkasProductVariant.prototype, "mainImage", {
19424
+ get: function () {
19425
+ return this.images.length ? this.images[0] : undefined;
19426
+ },
19427
+ enumerable: false,
19428
+ configurable: true
19429
+ });
19430
+ return IkasProductVariant;
19431
+ }());
19473
19432
 
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
- }
19433
+ var IkasVariantType = /** @class */ (function () {
19434
+ function IkasVariantType(data) {
19435
+ var _this = this;
19436
+ if (data === void 0) { data = {}; }
19437
+ this.id = data.id || "";
19438
+ this.name = data.name || "";
19439
+ this.selectionType = data.selectionType || IkasVariantSelectionType.CHOICE;
19440
+ this.values = data.values
19441
+ ? data.values.map(function (v) {
19442
+ return new IkasVariantValue(__assign(__assign({}, v), { variantTypeId: _this.id }));
19443
+ })
19444
+ : [];
19445
+ makeAutoObservable(this);
19446
+ }
19447
+ Object.defineProperty(IkasVariantType.prototype, "isColorSelection", {
19448
+ get: function () {
19449
+ return this.selectionType === IkasVariantSelectionType.COLOR;
19450
+ },
19451
+ enumerable: false,
19452
+ configurable: true
19453
+ });
19454
+ Object.defineProperty(IkasVariantType.prototype, "slug", {
19455
+ get: function () {
19456
+ return stringToSlug(this.name);
19457
+ },
19458
+ enumerable: false,
19459
+ configurable: true
19460
+ });
19461
+ return IkasVariantType;
19462
+ }());
19463
+ var IkasVariantSelectionType;
19464
+ (function (IkasVariantSelectionType) {
19465
+ IkasVariantSelectionType["CHOICE"] = "CHOICE";
19466
+ IkasVariantSelectionType["COLOR"] = "COLOR";
19467
+ })(IkasVariantSelectionType || (IkasVariantSelectionType = {}));
19497
19468
 
19498
- var _isIterateeCall = isIterateeCall;
19469
+ var IkasProductVariantType = /** @class */ (function () {
19470
+ function IkasProductVariantType(data) {
19471
+ var _this = this;
19472
+ this.variantType = data.variantType
19473
+ ? new IkasVariantType(data.variantType)
19474
+ : new IkasVariantType();
19475
+ this.variantValueIds = data.variantValueIds || [];
19476
+ this.variantType.values = this.variantType.values.filter(function (v) {
19477
+ return _this.variantValueIds.includes(v.id);
19478
+ });
19479
+ makeAutoObservable(this);
19480
+ }
19481
+ return IkasProductVariantType;
19482
+ }());
19499
19483
 
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
- });
19484
+ var IkasProductTag = /** @class */ (function () {
19485
+ function IkasProductTag(data) {
19486
+ this.id = data.id || "";
19487
+ this.name = data.name || "";
19488
+ makeAutoObservable(this);
19489
+ }
19490
+ return IkasProductTag;
19491
+ }());
19541
19492
 
19542
- var sortBy_1 = sortBy;
19493
+ var IkasProduct = /** @class */ (function () {
19494
+ function IkasProduct(data) {
19495
+ if (data === void 0) { data = {}; }
19496
+ this.id = data.id || "";
19497
+ this.name = data.name || "";
19498
+ this.type = data.type || IkasProductType.PHYSICAL;
19499
+ this.description = data.description || "";
19500
+ this.shortDescription = data.shortDescription || "";
19501
+ this.metaData = data.metaData
19502
+ ? new IkasHTMLMetaData(data.metaData)
19503
+ : undefined;
19504
+ this.brand = data.brand ? new IkasBrand(data.brand) : null;
19505
+ this.categories = data.categories
19506
+ ? data.categories.map(function (c) { return new IkasCategory(c); })
19507
+ : [];
19508
+ this.tags = data.tags
19509
+ ? data.tags.map(function (tag) { return new IkasProductTag(tag); })
19510
+ : [];
19511
+ this.variants = data.variants
19512
+ ? data.variants.map(function (v) { return new IkasProductVariant(v); })
19513
+ : [];
19514
+ this.attributes = data.attributes
19515
+ ? data.attributes.map(function (a) { return new IkasProductAttributeValue(a); })
19516
+ : [];
19517
+ this.variantTypes = data.variantTypes
19518
+ ? data.variantTypes.map(function (v) { return new IkasProductVariantType(v); })
19519
+ : [];
19520
+ makeAutoObservable(this);
19521
+ }
19522
+ Object.defineProperty(IkasProduct.prototype, "hasVariant", {
19523
+ get: function () {
19524
+ return !!this.variantTypes.length;
19525
+ },
19526
+ enumerable: false,
19527
+ configurable: true
19528
+ });
19529
+ Object.defineProperty(IkasProduct.prototype, "mainVariantType", {
19530
+ get: function () {
19531
+ if (!this.hasVariant)
19532
+ return;
19533
+ return this.variantTypes[0].variantType;
19534
+ },
19535
+ enumerable: false,
19536
+ configurable: true
19537
+ });
19538
+ Object.defineProperty(IkasProduct.prototype, "href", {
19539
+ get: function () {
19540
+ var _a;
19541
+ if (!((_a = this.metaData) === null || _a === void 0 ? void 0 : _a.slug))
19542
+ return "";
19543
+ return "/" + this.metaData.slug;
19544
+ },
19545
+ enumerable: false,
19546
+ configurable: true
19547
+ });
19548
+ return IkasProduct;
19549
+ }());
19550
+ var IkasProductType;
19551
+ (function (IkasProductType) {
19552
+ IkasProductType["PHYSICAL"] = "PHYSICAL";
19553
+ IkasProductType["DIGITAL"] = "DIGITAL";
19554
+ IkasProductType["MEMBERSHIP"] = "MEMBERSHIP";
19555
+ })(IkasProductType || (IkasProductType = {}));
19543
19556
 
19544
19557
  var IkasProductFilter = /** @class */ (function () {
19545
19558
  function IkasProductFilter(data, productList) {
@@ -24798,13 +24811,13 @@ var IkasCheckoutAPI = /** @class */ (function () {
24798
24811
  });
24799
24812
  });
24800
24813
  };
24801
- IkasCheckoutAPI.listPaymentGateway = function () {
24814
+ IkasCheckoutAPI.listPaymentGateway = function (idList) {
24802
24815
  return __awaiter(this, void 0, void 0, function () {
24803
24816
  var QUERY, _a, data, errors, err_5;
24804
24817
  return __generator(this, function (_b) {
24805
24818
  switch (_b.label) {
24806
24819
  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 testMode\n }\n }\n "], ["\n query listPaymentGateway {\n listPaymentGateway {\n paymentMethods {\n name\n logoUrl\n }\n paymentMethodType\n id\n name\n testMode\n }\n }\n "])));
24820
+ 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
24821
  _b.label = 1;
24809
24822
  case 1:
24810
24823
  _b.trys.push([1, 3, , 4]);
@@ -24812,6 +24825,9 @@ var IkasCheckoutAPI = /** @class */ (function () {
24812
24825
  .getClient()
24813
24826
  .query({
24814
24827
  query: QUERY,
24828
+ variables: {
24829
+ id: idList ? { in: idList } : undefined,
24830
+ },
24815
24831
  })];
24816
24832
  case 2:
24817
24833
  _a = _b.sent(), data = _a.data, errors = _a.errors;
@@ -24881,7 +24897,9 @@ var IkasCheckoutAPI = /** @class */ (function () {
24881
24897
  query: QUERY,
24882
24898
  variables: {
24883
24899
  lines: lines,
24884
- stockLocationIdList: stockLocationIdList,
24900
+ stockLocationIdList: stockLocationIdList.length
24901
+ ? stockLocationIdList
24902
+ : null,
24885
24903
  },
24886
24904
  })];
24887
24905
  case 2:
@@ -26652,7 +26670,7 @@ var styles$2 = {"CheckoutPage":"style-module_CheckoutPage__A_f2V","Left":"style-
26652
26670
  styleInject(css_248z$3);
26653
26671
 
26654
26672
  var AddressForm$1 = observer(function (_a) {
26655
- var _b, _c, _d, _e, _f, _g, _h;
26673
+ var _b, _c, _d, _e, _f;
26656
26674
  var isErrorsVisible = _a.isErrorsVisible, validationResult = _a.validationResult, props = __rest(_a, ["isErrorsVisible", "validationResult"]);
26657
26675
  var vm = useState(function () { return new AddressFormViewModel(props); })[0];
26658
26676
  useEffect(function () {
@@ -26680,10 +26698,12 @@ var AddressForm$1 = observer(function (_a) {
26680
26698
  vm.hasState && (createElement(FormItem, { type: FormItemType.SELECT, label: "Eyalet", value: ((_c = vm.state) === null || _c === void 0 ? void 0 : _c.id) || "", onChange: vm.onStateChange, options: vm.stateOptions, hasError: isErrorsVisible && !(validationResult === null || validationResult === void 0 ? void 0 : validationResult.state), errorText: "Eyalet seçin" })),
26681
26699
  createElement(FormItem, { type: FormItemType.SELECT, label: "\u0130l", value: ((_d = vm.city) === null || _d === void 0 ? void 0 : _d.id) || "", onChange: vm.onCityChange, options: vm.cityOptions, hasError: isErrorsVisible && !(validationResult === null || validationResult === void 0 ? void 0 : validationResult.city), errorText: "Şehir seçin" }),
26682
26700
  vm.districtOptions.length ? (createElement(FormItem, { type: FormItemType.SELECT, label: "\u0130l\u00E7e", value: ((_e = vm.district) === null || _e === void 0 ? void 0 : _e.id) || "", onChange: vm.onDistrictChange, options: vm.districtOptions, errorText: "İlçe seçin" })) : (createElement(FormItem, { type: FormItemType.TEXT, label: "\u0130l\u00E7e", value: ((_f = vm.district) === null || _f === void 0 ? void 0 : _f.name) || "", onChange: vm.onDistrictInputChange })),
26683
- ((_g = vm.address.checkoutSettings) === null || _g === void 0 ? void 0 : _g.phoneRequirement) !==
26684
- IkasCheckoutRequirementEnum.INVISIBLE && (createElement(FormItem, { type: FormItemType.TEXT, label: "Telefon", autocomplete: "tel", value: vm.phone || "", onChange: vm.onPhoneChange, hasError: isErrorsVisible && !(validationResult === null || validationResult === void 0 ? void 0 : validationResult.phone), errorText: "Geçerli bir telefon girin" })),
26685
- ((_h = vm.address.checkoutSettings) === null || _h === void 0 ? void 0 : _h.identityNumberRequirement) !==
26686
- IkasCheckoutRequirementEnum.INVISIBLE && (createElement(FormItem, { type: FormItemType.TEXT, label: "TC Kimlik No", value: vm.identityNumber || "", onChange: vm.onIdentityNumberChange, hasError: isErrorsVisible && !(validationResult === null || validationResult === void 0 ? void 0 : validationResult.identityNumber), errorText: "TC kimlik no girin" })))));
26701
+ !!vm.address.checkoutSettings &&
26702
+ vm.address.checkoutSettings.phoneRequirement !==
26703
+ IkasCheckoutRequirementEnum.INVISIBLE && (createElement(FormItem, { type: FormItemType.TEXT, label: "Telefon", autocomplete: "tel", value: vm.phone || "", onChange: vm.onPhoneChange, hasError: isErrorsVisible && !(validationResult === null || validationResult === void 0 ? void 0 : validationResult.phone), errorText: "Geçerli bir telefon girin" })),
26704
+ !!vm.address.checkoutSettings &&
26705
+ vm.address.checkoutSettings.identityNumberRequirement !==
26706
+ IkasCheckoutRequirementEnum.INVISIBLE && (createElement(FormItem, { type: FormItemType.TEXT, label: "TC Kimlik No", value: vm.identityNumber || "", onChange: vm.onIdentityNumberChange, hasError: isErrorsVisible && !(validationResult === null || validationResult === void 0 ? void 0 : validationResult.identityNumber), errorText: "TC kimlik no girin" })))));
26687
26707
  });
26688
26708
 
26689
26709
  var css_248z$4 = ".style-module_Button__1UPMN {\n cursor: pointer;\n border: 1px transparent solid;\n border-radius: 6px;\n font-weight: 500;\n text-align: center;\n position: relative;\n transition: all .2s;\n display: flex;\n justify-content: center;\n align-items: center; }\n .style-module_Button__1UPMN.style-module_Large__2wPlw {\n height: 64px;\n padding: 0 1.7em; }\n .style-module_Button__1UPMN.style-module_Dark__1Z_hs {\n background-color: #111111;\n color: white; }\n .style-module_Button__1UPMN.style-module_Disabled__3HYF_ {\n background-color: #c8c8c8;\n color: #545454;\n pointer-events: none; }\n @media only screen and (max-width: 1000px) {\n .style-module_Button__1UPMN.style-module_FullWidthMobile__3MTFv {\n width: 100%; } }\n .style-module_Button__1UPMN .style-module_loader__3v6kq,\n .style-module_Button__1UPMN .style-module_loader__3v6kq:after {\n border-radius: 50%;\n width: 5em;\n height: 5em; }\n .style-module_Button__1UPMN .style-module_loader__3v6kq {\n font-size: 6px;\n position: relative;\n text-indent: -9999em;\n border-top: 0.5em solid rgba(255, 255, 255, 0.2);\n border-right: 0.5em solid rgba(255, 255, 255, 0.2);\n border-bottom: 0.5em solid rgba(255, 255, 255, 0.2);\n border-left: 0.5em solid #ffffff;\n -webkit-transform: translateZ(0);\n -ms-transform: translateZ(0);\n transform: translateZ(0);\n -webkit-animation: style-module_load8__2z7nj 1.1s infinite linear;\n animation: style-module_load8__2z7nj 1.1s infinite linear; }\n\n@-webkit-keyframes style-module_load8__2z7nj {\n 0% {\n -webkit-transform: rotate(0deg);\n transform: rotate(0deg); }\n 100% {\n -webkit-transform: rotate(360deg);\n transform: rotate(360deg); } }\n\n@keyframes style-module_load8__2z7nj {\n 0% {\n -webkit-transform: rotate(0deg);\n transform: rotate(0deg); }\n 100% {\n -webkit-transform: rotate(360deg);\n transform: rotate(360deg); } }\n";
@@ -26950,7 +26970,7 @@ var PaymentGateways = observer(function (_a) {
26950
26970
  : pg.name)),
26951
26971
  expandContent: pg.paymentMethodType === IkasPaymentMethodType.CREDIT_CARD ? (createElement("div", null,
26952
26972
  createElement(CreditCardForm, { vm: vm }),
26953
- vm.installmentInfo && createElement(Installments, { vm: vm }))) : undefined,
26973
+ vm.installmentInfo && createElement(Installments, { vm: vm }))) : pg.description ? (createElement("div", null, pg.description)) : undefined,
26954
26974
  rightContent: (createElement(PaymentMethodLogos, null, pg.paymentMethods.map(function (pm, index) {
26955
26975
  return pm.logoUrl ? (createElement("div", { className: styles$b.PaymentLogoContainer, key: index },
26956
26976
  createElement("img", { src: pm.logoUrl }))) : (createElement("div", { className: styles$b.PaymentLogoContainer, key: index }, pm.name));
@@ -27005,6 +27025,7 @@ var CheckoutStepPayment = observer(function (_a) {
27005
27025
  var vm = _a.vm;
27006
27026
  var onShowTermsClick = function (e) {
27007
27027
  e.stopPropagation();
27028
+ vm.policyModalTitle = "Mesafeli Satış Sözleşmesi";
27008
27029
  vm.policyModalText = vm.termsOfService;
27009
27030
  };
27010
27031
  return (createElement("div", { className: [styles$d.StepPayment, commonStyles.FormContainer].join(" ") },
@@ -28498,13 +28519,15 @@ var IkasStorefront = /** @class */ (function () {
28498
28519
  var IkasSalesChannel = /** @class */ (function () {
28499
28520
  function IkasSalesChannel(data) {
28500
28521
  if (data === void 0) { data = {}; }
28501
- var _a;
28522
+ var _a, _b;
28502
28523
  this.id = data.id || "";
28503
28524
  this.name = data.name || "";
28504
28525
  this.priceListId = data.priceListId || "";
28505
28526
  this.stockLocations =
28506
28527
  ((_a = data.stockLocations) === null || _a === void 0 ? void 0 : _a.map(function (sl) { return new IkasSalesChannelStockLocation(sl); })) ||
28507
28528
  [];
28529
+ this.paymentGateways =
28530
+ ((_b = data.paymentGateways) === null || _b === void 0 ? void 0 : _b.map(function (pg) { return new IkasSalesChannelPaymentGateway(pg); })) || [];
28508
28531
  }
28509
28532
  return IkasSalesChannel;
28510
28533
  }());
@@ -28514,6 +28537,13 @@ var IkasSalesChannelStockLocation = /** @class */ (function () {
28514
28537
  this.order = data.order || 0;
28515
28538
  }
28516
28539
  return IkasSalesChannelStockLocation;
28540
+ }());
28541
+ var IkasSalesChannelPaymentGateway = /** @class */ (function () {
28542
+ function IkasSalesChannelPaymentGateway(data) {
28543
+ this.id = data.id || "";
28544
+ this.order = data.order || 0;
28545
+ }
28546
+ return IkasSalesChannelPaymentGateway;
28517
28547
  }());
28518
28548
 
28519
28549
  var IkasStorefrontThemeLocalization = /** @class */ (function () {
@@ -28713,6 +28743,7 @@ var SettingsHelper = /** @class */ (function () {
28713
28743
  IkasStorefrontConfig.priceListId = routing.priceListId || undefined;
28714
28744
  IkasStorefrontConfig.stockLocationIds = (_a = salesChannel.stockLocations) === null || _a === void 0 ? void 0 : _a.map(function (sl) { return sl.id; });
28715
28745
  IkasStorefrontConfig.routings = storefront.routings;
28746
+ IkasStorefrontConfig.paymentGateways = salesChannel.paymentGateways || [];
28716
28747
  IkasStorefrontConfig.gtmId = storefront.gtmId || undefined;
28717
28748
  IkasStorefrontConfig.fbpId = storefront.fbpId || undefined;
28718
28749
  provider = new IkasPageDataProvider(themeLocalization.themeJson, context.params, pageType);
@@ -29361,7 +29392,7 @@ var IkasBaseStore = /** @class */ (function () {
29361
29392
  }
29362
29393
  IkasBaseStore.prototype.checkLocalization = function () {
29363
29394
  return __awaiter(this, void 0, void 0, function () {
29364
- var myCountryCode, currentRouting, correctRouting, isCorrectLocale, countries_1, localeOptions_1;
29395
+ var myCountryCode, currentRouting, correctRouting, isCorrectLocale, hasNoSpecificCountry, countries_1, localeOptions_1;
29365
29396
  return __generator(this, function (_a) {
29366
29397
  switch (_a.label) {
29367
29398
  case 0:
@@ -29375,12 +29406,15 @@ var IkasBaseStore = /** @class */ (function () {
29375
29406
  case 1:
29376
29407
  myCountryCode = _a.sent();
29377
29408
  currentRouting = IkasStorefrontConfig.routings.find(function (r) { return r.id === IkasStorefrontConfig.storefrontRoutingId; });
29378
- console.log("storefrontRoutingId", IkasStorefrontConfig.storefrontRoutingId);
29379
- console.log("currentRouting", currentRouting);
29380
- console.log(IkasStorefrontConfig.routings);
29381
29409
  if (!(currentRouting && myCountryCode)) return [3 /*break*/, 3];
29382
29410
  correctRouting = IkasStorefrontConfig.routings.find(function (r) { var _a; return (_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.includes(myCountryCode); });
29383
29411
  isCorrectLocale = IkasStorefrontConfig.storefrontRoutingId === (correctRouting === null || correctRouting === void 0 ? void 0 : correctRouting.id);
29412
+ if (!isCorrectLocale) {
29413
+ hasNoSpecificCountry = IkasStorefrontConfig.routings.length === 0 ||
29414
+ IkasStorefrontConfig.routings.every(function (r) { var _a; return !((_a = r.countryCodes) === null || _a === void 0 ? void 0 : _a.length); });
29415
+ if (hasNoSpecificCountry)
29416
+ isCorrectLocale = true;
29417
+ }
29384
29418
  return [4 /*yield*/, IkasCountryAPI.listCountries()];
29385
29419
  case 2:
29386
29420
  countries_1 = _a.sent();
@@ -29409,7 +29443,6 @@ var IkasBaseStore = /** @class */ (function () {
29409
29443
  });
29410
29444
  this.localeOptions = localeOptions_1;
29411
29445
  if (!isCorrectLocale) {
29412
- console.log("showing locale options");
29413
29446
  this.showLocaleOptions = true;
29414
29447
  }
29415
29448
  this.localeChecked = true;
@@ -29420,7 +29453,6 @@ var IkasBaseStore = /** @class */ (function () {
29420
29453
  });
29421
29454
  };
29422
29455
  IkasBaseStore.prototype.setLocalization = function (localeOption) {
29423
- document.cookie = "NEXT_LOCALE=" + (localeOption.routing.path || localeOption.routing.id) + "; expires=Thu, 1 Dec 2050 12:00:00 UTC";
29424
29456
  if (localeOption.routing.domain) {
29425
29457
  window.location.replace("https://" + localeOption.routing.domain);
29426
29458
  }