Esempio n. 1
0
 public static TransactionHistoryEntity CreateForSmartVoucherTransferReceiver(SmartVoucherTransferDto operation)
 {
     return(new TransactionHistoryEntity
     {
         CustomerId = operation.NewCustomerId.ToString(),
         Timestamp = operation.Timestamp,
         AssetSymbol = operation.AssetSymbol,
         TransactionId = operation.Id,
         Type = OperationType.SmartVoucherTransfer.ToString(),
     });
 }
        public async Task AddTransferAsync(SmartVoucherTransferDto transfer)
        {
            using (var context = _contextFactory.CreateDataContext())
            {
                var entity = SmartVoucherTransferEntity.Create(transfer);
                var historyEntityForSender   = TransactionHistoryEntity.CreateForSmartVoucherTransferSender(transfer);
                var historyEntityForReceiver = TransactionHistoryEntity.CreateForSmartVoucherTransferReceiver(transfer);

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

                context.SmartVoucherTransfers.Add(entity);
                context.TransactionHistories.Add(historyEntityForSender);
                context.TransactionHistories.Add(historyEntityForReceiver);

                await context.SaveChangesAsync();
            }
        }
Esempio n. 3
0
 public static SmartVoucherTransferEntity Create(SmartVoucherTransferDto smartVoucherTransfer)
 {
     return(new SmartVoucherTransferEntity
     {
         Timestamp = smartVoucherTransfer.Timestamp,
         PartnerId = smartVoucherTransfer.PartnerId,
         Amount = smartVoucherTransfer.Amount,
         AssetSymbol = smartVoucherTransfer.AssetSymbol,
         OldCustomerId = smartVoucherTransfer.OldCustomerId,
         NewCustomerId = smartVoucherTransfer.NewCustomerId,
         CampaignId = smartVoucherTransfer.CampaignId,
         Id = smartVoucherTransfer.Id,
         PartnerName = smartVoucherTransfer.PartnerName,
         Vertical = smartVoucherTransfer.Vertical,
         ShortCode = smartVoucherTransfer.ShortCode,
     });
 }
Esempio n. 4
0
        protected override async Task ProcessMessageAsync(SmartVoucherTransferredEvent message)
        {
            var dto = new SmartVoucherTransferDto
            {
                Amount        = message.Amount,
                AssetSymbol   = message.Currency,
                PartnerId     = message.PartnerId,
                ShortCode     = message.VoucherShortCode,
                Timestamp     = message.Timestamp,
                CampaignId    = message.CampaignId.ToString(),
                NewCustomerId = message.NewCustomerId,
                OldCustomerId = message.OldCustomerId,
            };

            await _operationsService.ProcessSmartVoucherTransferredEventAsync(dto);

            _log.Info("Processed SmartVoucherTransferredEvent", context: message);
        }
        private bool ValidateSmartVoucherTransferOperation(SmartVoucherTransferDto smartVoucherTransfer)
        {
            bool isValid = true;

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

            if (smartVoucherTransfer.OldCustomerId == Guid.Empty)
            {
                isValid = false;
                _log.Warning("Smart voucher transfer without customer id", context: smartVoucherTransfer);
            }

            if (smartVoucherTransfer.NewCustomerId == Guid.Empty)
            {
                isValid = false;
                _log.Warning("Smart voucher transfer without customer id", context: smartVoucherTransfer);
            }

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

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

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

            return(isValid);
        }
        public async Task ProcessSmartVoucherTransferredEventAsync(SmartVoucherTransferDto smartVoucherTransfer)
        {
            smartVoucherTransfer.Id = Guid.NewGuid().ToString();

            var isValid = ValidateSmartVoucherTransferOperation(smartVoucherTransfer);

            if (!isValid)
            {
                return;
            }

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

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

            await _smartVoucherRepository.AddTransferAsync(smartVoucherTransfer);
        }