1
0
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:
Kyle Spearrin
2019-02-21 22:43:37 -05:00
parent d514fcdaeb
commit fdaa9504d5
11 changed files with 144 additions and 0 deletions

View 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.");
}
}
}
}