Example #1
0
        private async Task <Result <Company> > RegisterBillingAccount(Company company, DtoCreateCompanyRequest request)
        {
            string accountId;

            try
            {
                accountId = await billingManager.RegisterBillingAccount(company, new BillingAccountDetails
                {
                    IsBusinessAccount = request.BankAccountIsBusiness,
                    AccountNumber     = request.AccountNumber,
                    SortCode          = request.SortCode,
                    NameOnAccount     = request.NameOnAccount
                }).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                return(Result.Fail <Company>($"Error occurred creating account: {ex}"));
            }

            company.ExternalAccountId = accountId;

            return(await companies.UpdateCompany(new CompanyPatch
            {
                ResourceId = company.CompanyId,
                ExternalAccountId = new PatchOperation <string> {
                    Operation = OperationKind.Update, Value = accountId
                }
            })
                   .OnSuccess(() => company)
                   .ConfigureAwait(false));
        }