-
Notifications
You must be signed in to change notification settings - Fork 43
Description
PHP: 8.1
bitpay/sdk: 7.0.0
When creating an Invoice, then using ->toArray() on the result, it throws the error Call to a member function toArray() on array. Steps to recreate:
<?php
namespace YourNamespace\BitpayPHPExample;
error_reporting(E_ALL ^ E_DEPRECATED);
use \BitPaySDK\Model\Currency;
use \BitPaySDK\Model\Invoice\Buyer;
use \BitPaySDK\Model\Invoice\Invoice;
require __DIR__ . '/vendor/autoload.php';
class ExampleInvoice {
private $client;
private function setClient($token, $password) {
$client = \BitPaySDK\Client::create()->withData(
\BitPaySDK\Env::Test,
__DIR__ . '/examples/bitpay.key',
new \BitPaySDK\Tokens(
$token
),
$password,
null
);
$this->client = $client;
}
public function create($token, $password) {
$this->setClient($token, $password);
$invoice = new Invoice(50.0, Currency::USD); //Always use the included Currency model to avoid typos
$invoice->setToken($token);
$basicInvoice = $this->client->createInvoice($invoice);
echo 'Invoice URL : ' . $basicInvoice->getUrl() . PHP_EOL;
echo 'Invoice JSON URL : ' . 'https://test.bitpay.com/invoices/' . $basicInvoice->getId() . PHP_EOL;
var_dump($basicInvoice->toArray());
}
}
$bitpay = new ExampleInvoice();
$bitpay->create('MyToken',"MyPassword");
Uncaught Error: Call to a member function toArray() on array in /home/vagrant/code/bitpaytest/src/BitPaySDK/Model/Invoice/Invoice.php:855
Stack trace:
#0 /home/vagrant/code/bitpaytest/test.php(37): BitPaySDK\Model\Invoice\Invoice->toArray()
#1 /home/vagrant/code/bitpaytest/test.php(42): YourNamespace\BitpayPHPExample\ExampleInvoice->create()
#2 {main}
thrown in /home/vagrant/code/bitpaytest/src/BitPaySDK/Model/Invoice/Invoice.php on line 855
The error line is 'itemizedDetails' => $this->getItemizedDetails()->toArray(),, and setItemizedDetails already creates an array.