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,
FullNotifications = true,
ExtendedNotifications = true,
RedirectURL = HttpContext.Request.GetAbsoluteRoot(),
RedirectURL = HttpContext.Request.GetAbsoluteRoot()+ "/apps/{appId}/crowdfund",
}, store, HttpContext.Request.GetAbsoluteRoot());
if (request.RedirectToCheckout)

View File

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

View File

@@ -45,6 +45,7 @@ namespace BTCPayServer.Hubs
{
var controller = scope.ServiceProvider.GetService<AppsPublicController>();
model.RedirectToCheckout = false;
controller.ControllerContext.HttpContext = Context.GetHttpContext();
var result = await controller.ContributeToCrowdfund(Context.Items["app"].ToString(), model);
await Clients.Caller.SendCoreAsync("InvoiceCreated", new[] {(result as OkObjectResult)?.Value.ToString()});
}
@@ -123,9 +124,18 @@ namespace BTCPayServer.Hubs
return;
}
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 } );
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/>
<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>

View File

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