public async Task <Domain.Scheduling.Billing.Customer> CreateTrialCustomer(User user, SubscriptionPlan trialPlan) { var customerId = Guid.NewGuid(); var custCreateOpts = new Stripe.CustomerCreateOptions { Email = user.Email, Metadata = new Dictionary <string, string>(new[] { KeyValuePair.Create("Id", customerId.ToString()), KeyValuePair.Create("UserId", user.Id.ToString()), }) }; var customer = await customerService.CreateAsync(custCreateOpts); var price = trialPlan.Prices.Find(p => p.BillingReference.BillingId == config.DefaultPrice) !; var subId = Guid.NewGuid(); var subCreateOpts = new Stripe.SubscriptionCreateOptions { Customer = customer.Id, Items = new List <Stripe.SubscriptionItemOptions> { new Stripe.SubscriptionItemOptions { Price = price.BillingReference.BillingId } }, TrialPeriodDays = config.TrialPeriod, Metadata = new Dictionary <string, string>(new[] { KeyValuePair.Create("Id", subId.ToString()), KeyValuePair.Create("PlanId", trialPlan.Id.ToString()), KeyValuePair.Create("PriceBillingId", price.BillingReference.BillingId) }) }; var subscription = await subscriptionService.CreateAsync(subCreateOpts); return(new Domain.Scheduling.Billing.Customer( customerId, user.Id, BillingReference.Customer(customer.Id), new Domain.Scheduling.Billing.Subscription( subId, Domain.Scheduling.Billing.Subscription.ParseStatus(subscription.Status), new Domain.Scheduling.Billing.Period( subscription.TrialStart ?? throw new NullReferenceException(), subscription.TrialEnd ?? throw new NullReferenceException() ), new Domain.Scheduling.Billing.Period( subscription.CurrentPeriodStart, subscription.CurrentPeriodEnd ), subscription.CancelAtPeriodEnd, new SubscriptionPlanReference( trialPlan.Id, price.BillingReference.BillingId ), BillingReference.Subscription(subscription.Id) ) )); }
async public Task <string> CreateCustomer(Users user) { CustomerCreateOptions customerOpts = new CustomerCreateOptions { Email = user.Email }; Stripe.CustomerService customerService = new Stripe.CustomerService(); Stripe.Customer newCustomer = await customerService.CreateAsync(customerOpts); return(newCustomer.Id); }
public async Task <Customer> CreateCustomerAsync(string name, string email, string phone) { var options = new CustomerCreateOptions { Name = name, Email = email, Phone = phone }; var service = new Stripe.CustomerService(); return(await service.CreateAsync(options)); }
public async Task <IActionResult> getOrCreateCustomer() { PayModel paymodel = getPayModel(); var service = new CustomerService(); var listOptions = new CustomerListOptions { Limit = 1 }; listOptions.AddExtraParam("email", paymodel.Email); var customer = (await service.ListAsync(listOptions)).Data.FirstOrDefault(); if (customer != null) { return(Ok(customer)); } var options = new CustomerCreateOptions { Email = paymodel.Email, Phone = paymodel.Phone, Name = paymodel.Name, Address = new AddressOptions() { Line1 = paymodel.AddressLine1, Line2 = paymodel.AddressLine2, State = paymodel.AddressState, City = paymodel.AddressCity, Country = paymodel.AddressCountry, PostalCode = paymodel.AddressZip }, Metadata = new Dictionary <string, string>() { { "TrainingYears", "user.TrainingYears" }, { "GroupName", "user.GroupName" }, { "Level", "user.Level" } }, }; var result = await service.CreateAsync(options); var response = await Task.FromResult(result); return(Ok(response)); }
public async Task <IActionResult> CreateCustomerAsync() { PayModel paymodel = getPayModel(); var options = new CustomerCreateOptions { Source = this.Token().Id, Name = paymodel.Name, Email = paymodel.Email, Phone = paymodel.Phone }; var service = new CustomerService(); Stripe.Customer customer = await service.CreateAsync(options); var response = await Task.FromResult(customer); return(Ok(response)); }
private async Task <Customer> getOrCreateCustomer(string email) { var service = new Stripe.CustomerService(); var listOptions = new Stripe.CustomerListOptions { Limit = 1 }; listOptions.AddExtraParam("email", email); var customer = (await service.ListAsync(listOptions)).Data.FirstOrDefault(); if (customer != null) { return(customer); } var customerCreateOptions = new Stripe.CustomerCreateOptions { Email = email }; return(await service.CreateAsync(customerCreateOptions)); }