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