diff --git a/src/Admin/Startup.cs b/src/Admin/Startup.cs index e77d65195e..6ce698fc48 100644 --- a/src/Admin/Startup.cs +++ b/src/Admin/Startup.cs @@ -38,7 +38,7 @@ namespace Bit.Admin services.AddCustomDataProtectionServices(Environment, globalSettings); // Stripe Billing - StripeConfiguration.SetApiKey(globalSettings.StripeApiKey); + StripeConfiguration.ApiKey = globalSettings.StripeApiKey; // Repositories services.AddSqlServerRepositories(globalSettings); diff --git a/src/Api/Startup.cs b/src/Api/Startup.cs index 7529b26acf..7b4f0ee81d 100644 --- a/src/Api/Startup.cs +++ b/src/Api/Startup.cs @@ -47,7 +47,7 @@ namespace Bit.Api services.AddCustomDataProtectionServices(Environment, globalSettings); // Stripe Billing - StripeConfiguration.SetApiKey(globalSettings.StripeApiKey); + StripeConfiguration.ApiKey = globalSettings.StripeApiKey; // Repositories services.AddSqlServerRepositories(globalSettings); diff --git a/src/Billing/Controllers/StripeController.cs b/src/Billing/Controllers/StripeController.cs index 9d396e0c62..279ae41565 100644 --- a/src/Billing/Controllers/StripeController.cs +++ b/src/Billing/Controllers/StripeController.cs @@ -506,7 +506,7 @@ namespace Bit.Billing.Controllers private bool UnpaidAutoChargeInvoiceForSubscriptionCycle(Invoice invoice) { - return invoice.AmountDue > 0 && !invoice.Paid && invoice.Billing == Stripe.Billing.ChargeAutomatically && + return invoice.AmountDue > 0 && !invoice.Paid && invoice.CollectionMethod == "charge_automatically" && invoice.BillingReason == "subscription_cycle" && invoice.SubscriptionId != null; } } diff --git a/src/Billing/Startup.cs b/src/Billing/Startup.cs index 19f634d529..839c596dc0 100644 --- a/src/Billing/Startup.cs +++ b/src/Billing/Startup.cs @@ -33,7 +33,7 @@ namespace Bit.Billing services.Configure(Configuration.GetSection("BillingSettings")); // Stripe Billing - StripeConfiguration.SetApiKey(globalSettings.StripeApiKey); + StripeConfiguration.ApiKey = globalSettings.StripeApiKey; // Repositories services.AddSqlServerRepositories(globalSettings); diff --git a/src/Core/Core.csproj b/src/Core/Core.csproj index ddb545e0bc..f54c894dae 100644 --- a/src/Core/Core.csproj +++ b/src/Core/Core.csproj @@ -52,7 +52,7 @@ - + diff --git a/src/Core/Models/Business/BillingInfo.cs b/src/Core/Models/Business/BillingInfo.cs index efed944d0b..233defe446 100644 --- a/src/Core/Models/Business/BillingInfo.cs +++ b/src/Core/Models/Business/BillingInfo.cs @@ -124,13 +124,12 @@ namespace Bit.Core.Models.Business public BillingInvoice(Invoice inv) { Amount = inv.AmountDue / 100M; - Date = inv.Date.Value; + Date = inv.Created; Url = inv.HostedInvoiceUrl; PdfUrl = inv.InvoicePdf; Number = inv.Number; Paid = inv.Paid; Amount = inv.Total / 100M; - Date = inv.Date.Value; } public decimal Amount { get; set; } diff --git a/src/Core/Models/Business/SubscriptionInfo.cs b/src/Core/Models/Business/SubscriptionInfo.cs index b329d504b7..3f82d919fc 100644 --- a/src/Core/Models/Business/SubscriptionInfo.cs +++ b/src/Core/Models/Business/SubscriptionInfo.cs @@ -123,7 +123,7 @@ namespace Bit.Core.Models.Business public BillingUpcomingInvoice(Invoice inv) { Amount = inv.AmountDue / 100M; - Date = inv.Date.Value; + Date = inv.Created; } public BillingUpcomingInvoice(Braintree.Subscription sub) diff --git a/src/Core/Services/Implementations/StripePaymentService.cs b/src/Core/Services/Implementations/StripePaymentService.cs index 96e45822da..ac3c311e47 100644 --- a/src/Core/Services/Implementations/StripePaymentService.cs +++ b/src/Core/Services/Implementations/StripePaymentService.cs @@ -136,7 +136,7 @@ namespace Bit.Core.Services { Description = org.BusinessName, Email = org.BillingEmail, - SourceToken = stipeCustomerSourceToken, + Source = stipeCustomerSourceToken, Metadata = stripeCustomerMetadata }); subCreateOptions.CustomerId = customer.Id; @@ -171,8 +171,9 @@ namespace Bit.Core.Services } var customerService = new CustomerService(); - customerService.ExpandDefaultSource = true; - var customer = await customerService.GetAsync(org.GatewayCustomerId); + var customerOptions = new CustomerGetOptions(); + customerOptions.AddExpand("default_source"); + var customer = await customerService.GetAsync(org.GatewayCustomerId, customerOptions); if(customer == null) { throw new GatewayException("Could not find customer payment profile."); @@ -332,7 +333,7 @@ namespace Bit.Core.Services { Description = user.Name, Email = user.Email, - SourceToken = stipeCustomerSourceToken, + Source = stipeCustomerSourceToken, Metadata = stripeCustomerMetadata }); createdStripeCustomer = true; @@ -437,7 +438,7 @@ namespace Bit.Core.Services await customerService.UpdateAsync(customer.Id, new CustomerUpdateOptions { - AccountBalance = customer.AccountBalance - previewInvoice.AmountDue + Balance = customer.Balance - previewInvoice.AmountDue }); addedCreditToStripeCustomer = true; } @@ -492,11 +493,11 @@ namespace Bit.Core.Services { await customerService.DeleteAsync(customer.Id); } - else if(addedCreditToStripeCustomer || customer.AccountBalance < 0) + else if(addedCreditToStripeCustomer || customer.Balance < 0) { await customerService.UpdateAsync(customer.Id, new CustomerUpdateOptions { - AccountBalance = customer.AccountBalance + Balance = customer.Balance }); } } @@ -690,8 +691,9 @@ namespace Bit.Core.Services // Invoice them and pay now instead of waiting until next billing cycle. var customerService = new CustomerService(); - customerService.ExpandDefaultSource = true; - var customer = await customerService.GetAsync(subscriber.GatewayCustomerId); + var customerOptions = new CustomerGetOptions(); + customerOptions.AddExpand("default_source"); + var customer = await customerService.GetAsync(subscriber.GatewayCustomerId, customerOptions); var invoiceAmountDue = upcomingPreview.StartingBalance + invoiceAmount; if(invoiceAmountDue > 0 && !customer.Metadata.ContainsKey("btCustomerId")) @@ -728,7 +730,7 @@ namespace Bit.Core.Services invoice = await invoiceService.CreateAsync(new InvoiceCreateOptions { - Billing = Billing.SendInvoice, + CollectionMethod = "send_invoice", DaysUntilDue = 1, CustomerId = subscriber.GatewayCustomerId, SubscriptionId = subscriber.GatewaySubscriptionId @@ -800,7 +802,7 @@ namespace Bit.Core.Services { await customerService.UpdateAsync(customer.Id, new CustomerUpdateOptions { - AccountBalance = customer.AccountBalance + Balance = customer.Balance }); } @@ -1041,7 +1043,7 @@ namespace Bit.Core.Services { Description = subscriber.BillingName(), Email = subscriber.BillingEmailAddress(), - SourceToken = stipeCustomerSourceToken, + Source = stipeCustomerSourceToken, Metadata = stripeCustomerMetadata }); @@ -1059,7 +1061,7 @@ namespace Bit.Core.Services { var bankAccount = await bankSerice.CreateAsync(customer.Id, new BankAccountCreateOptions { - SourceToken = paymentToken + Source = paymentToken }); defaultSourceId = bankAccount.Id; } @@ -1067,7 +1069,7 @@ namespace Bit.Core.Services { var card = await cardService.CreateAsync(customer.Id, new CardCreateOptions { - SourceToken = paymentToken, + Source = paymentToken, }); defaultSourceId = card.Id; } @@ -1126,7 +1128,7 @@ namespace Bit.Core.Services } await customerService.UpdateAsync(customer.Id, new CustomerUpdateOptions { - AccountBalance = customer.AccountBalance - (long)(creditAmount * 100) + Balance = customer.Balance - (long)(creditAmount * 100) }); return !customerExists; } @@ -1165,7 +1167,7 @@ namespace Bit.Core.Services catch(StripeException) { } if(customer != null) { - billingInfo.Balance = customer.AccountBalance / 100M; + billingInfo.Balance = customer.Balance / 100M; if(customer.Metadata?.ContainsKey("btCustomerId") ?? false) { @@ -1200,7 +1202,7 @@ namespace Bit.Core.Services Limit = 50 }); billingInfo.Invoices = invoices.Data.Where(i => i.Status != "void" && i.Status != "draft") - .OrderByDescending(i => i.Date).Select(i => new BillingInfo.BillingInvoice(i)); + .OrderByDescending(i => i.Created).Select(i => new BillingInfo.BillingInvoice(i)); } } diff --git a/src/Icons/Services/IconFetchingService.cs b/src/Icons/Services/IconFetchingService.cs index 8ec8d9c465..3edda71e12 100644 --- a/src/Icons/Services/IconFetchingService.cs +++ b/src/Icons/Services/IconFetchingService.cs @@ -299,7 +299,7 @@ namespace Bit.Icons.Services { return await _httpClient.SendAsync(message); } - catch(Exception e) + catch { return null; }