public async Task ProcessSmartVoucherSoldEventAsync(SmartVoucherPaymentDto smartVoucherPayment) { var isValid = ValidateSmartVoucherPaymentOperation(smartVoucherPayment); if (!isValid) { return; } await _smartVoucherPaymentsRepository.AddAsync(smartVoucherPayment); }
public static TransactionHistoryEntity CreateForSmartVoucherPayment(SmartVoucherPaymentDto operation) { return(new TransactionHistoryEntity { CustomerId = operation.CustomerId.ToString(), Timestamp = operation.Timestamp, AssetSymbol = operation.AssetSymbol, TransactionId = operation.PaymentRequestId, Type = OperationType.SmartVoucherPayment.ToString(), }); }
public async Task AddPaymentAsync(SmartVoucherPaymentDto payment) { using (var context = _contextFactory.CreateDataContext()) { var entity = SmartVoucherPaymentEntity.Create(payment); var historyEntity = TransactionHistoryEntity.CreateForSmartVoucherPayment(payment); entity.Campaign = await GetAndUpdateCampaign(context, payment.CampaignId, payment.CampaignName); context.SmartVoucherPayments.Add(entity); context.TransactionHistories.Add(historyEntity); await context.SaveChangesAsync(); } }
private bool ValidateSmartVoucherPaymentOperation(SmartVoucherPaymentDto smartVoucherPayment) { bool isValid = true; if (smartVoucherPayment.Amount < 0) { isValid = false; _log.Warning("Smart voucher payment with negative fee amount", context: smartVoucherPayment); } if (smartVoucherPayment.CustomerId == Guid.Empty) { isValid = false; _log.Warning("Smart voucher payment without customer id", context: smartVoucherPayment); } if (smartVoucherPayment.CampaignId == Guid.Empty) { isValid = false; _log.Warning("Smart voucher payment without campaign id", context: smartVoucherPayment); } if (string.IsNullOrEmpty(smartVoucherPayment.ShortCode)) { isValid = false; _log.Warning("Smart voucher payment without short code", context: smartVoucherPayment); } if (string.IsNullOrEmpty(smartVoucherPayment.PaymentRequestId)) { isValid = false; _log.Warning("Smart voucher payment without payment request id", context: smartVoucherPayment); } if (smartVoucherPayment.PartnerId == Guid.Empty) { isValid = false; _log.Warning("Smart voucher payment without partner id", context: smartVoucherPayment); } if (string.IsNullOrEmpty(smartVoucherPayment.AssetSymbol)) { isValid = false; _log.Warning("Smart voucher payment without asset symbol", context: smartVoucherPayment); } return(isValid); }
public static SmartVoucherPaymentEntity Create(SmartVoucherPaymentDto payment) { return(new SmartVoucherPaymentEntity { Timestamp = payment.Timestamp, PartnerId = payment.PartnerId, Amount = payment.Amount, ShortCode = payment.ShortCode, AssetSymbol = payment.AssetSymbol, CustomerId = payment.CustomerId, CampaignId = payment.CampaignId, PaymentRequestId = payment.PaymentRequestId, Vertical = payment.Vertical, PartnerName = payment.PartnerName, }); }
protected override async Task ProcessMessageAsync(SmartVoucherSoldEvent message) { var dto = new SmartVoucherPaymentDto { Amount = message.Amount, AssetSymbol = message.Currency, CustomerId = message.CustomerId, PartnerId = message.PartnerId, ShortCode = message.VoucherShortCode, Timestamp = message.Timestamp, CampaignId = message.CampaignId, PaymentRequestId = message.PaymentRequestId, }; await _operationsService.ProcessSmartVoucherSoldEventAsync(dto); _log.Info("Processed SmartVoucherSoldEvent", context: message); }
public async Task ProcessSmartVoucherSoldEventAsync(SmartVoucherPaymentDto smartVoucherPayment) { var isValid = ValidateSmartVoucherPaymentOperation(smartVoucherPayment); if (!isValid) { return; } var(partnerName, vertical, campaignName) = await GetAdditionalDataForSmartVoucher( smartVoucherPayment.CampaignId, smartVoucherPayment.PartnerId); smartVoucherPayment.PartnerName = partnerName; smartVoucherPayment.Vertical = vertical; smartVoucherPayment.CampaignName = campaignName; await _smartVoucherRepository.AddPaymentAsync(smartVoucherPayment); }