mirror of
https://github.com/bitwarden/server
synced 2025-12-20 18:23:44 +00:00
* feat(billing): add PaymentMethod union * feat(billing): add nontokenized payment method * feat(billing): add validation for tokinized and nontokenized payments * feat(billing): update and add payment method requests * feat(billing): update command with new union object * test(billing): add tests for account credit for user. * feat(billing): update premium cloud hosted subscription request * fix(billing): dotnet format * tests(billing): include payment method tests * fix(billing): clean up tests and converter method
53 lines
2.0 KiB
C#
53 lines
2.0 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using Bit.Api.Billing.Models.Requests.Payment;
|
|
using Bit.Core.Billing.Payment.Models;
|
|
|
|
namespace Bit.Api.Billing.Models.Requests.Premium;
|
|
|
|
public class PremiumCloudHostedSubscriptionRequest : IValidatableObject
|
|
{
|
|
public MinimalTokenizedPaymentMethodRequest? TokenizedPaymentMethod { get; set; }
|
|
public NonTokenizedPaymentMethodRequest? NonTokenizedPaymentMethod { get; set; }
|
|
|
|
[Required]
|
|
public required MinimalBillingAddressRequest BillingAddress { get; set; }
|
|
|
|
[Range(0, 99)]
|
|
public short AdditionalStorageGb { get; set; } = 0;
|
|
|
|
|
|
public (PaymentMethod, BillingAddress, short) ToDomain()
|
|
{
|
|
// Check if TokenizedPaymentMethod or NonTokenizedPaymentMethod is provided.
|
|
var tokenizedPaymentMethod = TokenizedPaymentMethod?.ToDomain();
|
|
var nonTokenizedPaymentMethod = NonTokenizedPaymentMethod?.ToDomain();
|
|
|
|
PaymentMethod paymentMethod = tokenizedPaymentMethod != null
|
|
? tokenizedPaymentMethod
|
|
: nonTokenizedPaymentMethod!;
|
|
|
|
var billingAddress = BillingAddress.ToDomain();
|
|
|
|
return (paymentMethod, billingAddress, AdditionalStorageGb);
|
|
}
|
|
|
|
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
|
{
|
|
if (TokenizedPaymentMethod == null && NonTokenizedPaymentMethod == null)
|
|
{
|
|
yield return new ValidationResult(
|
|
"Either TokenizedPaymentMethod or NonTokenizedPaymentMethod must be provided.",
|
|
new[] { nameof(TokenizedPaymentMethod), nameof(NonTokenizedPaymentMethod) }
|
|
);
|
|
}
|
|
|
|
if (TokenizedPaymentMethod != null && NonTokenizedPaymentMethod != null)
|
|
{
|
|
yield return new ValidationResult(
|
|
"Only one of TokenizedPaymentMethod or NonTokenizedPaymentMethod can be provided.",
|
|
new[] { nameof(TokenizedPaymentMethod), nameof(NonTokenizedPaymentMethod) }
|
|
);
|
|
}
|
|
}
|
|
}
|