private static PaymentHistoryType ToPaymentHistoryType(AccountEventType type) { return(type switch { AccountEventType.None => PaymentHistoryType.None, AccountEventType.Add => PaymentHistoryType.Add, AccountEventType.Charge => PaymentHistoryType.Charge, AccountEventType.Authorize => PaymentHistoryType.Authorize, AccountEventType.Capture => PaymentHistoryType.Capture, AccountEventType.Void => PaymentHistoryType.Void, AccountEventType.Refund => PaymentHistoryType.Refund, _ => throw new ArgumentOutOfRangeException(nameof(type), type, null) });
public async Task Write <TEventData>(AccountEventType eventType, int accountId, decimal amount, ApiCaller apiCaller, TEventData eventData, string referenceCode) { var logEntry = new AccountBalanceAuditLogEntry { Created = _dateTimeProvider.UtcNow(), Type = eventType, AccountId = accountId, Amount = amount, UserId = apiCaller.Id, ApiCallerType = apiCaller.Type, EventData = JsonConvert.SerializeObject(eventData), ReferenceCode = referenceCode }; _context.AccountBalanceAuditLogs.Add(logEntry); await _context.SaveChangesAsync(); }
public AccountEvent CreateEvent() { AccountEventType type = new AccountEventType(); type.Name = "test type"; Country country = new Country(); country.Name = "USA"; State state = new State(); state.Country = country; state.Name = "NY"; City city = new City(); city.Country = country; city.State = state; city.Name = "New York"; Place place = new Place(); place.City = city; place.Name = "My Space"; AccountEvent evt = new AccountEvent(); evt.Description = "event description\r\nhttp://www.vestris.com/\r\nмолоко"; evt.AccountEventType = type; evt.Cost = "10$"; evt.Created = evt.Modified = DateTime.UtcNow; evt.Name = "milk - молоко"; evt.Phone = "(212) 123-1234"; evt.Place = place; evt.Website = GetNewUri(); evt.Email = "*****@*****.**"; return(evt); }
private static PaymentHistoryType ToPaymentHistoryType(AccountEventType type) { switch (type) { case AccountEventType.None: return(PaymentHistoryType.None); case AccountEventType.Add: return(PaymentHistoryType.Add); case AccountEventType.Charge: return(PaymentHistoryType.Charge); case AccountEventType.Authorize: return(PaymentHistoryType.Authorize); case AccountEventType.Capture: return(PaymentHistoryType.Capture); case AccountEventType.Void: return(PaymentHistoryType.Void); case AccountEventType.Refund: return(PaymentHistoryType.Refund); case AccountEventType.CounterpartyTransferToAgency: return(PaymentHistoryType.Add); default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } }
private async Task <AgencyAccount> WriteAuditLogWithReferenceCode(AgencyAccount account, ChargedMoneyData paymentData, AccountEventType eventType, UserInfo user) { var eventData = new AccountBalanceLogEventData(paymentData.Reason, account.Balance); await _auditService.Write(eventType, account.Id, paymentData.Amount, user, eventData, paymentData.ReferenceCode); return(account); }
private async Task <Result> IncreaseBalance(int agencyAccountId, PaymentData paymentData, ApiCaller apiCaller, AccountEventType eventType) { return(await GetAgencyAccount(agencyAccountId) .Ensure(a => AreCurrenciesMatch(a, paymentData), "Account and payment currency mismatch") .Ensure(IsReasonProvided, "Payment reason cannot be empty") .Ensure(IsAmountPositive, "Payment amount must be a positive number") .BindWithLock(_locker, a => Result.Success(a) .BindWithTransaction(_context, accounts => Result.Success(accounts) .Map(Increase) .Map(WriteAuditLog)))); bool IsReasonProvided(AgencyAccount _) => !string.IsNullOrEmpty(paymentData.Reason); bool IsAmountPositive(AgencyAccount _) => paymentData.Amount.IsGreaterThan(decimal.Zero); async Task <AgencyAccount> WriteAuditLog(AgencyAccount account) { var eventData = new AccountBalanceLogEventData(paymentData.Reason, account.Balance); await _accountBalanceAuditService.Write(eventType : eventType, accountId : account.Id, amount : paymentData.Amount, apiCaller : apiCaller, eventData : eventData, null); return(account); } async Task <AgencyAccount> Increase(AgencyAccount agencyAccount) { agencyAccount.Balance += paymentData.Amount; _context.Update(agencyAccount); await _context.SaveChangesAsync(); return(agencyAccount); } }