mirror of
https://github.com/bitwarden/server.git
synced 2025-07-05 18:12:48 -05:00
[AC-2959] ACH Direct Debit POC (#4703)
* Refactor: Rename some methods and models for consistency This commit contains no logic changes at all. It's entirely comprised of renames of existing models and methods to bring our codebase more in line with our app's functionality and terminology. * Add feature flag: AC-2476-deprecate-stripe-sources-api * Standardize error responses from applicable billing controllers During my work on CB, I found that just using the built-in TypedResults errors results in the client choking on the response because it's looking for the ErrroResponseModel. The new BaseBillingController provides Error utilities to return TypedResults wrapping that model so the client can process it. * Add feature flagged payment method endoints to OrganizationBillingController * Run dotnet format
This commit is contained in:
@ -12,7 +12,7 @@ public class BillingInfo
|
||||
{
|
||||
public BillingSource() { }
|
||||
|
||||
public BillingSource(PaymentMethod method)
|
||||
public BillingSource(Stripe.PaymentMethod method)
|
||||
{
|
||||
if (method.Card == null)
|
||||
{
|
||||
|
@ -1,8 +1,8 @@
|
||||
namespace Bit.Core.Billing.Models;
|
||||
|
||||
public record OrganizationMetadataDTO(
|
||||
public record OrganizationMetadata(
|
||||
bool IsOnSecretsManagerStandalone)
|
||||
{
|
||||
public static OrganizationMetadataDTO Default() => new(
|
||||
public static OrganizationMetadata Default() => new(
|
||||
IsOnSecretsManagerStandalone: default);
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
namespace Bit.Core.Billing.Models;
|
||||
|
||||
public record PaymentInformationDTO(
|
||||
public record PaymentMethod(
|
||||
long AccountCredit,
|
||||
MaskedPaymentMethodDTO PaymentMethod,
|
||||
PaymentSource PaymentSource,
|
||||
string SubscriptionStatus,
|
||||
TaxInformation TaxInformation);
|
@ -3,12 +3,12 @@ using Bit.Core.Enums;
|
||||
|
||||
namespace Bit.Core.Billing.Models;
|
||||
|
||||
public record MaskedPaymentMethodDTO(
|
||||
public record PaymentSource(
|
||||
PaymentMethodType Type,
|
||||
string Description,
|
||||
bool NeedsVerification)
|
||||
{
|
||||
public static MaskedPaymentMethodDTO From(Stripe.Customer customer)
|
||||
public static PaymentSource From(Stripe.Customer customer)
|
||||
{
|
||||
var defaultPaymentMethod = customer.InvoiceSettings?.DefaultPaymentMethod;
|
||||
|
||||
@ -25,7 +25,7 @@ public record MaskedPaymentMethodDTO(
|
||||
};
|
||||
}
|
||||
|
||||
public static MaskedPaymentMethodDTO From(Stripe.SetupIntent setupIntent)
|
||||
public static PaymentSource From(Stripe.SetupIntent setupIntent)
|
||||
{
|
||||
if (!setupIntent.IsUnverifiedBankAccount())
|
||||
{
|
||||
@ -36,13 +36,13 @@ public record MaskedPaymentMethodDTO(
|
||||
|
||||
var description = $"{bankAccount.BankName}, *{bankAccount.Last4}";
|
||||
|
||||
return new MaskedPaymentMethodDTO(
|
||||
return new PaymentSource(
|
||||
PaymentMethodType.BankAccount,
|
||||
description,
|
||||
true);
|
||||
}
|
||||
|
||||
public static MaskedPaymentMethodDTO From(Braintree.Customer customer)
|
||||
public static PaymentSource From(Braintree.Customer customer)
|
||||
{
|
||||
var defaultPaymentMethod = customer.DefaultPaymentMethod;
|
||||
|
||||
@ -55,7 +55,7 @@ public record MaskedPaymentMethodDTO(
|
||||
{
|
||||
case Braintree.PayPalAccount payPalAccount:
|
||||
{
|
||||
return new MaskedPaymentMethodDTO(
|
||||
return new PaymentSource(
|
||||
PaymentMethodType.PayPal,
|
||||
payPalAccount.Email,
|
||||
false);
|
||||
@ -67,14 +67,14 @@ public record MaskedPaymentMethodDTO(
|
||||
var description =
|
||||
$"{creditCard.CardType}, *{creditCard.LastFour}, {paddedExpirationMonth}/{creditCard.ExpirationYear}";
|
||||
|
||||
return new MaskedPaymentMethodDTO(
|
||||
return new PaymentSource(
|
||||
PaymentMethodType.Card,
|
||||
description,
|
||||
false);
|
||||
}
|
||||
case Braintree.UsBankAccount bankAccount:
|
||||
{
|
||||
return new MaskedPaymentMethodDTO(
|
||||
return new PaymentSource(
|
||||
PaymentMethodType.BankAccount,
|
||||
$"{bankAccount.BankName}, *{bankAccount.Last4}",
|
||||
false);
|
||||
@ -86,18 +86,18 @@ public record MaskedPaymentMethodDTO(
|
||||
}
|
||||
}
|
||||
|
||||
private static MaskedPaymentMethodDTO FromStripeBankAccountPaymentMethod(
|
||||
private static PaymentSource FromStripeBankAccountPaymentMethod(
|
||||
Stripe.PaymentMethodUsBankAccount bankAccount)
|
||||
{
|
||||
var description = $"{bankAccount.BankName}, *{bankAccount.Last4}";
|
||||
|
||||
return new MaskedPaymentMethodDTO(
|
||||
return new PaymentSource(
|
||||
PaymentMethodType.BankAccount,
|
||||
description,
|
||||
false);
|
||||
}
|
||||
|
||||
private static MaskedPaymentMethodDTO FromStripeCardPaymentMethod(Stripe.PaymentMethodCard card)
|
||||
private static PaymentSource FromStripeCardPaymentMethod(Stripe.PaymentMethodCard card)
|
||||
=> new(
|
||||
PaymentMethodType.Card,
|
||||
GetCardDescription(card.Brand, card.Last4, card.ExpMonth, card.ExpYear),
|
||||
@ -105,7 +105,7 @@ public record MaskedPaymentMethodDTO(
|
||||
|
||||
#region Legacy Source Payments
|
||||
|
||||
private static MaskedPaymentMethodDTO FromStripeLegacyPaymentSource(Stripe.IPaymentSource paymentSource)
|
||||
private static PaymentSource FromStripeLegacyPaymentSource(Stripe.IPaymentSource paymentSource)
|
||||
=> paymentSource switch
|
||||
{
|
||||
Stripe.BankAccount bankAccount => FromStripeBankAccountLegacySource(bankAccount),
|
||||
@ -114,7 +114,7 @@ public record MaskedPaymentMethodDTO(
|
||||
_ => null
|
||||
};
|
||||
|
||||
private static MaskedPaymentMethodDTO FromStripeBankAccountLegacySource(Stripe.BankAccount bankAccount)
|
||||
private static PaymentSource FromStripeBankAccountLegacySource(Stripe.BankAccount bankAccount)
|
||||
{
|
||||
var status = bankAccount.Status switch
|
||||
{
|
||||
@ -128,19 +128,19 @@ public record MaskedPaymentMethodDTO(
|
||||
|
||||
var needsVerification = bankAccount.Status is "new" or "validated";
|
||||
|
||||
return new MaskedPaymentMethodDTO(
|
||||
return new PaymentSource(
|
||||
PaymentMethodType.BankAccount,
|
||||
description,
|
||||
needsVerification);
|
||||
}
|
||||
|
||||
private static MaskedPaymentMethodDTO FromStripeCardLegacySource(Stripe.Card card)
|
||||
private static PaymentSource FromStripeCardLegacySource(Stripe.Card card)
|
||||
=> new(
|
||||
PaymentMethodType.Card,
|
||||
GetCardDescription(card.Brand, card.Last4, card.ExpMonth, card.ExpYear),
|
||||
false);
|
||||
|
||||
private static MaskedPaymentMethodDTO FromStripeSourceCardLegacySource(Stripe.SourceCard card)
|
||||
private static PaymentSource FromStripeSourceCardLegacySource(Stripe.SourceCard card)
|
||||
=> new(
|
||||
PaymentMethodType.Card,
|
||||
GetCardDescription(card.Brand, card.Last4, card.ExpMonth, card.ExpYear),
|
@ -2,6 +2,6 @@
|
||||
|
||||
namespace Bit.Core.Billing.Models;
|
||||
|
||||
public record TokenizedPaymentMethodDTO(
|
||||
public record TokenizedPaymentSource(
|
||||
PaymentMethodType Type,
|
||||
string Token);
|
Reference in New Issue
Block a user