1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-06 21:48:12 -05:00

update stripe sdk

This commit is contained in:
Kyle Spearrin 2018-09-13 10:28:51 -04:00
parent 07855a3203
commit 8fde736e98
3 changed files with 15 additions and 8 deletions

View File

@ -37,7 +37,7 @@
<PackageReference Include="Braintree" Version="4.5.0" /> <PackageReference Include="Braintree" Version="4.5.0" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.2" /> <PackageReference Include="Portable.BouncyCastle" Version="1.8.2" />
<PackageReference Include="Sendgrid" Version="9.9.0" /> <PackageReference Include="Sendgrid" Version="9.9.0" />
<PackageReference Include="Stripe.net" Version="17.8.0" /> <PackageReference Include="Stripe.net" Version="19.6.0" />
<PackageReference Include="U2F.Core" Version="1.0.4" /> <PackageReference Include="U2F.Core" Version="1.0.4" />
<PackageReference Include="Otp.NET" Version="1.2.0" /> <PackageReference Include="Otp.NET" Version="1.2.0" />
<PackageReference Include="YubicoDotNetClient" Version="1.2.0" /> <PackageReference Include="YubicoDotNetClient" Version="1.2.0" />

View File

@ -185,6 +185,7 @@ namespace Bit.Core.Services
// They must have been on a free plan. Create new sub. // They must have been on a free plan. Create new sub.
var subCreateOptions = new StripeSubscriptionCreateOptions var subCreateOptions = new StripeSubscriptionCreateOptions
{ {
CustomerId = organization.GatewayCustomerId,
TrialPeriodDays = newPlan.TrialPeriodDays, TrialPeriodDays = newPlan.TrialPeriodDays,
Items = new List<StripeSubscriptionItemOption>(), Items = new List<StripeSubscriptionItemOption>(),
Metadata = new Dictionary<string, string> { Metadata = new Dictionary<string, string> {
@ -210,7 +211,7 @@ namespace Bit.Core.Services
}); });
} }
await subscriptionService.CreateAsync(organization.GatewayCustomerId, subCreateOptions); await subscriptionService.CreateAsync(subCreateOptions);
} }
else else
{ {
@ -468,6 +469,7 @@ namespace Bit.Core.Services
var subCreateOptions = new StripeSubscriptionCreateOptions var subCreateOptions = new StripeSubscriptionCreateOptions
{ {
CustomerId = customer.Id,
TrialPeriodDays = plan.TrialPeriodDays, TrialPeriodDays = plan.TrialPeriodDays,
Items = new List<StripeSubscriptionItemOption>(), Items = new List<StripeSubscriptionItemOption>(),
Metadata = new Dictionary<string, string> { Metadata = new Dictionary<string, string> {
@ -504,7 +506,7 @@ namespace Bit.Core.Services
try try
{ {
subscription = await subscriptionService.CreateAsync(customer.Id, subCreateOptions); subscription = await subscriptionService.CreateAsync(subCreateOptions);
} }
catch(StripeException) catch(StripeException)
{ {

View File

@ -26,6 +26,7 @@ namespace Bit.Core.Services
var subCreateOptions = new StripeSubscriptionCreateOptions var subCreateOptions = new StripeSubscriptionCreateOptions
{ {
CustomerId = customer.Id,
Items = new List<StripeSubscriptionItemOption>(), Items = new List<StripeSubscriptionItemOption>(),
Metadata = new Dictionary<string, string> Metadata = new Dictionary<string, string>
{ {
@ -52,7 +53,7 @@ namespace Bit.Core.Services
try try
{ {
var subscriptionService = new StripeSubscriptionService(); var subscriptionService = new StripeSubscriptionService();
subscription = await subscriptionService.CreateAsync(customer.Id, subCreateOptions); subscription = await subscriptionService.CreateAsync(subCreateOptions);
} }
catch(StripeException) catch(StripeException)
{ {
@ -114,7 +115,8 @@ namespace Bit.Core.Services
if(!string.IsNullOrWhiteSpace(subscriber.GatewaySubscriptionId)) if(!string.IsNullOrWhiteSpace(subscriber.GatewaySubscriptionId))
{ {
var subscriptionService = new StripeSubscriptionService(); var subscriptionService = new StripeSubscriptionService();
await subscriptionService.CancelAsync(subscriber.GatewaySubscriptionId, false); await subscriptionService.CancelAsync(subscriber.GatewaySubscriptionId,
new StripeSubscriptionCancelOptions());
} }
if(string.IsNullOrWhiteSpace(subscriber.GatewayCustomerId)) if(string.IsNullOrWhiteSpace(subscriber.GatewayCustomerId))
@ -158,7 +160,7 @@ namespace Bit.Core.Services
try try
{ {
// Owes more than prorateThreshold on next invoice. // Owes more than prorateThreshold on next invoice.
// Invoice them and pay now instead of waiting until next month. // Invoice them and pay now instead of waiting until next billing cycle.
var invoice = await invoiceService.CreateAsync(subscriber.GatewayCustomerId, var invoice = await invoiceService.CreateAsync(subscriber.GatewayCustomerId,
new StripeInvoiceCreateOptions new StripeInvoiceCreateOptions
{ {
@ -167,7 +169,7 @@ namespace Bit.Core.Services
if(invoice.AmountDue > 0) if(invoice.AmountDue > 0)
{ {
await invoiceService.PayAsync(invoice.Id); await invoiceService.PayAsync(invoice.Id, new StripeInvoicePayOptions());
} }
} }
catch(StripeException) { } catch(StripeException) { }
@ -201,7 +203,10 @@ namespace Bit.Core.Services
try try
{ {
var canceledSub = await subscriptionService.CancelAsync(sub.Id, endOfPeriod); var canceledSub = endOfPeriod ?
await subscriptionService.UpdateAsync(sub.Id,
new StripeSubscriptionUpdateOptions { CancelAtPeriodEnd = true }) :
await subscriptionService.CancelAsync(sub.Id, new StripeSubscriptionCancelOptions());
if(!canceledSub.CanceledAt.HasValue) if(!canceledSub.CanceledAt.HasValue)
{ {
throw new GatewayException("Unable to cancel subscription."); throw new GatewayException("Unable to cancel subscription.");