public void CreateAccount_Success() { var customer = _customerTests.RegisterCustomer_Success( Constants.Country.GreekCountryCode); Assert.NotNull(customer); var accountOptions = new CreateAccountOptions() { CurrencyCode = Constants.CurrencyCode.Euro, Description = "My test account" }; var accountResult = _accounts.Create( customer.CustomerId, accountOptions); Assert.True(accountResult.IsSuccessful()); var account = accountResult.Data; Assert.StartsWith(customer.CountryCode, account.AccountId); Assert.Equal(customer.CustomerId, account.CustomerId); Assert.Equal(0M, account.Balance); Assert.Equal(Constants.AccountState.Active, account.State); }
public async Task <Account> CreateAsync(CreateAccount create, Action <CreateAccountOptions>?setOpts = null) { var balance = AccountBalance.Zero(create.Currency); var acc = new Account(create.Id, balance, true); try { await _repo.CreateAsync(acc); return(acc); } catch (AccountUniqException) { var options = new CreateAccountOptions(); setOpts?.Invoke(options); if (!options.IngoreOnDuplicate) { var info = new Dictionary <string, string>() { ["Id"] = create.Id.ToString() }; throw new WPayException(AccountErrors.AlreadyExist, info); } return(acc); } }
public void CreateAccountOnExistingCustomer_Success() { var resultCustomer = _customer.GetById(Guid.Parse("5294743F-2622-40F3-B662-31319F3BC041")); Assert.Equal(Constants.ApiResultCode.Success, resultCustomer.Code); var customer = resultCustomer.Data; var accountOptions = new CreateAccountOptions() { CurrencyCode = Constants.CurrencyCode.Euro, Description = "My test account" }; var accountResult = _accounts.Create( customer.CustomerId, accountOptions); Assert.True(accountResult.IsSuccessful()); var account = accountResult.Data; Assert.StartsWith(customer.CountryCode, account.AccountId); Assert.Equal(customer.CustomerId, account.CustomerId); Assert.Equal(0M, account.Balance); Assert.Equal(Constants.AccountState.Active, account.State); }
public Account CreateNewAccountOnCustomer() { //my customer Guid customerId = Guid.Parse("0c4e8659-8573-4df2-b804-811376553a86"); var customerResult = _customers.GetById(customerId); var customer = customerResult?.Data; Assert.NotNull(customer); var accountOptions = new CreateAccountOptions() { CurrencyCode = Constants.CurrencyCode.Euro, Description = "SavingAccount", Balance = 10000 }; var accountResult = _accounts.Create( customer.CustomerId, accountOptions); Assert.True(accountResult.IsSuccessful()); var account = accountResult.Data; Assert.StartsWith(customer.CountryCode, account.AccountId); Assert.Equal(customer.CustomerId, account.CustomerId); //Assert.Equal(0M, account.Balance); Assert.Equal(Constants.AccountState.Active, account.State); return(account); }
public static async Task <AccountResource> CreateAccountAsync(ITwilioRestClient client, string friendlyName) { var options = new CreateAccountOptions() { FriendlyName = friendlyName }; return(await AccountResource.CreateAsync(options, client)); }
public ApiResult <Account> Create(Guid customerId, CreateAccountOptions options) { if (options == null) { return(ApiResult <Account> .CreateFailed( Constants.ApiResultCode.BadRequest, $"Null {nameof(options)}")); } if (string.IsNullOrWhiteSpace(options.CurrencyCode) || !options.CurrencyCode.Equals( Constants.CurrencyCode.Euro, StringComparison.OrdinalIgnoreCase)) { return(ApiResult <Account> .CreateFailed( Constants.ApiResultCode.BadRequest, $"Invalid or unsupported currency {options.CurrencyCode}")); } var customerResult = _customers.GetById(customerId); if (!customerResult.IsSuccessful()) { return(customerResult.ToResult <Account>()); } var customer = customerResult.Data; var account = new Account() { AccountId = CreateAccountId(customer.CountryCode), Balance = 0M, CurrencyCode = options.CurrencyCode, Customer = customer, State = Constants.AccountState.Active, Description = options.Description }; _dbContext.Add(account); try { _dbContext.SaveChanges(); } catch (Exception) { return(ApiResult <Account> .CreateFailed( Constants.ApiResultCode.InternalServerError, "Could not save account")); } return(ApiResult <Account> .CreateSuccessful(account)); }
public ApiResult <Card> Create(Guid customerId, CreateAccountOptions options) { throw new NotImplementedException(); }
public async Task <Result <Account> > CreateAccountAsync(CreateAccountOptions options) { if (string.IsNullOrWhiteSpace(options.AccountId)) { //turn null; return(new Result <Account>() { ErrorMessage = "AccountId is required", Code = Constants.ResultCode.BadRequest }); } if (options.CustomerId == 0) { return(new Result <Account>() { ErrorMessage = "Customer is required", Code = Constants.ResultCode.BadRequest }); } var opt = new FindCustomerOptions() { CustomerId = options.CustomerId }; var q = new CustomerService(_dbContext).FindCustomerAsync(opt).Result.Data; //var q = _customers.FindCustomer(opt); if (q == null) { return(new Result <Account>() { ErrorMessage = "Customer is not registered", Code = Constants.ResultCode.NotFound }); } var account = new Account() { AccountId = options.AccountId, CustomerId = options.CustomerId }; _dbContext.Add(account); try { await _dbContext.SaveChangesAsync(); } catch (Exception) { return(new Result <Account>() { Code = Constants.ResultCode.InternalServerError, ErrorMessage = "Account could not be saved" }); } return(new Result <Account>() { Code = Constants.ResultCode.Success, Data = account }); }