2019-01-14 22:43:29 +01:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2022-11-02 18:41:19 +09:00
|
|
|
using System.Linq;
|
2020-10-23 10:37:28 +02:00
|
|
|
using BTCPayServer.Client.Models;
|
2019-08-30 00:24:42 +09:00
|
|
|
using BTCPayServer.Data;
|
2020-10-23 10:37:28 +02:00
|
|
|
using BTCPayServer.Services.Invoices;
|
2019-01-14 22:43:29 +01:00
|
|
|
using BTCPayServer.Services.Rates;
|
2022-06-23 13:41:52 +09:00
|
|
|
using BTCPayServer.Validation;
|
2019-01-14 22:43:29 +01:00
|
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
2022-11-25 02:42:55 +01:00
|
|
|
using Newtonsoft.Json.Linq;
|
2020-05-19 19:59:23 +02:00
|
|
|
using PaymentRequestData = BTCPayServer.Data.PaymentRequestData;
|
2019-01-14 22:43:29 +01:00
|
|
|
|
|
|
|
namespace BTCPayServer.Models.PaymentRequestViewModels
|
|
|
|
{
|
2020-07-19 17:04:29 -05:00
|
|
|
public class ListPaymentRequestsViewModel : BasePagingViewModel
|
2019-01-14 22:43:29 +01:00
|
|
|
{
|
|
|
|
public List<ViewPaymentRequestViewModel> Items { get; set; }
|
2022-05-02 16:35:28 +09:00
|
|
|
public override int CurrentPageCount => Items.Count;
|
2019-01-14 22:43:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public class UpdatePaymentRequestViewModel
|
|
|
|
{
|
|
|
|
public UpdatePaymentRequestViewModel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public UpdatePaymentRequestViewModel(PaymentRequestData data)
|
|
|
|
{
|
|
|
|
if (data == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Id = data.Id;
|
|
|
|
StoreId = data.StoreDataId;
|
2020-05-08 12:33:47 +02:00
|
|
|
Archived = data.Archived;
|
2019-01-14 22:43:29 +01:00
|
|
|
var blob = data.GetBlob();
|
2022-11-25 02:42:55 +01:00
|
|
|
FormId = blob.FormId;
|
2019-01-14 22:43:29 +01:00
|
|
|
Title = blob.Title;
|
|
|
|
Amount = blob.Amount;
|
|
|
|
Currency = blob.Currency;
|
|
|
|
Description = blob.Description;
|
2022-01-11 18:42:44 +09:00
|
|
|
ExpiryDate = blob.ExpiryDate?.UtcDateTime;
|
2019-01-14 22:43:29 +01:00
|
|
|
Email = blob.Email;
|
|
|
|
CustomCSSLink = blob.CustomCSSLink;
|
|
|
|
EmbeddedCSS = blob.EmbeddedCSS;
|
|
|
|
AllowCustomPaymentAmounts = blob.AllowCustomPaymentAmounts;
|
2022-11-25 02:42:55 +01:00
|
|
|
FormResponse = blob.FormResponse is null
|
|
|
|
? null
|
|
|
|
: blob.FormResponse.ToObject<Dictionary<string, object>>();
|
2019-01-14 22:43:29 +01:00
|
|
|
}
|
|
|
|
|
2022-11-25 02:42:55 +01:00
|
|
|
[Display(Name = "Request customer data on checkout")]
|
|
|
|
public string FormId { get; set; }
|
|
|
|
|
2020-05-08 12:33:47 +02:00
|
|
|
public bool Archived { get; set; }
|
|
|
|
|
2019-01-14 22:43:29 +01:00
|
|
|
public string Id { get; set; }
|
|
|
|
[Required] public string StoreId { get; set; }
|
2019-08-21 17:05:06 +03:00
|
|
|
|
|
|
|
[Required]
|
2020-03-17 08:03:12 +01:00
|
|
|
[Range(double.Epsilon, double.PositiveInfinity, ErrorMessage = "Please provide an amount greater than 0")]
|
2019-08-21 17:05:06 +03:00
|
|
|
public decimal Amount { get; set; }
|
2019-01-14 22:43:29 +01:00
|
|
|
|
2022-01-11 05:16:16 -08:00
|
|
|
[Display(Name = "Currency")]
|
2019-01-14 22:43:29 +01:00
|
|
|
public string Currency { get; set; }
|
|
|
|
|
|
|
|
[Display(Name = "Expiration Date")]
|
|
|
|
public DateTime? ExpiryDate { get; set; }
|
|
|
|
[Required] public string Title { get; set; }
|
|
|
|
public string Description { get; set; }
|
|
|
|
|
2021-10-25 00:15:08 -04:00
|
|
|
[Display(Name = "Store")]
|
2019-01-14 22:43:29 +01:00
|
|
|
public SelectList Stores { get; set; }
|
2021-12-31 16:59:02 +09:00
|
|
|
|
2022-06-23 13:41:52 +09:00
|
|
|
[MailboxAddress]
|
2019-01-14 22:43:29 +01:00
|
|
|
public string Email { get; set; }
|
2020-06-28 17:55:27 +09:00
|
|
|
|
2019-01-14 22:43:29 +01:00
|
|
|
[MaxLength(500)]
|
2021-07-23 03:57:19 -07:00
|
|
|
[Display(Name = "Custom CSS URL")]
|
2019-01-14 22:43:29 +01:00
|
|
|
public string CustomCSSLink { get; set; }
|
|
|
|
|
|
|
|
[Display(Name = "Custom CSS Code")]
|
2020-06-28 17:55:27 +09:00
|
|
|
public string EmbeddedCSS { get; set; }
|
2019-01-14 22:43:29 +01:00
|
|
|
[Display(Name = "Allow payee to create invoices in their own denomination")]
|
|
|
|
public bool AllowCustomPaymentAmounts { get; set; }
|
2022-11-25 02:42:55 +01:00
|
|
|
|
|
|
|
public Dictionary<string, object> FormResponse { get; set; }
|
2022-12-13 21:01:48 -08:00
|
|
|
public bool AmountAndCurrencyEditable { get; set; } = true;
|
2019-01-14 22:43:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public class ViewPaymentRequestViewModel
|
|
|
|
{
|
|
|
|
public ViewPaymentRequestViewModel(PaymentRequestData data)
|
|
|
|
{
|
|
|
|
Id = data.Id;
|
2021-12-11 04:32:23 +01:00
|
|
|
StoreId = data.StoreDataId;
|
2019-01-14 22:43:29 +01:00
|
|
|
var blob = data.GetBlob();
|
2020-05-08 12:33:47 +02:00
|
|
|
Archived = data.Archived;
|
2019-01-14 22:43:29 +01:00
|
|
|
Title = blob.Title;
|
|
|
|
Amount = blob.Amount;
|
|
|
|
Currency = blob.Currency;
|
|
|
|
Description = blob.Description;
|
2022-01-11 18:42:44 +09:00
|
|
|
ExpiryDate = blob.ExpiryDate?.UtcDateTime;
|
2019-01-14 22:43:29 +01:00
|
|
|
Email = blob.Email;
|
|
|
|
EmbeddedCSS = blob.EmbeddedCSS;
|
|
|
|
CustomCSSLink = blob.CustomCSSLink;
|
|
|
|
AllowCustomPaymentAmounts = blob.AllowCustomPaymentAmounts;
|
2019-08-10 14:53:24 +09:00
|
|
|
if (!string.IsNullOrEmpty(EmbeddedCSS))
|
|
|
|
EmbeddedCSS = $"<style>{EmbeddedCSS}</style>";
|
2019-01-14 22:43:29 +01:00
|
|
|
switch (data.Status)
|
|
|
|
{
|
2020-05-19 19:59:23 +02:00
|
|
|
case Client.Models.PaymentRequestData.PaymentRequestStatus.Pending:
|
2022-11-18 05:24:57 +01:00
|
|
|
Status = "Pending";
|
2019-01-14 22:43:29 +01:00
|
|
|
IsPending = true;
|
|
|
|
break;
|
2020-05-19 19:59:23 +02:00
|
|
|
case Client.Models.PaymentRequestData.PaymentRequestStatus.Completed:
|
2019-01-14 22:43:29 +01:00
|
|
|
Status = "Settled";
|
|
|
|
break;
|
2020-05-19 19:59:23 +02:00
|
|
|
case Client.Models.PaymentRequestData.PaymentRequestStatus.Expired:
|
2019-01-14 22:43:29 +01:00
|
|
|
Status = "Expired";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool AllowCustomPaymentAmounts { get; set; }
|
|
|
|
public string Email { get; set; }
|
|
|
|
public string Status { get; set; }
|
|
|
|
public bool IsPending { get; set; }
|
|
|
|
public decimal AmountCollected { get; set; }
|
|
|
|
public decimal AmountDue { get; set; }
|
|
|
|
public string AmountDueFormatted { get; set; }
|
|
|
|
public decimal Amount { get; set; }
|
|
|
|
public string Id { get; set; }
|
2021-12-11 04:32:23 +01:00
|
|
|
public string StoreId { get; set; }
|
2019-01-14 22:43:29 +01:00
|
|
|
public string Currency { get; set; }
|
|
|
|
public DateTime? ExpiryDate { get; set; }
|
|
|
|
public string Title { get; set; }
|
|
|
|
public string Description { get; set; }
|
2023-01-30 09:23:49 +01:00
|
|
|
public string LogoFileId { get; set; }
|
|
|
|
public string CssFileId { get; set; }
|
|
|
|
public string BrandColor { get; set; }
|
|
|
|
public string StoreName { get; set; }
|
2019-01-14 22:43:29 +01:00
|
|
|
public string EmbeddedCSS { get; set; }
|
|
|
|
public string CustomCSSLink { get; set; }
|
2022-11-02 18:41:19 +09:00
|
|
|
|
|
|
|
#nullable enable
|
|
|
|
public class InvoiceList : List<PaymentRequestInvoice>
|
|
|
|
{
|
|
|
|
static HashSet<InvoiceState> stateAllowedToDisplay = new HashSet<InvoiceState>
|
|
|
|
{
|
|
|
|
new InvoiceState(InvoiceStatusLegacy.New, InvoiceExceptionStatus.None),
|
|
|
|
new InvoiceState(InvoiceStatusLegacy.New, InvoiceExceptionStatus.PaidPartial),
|
|
|
|
};
|
|
|
|
public InvoiceList()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
public InvoiceList(IEnumerable<PaymentRequestInvoice> collection) : base(collection)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
public PaymentRequestInvoice? GetReusableInvoice(decimal? amount)
|
|
|
|
{
|
|
|
|
return this
|
|
|
|
.Where(i => amount is null || amount.Value == i.Amount)
|
|
|
|
.FirstOrDefault(invoice => stateAllowedToDisplay.Contains(invoice.State));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#nullable restore
|
|
|
|
public InvoiceList Invoices { get; set; } = new InvoiceList();
|
2019-01-14 22:43:29 +01:00
|
|
|
public DateTime LastUpdated { get; set; }
|
|
|
|
public CurrencyData CurrencyData { get; set; }
|
|
|
|
public string AmountCollectedFormatted { get; set; }
|
|
|
|
public string AmountFormatted { get; set; }
|
|
|
|
public bool AnyPendingInvoice { get; set; }
|
2019-05-07 08:26:40 +00:00
|
|
|
public bool PendingInvoiceHasPayments { get; set; }
|
2019-03-09 16:08:31 +09:00
|
|
|
public string HubPath { get; set; }
|
2020-05-08 12:33:47 +02:00
|
|
|
public bool Archived { get; set; }
|
2022-11-25 02:42:55 +01:00
|
|
|
public string FormId { get; set; }
|
|
|
|
public bool FormSubmitted { get; set; }
|
2019-01-14 22:43:29 +01:00
|
|
|
|
|
|
|
public class PaymentRequestInvoice
|
|
|
|
{
|
|
|
|
public string Id { get; set; }
|
|
|
|
public DateTime ExpiryDate { get; set; }
|
|
|
|
public decimal Amount { get; set; }
|
2019-03-03 16:51:19 -06:00
|
|
|
public string AmountFormatted { get; set; }
|
2020-10-23 10:37:28 +02:00
|
|
|
public InvoiceState State { get; set; }
|
2020-11-23 15:57:05 +09:00
|
|
|
public InvoiceStatusLegacy Status { get; set; }
|
2020-10-23 21:00:23 +09:00
|
|
|
public string StateFormatted { get; set; }
|
2019-01-14 22:43:29 +01:00
|
|
|
|
|
|
|
public List<PaymentRequestInvoicePayment> Payments { get; set; }
|
|
|
|
public string Currency { get; set; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public class PaymentRequestInvoicePayment
|
|
|
|
{
|
|
|
|
public string PaymentMethod { get; set; }
|
|
|
|
public decimal Amount { get; set; }
|
2020-10-23 10:37:28 +02:00
|
|
|
public string RateFormatted { get; set; }
|
|
|
|
public decimal Paid { get; set; }
|
|
|
|
public string PaidFormatted { get; set; }
|
|
|
|
public DateTime ReceivedDate { get; set; }
|
2019-01-14 22:43:29 +01:00
|
|
|
public string Link { get; set; }
|
|
|
|
public string Id { get; set; }
|
2021-08-04 09:13:33 +02:00
|
|
|
public string Destination { get; set; }
|
2019-01-14 22:43:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|