mirror of
https://github.com/bitwarden/server.git
synced 2024-11-25 12:45:18 +01:00
stripe subscription creation
This commit is contained in:
parent
5187f4c15f
commit
a4ef7c906e
@ -33,6 +33,7 @@ using Bit.Api.IdentityServer;
|
|||||||
using Bit.Core.Enums;
|
using Bit.Core.Enums;
|
||||||
using Microsoft.AspNetCore.DataProtection;
|
using Microsoft.AspNetCore.DataProtection;
|
||||||
using Microsoft.WindowsAzure.Storage;
|
using Microsoft.WindowsAzure.Storage;
|
||||||
|
using Stripe;
|
||||||
|
|
||||||
namespace Bit.Api
|
namespace Bit.Api
|
||||||
{
|
{
|
||||||
@ -83,6 +84,9 @@ namespace Bit.Api
|
|||||||
.ProtectKeysWithCertificate(dataProtectionCert);
|
.ProtectKeysWithCertificate(dataProtectionCert);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stripe Billing
|
||||||
|
StripeConfiguration.SetApiKey(globalSettings.StripeApiKey);
|
||||||
|
|
||||||
// Repositories
|
// Repositories
|
||||||
services.AddSingleton<IUserRepository, SqlServerRepos.UserRepository>();
|
services.AddSingleton<IUserRepository, SqlServerRepos.UserRepository>();
|
||||||
services.AddSingleton<ICipherRepository, SqlServerRepos.CipherRepository>();
|
services.AddSingleton<ICipherRepository, SqlServerRepos.CipherRepository>();
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
"siteName": "bitwarden",
|
"siteName": "bitwarden",
|
||||||
"baseVaultUri": "http://localhost:4001/#",
|
"baseVaultUri": "http://localhost:4001/#",
|
||||||
"jwtSigningKey": "THIS IS A SECRET. IT KEEPS YOUR TOKEN SAFE. :)",
|
"jwtSigningKey": "THIS IS A SECRET. IT KEEPS YOUR TOKEN SAFE. :)",
|
||||||
|
"stripeApiKey": "SECRET",
|
||||||
"sqlServer": {
|
"sqlServer": {
|
||||||
"connectionString": "SECRET"
|
"connectionString": "SECRET"
|
||||||
},
|
},
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.1" />
|
<PackageReference Include="Newtonsoft.Json" Version="10.0.1" />
|
||||||
<PackageReference Include="Sendgrid" Version="9.0.12" />
|
<PackageReference Include="Sendgrid" Version="9.0.12" />
|
||||||
<PackageReference Include="PushSharp" Version="4.0.10" />
|
<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="WindowsAzure.Storage" Version="8.1.1" />
|
||||||
<PackageReference Include="Otp.NET" Version="1.0.1" />
|
<PackageReference Include="Otp.NET" Version="1.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
public enum PlanType : byte
|
public enum PlanType : byte
|
||||||
{
|
{
|
||||||
Free = 0,
|
Free = 0,
|
||||||
Family = 1,
|
Personal = 1,
|
||||||
Teams = 2,
|
Teams = 2,
|
||||||
Enterprise = 3,
|
Enterprise = 3,
|
||||||
Custom = 4
|
Custom = 4
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
public virtual string SiteName { get; set; }
|
public virtual string SiteName { get; set; }
|
||||||
public virtual string BaseVaultUri { get; set; }
|
public virtual string BaseVaultUri { get; set; }
|
||||||
public virtual string JwtSigningKey { get; set; }
|
public virtual string JwtSigningKey { get; set; }
|
||||||
|
public virtual string StripeApiKey { get; set; }
|
||||||
public virtual SqlServerSettings SqlServer { get; set; } = new SqlServerSettings();
|
public virtual SqlServerSettings SqlServer { get; set; } = new SqlServerSettings();
|
||||||
public virtual MailSettings Mail { get; set; } = new MailSettings();
|
public virtual MailSettings Mail { get; set; } = new MailSettings();
|
||||||
public virtual PushSettings Push { get; set; } = new PushSettings();
|
public virtual PushSettings Push { get; set; } = new PushSettings();
|
||||||
|
@ -10,6 +10,7 @@ namespace Bit.Core.Models.Api
|
|||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public PlanType PlanType { get; set; }
|
public PlanType PlanType { get; set; }
|
||||||
public string Key { get; set; }
|
public string Key { get; set; }
|
||||||
|
public string CardToken { get; set; }
|
||||||
|
|
||||||
public virtual OrganizationSignup ToOrganizationSignup(User user)
|
public virtual OrganizationSignup ToOrganizationSignup(User user)
|
||||||
{
|
{
|
||||||
@ -18,7 +19,8 @@ namespace Bit.Core.Models.Api
|
|||||||
Owner = user,
|
Owner = user,
|
||||||
OwnerKey = Key,
|
OwnerKey = Key,
|
||||||
Name = Name,
|
Name = Name,
|
||||||
Plan = PlanType
|
Plan = PlanType,
|
||||||
|
PaymentToken = CardToken
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,6 @@ namespace Bit.Core.Models.Business
|
|||||||
public User Owner { get; set; }
|
public User Owner { get; set; }
|
||||||
public string OwnerKey { get; set; }
|
public string OwnerKey { get; set; }
|
||||||
public Enums.PlanType Plan { get; set; }
|
public Enums.PlanType Plan { get; set; }
|
||||||
public PaymentDetails Payment { get; set; }
|
public string PaymentToken { get; set; }
|
||||||
|
|
||||||
public class PaymentDetails
|
|
||||||
{
|
|
||||||
public string Name { get; set; }
|
|
||||||
public string Token { get; set; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ namespace Bit.Core.Models.StaticStore
|
|||||||
{
|
{
|
||||||
public class Plan
|
public class Plan
|
||||||
{
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string StripeId { get; set; }
|
||||||
public PlanType Type { get; set; }
|
public PlanType Type { get; set; }
|
||||||
public short MaxUsers { get; set; }
|
public short MaxUsers { get; set; }
|
||||||
public decimal Price { get; set; }
|
public decimal Price { get; set; }
|
||||||
|
@ -8,6 +8,7 @@ using Bit.Core.Utilities;
|
|||||||
using Bit.Core.Exceptions;
|
using Bit.Core.Exceptions;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.DataProtection;
|
using Microsoft.AspNetCore.DataProtection;
|
||||||
|
using Stripe;
|
||||||
|
|
||||||
namespace Bit.Core.Services
|
namespace Bit.Core.Services
|
||||||
{
|
{
|
||||||
@ -47,6 +48,15 @@ namespace Bit.Core.Services
|
|||||||
throw new BadRequestException("Plan not found.");
|
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
|
var organization = new Organization
|
||||||
{
|
{
|
||||||
Name = signup.Name,
|
Name = signup.Name,
|
||||||
|
@ -99,11 +99,14 @@ namespace Bit.Core.Utilities
|
|||||||
},
|
},
|
||||||
new Plan
|
new Plan
|
||||||
{
|
{
|
||||||
Type = PlanType.Family,
|
Type = PlanType.Personal,
|
||||||
MaxUsers = 5,
|
MaxUsers = 5,
|
||||||
Price = 1,
|
Price = 1,
|
||||||
Trial = new TimeSpan(14, 0, 0, 0),
|
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
|
new Plan
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user