mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 08:02:49 -05:00
bitpay invoice api
This commit is contained in:
65
src/Core/Models/Api/Request/BitPayInvoiceRequestModel.cs
Normal file
65
src/Core/Models/Api/Request/BitPayInvoiceRequestModel.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
public class BitPayInvoiceRequestModel : IValidatableObject
|
||||
{
|
||||
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; }
|
||||
public string Email { get; set; }
|
||||
|
||||
public NBitpayClient.Invoice ToBitpayClientInvoice()
|
||||
{
|
||||
var inv = new NBitpayClient.Invoice
|
||||
{
|
||||
Price = Amount.Value,
|
||||
Currency = "USD",
|
||||
RedirectURL = ReturnUrl,
|
||||
BuyerEmail = Email,
|
||||
Buyer = new NBitpayClient.Buyer
|
||||
{
|
||||
email = Email,
|
||||
Name = Name
|
||||
}
|
||||
};
|
||||
|
||||
var posData = string.Empty;
|
||||
if(UserId.HasValue)
|
||||
{
|
||||
posData = "userId:" + UserId.Value;
|
||||
}
|
||||
else if(OrganizationId.HasValue)
|
||||
{
|
||||
posData = "organizationId:" + OrganizationId.Value;
|
||||
}
|
||||
|
||||
if(Credit)
|
||||
{
|
||||
posData += ",accountCredit:1";
|
||||
inv.ItemDesc = "Bitwarden Account Credit";
|
||||
}
|
||||
else
|
||||
{
|
||||
inv.ItemDesc = "Bitwarden";
|
||||
}
|
||||
|
||||
inv.PosData = posData;
|
||||
return inv;
|
||||
}
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(!UserId.HasValue && !OrganizationId.HasValue)
|
||||
{
|
||||
yield return new ValidationResult("User or Ooganization is required.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user