mirror of
https://github.com/bitwarden/server.git
synced 2024-11-28 13:15:12 +01:00
billing updater program
This commit is contained in:
parent
9e03124b9b
commit
6573bf44ab
@ -1,7 +1,7 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26730.3
|
||||
VisualStudioVersion = 15.0.26730.12
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{DD5BD056-4AAE-43EF-BBD2-0B569B8DA84D}"
|
||||
EndProject
|
||||
@ -41,6 +41,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jobs", "src\Jobs\Jobs.cspro
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapper", "..\Dapper\Dapper\Dapper.csproj", "{6951E73D-1761-41F6-B5D3-BEF4C2F73EA3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BillingUpdater", "util\BillingUpdater\BillingUpdater.csproj", "{A0FBA4DF-2F24-45A6-B188-EBDBD2FAF445}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -89,6 +91,10 @@ Global
|
||||
{6951E73D-1761-41F6-B5D3-BEF4C2F73EA3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6951E73D-1761-41F6-B5D3-BEF4C2F73EA3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6951E73D-1761-41F6-B5D3-BEF4C2F73EA3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A0FBA4DF-2F24-45A6-B188-EBDBD2FAF445}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A0FBA4DF-2F24-45A6-B188-EBDBD2FAF445}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A0FBA4DF-2F24-45A6-B188-EBDBD2FAF445}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A0FBA4DF-2F24-45A6-B188-EBDBD2FAF445}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -104,6 +110,7 @@ Global
|
||||
{66B0A682-658A-4A82-B606-A077A4871448} = {DD5BD056-4AAE-43EF-BBD2-0B569B8DA84E}
|
||||
{7DCEBD8F-E5F3-4A3C-BD35-B64341590B74} = {DD5BD056-4AAE-43EF-BBD2-0B569B8DA84D}
|
||||
{6951E73D-1761-41F6-B5D3-BEF4C2F73EA3} = {DD5BD056-4AAE-43EF-BBD2-0B569B8DA84D}
|
||||
{A0FBA4DF-2F24-45A6-B188-EBDBD2FAF445} = {DD5BD056-4AAE-43EF-BBD2-0B569B8DA84E}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {E01CBF68-2E20-425F-9EDB-E0A6510CA92F}
|
||||
|
13
util/BillingUpdater/BillingUpdater.csproj
Normal file
13
util/BillingUpdater/BillingUpdater.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<RootNamespace>Bit.BillingUpdater</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Core\Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
53
util/BillingUpdater/Program.cs
Normal file
53
util/BillingUpdater/Program.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Data.SqlClient;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core.Models.Table;
|
||||
using Dapper;
|
||||
using Stripe;
|
||||
|
||||
namespace Bit.BillingUpdater
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
MainAsync().Wait();
|
||||
}
|
||||
|
||||
public async static Task MainAsync()
|
||||
{
|
||||
var connectionString = "";
|
||||
var stripeApiKey = "";
|
||||
var stripeSubscriptionService = new StripeSubscriptionService(stripeApiKey);
|
||||
|
||||
using(var connection = new SqlConnection(connectionString))
|
||||
{
|
||||
//Paid orgs
|
||||
|
||||
var orgs = await connection.QueryAsync<Organization>(
|
||||
"SELECT * FROM [Organization] WHERE [Enabled] = 1 AND AND GatewaySubscriptionId IS NOT NULL");
|
||||
|
||||
foreach(var org in orgs)
|
||||
{
|
||||
DateTime? expDate = null;
|
||||
if(org.Gateway == Core.Enums.GatewayType.Stripe)
|
||||
{
|
||||
var sub = await stripeSubscriptionService.GetAsync(org.GatewaySubscriptionId);
|
||||
if(sub != null)
|
||||
{
|
||||
expDate = sub.CurrentPeriodEnd;
|
||||
}
|
||||
}
|
||||
|
||||
if(expDate.HasValue)
|
||||
{
|
||||
Console.WriteLine("Updating org {0} exp to {1}.", org.Id, expDate.Value);
|
||||
await connection.ExecuteAsync(
|
||||
"UPDATE [Organization] SET [ExpirationDate] = @Date WHERE [Id] = @Id",
|
||||
new { Date = expDate, Id = org.Id });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user