ng-miam 8.5.2 → 8.5.4

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.
@@ -4130,30 +4130,38 @@
4130
4130
  return this.posService.pos$.pipe(operators.skipWhile(function (pos) { return !pos; }), operators.take(1), operators.switchMap(function (pos) { return _this.waitForBasket.pipe(operators.tap(function (basket) { return _this.analyticsService.sendEventsOfResetBasket(basket, eventTrace); }), operators.switchMap(function () { return _this.get("reset?point_of_sale_id=" + pos.id + "&fields[baskets]=" + BASKET_SPARSE_FIELDS.baskets.join(',')).pipe(operators.skipWhile(function (basket) { return basket.is_loading; }), operators.switchMap(function (basket) { return _this.updateLocalBasket(basket); })); })); }));
4131
4131
  };
4132
4132
  /** ********************************************************* CONFIRM BASKET ********************************************************* **/
4133
- // Set basket as confirmed, and returns only once the new current list is returned
4134
- BasketsService.prototype.confirmBasket = function (totalPrice) {
4133
+ /**
4134
+ * Sends payment.confirm event then confirm basket if retailer's cart price and Mealz basket price are both non-zero
4135
+ * @param totalPrice The price of retailer's basket
4136
+ * @returns the current basket
4137
+ */
4138
+ BasketsService.prototype.confirmPaymentAndBasket = function (totalPrice) {
4135
4139
  var _this = this;
4136
- var confirmedBasket;
4137
- console.debug("[Miam] Confirm basket " + JSON.stringify(confirmedBasket));
4138
- return this.waitForBasket.pipe(operators.tap(function (basket) {
4139
- if (basket.totalPrice > 0) {
4140
+ return this.waitForBasket.pipe(operators.switchMap(function (basket) {
4141
+ if (+totalPrice > 0 && basket.totalPrice > 0) {
4140
4142
  _this.analyticsService.sendEventWhenReady(_this.analyticsService.EVENT_PAYMENT_CONFIRMED, null, _this.eventProps(basket, totalPrice));
4143
+ return _this.confirmBasket(basket, totalPrice);
4141
4144
  }
4142
- }), operators.switchMap(function (basket) {
4143
- console.debug('[Miam] Save basket with confirmed=true');
4144
- basket.attributes.confirmed = true;
4145
- return basket.save({ fields: { baskets: __spread(BASKET_SPARSE_FIELDS.baskets, ['token']) } });
4146
- }), operators.switchMap(function (resp) {
4147
- confirmedBasket = _this.new();
4148
- confirmedBasket.fill(resp);
4149
- console.debug("[Miam] send push analytics event if > 0: " + JSON.stringify(confirmedBasket.totalPrice) + " " + JSON.stringify(confirmedBasket));
4150
- if (confirmedBasket.totalPrice > 0 && confirmedBasket.token) {
4151
- _this.analyticsService.sendEventWhenReady(_this.analyticsService.EVENT_BASKET_CONFIRMED, null, _this.eventProps(confirmedBasket, totalPrice));
4152
- localStorage.removeItem('_miam/affiliate');
4145
+ return _this._basket$;
4146
+ }));
4147
+ };
4148
+ /**
4149
+ * Tries to confirm basket. Sends analytic event and refresh current basket on successfull confirmation
4150
+ */
4151
+ BasketsService.prototype.confirmBasket = function (basket, totalPrice) {
4152
+ var _this = this;
4153
+ console.debug('[Miam] Confirm Mealz basket');
4154
+ return this.posService.pos$.pipe(operators.skipWhile(function (pos) { return !pos; }), operators.take(1), operators.switchMap(function (pos) {
4155
+ var url = environment$1.miamAPI + "/api/v1/baskets/confirm?point_of_sale_id=" + pos.id;
4156
+ return _this.http.patch(url, {});
4157
+ }), operators.catchError(function () { return rxjs.of(null); }), operators.switchMap(function (result) {
4158
+ if (!result) {
4159
+ return rxjs.of(null);
4153
4160
  }
4154
- _this._basket$.next(undefined);
4155
- return _this.resetBasket();
4156
- }), operators.switchMap(function () { return _this._basket$; }), operators.skipWhile(function (b) { return !b; }), operators.map(function () { return confirmedBasket; }));
4161
+ localStorage.removeItem('_miam/affiliate');
4162
+ _this.analyticsService.sendEventWhenReady(_this.analyticsService.EVENT_BASKET_CONFIRMED, null, _this.eventProps(basket, totalPrice));
4163
+ return _this.refreshCurrentBasket();
4164
+ }), operators.take(1));
4157
4165
  };
4158
4166
  BasketsService.prototype.eventProps = function (basket, totalPrice) {
4159
4167
  return {
@@ -5314,7 +5322,7 @@
5314
5322
  BasketsSynchronizerService.prototype.handlePayment = function (total) {
5315
5323
  var _this = this;
5316
5324
  if (total) {
5317
- this.basketsService.confirmBasket(total).subscribe(function () {
5325
+ this.basketsService.confirmPaymentAndBasket(total).subscribe(function () {
5318
5326
  _this.firstRetailerBasket = [];
5319
5327
  });
5320
5328
  }
@@ -8548,7 +8556,7 @@
8548
8556
  MiamInterceptor.prototype.setMiamHeaders = function (request) {
8549
8557
  var headersToAdd = {
8550
8558
  'miam-origin': this.context.origin.value,
8551
- 'miam-front-version': '8.5.2',
8559
+ 'miam-front-version': '8.5.4',
8552
8560
  'miam-front-type': 'web',
8553
8561
  'miam-api-version': '4.7.0'
8554
8562
  };
@@ -28636,7 +28644,7 @@
28636
28644
  _this.basketChangedSinceOpened = true;
28637
28645
  _this.cdr.detectChanges();
28638
28646
  }
28639
- }), this.basketsService.basket$.pipe(operators.filter(function (basket) { return basket !== null; }), operators.map(function (basket) { return basket.totalPrice; })).subscribe(function (totalPrice) {
28647
+ }), this.basketsService.basket$.pipe(operators.skipWhile(function (basket) { return !basket; }), operators.map(function (basket) { return basket.totalPrice; })).subscribe(function (totalPrice) {
28640
28648
  _this.totalPrice = totalPrice;
28641
28649
  _this.updateShowPlaceOrderFooter();
28642
28650
  _this.cdr.detectChanges();
@@ -28668,18 +28676,24 @@
28668
28676
  _this.registerTrace(result === null || result === void 0 ? void 0 : result.eventTrace);
28669
28677
  if (!(result === null || result === void 0 ? void 0 : result.recipe)) {
28670
28678
  if (result === null || result === void 0 ? void 0 : result.force) {
28671
- _this.previewMode.next(result.previewMode);
28672
- _this.previewAllowed = result.previewAllowed;
28673
- _this.show = true;
28674
- // Put back if/when printing is reimplemented
28675
- // this.printService.prepareForPrint(this.elRef);
28679
+ _this.subscriptions.push(_this.posService.posWasInitialized().pipe(operators.take(1)).subscribe(function (wasInitialized) {
28680
+ if (!wasInitialized) {
28681
+ _this.storeLocatorService.storeLocatorOpened$.next(true);
28682
+ }
28683
+ _this.previewMode.next(result.previewMode);
28684
+ _this.previewAllowed = result.previewAllowed;
28685
+ _this.show = true;
28686
+ // Put back if/when printing is reimplemented
28687
+ // this.printService.prepareForPrint(this.elRef);
28688
+ _this.cdr.detectChanges();
28689
+ }));
28676
28690
  }
28677
28691
  else {
28678
28692
  _this.show = false;
28679
28693
  _this._storeLocatorInit = false;
28680
28694
  _this.storeLocatorService.storeLocatorOpened$.next(false);
28695
+ _this.cdr.detectChanges();
28681
28696
  }
28682
- _this.cdr.detectChanges();
28683
28697
  }
28684
28698
  else {
28685
28699
  _this.recipeWasAdded = result.wasAdded;