mollie / mollie-api-php

Mollie API client for PHP
http://www.mollie.com
BSD 2-Clause "Simplified" License
550 stars 189 forks source link

API returns object(Mollie\Api\Resources\SettlementCollection) instead of JSON #712

Closed yachtino-dev closed 5 months ago

yachtino-dev commented 5 months ago

Specifications

Describe the issue

I call:

$mollie = new \Mollie\Api\MollieApiClient();
$mollie->setAccessToken('access_xxxxxxxxxxxxxxxx');
$settlements = $mollie->settlements->page();
var_dump($settlements);

Output:

object(Mollie\Api\Resources\SettlementCollection)#88 (4) {
  ["count"]=>
  int(1)
  ["_links"]=>
  object(stdClass)#116 (4) {
    ["documentation"]=>
    object(stdClass)#115 (2) {
      ["href"]=>
      string(69) "https://docs.mollie.com/reference/v2/settlements-api/list-settlements"
      ["type"]=>
      string(9) "text/html"
    }
    ["self"]=>
    object(stdClass)#117 (2) {
      ["href"]=>
      string(46) "https://api.mollie.com/v2/settlements?limit=50"
      ["type"]=>
      string(20) "application/hal+json"
    }
    ["previous"]=>
    NULL
    ["next"]=>
    NULL
  }
  ["client":protected]=>
  object(Mollie\Api\MollieApiClient)#17 (44) {
    ["httpClient":protected]=>
    object(Mollie\Api\HttpAdapter\Guzzle6And7MollieHttpAdapter)#36 (2) {
      ["httpClient":protected]=>
      object(GuzzleHttp\Client)#35 (1) {
        ["config":"GuzzleHttp\Client":private]=>
        array(10) {
          ["verify"]=>
          string(113) "......\vendor\composer\ca-bundle\src/../res/cacert.pem"
          ["timeout"]=>
          int(10)
          ["connect_timeout"]=>
          int(2)
          ["handler"]=>
          object(GuzzleHttp\HandlerStack)#20 (3) {
            ["handler":"GuzzleHttp\HandlerStack":private]=>
            object(Closure)#27 (2) {
...

Do I do anything wrong? How to get the data for this settlement? I get all API responses as API objects (no JSON at all), but eg. for payments I can address the desired variables in the returned object.

Naoray commented 5 months ago

You are not doing anything wrong, this is the expected behavior. You can loop over the collection to get the settlement data.

Check the pagination example for further details.

yachtino-dev commented 5 months ago

I was looking for "_embedded" node/method/property - so it is in the documentation: https://docs.mollie.com/reference/v2/settlements-api/list-settlements

But there is no "_embedded" you could loop through. You have to use $mollie->settlements->iterator() to get a single settlement. Not really understandable from the docu - I not necessarily look into pagination docu when I have ONE settlement item.

Thank you for your quick answer, it helped me.