Handling payment button post and providing test form

This commit is contained in:
rockstardev
2018-08-17 12:38:03 +02:00
parent ed36fba0d7
commit 74ddcfa01e
5 changed files with 59 additions and 10 deletions

View File

@@ -119,6 +119,9 @@
<Content Update="Views\Apps\PayButton.cshtml"> <Content Update="Views\Apps\PayButton.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack> <Pack>$(IncludeRazorContentInPack)</Pack>
</Content> </Content>
<Content Update="Views\Apps\PayButtonTest.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Views\Server\LNDGRPCServices.cshtml"> <Content Update="Views\Server\LNDGRPCServices.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack> <Pack>$(IncludeRazorContentInPack)</Pack>
</Content> </Content>

View File

@@ -308,5 +308,37 @@ namespace BTCPayServer.Controllers
}; };
return View(model); return View(model);
} }
[HttpPost]
[Route("{appId}/pay")]
[IgnoreAntiforgeryToken]
[EnableCors(CorsPolicies.All)]
public async Task<IActionResult> PayButtonHandle(string appId, [FromForm]PayButtonViewModel model)
{
var app = await GetApp(appId, AppType.PointOfSale);
var settings = app.GetSettings<PointOfSaleSettings>();
var store = await GetStore(app);
var invoice = await _InvoiceController.CreateInvoiceCore(new NBitpayClient.Invoice()
{
Price = model.Price,
Currency = model.Currency,
ItemDesc = model.CheckoutDesc,
OrderId = model.OrderId,
BuyerEmail = model.NotifyEmail,
NotificationURL = model.ServerIpn,
RedirectURL = model.BrowserRedirect,
FullNotifications = true
}, store, HttpContext.Request.GetAbsoluteRoot());
return Redirect(invoice.Data.Url);
}
[HttpGet]
[Route("{appId}/paybuttontest")]
public async Task<IActionResult> PayButtonTest(string appId)
{
return View();
}
} }
} }

View File

@@ -14,7 +14,7 @@ namespace BTCPayServer.Models.AppViewModels
public int ButtonSize { get; set; } public int ButtonSize { get; set; }
public string ServerIpn { get; set; } public string ServerIpn { get; set; }
public string BrowserRedirect { get; set; } public string BrowserRedirect { get; set; }
public string EmailToNotify { get; set; } public string NotifyEmail { get; set; }
// //
public string UrlRoot { get; set; } public string UrlRoot { get; set; }

View File

@@ -82,10 +82,10 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Send Email Notifications to</label> <label>Send Email Notifications to</label>
<input name="emailToNotify" type="text" class="form-control" placeholder="(optional)" <input name="notifyEmail" type="text" class="form-control" placeholder="(optional)"
v-model="srvModel.emailToNotify" v-on:change="inputChanges" v-model="srvModel.notifyEmail" v-on:change="inputChanges"
v-validate="'email'" :class="{'is-invalid': errors.has('emailToNotify') }"> v-validate="'email'" :class="{'is-invalid': errors.has('notifyEmail') }">
<small class="text-danger">{{ errors.first('emailToNotify') }}</small> <small class="text-danger">{{ errors.first('notifyEmail') }}</small>
</div> </div>
<div class="form-group"> <div class="form-group">
@@ -145,7 +145,7 @@
en: { en: {
attributes: { attributes: {
price: 'Price', checkoutDesc: 'Checkout Description', orderId: 'Order Id', price: 'Price', checkoutDesc: 'Checkout Description', orderId: 'Order Id',
serverIpn: 'Server IPN', emailToNotify: 'Send Email Notifications', browserRedirect: 'Browser Redirect' serverIpn: 'Server IPN', notifyEmail: 'Send Email Notifications', browserRedirect: 'Browser Redirect'
} }
} }
}; };
@@ -167,8 +167,8 @@
srvModel.buttonSize = buttonSize; srvModel.buttonSize = buttonSize;
} }
var html = '&lt;form method="POST" action="' + srvModel.urlRoot + '/apps/3jVExUHqRkGi4eaJEFCTxw5zjk14VAFzoVZXZJ3fbwED/pos"&gt;'; var html = '&lt;form method="POST" action="' + srvModel.urlRoot + '/apps/3jVExUHqRkGi4eaJEFCTxw5zjk14VAFzoVZXZJ3fbwED/pay"&gt;';
html += addinput("amount", srvModel.price); html += addinput("price", srvModel.price);
if (srvModel.currency) { if (srvModel.currency) {
html += addinput("currency", srvModel.currency); html += addinput("currency", srvModel.currency);
} }
@@ -185,8 +185,8 @@
if (srvModel.browserRedirect) { if (srvModel.browserRedirect) {
html += addinput("browserRedirect", srvModel.browserRedirect); html += addinput("browserRedirect", srvModel.browserRedirect);
} }
if (srvModel.emailToNotify) { if (srvModel.notifyEmail) {
html += addinput("emailToNotify", srvModel.emailToNotify); html += addinput("notifyEmail", srvModel.notifyEmail);
} }
var width = "209px"; var width = "209px";

View File

@@ -0,0 +1,14 @@

<section>
<div class="container" id="payButtonCtrl">
<div class="row">
<form method="POST" action="http://127.0.0.1:14142/apps/3jVExUHqRkGi4eaJEFCTxw5zjk14VAFzoVZXZJ3fbwED/pay">
<input type="hidden" name="price" value="10" />
<input type="hidden" name="currency" value="USD" />
<input type="image" src="http://127.0.0.1:14142/img/paywithbtcpay.png" name="submit" style="width:209px" alt="Pay with BtcPay, Self-Hosted Bitcoin Payment Processor">
</form>
</div>
</div>
</section>