PHP API Library Help with $User

First of all I am not a current developer, I’m an architect …
now that you’ve finished throwing fruit at me, I’m a little confused with the current PHP API library for Patreon.
Right now I’m just trying to check current data.

I’ve used the example code and my oAuth is happy and returns a callback and I get a data stream which is happily rendered into an Array.

A big Array (Patreon\JSONAPI\ResourceItem Object ( [resource_item:protected] => Art4\JsonApiClient\ResourceItem Object ( [container:protected] => Art4\JsonApiClient\Utils\DataContainer Object ( [allowed_keys:protected] => Array ( ) [data:protected] => Array ( [type] => user [id] )

However the problem comes when I get to looking at user data (and this is from the example code)

if ($user->has(‘relationships.pledges’)) {
Results in :
Notice: Undefined variable: user in /var/www/html/CDS/oauth.php on line 38

Unless I am wrong, I thought the base array types (according to the comments) were assigned automagically.

1 Like

Argh, never mind …
the example code is incorrect it seems…
replacing $user with $patron seems to work just fine.

It even says so in the comments:
$patron will have the authenticated user’s user data, and
$pledge will have their patronage data.

@markgoldienz your first lines made me laugh out loud - and thank you for finding that. Phew - that is frustrating, I apologize - will fix that. We need to overall audit our PHP library and example code. It’s due for some attention.

Thanks Tal, There are a few things I am not getting from the resolve of patron_response.

$pledge->attribute(‘total_historical_amount_cents’)

doesn’t seem to resolve.
I also am unable to find the current reward level, it doesn’t seem to be structured in the way I would expect.

$reward = $patron->relationship(‘reward’)->get(0)->resolve($patron_response);

1 Like

total_historical_amount_cents seems to be properly returned by api while using other libraries, so it doesnt seem to be an api problem.

the function attribute in ResourceIdentifier.php needs to return $pledge->attribute(‘total_historical_amount_cents’) when requested, using factory json api class instantiated as below

$this->resource_item = new \Art4\JsonApiClient\ResourceItem($manager, $parent); in __construct.

Dropping some var_dump to see the input variables and the json api return in __construct may help to see whats going on. Also, if the patron doesnt have any pledge history, that variable may not be returned at all. (Ie, the patron hasnt paid yet).

I’ll look into this, but i have to install the lib in a test environment myself and check it out.

Being too tired and too late here, what i typed above may not be of much help but hopefully will give you some pointers for the time being.

1 Like

Thanks @codebard!

@markgoldienz thanks to @codebard’s help we’ve found some additional issues that seem to likely be our fault here - investigating internally. My apologies for the frustration. Our libraries need a lot of love.

1 Like

For the record, this is how details about the current user is returned.

return $this->__get_json(“current_user”);

But this call doesnt return total_historical_amount_cents by default. You have to specifically ask it like below:

return $this->__get_json(“current_user?fields[pledge]=total_historical_amount_cents”);

However, while this works with WordPress plugin and its calls, for some reason api returns an error when you try the same thing with the PHP library. At least, in the php7 dev container i set up in docker.

You may try modifying the api class to make the call specifically as above, asking for the field and see if it returns properly.

Also you are right in that the data doesnt seem to be structured as described in the example.

$pledge = $patron->relationship('pledges');

echo '<pre>';
print_r($pledge);
echo '</pre>';

May provide more info.