bitpay / php-bitpay-client-v2

PHP implementation for the BitPay Cryptographically Secure RESTful API
MIT License
42 stars 41 forks source link

BITPAY-INVOICE-CREATE: Failed to create invoice-> failed to serialize Invoice object : failed to retrieve HTTP response body : Unauthorized sin" #111

Closed foam-agency closed 2 years ago

foam-agency commented 2 years ago

Tries to use sdk on test api. 1) I generate private key with master password 2) I create and approve merchant token with the help of generator from examples, for key from 1st step. I saw it in dashboard for my account 3) Now tries to create invoice with configured client on the test api and got subject error in response

What I'm doing wrong?

bobbrodie commented 2 years ago

Hi there @foam-agency -- could you share a bit more about your scenario?

foam-agency commented 2 years ago

php 8.0 merchat facade Here is laravel DI for bitpay service

$this->app->singleton(\BitPaySDK\Client::class, function ($app) {
            return \BitPaySDK\Client::create()->withData(
                'Test',
                '/var/www/html/private.key',
                \BitPaySDK\Tokens::loadFromArray([
                    'merchant' => '2M<secret>1n', //merchant
                ]),
                'secret' //used to decrypt your private key, if encrypted
            );
        });

Here is invoice creattion code

$bitpay_client = resolve(Client::class); /** @var $bitpay_client Client */

        $invoice = new Invoice($cart->getAmount(), 'USD'); //Always use the included Currency model to avoid typos
        $invoice->setOrderId("65f5090680f6");
        $invoice->setFullNotifications(true);
        $invoice->setExtendedNotifications(true);
        $invoice->setNotificationURL("https://hookbin.com/lJnJg9WW7MtG9GZlPVdj");
        $invoice->setRedirectURL("https://hookbin.com/lJnJg9WW7MtG9GZlPVdj");
        $invoice->setItemDesc("Ab tempora sed ut.");
        $invoice->setNotificationEmail("");

        $buyer = new Buyer();
        $buyer->setName("Bily Matthews");
        $buyer->setEmail("");
        $buyer->setAddress1("168 General Grove");
        $buyer->setAddress2("");
        $buyer->setCountry("AD");
        $buyer->setLocality("Port Horizon");
        $buyer->setNotify(true);
        $buyer->setPhone("+990123456789");
        $buyer->setPostalCode("KY7 1TH");
        $buyer->setRegion("New Port");

        $invoice->setBuyer($buyer);

        $result_invoice = $bitpay_client->createInvoice($invoice, 'merchant');
karenmt commented 2 years ago

I am getting the same error. I created the key with the ConfigGenerator, added the token to my API account. It doesn't work with similar code above, nor does it work when I try with the BitPay Tests. I am running PHP 8.1 and Laravel 9.

use BitPaySDK\Client;
use BitPaySDK\Model\Currency;
use BitPaySDK\Model\Invoice\Invoice;
use BitPaySDK\Tokens;

class PaymentHelper
{

    public static function bitpayRequest($orderId, $grandTotal, $billing)
    {

        $bitpay = Client::create()->withData(
            'Test',
            config_path('bitpay/bitpay.key'),
            new Tokens(
                "Token" //merchant
            ),
            "Password", //used to decrypt your private key, if encrypted
        );
        $invoice = new Invoice(50.0, Currency::USD);
        $basicInvoice = $bitpay->createInvoice($invoice);
    }
}

BitPaySDK\Exceptions\InvoiceCreationException with message 'BITPAY-INVOICE-CREATE: Failed to create invoice-> failed to serialize Invoice object : failed to retrieve HTTP response body : Unauthorized sin'

Also of note, the Guide has $invoice->setToken($bitpay->_token);, but $bitpay->_token does not exist.

bobbrodie commented 2 years ago

@foam-agency , @karenmt thank you so much for the feedback. We're in the process of updating our SDK and guides, and do have a working example we can share, however it's not shown using Laravel. With the popularity of the framework, we'll be sure to add this to our backlog as something to provide in the near future.

Can you both confirm that when you create your token, you are:

Here are some examples that I use locally, without a framework. They aren't intended to be production-ready, just something scrappy I use for on-the-fly testing. I add and remove various bits depending on what I need to do, so there may be an occasional unused variable, etc. but I tested before posting so it should be alright.

Simplified key generation class

<?php
namespace YourNamespace\BitpayPHPExample;

error_reporting(E_ALL ^ E_DEPRECATED);

