bunq / tinker_php

Install Tinker by just running this command: bash <(curl -s https://tinker.bunq.com/php/setup.sh)
MIT License
7 stars 8 forks source link

[SOLUTION] SDK is outdated the BunqLib causing Tinker (and examples) Errors in addCallbackUrl #46

Open McSloverd opened 4 years ago

McSloverd commented 4 years ago

First, It is Solved. It is FOR SURE a bug with SDK and the BunqLib in Tinker and Examples.

The basic flow is: Tinker::addCallbackUrl => BunqLib::addCallbackUrl => UserPerson::getNotificationFilters => Add new notification filters to the current filter list => UserPerson::update().

But this is wrong in several places:

  1. at BunqLib::addCallbackUrl is using "new NotificationFilter()" to generate a new NotificationFilter Object. This is incorrect because the SDK is asking for the NotificationFilterUrlUser / NotificationFilterMonataryAccount;

  2. at BunqLib::addCallbackUrl is using UserPerson::update() to set the new NotificationFiler. This is incorrect because: a. the parameters are mismatched; b. the update is no longer taking NotificationFilter as a parameter and it is not going to update the filters;

The Solution: STEP 1. replace BunqLib::addCallbackUrl with:

public function addCallbackUrl(string $callbackUrl) {
       $allUpdatedNotificationFilter[] = new NotificationFilterUrl(
            self::NOTIFICATION_CATEGORY_MUTATION,
            $callbackUrl
        );

        $notificationFilterUrlUser = new NotificationFilterUrlUser($allUpdatedNotificationFilter);
        $notificationFilterUrlUser -> create($allUpdatedNotificationFilter);
}

STEP 2. (THE BUG): in bunq\sdk_php\Model\Core\BunqModel.php at line: 361 Change: $value = static::createListFromResponseArray($response, $wrapper); Into: $value = static::createListFromResponseArray($response[0], $wrapper);

Because the returned response is like:

     Array(1) => 
           Array(1) => 
                Array(5)
                     "NotificationFilters" => 
                     ....

There is one more dimension of the response array.

It is tested in both SANDBOX and PRODUCTION environments.

McSloverd commented 4 years ago

Happy Tinkering~