mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 22:14:26 +01:00
Automatic conversion to lower Camel Case for JSON
This commit is contained in:
@@ -142,28 +142,28 @@ namespace BTCPayServer.Controllers
|
|||||||
|
|
||||||
var model = new PaymentModel()
|
var model = new PaymentModel()
|
||||||
{
|
{
|
||||||
serverUrl = HttpContext.Request.GetAbsoluteRoot(),
|
ServerUrl = HttpContext.Request.GetAbsoluteRoot(),
|
||||||
OrderId = invoice.OrderId,
|
OrderId = invoice.OrderId,
|
||||||
invoiceId = invoice.Id,
|
InvoiceId = invoice.Id,
|
||||||
btcAddress = invoice.DepositAddress.ToString(),
|
BtcAddress = invoice.DepositAddress.ToString(),
|
||||||
BTCAmount = (invoice.GetTotalCryptoDue() - invoice.TxFee).ToString(),
|
BtcAmount = (invoice.GetTotalCryptoDue() - invoice.TxFee).ToString(),
|
||||||
BTCTotalDue = invoice.GetTotalCryptoDue().ToString(),
|
BtcTotalDue = invoice.GetTotalCryptoDue().ToString(),
|
||||||
btcDue = invoice.GetCryptoDue().ToString(),
|
BtcDue = invoice.GetCryptoDue().ToString(),
|
||||||
customerEmail = invoice.RefundMail,
|
CustomerEmail = invoice.RefundMail,
|
||||||
expirationSeconds = Math.Max(0, (int)(invoice.ExpirationTime - DateTimeOffset.UtcNow).TotalSeconds),
|
ExpirationSeconds = Math.Max(0, (int)(invoice.ExpirationTime - DateTimeOffset.UtcNow).TotalSeconds),
|
||||||
maxTimeSeconds = (int)(invoice.ExpirationTime - invoice.InvoiceTime).TotalSeconds,
|
MaxTimeSeconds = (int)(invoice.ExpirationTime - invoice.InvoiceTime).TotalSeconds,
|
||||||
ItemDesc = invoice.ProductInformation.ItemDesc,
|
ItemDesc = invoice.ProductInformation.ItemDesc,
|
||||||
Rate = invoice.Rate.ToString("C", GetCurrencyProvider(invoice.ProductInformation.Currency)),
|
Rate = invoice.Rate.ToString("C", GetCurrencyProvider(invoice.ProductInformation.Currency)),
|
||||||
merchantRefLink = invoice.RedirectURL,
|
MerchantRefLink = invoice.RedirectURL,
|
||||||
StoreName = store.StoreName,
|
StoreName = store.StoreName,
|
||||||
TxFees = invoice.TxFee.ToString(),
|
TxFees = invoice.TxFee.ToString(),
|
||||||
InvoiceBitcoinUrl = dto.PaymentUrls.BIP72,
|
InvoiceBitcoinUrl = dto.PaymentUrls.BIP72,
|
||||||
TxCount = invoice.GetTxCount(),
|
TxCount = invoice.GetTxCount(),
|
||||||
BTCPaid = invoice.GetTotalPaid().ToString(),
|
BtcPaid = invoice.GetTotalPaid().ToString(),
|
||||||
status = invoice.Status
|
Status = invoice.Status
|
||||||
};
|
};
|
||||||
|
|
||||||
var expiration = TimeSpan.FromSeconds(model.expirationSeconds);
|
var expiration = TimeSpan.FromSeconds(model.ExpirationSeconds);
|
||||||
model.TimeLeft = PrettyPrint(expiration);
|
model.TimeLeft = PrettyPrint(expiration);
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
using BTCPayServer.Authentication;
|
using BTCPayServer.Authentication;
|
||||||
using BTCPayServer.Configuration;
|
using BTCPayServer.Configuration;
|
||||||
|
using Microsoft.AspNetCore.Html;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -44,5 +47,12 @@ namespace BTCPayServer
|
|||||||
return throws ? throw new UnauthorizedAccessException("no-bitid") : (BitIdentity)null;
|
return throws ? throw new UnauthorizedAccessException("no-bitid") : (BitIdentity)null;
|
||||||
return (BitIdentity)controller.User.Identity;
|
return (BitIdentity)controller.User.Identity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static JsonSerializerSettings jsonSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() };
|
||||||
|
public static HtmlString ToJson(this object o)
|
||||||
|
{
|
||||||
|
var res = JsonConvert.SerializeObject(o, Formatting.None, jsonSettings);
|
||||||
|
return new HtmlString(res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,38 +5,31 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace BTCPayServer.Models.InvoicingModels
|
namespace BTCPayServer.Models.InvoicingModels
|
||||||
{
|
{
|
||||||
// going with lowercase for property names to enable easy ToJson conversion
|
|
||||||
// down the road I can look into mapper who transforms capital into lower case
|
|
||||||
// because of different conventions between server and client side
|
|
||||||
public class PaymentModel
|
public class PaymentModel
|
||||||
{
|
{
|
||||||
public string serverUrl { get; set; }
|
public string ServerUrl { get; set; }
|
||||||
public string invoiceId { get; set; }
|
public string InvoiceId { get; set; }
|
||||||
public string btcAddress { get; set; }
|
public string BtcAddress { get; set; }
|
||||||
public string btcDue { get; set; }
|
public string BtcDue { get; set; }
|
||||||
public string customerEmail { get; set; }
|
public string CustomerEmail { get; set; }
|
||||||
public int expirationSeconds { get; set; }
|
public int ExpirationSeconds { get; set; }
|
||||||
public string status { get; set; }
|
public string Status { get; set; }
|
||||||
public string merchantRefLink { get; set; }
|
public string MerchantRefLink { get; set; }
|
||||||
public int maxTimeSeconds { get; set; }
|
public int MaxTimeSeconds { get; set; }
|
||||||
|
|
||||||
// These properties are still not used in client side code
|
// These properties are not used in client side code
|
||||||
// so will stick with C# notation for now
|
|
||||||
public string StoreName { get; set; }
|
public string StoreName { get; set; }
|
||||||
public string ItemDesc { get; set; }
|
public string ItemDesc { get; set; }
|
||||||
public string TimeLeft { get; set; }
|
public string TimeLeft { get; set; }
|
||||||
public string Rate { get; set; }
|
public string Rate { get; set; }
|
||||||
public string BTCAmount { get; set; }
|
public string BtcAmount { get; set; }
|
||||||
public string TxFees { get; set; }
|
public string TxFees { get; set; }
|
||||||
public string InvoiceBitcoinUrl { get; set; }
|
public string InvoiceBitcoinUrl { get; set; }
|
||||||
public string BTCTotalDue { get; set; }
|
public string BtcTotalDue { get; set; }
|
||||||
public int TxCount { get; set; }
|
public int TxCount { get; set; }
|
||||||
public string BTCPaid { get; set; }
|
public string BtcPaid { get; set; }
|
||||||
public string StoreEmail { get; set; }
|
public string StoreEmail { get; set; }
|
||||||
|
|
||||||
public string OrderId
|
public string OrderId { get; set; }
|
||||||
{
|
|
||||||
get; set;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
crossorigin="anonymous"></script>
|
crossorigin="anonymous"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var srvModel = @Html.Raw(JsonConvert.SerializeObject(Model));
|
var srvModel = @Model.ToJson();
|
||||||
</script>
|
</script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.7.1/clipboard.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.7.1/clipboard.min.js"></script>
|
||||||
<script src="~/js/core.js" type="text/javascript" defer="defer"></script>
|
<script src="~/js/core.js" type="text/javascript" defer="defer"></script>
|
||||||
@@ -113,7 +113,7 @@
|
|||||||
<!---->
|
<!---->
|
||||||
<div class="single-item-order__right">
|
<div class="single-item-order__right">
|
||||||
<div class="single-item-order__right__btc-price clickable" id="buyerTotalBtcAmount">
|
<div class="single-item-order__right__btc-price clickable" id="buyerTotalBtcAmount">
|
||||||
<span>@Model.BTCTotalDue</span>
|
<span>@Model.BtcTotalDue</span>
|
||||||
</div>
|
</div>
|
||||||
<!---->
|
<!---->
|
||||||
<div class="single-item-order__right__ex-rate">
|
<div class="single-item-order__right__ex-rate">
|
||||||
@@ -128,7 +128,7 @@
|
|||||||
<!---->
|
<!---->
|
||||||
<div class="line-items__item">
|
<div class="line-items__item">
|
||||||
<div class="line-items__item__label" i18n="">Payment Amount</div>
|
<div class="line-items__item__label" i18n="">Payment Amount</div>
|
||||||
<div class="line-items__item__value">@Model.BTCAmount BTC</div>
|
<div class="line-items__item__value">@Model.BtcAmount BTC</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="line-items__item">
|
<div class="line-items__item">
|
||||||
<div class="line-items__item__label">
|
<div class="line-items__item__label">
|
||||||
@@ -140,11 +140,11 @@
|
|||||||
<div class="line-items__item__label">
|
<div class="line-items__item__label">
|
||||||
<span i18n="">Already Paid</span>
|
<span i18n="">Already Paid</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="line-items__item__value" i18n="">-@Model.BTCPaid BTC</div>
|
<div class="line-items__item__value" i18n="">-@Model.BtcPaid BTC</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="line-items__item line-items__item--total">
|
<div class="line-items__item line-items__item--total">
|
||||||
<div class="line-items__item__label" i18n="">Due </div>
|
<div class="line-items__item__label" i18n="">Due </div>
|
||||||
<div class="line-items__item__value">@Model.btcDue BTC</div>
|
<div class="line-items__item__value">@Model.BtcDue BTC</div>
|
||||||
</div>
|
</div>
|
||||||
<!---->
|
<!---->
|
||||||
</div>
|
</div>
|
||||||
@@ -363,7 +363,7 @@
|
|||||||
<div class="manual-box__amount__label label" i18n="">Amount</div>
|
<div class="manual-box__amount__label label" i18n="">Amount</div>
|
||||||
<!---->
|
<!---->
|
||||||
<div class="manual-box__amount__value copy-cursor" ngxclipboard="">
|
<div class="manual-box__amount__value copy-cursor" ngxclipboard="">
|
||||||
<span>@Model.btcDue</span> BTC
|
<span>@Model.BtcDue</span> BTC
|
||||||
<div class="copied-label">
|
<div class="copied-label">
|
||||||
<span i18n="">Copied</span>
|
<span i18n="">Copied</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -382,7 +382,7 @@
|
|||||||
<div class="manual-box__address__wrapper__logo">
|
<div class="manual-box__address__wrapper__logo">
|
||||||
<img src="~/img/bitcoin-symbol.svg">
|
<img src="~/img/bitcoin-symbol.svg">
|
||||||
</div>
|
</div>
|
||||||
<div class="manual-box__address__wrapper__value">@Model.btcAddress</div>
|
<div class="manual-box__address__wrapper__value">@Model.BtcAddress</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="copied-label" style="top: 5px;">
|
<div class="copied-label" style="top: 5px;">
|
||||||
<span i18n="">Copied</span>
|
<span i18n="">Copied</span>
|
||||||
@@ -520,7 +520,7 @@
|
|||||||
hours.
|
hours.
|
||||||
</div>
|
</div>
|
||||||
<div class="expired__text">
|
<div class="expired__text">
|
||||||
<span class="expired__text__bullet" i18n="">Invoice ID:</span> @Model.invoiceId<br>
|
<span class="expired__text__bullet" i18n="">Invoice ID:</span> @Model.InvoiceId<br>
|
||||||
<!---->
|
<!---->
|
||||||
<span>
|
<span>
|
||||||
<span class="expired__text__bullet" i18n="">Order ID:</span> @Model.OrderId
|
<span class="expired__text__bullet" i18n="">Order ID:</span> @Model.OrderId
|
||||||
|
|||||||
@@ -5,5 +5,4 @@
|
|||||||
@using BTCPayServer.Models.InvoicingModels
|
@using BTCPayServer.Models.InvoicingModels
|
||||||
@using BTCPayServer.Models.ManageViewModels
|
@using BTCPayServer.Models.ManageViewModels
|
||||||
@using BTCPayServer.Models.StoreViewModels
|
@using BTCPayServer.Models.StoreViewModels
|
||||||
@using Newtonsoft.Json;
|
|
||||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
|
|||||||
Reference in New Issue
Block a user