Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a586dd4a67 | ||
|
|
8bcbdd1c9f | ||
|
|
68ca0e12dc | ||
|
|
2726313b82 | ||
|
|
f24ed2182a | ||
|
|
e3a70c1b76 | ||
|
|
859e75a7c4 | ||
|
|
cfeacb527a | ||
|
|
a14fd6916f | ||
|
|
0ce45d4860 | ||
|
|
8b1ee1cfe2 |
@ -126,25 +126,16 @@ namespace Nop.Plugin.Payments.BTCPayServer
|
||||
"<div class=\"mb-1\"><br/><b>Automatic Configuration:</b></div>" +
|
||||
"<ul>" +
|
||||
" <li>Enter the \"BTCPay Url\" parameter.</li>" +
|
||||
" <li>Click on the \"Configure automatically\" button to be redirected to the key creation page on your BTCPay server.</li>" +
|
||||
" <li>The \"API Key\", \"BTCPay Store ID\" and \"WebHook Secret\" parameters will be automatically filled. Save.</li>" +
|
||||
" <li>Click on the \"Configure automatically\" button to be redirected to the key creation page on your BTCPay Server.</li>" +
|
||||
" <li>The \"API Key\", \"BTCPay Store ID\" and \"WebHook Secret\" parameters will be automatically filled. Make sure to click Save.</li>" +
|
||||
"</ul>" +
|
||||
"<div class=\"mb-1\"><br/><b>Manual Configuration:</b></div>" +
|
||||
"<ul>" +
|
||||
" <li>The \"BTCPay Url,\" \"API Key,\" \"BTCPay Store ID,\" and \"WebHook Secret\" fields must be filled out.</li>" +
|
||||
" <li>To create the BTCPay API key, <a href =\"https://docs.btcpayserver.org/VirtueMart/#22-create-an-api-key-and-configure-permissions\" target=\"_blank\">read this</a>.<br/>" +
|
||||
" <i>Note: If you want to use the Refund feature, you must also add the \"Modify your stores\" permission.<br/>" +
|
||||
" After a refund, an order note is created, indicating the BTCPay link where the customer can request a refund." +
|
||||
" </i>" +
|
||||
" </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>" +
|
||||
" <li>The \"BTCPay Url,\" \"API Key,\" \"BTCPay Store ID,\" and \"WebHook Secret\" fields must be filled out, then save.</li>" +
|
||||
" <li>Read detailed step by step <a href =\"https://github.com/btcpayserver/nopcommerce?tab=readme-ov-file#manual-configuration\" target=\"_blank\"> instructions on how to manually configure</a>. </li>" +
|
||||
"</ul>",
|
||||
|
||||
["Plugins.Payments.BTCPayServer.WebHookInfo"] = "Here is the URL to set for the WebHook creation in BTCPay : ",
|
||||
["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 NopCommerce 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.",
|
||||
|
||||
["Plugins.Payments.BTCPayServer.PaymentMethodDescription"] = "Pay your order in bitcoins",
|
||||
["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.",
|
||||
@ -308,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);
|
||||
@ -369,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
|
||||
{
|
||||
@ -420,4 +411,4 @@ namespace Nop.Plugin.Payments.BTCPayServer
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -27,8 +27,7 @@ using NUglify.Helpers;
|
||||
|
||||
namespace Nop.Plugin.Payments.BTCPayServer.Controllers
|
||||
{
|
||||
[AuthorizeAdmin]
|
||||
[Area(AreaNames.Admin)]
|
||||
[Area(AreaNames.ADMIN)]
|
||||
[AutoValidateAntiforgeryToken]
|
||||
public class PaymentBTCPayServerController : BasePaymentController
|
||||
{
|
||||
@ -75,9 +74,11 @@ namespace Nop.Plugin.Payments.BTCPayServer.Controllers
|
||||
|
||||
#region Methods
|
||||
|
||||
|
||||
[AuthorizeAdmin]
|
||||
public async Task<IActionResult> 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
|
||||
@ -111,16 +112,21 @@ namespace Nop.Plugin.Payments.BTCPayServer.Controllers
|
||||
}
|
||||
|
||||
var myStore = _storeContext.GetCurrentStore();
|
||||
var adminUrl = new Uri(new Uri(myStore.Url),
|
||||
//var adminUrl = new Uri(new Uri(myStore.Url),
|
||||
// _linkGenerator.GetPathByAction(HttpContext, "GetAutomaticApiKeyConfig", "PaymentBTCPayServer",
|
||||
// new { ssid = myStore.Id, btcpayuri = btcpayUri }));
|
||||
var adminUrl = new Uri(new Uri("https://" + Request.Host.Value),
|
||||
_linkGenerator.GetPathByAction(HttpContext, "GetAutomaticApiKeyConfig", "PaymentBTCPayServer",
|
||||
new { ssid = myStore.Id, btcpayuri = btcpayUri }));
|
||||
|
||||
|
||||
var uri = BTCPayServerClient.GenerateAuthorizeUri(btcpayUri,
|
||||
new[]
|
||||
{
|
||||
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
|
||||
},
|
||||
@ -130,9 +136,10 @@ namespace Nop.Plugin.Payments.BTCPayServer.Controllers
|
||||
|
||||
|
||||
[HttpPost]
|
||||
[AuthorizeAdmin]
|
||||
public async Task<IActionResult> 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
|
||||
|
||||
@ -36,7 +36,7 @@ namespace Nop.Plugin.Payments.BTCPayServer.Controllers
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Process([FromHeader(Name = "BTCPAY-SIG")] string BtcPaySig)
|
||||
public async Task<IActionResult> Process([FromHeader(Name = "BTCPAY-Sig")] string BtcPaySig)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Copyright>Copyright © Nisaba Solutions</Copyright>
|
||||
<Company>Nisaba Solutions</Company>
|
||||
<Authors>Nisaba Solutions</Authors>
|
||||
@ -45,7 +45,7 @@
|
||||
<Folder Include="Services\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BTCPayServer.Client" Version="1.7.3" />
|
||||
<PackageReference Include="BTCPayServer.Client" Version="2.0.1" />
|
||||
</ItemGroup>
|
||||
<!-- This target execute after "Build" target -->
|
||||
<Target Name="NopTarget" AfterTargets="Build">
|
||||
|
||||
6
Nop.Plugin.Payments.BtcPayServer.csproj.user
Normal file
6
Nop.Plugin.Payments.BtcPayServer.csproj.user
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<_LastSelectedProfileId>C:\CODES-SOURCES\NopCommerce2\src\Plugins\Nop.Plugin.Payments.BTCPayServer\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@ -1,6 +1,6 @@
|
||||
# BTCPay Server – Accept Bitcoin payments in nopCommerce
|
||||
|
||||

|
||||

|
||||
|
||||
## Plugin Overview
|
||||
|
||||
|
||||
@ -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<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:
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
<br />
|
||||
<p>
|
||||
@T("Plugins.Payments.BTCPayServer.WebHookInfo") @ViewBag.UrlWebHook<br />
|
||||
<i> @Html.Raw(T("Plugins.Payments.BTCPayServer.WebHookNote"))</i>
|
||||
</p>
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,10 +2,10 @@
|
||||
"Group": "Payment methods",
|
||||
"FriendlyName": "Bitcoin payments with BTCPay",
|
||||
"SystemName": "Payments.BTCPayServer",
|
||||
"Version": "1.01",
|
||||
"SupportedVersions": [ "4.60" ],
|
||||
"Version": "1.11",
|
||||
"SupportedVersions": [ "4.80", "4.90" ],
|
||||
"Author": "Nisaba Solutions",
|
||||
"DisplayOrder": 1,
|
||||
"FileName": "Nop.Plugin.Payments.BTCPayServer.dll",
|
||||
"Description": "This plugin enables Bitcoin payment with your BTCPay Server instance"
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user