Allow POS to redirect invoices automatically after paid

closes #730
This commit is contained in:
Kukks 2019-04-11 11:08:42 +02:00
parent c79751829b
commit 1cf17872ab
10 changed files with 39 additions and 3 deletions

View File

@ -79,6 +79,7 @@ namespace BTCPayServer.Controllers
public string CustomCSSLink { get; set; }
public string NotificationEmail { get; set; }
public string NotificationUrl { get; set; }
public bool RedirectAutomatically { get; set; }
}
[HttpGet]
@ -105,7 +106,8 @@ namespace BTCPayServer.Controllers
CustomTipPercentages = settings.CustomTipPercentages != null ? string.Join(",", settings.CustomTipPercentages) : string.Join(",", PointOfSaleSettings.CUSTOM_TIP_PERCENTAGES_DEF),
CustomCSSLink = settings.CustomCSSLink,
NotificationEmail = settings.NotificationEmail,
NotificationUrl = settings.NotificationUrl
NotificationUrl = settings.NotificationUrl,
RedirectAutomatically = settings.RedirectAutomatically
};
if (HttpContext?.Request != null)
{
@ -180,7 +182,8 @@ namespace BTCPayServer.Controllers
CustomTipPercentages = ListSplit(vm.CustomTipPercentages),
CustomCSSLink = vm.CustomCSSLink,
NotificationUrl = vm.NotificationUrl,
NotificationEmail = vm.NotificationEmail
NotificationEmail = vm.NotificationEmail,
RedirectAutomatically = vm.RedirectAutomatically
});
await UpdateAppSettings(app);

View File

@ -270,7 +270,8 @@ namespace BTCPayServer.Controllers
RedirectURL = redirectUrl ?? Request.GetDisplayUrl(),
FullNotifications = true,
ExtendedNotifications = true,
PosData = string.IsNullOrEmpty(posData) ? null : posData
PosData = string.IsNullOrEmpty(posData) ? null : posData,
RedirectAutomatically = settings.RedirectAutomatically
}, store, HttpContext.Request.GetAbsoluteRoot(),
new List<string>() {AppService.GetAppInternalTag(appId)},
cancellationToken);

View File

@ -314,6 +314,7 @@ namespace BTCPayServer.Controllers
ItemDesc = invoice.ProductInformation.ItemDesc,
Rate = ExchangeRate(paymentMethod),
MerchantRefLink = invoice.RedirectURL ?? "/",
RedirectAutomatically = invoice.RedirectAutomatically,
StoreName = store.StoreName,
InvoiceBitcoinUrl = paymentMethodId.PaymentType == PaymentTypes.BTCLike ? cryptoInfo.PaymentUrls.BIP21 :
paymentMethodId.PaymentType == PaymentTypes.LightningLike ? cryptoInfo.PaymentUrls.BOLT11 :

View File

@ -125,6 +125,8 @@ namespace BTCPayServer.Controllers
if (!Uri.IsWellFormedUriString(entity.RedirectURL, UriKind.Absolute))
entity.RedirectURL = null;
entity.RedirectAutomatically = invoice.RedirectAutomatically;
entity.Status = InvoiceStatus.New;
entity.SpeedPolicy = ParseSpeedPolicy(invoice.TransactionSpeed, store.SpeedPolicy);

View File

@ -54,5 +54,8 @@ namespace BTCPayServer.Models.AppViewModels
public string CustomCSSLink { get; set; }
public string Id { get; set; }
[Display(Name = "Redirect invoice to redirect url automatically after paid")]
public bool RedirectAutomatically { get; set; }
}
}

View File

@ -79,5 +79,8 @@ namespace BTCPayServer.Models
public string Guid { get; set; }
[JsonProperty(PropertyName = "token", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Token { get; set; }
[JsonProperty(PropertyName = "redirectAutomatically", DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool RedirectAutomatically { get; set; }
}
}

View File

@ -67,5 +67,6 @@ namespace BTCPayServer.Models.InvoicingModels
public string CoinSwitchMerchantId { get; set; }
public string RootPath { get; set; }
public decimal CoinSwitchAmountMarkupPercentage { get; set; }
public bool RedirectAutomatically { get; set; }
}
}

View File

@ -298,6 +298,12 @@ namespace BTCPayServer.Services.Invoices
get;
set;
}
public bool RedirectAutomatically
{
get;
set;
}
[Obsolete("Use GetPaymentMethod(network).GetTxFee() instead")]
public Money TxFee

View File

@ -52,18 +52,22 @@
<div class="form-group">
<label asp-for="EnableShoppingCart"></label>
<input asp-for="EnableShoppingCart" type="checkbox" class="form-check" />
<span asp-validation-for="EnableShoppingCart" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="ShowCustomAmount"></label>
<input asp-for="ShowCustomAmount" type="checkbox" class="form-check" />
<span asp-validation-for="ShowCustomAmount" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="ShowDiscount"></label>
<input asp-for="ShowDiscount" type="checkbox" class="form-check" />
<span asp-validation-for="ShowDiscount" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="EnableTips"></label>
<input asp-for="EnableTips" type="checkbox" class="form-check" />
<span asp-validation-for="EnableTips" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="ButtonText" class="control-label"></label>*
@ -114,6 +118,12 @@
<input type="email" asp-for="NotificationEmail" class="form-control" />
<span asp-validation-for="NotificationEmail" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="RedirectAutomatically"></label>
<input asp-for="RedirectAutomatically" type="checkbox" class="form-check" />
<span asp-validation-for="RedirectAutomatically" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Save Settings" />
</div>

View File

@ -46,6 +46,12 @@ function onDataCallback(jsonData) {
resetTabsSlider();
$("#paid").addClass("active");
if (!jsonData.isModal && jsonData.redirectAutomatically && jsonData.merchantRefLink) {
$(".payment__spinner").show();
setTimeout(function () {
window.location = jsonData.merchantRefLink;
}, 2000);
}
}
if (newStatus === "expired" || newStatus === "invalid") { //TODO: different state if the invoice is invalid (failed to confirm after timeout)