Update 2 files

This commit is contained in:
Mikhail 2023-08-18 18:50:41 +00:00
parent d6b891b7c5
commit f60f070239

@ -149,13 +149,18 @@ func (receiver *Service) Pay(ctx context.Context, accessToken string, userID str
return err
}
receiver.logger.Debug("account for buy cart", zap.Any("trtr", account))
tariffs, err := receiver.hubadminClient.GetTariffs(ctx, accessToken, account.Cart)
if err != nil {
receiver.logger.Error("failed to get tarrifs on <Pay> of <CartService>", zap.Strings("cart", account.Cart), zap.Error(err))
return err
}
receiver.logger.Debug("tariffs for buy cart", zap.Any("trtr", tariffs))
tariffsAmount := utils.CalculateCartPurchasesAmount(tariffs)
receiver.logger.Debug("tariffsAmount for buy cart", zap.Any("trtr", tariffsAmount))
response, err := receiver.discountClient.Apply(ctx, &discount.ApplyDiscountRequest{
UserInformation: &discount.UserInformation{
@ -172,6 +177,8 @@ func (receiver *Service) Pay(ctx context.Context, accessToken string, userID str
return err
}
receiver.logger.Debug("applyed discounts for buy cart", zap.Any("trtr", response))
if account.Wallet.Money < int64(response.Price) {
receiver.logger.Error("insufficient funds on <Pay> of <CartService>")
return errors.New(fmt.Errorf("insufficient funds: %d", int64(response.Price)-account.Wallet.Money), errors.ErrInsufficientFunds)