1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-22 12:15:36 +01:00

stripe subscription creation

This commit is contained in:
Kyle Spearrin 2017-04-04 10:13:16 -04:00
parent 5187f4c15f
commit a4ef7c906e
10 changed files with 29 additions and 11 deletions

View File

@ -33,6 +33,7 @@ using Bit.Api.IdentityServer;
using Bit.Core.Enums;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.WindowsAzure.Storage;
using Stripe;
namespace Bit.Api
{
@ -83,6 +84,9 @@ namespace Bit.Api
.ProtectKeysWithCertificate(dataProtectionCert);
}
// Stripe Billing
StripeConfiguration.SetApiKey(globalSettings.StripeApiKey);
// Repositories
services.AddSingleton<IUserRepository, SqlServerRepos.UserRepository>();
services.AddSingleton<ICipherRepository, SqlServerRepos.CipherRepository>();

View File

@ -3,6 +3,7 @@
"siteName": "bitwarden",
"baseVaultUri": "http://localhost:4001/#",
"jwtSigningKey": "THIS IS A SECRET. IT KEEPS YOUR TOKEN SAFE. :)",
"stripeApiKey": "SECRET",
"sqlServer": {
"connectionString": "SECRET"
},

View File

@ -22,6 +22,7 @@
<PackageReference Include="Newtonsoft.Json" Version="10.0.1" />
<PackageReference Include="Sendgrid" Version="9.0.12" />
<PackageReference Include="PushSharp" Version="4.0.10" />
<PackageReference Include="Stripe.net" Version="7.7.0" />
<PackageReference Include="WindowsAzure.Storage" Version="8.1.1" />
<PackageReference Include="Otp.NET" Version="1.0.1" />
</ItemGroup>

View File

@ -3,7 +3,7 @@
public enum PlanType : byte
{
Free = 0,
Family = 1,
Personal = 1,
Teams = 2,
Enterprise = 3,
Custom = 4

View File

@ -5,6 +5,7 @@
public virtual string SiteName { get; set; }
public virtual string BaseVaultUri { get; set; }
public virtual string JwtSigningKey { get; set; }
public virtual string StripeApiKey { get; set; }
public virtual SqlServerSettings SqlServer { get; set; } = new SqlServerSettings();
public virtual MailSettings Mail { get; set; } = new MailSettings();
public virtual PushSettings Push { get; set; } = new PushSettings();

View File

@ -10,6 +10,7 @@ namespace Bit.Core.Models.Api
public string Name { get; set; }
public PlanType PlanType { get; set; }
public string Key { get; set; }
public string CardToken { get; set; }
public virtual OrganizationSignup ToOrganizationSignup(User user)
{
@ -18,7 +19,8 @@ namespace Bit.Core.Models.Api
Owner = user,
OwnerKey = Key,
Name = Name,
Plan = PlanType
Plan = PlanType,
PaymentToken = CardToken
};
}
}

View File

@ -9,12 +9,6 @@ namespace Bit.Core.Models.Business
public User Owner { get; set; }
public string OwnerKey { get; set; }
public Enums.PlanType Plan { get; set; }
public PaymentDetails Payment { get; set; }
public class PaymentDetails
{
public string Name { get; set; }
public string Token { get; set; }
}
public string PaymentToken { get; set; }
}
}

View File

@ -5,6 +5,8 @@ namespace Bit.Core.Models.StaticStore
{
public class Plan
{
public string Name { get; set; }
public string StripeId { get; set; }
public PlanType Type { get; set; }
public short MaxUsers { get; set; }
public decimal Price { get; set; }

View File

@ -8,6 +8,7 @@ using Bit.Core.Utilities;
using Bit.Core.Exceptions;
using System.Collections.Generic;
using Microsoft.AspNetCore.DataProtection;
using Stripe;
namespace Bit.Core.Services
{
@ -47,6 +48,15 @@ namespace Bit.Core.Services
throw new BadRequestException("Plan not found.");
}
var customerService = new StripeCustomerService();
var customer = await customerService.CreateAsync(new StripeCustomerCreateOptions
{
SourceToken = signup.PaymentToken
});
var subscriptionService = new StripeSubscriptionService();
var subscription = await subscriptionService.CreateAsync(customer.Id, plan.StripeId);
var organization = new Organization
{
Name = signup.Name,

View File

@ -99,11 +99,14 @@ namespace Bit.Core.Utilities
},
new Plan
{
Type = PlanType.Family,
Type = PlanType.Personal,
MaxUsers = 5,
Price = 1,
Trial = new TimeSpan(14, 0, 0, 0),
Cycle = now => now.AddYears(1) - now
Cycle = now => now.AddYears(1) - now,
Name = "Personal",
StripeId = "premium-yearly"
},
new Plan
{