ng-miam 8.3.9 → 8.3.10

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.
@@ -4109,30 +4109,38 @@
4109
4109
  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); })); })); }));
4110
4110
  };
4111
4111
  /** ********************************************************* CONFIRM BASKET ********************************************************* **/
4112
- // Set basket as confirmed, and returns only once the new current list is returned
4113
- BasketsService.prototype.confirmBasket = function (totalPrice) {
4112
+ /**
4113
+ * Sends payment.confirm event then confirm basket if retailer's cart price and Mealz basket price are both non-zero
4114
+ * @param totalPrice The price of retailer's basket
4115
+ * @returns the current basket
4116
+ */
4117
+ BasketsService.prototype.confirmPaymentAndBasket = function (totalPrice) {
4114
4118
  var _this = this;
4115
- var confirmedBasket;
4116
- console.debug("[Miam] Confirm basket " + JSON.stringify(confirmedBasket));
4117
- return this.waitForBasket.pipe(operators.tap(function (basket) {
4118
- if (basket.totalPrice > 0) {
4119
+ return this.waitForBasket.pipe(operators.switchMap(function (basket) {
4120
+ if (+totalPrice > 0 && basket.totalPrice > 0) {
4119
4121
  _this.analyticsService.sendEventWhenReady(_this.analyticsService.EVENT_PAYMENT_CONFIRMED, null, _this.eventProps(basket, totalPrice));
4122
+ return _this.confirmBasket(basket, totalPrice);
4120
4123
  }
4121
- }), operators.switchMap(function (basket) {
4122
- console.debug('[Miam] Save basket with confirmed=true');
4123
- basket.attributes.confirmed = true;
4124
- return basket.save({ fields: { baskets: __spread(BASKET_SPARSE_FIELDS.baskets, ['token']) } });
4125
- }), operators.switchMap(function (resp) {
4126
- confirmedBasket = _this.new();
4127
- confirmedBasket.fill(resp);
4128
- console.debug("[Miam] send push analytics event if > 0: " + JSON.stringify(confirmedBasket.totalPrice) + " " + JSON.stringify(confirmedBasket));
4129
- if (confirmedBasket.totalPrice > 0 && confirmedBasket.token) {
4130
- _this.analyticsService.sendEventWhenReady(_this.analyticsService.EVENT_BASKET_CONFIRMED, null, _this.eventProps(confirmedBasket, totalPrice));
4131
- localStorage.removeItem('_miam/affiliate');
4124
+ return _this._basket$;
4125
+ }));
4126
+ };
4127
+ /**
4128
+ * Tries to confirm basket. Sends analytic event and refresh current basket on successfull confirmation
4129
+ */
4130
+ BasketsService.prototype.confirmBasket = function (basket, totalPrice) {
4131
+ var _this = this;
4132
+ console.debug('[Miam] Confirm Mealz basket');
4133
+ return this.posService.pos$.pipe(operators.skipWhile(function (pos) { return !pos; }), operators.take(1), operators.switchMap(function (pos) {
4134
+ var url = environment$1.miamAPI + "/api/v1/baskets/confirm?point_of_sale_id=" + pos.id;
4135
+ return _this.http.patch(url, {});
4136
+ }), operators.catchError(function () { return rxjs.of(null); }), operators.switchMap(function (result) {
4137
+ if (!result) {
4138
+ return rxjs.of(null);
4132
4139
  }
4133
- _this._basket$.next(undefined);
4134
- return _this.resetBasket();
4135
- }), operators.switchMap(function () { return _this._basket$; }), operators.skipWhile(function (b) { return !b; }), operators.map(function () { return confirmedBasket; }));
4140
+ localStorage.removeItem('_miam/affiliate');
4141
+ _this.analyticsService.sendEventWhenReady(_this.analyticsService.EVENT_BASKET_CONFIRMED, null, _this.eventProps(basket, totalPrice));
4142
+ return _this.refreshCurrentBasket();
4143
+ }), operators.take(1));
4136
4144
  };
4137
4145
  BasketsService.prototype.eventProps = function (basket, totalPrice) {
4138
4146
  return {
@@ -5257,7 +5265,7 @@
5257
5265
  BasketsSynchronizerService.prototype.handlePayment = function (total) {
5258
5266
  var _this = this;
5259
5267
  if (total) {
5260
- this.basketsService.confirmBasket(total).subscribe(function () {
5268
+ this.basketsService.confirmPaymentAndBasket(total).subscribe(function () {
5261
5269
  _this.firstRetailerBasket = [];
5262
5270
  });
5263
5271
  }
@@ -8478,7 +8486,7 @@
8478
8486
  MiamInterceptor.prototype.setMiamHeaders = function (request) {
8479
8487
  var headersToAdd = {
8480
8488
  'miam-origin': this.context.origin.value,
8481
- 'miam-front-version': '8.3.9',
8489
+ 'miam-front-version': '8.3.10',
8482
8490
  'miam-front-type': 'web',
8483
8491
  'miam-api-version': '4.7.0'
8484
8492
  };
@@ -28885,7 +28893,7 @@
28885
28893
  _this.basketChangedSinceOpened = true;
28886
28894
  _this.cdr.detectChanges();
28887
28895
  }
28888
- }), this.basketsService.basket$.pipe(operators.filter(function (basket) { return basket !== null; }), operators.map(function (basket) { return basket.totalPrice; })).subscribe(function (totalPrice) {
28896
+ }), this.basketsService.basket$.pipe(operators.skipWhile(function (basket) { return !basket; }), operators.map(function (basket) { return basket.totalPrice; })).subscribe(function (totalPrice) {
28889
28897
  _this.totalPrice = totalPrice;
28890
28898
  _this.updateShowPlaceOrderFooter();
28891
28899
  _this.cdr.detectChanges();