mirror of
https://github.com/bitwarden/server
synced 2025-12-26 13:13:24 +00:00
billing info and tx management tools
This commit is contained in:
12
src/Admin/Models/BillingInformationModel.cs
Normal file
12
src/Admin/Models/BillingInformationModel.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using Bit.Core.Models.Business;
|
||||
|
||||
namespace Bit.Admin.Models
|
||||
{
|
||||
public class BillingInformationModel
|
||||
{
|
||||
public BillingInfo BillingInfo { get; set; }
|
||||
public Guid? UserId { get; set; }
|
||||
public Guid? OrganizationId { get; set; }
|
||||
}
|
||||
}
|
||||
80
src/Admin/Models/CreateUpdateTransactionModel.cs
Normal file
80
src/Admin/Models/CreateUpdateTransactionModel.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Admin.Models
|
||||
{
|
||||
public class CreateUpdateTransactionModel : IValidatableObject
|
||||
{
|
||||
public CreateUpdateTransactionModel() { }
|
||||
|
||||
public CreateUpdateTransactionModel(Transaction transaction)
|
||||
{
|
||||
Edit = true;
|
||||
UserId = transaction.UserId;
|
||||
OrganizationId = transaction.OrganizationId;
|
||||
Amount = transaction.Amount;
|
||||
RefundedAmount = transaction.RefundedAmount;
|
||||
Refunded = transaction.Refunded.GetValueOrDefault();
|
||||
Details = transaction.Details;
|
||||
Date = transaction.CreationDate;
|
||||
PaymentMethod = transaction.PaymentMethodType;
|
||||
Gateway = transaction.Gateway;
|
||||
GatewayId = transaction.GatewayId;
|
||||
Type = transaction.Type;
|
||||
}
|
||||
|
||||
public bool Edit { get; set; }
|
||||
|
||||
[Display(Name = "User Id")]
|
||||
public Guid? UserId { get; set; }
|
||||
[Display(Name = "Organization Id")]
|
||||
public Guid? OrganizationId { get; set; }
|
||||
[Required]
|
||||
public decimal? Amount { get; set; }
|
||||
[Display(Name = "Refunded Amount")]
|
||||
public decimal? RefundedAmount { get; set; }
|
||||
public bool Refunded { get; set; }
|
||||
[Required]
|
||||
public string Details { get; set; }
|
||||
[Required]
|
||||
public DateTime? Date { get; set; }
|
||||
[Display(Name = "Payment Method")]
|
||||
public PaymentMethodType? PaymentMethod { get; set; }
|
||||
public GatewayType? Gateway { get; set; }
|
||||
[Display(Name = "Gateway Id")]
|
||||
public string GatewayId { get; set; }
|
||||
[Required]
|
||||
public TransactionType? Type { get; set; }
|
||||
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if((!UserId.HasValue && !OrganizationId.HasValue) || (UserId.HasValue && OrganizationId.HasValue))
|
||||
{
|
||||
yield return new ValidationResult("Must provide either User Id, or Organization Id.");
|
||||
}
|
||||
}
|
||||
|
||||
public Transaction ToTransaction(Guid? id = null)
|
||||
{
|
||||
return new Transaction
|
||||
{
|
||||
Id = id.GetValueOrDefault(),
|
||||
UserId = UserId,
|
||||
OrganizationId = OrganizationId,
|
||||
Amount = Amount.Value,
|
||||
RefundedAmount = RefundedAmount,
|
||||
Refunded = Refunded ? true : (bool?)null,
|
||||
Details = Details,
|
||||
CreationDate = Date.Value,
|
||||
PaymentMethodType = PaymentMethod,
|
||||
Gateway = Gateway,
|
||||
GatewayId = GatewayId,
|
||||
Type = Type.Value
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Admin.Models
|
||||
{
|
||||
public class TransactionViewModel
|
||||
{
|
||||
public TransactionViewModel() { }
|
||||
|
||||
public TransactionViewModel(User user, IEnumerable<Cipher> ciphers)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ namespace Bit.Admin.Models
|
||||
LicenseKey = user.LicenseKey;
|
||||
PremiumExpirationDate = user.PremiumExpirationDate;
|
||||
}
|
||||
|
||||
|
||||
public BillingInfo BillingInfo { get; set; }
|
||||
public string RandomLicenseKey => CoreHelpers.SecureRandomString(20);
|
||||
public string OneYearExpirationDate => DateTime.Now.AddYears(1).ToString("yyyy-MM-ddTHH:mm");
|
||||
|
||||
Reference in New Issue
Block a user