integrate invoice popup

This commit is contained in:
Kukks
2018-12-28 12:07:15 +01:00
parent b11f8acba1
commit 8bcf7109a3
5 changed files with 46 additions and 6 deletions

View File

@@ -116,7 +116,7 @@ namespace BTCPayServer.Controllers
NotificationURL = settings.NotificationUrl, NotificationURL = settings.NotificationUrl,
FullNotifications = true, FullNotifications = true,
ExtendedNotifications = true, ExtendedNotifications = true,
RedirectURL = HttpContext.Request.GetAbsoluteRoot(), RedirectURL = HttpContext.Request.GetAbsoluteRoot()+ "/apps/{appId}/crowdfund",
}, store, HttpContext.Request.GetAbsoluteRoot()); }, store, HttpContext.Request.GetAbsoluteRoot());
if (request.RedirectToCheckout) if (request.RedirectToCheckout)

View File

@@ -158,6 +158,7 @@ namespace BTCPayServer.Hosting
services.TryAddScoped<IHttpContextAccessor, HttpContextAccessor>(); services.TryAddScoped<IHttpContextAccessor, HttpContextAccessor>();
services.AddTransient<AccessTokenController>(); services.AddTransient<AccessTokenController>();
services.AddTransient<InvoiceController>(); services.AddTransient<InvoiceController>();
services.AddTransient<AppsPublicController>();
// Add application services. // Add application services.
services.AddTransient<IEmailSender, EmailSender>(); services.AddTransient<IEmailSender, EmailSender>();
// bundling // bundling

View File

@@ -45,6 +45,7 @@ namespace BTCPayServer.Hubs
{ {
var controller = scope.ServiceProvider.GetService<AppsPublicController>(); var controller = scope.ServiceProvider.GetService<AppsPublicController>();
model.RedirectToCheckout = false; model.RedirectToCheckout = false;
controller.ControllerContext.HttpContext = Context.GetHttpContext();
var result = await controller.ContributeToCrowdfund(Context.Items["app"].ToString(), model); var result = await controller.ContributeToCrowdfund(Context.Items["app"].ToString(), model);
await Clients.Caller.SendCoreAsync("InvoiceCreated", new[] {(result as OkObjectResult)?.Value.ToString()}); await Clients.Caller.SendCoreAsync("InvoiceCreated", new[] {(result as OkObjectResult)?.Value.ToString()});
} }
@@ -123,9 +124,18 @@ namespace BTCPayServer.Hubs
return; return;
} }
var appId = invoiceEvent.Invoice.OrderId.Replace(CrowdfundInvoiceOrderIdPrefix, "", StringComparison.InvariantCultureIgnoreCase); var appId = invoiceEvent.Invoice.OrderId.Replace(CrowdfundInvoiceOrderIdPrefix, "", StringComparison.InvariantCultureIgnoreCase);
if (invoiceEvent.Name == InvoiceEvent.ReceivedPayment) switch (invoiceEvent.Name)
{ {
case InvoiceEvent.ReceivedPayment:
_HubContext.Clients.Group(appId).SendCoreAsync("PaymentReceived", new object[]{ invoiceEvent.Invoice.AmountPaid } ); _HubContext.Clients.Group(appId).SendCoreAsync("PaymentReceived", new object[]{ invoiceEvent.Invoice.AmountPaid } );
break;
case InvoiceEvent.Completed:
if (_CacheTokens.ContainsKey(appId))
{
_CacheTokens[appId].Cancel();
}
_HubContext.Clients.Group(appId).SendCoreAsync("InfoUpdated", new object[]{} );
break;
} }
} }

View File

@@ -72,6 +72,23 @@
<hr/> <hr/>
<h3>Contribute</h3> <h3>Contribute</h3>
<form v-on:submit="onContributeFormSubmit">
<div class="form-group">
<label ></label>
<input type="email" class="form-control" v-model="contributionForm.email"/>
</div>
<div class="form-group">
<label ></label>
<div class="input-group mb-3">
<input type="number" step="any" class="form-control" v-model="contributionForm.amount"/>
<div class="input-group-append">
<span class="input-group-text">{{srvModel.targetCurrency}}</span>
</div>
</div>
</div>
<button type="submit" class="btn btn-primary">Contribute</button>
</form>
</div> </div>
</div> </div>

View File

@@ -12,7 +12,8 @@ window.onload = function (ev) {
startDateRelativeTime: "", startDateRelativeTime: "",
endDateRelativeTime: "", endDateRelativeTime: "",
started: false, started: false,
ended: false ended: false,
contributionForm: { email: "", amount: 0}
} }
}, },
computed: {}, computed: {},
@@ -29,19 +30,30 @@ window.onload = function (ev) {
if (this.srvModel.startDate) { if (this.srvModel.startDate) {
var startDateM = moment(this.srvModel.startDate); var startDateM = moment(this.srvModel.startDate);
this.startDate = moment(startDateM).format('MMMM Do YYYY'); this.startDate = startDateM.format('MMMM Do YYYY');
this.startDateRelativeTime = moment(startDateM).fromNow(); this.startDateRelativeTime = startDateM.fromNow();
this.started = startDateM.isBefore(moment()); this.started = startDateM.isBefore(moment());
}else{ }else{
this.started = true; this.started = true;
} }
setTimeout(this.updateComputed, 1000); setTimeout(this.updateComputed, 1000);
},
onContributeFormSubmit: function(e){
if(e){
e.preventDefault();
}
eventAggregator.$emit("contribute", this.contributionForm);
} }
}, },
mounted: function () { mounted: function () {
hubListener.connect(); hubListener.connect();
eventAggregator.$on("invoice-created", function (invoiceId) { eventAggregator.$on("invoice-created", function (invoiceId) {
btcpay.setApiUrlPrefix(window.location.origin);
btcpay.showInvoice(invoiceId); btcpay.showInvoice(invoiceId);
btcpay.showFrame();
});
eventAggregator.$on("payment-received", function (amount) {
console.warn("AAAAAA", amount);
}); });
eventAggregator.$on("info-updated", function (model) { eventAggregator.$on("info-updated", function (model) {
this.srvModel = model; this.srvModel = model;