use BitPayKeyUtils\KeyHelper\PrivateKey;
use BitPayKeyUtils\Storage\EncryptedFilesystemStorage;

require __DIR__ . '/../vendor/autoload.php';

class Keygen {
  private $privateKey;

  private function createToken() {
    $facade      = 'merchant';
    $publicKey   = $this->privateKey->getPublicKey();
    $resourceUrl = 'https://test.bitpay.com/tokens';
    $sin         = $publicKey->getSin()->__toString();

    $postData = json_encode([
        'id' => $sin,
        'facade' => $facade
    ]);

    $curlCli = curl_init($resourceUrl);
    $xSignature = $this->privateKey->sign($resourceUrl . $postData);
    echo 'Signed Data: ' . $xSignature . PHP_EOL . PHP_EOL;

    curl_setopt($curlCli, CURLOPT_HTTPHEADER, [
        'x-accept-version: 2.0.0',
        'Content-Type: application/json',
        'x-identity' => $publicKey->__toString(),
        'x-signature' => $xSignature
    ]);

    curl_setopt($curlCli, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($curlCli, CURLOPT_POSTFIELDS, stripslashes($postData));
    curl_setopt($curlCli, CURLOPT_RETURNTRANSFER, true);

    $result = curl_exec($curlCli);
    $resultData = json_decode($result, TRUE);

    curl_close($curlCli);

    if (array_key_exists('error', $resultData)) {
        echo $resultData['error'];
        exit;
    }

    echo 'Store this information for later!' . PHP_EOL;
    echo '=================================' . PHP_EOL;
    echo 'SIN:          ' . $sin . PHP_EOL;
    echo 'X-Identity:   ' . $publicKey->__toString() . PHP_EOL;
    echo 'Token:        ' . $resultData['data'][0]['token'] . PHP_EOL;
    echo 'Facade:       ' . $resultData['data'][0]['facade'] . PHP_EOL;
    echo '=================================' . PHP_EOL;

    /**
     * Example of a pairing Code returned from the BitPay API
     * which needs to be APPROVED on the BitPay Dashboard before being able to use it.
     **/
    echo 'Pairing Code: ' . $resultData['data'][0]['pairingCode'] . PHP_EOL . PHP_EOL;
    echo 'Log into the BitPay dashboard, search for your pairing code, and create the token.' . PHP_EOL;
  }

  public function generate($password) {
    $privateKey = new PrivateKey(__DIR__ . '/../secure/private.key');
    $this->privateKey = $privateKey->generate();

    $storageEngine = new EncryptedFilesystemStorage($password);
    $storageEngine->persist($this->privateKey);

    $this->createToken();
  }
}

If you run generate(), it will print data like this (note the *** are just placeholders so we're not sharing sensitive info):

Signed Data: *** LONG STRING ***

Store this information for later!
=================================
SIN:          *** YOUR SIN STRING ***
X-Identity:   *** X-IDENTITY HEADER FOR THIS CALL ***
Token:        *** THE TOKEN TO USE IN OTHER CALLS ***
Facade:       merchant
=================================
Pairing Code: *** PAIRING CODE TO CLAIM TOKEN ***

Example class to generate invoice

<?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__ . '/../secure/private.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);
    $invoice->setOrderId('1000000000');
    $invoice->setFullNotifications(true);
    $invoice->setExtendedNotifications(true);
    $invoice->setNotificationURL('https://hookb.in/kxEkW1MzZoUBDokBLjGP');
    $invoice->setRedirectURL('https://hookb.in/kxEkW1MzZoUBDokBLjGP');
    $invoice->setItemDesc('My test item');
    $invoice->setNotificationEmail('r.brodie+seller@your-domain-here.com');
    $invoice->setBuyerEmail('r.brodie+buyer@your-domain-here.com');

    $buyer = new Buyer();
    $buyer->setName('Robert Brodie');
    $buyer->setEmail('r.brodie+buyer@your-domain-here.com');
    $buyer->setAddress1('123 Main St.');
    $buyer->setAddress2('');
    $buyer->setCountry('US');
    $buyer->setLocality('Anytown');
    $buyer->setNotify(true);
    $buyer->setPostalCode('11111');
    $buyer->setRegion('New City');

    $invoice->setBuyer($buyer);

    $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;
  }
}

This will give output like the following:

Invoice URL      : https://test.bitpay.com/invoice?id=*** INVOICE ID ***
Invoice JSON URL : https://test.bitpay.com/invoices/*** INVOICE ID ***
karenmt commented 2 years ago

