mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 05:54:26 +01:00
Minor refactorings
This commit is contained in:
@@ -36,6 +36,17 @@ public static class HttpRequestExtensions
|
|||||||
request.Path.ToUriComponent());
|
request.Path.ToUriComponent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetCurrentUrlWithQueryString(this HttpRequest request)
|
||||||
|
{
|
||||||
|
return string.Concat(
|
||||||
|
request.Scheme,
|
||||||
|
"://",
|
||||||
|
request.Host.ToUriComponent(),
|
||||||
|
request.PathBase.ToUriComponent(),
|
||||||
|
request.Path.ToUriComponent(),
|
||||||
|
request.QueryString.ToUriComponent());
|
||||||
|
}
|
||||||
|
|
||||||
public static string GetCurrentPath(this HttpRequest request)
|
public static string GetCurrentPath(this HttpRequest request)
|
||||||
{
|
{
|
||||||
return string.Concat(
|
return string.Concat(
|
||||||
|
|||||||
@@ -409,7 +409,7 @@ namespace BTCPayServer.Tests
|
|||||||
}, evt => evt.InvoiceId == invoice.Id);
|
}, evt => evt.InvoiceId == invoice.Id);
|
||||||
|
|
||||||
var fetchedInvoice = await tester.PayTester.InvoiceRepository.GetInvoice(evt.InvoiceId);
|
var fetchedInvoice = await tester.PayTester.InvoiceRepository.GetInvoice(evt.InvoiceId);
|
||||||
Assert.Equal(fetchedInvoice.Status, InvoiceStatus.Settled);
|
Assert.Equal(InvoiceStatus.Settled, fetchedInvoice.Status);
|
||||||
Assert.Equal(InvoiceExceptionStatus.None, fetchedInvoice.ExceptionStatus);
|
Assert.Equal(InvoiceExceptionStatus.None, fetchedInvoice.ExceptionStatus);
|
||||||
|
|
||||||
//BTCPay will attempt to cancel previous bolt11 invoices so that there are less weird edge case scenarios
|
//BTCPay will attempt to cancel previous bolt11 invoices so that there are less weird edge case scenarios
|
||||||
|
|||||||
@@ -154,19 +154,7 @@ namespace BTCPayServer.Controllers.Greenfield
|
|||||||
}
|
}
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return this.CreateValidationError(ModelState);
|
return this.CreateValidationError(ModelState);
|
||||||
var ppId = await _pullPaymentService.CreatePullPayment(new CreatePullPayment()
|
var ppId = await _pullPaymentService.CreatePullPayment(storeId, request);
|
||||||
{
|
|
||||||
StartsAt = request.StartsAt,
|
|
||||||
ExpiresAt = request.ExpiresAt,
|
|
||||||
BOLT11Expiration = request.BOLT11Expiration,
|
|
||||||
Name = request.Name,
|
|
||||||
Description = request.Description,
|
|
||||||
Amount = request.Amount,
|
|
||||||
Currency = request.Currency,
|
|
||||||
StoreId = storeId,
|
|
||||||
PayoutMethodIds = payoutMethods,
|
|
||||||
AutoApproveClaims = request.AutoApproveClaims
|
|
||||||
});
|
|
||||||
var pp = await _pullPaymentService.GetPullPayment(ppId, false);
|
var pp = await _pullPaymentService.GetPullPayment(ppId, false);
|
||||||
return this.Ok(CreatePullPaymentData(pp));
|
return this.Ok(CreatePullPaymentData(pp));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -502,7 +502,7 @@ namespace BTCPayServer
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<IActionResult> GetLNURLRequest(
|
public async Task<IActionResult> GetLNURLRequest(
|
||||||
string cryptoCode,
|
string cryptoCode,
|
||||||
Data.StoreData store,
|
Data.StoreData store,
|
||||||
Data.StoreBlob blob,
|
Data.StoreBlob blob,
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace BTCPayServer.HostedServices
|
|||||||
public class PullPaymentHostedService : BaseAsyncService
|
public class PullPaymentHostedService : BaseAsyncService
|
||||||
{
|
{
|
||||||
private readonly string[] _lnurlSupportedCurrencies = { "BTC", "SATS" };
|
private readonly string[] _lnurlSupportedCurrencies = { "BTC", "SATS" };
|
||||||
|
|
||||||
public class CancelRequest
|
public class CancelRequest
|
||||||
{
|
{
|
||||||
public CancelRequest(string pullPaymentId)
|
public CancelRequest(string pullPaymentId)
|
||||||
@@ -106,7 +106,22 @@ namespace BTCPayServer.HostedServices
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public Task<string> CreatePullPayment(string storeId, CreatePullPaymentRequest request)
|
||||||
|
{
|
||||||
|
return CreatePullPayment(new CreatePullPayment()
|
||||||
|
{
|
||||||
|
StartsAt = request.StartsAt,
|
||||||
|
ExpiresAt = request.ExpiresAt,
|
||||||
|
BOLT11Expiration = request.BOLT11Expiration,
|
||||||
|
Name = request.Name,
|
||||||
|
Description = request.Description,
|
||||||
|
Amount = request.Amount,
|
||||||
|
Currency = request.Currency,
|
||||||
|
StoreId = storeId,
|
||||||
|
PayoutMethodIds = request.PaymentMethods.Select(p => PayoutMethodId.Parse(p)).ToArray(),
|
||||||
|
AutoApproveClaims = request.AutoApproveClaims
|
||||||
|
});
|
||||||
|
}
|
||||||
public async Task<string> CreatePullPayment(CreatePullPayment create)
|
public async Task<string> CreatePullPayment(CreatePullPayment create)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(create);
|
ArgumentNullException.ThrowIfNull(create);
|
||||||
@@ -373,7 +388,7 @@ namespace BTCPayServer.HostedServices
|
|||||||
|
|
||||||
public bool SupportsLNURL(PullPaymentBlob blob)
|
public bool SupportsLNURL(PullPaymentBlob blob)
|
||||||
{
|
{
|
||||||
var pms = blob.SupportedPaymentMethods.FirstOrDefault(id =>
|
var pms = blob.SupportedPaymentMethods.FirstOrDefault(id =>
|
||||||
PayoutTypes.LN.GetPayoutMethodId(_networkProvider.DefaultNetwork.CryptoCode)
|
PayoutTypes.LN.GetPayoutMethodId(_networkProvider.DefaultNetwork.CryptoCode)
|
||||||
== id);
|
== id);
|
||||||
return pms is not null && _lnurlSupportedCurrencies.Contains(blob.Currency);
|
return pms is not null && _lnurlSupportedCurrencies.Contains(blob.Currency);
|
||||||
@@ -637,7 +652,7 @@ namespace BTCPayServer.HostedServices
|
|||||||
{
|
{
|
||||||
Amount = claimed,
|
Amount = claimed,
|
||||||
Destination = req.ClaimRequest.Destination.ToString(),
|
Destination = req.ClaimRequest.Destination.ToString(),
|
||||||
Metadata = req.ClaimRequest.Metadata?? new JObject(),
|
Metadata = req.ClaimRequest.Metadata ?? new JObject(),
|
||||||
};
|
};
|
||||||
payout.SetBlob(payoutBlob, _jsonSerializerSettings);
|
payout.SetBlob(payoutBlob, _jsonSerializerSettings);
|
||||||
await ctx.Payouts.AddAsync(payout);
|
await ctx.Payouts.AddAsync(payout);
|
||||||
@@ -883,25 +898,25 @@ namespace BTCPayServer.HostedServices
|
|||||||
{
|
{
|
||||||
null when destination.Amount is null && ppCurrency is null => ("Amount is not specified in destination or payout request", null),
|
null when destination.Amount is null && ppCurrency is null => ("Amount is not specified in destination or payout request", null),
|
||||||
null when destination.Amount is null => (null, null),
|
null when destination.Amount is null => (null, null),
|
||||||
null when destination.Amount != null => (null,destination.Amount),
|
null when destination.Amount != null => (null, destination.Amount),
|
||||||
not null when destination.Amount is null => (null,amount),
|
not null when destination.Amount is null => (null, amount),
|
||||||
not null when destination.Amount != null && amount != destination.Amount &&
|
not null when destination.Amount != null && amount != destination.Amount &&
|
||||||
destination.IsExplicitAmountMinimum &&
|
destination.IsExplicitAmountMinimum &&
|
||||||
payoutCurrency == "BTC" && ppCurrency == "SATS" &&
|
payoutCurrency == "BTC" && ppCurrency == "SATS" &&
|
||||||
new Money(amount.Value, MoneyUnit.Satoshi).ToUnit(MoneyUnit.BTC) < destination.Amount =>
|
new Money(amount.Value, MoneyUnit.Satoshi).ToUnit(MoneyUnit.BTC) < destination.Amount =>
|
||||||
($"Amount is implied in both destination ({destination.Amount}) and payout request ({amount}), but the payout request amount is less than the destination amount",null),
|
($"Amount is implied in both destination ({destination.Amount}) and payout request ({amount}), but the payout request amount is less than the destination amount", null),
|
||||||
not null when destination.Amount != null && amount != destination.Amount &&
|
not null when destination.Amount != null && amount != destination.Amount &&
|
||||||
destination.IsExplicitAmountMinimum &&
|
destination.IsExplicitAmountMinimum &&
|
||||||
!(payoutCurrency == "BTC" && ppCurrency == "SATS") &&
|
!(payoutCurrency == "BTC" && ppCurrency == "SATS") &&
|
||||||
amount < destination.Amount =>
|
amount < destination.Amount =>
|
||||||
($"Amount is implied in both destination ({destination.Amount}) and payout request ({amount}), but the payout request amount is less than the destination amount",null),
|
($"Amount is implied in both destination ({destination.Amount}) and payout request ({amount}), but the payout request amount is less than the destination amount", null),
|
||||||
not null when destination.Amount != null && amount != destination.Amount &&
|
not null when destination.Amount != null && amount != destination.Amount &&
|
||||||
!destination.IsExplicitAmountMinimum =>
|
!destination.IsExplicitAmountMinimum =>
|
||||||
($"Amount is implied in destination ({destination.Amount}) that does not match the payout amount provided {amount})", null),
|
($"Amount is implied in destination ({destination.Amount}) that does not match the payout amount provided {amount})", null),
|
||||||
_ => (null, amount)
|
_ => (null, amount)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetErrorMessage(ClaimResult result)
|
public static string GetErrorMessage(ClaimResult result)
|
||||||
{
|
{
|
||||||
switch (result)
|
switch (result)
|
||||||
|
|||||||
Reference in New Issue
Block a user