From 8bcbdd1c9f8198b5599715b0cdaf146fc62332cf Mon Sep 17 00:00:00 2001 From: Nisaba <34550856+Nisaba@users.noreply.github.com> Date: Tue, 18 Feb 2025 00:09:38 +0000 Subject: [PATCH] Update NopCommerce 4.9 / BTCPay 2 --- BtcPayPaymentProcessor.cs | 7 ++++--- Controllers/PaymentBTCPayServerController.cs | 8 ++++---- Controllers/WebHookBtcPayController.cs | 2 +- Nop.Plugin.Payments.BtcPayServer.csproj | 4 ++-- Nop.Plugin.Payments.BtcPayServer.csproj.user | 6 ++++++ Services/BtcPayService.cs | 13 ++++++------- plugin.json | 4 ++-- 7 files changed, 25 insertions(+), 19 deletions(-) create mode 100644 Nop.Plugin.Payments.BtcPayServer.csproj.user diff --git a/BtcPayPaymentProcessor.cs b/BtcPayPaymentProcessor.cs index 2946dfa..96d6230 100644 --- a/BtcPayPaymentProcessor.cs +++ b/BtcPayPaymentProcessor.cs @@ -133,6 +133,7 @@ namespace Nop.Plugin.Payments.BTCPayServer "", ["Plugins.Payments.BTCPayServer.WebHookInfo"] = "Here is the URL to set for the WebHook creation in BTCPay : ", @@ -298,7 +299,7 @@ namespace Nop.Plugin.Payments.BTCPayServer // implement process payment try { - + var myStore = await _storeService.GetStoreByIdAsync(processPaymentRequest.StoreId); var currency = await _currencyService.GetCurrencyByIdAsync(_currencySettings.PrimaryStoreCurrencyId); var lang = await _languageService.GetLanguageByIdAsync(myStore.DefaultLanguageId); @@ -359,7 +360,7 @@ namespace Nop.Plugin.Payments.BTCPayServer var result = new RefundPaymentResult(); try { - var sUrl = await _btcPayService.CreateRefund(_btcPaySettings, refundPaymentRequest); + var sUrl = await _btcPayService.CreateRefund(_btcPaySettings, refundPaymentRequest); result.NewPaymentStatus = refundPaymentRequest.IsPartialRefund ? PaymentStatus.PartiallyRefunded : PaymentStatus.Refunded; await _orderService.InsertOrderNoteAsync(new OrderNote { @@ -410,4 +411,4 @@ namespace Nop.Plugin.Payments.BTCPayServer } } -} +} \ No newline at end of file diff --git a/Controllers/PaymentBTCPayServerController.cs b/Controllers/PaymentBTCPayServerController.cs index 7c44bed..9e481dd 100644 --- a/Controllers/PaymentBTCPayServerController.cs +++ b/Controllers/PaymentBTCPayServerController.cs @@ -27,7 +27,7 @@ using NUglify.Helpers; namespace Nop.Plugin.Payments.BTCPayServer.Controllers { - [Area(AreaNames.Admin)] + [Area(AreaNames.ADMIN)] [AutoValidateAntiforgeryToken] public class PaymentBTCPayServerController : BasePaymentController { @@ -78,7 +78,7 @@ namespace Nop.Plugin.Payments.BTCPayServer.Controllers [AuthorizeAdmin] public async Task Configure() { - if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManagePaymentMethods)) + if (!await _permissionService.AuthorizeAsync(StandardPermission.Configuration.MANAGE_PAYMENT_METHODS)) return AccessDeniedView(); //load settings for a chosen store scope @@ -126,7 +126,7 @@ namespace Nop.Plugin.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 }, @@ -139,7 +139,7 @@ namespace Nop.Plugin.Payments.BTCPayServer.Controllers [AuthorizeAdmin] public async Task Configure(ConfigurationModel model, string command = null) { - if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManagePaymentMethods)) + if (!await _permissionService.AuthorizeAsync(StandardPermission.Configuration.MANAGE_PAYMENT_METHODS)) return AccessDeniedView(); //load settings for a chosen store scope diff --git a/Controllers/WebHookBtcPayController.cs b/Controllers/WebHookBtcPayController.cs index 7a7c30b..0f8926d 100644 --- a/Controllers/WebHookBtcPayController.cs +++ b/Controllers/WebHookBtcPayController.cs @@ -36,7 +36,7 @@ namespace Nop.Plugin.Payments.BTCPayServer.Controllers [HttpPost] - public async Task Process([FromHeader(Name = "BTCPAY-SIG")] string BtcPaySig) + public async Task Process([FromHeader(Name = "BTCPAY-Sig")] string BtcPaySig) { try { diff --git a/Nop.Plugin.Payments.BtcPayServer.csproj b/Nop.Plugin.Payments.BtcPayServer.csproj index 4872b0f..566336e 100644 --- a/Nop.Plugin.Payments.BtcPayServer.csproj +++ b/Nop.Plugin.Payments.BtcPayServer.csproj @@ -1,6 +1,6 @@ - net7.0 + net9.0 Copyright © Nisaba Solutions Nisaba Solutions Nisaba Solutions @@ -45,7 +45,7 @@ - + diff --git a/Nop.Plugin.Payments.BtcPayServer.csproj.user b/Nop.Plugin.Payments.BtcPayServer.csproj.user new file mode 100644 index 0000000..a0474c6 --- /dev/null +++ b/Nop.Plugin.Payments.BtcPayServer.csproj.user @@ -0,0 +1,6 @@ + + + + <_LastSelectedProfileId>C:\CODES-SOURCES\NopCommerce2\src\Plugins\Nop.Plugin.Payments.BTCPayServer\Properties\PublishProfiles\FolderProfile.pubxml + + \ No newline at end of file diff --git a/Services/BtcPayService.cs b/Services/BtcPayService.cs index cd9d851..abad764 100644 --- a/Services/BtcPayService.cs +++ b/Services/BtcPayService.cs @@ -50,8 +50,7 @@ namespace Nop.Plugin.Payments.BTCPayServer.Services { DefaultLanguage = paymentData.Lang, RedirectURL = paymentData.RedirectionURL, - RedirectAutomatically = true, - RequiresRefundEmail = false + RedirectAutomatically = true }, Metadata = JObject.FromObject(new { @@ -74,11 +73,11 @@ namespace Nop.Plugin.Payments.BTCPayServer.Services var client = GetClient(settings); var invoice = await client.GetInvoicePaymentMethods(settings.BtcPayStoreID, refundRequest.Order.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.Order.OrderGuid, - PaymentMethod = pm, + PayoutMethodId = pm, }; if (refundRequest.IsPartialRefund) { @@ -90,7 +89,7 @@ namespace Nop.Plugin.Payments.BTCPayServer.Services else { refundInvoiceRequest.Description = "Full"; - refundInvoiceRequest.PaymentMethod = "BTC"; + refundInvoiceRequest.PayoutMethodId = "BTC"; refundInvoiceRequest.RefundVariant = RefundVariant.Fiat; } @@ -266,11 +265,11 @@ namespace Nop.Plugin.Payments.BTCPayServer.Services case WebhookEventType.InvoiceReceivedPayment when webhookEvent.ReadAs() is { } receivedPaymentEvent: return - $"Payment detected ({receivedPaymentEvent.PaymentMethod}: {receivedPaymentEvent.Payment.Value})"; + $"Payment detected ({receivedPaymentEvent.PaymentMethodId}: {receivedPaymentEvent.Payment.Value})"; case WebhookEventType.InvoicePaymentSettled when webhookEvent.ReadAs() is { } receivedPaymentEvent: return - $"Payment settled ({receivedPaymentEvent.PaymentMethod}: {receivedPaymentEvent.Payment.Value})"; + $"Payment settled ({receivedPaymentEvent.PaymentMethodId}: {receivedPaymentEvent.Payment.Value})"; case WebhookEventType.InvoiceProcessing when webhookEvent.ReadAs() is { } receivedPaymentEvent && receivedPaymentEvent.OverPaid: diff --git a/plugin.json b/plugin.json index 3e213d9..9527cac 100644 --- a/plugin.json +++ b/plugin.json @@ -2,8 +2,8 @@ "Group": "Payment methods", "FriendlyName": "Bitcoin payments with BTCPay", "SystemName": "Payments.BTCPayServer", - "Version": "1.01", - "SupportedVersions": [ "4.60" ], + "Version": "1.11", + "SupportedVersions": [ "4.90" ], "Author": "Nisaba Solutions", "DisplayOrder": 1, "FileName": "Nop.Plugin.Payments.BTCPayServer.dll",