Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BEEEP] [PM-18518] Cleanup StripePaymentService #5435

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Core/Billing/Extensions/CustomerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@
/// <returns></returns>
public static bool HasTaxLocationVerified(this Customer customer) =>
customer?.Tax?.AutomaticTax == StripeConstants.AutomaticTaxStatus.Supported;

public static decimal GetBillingBalance(this Customer customer)
{

Check warning on line 18 in src/Core/Billing/Extensions/CustomerExtensions.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Billing/Extensions/CustomerExtensions.cs#L18

Added line #L18 was not covered by tests
return customer != null ? customer.Balance / 100M : default;
}

Check warning on line 20 in src/Core/Billing/Extensions/CustomerExtensions.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Billing/Extensions/CustomerExtensions.cs#L20

Added line #L20 was not covered by tests
}
26 changes: 26 additions & 0 deletions src/Core/Billing/Extensions/SubscriberExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
๏ปฟusing Bit.Core.Entities;

namespace Bit.Core.Billing.Extensions;

public static class SubscriberExtensions
{
/// <summary>
/// We are taking only first 30 characters of the SubscriberName because stripe provide for 30 characters for
/// custom_fields,see the link: https://stripe.com/docs/api/invoices/create
/// </summary>
/// <param name="subscriber"></param>
/// <returns></returns>
public static string GetFormattedInvoiceName(this ISubscriber subscriber)
{
var subscriberName = subscriber.SubscriberName();

if (string.IsNullOrWhiteSpace(subscriberName))
{
return string.Empty;

Check warning on line 19 in src/Core/Billing/Extensions/SubscriberExtensions.cs

View check run for this annotation

Codecov / codecov/patch

src/Core/Billing/Extensions/SubscriberExtensions.cs#L18-L19

Added lines #L18 - L19 were not covered by tests
}

return subscriberName.Length <= 30
? subscriberName
: subscriberName[..30];
}
}
12 changes: 0 additions & 12 deletions src/Core/Services/IPaymentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,8 @@ namespace Bit.Core.Services;
public interface IPaymentService
{
Task CancelAndRecoverChargesAsync(ISubscriber subscriber);
Task<string> PurchaseOrganizationAsync(Organization org, PaymentMethodType paymentMethodType,
string paymentToken, Plan plan, short additionalStorageGb, int additionalSeats,
bool premiumAccessAddon, TaxInfo taxInfo, bool provider = false, int additionalSmSeats = 0,
int additionalServiceAccount = 0, bool signupIsFromSecretsManagerTrial = false);
Task<string> PurchaseOrganizationNoPaymentMethod(Organization org, Plan plan, int additionalSeats,
bool premiumAccessAddon, int additionalSmSeats = 0, int additionalServiceAccount = 0,
bool signupIsFromSecretsManagerTrial = false);
Task SponsorOrganizationAsync(Organization org, OrganizationSponsorship sponsorship);
Task RemoveOrganizationSponsorshipAsync(Organization org, OrganizationSponsorship sponsorship);
Task<string> UpgradeFreeOrganizationAsync(Organization org, Plan plan, OrganizationUpgrade upgrade);
Task<string> PurchasePremiumAsync(User user, PaymentMethodType paymentMethodType, string paymentToken,
short additionalStorageGb, TaxInfo taxInfo);
Task<string> AdjustSubscription(
Organization organization,
Plan updatedPlan,
Expand Down Expand Up @@ -56,9 +46,7 @@ Task<bool> UpdatePaymentMethodAsync(ISubscriber subscriber, PaymentMethodType pa
Task SaveTaxInfoAsync(ISubscriber subscriber, TaxInfo taxInfo);
Task<string> AddSecretsManagerToSubscription(Organization org, Plan plan, int additionalSmSeats,
int additionalServiceAccount);
Task<bool> RisksSubscriptionFailure(Organization organization);
Task<bool> HasSecretsManagerStandalone(Organization organization);
Task<(DateTime?, DateTime?)> GetSuspensionDateAsync(Stripe.Subscription subscription);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one's implementation can be made private

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot that one. It's fixed. Moved a few other methods out that could be made extension methods.

Task<PreviewInvoiceResponseModel> PreviewInvoiceAsync(PreviewIndividualInvoiceRequestBody parameters, string gatewayCustomerId, string gatewaySubscriptionId);
Task<PreviewInvoiceResponseModel> PreviewInvoiceAsync(PreviewOrganizationInvoiceRequestBody parameters, string gatewayCustomerId, string gatewaySubscriptionId);

Expand Down
Loading
Loading