When creating the private key, I followed the instructions on https://github.com/bitpay/php-bitpay-client-v2/blob/master/GUIDE.md#getting-started which only mentions running the Bitpay Config Generator. There is no mention of creating a public key or sin. There is a link that says "Getting your client token", but it's a dead link.

It looks like the library should be grabbing the public key on its own. In RESTcli.php, it creates x-identity with $this->_identity = $this->_ecKey->getPublicKey()->__toString();, where $this->_ecKey is an instance of PrivateKey. $sin is referenced in the ConfigGenerator, but it doesn't provide it at al.

bobbrodie commented 2 years ago

Hi @karenmt we are currently working on updating documentation and will have more robust information for the SDKs, overall. More in-depth documentation regarding the end-to-end process can be found in the API documentation.

An SIN is the system identification number, and can be derived from the public key. You don't need a static public key like many key pairs, because a new one can be easily derived. You're right that it doesn't mention generating a public key or SIN, I just keep them in my personal scripts because they're concepts to understand regarding the system. The SDK does this for you and populates the necessary headers.

Testing

I've re-tested the config generator and have been able to create invoices.

Here are the steps that I followed:

  1. Ensure that the PrivateKeyName.key file does not exist in the directory that you run the config generator from (examples/)
  2. Change to the examples/ directory
  3. Run php ConfigGenerator.php
    • Note the pairing codes
    • Note the tokens
  4. Claim your pairing codes
  5. Implement a BitPay Client (note: the password used in the ConfigGenerator, unless modified, will be YourMasterPassword.)
  6. Use the BitPay Client to create an invoice

Notes

Please let me know if this is helpful -- we're taking all feedback and are considering it all as we build out plans both near-term and long-term.

karenmt commented 2 years ago

Here are the steps I took:

use BitPaySDK\Client;
use BitPaySDK\Env;
use BitPaySDK\Model\Currency;
use BitPaySDK\Model\Invoice\Invoice;
use BitPaySDK\Tokens;

$bitpay =Client::create()->withData(
            Env::Test,
            config_path('bitpay/bitpay.key'), // Laravel's helper to create the absolute path to the file
            new Tokens(
                "MyMerchantToken" // Same as in the config and shown on screen
            ),
            "MyPassword", // same used in ConfigGenerator and showing in BitPay.config.json
        );
        $invoice = new Invoice(50.0, Currency::USD);
        $basicInvoice = $bitpay->createInvoice($invoice);

With that, I get

BitPaySDK\Exceptions\InvoiceCreationException with message 'BITPAY-INVOICE-CREATE: Failed to create invoice-> failed to serialize Invoice object : failed to retrieve HTTP response body : Unauthorized sin

I also copied your ExampleInvoice script, and got the same error.

bobbrodie commented 2 years ago

Thanks again, @karenmt . I've used your example to create an invoice using Laravel. Here are the steps that I've followed to achieve this.

NOTE: I am sharing my tokens (not the generated private key) for real-world demonstration purposes, but they were for the Test environment and have since been revoked.

Step 1: Generate Private Key and Tokens

The ConfigGenerator is just an example to show how keys and tokens can be generated. It is not intended to be run from within a project, so here's what I did, starting from scratch (I am using PHP 8.1):

Check out the SDK into a separate directory

git clone git@github.com:bitpay/php-bitpay-client-v2.git

Change to the new directory

cd php-bitpay-client-v2

Install dependencies

composer install

Change to the examples/ directory

cd examples/

Update ConfigGenerator.php

$privateKeyname = 'bitpay.key';
$yourMasterPassword = 'MyPassword';

Run ConfigGenerator.php

php ConfigGenerator.php

My output

Merchant Facade
    -> Pairing Code: ZpQ1tku
    -> Token: 3yPULLLr8HZF5xknd141Dx15Mh6CHt1TTXbncqtooneH

Payout Facade
    -> Pairing Code: xXhrP8h
    -> Token: CEufXJGDTbYKAtR5YhNx8kRZc5AL7kvsfcKoqXxkVcqM

Claim the merchant token (not worried about payout for this test)

Note: The Client ID and Token are not the same, no expectation for them to match.

Step 2: Set up Laravel

Create a new application

laravel new test-laravel

Install the BitPay SDK

composer require bitpay/sdk

Copy the private key to the Laravel app

Load Tinker

php artisan tinker

Run the following

