Skip to content

Error while retrieving a payout batch #238

@AlexanderKarpanProdege

Description

@AlexanderKarpanProdege

We use PHP 8.2 and bitpay/sdk:7.3 (the same error is on 7.2 and dev-master)

A call to GET /payoutBatches/:payoutBatchId throws an exception:
Cannot use object of type stdClass as array
Stack trace:

vendor/bitpay/sdk/src/BitPaySDK/Model/Payout/PayoutBatch.php:87
vendor/bitpay/sdk/src/BitPaySDK/Model/Payout/PayoutBatch.php:243
???:0
vendor/bitpay/sdk/src/BitPaySDK/Util/JsonMapper/JsonMapper.php:651
vendor/bitpay/sdk/src/BitPaySDK/Util/JsonMapper/JsonMapper.php:249
vendor/bitpay/sdk/src/BitPaySDK/Client.php:2030

The JSON response from the endpoint seems to be valid. When the SDK tries to deserialize it with JsonMapper it fails on array of 'instructions'.

vendor/bitpay/sdk/src/BitPaySDK/Model/Payout/PayoutBatch.php:79-92

    private function _computeAndSetAmount()
    {
        $amount = 0.0;
        if ($this->_instructions) {
            foreach ($this->_instructions as $instruction) {
                if ($instruction instanceof PayoutInstruction) {
                    $amount += $instruction->getAmount();
                } else {
                    $amount += $instruction['amount']; // <-- This line
                }
            }
        }
        $this->_amount = $amount;
    }

Instructions are deserialized as an array of stdClass, so it fails on the line $amount += $instruction['amount']; which used to be $amount += $instruction->amount; in the previous versions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions