btcpayserver/BTCPayServer/Views/AppsPublic/PointOfSale/Print.cshtml

91 lines
3.8 KiB
Text
Raw Normal View History

2021-10-29 10:27:33 +02:00
@using BTCPayServer.Models.AppViewModels
@using BTCPayServer.Payments.Lightning
@using LNURL
@inject BTCPayNetworkProvider BTCPayNetworkProvider
@model BTCPayServer.Models.AppViewModels.ViewPointOfSaleViewModel
<style>
/* This hides unwanted metadata such as url, date, etc from appearing on a printed page. */
@@media print {
@@page {
margin-top: 0;
margin-bottom: 0;
}
}
.card { display: inline-block; width: 300px; page-break-inside: avoid; margin: 2em 1em 0 1em; }
</style>
2021-10-29 10:27:33 +02:00
@{
Layout = "_LayoutPos";
2021-10-29 10:27:33 +02:00
Context.Request.Query.TryGetValue("cryptocode", out var cryptoCodeValues);
var cryptoCode = cryptoCodeValues.FirstOrDefault() ?? "BTC";
var supported = Model.Store.GetSupportedPaymentMethods(BTCPayNetworkProvider).OfType<LNURLPaySupportedPaymentMethod>().OrderBy(method => method.CryptoCode == cryptoCode).FirstOrDefault();
if (supported != null && !Model.Store.GetEnabledPaymentIds(BTCPayNetworkProvider).Contains(supported.PaymentId))
{
supported = null;
}
}
2021-10-29 10:27:33 +02:00
@if (supported is null)
{
<div class="alert alert-warning text-center sticky-top mb-0 rounded-0" role="alert">
LNURL is not enabled on your store, which this print feature relies on.
<a asp-action="PaymentMethods" asp-controller="Stores" asp-route-storeId="@Model.Store.Id" class="alert-link p-0">
Enable LNURL
</a>
</div>
}
else
{
<div class="alert alert-info d-flex align-items-center justify-content-center sticky-top mb-0 rounded-0 d-print-none" role="alert">
<button type="button" class="btn btn-info me-4 border border-light" onclick="window.print()">
<i class="fa fa-print"></i>&nbsp;Print
</button>
This view is intended for printing only —
<a asp-route-viewType="static" class="alert-link">Regular version</a>
2021-10-29 10:27:33 +02:00
</div>
}
<div class="container text-center">
@for (int x = 0; x < Model.Items.Length; x++)
{
var item = Model.Items[x];
<div class="card" data-id="@x">
<div class="card-body my-auto">
<h4 class="card-title text-center">@item.Title</h4>
<div class="w-100 mb-3 fs-5 text-center">
@switch (item.Price.Type)
2021-10-29 10:27:33 +02:00
{
case ViewPointOfSaleViewModel.Item.ItemPrice.ItemPriceType.Topup:
<span>Any amount</span>
break;
case ViewPointOfSaleViewModel.Item.ItemPrice.ItemPriceType.Minimum:
<span>@item.Price.Formatted minimum</span>
break;
case ViewPointOfSaleViewModel.Item.ItemPrice.ItemPriceType.Fixed:
@item.Price.Formatted
break;
default:
throw new ArgumentOutOfRangeException();
2021-10-29 10:27:33 +02:00
}
</div>
@if (!item.Inventory.HasValue || item.Inventory.Value > 0)
{
if (supported != null)
{
var lnurlEndpoint = new Uri(Url.Action("GetLNURLForApp", "LNURL", new
{
cryptoCode = supported.CryptoCode,
appid = Model.AppId,
ItemCode = item.Id
}, Context.Request.Scheme, Context.Request.Host.ToString()));
var lnUrl = LNURL.EncodeUri(lnurlEndpoint, "payRequest", supported.UseBech32Scheme);
<a href="@lnUrl" rel="noreferrer noopener"><vc:qr-code data="@lnUrl.ToString().ToUpperInvariant()" /></a>
}
}
</div>
2021-10-29 10:27:33 +02:00
</div>
}
</div>