1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 23:52:50 -05:00

billing updater program

This commit is contained in:
Kyle Spearrin
2017-09-08 11:43:47 -04:00
parent 9e03124b9b
commit 6573bf44ab
3 changed files with 74 additions and 1 deletions

View 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>

View 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 });
}
}
}
}
}
}