Files
server/src/Api/Models/Request/BitPayInvoiceRequestModel.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

66 lines
1.8 KiB
C#
Raw Normal View History

using System.ComponentModel.DataAnnotations;
using Bit.Core.Settings;
2019-02-21 22:43:37 -05:00
2021-12-14 15:05:07 +00:00
namespace Bit.Api.Models.Request;
2022-08-29 16:06:55 -04:00
2021-12-14 15:05:07 +00:00
public class BitPayInvoiceRequestModel : IValidatableObject
2019-02-21 22:43:37 -05:00
{
public Guid? UserId { get; set; }
public Guid? OrganizationId { get; set; }
public bool Credit { get; set; }
[Required]
public decimal? Amount { get; set; }
public string ReturnUrl { get; set; }
public string Name { get; set; }
2019-02-21 22:43:37 -05:00
public string Email { get; set; }
public BitPayLight.Models.Invoice.Invoice ToBitpayInvoice(GlobalSettings globalSettings)
2022-08-29 16:06:55 -04:00
{
var inv = new BitPayLight.Models.Invoice.Invoice
2019-02-21 22:43:37 -05:00
{
Price = Convert.ToDouble(Amount.Value),
2019-02-21 22:43:37 -05:00
Currency = "USD",
RedirectUrl = ReturnUrl,
Buyer = new BitPayLight.Models.Invoice.Buyer
2019-02-21 22:43:37 -05:00
{
Email = Email,
Name = Name
2022-08-29 16:06:55 -04:00
},
2019-02-21 22:43:37 -05:00
NotificationUrl = globalSettings.BitPay.NotificationUrl,
FullNotifications = true,
2019-02-21 22:43:37 -05:00
ExtendedNotifications = true
};
var posData = string.Empty;
if (UserId.HasValue)
2022-08-29 14:53:16 -04:00
{
2019-02-21 22:43:37 -05:00
posData = "userId:" + UserId.Value;
2022-08-29 14:53:16 -04:00
}
else if (OrganizationId.HasValue)
{
2019-02-21 22:43:37 -05:00
posData = "organizationId:" + OrganizationId.Value;
}
if (Credit)
2022-08-29 16:06:55 -04:00
{
2019-02-21 22:43:37 -05:00
posData += ",accountCredit:1";
2022-08-29 14:53:16 -04:00
inv.ItemDesc = "Bitwarden Account Credit";
2022-08-29 16:06:55 -04:00
}
else
{
2019-02-21 22:43:37 -05:00
inv.ItemDesc = "Bitwarden";
2022-08-29 14:53:16 -04:00
}
2019-02-21 22:43:37 -05:00
inv.PosData = posData;
2022-08-29 16:06:55 -04:00
return inv;
}
2019-02-21 22:43:37 -05:00
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
2022-08-29 16:06:55 -04:00
{
if (!UserId.HasValue && !OrganizationId.HasValue)
2019-02-21 22:43:37 -05:00
{
yield return new ValidationResult("User or Ooganization is required.");
}
}
}