Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc4fb804aa | ||
|
|
e89410d239 |
@ -1,21 +1,19 @@
|
||||
using BTCPayServer.Client;
|
||||
using Grand.Business.Core.Interfaces.Common.Configuration;
|
||||
using Grand.Business.Core.Interfaces.Common.Localization;
|
||||
using Grand.Business.Core.Interfaces.Common.Logging;
|
||||
using Grand.Business.Core.Interfaces.Common.Security;
|
||||
using Grand.Business.Core.Interfaces.Common.Stores;
|
||||
using Grand.Business.Core.Utilities.Common.Security;
|
||||
using Grand.Domain.Common;
|
||||
using Grand.Domain.Customers;
|
||||
using Grand.Domain.Logging;
|
||||
using Grand.Domain.Payments;
|
||||
using Grand.Domain.Permissions;
|
||||
using Grand.Infrastructure;
|
||||
using Grand.Web.Common.Controllers;
|
||||
using Grand.Web.Common.Filters;
|
||||
using Grand.Web.Common.Security.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using NUglify.Helpers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Payments.BTCPayServer.Models;
|
||||
using Payments.BTCPayServer.Services;
|
||||
using System.Web;
|
||||
@ -37,7 +35,7 @@ namespace Payments.BTCPayServer.Controllers
|
||||
private readonly LinkGenerator _linkGenerator;
|
||||
private readonly PaymentSettings _paymentSettings;
|
||||
private readonly Func<BtcPayService> _btcPayService;
|
||||
private readonly ILogger _logger;
|
||||
private readonly ILogger<BTCPayServerController> _logger;
|
||||
|
||||
#endregion
|
||||
|
||||
@ -50,7 +48,7 @@ namespace Payments.BTCPayServer.Controllers
|
||||
ISettingService settingService,
|
||||
ITranslationService translationService,
|
||||
PaymentSettings settings,
|
||||
ILogger logger,
|
||||
ILogger<BTCPayServerController> logger,
|
||||
IPermissionService permissionService,
|
||||
Func<BtcPayService> btcPayService)
|
||||
{
|
||||
@ -89,13 +87,13 @@ namespace Payments.BTCPayServer.Controllers
|
||||
|
||||
//load settings for a chosen store scope
|
||||
var storeScope = await GetActiveStore();
|
||||
var btcPaySettings = _settingService.LoadSetting<BtcPaySettings>(storeScope);
|
||||
var btcPaySettings = await _settingService.LoadSetting<BtcPaySettings>(storeScope);
|
||||
|
||||
var model = new ConfigurationModel {
|
||||
BtcPayUrl = btcPaySettings.BtcPayUrl.IfNullOrWhiteSpace(""),
|
||||
ApiKey = btcPaySettings.ApiKey.IfNullOrWhiteSpace(""),
|
||||
BtcPayStoreID = btcPaySettings.BtcPayStoreID.IfNullOrWhiteSpace(""),
|
||||
WebHookSecret = btcPaySettings.WebHookSecret.IfNullOrWhiteSpace(""),
|
||||
BtcPayUrl = string.IsNullOrWhiteSpace(btcPaySettings.BtcPayUrl) ? "" : btcPaySettings.BtcPayUrl,
|
||||
ApiKey = string.IsNullOrWhiteSpace(btcPaySettings.ApiKey) ? "" : btcPaySettings.ApiKey,
|
||||
BtcPayStoreID = string.IsNullOrWhiteSpace(btcPaySettings.BtcPayStoreID) ? "" : btcPaySettings.BtcPayStoreID,
|
||||
WebHookSecret = string.IsNullOrWhiteSpace(btcPaySettings.WebHookSecret) ? "" : btcPaySettings.WebHookSecret,
|
||||
AdditionalFee = btcPaySettings.AdditionalFee,
|
||||
AdditionalFeePercentage = btcPaySettings.AdditionalFeePercentage,
|
||||
StoreScope = storeScope
|
||||
@ -115,7 +113,7 @@ namespace Payments.BTCPayServer.Controllers
|
||||
|
||||
//load settings for a chosen store scope
|
||||
var storeScope = await GetActiveStore();
|
||||
var settings = _settingService.LoadSetting<BtcPaySettings>(storeScope);
|
||||
var settings = await _settingService.LoadSetting<BtcPaySettings>(storeScope);
|
||||
|
||||
|
||||
if (command == "delete")
|
||||
@ -192,11 +190,11 @@ namespace Payments.BTCPayServer.Controllers
|
||||
|
||||
if (model.Ssid != myStore.Id)
|
||||
{
|
||||
await _logger.InsertLog(LogLevel.Error, "GetAutomaticApiKeyConfig(): NotFound");
|
||||
_logger.LogError("GetAutomaticApiKeyConfig(): NotFound");
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var settings = _settingService.LoadSetting<BtcPaySettings>(myStore.Id);
|
||||
var settings = await _settingService.LoadSetting<BtcPaySettings>(myStore.Id);
|
||||
|
||||
try
|
||||
{
|
||||
@ -219,7 +217,7 @@ namespace Payments.BTCPayServer.Controllers
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _logger.InsertLog(LogLevel.Error, "1- " + ex.Message);
|
||||
_logger.LogError("1- " + ex.Message);
|
||||
}
|
||||
|
||||
_paymentSettings.ActivePaymentProviderSystemNames.Add("Payments.BTCPayServer");
|
||||
@ -234,7 +232,7 @@ namespace Payments.BTCPayServer.Controllers
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _logger.InsertLog(LogLevel.Error, "2- " + ex.Message);
|
||||
_logger.LogError("2- " + ex.Message);
|
||||
|
||||
}
|
||||
return RedirectToAction(nameof(Configure));
|
||||
@ -260,7 +258,7 @@ namespace Payments.BTCPayServer.Controllers
|
||||
Policies.CanCreateInvoice, // create invoices for payment
|
||||
Policies.CanViewInvoices, // fetch created invoices to check status
|
||||
Policies.CanModifyInvoices, // able to mark an invoice invalid in case merchant wants to void the order
|
||||
Policies.CanModifyStoreWebhooks, // able to create the webhook required automatically
|
||||
Policies.CanModifyWebhooks, // able to create the webhook required automatically
|
||||
Policies.CanViewStoreSettings, // able to fetch rates
|
||||
Policies.CanCreateNonApprovedPullPayments // able to create refunds
|
||||
},
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using Grand.Business.Core.Extensions;
|
||||
using Grand.Business.Common.Services.Localization;
|
||||
using Grand.Business.Core.Extensions;
|
||||
using Grand.Business.Core.Interfaces.Common.Configuration;
|
||||
using Grand.Business.Core.Interfaces.Common.Directory;
|
||||
using Grand.Business.Core.Interfaces.Common.Localization;
|
||||
@ -7,25 +8,10 @@ using Grand.Infrastructure.Plugins;
|
||||
|
||||
namespace Payments.BTCPayServer
|
||||
{
|
||||
public class BTCPayServerPaymentPlugin : BasePlugin, IPlugin
|
||||
public class BTCPayServerPaymentPlugin( ICurrencyService currencyService,
|
||||
ISettingService settingService,
|
||||
IPluginTranslateResource pluginTranslateResource) : BasePlugin, IPlugin
|
||||
{
|
||||
private readonly ITranslationService _translationService;
|
||||
private readonly ILanguageService _languageService;
|
||||
private readonly ISettingService _settingService;
|
||||
private readonly ICurrencyService _currencyService;
|
||||
|
||||
public BTCPayServerPaymentPlugin(
|
||||
ITranslationService translationService,
|
||||
ILanguageService languageService,
|
||||
ICurrencyService currencyService,
|
||||
ISettingService settingService)
|
||||
{
|
||||
_translationService = translationService;
|
||||
_currencyService = currencyService;
|
||||
_languageService = languageService;
|
||||
_settingService = settingService;
|
||||
}
|
||||
|
||||
public override string ConfigurationUrl()
|
||||
{
|
||||
return "/Admin/BTCPayServer/Configure";
|
||||
@ -36,7 +22,7 @@ namespace Payments.BTCPayServer
|
||||
{
|
||||
try
|
||||
{
|
||||
await _currencyService.InsertCurrency(new Currency {
|
||||
await currencyService.InsertCurrency(new Currency {
|
||||
DisplayLocale = "en-US",
|
||||
Name = "Bitcoin",
|
||||
CurrencyCode = "BTC",
|
||||
@ -55,7 +41,7 @@ namespace Payments.BTCPayServer
|
||||
|
||||
public async override Task Install()
|
||||
{
|
||||
await _settingService.SaveSetting(new BtcPaySettings {
|
||||
await settingService.SaveSetting(new BtcPaySettings {
|
||||
BtcPayUrl = "",
|
||||
ApiKey = "",
|
||||
BtcPayStoreID = "",
|
||||
@ -63,12 +49,12 @@ namespace Payments.BTCPayServer
|
||||
});
|
||||
await AddBTCCurrency();
|
||||
|
||||
await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.AdditionalFee", "Additional fee");
|
||||
await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.AdditionalFee.Hint", "The additional fee.");
|
||||
await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.AdditionalFeePercentage", "Additional fee. Use percentage");
|
||||
await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.AdditionalFeePercentage.Hint", "Determines whether to apply a percentage additional fee to the order total. If not enabled, a fixed value is used.");
|
||||
await pluginTranslateResource.AddOrUpdatePluginTranslateResource("Plugins.Payments.BTCPayServer.AdditionalFee", "Additional fee");
|
||||
await pluginTranslateResource.AddOrUpdatePluginTranslateResource("Plugins.Payments.BTCPayServer.AdditionalFee.Hint", "The additional fee.");
|
||||
await pluginTranslateResource.AddOrUpdatePluginTranslateResource("Plugins.Payments.BTCPayServer.AdditionalFeePercentage", "Additional fee. Use percentage");
|
||||
await pluginTranslateResource.AddOrUpdatePluginTranslateResource("Plugins.Payments.BTCPayServer.AdditionalFeePercentage.Hint", "Determines whether to apply a percentage additional fee to the order total. If not enabled, a fixed value is used.");
|
||||
|
||||
await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.Instructions", "<div class=\"mb-1\"><b>BTCPay Plugin for GrandNode</b></div>" +
|
||||
await pluginTranslateResource.AddOrUpdatePluginTranslateResource("Plugins.Payments.BTCPayServer.Instructions", "<div class=\"mb-1\"><b>BTCPay Plugin for GrandNode</b></div>" +
|
||||
"<div class=\"mb-1\">The plugin configuration can be done automatically or manually.</div>" +
|
||||
"<div class=\"mb-1\"><br/><b>Automatic Configuration:</b></div>" +
|
||||
"<ul>" +
|
||||
@ -86,67 +72,67 @@ namespace Payments.BTCPayServer
|
||||
" </li>" +
|
||||
" <li>To create the BTCPay WebHook, <a href =\"https://docs.btcpayserver.org/VirtueMart/#23-create-a-webhook-on-btcpay-server\" target=\"_blank\">read this</a>. (use the default secret code generated by BTCPay)</li>" +
|
||||
"</ul>");
|
||||
await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.PaymentMethodDescription", "Pay your order in bitcoins");
|
||||
await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.PaymentMethodDescription2", "After completing the order you will be redirected to the merchant BTCPay instance, where you can make the Bitcoin payment for your order.");
|
||||
await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.PaymentError", "Error processing the payment. Please try again and contact us if the problem persists.");
|
||||
await pluginTranslateResource.AddOrUpdatePluginTranslateResource("Plugins.Payments.BTCPayServer.PaymentMethodDescription", "Pay your order in bitcoins");
|
||||
await pluginTranslateResource.AddOrUpdatePluginTranslateResource("Plugins.Payments.BTCPayServer.PaymentMethodDescription2", "After completing the order you will be redirected to the merchant BTCPay instance, where you can make the Bitcoin payment for your order.");
|
||||
await pluginTranslateResource.AddOrUpdatePluginTranslateResource("Plugins.Payments.BTCPayServer.PaymentError", "Error processing the payment. Please try again and contact us if the problem persists.");
|
||||
|
||||
await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.BtcPayUrl", "BTCPay Url");
|
||||
await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.BtcPayUrl.Hint", "The url of your BTCPay instance");
|
||||
await pluginTranslateResource.AddOrUpdatePluginTranslateResource("Plugins.Payments.BTCPayServer.BtcPayUrl", "BTCPay Url");
|
||||
await pluginTranslateResource.AddOrUpdatePluginTranslateResource("Plugins.Payments.BTCPayServer.BtcPayUrl.Hint", "The url of your BTCPay instance");
|
||||
|
||||
await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.CreateApiKey", "Create API key automatically");
|
||||
await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.ApiKey", "API Key");
|
||||
await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.ApiKey.Hint", "The API Key value generated in your BTCPay instance");
|
||||
await pluginTranslateResource.AddOrUpdatePluginTranslateResource("Plugins.Payments.BTCPayServer.CreateApiKey", "Create API key automatically");
|
||||
await pluginTranslateResource.AddOrUpdatePluginTranslateResource("Plugins.Payments.BTCPayServer.ApiKey", "API Key");
|
||||
await pluginTranslateResource.AddOrUpdatePluginTranslateResource("Plugins.Payments.BTCPayServer.ApiKey.Hint", "The API Key value generated in your BTCPay instance");
|
||||
|
||||
await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.BtcPayStoreID", "BTCPay Store ID");
|
||||
await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.BtcPayStoreID.Hint", "The BTCPay Store ID");
|
||||
await pluginTranslateResource.AddOrUpdatePluginTranslateResource("Plugins.Payments.BTCPayServer.BtcPayStoreID", "BTCPay Store ID");
|
||||
await pluginTranslateResource.AddOrUpdatePluginTranslateResource("Plugins.Payments.BTCPayServer.BtcPayStoreID.Hint", "The BTCPay Store ID");
|
||||
|
||||
await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.CreateWebhook", "Create webhook automatically");
|
||||
await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.WebHookUrl", "WebHook Url");
|
||||
await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.WebHookSecret", "WebHook Secret");
|
||||
await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.WebHookSecret.Hint", "The WebHook Secret value generated in your BTCPay instance");
|
||||
await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.WebHookInfo", "Here is the URL to set for the WebHook creation in BTCPay : ");
|
||||
await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.WebHookNote", "Note: when testing the webhook from BTCPay, you should get an HTTP 422 error.<br/>" +
|
||||
await pluginTranslateResource.AddOrUpdatePluginTranslateResource("Plugins.Payments.BTCPayServer.CreateWebhook", "Create webhook automatically");
|
||||
await pluginTranslateResource.AddOrUpdatePluginTranslateResource("Plugins.Payments.BTCPayServer.WebHookUrl", "WebHook Url");
|
||||
await pluginTranslateResource.AddOrUpdatePluginTranslateResource("Plugins.Payments.BTCPayServer.WebHookSecret", "WebHook Secret");
|
||||
await pluginTranslateResource.AddOrUpdatePluginTranslateResource("Plugins.Payments.BTCPayServer.WebHookSecret.Hint", "The WebHook Secret value generated in your BTCPay instance");
|
||||
await pluginTranslateResource.AddOrUpdatePluginTranslateResource("Plugins.Payments.BTCPayServer.WebHookInfo", "Here is the URL to set for the WebHook creation in BTCPay : ");
|
||||
await pluginTranslateResource.AddOrUpdatePluginTranslateResource("Plugins.Payments.BTCPayServer.WebHookNote", "Note: when testing the webhook from BTCPay, you should get an HTTP 422 error.<br/>" +
|
||||
"This is because BTCPay sends empty data while the GrandNode plugin expects real data.<br/>" +
|
||||
"This error therefore indicates that the webhook is indeed accessible from BTCPay.<br/>" +
|
||||
"With a real transaction, you can therefore expect correct operation.");
|
||||
|
||||
await this.AddOrUpdatePluginTranslateResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.NoteRefund", "Please visit the following link to claim your refund: ");
|
||||
await pluginTranslateResource.AddOrUpdatePluginTranslateResource("Plugins.Payments.BTCPayServer.NoteRefund", "Please visit the following link to claim your refund: ");
|
||||
await base.Install();
|
||||
}
|
||||
|
||||
public async override Task Uninstall()
|
||||
{
|
||||
//settings
|
||||
await _settingService.DeleteSetting<BtcPaySettings>();
|
||||
await settingService.DeleteSetting<BtcPaySettings>();
|
||||
|
||||
await this.DeletePluginTranslationResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.AdditionalFee");
|
||||
await this.DeletePluginTranslationResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.AdditionalFee.Hint");
|
||||
await this.DeletePluginTranslationResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.AdditionalFeePercentage");
|
||||
await this.DeletePluginTranslationResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.AdditionalFeePercentage.Hint");
|
||||
await pluginTranslateResource.DeletePluginTranslationResource("Plugins.Payments.BTCPayServer.AdditionalFee");
|
||||
await pluginTranslateResource.DeletePluginTranslationResource("Plugins.Payments.BTCPayServer.AdditionalFee.Hint");
|
||||
await pluginTranslateResource.DeletePluginTranslationResource("Plugins.Payments.BTCPayServer.AdditionalFeePercentage");
|
||||
await pluginTranslateResource.DeletePluginTranslationResource("Plugins.Payments.BTCPayServer.AdditionalFeePercentage.Hint");
|
||||
|
||||
await this.DeletePluginTranslationResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.Instructions");
|
||||
await this.DeletePluginTranslationResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.PaymentMethodDescription");
|
||||
await this.DeletePluginTranslationResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.PaymentMethodDescription2");
|
||||
await this.DeletePluginTranslationResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.PaymentError");
|
||||
await pluginTranslateResource.DeletePluginTranslationResource("Plugins.Payments.BTCPayServer.Instructions");
|
||||
await pluginTranslateResource.DeletePluginTranslationResource("Plugins.Payments.BTCPayServer.PaymentMethodDescription");
|
||||
await pluginTranslateResource.DeletePluginTranslationResource("Plugins.Payments.BTCPayServer.PaymentMethodDescription2");
|
||||
await pluginTranslateResource.DeletePluginTranslationResource("Plugins.Payments.BTCPayServer.PaymentError");
|
||||
|
||||
await this.DeletePluginTranslationResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.BtcPayUrl");
|
||||
await this.DeletePluginTranslationResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.BtcPayUrl.Hint");
|
||||
await pluginTranslateResource.DeletePluginTranslationResource("Plugins.Payments.BTCPayServer.BtcPayUrl");
|
||||
await pluginTranslateResource.DeletePluginTranslationResource("Plugins.Payments.BTCPayServer.BtcPayUrl.Hint");
|
||||
|
||||
await this.DeletePluginTranslationResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.CreateApiKey");
|
||||
await this.DeletePluginTranslationResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.ApiKey");
|
||||
await this.DeletePluginTranslationResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.ApiKey.Hint");
|
||||
await pluginTranslateResource.DeletePluginTranslationResource("Plugins.Payments.BTCPayServer.CreateApiKey");
|
||||
await pluginTranslateResource.DeletePluginTranslationResource("Plugins.Payments.BTCPayServer.ApiKey");
|
||||
await pluginTranslateResource.DeletePluginTranslationResource("Plugins.Payments.BTCPayServer.ApiKey.Hint");
|
||||
|
||||
await this.DeletePluginTranslationResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.BtcPayStoreID");
|
||||
await this.DeletePluginTranslationResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.BtcPayStoreID.Hint");
|
||||
await pluginTranslateResource.DeletePluginTranslationResource("Plugins.Payments.BTCPayServer.BtcPayStoreID");
|
||||
await pluginTranslateResource.DeletePluginTranslationResource("Plugins.Payments.BTCPayServer.BtcPayStoreID.Hint");
|
||||
|
||||
await this.DeletePluginTranslationResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.CreateWebhook");
|
||||
await this.DeletePluginTranslationResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.WebHookUrl");
|
||||
await this.DeletePluginTranslationResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.WebHookSecret");
|
||||
await this.DeletePluginTranslationResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.WebHookSecret.Hint");
|
||||
await this.DeletePluginTranslationResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.WebHookInfo");
|
||||
await this.DeletePluginTranslationResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.WebHookNote");
|
||||
await pluginTranslateResource.DeletePluginTranslationResource("Plugins.Payments.BTCPayServer.CreateWebhook");
|
||||
await pluginTranslateResource.DeletePluginTranslationResource("Plugins.Payments.BTCPayServer.WebHookUrl");
|
||||
await pluginTranslateResource.DeletePluginTranslationResource("Plugins.Payments.BTCPayServer.WebHookSecret");
|
||||
await pluginTranslateResource.DeletePluginTranslationResource("Plugins.Payments.BTCPayServer.WebHookSecret.Hint");
|
||||
await pluginTranslateResource.DeletePluginTranslationResource("Plugins.Payments.BTCPayServer.WebHookInfo");
|
||||
await pluginTranslateResource.DeletePluginTranslationResource("Plugins.Payments.BTCPayServer.WebHookNote");
|
||||
|
||||
await this.DeletePluginTranslationResource(_translationService, _languageService, "Plugins.Payments.BTCPayServer.NoteRefund");
|
||||
await pluginTranslateResource.DeletePluginTranslationResource("Plugins.Payments.BTCPayServer.NoteRefund");
|
||||
await base.Uninstall();
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,13 +3,12 @@ using Grand.Business.Core.Interfaces.Checkout.Orders;
|
||||
using Grand.Business.Core.Interfaces.Checkout.Payments;
|
||||
using Grand.Business.Core.Interfaces.Common.Directory;
|
||||
using Grand.Business.Core.Interfaces.Common.Localization;
|
||||
using Grand.Business.Core.Interfaces.Common.Logging;
|
||||
using Grand.Business.Core.Utilities.Checkout;
|
||||
using Grand.Domain.Customers;
|
||||
using Grand.Domain.Logging;
|
||||
using Grand.Domain.Orders;
|
||||
using Grand.Domain.Payments;
|
||||
using Grand.Infrastructure;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@ -28,7 +27,7 @@ namespace Payments.BTCPayServer
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly IWorkContext _workContext;
|
||||
private readonly ILogger _logger;
|
||||
private readonly ILogger <BTCPayServerPaymentProvider> _logger;
|
||||
private readonly IOrderService _orderService;
|
||||
private readonly LinkGenerator _linkGenerator;
|
||||
private readonly Func<BtcPayService> _btcPayService;
|
||||
@ -42,7 +41,7 @@ namespace Payments.BTCPayServer
|
||||
BtcPaySettings btcPaySettings,
|
||||
LinkGenerator linkGenerator,
|
||||
IOrderService orderService,
|
||||
ILogger logger,
|
||||
ILogger<BTCPayServerPaymentProvider> logger,
|
||||
Func<BtcPayService> btcPayService)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
@ -172,7 +171,7 @@ namespace Payments.BTCPayServer
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task PostRedirectPayment(PaymentTransaction paymentTransaction)
|
||||
public async Task<string> PostRedirectPayment(PaymentTransaction paymentTransaction)
|
||||
{
|
||||
// implement process payment
|
||||
Order? order = null;
|
||||
@ -208,12 +207,13 @@ namespace Payments.BTCPayServer
|
||||
|
||||
await _orderService.UpdateOrder(order);
|
||||
|
||||
_httpContextAccessor.HttpContext?.Response.Redirect(invoice.CheckoutLink);
|
||||
// _httpContextAccessor.HttpContext?.Response.Redirect(invoice.CheckoutLink);
|
||||
return invoice.CheckoutLink;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _logger.InsertLog(LogLevel.Error, ex.Message);
|
||||
_logger.LogError(ex.Message);
|
||||
if (order == null)
|
||||
{
|
||||
order = await _orderService.GetOrderByGuid(paymentTransaction.OrderGuid);
|
||||
@ -224,6 +224,7 @@ namespace Payments.BTCPayServer
|
||||
DisplayToCustomer = true,
|
||||
CreatedOnUtc = DateTime.UtcNow
|
||||
});
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
}
|
||||
@ -246,7 +247,7 @@ namespace Payments.BTCPayServer
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _logger.InsertLog(LogLevel.Error, ex.Message);
|
||||
_logger.LogError(ex.Message);
|
||||
result.AddError(ex.Message);
|
||||
}
|
||||
|
||||
@ -292,7 +293,7 @@ namespace Payments.BTCPayServer
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _logger.InsertLog(LogLevel.Error, ex.Message);
|
||||
_logger.LogError(ex.Message);
|
||||
return new VoidPaymentResult() { NewTransactionStatus = TransactionStatus.Voided };
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
using BTCPayServer.Client.Models;
|
||||
using Grand.Business.Core.Interfaces.Checkout.Orders;
|
||||
using Grand.Business.Core.Interfaces.Common.Configuration;
|
||||
using Grand.Business.Core.Interfaces.Common.Logging;
|
||||
using Grand.Domain.Logging;
|
||||
using Grand.Web.Common.Controllers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Payments.BTCPayServer;
|
||||
using Payments.BTCPayServer.Services;
|
||||
@ -46,23 +45,23 @@ namespace BTCPayServer.Controllers
|
||||
|
||||
if (webhookEvent?.InvoiceId is null || webhookEvent.Metadata?.TryGetValue("orderId", out var orderIdToken) is not true || orderIdToken.ToString() is not { } orderId)
|
||||
{
|
||||
await _logger.InsertLog(LogLevel.Error, "Missing fields in request");
|
||||
_logger.LogError("Missing fields in request");
|
||||
return StatusCode(StatusCodes.Status422UnprocessableEntity);
|
||||
}
|
||||
|
||||
var order = await _orderService.GetOrderByGuid(new Guid(orderId));
|
||||
if (order == null)
|
||||
{
|
||||
await _logger.InsertLog(LogLevel.Error, "Order not found");
|
||||
_logger.LogError("Order not found");
|
||||
return StatusCode(StatusCodes.Status422UnprocessableEntity);
|
||||
}
|
||||
|
||||
|
||||
var settings = _settingService.LoadSetting<BtcPaySettings>(order.StoreId);
|
||||
var settings = await _settingService.LoadSetting<BtcPaySettings>(order.StoreId);
|
||||
|
||||
if (settings.WebHookSecret is not null && !BtcPayService.CheckSecretKey(settings.WebHookSecret, jsonStr, BtcPaySecret))
|
||||
{
|
||||
await _logger.InsertLog(LogLevel.Error, "Bad secret key");
|
||||
_logger.LogError("Bad secret key");
|
||||
return StatusCode(StatusCodes.Status400BadRequest);
|
||||
}
|
||||
|
||||
@ -74,7 +73,7 @@ namespace BTCPayServer.Controllers
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _logger.InsertLog(LogLevel.Error, ex.Message);
|
||||
_logger.LogError(ex.Message);
|
||||
return StatusCode(StatusCodes.Status400BadRequest);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
using Grand.Infrastructure;
|
||||
using Grand.Infrastructure.Plugins;
|
||||
using Grand.Infrastructure.Plugins;
|
||||
|
||||
[assembly: PluginInfo(
|
||||
FriendlyName = "BTCPay - Pay in bitcoins",
|
||||
Group = "Payment methods",
|
||||
SystemName = "Payments.BTCPayServer",
|
||||
SupportedVersion = GrandVersion.SupportedPluginVersion,
|
||||
Author = "Nisaba Solutions",
|
||||
Version = GrandVersion.SupportedPluginVersion + ".002"
|
||||
)]
|
||||
Version = "2.3.0"
|
||||
)]
|
||||
|
||||
@ -2,9 +2,7 @@
|
||||
<Import Project="..\..\Build\Grand.Common.props" />
|
||||
<PropertyGroup>
|
||||
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<StaticWebAssetsEnabled>false</StaticWebAssetsEnabled>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
@ -14,14 +12,12 @@
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<OutputPath>..\..\Web\Grand.Web\Plugins\Payments.BTCPayServer\</OutputPath>
|
||||
<OutDir>
|
||||
$(OutputPath)
|
||||
</OutDir>
|
||||
<OutDir>$(OutputPath)</OutDir>
|
||||
</PropertyGroup>
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<RemoveDir Directories="..\..\Web\Grand.Web\Plugins\Payments.BTCPayServer\refs" />
|
||||
<RemoveDir Directories="..\..\Web\Grand.Web\Plugins\Payments.BTCPayServer\ref" />
|
||||
</Target>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BTCPayServer.Client" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Business\Grand.Business.Core\Grand.Business.Core.csproj">
|
||||
@ -42,17 +38,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BTCPayServer.Client" Version="1.7.3" />
|
||||
<PackageReference Include="NBitcoin" Version="7.0.24" />
|
||||
</ItemGroup>
|
||||
<Target Name="CopyFile" AfterTargets="AfterBuild">
|
||||
<ItemGroup>
|
||||
<CopyFiles Include="$(NuGetPackageRoot)\btcpayserver.client\1.7.3\lib\netstandard2.1\*.dll" />
|
||||
<CopyFiles Include="$(NuGetPackageRoot)\nbitcoin\7.0.24\lib\netstandard2.1\*.dll" />
|
||||
</ItemGroup>
|
||||
<Copy SourceFiles="@(CopyFiles)" DestinationFolder="..\..\Web\Grand.Web\Plugins\Payments.BTCPayServer\" />
|
||||
</Target>
|
||||
<ItemGroup>
|
||||
<None Update="logo.jpg">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
|
||||
@ -2,13 +2,13 @@
|
||||
using BTCPayServer.Client.Models;
|
||||
using Grand.Business.Core.Interfaces.Checkout.Orders;
|
||||
using Grand.Business.Core.Interfaces.Checkout.Payments;
|
||||
using Grand.Business.Core.Interfaces.Common.Logging;
|
||||
using Grand.Business.Core.Utilities.Checkout;
|
||||
using Grand.Domain.Logging;
|
||||
using Grand.Domain.Orders;
|
||||
using Grand.Domain.Payments;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Payments.BTCPayServer.Models;
|
||||
using System.Net.Http;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Payments.BTCPayServer.Services
|
||||
@ -19,12 +19,12 @@ namespace Payments.BTCPayServer.Services
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly IOrderService _orderService;
|
||||
private readonly IPaymentTransactionService _paymentTransactionService;
|
||||
private readonly ILogger _logger;
|
||||
private readonly ILogger<BtcPayService> _logger;
|
||||
|
||||
public BtcPayService(
|
||||
IOrderService orderService,
|
||||
IPaymentTransactionService paymentTransactionService,
|
||||
ILogger logger,
|
||||
ILogger<BtcPayService> logger,
|
||||
IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory;
|
||||
@ -53,8 +53,7 @@ namespace Payments.BTCPayServer.Services
|
||||
Checkout = new InvoiceDataBase.CheckoutOptions() {
|
||||
DefaultLanguage = paymentData.Lang,
|
||||
RedirectURL = paymentData.RedirectionURL,
|
||||
RedirectAutomatically = true,
|
||||
RequiresRefundEmail = false
|
||||
RedirectAutomatically = true
|
||||
},
|
||||
Metadata = JObject.FromObject(new
|
||||
{
|
||||
@ -77,10 +76,10 @@ namespace Payments.BTCPayServer.Services
|
||||
var client = GetClient(settings);
|
||||
var invoice = await client.GetInvoicePaymentMethods(settings.BtcPayStoreID,
|
||||
refundRequest.PaymentTransaction.AuthorizationTransactionId);
|
||||
var pm = (invoice.FirstOrDefault(p => p.Payments.Any()) ?? invoice.First()).PaymentMethod;
|
||||
var pm = (invoice.FirstOrDefault(p => p.Payments.Any()) ?? invoice.First()).PaymentMethodId;
|
||||
var refundInvoiceRequest = new RefundInvoiceRequest() {
|
||||
Name = "Refund order " + refundRequest.PaymentTransaction.OrderGuid,
|
||||
PaymentMethod = pm,
|
||||
PayoutMethodId = pm,
|
||||
};
|
||||
if (refundRequest.IsPartialRefund)
|
||||
{
|
||||
@ -92,7 +91,7 @@ namespace Payments.BTCPayServer.Services
|
||||
else
|
||||
{
|
||||
refundInvoiceRequest.Description = "Full";
|
||||
refundInvoiceRequest.PaymentMethod = "BTC";
|
||||
refundInvoiceRequest.PayoutMethodId = "BTC";
|
||||
refundInvoiceRequest.RefundVariant = RefundVariant.Fiat;
|
||||
}
|
||||
|
||||
@ -187,7 +186,7 @@ namespace Payments.BTCPayServer.Services
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _logger.InsertLog(LogLevel.Error, "UpdateOrderWithInvoice() - paymentTransaction: " + ex.Message);
|
||||
_logger.LogError("UpdateOrderWithInvoice() - paymentTransaction: " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -285,11 +284,11 @@ namespace Payments.BTCPayServer.Services
|
||||
case WebhookEventType.InvoiceReceivedPayment
|
||||
when webhookEvent.ReadAs<WebhookInvoiceReceivedPaymentEvent>() is { } receivedPaymentEvent:
|
||||
return
|
||||
$"Payment detected ({receivedPaymentEvent.PaymentMethod}: {receivedPaymentEvent.Payment.Value})";
|
||||
$"Payment detected ({receivedPaymentEvent.PaymentMethodId}: {receivedPaymentEvent.Payment.Value})";
|
||||
case WebhookEventType.InvoicePaymentSettled
|
||||
when webhookEvent.ReadAs<WebhookInvoicePaymentSettledEvent>() is { } receivedPaymentEvent:
|
||||
return
|
||||
$"Payment settled ({receivedPaymentEvent.PaymentMethod}: {receivedPaymentEvent.Payment.Value})";
|
||||
$"Payment settled ({receivedPaymentEvent.PaymentMethodId}: {receivedPaymentEvent.Payment.Value})";
|
||||
case WebhookEventType.InvoiceProcessing
|
||||
when webhookEvent.ReadAs<WebhookInvoiceProcessingEvent>() is { } receivedPaymentEvent &&
|
||||
receivedPaymentEvent.OverPaid:
|
||||
|
||||
@ -21,7 +21,7 @@ namespace Payments.BTCPayServer
|
||||
}
|
||||
|
||||
public int Priority => 10;
|
||||
public void Configure(IApplicationBuilder application, IWebHostEnvironment webHostEnvironment)
|
||||
public void Configure(WebApplication application, IWebHostEnvironment webHostEnvironment)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user