Fix CreateInvoice screen, can now select the store

This commit is contained in:
NicolasDorier 2017-09-14 00:13:22 +09:00
parent 467ecd0923
commit d039b5f6ff
3 changed files with 32 additions and 5 deletions

View file

@ -4,6 +4,7 @@ using BTCPayServer.Invoicing;
using BTCPayServer.Models.InvoicingModels; using BTCPayServer.Models.InvoicingModels;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using NBitcoin; using NBitcoin;
using NBitpayClient; using NBitpayClient;
using System; using System;
@ -123,9 +124,9 @@ namespace BTCPayServer.Controllers
[Route("invoices/create")] [Route("invoices/create")]
[Authorize(AuthenticationSchemes = "Identity.Application")] [Authorize(AuthenticationSchemes = "Identity.Application")]
[BitpayAPIConstraint(false)] [BitpayAPIConstraint(false)]
public IActionResult CreateInvoice() public async Task<IActionResult> CreateInvoice()
{ {
return View(); return View(new CreateInvoiceModel() { Stores = await GetStores(GetUserId()) });
} }
[HttpPost] [HttpPost]
@ -136,9 +137,18 @@ namespace BTCPayServer.Controllers
{ {
if(!ModelState.IsValid) if(!ModelState.IsValid)
{ {
model.Stores = await GetStores(GetUserId(), model.StoreId);
return View(model); return View(model);
} }
var store = await _StoreRepository.FindStore(model.StoreId, GetUserId()); var store = await _StoreRepository.FindStore(model.StoreId, GetUserId());
if(string.IsNullOrEmpty(store.DerivationStrategy))
{
StatusMessage = "Error: You need to configure the derivation scheme in order to create an invoice";
return RedirectToAction(nameof(StoresController.UpdateStore), "Stores", new
{
storeId = store.Id
});
}
var result = await CreateInvoiceCore(new Invoice() var result = await CreateInvoiceCore(new Invoice()
{ {
Price = model.Amount.Value, Price = model.Amount.Value,
@ -149,13 +159,18 @@ namespace BTCPayServer.Controllers
//NotificationURL = CallbackUri + "/notification", //NotificationURL = CallbackUri + "/notification",
ItemDesc = model.ItemDesc, ItemDesc = model.ItemDesc,
FullNotifications = true, FullNotifications = true,
BuyerEmail = model.BuyerEmail BuyerEmail = model.BuyerEmail,
}, store); }, store);
StatusMessage = $"Invoice {result.Data.Id} just created!"; StatusMessage = $"Invoice {result.Data.Id} just created!";
return RedirectToAction(nameof(ListInvoices)); return RedirectToAction(nameof(ListInvoices));
} }
private async Task<SelectList> GetStores(string userId, string storeId = null)
{
return new SelectList(await _StoreRepository.GetStoresByUserId(userId), nameof(StoreData.Id), nameof(StoreData.StoreName), storeId);
}
[HttpPost] [HttpPost]
[Authorize(AuthenticationSchemes = "Identity.Application")] [Authorize(AuthenticationSchemes = "Identity.Application")]
[BitpayAPIConstraint(false)] [BitpayAPIConstraint(false)]

View file

@ -1,4 +1,5 @@
using System; using Microsoft.AspNetCore.Mvc.Rendering;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
@ -40,5 +41,11 @@ namespace BTCPayServer.Models.InvoicingModels
{ {
get; set; get; set;
} }
public SelectList Stores
{
get;
set;
}
} }
} }

View file

@ -12,7 +12,7 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-lg-12"> <div class="col-lg-12">
<form asp-action="CreateInvoice"> <form asp-action="CreateInvoice" method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div> <div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group"> <div class="form-group">
<label asp-for="Amount" class="control-label"></label>* <label asp-for="Amount" class="control-label"></label>*
@ -39,6 +39,11 @@
<input asp-for="BuyerEmail" class="form-control" /> <input asp-for="BuyerEmail" class="form-control" />
<span asp-validation-for="BuyerEmail" class="text-danger"></span> <span asp-validation-for="BuyerEmail" class="text-danger"></span>
</div> </div>
<div class="form-group">
<label asp-for="StoreId" class="control-label"></label>
<select asp-for="StoreId" asp-items="Model.Stores" class="form-control"></select>
<span asp-validation-for="StoreId" class="text-danger"></span>
</div>
<div class="form-group"> <div class="form-group">
<input type="submit" value="Create" class="btn btn-default" /> <input type="submit" value="Create" class="btn btn-default" />
</div> </div>