public Task<DomainCustomer> AddAsync(DomainCustomerCreateOptions options)
        {
            return Task.Run(() =>
            {
                try
                {
                    StripeCustomerCreateOptions createOptions =
                        _mapper.Map<DomainCustomerCreateOptions, StripeCustomerCreateOptions>(options);

                    StripeCustomer customer = _service.Create(createOptions);
                    return Task.FromResult(_mapper.Map<StripeCustomer, DomainCustomer>(customer));
                }
                catch (StripeException e)
                {
                    throw new BillingException(string.Format("Failed to create customer {0}: {1}", options.Email, e));
                }
            });
        }
Beispiel #2
0
        public async Task<DomainCompany> AddAsync(DomainCompany company)
        {
            company.Created = DateTime.UtcNow;
            company.Email = company.Email.ToLowerInvariant();

            CompanyEntity entity = _mapper.Map<DomainCompany, CompanyEntity>(company);

            // Creating customer in billing system
            var customerCreateOptions = new DomainCustomerCreateOptions
            {
                Email = entity.Email
            };

            DomainCustomer customer;
            try
            {
                customer = await _billingCustomerService.AddAsync(customerCreateOptions);
            }
            catch (BillingException e)
            {
                throw new BadRequestException(string.Format("Failed to register customer {0}: {1}", entity.Email, e));
            }

            entity.BillingCustomerId = customer.Id;
            entity = await _companyRepository.AddAsync(entity);

            return _mapper.Map<CompanyEntity, DomainCompany>(entity);
        }