use BitPaySDK\Client;
use BitPaySDK\Env;
use BitPaySDK\Model\Currency;
use BitPaySDK\Model\Invoice\Invoice;
use BitPaySDK\Tokens;

$bitpay = Client::create()->withData(
            Env::Test,
            config_path('bitpay/bitpay.key'),
            new Tokens(
              "3yPULLLr8HZF5xknd141Dx15Mh6CHt1TTXbncqtooneH"
            ),
            "MyPassword",
          );
$invoice = new Invoice(50.0, Currency::USD);
$basicInvoice = $bitpay->createInvoice($invoice);
print_r($basicInvoice);

Receive the following output

BitPaySDK\Model\Invoice\Invoice Object
(
    [_currency:protected] => USD
    [_guid:protected] => 646c7c87-882a-b7a9-0da2-f97906753f71
    [_token:protected] => AR4cRaMFnTAFzNWt1ABFdTEAhgpx5RAdvQNR7fmboc1iMhSwPVsqUWNweF9a5Y8FL
    [_price:protected] => 50
    [_posData:protected] => 
    [_notificationURL:protected] => 
    [_transactionSpeed:protected] => medium
    [_fullNotifications:protected] => 
    [_notificationEmail:protected] => 
    [_redirectURL:protected] => 
    [_orderId:protected] => 
    [_itemDesc:protected] => 
    [_itemCode:protected] => 
    [_physical:protected] => 
    [_paymentCurrencies:protected] => 
    [_paymentSubtotals:protected] => stdClass Object
        (
            [BTC] => 248700
            [BCH] => 41017200
            [ETH] => 37328000000000000
            [GUSD] => 5000
            [PAX] => 5.0E+19
            [BUSD] => 5.0E+19
            [USDC] => 50000000
            [DOGE] => 77755056000
            [LTC] => 92575400
            [MATIC] => 5.9185606E+19
            [USDC_m] => 50000000
        )

    [_paymentTotals:protected] => stdClass Object
        (
            [BTC] => 248800
            [BCH] => 41017200
            [ETH] => 37328000000000000
            [GUSD] => 5000
            [PAX] => 5.0E+19
            [BUSD] => 5.0E+19
            [USDC] => 50000000
            [DOGE] => 77755056000
            [LTC] => 92575400
            [MATIC] => 5.9185606E+19
            [USDC_m] => 50000000
        )

    [_paymentDisplayTotals:protected] => 
    [_paymentDisplaySubTotals:protected] => 
    [_paymentCodes:protected] => stdClass Object
        (
            [BTC] => stdClass Object
                (
                    [BIP72b] => bitcoin:?r=https://test.bitpay.com/i/8KZMYg3ZHZDuLTNFk7vvhz
                    [BIP73] => https://test.bitpay.com/i/8KZMYg3ZHZDuLTNFk7vvhz
                )

            [BCH] => stdClass Object
                (
                    [BIP72b] => bitcoincash:?r=https://test.bitpay.com/i/8KZMYg3ZHZDuLTNFk7vvhz
                    [BIP73] => https://test.bitpay.com/i/8KZMYg3ZHZDuLTNFk7vvhz
                )

            [ETH] => stdClass Object
                (
                    [EIP681] => ethereum:?r=https://test.bitpay.com/i/8KZMYg3ZHZDuLTNFk7vvhz
                )

            [GUSD] => stdClass Object
                (
                    [EIP681b] => ethereum:?r=https://test.bitpay.com/i/8KZMYg3ZHZDuLTNFk7vvhz
                )

            [PAX] => stdClass Object
                (
                    [EIP681b] => ethereum:?r=https://test.bitpay.com/i/8KZMYg3ZHZDuLTNFk7vvhz
                )

            [BUSD] => stdClass Object
                (
                    [EIP681b] => ethereum:?r=https://test.bitpay.com/i/8KZMYg3ZHZDuLTNFk7vvhz
                )

            [USDC] => stdClass Object
                (
                    [EIP681b] => ethereum:?r=https://test.bitpay.com/i/8KZMYg3ZHZDuLTNFk7vvhz
                )

            [DOGE] => stdClass Object
                (
                    [BIP72b] => dogecoin:?r=https://test.bitpay.com/i/8KZMYg3ZHZDuLTNFk7vvhz
                    [BIP73] => https://test.bitpay.com/i/8KZMYg3ZHZDuLTNFk7vvhz
                )

            [LTC] => stdClass Object
                (
                    [BIP72b] => litecoin:?r=https://test.bitpay.com/i/8KZMYg3ZHZDuLTNFk7vvhz
                    [BIP73] => https://test.bitpay.com/i/8KZMYg3ZHZDuLTNFk7vvhz
                )

            [MATIC] => stdClass Object
                (
                    [EIP681] => matic:?r=https://test.bitpay.com/i/8KZMYg3ZHZDuLTNFk7vvhz
                )

            [USDC_m] => stdClass Object
                (
                    [EIP681b] => matic:?r=https://test.bitpay.com/i/8KZMYg3ZHZDuLTNFk7vvhz
                )

        )

    [_paymentString:protected] => 
    [_verificationLink:protected] => 
    [_acceptanceWindow:protected] => 
    [_buyer:protected] => BitPaySDK\Model\Invoice\Buyer Object
        (
            [_name:protected] => 
            [_address1:protected] => 
            [_address2:protected] => 
            [_locality:protected] => 
            [_region:protected] => 
            [_postalCode:protected] => 
            [_country:protected] => 
            [_email:protected] => 
            [_phone:protected] => 
            [_notify:protected] => 
        )

    [_refundAddresses:protected] => Array
        (
        )

    [_closeURL:protected] => 
    [_autoRedirect:protected] => 
    [_jsonPayProRequired:protected] => 
    [_buyerEmail:protected] => 
    [_buyerSms:protected] => 
    [_merchantName:protected] => SUMO Heavy Industries LLC
    [_selectedTransactionCurrency:protected] => 
    [_forcedBuyerSelectedWallet:protected] => 
    [_forcedBuyerSelectedTransactionCurrency:protected] => 
    [_itemizedDetails:protected] => Array
        (
        )

    [_id:protected] => 8KZMYg3ZHZDuLTNFk7vvhz
    [_url:protected] => https://test.bitpay.com/invoice?id=8KZMYg3ZHZDuLTNFk7vvhz
    [_status:protected] => new
    [_lowFeeDetected:protected] => 
    [_invoiceTime:protected] => 1664988110338
    [_expirationTime:protected] => 1664989010338
    [_currentTime:protected] => 1664988110411
    [_transactions:protected] => Array
        (
        )

    [_exceptionStatus:protected] => 
    [_targetConfirmations:protected] => 6
    [_refundAddressRequestPending:protected] => 
    [_buyerProvidedEmail:protected] => 
    [_buyerProvidedInfo:protected] => BitPaySDK\Model\Invoice\BuyerProvidedInfo Object
        (
            [_name:protected] => 
            [_phoneNumber:protected] => 
            [_selectedWallet:protected] => 
            [_emailAddress:protected] => 
            [_selectedTransactionCurrency:protected] => 
            [_sms:protected] => 
            [_smsVerified:protected] => 
        )

    [_transactionDetails:protected] => BitPaySDK\Model\Invoice\TransactionDetails Object
        (
            [_amount:protected] => 
            [_description:protected] => 
            [_isFee:protected] => 
        )

    [_universalCodes:protected] => BitPaySDK\Model\Invoice\UniversalCodes Object
        (
            [_paymentString:protected] => https://link.test.bitpay.com/i/8KZMYg3ZHZDuLTNFk7vvhz
            [_verificationLink:protected] => 
        )

    [_supportedTransactionCurrencies:protected] => BitPaySDK\Model\Invoice\SupportedTransactionCurrencies Object
        (
            [_btc:protected] => BitPaySDK\Model\Invoice\SupportedTransactionCurrency Object
                (
                    [_enabled:protected] => 1
                    [_reason:protected] => 
                )

            [_bch:protected] => BitPaySDK\Model\Invoice\SupportedTransactionCurrency Object
                (
                    [_enabled:protected] => 1
                    [_reason:protected] => 
                )

            [_eth:protected] => BitPaySDK\Model\Invoice\SupportedTransactionCurrency Object
                (
                    [_enabled:protected] => 1
                    [_reason:protected] => 
                )

            [_usdc:protected] => BitPaySDK\Model\Invoice\SupportedTransactionCurrency Object
                (
                    [_enabled:protected] => 1
                    [_reason:protected] => 
                )

            [_gusd:protected] => BitPaySDK\Model\Invoice\SupportedTransactionCurrency Object
                (
                    [_enabled:protected] => 1
                    [_reason:protected] => 
                )

            [_pax:protected] => BitPaySDK\Model\Invoice\SupportedTransactionCurrency Object
                (
                    [_enabled:protected] => 1
                    [_reason:protected] => 
                )

            [_xrp:protected] => BitPaySDK\Model\Invoice\SupportedTransactionCurrency Object
                (
                    [_enabled:protected] => 
                    [_reason:protected] => usaRestricted
                )

        )

    [_minerFees:protected] => BitPaySDK\Model\Invoice\MinerFees Object
        (
            [_btc:protected] => BitPaySDK\Model\Invoice\MinerFeesItem Object
                (
                    [_satoshisPerByte:protected] => 1
                    [_totalFee:protected] => 100
                    [_fiatAmount:protected] => 0.02
                )

            [_bch:protected] => BitPaySDK\Model\Invoice\MinerFeesItem Object
                (
                    [_satoshisPerByte:protected] => 0
                    [_totalFee:protected] => 0
                    [_fiatAmount:protected] => 0
                )

            [_eth:protected] => BitPaySDK\Model\Invoice\MinerFeesItem Object
                (
                    [_satoshisPerByte:protected] => 0
                    [_totalFee:protected] => 0
                    [_fiatAmount:protected] => 0
                )

            [_usdc:protected] => BitPaySDK\Model\Invoice\MinerFeesItem Object
                (
                    [_satoshisPerByte:protected] => 0
                    [_totalFee:protected] => 0
                    [_fiatAmount:protected] => 0
                )

            [_gusd:protected] => BitPaySDK\Model\Invoice\MinerFeesItem Object
                (
                    [_satoshisPerByte:protected] => 0
                    [_totalFee:protected] => 0
                    [_fiatAmount:protected] => 0
                )

            [_pax:protected] => BitPaySDK\Model\Invoice\MinerFeesItem Object
                (
                    [_satoshisPerByte:protected] => 0
                    [_totalFee:protected] => 0
                    [_fiatAmount:protected] => 0
                )

            [_busd:protected] => BitPaySDK\Model\Invoice\MinerFeesItem Object
                (
                    [_satoshisPerByte:protected] => 0
                    [_totalFee:protected] => 0
                    [_fiatAmount:protected] => 0
                )

            [_xrp:protected] => BitPaySDK\Model\Invoice\MinerFeesItem Object
                (
                    [_satoshisPerByte:protected] => 
                    [_totalFee:protected] => 
                    [_fiatAmount:protected] => 
                )

            [_doge:protected] => BitPaySDK\Model\Invoice\MinerFeesItem Object
                (
                    [_satoshisPerByte:protected] => 0
                    [_totalFee:protected] => 0
                    [_fiatAmount:protected] => 0
                )

            [_ltc:protected] => BitPaySDK\Model\Invoice\MinerFeesItem Object
                (
                    [_satoshisPerByte:protected] => 0
                    [_totalFee:protected] => 0
                    [_fiatAmount:protected] => 0
                )

        )

    [_nonPayProPaymentReceived:protected] => 
    [_shopper:protected] => BitPaySDK\Model\Invoice\Shopper Object
        (
            [_user:protected] => 
        )

    [_billId:protected] => 
    [_refundInfo:protected] => BitPaySDK\Model\Invoice\RefundInfo Object
        (
            [_supportRequest:protected] => 
            [_currency:protected] => 
            [_amounts:protected] => 
        )

    [_extendedNotifications:protected] => 
    [_isCancelled:protected] => 
    [_transactionCurrency:protected] => 
    [_underpaidAmount:protected] => 
    [_overpaidAmount:protected] => 
    [_amountPaid:protected] => 0
    [_displayAmountPaid:protected] => 0
    [_exchangeRates:protected] => stdClass Object
        (
            [BTC] => stdClass Object
                (
                    [USD] => 20106.016084813
                    [BCH] => 164.84394585211
                    [ETH] => 15.007737556584
                    [GUSD] => 20106.016084813
                    [PAX] => 20106.016084813
                    [BUSD] => 20106.016084813
                    [USDC] => 20106.016084813
                    [DOGE] => 312529.3950501
                    [LTC] => 372.19578085589
                    [MATIC] => 23802.552488122
                    [USDC_m] => 20106.016084813
                )

            [BCH] => stdClass Object
                (
                    [USD] => 121.9
                    [BTC] => 0.0060628668059286
                    [ETH] => 0.090989841085011
                    [GUSD] => 121.9
                    [PAX] => 121.9
                    [BUSD] => 121.9
                    [USDC] => 121.9
                    [DOGE] => 1894.8225799432
                    [LTC] => 2.2565716401333
                    [MATIC] => 144.31158991358
                    [USDC_m] => 121.9
                )

            [ETH] => stdClass Object
                (
                    [USD] => 1339.47
                    [BTC] => 0.066620411817368
                    [BCH] => 10.981962777732
                    [GUSD] => 1339.47
                    [PAX] => 1339.47
                    [BUSD] => 1339.47
                    [USDC] => 1339.47
                    [DOGE] => 20820.820354032
                    [LTC] => 24.79581636431
                    [MATIC] => 1585.7345803244
                    [USDC_m] => 1339.47
                )

            [GUSD] => stdClass Object
                (
                    [USD] => 1
                    [BTC] => 4.9736397095394E-5
                    [BCH] => 0.0081987373944413
                    [ETH] => 0.00074643019758007
                    [PAX] => 1
                    [BUSD] => 1
                    [USDC] => 1
                    [DOGE] => 15.544073666474
                    [LTC] => 0.018511662347279
                    [MATIC] => 1.1838522552385
                    [USDC_m] => 1
                )

            [PAX] => stdClass Object
                (
                    [USD] => 1
                    [BTC] => 4.9736397095394E-5
                    [BCH] => 0.0081987373944413
                    [ETH] => 0.00074643019758007
                    [GUSD] => 1
                    [BUSD] => 1
                    [USDC] => 1
                    [DOGE] => 15.544073666474
                    [LTC] => 0.018511662347279
                    [MATIC] => 1.1838522552385
                    [USDC_m] => 1
                )

            [BUSD] => stdClass Object
                (
                    [USD] => 1
                    [BTC] => 4.9736397095394E-5
                    [BCH] => 0.0081987373944413
                    [ETH] => 0.00074643019758007
                    [GUSD] => 1
                    [PAX] => 1
                    [USDC] => 1
                    [DOGE] => 15.544073666474
                    [LTC] => 0.018511662347279
                    [MATIC] => 1.1838522552385
                    [USDC_m] => 1
                )

            [USDC] => stdClass Object
                (
                    [USD] => 1
                    [BTC] => 4.9736397095394E-5
                    [BCH] => 0.0081987373944413
                    [ETH] => 0.00074643019758007
                    [GUSD] => 1
                    [PAX] => 1
                    [BUSD] => 1
                    [DOGE] => 15.544073666474
                    [LTC] => 0.018511662347279
                    [MATIC] => 1.1838522552385
                    [USDC_m] => 1
                )

            [DOGE] => stdClass Object
                (
                    [USD] => 0.0643045
                    [BTC] => 3.1982741470208E-6
                    [BCH] => 0.00052721570878085
                    [ETH] => 4.7998820640288E-5
                    [GUSD] => 0.0643045
                    [PAX] => 0.0643045
                    [BUSD] => 0.0643045
                    [USDC] => 0.0643045
                    [LTC] => 0.0011903831914106
                    [MATIC] => 0.076127027346987
                    [USDC_m] => 0.0643045
                )

            [LTC] => stdClass Object
                (
                    [USD] => 54.01
                    [BTC] => 0.0026862628071223
                    [BCH] => 0.44281380667377
                    [ETH] => 0.0403146949713
                    [GUSD] => 54.01
                    [PAX] => 54.01
                    [BUSD] => 54.01
                    [USDC] => 54.01
                    [DOGE] => 839.53541872626
                    [MATIC] => 63.939860305434
                    [USDC_m] => 54.01
                )

            [MATIC] => stdClass Object
                (
                    [USD] => 0.8448
                    [BTC] => 4.2017308266189E-5
                    [BCH] => 0.006926293350824
                    [ETH] => 0.00063058423091565
                    [GUSD] => 0.8448
                    [PAX] => 0.8448
                    [BUSD] => 0.8448
                    [USDC] => 0.8448
                    [DOGE] => 13.131633433437
                    [LTC] => 0.015638652350981
                    [USDC_m] => 0.8448
                )

            [USDC_m] => stdClass Object
                (
                    [USD] => 1
                    [BTC] => 4.9736397095394E-5
                    [BCH] => 0.0081987373944413
                    [ETH] => 0.00074643019758007
                    [GUSD] => 1
                    [PAX] => 1
                    [BUSD] => 1
                    [USDC] => 1
                    [DOGE] => 15.544073666474
                    [LTC] => 0.018511662347279
                    [MATIC] => 1.1838522552385
                )

        )

    [_bitpayIdRequired:protected] => 
    [_paymentDisplaytotals] => stdClass Object
        (
            [BTC] => 0.002488
            [BCH] => 0.410172
            [ETH] => 0.037328
            [GUSD] => 50.00
            [PAX] => 50.00
            [BUSD] => 50.00
            [USDC] => 50.00
            [DOGE] => 777.550560
            [LTC] => 0.925754
            [MATIC] => 59.185606
            [USDC_m] => 50.00
        )

    [_paymentDisplaySubtotals] => stdClass Object
        (
            [BTC] => 0.002487
            [BCH] => 0.410172
            [ETH] => 0.037328
            [GUSD] => 50.00
            [PAX] => 50.00
            [BUSD] => 50.00
            [USDC] => 50.00
            [DOGE] => 777.550560
            [LTC] => 0.925754
            [MATIC] => 59.185606
            [USDC_m] => 50.00
        )

)

Summary

Unfortunately, without knowing more about your environment and setyp it will be difficult to fully understand what is happening for you in particular. This test was run using PHP 8.1 and Laravel 9.x. If you could report any specific issues you find while debugging, along with a stacktrace that would be very helpful.

karenmt commented 2 years ago

I created a new project/folder for just php-bitpay-client-v2, and running the ConfigGenerator from there created a useable key/token that worked with my existing Laravel code. At this point, I can only guess it's a difference in packages installed between Laravel and a straight installation of php-bitpay-client-v2. The majority of the differences in the packages are minor versions, but there's a few major version differences that I'm not sure make a difference. I've listed the packages below in case it might help. Laravel is fully up-to-date, and php-bitpay-client-v2 was installed an hour ago.

. Laravel Straight bitpay sdk bitpay/key-utils v1.1.0 v1.0.1908 doctrine/instantiator 1.4.1 1.4.0
guzzlehttp/guzzle 7.5.0 7.3.0
guzzlehttp/promises 1.5.2 1.4.1
guzzlehttp/psr7 2.4.1 2.0.0
myclabs/deep-copy 1.11.0 1.10.2
nikic/php-parser v4.15.1 v4.13.0
phar-io/version 3.2.1 3.1.0
phpdocumentor/reflection-docblock 5.2.2
phpdocumentor/type-resolver 1.6.1 1.5.1
phpspec/prophecy 1.14.0
phpunit/php-code-coverage 9.2.17 9.2.7
phpunit/php-file-iterator 3.0.6 3.0.5
phpunit/phpunit 9.5.25 9.5.10
sebastian/comparator 4.0.8 4.0.6
sebastian/environment 5.1.4 5.1.3
sebastian/exporter 4.0.5 4.0.3
sebastian/global-state 5.0.5 5.0.3
sebastian/type 3.2.0 2.3.4
symfony/deprecation-contracts v3.1.1 v2.4.0
symfony/polyfill-ctype v1.26.0 v1.23.0
symfony/yaml v6.1.4 v5.3.6
webmozart/assert 1.11.0 1.10.0

bobbrodie commented 2 years ago

Thanks, @karenmt. Since it's working on a clean setup, we'll close this for now. I would suggest ensuring that your existing Laravel application uses the same versions as the new one you created. If you find any specific replicable bugs, please let us know.

bobbrodie commented 2 years ago

@karenmt , @foam-agency just a quick heads up -- we have found the reason the setup I've posted works. Version 1.0.1908 of the keyutils was prior to an open source contribution of a deprecation cleanup released in 1.1.0. All tests have been passing and initial manual tests passed as well. We are addressing the issue and will release SDK version 7.0.1 and Key Utils version 1.2.0, which we are anticipating will be released early this coming week.

Note: keys generated with 1.0.1908 are working with an application using 1.1.0.

Thank you so much for reporting this, and I will report back here upon the release of the new versions of the SDK and Key Utils. In the meantime, I've re-opened this bug.

bobbrodie commented 2 years ago

We have updated the following:

We have checked that:

This is part of an effort to handle the deprecation of Serializable interfaces in PHP 8.1.

Thanks again @foam-agency , @karenmt !

IamOmni commented 1 year ago

I can confirm that I have encountered the same error today, also on Laravel, however as per @karenmt suggestion, running the config gen on a seperate project folder and plugging the keypair into existing project works like a charm.

I am running laravel sail on a mac, but unsure whether this is actually the cause of the issue, thought I would leave my confirmation here for anyone running into the same issue.