示例#1
0
 public static TransactionHistoryEntity CreateForSmartVoucherUse(SmartVoucherUseDto operation)
 {
     return(new TransactionHistoryEntity
     {
         CustomerId = operation.CustomerId.ToString(),
         Timestamp = operation.Timestamp,
         AssetSymbol = operation.AssetSymbol,
         TransactionId = operation.Id,
         Type = OperationType.SmartVoucherUse.ToString(),
     });
 }
        public async Task AddUseAsync(SmartVoucherUseDto smartVoucher)
        {
            using (var context = _contextFactory.CreateDataContext())
            {
                var entity        = SmartVoucherUseEntity.Create(smartVoucher);
                var historyEntity = TransactionHistoryEntity.CreateForSmartVoucherUse(smartVoucher);

                entity.Campaign = await GetAndUpdateCampaign(context, smartVoucher.CampaignId, smartVoucher.CampaignName);

                context.SmartVoucherUses.Add(entity);
                context.TransactionHistories.Add(historyEntity);

                await context.SaveChangesAsync();
            }
        }
示例#3
0
 public static SmartVoucherUseEntity Create(SmartVoucherUseDto smartVoucherUse)
 {
     return(new SmartVoucherUseEntity
     {
         Timestamp = smartVoucherUse.Timestamp,
         PartnerId = smartVoucherUse.PartnerId,
         Amount = smartVoucherUse.Amount,
         AssetSymbol = smartVoucherUse.AssetSymbol,
         CustomerId = smartVoucherUse.CustomerId,
         CampaignId = smartVoucherUse.CampaignId,
         LinkedCustomerId = smartVoucherUse.LinkedCustomerId,
         Id = smartVoucherUse.Id,
         LocationId = smartVoucherUse.LocationId,
         Vertical = smartVoucherUse.Vertical,
         PartnerName = smartVoucherUse.PartnerName,
     });
 }
示例#4
0
        protected override async Task ProcessMessageAsync(SmartVoucherUsedEvent message)
        {
            var dto = new SmartVoucherUseDto
            {
                Amount           = message.Amount,
                AssetSymbol      = message.Currency,
                CustomerId       = message.CustomerId,
                PartnerId        = message.PartnerId,
                Timestamp        = message.Timestamp,
                CampaignId       = message.CampaignId.ToString(),
                LinkedCustomerId = message.LinkedCustomerId,
                LocationId       = message.LocationId,
            };

            await _operationsService.ProcessSmartVoucherUsedEventAsync(dto);

            _log.Info("Processed SmartVoucherUsedEvent", context: message);
        }
        public async Task ProcessSmartVoucherUsedEventAsync(SmartVoucherUseDto smartVoucherUse)
        {
            smartVoucherUse.Id = Guid.NewGuid().ToString();

            var isValid = ValidateSmartVoucherUseOperation(smartVoucherUse);

            if (!isValid)
            {
                return;
            }

            var(partnerName, vertical, campaignName) = await GetAdditionalDataForSmartVoucher(
                smartVoucherUse.CampaignId,
                smartVoucherUse.PartnerId);

            smartVoucherUse.PartnerName  = partnerName;
            smartVoucherUse.Vertical     = vertical;
            smartVoucherUse.CampaignName = campaignName;

            await _smartVoucherRepository.AddUseAsync(smartVoucherUse);
        }
        private bool ValidateSmartVoucherUseOperation(SmartVoucherUseDto smartVoucherUse)
        {
            bool isValid = true;

            if (smartVoucherUse.Amount < 0)
            {
                isValid = false;
                _log.Warning("Smart voucher use with negative fee amount", context: smartVoucherUse);
            }

            if (smartVoucherUse.CustomerId == Guid.Empty)
            {
                isValid = false;
                _log.Warning("Smart voucher use without customer id", context: smartVoucherUse);
            }

            if (string.IsNullOrEmpty(smartVoucherUse.CampaignId))
            {
                isValid = false;
                _log.Warning("Smart voucher use without campaign id", context: smartVoucherUse);
            }

            if (smartVoucherUse.PartnerId == Guid.Empty)
            {
                isValid = false;
                _log.Warning("Smart voucher use without partner id", context: smartVoucherUse);
            }

            if (string.IsNullOrEmpty(smartVoucherUse.AssetSymbol))
            {
                isValid = false;
                _log.Warning("Smart voucher use without asset symbol", context: smartVoucherUse);
            }

            return(isValid);
        }