Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Response - Undefined array key "links" #126

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bnski
Copy link

@bnski bnski commented Jan 20, 2023

Not all API response body payloads contain the links key, which throws an exception.

Example:

<?php

use Hyperwallet\Hyperwallet;

$hyperwallet = new Hyperwallet('username', 'password');

$hyperwallet->listBalancesForAccount('prg-xxxx','act-xxxx');
 ErrorException 

  Undefined array key "links"

  at vendor/hyperwallet/sdk/src/Hyperwallet/Response/ListResponse.php:62
     58▕         } else {
     59▕             $this->hasNextPage = $body['hasNextPage'];
     60▕             $this->hasPreviousPage = $body['hasPreviousPage'];
     61▕             $this->limit = $body['limit'];
  ➜  62▕             $this->links = $body['links'];
     63▕             $this->data = array_map(function ($item) use ($convertEntry) {
     64▕                 return $convertEntry($item);
     65▕             }, $body['data']);
     66▕         }

The above change resolves this:

Hyperwallet\Response\ListResponse {#1282
  -limit: 100
  -hasNextPage: false
  -hasPreviousPage: false
  -data: array:1 [
    0 => Hyperwallet\Model\Balance {#1286
      -properties: array:2 [
        "currency" => "USD"
        "amount" => "1234.56"
      ]
      -updatedProperties: []
      -readOnlyProperties: array:2 [
        0 => "currency"
        1 => "amount"
      ]
    }
  ]
}

Not all API response body payloads contain the links key, which throws an exception.

Example:

```php
<?php

use Hyperwallet\Hyperwallet;

$hyperwallet = new Hyperwallet('username', 'password');

$hyperwallet->listBalancesForAccount('prg-xxxx','act-xxxx');
```

```
 ErrorException 

  Undefined array key "links"

  at vendor/hyperwallet/sdk/src/Hyperwallet/Response/ListResponse.php:62
     58▕         } else {
     59▕             $this->hasNextPage = $body['hasNextPage'];
     60▕             $this->hasPreviousPage = $body['hasPreviousPage'];
     61▕             $this->limit = $body['limit'];
  ➜  62▕             $this->links = $body['links'];
     63▕             $this->data = array_map(function ($item) use ($convertEntry) {
     64▕                 return $convertEntry($item);
     65▕             }, $body['data']);
     66▕         }
```

The above change resolves this:

```
Hyperwallet\Response\ListResponse {#1282
  -limit: 100
  -hasNextPage: false
  -hasPreviousPage: false
  -data: array:1 [
    0 => Hyperwallet\Model\Balance {#1286
      -properties: array:2 [
        "currency" => "USD"
        "amount" => "1234.56"
      ]
      -updatedProperties: []
      -readOnlyProperties: array:2 [
        0 => "currency"
        1 => "amount"
      ]
    }
  ]
}
```
@bnski bnski changed the title Update ListResponse.php API Response - Undefined array key "links" Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant