From f09f23e570ac88a893f1b1a5b7bda0421c2eb60f Mon Sep 17 00:00:00 2001 From: Andrew Camilleri Date: Tue, 29 Jan 2019 10:32:44 +0100 Subject: [PATCH] Enable better error when invoice cannot be created on crowdfund (#575) Closes #572 --- .../Controllers/AppsPublicController.cs | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/BTCPayServer/Controllers/AppsPublicController.cs b/BTCPayServer/Controllers/AppsPublicController.cs index 8c0b706a0..1733a2468 100644 --- a/BTCPayServer/Controllers/AppsPublicController.cs +++ b/BTCPayServer/Controllers/AppsPublicController.cs @@ -176,30 +176,38 @@ namespace BTCPayServer.Controllers } store.AdditionalClaims.Add(new Claim(Policies.CanCreateInvoice.Key, store.Id)); - var invoice = await _InvoiceController.CreateInvoiceCore(new Invoice() + try { - OrderId = $"{CrowdfundHubStreamer.CrowdfundInvoiceOrderIdPrefix}{appId}", - Currency = settings.TargetCurrency, - ItemCode = request.ChoiceKey ?? string.Empty, - ItemDesc = title, - BuyerEmail = request.Email, - Price = price, - NotificationURL = settings.NotificationUrl, - FullNotifications = true, - ExtendedNotifications = true, - RedirectURL = request.RedirectUrl ?? Request.GetDisplayUrl(), + var invoice = await _InvoiceController.CreateInvoiceCore(new Invoice() + { + OrderId = $"{CrowdfundHubStreamer.CrowdfundInvoiceOrderIdPrefix}{appId}", + Currency = settings.TargetCurrency, + ItemCode = request.ChoiceKey ?? string.Empty, + ItemDesc = title, + BuyerEmail = request.Email, + Price = price, + NotificationURL = settings.NotificationUrl, + FullNotifications = true, + ExtendedNotifications = true, + RedirectURL = request.RedirectUrl ?? Request.GetDisplayUrl(), - }, store, HttpContext.Request.GetAbsoluteRoot()); - if (request.RedirectToCheckout) - { - return RedirectToAction(nameof(InvoiceController.Checkout), "Invoice", - new {invoiceId = invoice.Data.Id}); + }, store, HttpContext.Request.GetAbsoluteRoot()); + if (request.RedirectToCheckout) + { + return RedirectToAction(nameof(InvoiceController.Checkout), "Invoice", + new {invoiceId = invoice.Data.Id}); + } + else + { + return Ok(invoice.Data.Id); + } } - else + catch (BitpayHttpException e) { - return Ok(invoice.Data.Id); + return BadRequest(e.Message); } + }