mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 14:04:26 +01:00
Address feedback from code review
Thanks @kukks
This commit is contained in:
committed by
Andrew Camilleri
parent
3a59e2a5c4
commit
8e5a9251d6
@@ -27,16 +27,17 @@ namespace BTCPayServer.Controllers
|
|||||||
[HttpGet("{appId}/settings/crowdfund")]
|
[HttpGet("{appId}/settings/crowdfund")]
|
||||||
public IActionResult UpdateCrowdfund(string appId)
|
public IActionResult UpdateCrowdfund(string appId)
|
||||||
{
|
{
|
||||||
if (CurrentApp == null)
|
var app = GetCurrentApp();
|
||||||
|
if (app == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
var settings = CurrentApp.GetSettings<CrowdfundSettings>();
|
var settings = app.GetSettings<CrowdfundSettings>();
|
||||||
var vm = new UpdateCrowdfundViewModel
|
var vm = new UpdateCrowdfundViewModel
|
||||||
{
|
{
|
||||||
Title = settings.Title,
|
Title = settings.Title,
|
||||||
StoreId = CurrentApp.StoreDataId,
|
StoreId = app.StoreDataId,
|
||||||
StoreName = CurrentApp.StoreData?.StoreName,
|
StoreName = app.StoreData?.StoreName,
|
||||||
AppName = CurrentApp.Name,
|
AppName = app.Name,
|
||||||
Enabled = settings.Enabled,
|
Enabled = settings.Enabled,
|
||||||
EnforceTargetAmount = settings.EnforceTargetAmount,
|
EnforceTargetAmount = settings.EnforceTargetAmount,
|
||||||
StartDate = settings.StartDate,
|
StartDate = settings.StartDate,
|
||||||
@@ -56,9 +57,9 @@ namespace BTCPayServer.Controllers
|
|||||||
AnimationsEnabled = settings.AnimationsEnabled,
|
AnimationsEnabled = settings.AnimationsEnabled,
|
||||||
ResetEveryAmount = settings.ResetEveryAmount,
|
ResetEveryAmount = settings.ResetEveryAmount,
|
||||||
ResetEvery = Enum.GetName(typeof(CrowdfundResetEvery), settings.ResetEvery),
|
ResetEvery = Enum.GetName(typeof(CrowdfundResetEvery), settings.ResetEvery),
|
||||||
UseAllStoreInvoices = CurrentApp.TagAllInvoices,
|
UseAllStoreInvoices = app.TagAllInvoices,
|
||||||
AppId = appId,
|
AppId = appId,
|
||||||
SearchTerm = CurrentApp.TagAllInvoices ? $"storeid:{CurrentApp.StoreDataId}" : $"orderid:{AppService.GetCrowdfundOrderId(appId)}",
|
SearchTerm = app.TagAllInvoices ? $"storeid:{app.StoreDataId}" : $"orderid:{AppService.GetCrowdfundOrderId(appId)}",
|
||||||
DisplayPerksRanking = settings.DisplayPerksRanking,
|
DisplayPerksRanking = settings.DisplayPerksRanking,
|
||||||
DisplayPerksValue = settings.DisplayPerksValue,
|
DisplayPerksValue = settings.DisplayPerksValue,
|
||||||
SortPerksByPopularity = settings.SortPerksByPopularity,
|
SortPerksByPopularity = settings.SortPerksByPopularity,
|
||||||
@@ -71,10 +72,11 @@ namespace BTCPayServer.Controllers
|
|||||||
[HttpPost("{appId}/settings/crowdfund")]
|
[HttpPost("{appId}/settings/crowdfund")]
|
||||||
public async Task<IActionResult> UpdateCrowdfund(string appId, UpdateCrowdfundViewModel vm, string command)
|
public async Task<IActionResult> UpdateCrowdfund(string appId, UpdateCrowdfundViewModel vm, string command)
|
||||||
{
|
{
|
||||||
if (CurrentApp == null)
|
var app = GetCurrentApp();
|
||||||
|
if (app == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
vm.TargetCurrency = await GetStoreDefaultCurrentIfEmpty(CurrentApp.StoreDataId, vm.TargetCurrency);
|
vm.TargetCurrency = await GetStoreDefaultCurrentIfEmpty(app.StoreDataId, vm.TargetCurrency);
|
||||||
if (_currencies.GetCurrencyData(vm.TargetCurrency, false) == null)
|
if (_currencies.GetCurrencyData(vm.TargetCurrency, false) == null)
|
||||||
ModelState.AddModelError(nameof(vm.TargetCurrency), "Invalid currency");
|
ModelState.AddModelError(nameof(vm.TargetCurrency), "Invalid currency");
|
||||||
|
|
||||||
@@ -125,7 +127,7 @@ namespace BTCPayServer.Controllers
|
|||||||
return View(vm);
|
return View(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentApp.Name = vm.AppName;
|
app.Name = vm.AppName;
|
||||||
var newSettings = new CrowdfundSettings
|
var newSettings = new CrowdfundSettings
|
||||||
{
|
{
|
||||||
Title = vm.Title,
|
Title = vm.Title,
|
||||||
@@ -155,15 +157,15 @@ namespace BTCPayServer.Controllers
|
|||||||
AnimationColors = parsedAnimationColors
|
AnimationColors = parsedAnimationColors
|
||||||
};
|
};
|
||||||
|
|
||||||
CurrentApp.TagAllInvoices = vm.UseAllStoreInvoices;
|
app.TagAllInvoices = vm.UseAllStoreInvoices;
|
||||||
CurrentApp.SetSettings(newSettings);
|
app.SetSettings(newSettings);
|
||||||
|
|
||||||
await _appService.UpdateOrCreateApp(CurrentApp);
|
await _appService.UpdateOrCreateApp(app);
|
||||||
|
|
||||||
_eventAggregator.Publish(new AppUpdated()
|
_eventAggregator.Publish(new AppUpdated()
|
||||||
{
|
{
|
||||||
AppId = appId,
|
AppId = appId,
|
||||||
StoreId = CurrentApp.StoreDataId,
|
StoreId = app.StoreDataId,
|
||||||
Settings = newSettings
|
Settings = newSettings
|
||||||
});
|
});
|
||||||
TempData[WellKnownTempData.SuccessMessage] = "App updated";
|
TempData[WellKnownTempData.SuccessMessage] = "App updated";
|
||||||
|
|||||||
@@ -89,18 +89,19 @@ namespace BTCPayServer.Controllers
|
|||||||
[HttpGet("{appId}/settings/pos")]
|
[HttpGet("{appId}/settings/pos")]
|
||||||
public IActionResult UpdatePointOfSale(string appId)
|
public IActionResult UpdatePointOfSale(string appId)
|
||||||
{
|
{
|
||||||
if (CurrentApp == null)
|
var app = GetCurrentApp();
|
||||||
|
if (app == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
var settings = CurrentApp.GetSettings<PointOfSaleSettings>();
|
var settings = app.GetSettings<PointOfSaleSettings>();
|
||||||
settings.DefaultView = settings.EnableShoppingCart ? PosViewType.Cart : settings.DefaultView;
|
settings.DefaultView = settings.EnableShoppingCart ? PosViewType.Cart : settings.DefaultView;
|
||||||
settings.EnableShoppingCart = false;
|
settings.EnableShoppingCart = false;
|
||||||
var vm = new UpdatePointOfSaleViewModel
|
var vm = new UpdatePointOfSaleViewModel
|
||||||
{
|
{
|
||||||
Id = appId,
|
Id = appId,
|
||||||
StoreId = CurrentApp.StoreDataId,
|
StoreId = app.StoreDataId,
|
||||||
StoreName = CurrentApp.StoreData?.StoreName,
|
StoreName = app.StoreData?.StoreName,
|
||||||
AppName = CurrentApp.Name,
|
AppName = app.Name,
|
||||||
Title = settings.Title,
|
Title = settings.Title,
|
||||||
DefaultView = settings.DefaultView,
|
DefaultView = settings.DefaultView,
|
||||||
ShowCustomAmount = settings.ShowCustomAmount,
|
ShowCustomAmount = settings.ShowCustomAmount,
|
||||||
@@ -117,7 +118,7 @@ namespace BTCPayServer.Controllers
|
|||||||
Description = settings.Description,
|
Description = settings.Description,
|
||||||
NotificationUrl = settings.NotificationUrl,
|
NotificationUrl = settings.NotificationUrl,
|
||||||
RedirectUrl = settings.RedirectUrl,
|
RedirectUrl = settings.RedirectUrl,
|
||||||
SearchTerm = $"storeid:{CurrentApp.StoreDataId}",
|
SearchTerm = $"storeid:{app.StoreDataId}",
|
||||||
RedirectAutomatically = settings.RedirectAutomatically.HasValue ? settings.RedirectAutomatically.Value ? "true" : "false" : "",
|
RedirectAutomatically = settings.RedirectAutomatically.HasValue ? settings.RedirectAutomatically.Value ? "true" : "false" : "",
|
||||||
RequiresRefundEmail = settings.RequiresRefundEmail
|
RequiresRefundEmail = settings.RequiresRefundEmail
|
||||||
};
|
};
|
||||||
@@ -162,13 +163,14 @@ namespace BTCPayServer.Controllers
|
|||||||
[HttpPost("{appId}/settings/pos")]
|
[HttpPost("{appId}/settings/pos")]
|
||||||
public async Task<IActionResult> UpdatePointOfSale(string appId, UpdatePointOfSaleViewModel vm)
|
public async Task<IActionResult> UpdatePointOfSale(string appId, UpdatePointOfSaleViewModel vm)
|
||||||
{
|
{
|
||||||
if (CurrentApp == null)
|
var app = GetCurrentApp();
|
||||||
|
if (app == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return View(vm);
|
return View(vm);
|
||||||
|
|
||||||
vm.Currency = await GetStoreDefaultCurrentIfEmpty(CurrentApp.StoreDataId, vm.Currency);
|
vm.Currency = await GetStoreDefaultCurrentIfEmpty(app.StoreDataId, vm.Currency);
|
||||||
if (_currencies.GetCurrencyData(vm.Currency, false) == null)
|
if (_currencies.GetCurrencyData(vm.Currency, false) == null)
|
||||||
ModelState.AddModelError(nameof(vm.Currency), "Invalid currency");
|
ModelState.AddModelError(nameof(vm.Currency), "Invalid currency");
|
||||||
try
|
try
|
||||||
@@ -184,8 +186,8 @@ namespace BTCPayServer.Controllers
|
|||||||
return View(vm);
|
return View(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentApp.Name = vm.AppName;
|
app.Name = vm.AppName;
|
||||||
CurrentApp.SetSettings(new PointOfSaleSettings
|
app.SetSettings(new PointOfSaleSettings
|
||||||
{
|
{
|
||||||
Title = vm.Title,
|
Title = vm.Title,
|
||||||
DefaultView = vm.DefaultView,
|
DefaultView = vm.DefaultView,
|
||||||
@@ -206,7 +208,7 @@ namespace BTCPayServer.Controllers
|
|||||||
RedirectAutomatically = string.IsNullOrEmpty(vm.RedirectAutomatically) ? (bool?)null : bool.Parse(vm.RedirectAutomatically),
|
RedirectAutomatically = string.IsNullOrEmpty(vm.RedirectAutomatically) ? (bool?)null : bool.Parse(vm.RedirectAutomatically),
|
||||||
RequiresRefundEmail = vm.RequiresRefundEmail,
|
RequiresRefundEmail = vm.RequiresRefundEmail,
|
||||||
});
|
});
|
||||||
await _appService.UpdateOrCreateApp(CurrentApp);
|
await _appService.UpdateOrCreateApp(app);
|
||||||
TempData[WellKnownTempData.SuccessMessage] = "App updated";
|
TempData[WellKnownTempData.SuccessMessage] = "App updated";
|
||||||
return RedirectToAction(nameof(UpdatePointOfSale), new { appId });
|
return RedirectToAction(nameof(UpdatePointOfSale), new { appId });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,8 @@ namespace BTCPayServer.Controllers
|
|||||||
string sortOrderColumn = null
|
string sortOrderColumn = null
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
var apps = await _appService.GetAllApps(GetUserId(), false, CurrentStore.Id);
|
var store = GetCurrentStore();
|
||||||
|
var apps = await _appService.GetAllApps(GetUserId(), false, store.Id);
|
||||||
|
|
||||||
if (sortOrder != null && sortOrderColumn != null)
|
if (sortOrder != null && sortOrderColumn != null)
|
||||||
{
|
{
|
||||||
@@ -91,14 +92,15 @@ namespace BTCPayServer.Controllers
|
|||||||
{
|
{
|
||||||
return View(new CreateAppViewModel
|
return View(new CreateAppViewModel
|
||||||
{
|
{
|
||||||
StoreId = CurrentStore.Id
|
StoreId = GetCurrentStore().Id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("/stores/{storeId}/apps/create")]
|
[HttpPost("/stores/{storeId}/apps/create")]
|
||||||
public async Task<IActionResult> CreateApp(string storeId, CreateAppViewModel vm)
|
public async Task<IActionResult> CreateApp(string storeId, CreateAppViewModel vm)
|
||||||
{
|
{
|
||||||
vm.StoreId = CurrentStore.Id;
|
var store = GetCurrentStore();
|
||||||
|
vm.StoreId = store.Id;
|
||||||
|
|
||||||
if (!Enum.TryParse(vm.SelectedAppType, out AppType appType))
|
if (!Enum.TryParse(vm.SelectedAppType, out AppType appType))
|
||||||
ModelState.AddModelError(nameof(vm.SelectedAppType), "Invalid App Type");
|
ModelState.AddModelError(nameof(vm.SelectedAppType), "Invalid App Type");
|
||||||
@@ -110,7 +112,7 @@ namespace BTCPayServer.Controllers
|
|||||||
|
|
||||||
var appData = new AppData
|
var appData = new AppData
|
||||||
{
|
{
|
||||||
StoreDataId = CurrentStore.Id,
|
StoreDataId = store.Id,
|
||||||
Name = vm.AppName,
|
Name = vm.AppName,
|
||||||
AppType = appType.ToString()
|
AppType = appType.ToString()
|
||||||
};
|
};
|
||||||
@@ -146,22 +148,24 @@ namespace BTCPayServer.Controllers
|
|||||||
[HttpGet("{appId}/delete")]
|
[HttpGet("{appId}/delete")]
|
||||||
public IActionResult DeleteApp(string appId)
|
public IActionResult DeleteApp(string appId)
|
||||||
{
|
{
|
||||||
if (CurrentApp == null)
|
var app = GetCurrentApp();
|
||||||
|
if (app == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
return View("Confirm", new ConfirmModel("Delete app", $"The app <strong>{CurrentApp.Name}</strong> and its settings will be permanently deleted. Are you sure?", "Delete"));
|
return View("Confirm", new ConfirmModel("Delete app", $"The app <strong>{app.Name}</strong> and its settings will be permanently deleted. Are you sure?", "Delete"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("{appId}/delete")]
|
[HttpPost("{appId}/delete")]
|
||||||
public async Task<IActionResult> DeleteAppPost(string appId)
|
public async Task<IActionResult> DeleteAppPost(string appId)
|
||||||
{
|
{
|
||||||
if (CurrentApp == null)
|
var app = GetCurrentApp();
|
||||||
|
if (app == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
if (await _appService.DeleteApp(CurrentApp))
|
if (await _appService.DeleteApp(app))
|
||||||
TempData[WellKnownTempData.SuccessMessage] = "App deleted successfully.";
|
TempData[WellKnownTempData.SuccessMessage] = "App deleted successfully.";
|
||||||
|
|
||||||
return RedirectToAction(nameof(ListApps), new { storeId = CurrentApp.StoreDataId });
|
return RedirectToAction(nameof(ListApps), new { storeId = app.StoreDataId });
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task<string> GetStoreDefaultCurrentIfEmpty(string storeId, string currency)
|
async Task<string> GetStoreDefaultCurrentIfEmpty(string storeId, string currency)
|
||||||
@@ -173,19 +177,10 @@ namespace BTCPayServer.Controllers
|
|||||||
return currency.Trim().ToUpperInvariant();
|
return currency.Trim().ToUpperInvariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetUserId()
|
private string GetUserId() => _userManager.GetUserId(User);
|
||||||
{
|
|
||||||
return _userManager.GetUserId(User);
|
|
||||||
}
|
|
||||||
|
|
||||||
private StoreData CurrentStore
|
private StoreData GetCurrentStore() => HttpContext.GetStoreData();
|
||||||
{
|
|
||||||
get => HttpContext.GetStoreData();
|
|
||||||
}
|
|
||||||
|
|
||||||
private AppData CurrentApp
|
private AppData GetCurrentApp() => HttpContext.GetAppData();
|
||||||
{
|
|
||||||
get => HttpContext.GetAppData();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -224,14 +224,16 @@ namespace BTCPayServer.Controllers
|
|||||||
{
|
{
|
||||||
using var ctx = _dbContextFactory.CreateContext();
|
using var ctx = _dbContextFactory.CreateContext();
|
||||||
|
|
||||||
if (CurrentInvoice == null)
|
var invoice = GetCurrentInvoice();
|
||||||
|
if (invoice == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
if (!CanRefund(CurrentInvoice.GetInvoiceState()))
|
if (!CanRefund(invoice.GetInvoiceState()))
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
|
var store = GetCurrentStore();
|
||||||
var paymentMethodId = PaymentMethodId.Parse(model.SelectedPaymentMethod);
|
var paymentMethodId = PaymentMethodId.Parse(model.SelectedPaymentMethod);
|
||||||
var cdCurrency = _CurrencyNameTable.GetCurrencyData(CurrentInvoice.Currency, true);
|
var cdCurrency = _CurrencyNameTable.GetCurrencyData(invoice.Currency, true);
|
||||||
var paymentMethodDivisibility = _CurrencyNameTable.GetCurrencyData(paymentMethodId.CryptoCode, false)?.Divisibility ?? 8;
|
var paymentMethodDivisibility = _CurrencyNameTable.GetCurrencyData(paymentMethodId.CryptoCode, false)?.Divisibility ?? 8;
|
||||||
RateRules rules;
|
RateRules rules;
|
||||||
RateResult rateResult;
|
RateResult rateResult;
|
||||||
@@ -241,7 +243,7 @@ namespace BTCPayServer.Controllers
|
|||||||
case RefundSteps.SelectPaymentMethod:
|
case RefundSteps.SelectPaymentMethod:
|
||||||
model.RefundStep = RefundSteps.SelectRate;
|
model.RefundStep = RefundSteps.SelectRate;
|
||||||
model.Title = "What to refund?";
|
model.Title = "What to refund?";
|
||||||
var pms = CurrentInvoice.GetPaymentMethods();
|
var pms = invoice.GetPaymentMethods();
|
||||||
var paymentMethod = pms.SingleOrDefault(method => method.GetId() == paymentMethodId);
|
var paymentMethod = pms.SingleOrDefault(method => method.GetId() == paymentMethodId);
|
||||||
|
|
||||||
//TODO: Make this clean
|
//TODO: Make this clean
|
||||||
@@ -257,9 +259,9 @@ namespace BTCPayServer.Controllers
|
|||||||
model.CryptoAmountThen = cryptoPaid.RoundToSignificant(paymentMethodDivisibility);
|
model.CryptoAmountThen = cryptoPaid.RoundToSignificant(paymentMethodDivisibility);
|
||||||
model.RateThenText =
|
model.RateThenText =
|
||||||
_CurrencyNameTable.DisplayFormatCurrency(model.CryptoAmountThen, paymentMethodId.CryptoCode);
|
_CurrencyNameTable.DisplayFormatCurrency(model.CryptoAmountThen, paymentMethodId.CryptoCode);
|
||||||
rules = CurrentStore.GetStoreBlob().GetRateRules(_NetworkProvider);
|
rules = store.GetStoreBlob().GetRateRules(_NetworkProvider);
|
||||||
rateResult = await _RateProvider.FetchRate(
|
rateResult = await _RateProvider.FetchRate(
|
||||||
new CurrencyPair(paymentMethodId.CryptoCode, CurrentInvoice.Currency), rules,
|
new CurrencyPair(paymentMethodId.CryptoCode, invoice.Currency), rules,
|
||||||
cancellationToken);
|
cancellationToken);
|
||||||
//TODO: What if fetching rate failed?
|
//TODO: What if fetching rate failed?
|
||||||
if (rateResult.BidAsk is null)
|
if (rateResult.BidAsk is null)
|
||||||
@@ -275,13 +277,14 @@ namespace BTCPayServer.Controllers
|
|||||||
model.FiatAmount = paidCurrency;
|
model.FiatAmount = paidCurrency;
|
||||||
}
|
}
|
||||||
|
|
||||||
model.FiatText = _CurrencyNameTable.DisplayFormatCurrency(model.FiatAmount, CurrentInvoice.Currency);
|
model.FiatText = _CurrencyNameTable.DisplayFormatCurrency(model.FiatAmount, invoice.Currency);
|
||||||
return View(model);
|
return View(model);
|
||||||
|
|
||||||
case RefundSteps.SelectRate:
|
case RefundSteps.SelectRate:
|
||||||
createPullPayment = new CreatePullPayment
|
createPullPayment = new CreatePullPayment
|
||||||
{
|
{
|
||||||
Name = $"Refund {CurrentInvoice.Id}", PaymentMethodIds = new[] { paymentMethodId },
|
Name = $"Refund {invoice.Id}", PaymentMethodIds = new[] { paymentMethodId },
|
||||||
StoreId = CurrentInvoice.StoreId
|
StoreId = invoice.StoreId
|
||||||
};
|
};
|
||||||
switch (model.SelectedRefundOption)
|
switch (model.SelectedRefundOption)
|
||||||
{
|
{
|
||||||
@@ -294,12 +297,12 @@ namespace BTCPayServer.Controllers
|
|||||||
createPullPayment.Amount = model.CryptoAmountNow;
|
createPullPayment.Amount = model.CryptoAmountNow;
|
||||||
break;
|
break;
|
||||||
case "Fiat":
|
case "Fiat":
|
||||||
createPullPayment.Currency = CurrentInvoice.Currency;
|
createPullPayment.Currency = invoice.Currency;
|
||||||
createPullPayment.Amount = model.FiatAmount;
|
createPullPayment.Amount = model.FiatAmount;
|
||||||
break;
|
break;
|
||||||
case "Custom":
|
case "Custom":
|
||||||
model.Title = "How much to refund?";
|
model.Title = "How much to refund?";
|
||||||
model.CustomCurrency = CurrentInvoice.Currency;
|
model.CustomCurrency = invoice.Currency;
|
||||||
model.CustomAmount = model.FiatAmount;
|
model.CustomAmount = model.FiatAmount;
|
||||||
model.RefundStep = RefundSteps.SelectCustomAmount;
|
model.RefundStep = RefundSteps.SelectCustomAmount;
|
||||||
return View(model);
|
return View(model);
|
||||||
@@ -325,7 +328,8 @@ namespace BTCPayServer.Controllers
|
|||||||
{
|
{
|
||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
rules = CurrentStore.GetStoreBlob().GetRateRules(_NetworkProvider);
|
|
||||||
|
rules = store.GetStoreBlob().GetRateRules(_NetworkProvider);
|
||||||
rateResult = await _RateProvider.FetchRate(
|
rateResult = await _RateProvider.FetchRate(
|
||||||
new CurrencyPair(paymentMethodId.CryptoCode, model.CustomCurrency), rules,
|
new CurrencyPair(paymentMethodId.CryptoCode, model.CustomCurrency), rules,
|
||||||
cancellationToken);
|
cancellationToken);
|
||||||
@@ -339,8 +343,8 @@ namespace BTCPayServer.Controllers
|
|||||||
|
|
||||||
createPullPayment = new CreatePullPayment
|
createPullPayment = new CreatePullPayment
|
||||||
{
|
{
|
||||||
Name = $"Refund {CurrentInvoice.Id}", PaymentMethodIds = new[] { paymentMethodId },
|
Name = $"Refund {invoice.Id}", PaymentMethodIds = new[] { paymentMethodId },
|
||||||
StoreId = CurrentInvoice.StoreId,
|
StoreId = invoice.StoreId,
|
||||||
Currency = model.CustomCurrency,
|
Currency = model.CustomCurrency,
|
||||||
Amount = model.CustomAmount
|
Amount = model.CustomAmount
|
||||||
};
|
};
|
||||||
@@ -355,10 +359,10 @@ namespace BTCPayServer.Controllers
|
|||||||
Html = "Refund successfully created!<br />Share the link to this page with a customer.<br />The customer needs to enter their address and claim the refund.<br />Once a customer claims the refund, you will get a notification and would need to approve and initiate it from your Store > Payouts.",
|
Html = "Refund successfully created!<br />Share the link to this page with a customer.<br />The customer needs to enter their address and claim the refund.<br />Once a customer claims the refund, you will get a notification and would need to approve and initiate it from your Store > Payouts.",
|
||||||
Severity = StatusMessageModel.StatusSeverity.Success
|
Severity = StatusMessageModel.StatusSeverity.Success
|
||||||
});
|
});
|
||||||
(await ctx.Invoices.FindAsync(new[] { CurrentInvoice.Id }, cancellationToken)).CurrentRefundId = ppId;
|
(await ctx.Invoices.FindAsync(new[] { invoice.Id }, cancellationToken)).CurrentRefundId = ppId;
|
||||||
ctx.Refunds.Add(new RefundData()
|
ctx.Refunds.Add(new RefundData()
|
||||||
{
|
{
|
||||||
InvoiceDataId = CurrentInvoice.Id,
|
InvoiceDataId = invoice.Id,
|
||||||
PullPaymentDataId = ppId
|
PullPaymentDataId = ppId
|
||||||
});
|
});
|
||||||
await ctx.SaveChangesAsync(cancellationToken);
|
await ctx.SaveChangesAsync(cancellationToken);
|
||||||
@@ -976,20 +980,11 @@ namespace BTCPayServer.Controllers
|
|||||||
public string? StatusString { get; set; }
|
public string? StatusString { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private StoreData CurrentStore
|
private StoreData GetCurrentStore() => HttpContext.GetStoreData();
|
||||||
{
|
|
||||||
get => HttpContext.GetStoreData();
|
|
||||||
}
|
|
||||||
|
|
||||||
private InvoiceEntity CurrentInvoice
|
private InvoiceEntity GetCurrentInvoice() => HttpContext.GetInvoiceData();
|
||||||
{
|
|
||||||
get => HttpContext.GetInvoiceData();
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GetUserId()
|
private string GetUserId() => _UserManager.GetUserId(User);
|
||||||
{
|
|
||||||
return _UserManager.GetUserId(User);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class PosDataParser
|
public class PosDataParser
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -62,11 +62,12 @@ namespace BTCPayServer.Controllers
|
|||||||
{
|
{
|
||||||
model = this.ParseListQuery(model ?? new ListPaymentRequestsViewModel());
|
model = this.ParseListQuery(model ?? new ListPaymentRequestsViewModel());
|
||||||
|
|
||||||
|
var store = GetCurrentStore();
|
||||||
var includeArchived = new SearchString(model.SearchTerm).GetFilterBool("includearchived") == true;
|
var includeArchived = new SearchString(model.SearchTerm).GetFilterBool("includearchived") == true;
|
||||||
var result = await _PaymentRequestRepository.FindPaymentRequests(new PaymentRequestQuery
|
var result = await _PaymentRequestRepository.FindPaymentRequests(new PaymentRequestQuery
|
||||||
{
|
{
|
||||||
UserId = GetUserId(),
|
UserId = GetUserId(),
|
||||||
StoreId = CurrentStore.Id,
|
StoreId = store.Id,
|
||||||
Skip = model.Skip,
|
Skip = model.Skip,
|
||||||
Count = model.Count,
|
Count = model.Count,
|
||||||
IncludeArchived = includeArchived
|
IncludeArchived = includeArchived
|
||||||
@@ -80,14 +81,16 @@ namespace BTCPayServer.Controllers
|
|||||||
[HttpGet("/stores/{storeId}/payment-requests/edit/{payReqId?}")]
|
[HttpGet("/stores/{storeId}/payment-requests/edit/{payReqId?}")]
|
||||||
public IActionResult EditPaymentRequest(string storeId, string payReqId)
|
public IActionResult EditPaymentRequest(string storeId, string payReqId)
|
||||||
{
|
{
|
||||||
if (CurrentPaymentRequest == null && !string.IsNullOrEmpty(payReqId))
|
var store = GetCurrentStore();
|
||||||
|
var paymentRequest = GetCurrentPaymentRequest();
|
||||||
|
if (paymentRequest == null && !string.IsNullOrEmpty(payReqId))
|
||||||
{
|
{
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
return View(nameof(EditPaymentRequest), new UpdatePaymentRequestViewModel(CurrentPaymentRequest)
|
return View(nameof(EditPaymentRequest), new UpdatePaymentRequestViewModel(paymentRequest)
|
||||||
{
|
{
|
||||||
StoreId = CurrentStore.Id
|
StoreId = store.Id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,12 +101,14 @@ namespace BTCPayServer.Controllers
|
|||||||
_Currencies.GetCurrencyData(viewModel.Currency, false) == null)
|
_Currencies.GetCurrencyData(viewModel.Currency, false) == null)
|
||||||
ModelState.AddModelError(nameof(viewModel.Currency), "Invalid currency");
|
ModelState.AddModelError(nameof(viewModel.Currency), "Invalid currency");
|
||||||
|
|
||||||
if (CurrentPaymentRequest == null && !string.IsNullOrEmpty(payReqId))
|
var store = GetCurrentStore();
|
||||||
|
var paymentRequest = GetCurrentPaymentRequest();
|
||||||
|
if (paymentRequest == null && !string.IsNullOrEmpty(payReqId))
|
||||||
{
|
{
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CurrentPaymentRequest?.Archived is true && viewModel.Archived)
|
if (paymentRequest?.Archived is true && viewModel.Archived)
|
||||||
{
|
{
|
||||||
ModelState.AddModelError(string.Empty, "You cannot edit an archived payment request.");
|
ModelState.AddModelError(string.Empty, "You cannot edit an archived payment request.");
|
||||||
}
|
}
|
||||||
@@ -113,7 +118,7 @@ namespace BTCPayServer.Controllers
|
|||||||
return View(nameof(EditPaymentRequest), viewModel);
|
return View(nameof(EditPaymentRequest), viewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = CurrentPaymentRequest ?? new PaymentRequestData();
|
var data = paymentRequest ?? new PaymentRequestData();
|
||||||
data.StoreDataId = viewModel.StoreId;
|
data.StoreDataId = viewModel.StoreId;
|
||||||
data.Archived = viewModel.Archived;
|
data.Archived = viewModel.Archived;
|
||||||
|
|
||||||
@@ -138,7 +143,7 @@ namespace BTCPayServer.Controllers
|
|||||||
_EventAggregator.Publish(new PaymentRequestUpdated { Data = data, PaymentRequestId = data.Id, });
|
_EventAggregator.Publish(new PaymentRequestUpdated { Data = data, PaymentRequestId = data.Id, });
|
||||||
|
|
||||||
TempData[WellKnownTempData.SuccessMessage] = "Saved";
|
TempData[WellKnownTempData.SuccessMessage] = "Saved";
|
||||||
return RedirectToAction(nameof(EditPaymentRequest), new { storeId = CurrentStore.Id, payReqId = data.Id });
|
return RedirectToAction(nameof(EditPaymentRequest), new { storeId = store.Id, payReqId = data.Id });
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{payReqId}")]
|
[HttpGet("{payReqId}")]
|
||||||
@@ -303,7 +308,8 @@ namespace BTCPayServer.Controllers
|
|||||||
[HttpGet("{payReqId}/clone")]
|
[HttpGet("{payReqId}/clone")]
|
||||||
public IActionResult ClonePaymentRequest(string payReqId)
|
public IActionResult ClonePaymentRequest(string payReqId)
|
||||||
{
|
{
|
||||||
var result = EditPaymentRequest(CurrentStore.Id, payReqId);
|
var store = GetCurrentStore();
|
||||||
|
var result = EditPaymentRequest(store.Id, payReqId);
|
||||||
if (result is ViewResult viewResult)
|
if (result is ViewResult viewResult)
|
||||||
{
|
{
|
||||||
var model = (UpdatePaymentRequestViewModel)viewResult.Model;
|
var model = (UpdatePaymentRequestViewModel)viewResult.Model;
|
||||||
@@ -320,7 +326,8 @@ namespace BTCPayServer.Controllers
|
|||||||
[HttpGet("{payReqId}/archive")]
|
[HttpGet("{payReqId}/archive")]
|
||||||
public async Task<IActionResult> TogglePaymentRequestArchival(string payReqId)
|
public async Task<IActionResult> TogglePaymentRequestArchival(string payReqId)
|
||||||
{
|
{
|
||||||
var result = EditPaymentRequest(CurrentStore.Id, payReqId);
|
var store = GetCurrentStore();
|
||||||
|
var result = EditPaymentRequest(store.Id, payReqId);
|
||||||
if (result is ViewResult viewResult)
|
if (result is ViewResult viewResult)
|
||||||
{
|
{
|
||||||
var model = (UpdatePaymentRequestViewModel)viewResult.Model;
|
var model = (UpdatePaymentRequestViewModel)viewResult.Model;
|
||||||
@@ -335,19 +342,10 @@ namespace BTCPayServer.Controllers
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetUserId()
|
private string GetUserId() => _UserManager.GetUserId(User);
|
||||||
{
|
|
||||||
return _UserManager.GetUserId(User);
|
|
||||||
}
|
|
||||||
|
|
||||||
private StoreData CurrentStore
|
private StoreData GetCurrentStore() => HttpContext.GetStoreData();
|
||||||
{
|
|
||||||
get => HttpContext.GetStoreData();
|
|
||||||
}
|
|
||||||
|
|
||||||
private PaymentRequestData CurrentPaymentRequest
|
private PaymentRequestData GetCurrentPaymentRequest() => HttpContext.GetPaymentRequestData();
|
||||||
{
|
|
||||||
get => HttpContext.GetPaymentRequestData();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -368,8 +368,9 @@ namespace BTCPayServer.Controllers
|
|||||||
var network = NetworkProvider.GetNetwork<BTCPayNetwork>(walletId?.CryptoCode);
|
var network = NetworkProvider.GetNetwork<BTCPayNetwork>(walletId?.CryptoCode);
|
||||||
if (network == null)
|
if (network == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
var store = GetCurrentStore();
|
||||||
var address = _walletReceiveService.Get(walletId)?.Address;
|
var address = _walletReceiveService.Get(walletId)?.Address;
|
||||||
var allowedPayjoin = paymentMethod.IsHotWallet && CurrentStore.GetStoreBlob().PayJoinEnabled;
|
var allowedPayjoin = paymentMethod.IsHotWallet && store.GetStoreBlob().PayJoinEnabled;
|
||||||
var bip21 = network.GenerateBIP21(address?.ToString(), null);
|
var bip21 = network.GenerateBIP21(address?.ToString(), null);
|
||||||
if (allowedPayjoin)
|
if (allowedPayjoin)
|
||||||
{
|
{
|
||||||
@@ -1030,14 +1031,9 @@ namespace BTCPayServer.Controllers
|
|||||||
return RedirectToAction();
|
return RedirectToAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
private StoreData CurrentStore
|
|
||||||
{
|
|
||||||
get => HttpContext.GetStoreData();
|
|
||||||
}
|
|
||||||
|
|
||||||
internal DerivationSchemeSettings GetDerivationSchemeSettings(WalletId walletId)
|
internal DerivationSchemeSettings GetDerivationSchemeSettings(WalletId walletId)
|
||||||
{
|
{
|
||||||
return CurrentStore.GetDerivationSchemeSettings(NetworkProvider, walletId.CryptoCode);
|
return GetCurrentStore().GetDerivationSchemeSettings(NetworkProvider, walletId.CryptoCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<IMoney> GetBalanceAsMoney(BTCPayWallet wallet, DerivationStrategyBase derivationStrategy)
|
private static async Task<IMoney> GetBalanceAsMoney(BTCPayWallet wallet, DerivationStrategyBase derivationStrategy)
|
||||||
@@ -1066,11 +1062,6 @@ namespace BTCPayServer.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetUserId()
|
|
||||||
{
|
|
||||||
return _userManager.GetUserId(User);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPost("{walletId}/actions")]
|
[HttpPost("{walletId}/actions")]
|
||||||
public async Task<IActionResult> WalletActions(
|
public async Task<IActionResult> WalletActions(
|
||||||
[ModelBinder(typeof(WalletIdModelBinder))]
|
[ModelBinder(typeof(WalletIdModelBinder))]
|
||||||
@@ -1125,6 +1116,10 @@ namespace BTCPayServer.Controllers
|
|||||||
: Url.Content(network.LightningImagePath);
|
: Url.Content(network.LightningImagePath);
|
||||||
return Request.GetRelativePathOrAbsolute(res);
|
return Request.GetRelativePathOrAbsolute(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string GetUserId() => _userManager.GetUserId(User);
|
||||||
|
|
||||||
|
private StoreData GetCurrentStore() => HttpContext.GetStoreData();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WalletReceiveViewModel
|
public class WalletReceiveViewModel
|
||||||
|
|||||||
Reference in New Issue
Block a user