mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-06 02:22:22 +01:00
* Opt-in for new checkout * Update wording * Create invoice view update * Remove jQuery from checkout testing code * Checkout v2 basics * WIP * WIP 2 * Updates and fixes * Updates * Design updates * More design updates * Cheating and JS fixes * Use checkout form id whenever invoices get created * Improve email form handling * Cleanups * Payment method exclusion cases for Lightning and LNURL TODO: Cases and implementation need to be discussed * Introduce CheckoutType in API and replace UseNewCheckout in backend Co-authored-by: nicolas.dorier <nicolas.dorier@gmail.com>
55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using BTCPayServer.Data;
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
|
|
namespace BTCPayServer.Services.Stores;
|
|
|
|
public enum GenericFormOption
|
|
{
|
|
[Display(Name = "Inherit from store settings")]
|
|
InheritFromStore,
|
|
|
|
[Display(Name = "Do not request any information")]
|
|
None,
|
|
|
|
[Display(Name = "Request email address only")]
|
|
Email,
|
|
|
|
[Display(Name = "Request shipping address")]
|
|
Address
|
|
}
|
|
|
|
public static class CheckoutFormSelectList
|
|
{
|
|
public static SelectList ForStore(StoreData store, string selectedFormId, bool isStoreEntity)
|
|
{
|
|
var choices = new List<SelectListItem>();
|
|
|
|
if (isStoreEntity)
|
|
{
|
|
var blob = store.GetStoreBlob();
|
|
var inherit = GenericOptionItem(GenericFormOption.InheritFromStore);
|
|
inherit.Text += Enum.TryParse<GenericFormOption>(blob.CheckoutFormId, out var item)
|
|
? $" ({DisplayName(item)})"
|
|
: $" ({blob.CheckoutFormId})";
|
|
|
|
choices.Add(inherit);
|
|
}
|
|
|
|
choices.Add(GenericOptionItem(GenericFormOption.None));
|
|
choices.Add(GenericOptionItem(GenericFormOption.Email));
|
|
choices.Add(GenericOptionItem(GenericFormOption.Address));
|
|
|
|
var chosen = choices.FirstOrDefault(t => t.Value == selectedFormId);
|
|
return new SelectList(choices, nameof(SelectListItem.Value), nameof(SelectListItem.Text), chosen?.Value);
|
|
}
|
|
|
|
private static string DisplayName(GenericFormOption opt) =>
|
|
typeof(GenericFormOption).DisplayName(opt.ToString());
|
|
|
|
private static SelectListItem GenericOptionItem(GenericFormOption opt) =>
|
|
new() { Text = DisplayName(opt), Value = opt.ToString() };
|
|
}
|