mirror of
https://github.com/bitwarden/server
synced 2026-01-06 18:43:36 +00:00
[PM-24616] refactor stripe adapter (#6527)
* move billing services+tests to billing namespaces * reorganized methods in file and added comment headers * renamed StripeAdapter methods for better clarity * clean up redundant qualifiers * Upgrade Stripe.net to v48.4.0 * Update PreviewTaxAmountCommand * Remove unused UpcomingInvoiceOptionExtensions * Added SubscriptionExtensions with GetCurrentPeriodEnd * Update PremiumUserBillingService * Update OrganizationBillingService * Update GetOrganizationWarningsQuery * Update BillingHistoryInfo * Update SubscriptionInfo * Remove unused Sql Billing folder * Update StripeAdapter * Update StripePaymentService * Update InvoiceCreatedHandler * Update PaymentFailedHandler * Update PaymentSucceededHandler * Update ProviderEventService * Update StripeEventUtilityService * Update SubscriptionDeletedHandler * Update SubscriptionUpdatedHandler * Update UpcomingInvoiceHandler * Update ProviderSubscriptionResponse * Remove unused Stripe Subscriptions Admin Tool * Update RemoveOrganizationFromProviderCommand * Update ProviderBillingService * Update RemoveOrganizatinoFromProviderCommandTests * Update PreviewTaxAmountCommandTests * Update GetCloudOrganizationLicenseQueryTests * Update GetOrganizationWarningsQueryTests * Update StripePaymentServiceTests * Update ProviderBillingControllerTests * Update ProviderEventServiceTests * Update SubscriptionDeletedHandlerTests * Update SubscriptionUpdatedHandlerTests * Resolve Billing test failures I completely removed tests for the StripeEventService as they were using a system I setup a while back that read JSON files of the Stripe event structure. I did not anticipate how frequently these structures would change with each API version and the cost of trying to update these specific JSON files to test a very static data retrieval service far outweigh the benefit. * Resolve Core test failures * Run dotnet format * Remove unused provider migration * Fixed failing tests * Run dotnet format * Replace the old webhook secret key with new one (#6223) * Fix compilation failures in additions * Run dotnet format * Bump Stripe API version * Fix recent addition: CreatePremiumCloudHostedSubscriptionCommand * Fix new code in main according to Stripe update * Fix InvoiceExtensions * Bump SDK version to match API Version * cleanup * fixing items missed after the merge * use expression body for all simple returns * forgot fixes, format, and pr feedback * claude pr feedback * pr feedback and cleanup * more claude feedback --------- Co-authored-by: Alex Morask <amorask@bitwarden.com> Co-authored-by: cyprain-okeke <108260115+cyprain-okeke@users.noreply.github.com>
This commit is contained in:
@@ -16,6 +16,7 @@ using Bit.Core.Billing.Enums;
|
||||
using Bit.Core.Billing.Extensions;
|
||||
using Bit.Core.Billing.Pricing;
|
||||
using Bit.Core.Billing.Providers.Services;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.OrganizationConnectionConfigs;
|
||||
using Bit.Core.OrganizationFeatures.OrganizationSponsorships.FamiliesForEnterprise.Interfaces;
|
||||
@@ -41,7 +42,7 @@ public class OrganizationsController : Controller
|
||||
private readonly ICollectionRepository _collectionRepository;
|
||||
private readonly IGroupRepository _groupRepository;
|
||||
private readonly IPolicyRepository _policyRepository;
|
||||
private readonly IPaymentService _paymentService;
|
||||
private readonly IStripePaymentService _paymentService;
|
||||
private readonly IApplicationCacheService _applicationCacheService;
|
||||
private readonly GlobalSettings _globalSettings;
|
||||
private readonly IProviderRepository _providerRepository;
|
||||
@@ -66,7 +67,7 @@ public class OrganizationsController : Controller
|
||||
ICollectionRepository collectionRepository,
|
||||
IGroupRepository groupRepository,
|
||||
IPolicyRepository policyRepository,
|
||||
IPaymentService paymentService,
|
||||
IStripePaymentService paymentService,
|
||||
IApplicationCacheService applicationCacheService,
|
||||
GlobalSettings globalSettings,
|
||||
IProviderRepository providerRepository,
|
||||
|
||||
@@ -339,11 +339,11 @@ public class ProvidersController : Controller
|
||||
]);
|
||||
await _providerBillingService.UpdateSeatMinimums(updateMspSeatMinimumsCommand);
|
||||
|
||||
var customer = await _stripeAdapter.CustomerGetAsync(provider.GatewayCustomerId);
|
||||
var customer = await _stripeAdapter.GetCustomerAsync(provider.GatewayCustomerId);
|
||||
if (model.PayByInvoice != customer.ApprovedToPayByInvoice())
|
||||
{
|
||||
var approvedToPayByInvoice = model.PayByInvoice ? "1" : "0";
|
||||
await _stripeAdapter.CustomerUpdateAsync(customer.Id, new CustomerUpdateOptions
|
||||
await _stripeAdapter.UpdateCustomerAsync(customer.Id, new CustomerUpdateOptions
|
||||
{
|
||||
Metadata = new Dictionary<string, string>
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ using Bit.Admin.Utilities;
|
||||
using Bit.Core.AdminConsole.Entities;
|
||||
using Bit.Core.AdminConsole.Repositories;
|
||||
using Bit.Core.Billing.Organizations.Queries;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Platform.Installations;
|
||||
using Bit.Core.Repositories;
|
||||
|
||||
@@ -5,6 +5,7 @@ using Bit.Admin.Models;
|
||||
using Bit.Admin.Services;
|
||||
using Bit.Admin.Utilities;
|
||||
using Bit.Core.Auth.UserFeatures.TwoFactorAuth.Interfaces;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Services;
|
||||
using Bit.Core.Settings;
|
||||
@@ -20,7 +21,7 @@ public class UsersController : Controller
|
||||
{
|
||||
private readonly IUserRepository _userRepository;
|
||||
private readonly ICipherRepository _cipherRepository;
|
||||
private readonly IPaymentService _paymentService;
|
||||
private readonly IStripePaymentService _paymentService;
|
||||
private readonly GlobalSettings _globalSettings;
|
||||
private readonly IAccessControlService _accessControlService;
|
||||
private readonly ITwoFactorIsEnabledQuery _twoFactorIsEnabledQuery;
|
||||
@@ -30,7 +31,7 @@ public class UsersController : Controller
|
||||
public UsersController(
|
||||
IUserRepository userRepository,
|
||||
ICipherRepository cipherRepository,
|
||||
IPaymentService paymentService,
|
||||
IStripePaymentService paymentService,
|
||||
GlobalSettings globalSettings,
|
||||
IAccessControlService accessControlService,
|
||||
ITwoFactorIsEnabledQuery twoFactorIsEnabledQuery,
|
||||
|
||||
@@ -6,6 +6,7 @@ using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.Interfaces;
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers;
|
||||
using Bit.Core.AdminConsole.Repositories;
|
||||
using Bit.Core.Auth.UserFeatures.TwoFactorAuth.Interfaces;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Context;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Services;
|
||||
@@ -24,7 +25,7 @@ public class MembersController : Controller
|
||||
private readonly ICurrentContext _currentContext;
|
||||
private readonly IUpdateOrganizationUserCommand _updateOrganizationUserCommand;
|
||||
private readonly IUpdateOrganizationUserGroupsCommand _updateOrganizationUserGroupsCommand;
|
||||
private readonly IPaymentService _paymentService;
|
||||
private readonly IStripePaymentService _paymentService;
|
||||
private readonly IOrganizationRepository _organizationRepository;
|
||||
private readonly ITwoFactorIsEnabledQuery _twoFactorIsEnabledQuery;
|
||||
private readonly IRemoveOrganizationUserCommand _removeOrganizationUserCommand;
|
||||
@@ -37,7 +38,7 @@ public class MembersController : Controller
|
||||
ICurrentContext currentContext,
|
||||
IUpdateOrganizationUserCommand updateOrganizationUserCommand,
|
||||
IUpdateOrganizationUserGroupsCommand updateOrganizationUserGroupsCommand,
|
||||
IPaymentService paymentService,
|
||||
IStripePaymentService paymentService,
|
||||
IOrganizationRepository organizationRepository,
|
||||
ITwoFactorIsEnabledQuery twoFactorIsEnabledQuery,
|
||||
IRemoveOrganizationUserCommand removeOrganizationUserCommand,
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Bit.Api.Billing.Controllers;
|
||||
[Route("accounts/billing")]
|
||||
[Authorize("Application")]
|
||||
public class AccountsBillingController(
|
||||
IPaymentService paymentService,
|
||||
IStripePaymentService paymentService,
|
||||
IUserService userService,
|
||||
IPaymentHistoryService paymentHistoryService) : Controller
|
||||
{
|
||||
|
||||
@@ -79,7 +79,7 @@ public class AccountsController(
|
||||
[HttpGet("subscription")]
|
||||
public async Task<SubscriptionResponseModel> GetSubscriptionAsync(
|
||||
[FromServices] GlobalSettings globalSettings,
|
||||
[FromServices] IPaymentService paymentService)
|
||||
[FromServices] IStripePaymentService paymentService)
|
||||
{
|
||||
var user = await userService.GetUserByPrincipalAsync(User);
|
||||
if (user == null)
|
||||
|
||||
@@ -5,7 +5,6 @@ using Bit.Core.Billing.Providers.Services;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Context;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Services;
|
||||
using Bit.Core.Utilities;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -19,7 +18,7 @@ public class OrganizationBillingController(
|
||||
ICurrentContext currentContext,
|
||||
IOrganizationBillingService organizationBillingService,
|
||||
IOrganizationRepository organizationRepository,
|
||||
IPaymentService paymentService,
|
||||
IStripePaymentService paymentService,
|
||||
IPaymentHistoryService paymentHistoryService) : BaseBillingController
|
||||
{
|
||||
// TODO: Remove when pm-25379-use-new-organization-metadata-structure is removed.
|
||||
|
||||
@@ -36,7 +36,7 @@ public class OrganizationsController(
|
||||
IOrganizationUserRepository organizationUserRepository,
|
||||
IOrganizationService organizationService,
|
||||
IUserService userService,
|
||||
IPaymentService paymentService,
|
||||
IStripePaymentService paymentService,
|
||||
ICurrentContext currentContext,
|
||||
IGetCloudOrganizationLicenseQuery getCloudOrganizationLicenseQuery,
|
||||
GlobalSettings globalSettings,
|
||||
|
||||
@@ -43,7 +43,7 @@ public class ProviderBillingController(
|
||||
return result;
|
||||
}
|
||||
|
||||
var invoices = await stripeAdapter.InvoiceListAsync(new StripeInvoiceListOptions
|
||||
var invoices = await stripeAdapter.ListInvoicesAsync(new StripeInvoiceListOptions
|
||||
{
|
||||
Customer = provider.GatewayCustomerId
|
||||
});
|
||||
@@ -87,7 +87,7 @@ public class ProviderBillingController(
|
||||
return result;
|
||||
}
|
||||
|
||||
var subscription = await stripeAdapter.SubscriptionGetAsync(provider.GatewaySubscriptionId,
|
||||
var subscription = await stripeAdapter.GetSubscriptionAsync(provider.GatewaySubscriptionId,
|
||||
new SubscriptionGetOptions { Expand = ["customer.tax_ids", "discounts", "test_clock"] });
|
||||
|
||||
var providerPlans = await providerPlanRepository.GetByProviderId(provider.Id);
|
||||
@@ -96,7 +96,7 @@ public class ProviderBillingController(
|
||||
{
|
||||
var plan = await pricingClient.GetPlanOrThrow(providerPlan.PlanType);
|
||||
var priceId = ProviderPriceAdapter.GetPriceId(provider, subscription, plan.Type);
|
||||
var price = await stripeAdapter.PriceGetAsync(priceId);
|
||||
var price = await stripeAdapter.GetPriceAsync(priceId);
|
||||
|
||||
var unitAmount = price.UnitAmountDecimal.HasValue
|
||||
? price.UnitAmountDecimal.Value / 100M
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Bit.Core.Billing.Tax.Services;
|
||||
using Bit.Core.Services;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Billing.Tax.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -28,7 +28,7 @@ public class StripeController(
|
||||
Usage = "off_session"
|
||||
};
|
||||
|
||||
var setupIntent = await stripeAdapter.SetupIntentCreate(options);
|
||||
var setupIntent = await stripeAdapter.CreateSetupIntentAsync(options);
|
||||
|
||||
return TypedResults.Ok(setupIntent.ClientSecret);
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public class StripeController(
|
||||
Usage = "off_session"
|
||||
};
|
||||
|
||||
var setupIntent = await stripeAdapter.SetupIntentCreate(options);
|
||||
var setupIntent = await stripeAdapter.CreateSetupIntentAsync(options);
|
||||
|
||||
return TypedResults.Ok(setupIntent.ClientSecret);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class BitPayController(
|
||||
IUserRepository userRepository,
|
||||
IProviderRepository providerRepository,
|
||||
IMailService mailService,
|
||||
IPaymentService paymentService,
|
||||
IStripePaymentService paymentService,
|
||||
ILogger<BitPayController> logger,
|
||||
IPremiumUserBillingService premiumUserBillingService)
|
||||
: Controller
|
||||
|
||||
@@ -23,7 +23,7 @@ public class PayPalController : Controller
|
||||
private readonly ILogger<PayPalController> _logger;
|
||||
private readonly IMailService _mailService;
|
||||
private readonly IOrganizationRepository _organizationRepository;
|
||||
private readonly IPaymentService _paymentService;
|
||||
private readonly IStripePaymentService _paymentService;
|
||||
private readonly ITransactionRepository _transactionRepository;
|
||||
private readonly IUserRepository _userRepository;
|
||||
private readonly IProviderRepository _providerRepository;
|
||||
@@ -34,7 +34,7 @@ public class PayPalController : Controller
|
||||
ILogger<PayPalController> logger,
|
||||
IMailService mailService,
|
||||
IOrganizationRepository organizationRepository,
|
||||
IPaymentService paymentService,
|
||||
IStripePaymentService paymentService,
|
||||
ITransactionRepository transactionRepository,
|
||||
IUserRepository userRepository,
|
||||
IProviderRepository providerRepository,
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
using Bit.Core.AdminConsole.Entities.Provider;
|
||||
using Bit.Core.AdminConsole.Repositories;
|
||||
using Bit.Core.Billing.Caches;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Services;
|
||||
using OneOf;
|
||||
using Stripe;
|
||||
using Event = Stripe.Event;
|
||||
@@ -59,10 +59,10 @@ public class SetupIntentSucceededHandler(
|
||||
return;
|
||||
}
|
||||
|
||||
await stripeAdapter.PaymentMethodAttachAsync(paymentMethod.Id,
|
||||
await stripeAdapter.AttachPaymentMethodAsync(paymentMethod.Id,
|
||||
new PaymentMethodAttachOptions { Customer = customerId });
|
||||
|
||||
await stripeAdapter.CustomerUpdateAsync(customerId, new CustomerUpdateOptions
|
||||
await stripeAdapter.UpdateCustomerAsync(customerId, new CustomerUpdateOptions
|
||||
{
|
||||
InvoiceSettings = new CustomerInvoiceSettingsOptions
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Bit.Core.AdminConsole.Models.Business;
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.Interfaces;
|
||||
using Bit.Core.AdminConsole.Repositories;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Exceptions;
|
||||
@@ -18,7 +19,7 @@ public class ImportOrganizationUsersAndGroupsCommand : IImportOrganizationUsersA
|
||||
{
|
||||
private readonly IOrganizationRepository _organizationRepository;
|
||||
private readonly IOrganizationUserRepository _organizationUserRepository;
|
||||
private readonly IPaymentService _paymentService;
|
||||
private readonly IStripePaymentService _paymentService;
|
||||
private readonly IGroupRepository _groupRepository;
|
||||
private readonly IEventService _eventService;
|
||||
private readonly IOrganizationService _organizationService;
|
||||
@@ -27,7 +28,7 @@ public class ImportOrganizationUsersAndGroupsCommand : IImportOrganizationUsersA
|
||||
|
||||
public ImportOrganizationUsersAndGroupsCommand(IOrganizationRepository organizationRepository,
|
||||
IOrganizationUserRepository organizationUserRepository,
|
||||
IPaymentService paymentService,
|
||||
IStripePaymentService paymentService,
|
||||
IGroupRepository groupRepository,
|
||||
IEventService eventService,
|
||||
IOrganizationService organizationService)
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.PasswordManager;
|
||||
using Bit.Core.AdminConsole.Utilities.Errors;
|
||||
using Bit.Core.AdminConsole.Utilities.Validation;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Models.Business;
|
||||
using Bit.Core.OrganizationFeatures.OrganizationSubscriptions.Interface;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Services;
|
||||
|
||||
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation;
|
||||
|
||||
@@ -15,7 +15,7 @@ public class InviteOrganizationUsersValidator(
|
||||
IOrganizationRepository organizationRepository,
|
||||
IInviteUsersPasswordManagerValidator inviteUsersPasswordManagerValidator,
|
||||
IUpdateSecretsManagerSubscriptionCommand secretsManagerSubscriptionCommand,
|
||||
IPaymentService paymentService) : IInviteUsersValidator
|
||||
IStripePaymentService paymentService) : IInviteUsersValidator
|
||||
{
|
||||
public async Task<ValidationResult<InviteOrganizationUsersValidationRequest>> ValidateAsync(
|
||||
InviteOrganizationUsersValidationRequest request)
|
||||
|
||||
@@ -9,8 +9,8 @@ using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.V
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.Provider;
|
||||
using Bit.Core.AdminConsole.Repositories;
|
||||
using Bit.Core.AdminConsole.Utilities.Validation;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Services;
|
||||
using Bit.Core.Settings;
|
||||
|
||||
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Validation.PasswordManager;
|
||||
@@ -22,7 +22,7 @@ public class InviteUsersPasswordManagerValidator(
|
||||
IInviteUsersEnvironmentValidator inviteUsersEnvironmentValidator,
|
||||
IInviteUsersOrganizationValidator inviteUsersOrganizationValidator,
|
||||
IProviderRepository providerRepository,
|
||||
IPaymentService paymentService,
|
||||
IStripePaymentService paymentService,
|
||||
IOrganizationRepository organizationRepository
|
||||
) : IInviteUsersPasswordManagerValidator
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ using Bit.Core.Billing.Enums;
|
||||
using Bit.Core.Billing.Organizations.Models;
|
||||
using Bit.Core.Billing.Organizations.Services;
|
||||
using Bit.Core.Billing.Pricing;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Exceptions;
|
||||
@@ -33,7 +34,7 @@ public interface ICloudOrganizationSignUpCommand
|
||||
public class CloudOrganizationSignUpCommand(
|
||||
IOrganizationUserRepository organizationUserRepository,
|
||||
IOrganizationBillingService organizationBillingService,
|
||||
IPaymentService paymentService,
|
||||
IStripePaymentService paymentService,
|
||||
IPolicyService policyService,
|
||||
IOrganizationRepository organizationRepository,
|
||||
IOrganizationApiKeyRepository organizationApiKeyRepository,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.Organizations.Interfaces;
|
||||
using Bit.Core.Auth.Enums;
|
||||
using Bit.Core.Auth.Repositories;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Services;
|
||||
@@ -12,13 +13,13 @@ public class OrganizationDeleteCommand : IOrganizationDeleteCommand
|
||||
{
|
||||
private readonly IApplicationCacheService _applicationCacheService;
|
||||
private readonly IOrganizationRepository _organizationRepository;
|
||||
private readonly IPaymentService _paymentService;
|
||||
private readonly IStripePaymentService _paymentService;
|
||||
private readonly ISsoConfigRepository _ssoConfigRepository;
|
||||
|
||||
public OrganizationDeleteCommand(
|
||||
IApplicationCacheService applicationCacheService,
|
||||
IOrganizationRepository organizationRepository,
|
||||
IPaymentService paymentService,
|
||||
IStripePaymentService paymentService,
|
||||
ISsoConfigRepository ssoConfigRepository)
|
||||
{
|
||||
_applicationCacheService = applicationCacheService;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Bit.Core.AdminConsole.Entities;
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers;
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Models;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Repositories;
|
||||
@@ -39,7 +40,7 @@ public class ResellerClientOrganizationSignUpCommand : IResellerClientOrganizati
|
||||
private readonly IOrganizationUserRepository _organizationUserRepository;
|
||||
private readonly IEventService _eventService;
|
||||
private readonly ISendOrganizationInvitesCommand _sendOrganizationInvitesCommand;
|
||||
private readonly IPaymentService _paymentService;
|
||||
private readonly IStripePaymentService _paymentService;
|
||||
|
||||
public ResellerClientOrganizationSignUpCommand(
|
||||
IOrganizationRepository organizationRepository,
|
||||
@@ -48,7 +49,7 @@ public class ResellerClientOrganizationSignUpCommand : IResellerClientOrganizati
|
||||
IOrganizationUserRepository organizationUserRepository,
|
||||
IEventService eventService,
|
||||
ISendOrganizationInvitesCommand sendOrganizationInvitesCommand,
|
||||
IPaymentService paymentService)
|
||||
IStripePaymentService paymentService)
|
||||
{
|
||||
_organizationRepository = organizationRepository;
|
||||
_organizationApiKeyRepository = organizationApiKeyRepository;
|
||||
|
||||
@@ -30,7 +30,7 @@ public class SelfHostedOrganizationSignUpCommand : ISelfHostedOrganizationSignUp
|
||||
private readonly ILicensingService _licensingService;
|
||||
private readonly IPolicyService _policyService;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IPaymentService _paymentService;
|
||||
private readonly IStripePaymentService _paymentService;
|
||||
|
||||
public SelfHostedOrganizationSignUpCommand(
|
||||
IOrganizationRepository organizationRepository,
|
||||
@@ -44,7 +44,7 @@ public class SelfHostedOrganizationSignUpCommand : ISelfHostedOrganizationSignUp
|
||||
ILicensingService licensingService,
|
||||
IPolicyService policyService,
|
||||
IGlobalSettings globalSettings,
|
||||
IPaymentService paymentService)
|
||||
IStripePaymentService paymentService)
|
||||
{
|
||||
_organizationRepository = organizationRepository;
|
||||
_organizationUserRepository = organizationUserRepository;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
using Bit.Core.AdminConsole.Models.Data.Organizations;
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.Organizations.Interfaces;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Bit.Core.AdminConsole.OrganizationFeatures.Organizations;
|
||||
|
||||
public class UpdateOrganizationSubscriptionCommand(IPaymentService paymentService,
|
||||
public class UpdateOrganizationSubscriptionCommand(IStripePaymentService paymentService,
|
||||
IOrganizationRepository repository,
|
||||
TimeProvider timeProvider,
|
||||
ILogger<UpdateOrganizationSubscriptionCommand> logger) : IUpdateOrganizationSubscriptionCommand
|
||||
|
||||
@@ -21,6 +21,7 @@ using Bit.Core.Billing.Constants;
|
||||
using Bit.Core.Billing.Enums;
|
||||
using Bit.Core.Billing.Extensions;
|
||||
using Bit.Core.Billing.Pricing;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Context;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
@@ -47,7 +48,7 @@ public class OrganizationService : IOrganizationService
|
||||
private readonly IPushNotificationService _pushNotificationService;
|
||||
private readonly IEventService _eventService;
|
||||
private readonly IApplicationCacheService _applicationCacheService;
|
||||
private readonly IPaymentService _paymentService;
|
||||
private readonly IStripePaymentService _paymentService;
|
||||
private readonly IPolicyRepository _policyRepository;
|
||||
private readonly IPolicyService _policyService;
|
||||
private readonly ISsoUserRepository _ssoUserRepository;
|
||||
@@ -74,7 +75,7 @@ public class OrganizationService : IOrganizationService
|
||||
IPushNotificationService pushNotificationService,
|
||||
IEventService eventService,
|
||||
IApplicationCacheService applicationCacheService,
|
||||
IPaymentService paymentService,
|
||||
IStripePaymentService paymentService,
|
||||
IPolicyRepository policyRepository,
|
||||
IPolicyService policyService,
|
||||
ISsoUserRepository ssoUserRepository,
|
||||
@@ -358,7 +359,7 @@ public class OrganizationService : IOrganizationService
|
||||
{
|
||||
var newDisplayName = organization.DisplayName();
|
||||
|
||||
await _stripeAdapter.CustomerUpdateAsync(organization.GatewayCustomerId,
|
||||
await _stripeAdapter.UpdateCustomerAsync(organization.GatewayCustomerId,
|
||||
new CustomerUpdateOptions
|
||||
{
|
||||
Email = organization.BillingEmail,
|
||||
|
||||
@@ -7,8 +7,8 @@ using Bit.Core.Billing.Models;
|
||||
using Bit.Core.Billing.Organizations.Models;
|
||||
using Bit.Core.Billing.Payment.Models;
|
||||
using Bit.Core.Billing.Pricing;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OneOf;
|
||||
using Stripe;
|
||||
@@ -125,7 +125,7 @@ public class PreviewOrganizationTaxCommand(
|
||||
|
||||
options.SubscriptionDetails = new InvoiceSubscriptionDetailsOptions { Items = items };
|
||||
|
||||
var invoice = await stripeAdapter.InvoiceCreatePreviewAsync(options);
|
||||
var invoice = await stripeAdapter.CreateInvoicePreviewAsync(options);
|
||||
return GetAmounts(invoice);
|
||||
});
|
||||
|
||||
@@ -165,7 +165,7 @@ public class PreviewOrganizationTaxCommand(
|
||||
|
||||
options.SubscriptionDetails = new InvoiceSubscriptionDetailsOptions { Items = items };
|
||||
|
||||
var invoice = await stripeAdapter.InvoiceCreatePreviewAsync(options);
|
||||
var invoice = await stripeAdapter.CreateInvoicePreviewAsync(options);
|
||||
return GetAmounts(invoice);
|
||||
}
|
||||
else
|
||||
@@ -181,7 +181,7 @@ public class PreviewOrganizationTaxCommand(
|
||||
|
||||
var options = GetBaseOptions(billingAddress, planChange.Tier != ProductTierType.Families);
|
||||
|
||||
var subscription = await stripeAdapter.SubscriptionGetAsync(organization.GatewaySubscriptionId,
|
||||
var subscription = await stripeAdapter.GetSubscriptionAsync(organization.GatewaySubscriptionId,
|
||||
new SubscriptionGetOptions { Expand = ["customer"] });
|
||||
|
||||
if (subscription.Customer.Discount != null)
|
||||
@@ -259,7 +259,7 @@ public class PreviewOrganizationTaxCommand(
|
||||
|
||||
options.SubscriptionDetails = new InvoiceSubscriptionDetailsOptions { Items = items };
|
||||
|
||||
var invoice = await stripeAdapter.InvoiceCreatePreviewAsync(options);
|
||||
var invoice = await stripeAdapter.CreateInvoicePreviewAsync(options);
|
||||
return GetAmounts(invoice);
|
||||
}
|
||||
});
|
||||
@@ -278,7 +278,7 @@ public class PreviewOrganizationTaxCommand(
|
||||
return new BadRequest("Organization does not have a subscription.");
|
||||
}
|
||||
|
||||
var subscription = await stripeAdapter.SubscriptionGetAsync(organization.GatewaySubscriptionId,
|
||||
var subscription = await stripeAdapter.GetSubscriptionAsync(organization.GatewaySubscriptionId,
|
||||
new SubscriptionGetOptions { Expand = ["customer.tax_ids"] });
|
||||
|
||||
var options = GetBaseOptions(subscription.Customer,
|
||||
@@ -336,7 +336,7 @@ public class PreviewOrganizationTaxCommand(
|
||||
|
||||
options.SubscriptionDetails = new InvoiceSubscriptionDetailsOptions { Items = items };
|
||||
|
||||
var invoice = await stripeAdapter.InvoiceCreatePreviewAsync(options);
|
||||
var invoice = await stripeAdapter.CreateInvoicePreviewAsync(options);
|
||||
return GetAmounts(invoice);
|
||||
});
|
||||
|
||||
|
||||
@@ -22,14 +22,14 @@ public interface IGetCloudOrganizationLicenseQuery
|
||||
public class GetCloudOrganizationLicenseQuery : IGetCloudOrganizationLicenseQuery
|
||||
{
|
||||
private readonly IInstallationRepository _installationRepository;
|
||||
private readonly IPaymentService _paymentService;
|
||||
private readonly IStripePaymentService _paymentService;
|
||||
private readonly ILicensingService _licensingService;
|
||||
private readonly IProviderRepository _providerRepository;
|
||||
private readonly IFeatureService _featureService;
|
||||
|
||||
public GetCloudOrganizationLicenseQuery(
|
||||
IInstallationRepository installationRepository,
|
||||
IPaymentService paymentService,
|
||||
IStripePaymentService paymentService,
|
||||
ILicensingService licensingService,
|
||||
IProviderRepository providerRepository,
|
||||
IFeatureService featureService)
|
||||
|
||||
@@ -9,7 +9,6 @@ using Bit.Core.Billing.Organizations.Models;
|
||||
using Bit.Core.Billing.Payment.Queries;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Context;
|
||||
using Bit.Core.Services;
|
||||
using Stripe;
|
||||
using Stripe.Tax;
|
||||
|
||||
@@ -201,7 +200,7 @@ public class GetOrganizationWarningsQuery(
|
||||
// ReSharper disable once InvertIf
|
||||
if (subscription.Status == SubscriptionStatus.PastDue)
|
||||
{
|
||||
var openInvoices = await stripeAdapter.InvoiceSearchAsync(new InvoiceSearchOptions
|
||||
var openInvoices = await stripeAdapter.SearchInvoiceAsync(new InvoiceSearchOptions
|
||||
{
|
||||
Query = $"subscription:'{subscription.Id}' status:'open'"
|
||||
});
|
||||
@@ -257,8 +256,8 @@ public class GetOrganizationWarningsQuery(
|
||||
|
||||
// Get active and scheduled registrations
|
||||
var registrations = (await Task.WhenAll(
|
||||
stripeAdapter.TaxRegistrationsListAsync(new RegistrationListOptions { Status = TaxRegistrationStatus.Active }),
|
||||
stripeAdapter.TaxRegistrationsListAsync(new RegistrationListOptions { Status = TaxRegistrationStatus.Scheduled })))
|
||||
stripeAdapter.ListTaxRegistrationsAsync(new RegistrationListOptions { Status = TaxRegistrationStatus.Active }),
|
||||
stripeAdapter.ListTaxRegistrationsAsync(new RegistrationListOptions { Status = TaxRegistrationStatus.Scheduled })))
|
||||
.SelectMany(registrations => registrations.Data);
|
||||
|
||||
// Find the matching registration for the customer
|
||||
|
||||
@@ -14,7 +14,6 @@ using Bit.Core.Billing.Tax.Services;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Services;
|
||||
using Bit.Core.Settings;
|
||||
using Braintree;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -161,7 +160,7 @@ public class OrganizationBillingService(
|
||||
try
|
||||
{
|
||||
// Update the subscription in Stripe
|
||||
await stripeAdapter.SubscriptionUpdateAsync(subscription.Id, updateOptions);
|
||||
await stripeAdapter.UpdateSubscriptionAsync(subscription.Id, updateOptions);
|
||||
organization.PlanType = newPlan.Type;
|
||||
await organizationRepository.ReplaceAsync(organization);
|
||||
}
|
||||
@@ -185,7 +184,7 @@ public class OrganizationBillingService(
|
||||
|
||||
var newDisplayName = organization.DisplayName();
|
||||
|
||||
await stripeAdapter.CustomerUpdateAsync(organization.GatewayCustomerId,
|
||||
await stripeAdapter.UpdateCustomerAsync(organization.GatewayCustomerId,
|
||||
new CustomerUpdateOptions
|
||||
{
|
||||
Email = organization.BillingEmail,
|
||||
@@ -324,7 +323,7 @@ public class OrganizationBillingService(
|
||||
case PaymentMethodType.BankAccount:
|
||||
{
|
||||
var setupIntent =
|
||||
(await stripeAdapter.SetupIntentList(new SetupIntentListOptions { PaymentMethod = paymentMethodToken }))
|
||||
(await stripeAdapter.ListSetupIntentsAsync(new SetupIntentListOptions { PaymentMethod = paymentMethodToken }))
|
||||
.FirstOrDefault();
|
||||
|
||||
if (setupIntent == null)
|
||||
@@ -358,7 +357,7 @@ public class OrganizationBillingService(
|
||||
|
||||
try
|
||||
{
|
||||
var customer = await stripeAdapter.CustomerCreateAsync(customerCreateOptions);
|
||||
var customer = await stripeAdapter.CreateCustomerAsync(customerCreateOptions);
|
||||
|
||||
organization.Gateway = GatewayType.Stripe;
|
||||
organization.GatewayCustomerId = customer.Id;
|
||||
@@ -509,7 +508,7 @@ public class OrganizationBillingService(
|
||||
subscriptionCreateOptions.AutomaticTax = new SubscriptionAutomaticTaxOptions { Enabled = true };
|
||||
}
|
||||
|
||||
var subscription = await stripeAdapter.SubscriptionCreateAsync(subscriptionCreateOptions);
|
||||
var subscription = await stripeAdapter.CreateSubscriptionAsync(subscriptionCreateOptions);
|
||||
|
||||
organization.GatewaySubscriptionId = subscription.Id;
|
||||
await organizationRepository.ReplaceAsync(organization);
|
||||
@@ -537,14 +536,14 @@ public class OrganizationBillingService(
|
||||
customer = customer switch
|
||||
{
|
||||
{ Address.Country: not Core.Constants.CountryAbbreviations.UnitedStates, TaxExempt: not StripeConstants.TaxExempt.Reverse } => await
|
||||
stripeAdapter.CustomerUpdateAsync(customer.Id,
|
||||
stripeAdapter.UpdateCustomerAsync(customer.Id,
|
||||
new CustomerUpdateOptions
|
||||
{
|
||||
Expand = expansions,
|
||||
TaxExempt = StripeConstants.TaxExempt.Reverse
|
||||
}),
|
||||
{ Address.Country: Core.Constants.CountryAbbreviations.UnitedStates, TaxExempt: StripeConstants.TaxExempt.Reverse } => await
|
||||
stripeAdapter.CustomerUpdateAsync(customer.Id,
|
||||
stripeAdapter.UpdateCustomerAsync(customer.Id,
|
||||
new CustomerUpdateOptions
|
||||
{
|
||||
Expand = expansions,
|
||||
@@ -603,7 +602,7 @@ public class OrganizationBillingService(
|
||||
}
|
||||
}
|
||||
};
|
||||
await stripeAdapter.SubscriptionUpdateAsync(organization.GatewaySubscriptionId, options);
|
||||
await stripeAdapter.UpdateSubscriptionAsync(organization.GatewaySubscriptionId, options);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ using Bit.Core.Billing.Extensions;
|
||||
using Bit.Core.Billing.Payment.Models;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Stripe;
|
||||
|
||||
@@ -46,7 +45,7 @@ public class UpdateBillingAddressCommand(
|
||||
BillingAddress billingAddress)
|
||||
{
|
||||
var customer =
|
||||
await stripeAdapter.CustomerUpdateAsync(subscriber.GatewayCustomerId,
|
||||
await stripeAdapter.UpdateCustomerAsync(subscriber.GatewayCustomerId,
|
||||
new CustomerUpdateOptions
|
||||
{
|
||||
Address = new AddressOptions
|
||||
@@ -71,7 +70,7 @@ public class UpdateBillingAddressCommand(
|
||||
BillingAddress billingAddress)
|
||||
{
|
||||
var customer =
|
||||
await stripeAdapter.CustomerUpdateAsync(subscriber.GatewayCustomerId,
|
||||
await stripeAdapter.UpdateCustomerAsync(subscriber.GatewayCustomerId,
|
||||
new CustomerUpdateOptions
|
||||
{
|
||||
Address = new AddressOptions
|
||||
@@ -92,7 +91,7 @@ public class UpdateBillingAddressCommand(
|
||||
await EnableAutomaticTaxAsync(subscriber, customer);
|
||||
|
||||
var deleteExistingTaxIds = customer.TaxIds?.Any() ?? false
|
||||
? customer.TaxIds.Select(taxId => stripeAdapter.TaxIdDeleteAsync(customer.Id, taxId.Id)).ToList()
|
||||
? customer.TaxIds.Select(taxId => stripeAdapter.DeleteTaxIdAsync(customer.Id, taxId.Id)).ToList()
|
||||
: [];
|
||||
|
||||
if (billingAddress.TaxId == null)
|
||||
@@ -101,12 +100,12 @@ public class UpdateBillingAddressCommand(
|
||||
return BillingAddress.From(customer.Address);
|
||||
}
|
||||
|
||||
var updatedTaxId = await stripeAdapter.TaxIdCreateAsync(customer.Id,
|
||||
var updatedTaxId = await stripeAdapter.CreateTaxIdAsync(customer.Id,
|
||||
new TaxIdCreateOptions { Type = billingAddress.TaxId.Code, Value = billingAddress.TaxId.Value });
|
||||
|
||||
if (billingAddress.TaxId.Code == StripeConstants.TaxIdType.SpanishNIF)
|
||||
{
|
||||
updatedTaxId = await stripeAdapter.TaxIdCreateAsync(customer.Id,
|
||||
updatedTaxId = await stripeAdapter.CreateTaxIdAsync(customer.Id,
|
||||
new TaxIdCreateOptions
|
||||
{
|
||||
Type = StripeConstants.TaxIdType.EUVAT,
|
||||
@@ -130,7 +129,7 @@ public class UpdateBillingAddressCommand(
|
||||
|
||||
if (subscription is { AutomaticTax.Enabled: false })
|
||||
{
|
||||
await stripeAdapter.SubscriptionUpdateAsync(subscriber.GatewaySubscriptionId,
|
||||
await stripeAdapter.UpdateSubscriptionAsync(subscriber.GatewaySubscriptionId,
|
||||
new SubscriptionUpdateOptions
|
||||
{
|
||||
AutomaticTax = new SubscriptionAutomaticTaxOptions { Enabled = true }
|
||||
|
||||
@@ -4,7 +4,6 @@ using Bit.Core.Billing.Constants;
|
||||
using Bit.Core.Billing.Payment.Models;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Services;
|
||||
using Bit.Core.Settings;
|
||||
using Bit.Core.Utilities;
|
||||
using Braintree;
|
||||
@@ -56,7 +55,7 @@ public class UpdatePaymentMethodCommand(
|
||||
|
||||
if (billingAddress != null && customer.Address is not { Country: not null, PostalCode: not null })
|
||||
{
|
||||
await stripeAdapter.CustomerUpdateAsync(customer.Id,
|
||||
await stripeAdapter.UpdateCustomerAsync(customer.Id,
|
||||
new CustomerUpdateOptions
|
||||
{
|
||||
Address = new AddressOptions
|
||||
@@ -75,7 +74,7 @@ public class UpdatePaymentMethodCommand(
|
||||
Customer customer,
|
||||
string token)
|
||||
{
|
||||
var setupIntents = await stripeAdapter.SetupIntentList(new SetupIntentListOptions
|
||||
var setupIntents = await stripeAdapter.ListSetupIntentsAsync(new SetupIntentListOptions
|
||||
{
|
||||
Expand = ["data.payment_method"],
|
||||
PaymentMethod = token
|
||||
@@ -104,9 +103,9 @@ public class UpdatePaymentMethodCommand(
|
||||
Customer customer,
|
||||
string token)
|
||||
{
|
||||
var paymentMethod = await stripeAdapter.PaymentMethodAttachAsync(token, new PaymentMethodAttachOptions { Customer = customer.Id });
|
||||
var paymentMethod = await stripeAdapter.AttachPaymentMethodAsync(token, new PaymentMethodAttachOptions { Customer = customer.Id });
|
||||
|
||||
await stripeAdapter.CustomerUpdateAsync(customer.Id,
|
||||
await stripeAdapter.UpdateCustomerAsync(customer.Id,
|
||||
new CustomerUpdateOptions
|
||||
{
|
||||
InvoiceSettings = new CustomerInvoiceSettingsOptions { DefaultPaymentMethod = token }
|
||||
@@ -139,7 +138,7 @@ public class UpdatePaymentMethodCommand(
|
||||
[StripeConstants.MetadataKeys.BraintreeCustomerId] = braintreeCustomer.Id
|
||||
};
|
||||
|
||||
await stripeAdapter.CustomerUpdateAsync(customer.Id, new CustomerUpdateOptions { Metadata = metadata });
|
||||
await stripeAdapter.UpdateCustomerAsync(customer.Id, new CustomerUpdateOptions { Metadata = metadata });
|
||||
}
|
||||
|
||||
var payPalAccount = braintreeCustomer.DefaultPaymentMethod as PayPalAccount;
|
||||
@@ -204,7 +203,7 @@ public class UpdatePaymentMethodCommand(
|
||||
[StripeConstants.MetadataKeys.BraintreeCustomerId] = string.Empty
|
||||
};
|
||||
|
||||
await stripeAdapter.CustomerUpdateAsync(customer.Id, new CustomerUpdateOptions { Metadata = metadata });
|
||||
await stripeAdapter.UpdateCustomerAsync(customer.Id, new CustomerUpdateOptions { Metadata = metadata });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ using Bit.Core.Billing.Extensions;
|
||||
using Bit.Core.Billing.Payment.Models;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Services;
|
||||
using Braintree;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Stripe;
|
||||
@@ -53,7 +52,7 @@ public class GetPaymentMethodQuery(
|
||||
|
||||
if (!string.IsNullOrEmpty(setupIntentId))
|
||||
{
|
||||
var setupIntent = await stripeAdapter.SetupIntentGet(setupIntentId, new SetupIntentGetOptions
|
||||
var setupIntent = await stripeAdapter.GetSetupIntentAsync(setupIntentId, new SetupIntentGetOptions
|
||||
{
|
||||
Expand = ["payment_method"]
|
||||
});
|
||||
|
||||
@@ -3,7 +3,6 @@ using Bit.Core.Billing.Constants;
|
||||
using Bit.Core.Billing.Extensions;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Services;
|
||||
using Stripe;
|
||||
|
||||
namespace Bit.Core.Billing.Payment.Queries;
|
||||
@@ -48,7 +47,7 @@ public class HasPaymentMethodQuery(
|
||||
return false;
|
||||
}
|
||||
|
||||
var setupIntent = await stripeAdapter.SetupIntentGet(setupIntentId, new SetupIntentGetOptions
|
||||
var setupIntent = await stripeAdapter.GetSetupIntentAsync(setupIntentId, new SetupIntentGetOptions
|
||||
{
|
||||
Expand = ["payment_method"]
|
||||
});
|
||||
|
||||
@@ -210,7 +210,7 @@ public class CreatePremiumCloudHostedSubscriptionCommand(
|
||||
case TokenizablePaymentMethodType.BankAccount:
|
||||
{
|
||||
var setupIntent =
|
||||
(await stripeAdapter.SetupIntentList(new SetupIntentListOptions { PaymentMethod = tokenizedPaymentMethod.Token }))
|
||||
(await stripeAdapter.ListSetupIntentsAsync(new SetupIntentListOptions { PaymentMethod = tokenizedPaymentMethod.Token }))
|
||||
.FirstOrDefault();
|
||||
|
||||
if (setupIntent == null)
|
||||
@@ -243,7 +243,7 @@ public class CreatePremiumCloudHostedSubscriptionCommand(
|
||||
|
||||
try
|
||||
{
|
||||
return await stripeAdapter.CustomerCreateAsync(customerCreateOptions);
|
||||
return await stripeAdapter.CreateCustomerAsync(customerCreateOptions);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -300,7 +300,7 @@ public class CreatePremiumCloudHostedSubscriptionCommand(
|
||||
ValidateLocation = ValidateTaxLocationTiming.Immediately
|
||||
}
|
||||
};
|
||||
return await stripeAdapter.CustomerUpdateAsync(customer.Id, options);
|
||||
return await stripeAdapter.UpdateCustomerAsync(customer.Id, options);
|
||||
}
|
||||
|
||||
private async Task<Subscription> CreateSubscriptionAsync(
|
||||
@@ -349,11 +349,11 @@ public class CreatePremiumCloudHostedSubscriptionCommand(
|
||||
OffSession = true
|
||||
};
|
||||
|
||||
var subscription = await stripeAdapter.SubscriptionCreateAsync(subscriptionCreateOptions);
|
||||
var subscription = await stripeAdapter.CreateSubscriptionAsync(subscriptionCreateOptions);
|
||||
|
||||
if (usingPayPal)
|
||||
{
|
||||
await stripeAdapter.InvoiceUpdateAsync(subscription.LatestInvoiceId, new InvoiceUpdateOptions
|
||||
await stripeAdapter.UpdateInvoiceAsync(subscription.LatestInvoiceId, new InvoiceUpdateOptions
|
||||
{
|
||||
AutoAdvance = false
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Bit.Core.Billing.Commands;
|
||||
using Bit.Core.Billing.Payment.Models;
|
||||
using Bit.Core.Billing.Pricing;
|
||||
using Bit.Core.Services;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Stripe;
|
||||
|
||||
@@ -56,7 +56,7 @@ public class PreviewPremiumTaxCommand(
|
||||
});
|
||||
}
|
||||
|
||||
var invoice = await stripeAdapter.InvoiceCreatePreviewAsync(options);
|
||||
var invoice = await stripeAdapter.CreateInvoicePreviewAsync(options);
|
||||
return GetAmounts(invoice);
|
||||
});
|
||||
|
||||
|
||||
50
src/Core/Billing/Services/IStripeAdapter.cs
Normal file
50
src/Core/Billing/Services/IStripeAdapter.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
// FIXME: Update this file to be null safe and then delete the line below
|
||||
#nullable disable
|
||||
|
||||
using Bit.Core.Models.BitStripe;
|
||||
using Stripe;
|
||||
using Stripe.Tax;
|
||||
|
||||
namespace Bit.Core.Billing.Services;
|
||||
|
||||
public interface IStripeAdapter
|
||||
{
|
||||
Task<Customer> CreateCustomerAsync(CustomerCreateOptions customerCreateOptions);
|
||||
Task<Customer> GetCustomerAsync(string id, CustomerGetOptions options = null);
|
||||
Task<Customer> UpdateCustomerAsync(string id, CustomerUpdateOptions options = null);
|
||||
Task<Customer> DeleteCustomerAsync(string id);
|
||||
Task<List<PaymentMethod>> ListCustomerPaymentMethodsAsync(string id, CustomerPaymentMethodListOptions options = null);
|
||||
Task<CustomerBalanceTransaction> CreateCustomerBalanceTransactionAsync(string customerId,
|
||||
CustomerBalanceTransactionCreateOptions options);
|
||||
Task<Subscription> CreateSubscriptionAsync(SubscriptionCreateOptions subscriptionCreateOptions);
|
||||
Task<Subscription> GetSubscriptionAsync(string id, SubscriptionGetOptions options = null);
|
||||
Task<StripeList<Registration>> ListTaxRegistrationsAsync(RegistrationListOptions options = null);
|
||||
Task DeleteCustomerDiscountAsync(string customerId, CustomerDeleteDiscountOptions options = null);
|
||||
Task<Subscription> UpdateSubscriptionAsync(string id, SubscriptionUpdateOptions options = null);
|
||||
Task<Subscription> CancelSubscriptionAsync(string id, SubscriptionCancelOptions options = null);
|
||||
Task<Invoice> GetInvoiceAsync(string id, InvoiceGetOptions options);
|
||||
Task<List<Invoice>> ListInvoicesAsync(StripeInvoiceListOptions options);
|
||||
Task<Invoice> CreateInvoicePreviewAsync(InvoiceCreatePreviewOptions options);
|
||||
Task<List<Invoice>> SearchInvoiceAsync(InvoiceSearchOptions options);
|
||||
Task<Invoice> UpdateInvoiceAsync(string id, InvoiceUpdateOptions options);
|
||||
Task<Invoice> FinalizeInvoiceAsync(string id, InvoiceFinalizeOptions options);
|
||||
Task<Invoice> SendInvoiceAsync(string id, InvoiceSendOptions options);
|
||||
Task<Invoice> PayInvoiceAsync(string id, InvoicePayOptions options = null);
|
||||
Task<Invoice> DeleteInvoiceAsync(string id, InvoiceDeleteOptions options = null);
|
||||
Task<Invoice> VoidInvoiceAsync(string id, InvoiceVoidOptions options = null);
|
||||
IEnumerable<PaymentMethod> ListPaymentMethodsAutoPaging(PaymentMethodListOptions options);
|
||||
IAsyncEnumerable<PaymentMethod> ListPaymentMethodsAutoPagingAsync(PaymentMethodListOptions options);
|
||||
Task<PaymentMethod> AttachPaymentMethodAsync(string id, PaymentMethodAttachOptions options = null);
|
||||
Task<PaymentMethod> DetachPaymentMethodAsync(string id, PaymentMethodDetachOptions options = null);
|
||||
Task<TaxId> CreateTaxIdAsync(string id, TaxIdCreateOptions options);
|
||||
Task<TaxId> DeleteTaxIdAsync(string customerId, string taxIdId, TaxIdDeleteOptions options = null);
|
||||
Task<StripeList<Charge>> ListChargesAsync(ChargeListOptions options);
|
||||
Task<Refund> CreateRefundAsync(RefundCreateOptions options);
|
||||
Task<Card> DeleteCardAsync(string customerId, string cardId, CardDeleteOptions options = null);
|
||||
Task<BankAccount> DeleteBankAccountAsync(string customerId, string bankAccount, BankAccountDeleteOptions options = null);
|
||||
Task<SetupIntent> CreateSetupIntentAsync(SetupIntentCreateOptions options);
|
||||
Task<List<SetupIntent>> ListSetupIntentsAsync(SetupIntentListOptions options);
|
||||
Task CancelSetupIntentAsync(string id, SetupIntentCancelOptions options = null);
|
||||
Task<SetupIntent> GetSetupIntentAsync(string id, SetupIntentGetOptions options = null);
|
||||
Task<Price> GetPriceAsync(string id, PriceGetOptions options = null);
|
||||
}
|
||||
@@ -8,9 +8,9 @@ using Bit.Core.Entities;
|
||||
using Bit.Core.Models.Business;
|
||||
using Bit.Core.Models.StaticStore;
|
||||
|
||||
namespace Bit.Core.Services;
|
||||
namespace Bit.Core.Billing.Services;
|
||||
|
||||
public interface IPaymentService
|
||||
public interface IStripePaymentService
|
||||
{
|
||||
Task CancelAndRecoverChargesAsync(ISubscriber subscriber);
|
||||
Task SponsorOrganizationAsync(Organization org, OrganizationSponsorship sponsorship);
|
||||
6
src/Core/Billing/Services/IStripeSyncService.cs
Normal file
6
src/Core/Billing/Services/IStripeSyncService.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Bit.Core.Billing.Services;
|
||||
|
||||
public interface IStripeSyncService
|
||||
{
|
||||
Task UpdateCustomerEmailAddressAsync(string gatewayCustomerId, string emailAddress);
|
||||
}
|
||||
@@ -4,7 +4,6 @@ using Bit.Core.Billing.Models;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Models.BitStripe;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Services;
|
||||
|
||||
namespace Bit.Core.Billing.Services.Implementations;
|
||||
|
||||
@@ -23,7 +22,7 @@ public class PaymentHistoryService(
|
||||
return Array.Empty<BillingHistoryInfo.BillingInvoice>();
|
||||
}
|
||||
|
||||
var invoices = await stripeAdapter.InvoiceListAsync(new StripeInvoiceListOptions
|
||||
var invoices = await stripeAdapter.ListInvoicesAsync(new StripeInvoiceListOptions
|
||||
{
|
||||
Customer = subscriber.GatewayCustomerId,
|
||||
Limit = pageSize,
|
||||
|
||||
@@ -12,7 +12,6 @@ using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Services;
|
||||
using Bit.Core.Settings;
|
||||
using Braintree;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -68,7 +67,7 @@ public class PremiumUserBillingService(
|
||||
}
|
||||
};
|
||||
|
||||
customer = await stripeAdapter.CustomerCreateAsync(options);
|
||||
customer = await stripeAdapter.CreateCustomerAsync(options);
|
||||
|
||||
user.Gateway = GatewayType.Stripe;
|
||||
user.GatewayCustomerId = customer.Id;
|
||||
@@ -81,7 +80,7 @@ public class PremiumUserBillingService(
|
||||
Balance = customer.Balance + credit
|
||||
};
|
||||
|
||||
await stripeAdapter.CustomerUpdateAsync(customer.Id, options);
|
||||
await stripeAdapter.UpdateCustomerAsync(customer.Id, options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,7 +226,7 @@ public class PremiumUserBillingService(
|
||||
case PaymentMethodType.BankAccount:
|
||||
{
|
||||
var setupIntent =
|
||||
(await stripeAdapter.SetupIntentList(new SetupIntentListOptions { PaymentMethod = paymentMethodToken }))
|
||||
(await stripeAdapter.ListSetupIntentsAsync(new SetupIntentListOptions { PaymentMethod = paymentMethodToken }))
|
||||
.FirstOrDefault();
|
||||
|
||||
if (setupIntent == null)
|
||||
@@ -260,7 +259,7 @@ public class PremiumUserBillingService(
|
||||
|
||||
try
|
||||
{
|
||||
return await stripeAdapter.CustomerCreateAsync(customerCreateOptions);
|
||||
return await stripeAdapter.CreateCustomerAsync(customerCreateOptions);
|
||||
}
|
||||
catch (StripeException stripeException) when (stripeException.StripeError?.Code ==
|
||||
StripeConstants.ErrorCodes.CustomerTaxLocationInvalid)
|
||||
@@ -347,11 +346,11 @@ public class PremiumUserBillingService(
|
||||
OffSession = true
|
||||
};
|
||||
|
||||
var subscription = await stripeAdapter.SubscriptionCreateAsync(subscriptionCreateOptions);
|
||||
var subscription = await stripeAdapter.CreateSubscriptionAsync(subscriptionCreateOptions);
|
||||
|
||||
if (usingPayPal)
|
||||
{
|
||||
await stripeAdapter.InvoiceUpdateAsync(subscription.LatestInvoiceId, new InvoiceUpdateOptions
|
||||
await stripeAdapter.UpdateInvoiceAsync(subscription.LatestInvoiceId, new InvoiceUpdateOptions
|
||||
{
|
||||
AutoAdvance = false
|
||||
});
|
||||
@@ -387,6 +386,6 @@ public class PremiumUserBillingService(
|
||||
}
|
||||
};
|
||||
|
||||
return await stripeAdapter.CustomerUpdateAsync(customer.Id, options);
|
||||
return await stripeAdapter.UpdateCustomerAsync(customer.Id, options);
|
||||
}
|
||||
}
|
||||
|
||||
209
src/Core/Billing/Services/Implementations/StripeAdapter.cs
Normal file
209
src/Core/Billing/Services/Implementations/StripeAdapter.cs
Normal file
@@ -0,0 +1,209 @@
|
||||
// FIXME: Update this file to be null safe and then delete the line below
|
||||
|
||||
#nullable disable
|
||||
|
||||
using Bit.Core.Models.BitStripe;
|
||||
using Stripe;
|
||||
using Stripe.Tax;
|
||||
using Stripe.TestHelpers;
|
||||
using CustomerService = Stripe.CustomerService;
|
||||
using RefundService = Stripe.RefundService;
|
||||
|
||||
namespace Bit.Core.Billing.Services.Implementations;
|
||||
|
||||
public class StripeAdapter : IStripeAdapter
|
||||
{
|
||||
private readonly CustomerService _customerService;
|
||||
private readonly SubscriptionService _subscriptionService;
|
||||
private readonly InvoiceService _invoiceService;
|
||||
private readonly PaymentMethodService _paymentMethodService;
|
||||
private readonly TaxIdService _taxIdService;
|
||||
private readonly ChargeService _chargeService;
|
||||
private readonly RefundService _refundService;
|
||||
private readonly CardService _cardService;
|
||||
private readonly BankAccountService _bankAccountService;
|
||||
private readonly PriceService _priceService;
|
||||
private readonly SetupIntentService _setupIntentService;
|
||||
private readonly TestClockService _testClockService;
|
||||
private readonly CustomerBalanceTransactionService _customerBalanceTransactionService;
|
||||
private readonly RegistrationService _taxRegistrationService;
|
||||
|
||||
public StripeAdapter()
|
||||
{
|
||||
_customerService = new CustomerService();
|
||||
_subscriptionService = new SubscriptionService();
|
||||
_invoiceService = new InvoiceService();
|
||||
_paymentMethodService = new PaymentMethodService();
|
||||
_taxIdService = new TaxIdService();
|
||||
_chargeService = new ChargeService();
|
||||
_refundService = new RefundService();
|
||||
_cardService = new CardService();
|
||||
_bankAccountService = new BankAccountService();
|
||||
_priceService = new PriceService();
|
||||
_setupIntentService = new SetupIntentService();
|
||||
_testClockService = new TestClockService();
|
||||
_customerBalanceTransactionService = new CustomerBalanceTransactionService();
|
||||
_taxRegistrationService = new RegistrationService();
|
||||
}
|
||||
|
||||
/**************
|
||||
** CUSTOMER **
|
||||
**************/
|
||||
public Task<Customer> CreateCustomerAsync(CustomerCreateOptions options) =>
|
||||
_customerService.CreateAsync(options);
|
||||
|
||||
public Task DeleteCustomerDiscountAsync(string customerId, CustomerDeleteDiscountOptions options = null) =>
|
||||
_customerService.DeleteDiscountAsync(customerId, options);
|
||||
|
||||
public Task<Customer> GetCustomerAsync(string id, CustomerGetOptions options = null) =>
|
||||
_customerService.GetAsync(id, options);
|
||||
|
||||
public Task<Customer> UpdateCustomerAsync(string id, CustomerUpdateOptions options = null) =>
|
||||
_customerService.UpdateAsync(id, options);
|
||||
|
||||
public Task<Customer> DeleteCustomerAsync(string id) =>
|
||||
_customerService.DeleteAsync(id);
|
||||
|
||||
public async Task<List<PaymentMethod>> ListCustomerPaymentMethodsAsync(string id,
|
||||
CustomerPaymentMethodListOptions options = null)
|
||||
{
|
||||
var paymentMethods = await _customerService.ListPaymentMethodsAsync(id, options);
|
||||
return paymentMethods.Data;
|
||||
}
|
||||
|
||||
public Task<CustomerBalanceTransaction> CreateCustomerBalanceTransactionAsync(string customerId,
|
||||
CustomerBalanceTransactionCreateOptions options) =>
|
||||
_customerBalanceTransactionService.CreateAsync(customerId, options);
|
||||
|
||||
/******************
|
||||
** SUBSCRIPTION **
|
||||
******************/
|
||||
public Task<Subscription> CreateSubscriptionAsync(SubscriptionCreateOptions options) =>
|
||||
_subscriptionService.CreateAsync(options);
|
||||
|
||||
public Task<Subscription> GetSubscriptionAsync(string id, SubscriptionGetOptions options = null) =>
|
||||
_subscriptionService.GetAsync(id, options);
|
||||
|
||||
public Task<Subscription> UpdateSubscriptionAsync(string id,
|
||||
SubscriptionUpdateOptions options = null) =>
|
||||
_subscriptionService.UpdateAsync(id, options);
|
||||
|
||||
public Task<Subscription> CancelSubscriptionAsync(string id, SubscriptionCancelOptions options = null) =>
|
||||
_subscriptionService.CancelAsync(id, options);
|
||||
|
||||
/*************
|
||||
** INVOICE **
|
||||
*************/
|
||||
public Task<Invoice> GetInvoiceAsync(string id, InvoiceGetOptions options) =>
|
||||
_invoiceService.GetAsync(id, options);
|
||||
|
||||
public async Task<List<Invoice>> ListInvoicesAsync(StripeInvoiceListOptions options)
|
||||
{
|
||||
if (!options.SelectAll)
|
||||
{
|
||||
return (await _invoiceService.ListAsync(options.ToInvoiceListOptions())).Data;
|
||||
}
|
||||
|
||||
options.Limit = 100;
|
||||
|
||||
var invoices = new List<Invoice>();
|
||||
|
||||
await foreach (var invoice in _invoiceService.ListAutoPagingAsync(options.ToInvoiceListOptions()))
|
||||
{
|
||||
invoices.Add(invoice);
|
||||
}
|
||||
|
||||
return invoices;
|
||||
}
|
||||
|
||||
public Task<Invoice> CreateInvoicePreviewAsync(InvoiceCreatePreviewOptions options) =>
|
||||
_invoiceService.CreatePreviewAsync(options);
|
||||
|
||||
public async Task<List<Invoice>> SearchInvoiceAsync(InvoiceSearchOptions options) =>
|
||||
(await _invoiceService.SearchAsync(options)).Data;
|
||||
|
||||
public Task<Invoice> UpdateInvoiceAsync(string id, InvoiceUpdateOptions options) =>
|
||||
_invoiceService.UpdateAsync(id, options);
|
||||
|
||||
public Task<Invoice> FinalizeInvoiceAsync(string id, InvoiceFinalizeOptions options) =>
|
||||
_invoiceService.FinalizeInvoiceAsync(id, options);
|
||||
|
||||
public Task<Invoice> SendInvoiceAsync(string id, InvoiceSendOptions options) =>
|
||||
_invoiceService.SendInvoiceAsync(id, options);
|
||||
|
||||
public Task<Invoice> PayInvoiceAsync(string id, InvoicePayOptions options = null) =>
|
||||
_invoiceService.PayAsync(id, options);
|
||||
|
||||
public Task<Invoice> DeleteInvoiceAsync(string id, InvoiceDeleteOptions options = null) =>
|
||||
_invoiceService.DeleteAsync(id, options);
|
||||
|
||||
public Task<Invoice> VoidInvoiceAsync(string id, InvoiceVoidOptions options = null) =>
|
||||
_invoiceService.VoidInvoiceAsync(id, options);
|
||||
|
||||
/********************
|
||||
** PAYMENT METHOD **
|
||||
********************/
|
||||
public IEnumerable<PaymentMethod> ListPaymentMethodsAutoPaging(PaymentMethodListOptions options) =>
|
||||
_paymentMethodService.ListAutoPaging(options);
|
||||
|
||||
public IAsyncEnumerable<PaymentMethod> ListPaymentMethodsAutoPagingAsync(PaymentMethodListOptions options)
|
||||
=> _paymentMethodService.ListAutoPagingAsync(options);
|
||||
|
||||
public Task<PaymentMethod> AttachPaymentMethodAsync(string id, PaymentMethodAttachOptions options = null) =>
|
||||
_paymentMethodService.AttachAsync(id, options);
|
||||
|
||||
public Task<PaymentMethod> DetachPaymentMethodAsync(string id, PaymentMethodDetachOptions options = null) =>
|
||||
_paymentMethodService.DetachAsync(id, options);
|
||||
|
||||
/************
|
||||
** TAX ID **
|
||||
************/
|
||||
public Task<TaxId> CreateTaxIdAsync(string id, TaxIdCreateOptions options) =>
|
||||
_taxIdService.CreateAsync(id, options);
|
||||
|
||||
public Task<TaxId> DeleteTaxIdAsync(string customerId, string taxIdId,
|
||||
TaxIdDeleteOptions options = null) =>
|
||||
_taxIdService.DeleteAsync(customerId, taxIdId, options);
|
||||
|
||||
/******************
|
||||
** BANK ACCOUNT **
|
||||
******************/
|
||||
public Task<BankAccount> DeleteBankAccountAsync(string customerId, string bankAccount, BankAccountDeleteOptions options = null) =>
|
||||
_bankAccountService.DeleteAsync(customerId, bankAccount, options);
|
||||
|
||||
/***********
|
||||
** PRICE **
|
||||
***********/
|
||||
public Task<Price> GetPriceAsync(string id, PriceGetOptions options = null) =>
|
||||
_priceService.GetAsync(id, options);
|
||||
|
||||
/******************
|
||||
** SETUP INTENT **
|
||||
******************/
|
||||
public Task<SetupIntent> CreateSetupIntentAsync(SetupIntentCreateOptions options) =>
|
||||
_setupIntentService.CreateAsync(options);
|
||||
|
||||
public async Task<List<SetupIntent>> ListSetupIntentsAsync(SetupIntentListOptions options) =>
|
||||
(await _setupIntentService.ListAsync(options)).Data;
|
||||
|
||||
public Task CancelSetupIntentAsync(string id, SetupIntentCancelOptions options = null) =>
|
||||
_setupIntentService.CancelAsync(id, options);
|
||||
|
||||
public Task<SetupIntent> GetSetupIntentAsync(string id, SetupIntentGetOptions options = null) =>
|
||||
_setupIntentService.GetAsync(id, options);
|
||||
|
||||
/*******************
|
||||
** MISCELLANEOUS **
|
||||
*******************/
|
||||
public Task<StripeList<Charge>> ListChargesAsync(ChargeListOptions options) =>
|
||||
_chargeService.ListAsync(options);
|
||||
|
||||
public Task<StripeList<Registration>> ListTaxRegistrationsAsync(RegistrationListOptions options = null) =>
|
||||
_taxRegistrationService.ListAsync(options);
|
||||
|
||||
public Task<Refund> CreateRefundAsync(RefundCreateOptions options) =>
|
||||
_refundService.CreateAsync(options);
|
||||
|
||||
public Task<Card> DeleteCardAsync(string customerId, string cardId, CardDeleteOptions options = null) =>
|
||||
_cardService.DeleteAsync(customerId, cardId, options);
|
||||
}
|
||||
@@ -21,9 +21,9 @@ using Stripe;
|
||||
using PaymentMethod = Stripe.PaymentMethod;
|
||||
using StaticStore = Bit.Core.Models.StaticStore;
|
||||
|
||||
namespace Bit.Core.Services;
|
||||
namespace Bit.Core.Billing.Services.Implementations;
|
||||
|
||||
public class StripePaymentService : IPaymentService
|
||||
public class StripePaymentService : IStripePaymentService
|
||||
{
|
||||
private const string SecretsManagerStandaloneDiscountId = "sm-standalone";
|
||||
|
||||
@@ -64,7 +64,7 @@ public class StripePaymentService : IPaymentService
|
||||
|
||||
await FinalizeSubscriptionChangeAsync(org, subscriptionUpdate, true);
|
||||
|
||||
var sub = await _stripeAdapter.SubscriptionGetAsync(org.GatewaySubscriptionId);
|
||||
var sub = await _stripeAdapter.GetSubscriptionAsync(org.GatewaySubscriptionId);
|
||||
org.ExpirationDate = sub.GetCurrentPeriodEnd();
|
||||
|
||||
if (sponsorship is not null)
|
||||
@@ -84,7 +84,7 @@ public class StripePaymentService : IPaymentService
|
||||
{
|
||||
// remember, when in doubt, throw
|
||||
var subGetOptions = new SubscriptionGetOptions { Expand = ["customer.tax", "customer.tax_ids"] };
|
||||
var sub = await _stripeAdapter.SubscriptionGetAsync(subscriber.GatewaySubscriptionId, subGetOptions);
|
||||
var sub = await _stripeAdapter.GetSubscriptionAsync(subscriber.GatewaySubscriptionId, subGetOptions);
|
||||
if (sub == null)
|
||||
{
|
||||
throw new GatewayException("Subscription not found.");
|
||||
@@ -107,7 +107,7 @@ public class StripePaymentService : IPaymentService
|
||||
var subUpdateOptions = new SubscriptionUpdateOptions
|
||||
{
|
||||
Items = updatedItemOptions,
|
||||
ProrationBehavior = invoiceNow ? Constants.AlwaysInvoice : Constants.CreateProrations,
|
||||
ProrationBehavior = invoiceNow ? Core.Constants.AlwaysInvoice : Core.Constants.CreateProrations,
|
||||
DaysUntilDue = daysUntilDue ?? 1,
|
||||
CollectionMethod = "send_invoice"
|
||||
};
|
||||
@@ -121,11 +121,11 @@ public class StripePaymentService : IPaymentService
|
||||
{
|
||||
if (sub.Customer is
|
||||
{
|
||||
Address.Country: not Constants.CountryAbbreviations.UnitedStates,
|
||||
Address.Country: not Core.Constants.CountryAbbreviations.UnitedStates,
|
||||
TaxExempt: not StripeConstants.TaxExempt.Reverse
|
||||
})
|
||||
{
|
||||
await _stripeAdapter.CustomerUpdateAsync(sub.CustomerId,
|
||||
await _stripeAdapter.UpdateCustomerAsync(sub.CustomerId,
|
||||
new CustomerUpdateOptions { TaxExempt = StripeConstants.TaxExempt.Reverse });
|
||||
}
|
||||
|
||||
@@ -141,9 +141,9 @@ public class StripePaymentService : IPaymentService
|
||||
string paymentIntentClientSecret = null;
|
||||
try
|
||||
{
|
||||
var subResponse = await _stripeAdapter.SubscriptionUpdateAsync(sub.Id, subUpdateOptions);
|
||||
var subResponse = await _stripeAdapter.UpdateSubscriptionAsync(sub.Id, subUpdateOptions);
|
||||
|
||||
var invoice = await _stripeAdapter.InvoiceGetAsync(subResponse?.LatestInvoiceId, new InvoiceGetOptions());
|
||||
var invoice = await _stripeAdapter.GetInvoiceAsync(subResponse?.LatestInvoiceId, new InvoiceGetOptions());
|
||||
if (invoice == null)
|
||||
{
|
||||
throw new BadRequestException("Unable to locate draft invoice for subscription update.");
|
||||
@@ -162,9 +162,9 @@ public class StripePaymentService : IPaymentService
|
||||
}
|
||||
else
|
||||
{
|
||||
invoice = await _stripeAdapter.InvoiceFinalizeInvoiceAsync(subResponse.LatestInvoiceId,
|
||||
invoice = await _stripeAdapter.FinalizeInvoiceAsync(subResponse.LatestInvoiceId,
|
||||
new InvoiceFinalizeOptions { AutoAdvance = false, });
|
||||
await _stripeAdapter.InvoiceSendInvoiceAsync(invoice.Id, new InvoiceSendOptions());
|
||||
await _stripeAdapter.SendInvoiceAsync(invoice.Id, new InvoiceSendOptions());
|
||||
paymentIntentClientSecret = null;
|
||||
}
|
||||
}
|
||||
@@ -172,7 +172,7 @@ public class StripePaymentService : IPaymentService
|
||||
catch
|
||||
{
|
||||
// Need to revert the subscription
|
||||
await _stripeAdapter.SubscriptionUpdateAsync(sub.Id, new SubscriptionUpdateOptions
|
||||
await _stripeAdapter.UpdateSubscriptionAsync(sub.Id, new SubscriptionUpdateOptions
|
||||
{
|
||||
Items = subscriptionUpdate.RevertItemsOptions(sub),
|
||||
// This proration behavior prevents a false "credit" from
|
||||
@@ -187,7 +187,7 @@ public class StripePaymentService : IPaymentService
|
||||
else if (invoice.Status != StripeConstants.InvoiceStatus.Paid)
|
||||
{
|
||||
// Pay invoice with no charge to the customer this completes the invoice immediately without waiting the scheduled 1h
|
||||
invoice = await _stripeAdapter.InvoicePayAsync(subResponse.LatestInvoiceId);
|
||||
invoice = await _stripeAdapter.PayInvoiceAsync(subResponse.LatestInvoiceId);
|
||||
paymentIntentClientSecret = null;
|
||||
}
|
||||
}
|
||||
@@ -196,7 +196,7 @@ public class StripePaymentService : IPaymentService
|
||||
// Change back the subscription collection method and/or days until due
|
||||
if (collectionMethod != "send_invoice" || daysUntilDue == null)
|
||||
{
|
||||
await _stripeAdapter.SubscriptionUpdateAsync(sub.Id,
|
||||
await _stripeAdapter.UpdateSubscriptionAsync(sub.Id,
|
||||
new SubscriptionUpdateOptions
|
||||
{
|
||||
CollectionMethod = collectionMethod,
|
||||
@@ -204,14 +204,14 @@ public class StripePaymentService : IPaymentService
|
||||
});
|
||||
}
|
||||
|
||||
var customer = await _stripeAdapter.CustomerGetAsync(sub.CustomerId);
|
||||
var customer = await _stripeAdapter.GetCustomerAsync(sub.CustomerId);
|
||||
|
||||
var newCoupon = customer.Discount?.Coupon?.Id;
|
||||
|
||||
if (!string.IsNullOrEmpty(existingCoupon) && string.IsNullOrEmpty(newCoupon))
|
||||
{
|
||||
// Re-add the lost coupon due to the update.
|
||||
await _stripeAdapter.SubscriptionUpdateAsync(sub.Id, new SubscriptionUpdateOptions
|
||||
await _stripeAdapter.UpdateSubscriptionAsync(sub.Id, new SubscriptionUpdateOptions
|
||||
{
|
||||
Discounts =
|
||||
[
|
||||
@@ -284,7 +284,7 @@ public class StripePaymentService : IPaymentService
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(subscriber.GatewaySubscriptionId))
|
||||
{
|
||||
await _stripeAdapter.SubscriptionCancelAsync(subscriber.GatewaySubscriptionId,
|
||||
await _stripeAdapter.CancelSubscriptionAsync(subscriber.GatewaySubscriptionId,
|
||||
new SubscriptionCancelOptions());
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ public class StripePaymentService : IPaymentService
|
||||
return;
|
||||
}
|
||||
|
||||
var customer = await _stripeAdapter.CustomerGetAsync(subscriber.GatewayCustomerId);
|
||||
var customer = await _stripeAdapter.GetCustomerAsync(subscriber.GatewayCustomerId);
|
||||
if (customer == null)
|
||||
{
|
||||
return;
|
||||
@@ -318,7 +318,7 @@ public class StripePaymentService : IPaymentService
|
||||
}
|
||||
else
|
||||
{
|
||||
var charges = await _stripeAdapter.ChargeListAsync(new ChargeListOptions
|
||||
var charges = await _stripeAdapter.ListChargesAsync(new ChargeListOptions
|
||||
{
|
||||
Customer = subscriber.GatewayCustomerId
|
||||
});
|
||||
@@ -327,12 +327,12 @@ public class StripePaymentService : IPaymentService
|
||||
{
|
||||
foreach (var charge in charges.Data.Where(c => c.Captured && !c.Refunded))
|
||||
{
|
||||
await _stripeAdapter.RefundCreateAsync(new RefundCreateOptions { Charge = charge.Id });
|
||||
await _stripeAdapter.CreateRefundAsync(new RefundCreateOptions { Charge = charge.Id });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await _stripeAdapter.CustomerDeleteAsync(subscriber.GatewayCustomerId);
|
||||
await _stripeAdapter.DeleteCustomerAsync(subscriber.GatewayCustomerId);
|
||||
}
|
||||
|
||||
public async Task<string> PayInvoiceAfterSubscriptionChangeAsync(ISubscriber subscriber, Invoice invoice)
|
||||
@@ -340,7 +340,7 @@ public class StripePaymentService : IPaymentService
|
||||
var customerOptions = new CustomerGetOptions();
|
||||
customerOptions.AddExpand("default_source");
|
||||
customerOptions.AddExpand("invoice_settings.default_payment_method");
|
||||
var customer = await _stripeAdapter.CustomerGetAsync(subscriber.GatewayCustomerId, customerOptions);
|
||||
var customer = await _stripeAdapter.GetCustomerAsync(subscriber.GatewayCustomerId, customerOptions);
|
||||
|
||||
string paymentIntentClientSecret = null;
|
||||
|
||||
@@ -360,13 +360,13 @@ public class StripePaymentService : IPaymentService
|
||||
// We're going to delete this draft invoice, it can't be paid
|
||||
try
|
||||
{
|
||||
await _stripeAdapter.InvoiceDeleteAsync(invoice.Id);
|
||||
await _stripeAdapter.DeleteInvoiceAsync(invoice.Id);
|
||||
}
|
||||
catch
|
||||
{
|
||||
await _stripeAdapter.InvoiceFinalizeInvoiceAsync(invoice.Id,
|
||||
await _stripeAdapter.FinalizeInvoiceAsync(invoice.Id,
|
||||
new InvoiceFinalizeOptions { AutoAdvance = false });
|
||||
await _stripeAdapter.InvoiceVoidInvoiceAsync(invoice.Id);
|
||||
await _stripeAdapter.VoidInvoiceAsync(invoice.Id);
|
||||
}
|
||||
|
||||
throw new BadRequestException("No payment method is available.");
|
||||
@@ -379,7 +379,7 @@ public class StripePaymentService : IPaymentService
|
||||
{
|
||||
// Finalize the invoice (from Draft) w/o auto-advance so we
|
||||
// can attempt payment manually.
|
||||
invoice = await _stripeAdapter.InvoiceFinalizeInvoiceAsync(invoice.Id,
|
||||
invoice = await _stripeAdapter.FinalizeInvoiceAsync(invoice.Id,
|
||||
new InvoiceFinalizeOptions { AutoAdvance = false, });
|
||||
var invoicePayOptions = new InvoicePayOptions { PaymentMethod = cardPaymentMethodId, };
|
||||
if (customer?.Metadata?.ContainsKey("btCustomerId") ?? false)
|
||||
@@ -414,7 +414,7 @@ public class StripePaymentService : IPaymentService
|
||||
}
|
||||
|
||||
braintreeTransaction = transactionResult.Target;
|
||||
invoice = await _stripeAdapter.InvoiceUpdateAsync(invoice.Id, new InvoiceUpdateOptions
|
||||
invoice = await _stripeAdapter.UpdateInvoiceAsync(invoice.Id, new InvoiceUpdateOptions
|
||||
{
|
||||
Metadata = new Dictionary<string, string>
|
||||
{
|
||||
@@ -428,7 +428,7 @@ public class StripePaymentService : IPaymentService
|
||||
|
||||
try
|
||||
{
|
||||
invoice = await _stripeAdapter.InvoicePayAsync(invoice.Id, invoicePayOptions);
|
||||
invoice = await _stripeAdapter.PayInvoiceAsync(invoice.Id, invoicePayOptions);
|
||||
}
|
||||
catch (StripeException e)
|
||||
{
|
||||
@@ -438,7 +438,7 @@ public class StripePaymentService : IPaymentService
|
||||
// SCA required, get intent client secret
|
||||
var invoiceGetOptions = new InvoiceGetOptions();
|
||||
invoiceGetOptions.AddExpand("confirmation_secret");
|
||||
invoice = await _stripeAdapter.InvoiceGetAsync(invoice.Id, invoiceGetOptions);
|
||||
invoice = await _stripeAdapter.GetInvoiceAsync(invoice.Id, invoiceGetOptions);
|
||||
paymentIntentClientSecret = invoice?.ConfirmationSecret?.ClientSecret;
|
||||
}
|
||||
else
|
||||
@@ -462,7 +462,7 @@ public class StripePaymentService : IPaymentService
|
||||
return paymentIntentClientSecret;
|
||||
}
|
||||
|
||||
invoice = await _stripeAdapter.InvoiceVoidInvoiceAsync(invoice.Id, new InvoiceVoidOptions());
|
||||
invoice = await _stripeAdapter.VoidInvoiceAsync(invoice.Id, new InvoiceVoidOptions());
|
||||
|
||||
// HACK: Workaround for customer balance credit
|
||||
if (invoice.StartingBalance < 0)
|
||||
@@ -470,12 +470,12 @@ public class StripePaymentService : IPaymentService
|
||||
// Customer had a balance applied to this invoice. Since we can't fully trust Stripe to
|
||||
// credit it back to the customer (even though their docs claim they will), we need to
|
||||
// check that balance against the current customer balance and determine if it needs to be re-applied
|
||||
customer = await _stripeAdapter.CustomerGetAsync(subscriber.GatewayCustomerId, customerOptions);
|
||||
customer = await _stripeAdapter.GetCustomerAsync(subscriber.GatewayCustomerId, customerOptions);
|
||||
|
||||
// Assumption: Customer balance should now be $0, otherwise payment would not have failed.
|
||||
if (customer.Balance == 0)
|
||||
{
|
||||
await _stripeAdapter.CustomerUpdateAsync(customer.Id,
|
||||
await _stripeAdapter.UpdateCustomerAsync(customer.Id,
|
||||
new CustomerUpdateOptions { Balance = invoice.StartingBalance });
|
||||
}
|
||||
}
|
||||
@@ -506,7 +506,7 @@ public class StripePaymentService : IPaymentService
|
||||
throw new GatewayException("No subscription.");
|
||||
}
|
||||
|
||||
var sub = await _stripeAdapter.SubscriptionGetAsync(subscriber.GatewaySubscriptionId);
|
||||
var sub = await _stripeAdapter.GetSubscriptionAsync(subscriber.GatewaySubscriptionId);
|
||||
if (sub == null)
|
||||
{
|
||||
throw new GatewayException("Subscription was not found.");
|
||||
@@ -522,9 +522,9 @@ public class StripePaymentService : IPaymentService
|
||||
try
|
||||
{
|
||||
var canceledSub = endOfPeriod
|
||||
? await _stripeAdapter.SubscriptionUpdateAsync(sub.Id,
|
||||
? await _stripeAdapter.UpdateSubscriptionAsync(sub.Id,
|
||||
new SubscriptionUpdateOptions { CancelAtPeriodEnd = true })
|
||||
: await _stripeAdapter.SubscriptionCancelAsync(sub.Id, new SubscriptionCancelOptions());
|
||||
: await _stripeAdapter.CancelSubscriptionAsync(sub.Id, new SubscriptionCancelOptions());
|
||||
if (!canceledSub.CanceledAt.HasValue)
|
||||
{
|
||||
throw new GatewayException("Unable to cancel subscription.");
|
||||
@@ -551,7 +551,7 @@ public class StripePaymentService : IPaymentService
|
||||
throw new GatewayException("No subscription.");
|
||||
}
|
||||
|
||||
var sub = await _stripeAdapter.SubscriptionGetAsync(subscriber.GatewaySubscriptionId);
|
||||
var sub = await _stripeAdapter.GetSubscriptionAsync(subscriber.GatewaySubscriptionId);
|
||||
if (sub == null)
|
||||
{
|
||||
throw new GatewayException("Subscription was not found.");
|
||||
@@ -563,7 +563,7 @@ public class StripePaymentService : IPaymentService
|
||||
throw new GatewayException("Subscription is not marked for cancellation.");
|
||||
}
|
||||
|
||||
var updatedSub = await _stripeAdapter.SubscriptionUpdateAsync(sub.Id,
|
||||
var updatedSub = await _stripeAdapter.UpdateSubscriptionAsync(sub.Id,
|
||||
new SubscriptionUpdateOptions { CancelAtPeriodEnd = false });
|
||||
if (updatedSub.CanceledAt.HasValue)
|
||||
{
|
||||
@@ -578,11 +578,11 @@ public class StripePaymentService : IPaymentService
|
||||
!string.IsNullOrWhiteSpace(subscriber.GatewayCustomerId);
|
||||
if (customerExists)
|
||||
{
|
||||
customer = await _stripeAdapter.CustomerGetAsync(subscriber.GatewayCustomerId);
|
||||
customer = await _stripeAdapter.GetCustomerAsync(subscriber.GatewayCustomerId);
|
||||
}
|
||||
else
|
||||
{
|
||||
customer = await _stripeAdapter.CustomerCreateAsync(new CustomerCreateOptions
|
||||
customer = await _stripeAdapter.CreateCustomerAsync(new CustomerCreateOptions
|
||||
{
|
||||
Email = subscriber.BillingEmailAddress(),
|
||||
Description = subscriber.BillingName(),
|
||||
@@ -591,9 +591,8 @@ public class StripePaymentService : IPaymentService
|
||||
subscriber.GatewayCustomerId = customer.Id;
|
||||
}
|
||||
|
||||
await _stripeAdapter.CustomerUpdateAsync(customer.Id,
|
||||
await _stripeAdapter.UpdateCustomerAsync(customer.Id,
|
||||
new CustomerUpdateOptions { Balance = customer.Balance - (long)(creditAmount * 100) });
|
||||
|
||||
return !customerExists;
|
||||
}
|
||||
|
||||
@@ -630,7 +629,7 @@ public class StripePaymentService : IPaymentService
|
||||
return subscriptionInfo;
|
||||
}
|
||||
|
||||
var subscription = await _stripeAdapter.SubscriptionGetAsync(subscriber.GatewaySubscriptionId,
|
||||
var subscription = await _stripeAdapter.GetSubscriptionAsync(subscriber.GatewaySubscriptionId,
|
||||
new SubscriptionGetOptions { Expand = ["customer.discount.coupon.applies_to", "discounts.coupon.applies_to", "test_clock"] });
|
||||
|
||||
if (subscription == null)
|
||||
@@ -675,7 +674,7 @@ public class StripePaymentService : IPaymentService
|
||||
Subscription = subscriber.GatewaySubscriptionId
|
||||
};
|
||||
|
||||
var upcomingInvoice = await _stripeAdapter.InvoiceCreatePreviewAsync(invoiceCreatePreviewOptions);
|
||||
var upcomingInvoice = await _stripeAdapter.CreateInvoicePreviewAsync(invoiceCreatePreviewOptions);
|
||||
|
||||
if (upcomingInvoice != null)
|
||||
{
|
||||
@@ -726,7 +725,7 @@ public class StripePaymentService : IPaymentService
|
||||
return false;
|
||||
}
|
||||
|
||||
var customer = await _stripeAdapter.CustomerGetAsync(gatewayCustomerId);
|
||||
var customer = await _stripeAdapter.GetCustomerAsync(gatewayCustomerId);
|
||||
|
||||
return customer?.Discount?.Coupon?.Id == SecretsManagerStandaloneDiscountId;
|
||||
}
|
||||
@@ -738,7 +737,7 @@ public class StripePaymentService : IPaymentService
|
||||
return (null, null);
|
||||
}
|
||||
|
||||
var openInvoices = await _stripeAdapter.InvoiceSearchAsync(new InvoiceSearchOptions
|
||||
var openInvoices = await _stripeAdapter.SearchInvoiceAsync(new InvoiceSearchOptions
|
||||
{
|
||||
Query = $"subscription:'{subscription.Id}' status:'open'"
|
||||
});
|
||||
@@ -774,7 +773,7 @@ public class StripePaymentService : IPaymentService
|
||||
|
||||
private PaymentMethod GetLatestCardPaymentMethod(string customerId)
|
||||
{
|
||||
var cardPaymentMethods = _stripeAdapter.PaymentMethodListAutoPaging(
|
||||
var cardPaymentMethods = _stripeAdapter.ListPaymentMethodsAutoPaging(
|
||||
new PaymentMethodListOptions { Customer = customerId, Type = "card" });
|
||||
return cardPaymentMethods.OrderByDescending(m => m.Created).FirstOrDefault();
|
||||
}
|
||||
@@ -837,7 +836,7 @@ public class StripePaymentService : IPaymentService
|
||||
Customer customer = null;
|
||||
try
|
||||
{
|
||||
customer = await _stripeAdapter.CustomerGetAsync(gatewayCustomerId, options);
|
||||
customer = await _stripeAdapter.GetCustomerAsync(gatewayCustomerId, options);
|
||||
}
|
||||
catch (StripeException)
|
||||
{
|
||||
@@ -870,21 +869,21 @@ public class StripePaymentService : IPaymentService
|
||||
|
||||
try
|
||||
{
|
||||
var paidInvoicesTask = _stripeAdapter.InvoiceListAsync(new StripeInvoiceListOptions
|
||||
var paidInvoicesTask = _stripeAdapter.ListInvoicesAsync(new StripeInvoiceListOptions
|
||||
{
|
||||
Customer = customer.Id,
|
||||
SelectAll = !limit.HasValue,
|
||||
Limit = limit,
|
||||
Status = "paid"
|
||||
});
|
||||
var openInvoicesTask = _stripeAdapter.InvoiceListAsync(new StripeInvoiceListOptions
|
||||
var openInvoicesTask = _stripeAdapter.ListInvoicesAsync(new StripeInvoiceListOptions
|
||||
{
|
||||
Customer = customer.Id,
|
||||
SelectAll = !limit.HasValue,
|
||||
Limit = limit,
|
||||
Status = "open"
|
||||
});
|
||||
var uncollectibleInvoicesTask = _stripeAdapter.InvoiceListAsync(new StripeInvoiceListOptions
|
||||
var uncollectibleInvoicesTask = _stripeAdapter.ListInvoicesAsync(new StripeInvoiceListOptions
|
||||
{
|
||||
Customer = customer.Id,
|
||||
SelectAll = !limit.HasValue,
|
||||
@@ -1,6 +1,6 @@
|
||||
using Bit.Core.Exceptions;
|
||||
|
||||
namespace Bit.Core.Services;
|
||||
namespace Bit.Core.Billing.Services.Implementations;
|
||||
|
||||
public class StripeSyncService : IStripeSyncService
|
||||
{
|
||||
@@ -11,7 +11,7 @@ public class StripeSyncService : IStripeSyncService
|
||||
_stripeAdapter = stripeAdapter;
|
||||
}
|
||||
|
||||
public async Task UpdateCustomerEmailAddress(string gatewayCustomerId, string emailAddress)
|
||||
public async Task UpdateCustomerEmailAddressAsync(string gatewayCustomerId, string emailAddress)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(gatewayCustomerId))
|
||||
{
|
||||
@@ -23,9 +23,9 @@ public class StripeSyncService : IStripeSyncService
|
||||
throw new InvalidEmailException();
|
||||
}
|
||||
|
||||
var customer = await _stripeAdapter.CustomerGetAsync(gatewayCustomerId);
|
||||
var customer = await _stripeAdapter.GetCustomerAsync(gatewayCustomerId);
|
||||
|
||||
await _stripeAdapter.CustomerUpdateAsync(customer.Id,
|
||||
await _stripeAdapter.UpdateCustomerAsync(customer.Id,
|
||||
new Stripe.CustomerUpdateOptions { Email = emailAddress });
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,6 @@ using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Services;
|
||||
using Bit.Core.Settings;
|
||||
using Bit.Core.Utilities;
|
||||
using Braintree;
|
||||
@@ -78,7 +77,7 @@ public class SubscriberService(
|
||||
{
|
||||
if (subscription.Metadata != null && subscription.Metadata.ContainsKey("organizationId"))
|
||||
{
|
||||
await stripeAdapter.SubscriptionUpdateAsync(subscription.Id, new SubscriptionUpdateOptions
|
||||
await stripeAdapter.UpdateSubscriptionAsync(subscription.Id, new SubscriptionUpdateOptions
|
||||
{
|
||||
Metadata = metadata
|
||||
});
|
||||
@@ -97,7 +96,7 @@ public class SubscriberService(
|
||||
options.CancellationDetails.Feedback = offboardingSurveyResponse.Reason;
|
||||
}
|
||||
|
||||
await stripeAdapter.SubscriptionCancelAsync(subscription.Id, options);
|
||||
await stripeAdapter.CancelSubscriptionAsync(subscription.Id, options);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -116,7 +115,7 @@ public class SubscriberService(
|
||||
options.CancellationDetails.Feedback = offboardingSurveyResponse.Reason;
|
||||
}
|
||||
|
||||
await stripeAdapter.SubscriptionUpdateAsync(subscription.Id, options);
|
||||
await stripeAdapter.UpdateSubscriptionAsync(subscription.Id, options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,7 +226,7 @@ public class SubscriberService(
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(subscriber))
|
||||
};
|
||||
|
||||
var customer = await stripeAdapter.CustomerCreateAsync(options);
|
||||
var customer = await stripeAdapter.CreateCustomerAsync(options);
|
||||
|
||||
switch (subscriber)
|
||||
{
|
||||
@@ -270,7 +269,7 @@ public class SubscriberService(
|
||||
|
||||
try
|
||||
{
|
||||
var customer = await stripeAdapter.CustomerGetAsync(subscriber.GatewayCustomerId, customerGetOptions);
|
||||
var customer = await stripeAdapter.GetCustomerAsync(subscriber.GatewayCustomerId, customerGetOptions);
|
||||
|
||||
if (customer != null)
|
||||
{
|
||||
@@ -306,7 +305,7 @@ public class SubscriberService(
|
||||
|
||||
try
|
||||
{
|
||||
var customer = await stripeAdapter.CustomerGetAsync(subscriber.GatewayCustomerId, customerGetOptions);
|
||||
var customer = await stripeAdapter.GetCustomerAsync(subscriber.GatewayCustomerId, customerGetOptions);
|
||||
|
||||
if (customer != null)
|
||||
{
|
||||
@@ -357,7 +356,7 @@ public class SubscriberService(
|
||||
|
||||
try
|
||||
{
|
||||
var subscription = await stripeAdapter.SubscriptionGetAsync(subscriber.GatewaySubscriptionId, subscriptionGetOptions);
|
||||
var subscription = await stripeAdapter.GetSubscriptionAsync(subscriber.GatewaySubscriptionId, subscriptionGetOptions);
|
||||
|
||||
if (subscription != null)
|
||||
{
|
||||
@@ -393,7 +392,7 @@ public class SubscriberService(
|
||||
|
||||
try
|
||||
{
|
||||
var subscription = await stripeAdapter.SubscriptionGetAsync(subscriber.GatewaySubscriptionId, subscriptionGetOptions);
|
||||
var subscription = await stripeAdapter.GetSubscriptionAsync(subscriber.GatewaySubscriptionId, subscriptionGetOptions);
|
||||
|
||||
if (subscription != null)
|
||||
{
|
||||
@@ -487,23 +486,23 @@ public class SubscriberService(
|
||||
switch (source)
|
||||
{
|
||||
case BankAccount:
|
||||
await stripeAdapter.BankAccountDeleteAsync(stripeCustomer.Id, source.Id);
|
||||
await stripeAdapter.DeleteBankAccountAsync(stripeCustomer.Id, source.Id);
|
||||
break;
|
||||
case Card:
|
||||
await stripeAdapter.CardDeleteAsync(stripeCustomer.Id, source.Id);
|
||||
await stripeAdapter.DeleteCardAsync(stripeCustomer.Id, source.Id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var paymentMethods = stripeAdapter.PaymentMethodListAutoPagingAsync(new PaymentMethodListOptions
|
||||
var paymentMethods = stripeAdapter.ListPaymentMethodsAutoPagingAsync(new PaymentMethodListOptions
|
||||
{
|
||||
Customer = stripeCustomer.Id
|
||||
});
|
||||
|
||||
await foreach (var paymentMethod in paymentMethods)
|
||||
{
|
||||
await stripeAdapter.PaymentMethodDetachAsync(paymentMethod.Id);
|
||||
await stripeAdapter.DetachPaymentMethodAsync(paymentMethod.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -532,7 +531,7 @@ public class SubscriberService(
|
||||
{
|
||||
case PaymentMethodType.BankAccount:
|
||||
{
|
||||
var getSetupIntentsForUpdatedPaymentMethod = stripeAdapter.SetupIntentList(new SetupIntentListOptions
|
||||
var getSetupIntentsForUpdatedPaymentMethod = stripeAdapter.ListSetupIntentsAsync(new SetupIntentListOptions
|
||||
{
|
||||
PaymentMethod = token
|
||||
});
|
||||
@@ -569,7 +568,7 @@ public class SubscriberService(
|
||||
await RemoveStripePaymentMethodsAsync(customer);
|
||||
|
||||
// Attach the incoming payment method.
|
||||
await stripeAdapter.PaymentMethodAttachAsync(token,
|
||||
await stripeAdapter.AttachPaymentMethodAsync(token,
|
||||
new PaymentMethodAttachOptions { Customer = subscriber.GatewayCustomerId });
|
||||
|
||||
var metadata = customer.Metadata;
|
||||
@@ -581,7 +580,7 @@ public class SubscriberService(
|
||||
}
|
||||
|
||||
// Set the customer's default payment method in Stripe and remove their Braintree customer ID.
|
||||
await stripeAdapter.CustomerUpdateAsync(subscriber.GatewayCustomerId, new CustomerUpdateOptions
|
||||
await stripeAdapter.UpdateCustomerAsync(subscriber.GatewayCustomerId, new CustomerUpdateOptions
|
||||
{
|
||||
InvoiceSettings = new CustomerInvoiceSettingsOptions
|
||||
{
|
||||
@@ -644,7 +643,7 @@ public class SubscriberService(
|
||||
Expand = ["subscriptions", "tax", "tax_ids"]
|
||||
});
|
||||
|
||||
customer = await stripeAdapter.CustomerUpdateAsync(customer.Id, new CustomerUpdateOptions
|
||||
customer = await stripeAdapter.UpdateCustomerAsync(customer.Id, new CustomerUpdateOptions
|
||||
{
|
||||
Address = new AddressOptions
|
||||
{
|
||||
@@ -662,7 +661,7 @@ public class SubscriberService(
|
||||
|
||||
if (taxId != null)
|
||||
{
|
||||
await stripeAdapter.TaxIdDeleteAsync(customer.Id, taxId.Id);
|
||||
await stripeAdapter.DeleteTaxIdAsync(customer.Id, taxId.Id);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(taxInformation.TaxId))
|
||||
@@ -685,12 +684,12 @@ public class SubscriberService(
|
||||
|
||||
try
|
||||
{
|
||||
await stripeAdapter.TaxIdCreateAsync(customer.Id,
|
||||
await stripeAdapter.CreateTaxIdAsync(customer.Id,
|
||||
new TaxIdCreateOptions { Type = taxIdType, Value = taxInformation.TaxId });
|
||||
|
||||
if (taxIdType == StripeConstants.TaxIdType.SpanishNIF)
|
||||
{
|
||||
await stripeAdapter.TaxIdCreateAsync(customer.Id,
|
||||
await stripeAdapter.CreateTaxIdAsync(customer.Id,
|
||||
new TaxIdCreateOptions { Type = StripeConstants.TaxIdType.EUVAT, Value = $"ES{taxInformation.TaxId}" });
|
||||
}
|
||||
}
|
||||
@@ -736,7 +735,7 @@ public class SubscriberService(
|
||||
Address.Country: not Core.Constants.CountryAbbreviations.UnitedStates,
|
||||
TaxExempt: not TaxExempt.Reverse
|
||||
}:
|
||||
await stripeAdapter.CustomerUpdateAsync(customer.Id,
|
||||
await stripeAdapter.UpdateCustomerAsync(customer.Id,
|
||||
new CustomerUpdateOptions { TaxExempt = TaxExempt.Reverse });
|
||||
break;
|
||||
case
|
||||
@@ -744,14 +743,14 @@ public class SubscriberService(
|
||||
Address.Country: Core.Constants.CountryAbbreviations.UnitedStates,
|
||||
TaxExempt: TaxExempt.Reverse
|
||||
}:
|
||||
await stripeAdapter.CustomerUpdateAsync(customer.Id,
|
||||
await stripeAdapter.UpdateCustomerAsync(customer.Id,
|
||||
new CustomerUpdateOptions { TaxExempt = TaxExempt.None });
|
||||
break;
|
||||
}
|
||||
|
||||
if (!subscription.AutomaticTax.Enabled)
|
||||
{
|
||||
await stripeAdapter.SubscriptionUpdateAsync(subscription.Id,
|
||||
await stripeAdapter.UpdateSubscriptionAsync(subscription.Id,
|
||||
new SubscriptionUpdateOptions
|
||||
{
|
||||
AutomaticTax = new SubscriptionAutomaticTaxOptions { Enabled = true }
|
||||
@@ -771,7 +770,7 @@ public class SubscriberService(
|
||||
|
||||
if (automaticTaxShouldBeEnabled && !subscription.AutomaticTax.Enabled)
|
||||
{
|
||||
await stripeAdapter.SubscriptionUpdateAsync(subscription.Id,
|
||||
await stripeAdapter.UpdateSubscriptionAsync(subscription.Id,
|
||||
new SubscriptionUpdateOptions
|
||||
{
|
||||
AutomaticTax = new SubscriptionAutomaticTaxOptions { Enabled = true }
|
||||
@@ -790,7 +789,7 @@ public class SubscriberService(
|
||||
}
|
||||
try
|
||||
{
|
||||
await stripeAdapter.CustomerGetAsync(subscriber.GatewayCustomerId);
|
||||
await stripeAdapter.GetCustomerAsync(subscriber.GatewayCustomerId);
|
||||
return true;
|
||||
}
|
||||
catch (StripeException e) when (e.StripeError.Code == "resource_missing")
|
||||
@@ -809,7 +808,7 @@ public class SubscriberService(
|
||||
}
|
||||
try
|
||||
{
|
||||
await stripeAdapter.SubscriptionGetAsync(subscriber.GatewaySubscriptionId);
|
||||
await stripeAdapter.GetSubscriptionAsync(subscriber.GatewaySubscriptionId);
|
||||
return true;
|
||||
}
|
||||
catch (StripeException e) when (e.StripeError.Code == "resource_missing")
|
||||
@@ -828,7 +827,7 @@ public class SubscriberService(
|
||||
|
||||
metadata[BraintreeCustomerIdKey] = braintreeCustomerId;
|
||||
|
||||
await stripeAdapter.CustomerUpdateAsync(customer.Id, new CustomerUpdateOptions
|
||||
await stripeAdapter.UpdateCustomerAsync(customer.Id, new CustomerUpdateOptions
|
||||
{
|
||||
Metadata = metadata
|
||||
});
|
||||
@@ -868,7 +867,7 @@ public class SubscriberService(
|
||||
return null;
|
||||
}
|
||||
|
||||
var setupIntent = await stripeAdapter.SetupIntentGet(setupIntentId, new SetupIntentGetOptions
|
||||
var setupIntent = await stripeAdapter.GetSetupIntentAsync(setupIntentId, new SetupIntentGetOptions
|
||||
{
|
||||
Expand = ["payment_method"]
|
||||
});
|
||||
@@ -886,7 +885,7 @@ public class SubscriberService(
|
||||
metadata[BraintreeCustomerIdOldKey] = value;
|
||||
metadata[BraintreeCustomerIdKey] = null;
|
||||
|
||||
await stripeAdapter.CustomerUpdateAsync(customer.Id, new CustomerUpdateOptions
|
||||
await stripeAdapter.UpdateCustomerAsync(customer.Id, new CustomerUpdateOptions
|
||||
{
|
||||
Metadata = metadata
|
||||
});
|
||||
@@ -903,18 +902,18 @@ public class SubscriberService(
|
||||
switch (source)
|
||||
{
|
||||
case BankAccount:
|
||||
await stripeAdapter.BankAccountDeleteAsync(customer.Id, source.Id);
|
||||
await stripeAdapter.DeleteBankAccountAsync(customer.Id, source.Id);
|
||||
break;
|
||||
case Card:
|
||||
await stripeAdapter.CardDeleteAsync(customer.Id, source.Id);
|
||||
await stripeAdapter.DeleteCardAsync(customer.Id, source.Id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var paymentMethods = await stripeAdapter.CustomerListPaymentMethods(customer.Id);
|
||||
var paymentMethods = await stripeAdapter.ListCustomerPaymentMethodsAsync(customer.Id);
|
||||
|
||||
await Task.WhenAll(paymentMethods.Select(pm => stripeAdapter.PaymentMethodDetachAsync(pm.Id)));
|
||||
await Task.WhenAll(paymentMethods.Select(pm => stripeAdapter.DetachPaymentMethodAsync(pm.Id)));
|
||||
}
|
||||
|
||||
private async Task ReplaceBraintreePaymentMethodAsync(
|
||||
|
||||
@@ -7,7 +7,6 @@ using Bit.Core.Billing.Extensions;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Services;
|
||||
using OneOf.Types;
|
||||
using Stripe;
|
||||
|
||||
@@ -53,7 +52,7 @@ public class RestartSubscriptionCommand(
|
||||
TrialPeriodDays = 0
|
||||
};
|
||||
|
||||
var subscription = await stripeAdapter.SubscriptionCreateAsync(options);
|
||||
var subscription = await stripeAdapter.CreateSubscriptionAsync(options);
|
||||
await EnableAsync(subscriber, subscription);
|
||||
return new None();
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#nullable disable
|
||||
|
||||
using Bit.Core.Billing.Models;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Billing.Tax.Models;
|
||||
using Bit.Core.Services;
|
||||
using Stripe;
|
||||
|
||||
namespace Bit.Core.Billing;
|
||||
@@ -22,7 +22,7 @@ public static class Utilities
|
||||
return null;
|
||||
}
|
||||
|
||||
var openInvoices = await stripeAdapter.InvoiceSearchAsync(new InvoiceSearchOptions
|
||||
var openInvoices = await stripeAdapter.SearchInvoiceAsync(new InvoiceSearchOptions
|
||||
{
|
||||
Query = $"subscription:'{subscription.Id}' status:'open'"
|
||||
});
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using Bit.Core.AdminConsole.Entities;
|
||||
using Bit.Core.Billing.Extensions;
|
||||
using Bit.Core.Billing.Models;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.OrganizationFeatures.OrganizationSponsorships.FamiliesForEnterprise.Interfaces;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Services;
|
||||
|
||||
namespace Bit.Core.OrganizationFeatures.OrganizationSponsorships.FamiliesForEnterprise.Cloud;
|
||||
|
||||
@@ -13,9 +13,9 @@ public class SetUpSponsorshipCommand : ISetUpSponsorshipCommand
|
||||
{
|
||||
private readonly IOrganizationSponsorshipRepository _organizationSponsorshipRepository;
|
||||
private readonly IOrganizationRepository _organizationRepository;
|
||||
private readonly IPaymentService _paymentService;
|
||||
private readonly IStripePaymentService _paymentService;
|
||||
|
||||
public SetUpSponsorshipCommand(IOrganizationSponsorshipRepository organizationSponsorshipRepository, IOrganizationRepository organizationRepository, IPaymentService paymentService)
|
||||
public SetUpSponsorshipCommand(IOrganizationSponsorshipRepository organizationSponsorshipRepository, IOrganizationRepository organizationRepository, IStripePaymentService paymentService)
|
||||
{
|
||||
_organizationSponsorshipRepository = organizationSponsorshipRepository;
|
||||
_organizationRepository = organizationRepository;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
using Bit.Core.AdminConsole.Entities;
|
||||
using Bit.Core.Billing.Extensions;
|
||||
using Bit.Core.Billing.Models;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.OrganizationFeatures.OrganizationSponsorships.FamiliesForEnterprise.Interfaces;
|
||||
using Bit.Core.Repositories;
|
||||
@@ -14,14 +15,14 @@ namespace Bit.Core.OrganizationFeatures.OrganizationSponsorships.FamiliesForEnte
|
||||
|
||||
public class ValidateSponsorshipCommand : CancelSponsorshipCommand, IValidateSponsorshipCommand
|
||||
{
|
||||
private readonly IPaymentService _paymentService;
|
||||
private readonly IStripePaymentService _paymentService;
|
||||
private readonly IMailService _mailService;
|
||||
private readonly ILogger<ValidateSponsorshipCommand> _logger;
|
||||
|
||||
public ValidateSponsorshipCommand(
|
||||
IOrganizationSponsorshipRepository organizationSponsorshipRepository,
|
||||
IOrganizationRepository organizationRepository,
|
||||
IPaymentService paymentService,
|
||||
IStripePaymentService paymentService,
|
||||
IMailService mailService,
|
||||
ILogger<ValidateSponsorshipCommand> logger) : base(organizationSponsorshipRepository, organizationRepository)
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ using Bit.Core.AdminConsole.Enums.Provider;
|
||||
using Bit.Core.AdminConsole.Repositories;
|
||||
using Bit.Core.Billing.Enums;
|
||||
using Bit.Core.Billing.Pricing;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.Models.Business;
|
||||
using Bit.Core.OrganizationFeatures.OrganizationSubscriptions.Interface;
|
||||
@@ -12,13 +13,13 @@ namespace Bit.Core.OrganizationFeatures.OrganizationSubscriptions;
|
||||
|
||||
public class AddSecretsManagerSubscriptionCommand : IAddSecretsManagerSubscriptionCommand
|
||||
{
|
||||
private readonly IPaymentService _paymentService;
|
||||
private readonly IStripePaymentService _paymentService;
|
||||
private readonly IOrganizationService _organizationService;
|
||||
private readonly IProviderRepository _providerRepository;
|
||||
private readonly IPricingClient _pricingClient;
|
||||
|
||||
public AddSecretsManagerSubscriptionCommand(
|
||||
IPaymentService paymentService,
|
||||
IStripePaymentService paymentService,
|
||||
IOrganizationService organizationService,
|
||||
IProviderRepository providerRepository,
|
||||
IPricingClient pricingClient)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
using Bit.Core.AdminConsole.Entities;
|
||||
using Bit.Core.Billing.Enums;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.Models.Business;
|
||||
@@ -18,7 +19,7 @@ namespace Bit.Core.OrganizationFeatures.OrganizationSubscriptions;
|
||||
public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubscriptionCommand
|
||||
{
|
||||
private readonly IOrganizationUserRepository _organizationUserRepository;
|
||||
private readonly IPaymentService _paymentService;
|
||||
private readonly IStripePaymentService _paymentService;
|
||||
private readonly IMailService _mailService;
|
||||
private readonly ILogger<UpdateSecretsManagerSubscriptionCommand> _logger;
|
||||
private readonly IServiceAccountRepository _serviceAccountRepository;
|
||||
@@ -29,7 +30,7 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs
|
||||
|
||||
public UpdateSecretsManagerSubscriptionCommand(
|
||||
IOrganizationUserRepository organizationUserRepository,
|
||||
IPaymentService paymentService,
|
||||
IStripePaymentService paymentService,
|
||||
IMailService mailService,
|
||||
ILogger<UpdateSecretsManagerSubscriptionCommand> logger,
|
||||
IServiceAccountRepository serviceAccountRepository,
|
||||
|
||||
@@ -11,6 +11,7 @@ using Bit.Core.Billing.Enums;
|
||||
using Bit.Core.Billing.Organizations.Models;
|
||||
using Bit.Core.Billing.Organizations.Services;
|
||||
using Bit.Core.Billing.Pricing;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.Models.Business;
|
||||
@@ -26,7 +27,7 @@ public class UpgradeOrganizationPlanCommand : IUpgradeOrganizationPlanCommand
|
||||
private readonly IOrganizationUserRepository _organizationUserRepository;
|
||||
private readonly ICollectionRepository _collectionRepository;
|
||||
private readonly IGroupRepository _groupRepository;
|
||||
private readonly IPaymentService _paymentService;
|
||||
private readonly IStripePaymentService _paymentService;
|
||||
private readonly IPolicyRepository _policyRepository;
|
||||
private readonly ISsoConfigRepository _ssoConfigRepository;
|
||||
private readonly IOrganizationConnectionRepository _organizationConnectionRepository;
|
||||
@@ -41,7 +42,7 @@ public class UpgradeOrganizationPlanCommand : IUpgradeOrganizationPlanCommand
|
||||
IOrganizationUserRepository organizationUserRepository,
|
||||
ICollectionRepository collectionRepository,
|
||||
IGroupRepository groupRepository,
|
||||
IPaymentService paymentService,
|
||||
IStripePaymentService paymentService,
|
||||
IPolicyRepository policyRepository,
|
||||
ISsoConfigRepository ssoConfigRepository,
|
||||
IOrganizationConnectionRepository organizationConnectionRepository,
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
// FIXME: Update this file to be null safe and then delete the line below
|
||||
#nullable disable
|
||||
|
||||
using Bit.Core.Models.BitStripe;
|
||||
using Stripe;
|
||||
using Stripe.Tax;
|
||||
|
||||
namespace Bit.Core.Services;
|
||||
|
||||
public interface IStripeAdapter
|
||||
{
|
||||
Task<Customer> CustomerCreateAsync(CustomerCreateOptions customerCreateOptions);
|
||||
Task CustomerDeleteDiscountAsync(string customerId, CustomerDeleteDiscountOptions options = null);
|
||||
Task<Customer> CustomerGetAsync(string id, CustomerGetOptions options = null);
|
||||
Task<Customer> CustomerUpdateAsync(string id, CustomerUpdateOptions options = null);
|
||||
Task<Customer> CustomerDeleteAsync(string id);
|
||||
Task<List<PaymentMethod>> CustomerListPaymentMethods(string id, CustomerPaymentMethodListOptions options = null);
|
||||
Task<CustomerBalanceTransaction> CustomerBalanceTransactionCreate(string customerId,
|
||||
CustomerBalanceTransactionCreateOptions options);
|
||||
Task<Subscription> SubscriptionCreateAsync(SubscriptionCreateOptions subscriptionCreateOptions);
|
||||
Task<Subscription> SubscriptionGetAsync(string id, SubscriptionGetOptions options = null);
|
||||
Task<Subscription> SubscriptionUpdateAsync(string id, SubscriptionUpdateOptions options = null);
|
||||
Task<Subscription> SubscriptionCancelAsync(string Id, SubscriptionCancelOptions options = null);
|
||||
Task<Invoice> InvoiceGetAsync(string id, InvoiceGetOptions options);
|
||||
Task<List<Invoice>> InvoiceListAsync(StripeInvoiceListOptions options);
|
||||
Task<Invoice> InvoiceCreatePreviewAsync(InvoiceCreatePreviewOptions options);
|
||||
Task<List<Invoice>> InvoiceSearchAsync(InvoiceSearchOptions options);
|
||||
Task<Invoice> InvoiceUpdateAsync(string id, InvoiceUpdateOptions options);
|
||||
Task<Invoice> InvoiceFinalizeInvoiceAsync(string id, InvoiceFinalizeOptions options);
|
||||
Task<Invoice> InvoiceSendInvoiceAsync(string id, InvoiceSendOptions options);
|
||||
Task<Invoice> InvoicePayAsync(string id, InvoicePayOptions options = null);
|
||||
Task<Invoice> InvoiceDeleteAsync(string id, InvoiceDeleteOptions options = null);
|
||||
Task<Invoice> InvoiceVoidInvoiceAsync(string id, InvoiceVoidOptions options = null);
|
||||
IEnumerable<PaymentMethod> PaymentMethodListAutoPaging(PaymentMethodListOptions options);
|
||||
IAsyncEnumerable<PaymentMethod> PaymentMethodListAutoPagingAsync(PaymentMethodListOptions options);
|
||||
Task<PaymentMethod> PaymentMethodAttachAsync(string id, PaymentMethodAttachOptions options = null);
|
||||
Task<PaymentMethod> PaymentMethodDetachAsync(string id, PaymentMethodDetachOptions options = null);
|
||||
Task<TaxId> TaxIdCreateAsync(string id, TaxIdCreateOptions options);
|
||||
Task<TaxId> TaxIdDeleteAsync(string customerId, string taxIdId, TaxIdDeleteOptions options = null);
|
||||
Task<StripeList<Registration>> TaxRegistrationsListAsync(RegistrationListOptions options = null);
|
||||
Task<StripeList<Charge>> ChargeListAsync(ChargeListOptions options);
|
||||
Task<Refund> RefundCreateAsync(RefundCreateOptions options);
|
||||
Task<Card> CardDeleteAsync(string customerId, string cardId, CardDeleteOptions options = null);
|
||||
Task<BankAccount> BankAccountCreateAsync(string customerId, BankAccountCreateOptions options = null);
|
||||
Task<BankAccount> BankAccountDeleteAsync(string customerId, string bankAccount, BankAccountDeleteOptions options = null);
|
||||
Task<StripeList<Price>> PriceListAsync(PriceListOptions options = null);
|
||||
Task<SetupIntent> SetupIntentCreate(SetupIntentCreateOptions options);
|
||||
Task<List<SetupIntent>> SetupIntentList(SetupIntentListOptions options);
|
||||
Task SetupIntentCancel(string id, SetupIntentCancelOptions options = null);
|
||||
Task<SetupIntent> SetupIntentGet(string id, SetupIntentGetOptions options = null);
|
||||
Task SetupIntentVerifyMicroDeposit(string id, SetupIntentVerifyMicrodepositsOptions options);
|
||||
Task<List<Stripe.TestHelpers.TestClock>> TestClockListAsync();
|
||||
Task<Price> PriceGetAsync(string id, PriceGetOptions options = null);
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace Bit.Core.Services;
|
||||
|
||||
public interface IStripeSyncService
|
||||
{
|
||||
Task UpdateCustomerEmailAddress(string gatewayCustomerId, string emailAddress);
|
||||
}
|
||||
@@ -1,284 +0,0 @@
|
||||
// FIXME: Update this file to be null safe and then delete the line below
|
||||
#nullable disable
|
||||
|
||||
using Bit.Core.Models.BitStripe;
|
||||
using Stripe;
|
||||
using Stripe.Tax;
|
||||
|
||||
namespace Bit.Core.Services;
|
||||
|
||||
public class StripeAdapter : IStripeAdapter
|
||||
{
|
||||
private readonly CustomerService _customerService;
|
||||
private readonly SubscriptionService _subscriptionService;
|
||||
private readonly InvoiceService _invoiceService;
|
||||
private readonly PaymentMethodService _paymentMethodService;
|
||||
private readonly TaxIdService _taxIdService;
|
||||
private readonly ChargeService _chargeService;
|
||||
private readonly RefundService _refundService;
|
||||
private readonly CardService _cardService;
|
||||
private readonly BankAccountService _bankAccountService;
|
||||
private readonly PlanService _planService;
|
||||
private readonly PriceService _priceService;
|
||||
private readonly SetupIntentService _setupIntentService;
|
||||
private readonly Stripe.TestHelpers.TestClockService _testClockService;
|
||||
private readonly CustomerBalanceTransactionService _customerBalanceTransactionService;
|
||||
private readonly Stripe.Tax.RegistrationService _taxRegistrationService;
|
||||
private readonly CalculationService _calculationService;
|
||||
|
||||
public StripeAdapter()
|
||||
{
|
||||
_customerService = new CustomerService();
|
||||
_subscriptionService = new SubscriptionService();
|
||||
_invoiceService = new InvoiceService();
|
||||
_paymentMethodService = new PaymentMethodService();
|
||||
_taxIdService = new TaxIdService();
|
||||
_chargeService = new ChargeService();
|
||||
_refundService = new RefundService();
|
||||
_cardService = new CardService();
|
||||
_bankAccountService = new BankAccountService();
|
||||
_priceService = new PriceService();
|
||||
_planService = new PlanService();
|
||||
_setupIntentService = new SetupIntentService();
|
||||
_testClockService = new Stripe.TestHelpers.TestClockService();
|
||||
_customerBalanceTransactionService = new CustomerBalanceTransactionService();
|
||||
_taxRegistrationService = new Stripe.Tax.RegistrationService();
|
||||
_calculationService = new CalculationService();
|
||||
}
|
||||
|
||||
public Task<Customer> CustomerCreateAsync(CustomerCreateOptions options)
|
||||
{
|
||||
return _customerService.CreateAsync(options);
|
||||
}
|
||||
|
||||
public Task CustomerDeleteDiscountAsync(string customerId, CustomerDeleteDiscountOptions options = null) =>
|
||||
_customerService.DeleteDiscountAsync(customerId, options);
|
||||
|
||||
public Task<Customer> CustomerGetAsync(string id, CustomerGetOptions options = null)
|
||||
{
|
||||
return _customerService.GetAsync(id, options);
|
||||
}
|
||||
|
||||
public Task<Customer> CustomerUpdateAsync(string id, CustomerUpdateOptions options = null)
|
||||
{
|
||||
return _customerService.UpdateAsync(id, options);
|
||||
}
|
||||
|
||||
public Task<Customer> CustomerDeleteAsync(string id)
|
||||
{
|
||||
return _customerService.DeleteAsync(id);
|
||||
}
|
||||
|
||||
public async Task<List<PaymentMethod>> CustomerListPaymentMethods(string id,
|
||||
CustomerPaymentMethodListOptions options = null)
|
||||
{
|
||||
var paymentMethods = await _customerService.ListPaymentMethodsAsync(id, options);
|
||||
return paymentMethods.Data;
|
||||
}
|
||||
|
||||
public async Task<CustomerBalanceTransaction> CustomerBalanceTransactionCreate(string customerId,
|
||||
CustomerBalanceTransactionCreateOptions options)
|
||||
=> await _customerBalanceTransactionService.CreateAsync(customerId, options);
|
||||
|
||||
public Task<Subscription> SubscriptionCreateAsync(SubscriptionCreateOptions options)
|
||||
{
|
||||
return _subscriptionService.CreateAsync(options);
|
||||
}
|
||||
|
||||
public Task<Subscription> SubscriptionGetAsync(string id, SubscriptionGetOptions options = null)
|
||||
{
|
||||
return _subscriptionService.GetAsync(id, options);
|
||||
}
|
||||
|
||||
public async Task<Subscription> ProviderSubscriptionGetAsync(
|
||||
string id,
|
||||
Guid providerId,
|
||||
SubscriptionGetOptions options = null)
|
||||
{
|
||||
var subscription = await _subscriptionService.GetAsync(id, options);
|
||||
if (subscription.Metadata.TryGetValue("providerId", out var value) && value == providerId.ToString())
|
||||
{
|
||||
return subscription;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("Subscription does not belong to the provider.");
|
||||
}
|
||||
|
||||
public Task<Subscription> SubscriptionUpdateAsync(string id,
|
||||
SubscriptionUpdateOptions options = null)
|
||||
{
|
||||
return _subscriptionService.UpdateAsync(id, options);
|
||||
}
|
||||
|
||||
public Task<Subscription> SubscriptionCancelAsync(string Id, SubscriptionCancelOptions options = null)
|
||||
{
|
||||
return _subscriptionService.CancelAsync(Id, options);
|
||||
}
|
||||
|
||||
public Task<Invoice> InvoiceGetAsync(string id, InvoiceGetOptions options)
|
||||
{
|
||||
return _invoiceService.GetAsync(id, options);
|
||||
}
|
||||
|
||||
public async Task<List<Invoice>> InvoiceListAsync(StripeInvoiceListOptions options)
|
||||
{
|
||||
if (!options.SelectAll)
|
||||
{
|
||||
return (await _invoiceService.ListAsync(options.ToInvoiceListOptions())).Data;
|
||||
}
|
||||
|
||||
options.Limit = 100;
|
||||
|
||||
var invoices = new List<Invoice>();
|
||||
|
||||
await foreach (var invoice in _invoiceService.ListAutoPagingAsync(options.ToInvoiceListOptions()))
|
||||
{
|
||||
invoices.Add(invoice);
|
||||
}
|
||||
|
||||
return invoices;
|
||||
}
|
||||
|
||||
public Task<Invoice> InvoiceCreatePreviewAsync(InvoiceCreatePreviewOptions options)
|
||||
{
|
||||
return _invoiceService.CreatePreviewAsync(options);
|
||||
}
|
||||
|
||||
public async Task<List<Invoice>> InvoiceSearchAsync(InvoiceSearchOptions options)
|
||||
=> (await _invoiceService.SearchAsync(options)).Data;
|
||||
|
||||
public Task<Invoice> InvoiceUpdateAsync(string id, InvoiceUpdateOptions options)
|
||||
{
|
||||
return _invoiceService.UpdateAsync(id, options);
|
||||
}
|
||||
|
||||
public Task<Invoice> InvoiceFinalizeInvoiceAsync(string id, InvoiceFinalizeOptions options)
|
||||
{
|
||||
return _invoiceService.FinalizeInvoiceAsync(id, options);
|
||||
}
|
||||
|
||||
public Task<Invoice> InvoiceSendInvoiceAsync(string id, InvoiceSendOptions options)
|
||||
{
|
||||
return _invoiceService.SendInvoiceAsync(id, options);
|
||||
}
|
||||
|
||||
public Task<Invoice> InvoicePayAsync(string id, InvoicePayOptions options = null)
|
||||
{
|
||||
return _invoiceService.PayAsync(id, options);
|
||||
}
|
||||
|
||||
public Task<Invoice> InvoiceDeleteAsync(string id, InvoiceDeleteOptions options = null)
|
||||
{
|
||||
return _invoiceService.DeleteAsync(id, options);
|
||||
}
|
||||
|
||||
public Task<Invoice> InvoiceVoidInvoiceAsync(string id, InvoiceVoidOptions options = null)
|
||||
{
|
||||
return _invoiceService.VoidInvoiceAsync(id, options);
|
||||
}
|
||||
|
||||
public IEnumerable<PaymentMethod> PaymentMethodListAutoPaging(PaymentMethodListOptions options)
|
||||
{
|
||||
return _paymentMethodService.ListAutoPaging(options);
|
||||
}
|
||||
|
||||
public IAsyncEnumerable<PaymentMethod> PaymentMethodListAutoPagingAsync(PaymentMethodListOptions options)
|
||||
=> _paymentMethodService.ListAutoPagingAsync(options);
|
||||
|
||||
public Task<PaymentMethod> PaymentMethodAttachAsync(string id, PaymentMethodAttachOptions options = null)
|
||||
{
|
||||
return _paymentMethodService.AttachAsync(id, options);
|
||||
}
|
||||
|
||||
public Task<PaymentMethod> PaymentMethodDetachAsync(string id, PaymentMethodDetachOptions options = null)
|
||||
{
|
||||
return _paymentMethodService.DetachAsync(id, options);
|
||||
}
|
||||
|
||||
public Task<Plan> PlanGetAsync(string id, PlanGetOptions options = null)
|
||||
{
|
||||
return _planService.GetAsync(id, options);
|
||||
}
|
||||
|
||||
public Task<TaxId> TaxIdCreateAsync(string id, TaxIdCreateOptions options)
|
||||
{
|
||||
return _taxIdService.CreateAsync(id, options);
|
||||
}
|
||||
|
||||
public Task<TaxId> TaxIdDeleteAsync(string customerId, string taxIdId,
|
||||
TaxIdDeleteOptions options = null)
|
||||
{
|
||||
return _taxIdService.DeleteAsync(customerId, taxIdId);
|
||||
}
|
||||
|
||||
public Task<StripeList<Registration>> TaxRegistrationsListAsync(RegistrationListOptions options = null)
|
||||
{
|
||||
return _taxRegistrationService.ListAsync(options);
|
||||
}
|
||||
|
||||
public Task<StripeList<Charge>> ChargeListAsync(ChargeListOptions options)
|
||||
{
|
||||
return _chargeService.ListAsync(options);
|
||||
}
|
||||
|
||||
public Task<Refund> RefundCreateAsync(RefundCreateOptions options)
|
||||
{
|
||||
return _refundService.CreateAsync(options);
|
||||
}
|
||||
|
||||
public Task<Card> CardDeleteAsync(string customerId, string cardId, CardDeleteOptions options = null)
|
||||
{
|
||||
return _cardService.DeleteAsync(customerId, cardId, options);
|
||||
}
|
||||
|
||||
public Task<BankAccount> BankAccountCreateAsync(string customerId, BankAccountCreateOptions options = null)
|
||||
{
|
||||
return _bankAccountService.CreateAsync(customerId, options);
|
||||
}
|
||||
|
||||
public Task<BankAccount> BankAccountDeleteAsync(string customerId, string bankAccount, BankAccountDeleteOptions options = null)
|
||||
{
|
||||
return _bankAccountService.DeleteAsync(customerId, bankAccount, options);
|
||||
}
|
||||
|
||||
public async Task<StripeList<Price>> PriceListAsync(PriceListOptions options = null)
|
||||
{
|
||||
return await _priceService.ListAsync(options);
|
||||
}
|
||||
|
||||
public Task<SetupIntent> SetupIntentCreate(SetupIntentCreateOptions options)
|
||||
=> _setupIntentService.CreateAsync(options);
|
||||
|
||||
public async Task<List<SetupIntent>> SetupIntentList(SetupIntentListOptions options)
|
||||
{
|
||||
var setupIntents = await _setupIntentService.ListAsync(options);
|
||||
|
||||
return setupIntents.Data;
|
||||
}
|
||||
|
||||
public Task SetupIntentCancel(string id, SetupIntentCancelOptions options = null)
|
||||
=> _setupIntentService.CancelAsync(id, options);
|
||||
|
||||
public Task<SetupIntent> SetupIntentGet(string id, SetupIntentGetOptions options = null)
|
||||
=> _setupIntentService.GetAsync(id, options);
|
||||
|
||||
public Task SetupIntentVerifyMicroDeposit(string id, SetupIntentVerifyMicrodepositsOptions options)
|
||||
=> _setupIntentService.VerifyMicrodepositsAsync(id, options);
|
||||
|
||||
public async Task<List<Stripe.TestHelpers.TestClock>> TestClockListAsync()
|
||||
{
|
||||
var items = new List<Stripe.TestHelpers.TestClock>();
|
||||
var options = new Stripe.TestHelpers.TestClockListOptions()
|
||||
{
|
||||
Limit = 100
|
||||
};
|
||||
await foreach (var i in _testClockService.ListAutoPagingAsync(options))
|
||||
{
|
||||
items.Add(i);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
public Task<Price> PriceGetAsync(string id, PriceGetOptions options = null)
|
||||
=> _priceService.GetAsync(id, options);
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public class UserService : UserManager<User>, IUserService
|
||||
private readonly ILicensingService _licenseService;
|
||||
private readonly IEventService _eventService;
|
||||
private readonly IApplicationCacheService _applicationCacheService;
|
||||
private readonly IPaymentService _paymentService;
|
||||
private readonly IStripePaymentService _paymentService;
|
||||
private readonly IPolicyRepository _policyRepository;
|
||||
private readonly IPolicyService _policyService;
|
||||
private readonly IFido2 _fido2;
|
||||
@@ -93,7 +93,7 @@ public class UserService : UserManager<User>, IUserService
|
||||
ILicensingService licenseService,
|
||||
IEventService eventService,
|
||||
IApplicationCacheService applicationCacheService,
|
||||
IPaymentService paymentService,
|
||||
IStripePaymentService paymentService,
|
||||
IPolicyRepository policyRepository,
|
||||
IPolicyService policyService,
|
||||
IFido2 fido2,
|
||||
@@ -534,7 +534,7 @@ public class UserService : UserManager<User>, IUserService
|
||||
|
||||
try
|
||||
{
|
||||
await _stripeSyncService.UpdateCustomerEmailAddress(user.GatewayCustomerId,
|
||||
await _stripeSyncService.UpdateCustomerEmailAddressAsync(user.GatewayCustomerId,
|
||||
user.BillingEmailAddress());
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -867,7 +867,7 @@ public class UserService : UserManager<User>, IUserService
|
||||
}
|
||||
|
||||
string paymentIntentClientSecret = null;
|
||||
IPaymentService paymentService = null;
|
||||
IStripePaymentService paymentService = null;
|
||||
if (_globalSettings.SelfHosted)
|
||||
{
|
||||
if (license == null || !_licenseService.VerifyLicense(license))
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Billing.Services;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.Services;
|
||||
|
||||
namespace Bit.Core.Utilities;
|
||||
|
||||
public static class BillingHelpers
|
||||
{
|
||||
internal static async Task<string> AdjustStorageAsync(IPaymentService paymentService, IStorableSubscriber storableSubscriber,
|
||||
internal static async Task<string> AdjustStorageAsync(IStripePaymentService paymentService, IStorableSubscriber storableSubscriber,
|
||||
short storageAdjustmentGb, string storagePlanId, short baseStorageGb)
|
||||
{
|
||||
if (storableSubscriber == null)
|
||||
|
||||
@@ -238,7 +238,7 @@ public static class ServiceCollectionExtensions
|
||||
PrivateKey = globalSettings.Braintree.PrivateKey
|
||||
};
|
||||
});
|
||||
services.AddScoped<IPaymentService, StripePaymentService>();
|
||||
services.AddScoped<IStripePaymentService, StripePaymentService>();
|
||||
services.AddScoped<IPaymentHistoryService, PaymentHistoryService>();
|
||||
services.AddScoped<ITwoFactorEmailService, TwoFactorEmailService>();
|
||||
// Legacy mailer service
|
||||
|
||||
Reference in New Issue
Block a user