最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

BTCPay Server integration using Greenfield API not authenticating - Stack Overflow

programmeradmin1浏览0评论

I am currently running this package

"btcpayserver/btcpayserver-greenfield-php": "^2.8"

I keep getting this error:

Error during POST to . Got response (401): {"code":"unauthenticated","message":"Authentication is required for accessing this endpoint"}
Warning: Array to string conversion in D:\xampp\htdocs\my_app\path to file.php on line 79
Array

When I run this code shown below and I don't see the array to string conversion is coming from:

use BTCPayServer\Client\Invoice;
use BTCPayServer\Client\InvoiceCheckoutOptions;
use BTCPayServer\Util\PreciseNumber;
public function createInvoice($amount, $orderId, $buyerEmail)
{
    // Create a basic invoice.
    try {
        $client = new Invoice($this->host, $this->apiKey);
        $result =
            $client->createInvoice(
                $this->storeId,
                $this->currency,
                PreciseNumber::parseString($amount),
                $orderId,
                $buyerEmail
            );
        return $result;
    } catch (\Exception $e) {
        echo "Error: " . $e->getMessage();
        echo $e->getTrace();
    }
}

Implementation:

require_once "vendor/autoload.php";

use Dotenv\Dotenv;
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();

$ObjBtcServer = new \MyApp\CryptoDepositClasses\BTCPayServerClass();
print_r($ObjBtcServer->createInvoice(amount: '600', orderId: "#303", buyerEmail: '[email protected]'));

Can anyone help me with this please?

I got the Store ID from the dashboard and also the API but it's still not authenticating.

I am currently running this package

"btcpayserver/btcpayserver-greenfield-php": "^2.8"

I keep getting this error:

Error during POST to https://mainnet.demo.btcpayserver./api/v1/stores/__STORE_ID/invoices. Got response (401): {"code":"unauthenticated","message":"Authentication is required for accessing this endpoint"}
Warning: Array to string conversion in D:\xampp\htdocs\my_app\path to file.php on line 79
Array

When I run this code shown below and I don't see the array to string conversion is coming from:

use BTCPayServer\Client\Invoice;
use BTCPayServer\Client\InvoiceCheckoutOptions;
use BTCPayServer\Util\PreciseNumber;
public function createInvoice($amount, $orderId, $buyerEmail)
{
    // Create a basic invoice.
    try {
        $client = new Invoice($this->host, $this->apiKey);
        $result =
            $client->createInvoice(
                $this->storeId,
                $this->currency,
                PreciseNumber::parseString($amount),
                $orderId,
                $buyerEmail
            );
        return $result;
    } catch (\Exception $e) {
        echo "Error: " . $e->getMessage();
        echo $e->getTrace();
    }
}

Implementation:

require_once "vendor/autoload.php";

use Dotenv\Dotenv;
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();

$ObjBtcServer = new \MyApp\CryptoDepositClasses\BTCPayServerClass();
print_r($ObjBtcServer->createInvoice(amount: '600', orderId: "#303", buyerEmail: '[email protected]'));

Can anyone help me with this please?

I got the Store ID from the dashboard and also the API but it's still not authenticating.

Share Improve this question edited Apr 9 at 19:44 marc_s 757k184 gold badges1.4k silver badges1.5k bronze badges asked Jan 22 at 10:01 MeshachMeshach 3513 silver badges6 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

It seems the solution was to wait for like 24 hours for the option to show because I did not see it at first until the next day. The previous API i was using was fromt he store level

i located it on the menu Account > API Keys > Generate Key and give it the appropriate authorisation level you want to give it

Now the code works fine, and the array-to-string conversion was coming from the way I was printing the result from the request; I was supposed to call it like this:

$result = new Invoice(..., ...);

$result->getData(): // fix here

发布评论

评论列表(0)

  1. 暂无评论