Skip to content

Firefly III: a personal finances manager

More code for bunq import, must now wait for reply from bunq itself

James Colec4fe9a6a51e0
diff --git a/app/Services/Bunq/Object/MonetaryAccountBank.php b/app/Services/Bunq/Object/MonetaryAccountBank.php
index 31f7224be2..2642d0ac5f 100644
--- a/app/Services/Bunq/Object/MonetaryAccountBank.php
+++ b/app/Services/Bunq/Object/MonetaryAccountBank.php
@@ -19,5 +19,13 @@ namespace FireflyIII\Services\Bunq\Object;
*/
class MonetaryAccountBank extends BunqObject
{
+ /**
+ * MonetaryAccountBank constructor.
+ *
+ * @param array $data
+ */
+ public function __construct(array $data) {
+
+ }
}
\ No newline at end of file
diff --git a/app/Services/Bunq/Object/UserCompany.php b/app/Services/Bunq/Object/UserCompany.php
index 9ae3f18931..c0c861f947 100644
--- a/app/Services/Bunq/Object/UserCompany.php
+++ b/app/Services/Bunq/Object/UserCompany.php
@@ -21,6 +21,52 @@ use Carbon\Carbon;
*/
class UserCompany extends BunqObject
{
+ private $addressMain;
+ private $addressPostal;
+ /** @var array */
+ private $aliases = [];
+ private $avatar;
+ /** @var string */
+ private $cocNumber = '';
+ /** @var string */
+ private $counterBankIban = '';
+ /** @var Carbon */
+ private $created;
+ private $dailyLimit;
+ private $directorAlias;
+ /** @var string */
+ private $displayName = '';
+ /** @var int */
+ private $id = 0;
+ /** @var string */
+ private $language = '';
+ /** @var string */
+ private $name = '';
+ /** @var array */
+ private $notificationFilters = [];
+ /** @var string */
+ private $publicNickName = '';
+ /** @var string */
+ private $publicUuid = '';
+ /** @var string */
+ private $region = '';
+ /** @var string */
+ private $sectorOfIndustry = '';
+ /** @var int */
+ private $sessionTimeout = 0;
+ /** @var string */
+ private $status = '';
+ /** @var string */
+ private $subStatus = '';
+ /** @var string */
+ private $typeOfBusinessEntity = '';
+ /** @var array */
+ private $ubos = [];
+ /** @var Carbon */
+ private $updated;
+ /** @var int */
+ private $versionTos = 0;
+
/**
* UserCompany constructor.
*
@@ -28,6 +74,23 @@ class UserCompany extends BunqObject
*/
public function __construct(array $data)
{
+ $this->id = intval($data['id']);
+ $this->created = Carbon::createFromFormat('Y-m-d H:i:s.u', $data['created']);
+ $this->updated = Carbon::createFromFormat('Y-m-d H:i:s.u', $data['updated']);
+ $this->status = $data['status'];
+ $this->subStatus = $data['sub_status'];
+ $this->publicUuid = $data['public_uuid'];
+ $this->displayName = $data['display_name'];
+ $this->publicNickName = $data['public_nick_name'];
+ $this->language = $data['language'];
+ $this->region = $data['region'];
+ $this->sessionTimeout = intval($data['session_timeout']);
+ $this->versionTos = intval($data['version_terms_of_service']);
+ $this->cocNumber = $data['chamber_of_commerce_number'];
+ $this->typeOfBusinessEntity = $data['type_of_business_entity'] ?? '';
+ $this->sectorOfIndustry = $data['sector_of_industry'] ?? '';
+ $this->counterBankIban = $data['counter_bank_iban'];
+ $this->name = $data['name'];
}
diff --git a/app/Services/Bunq/Object/UserLight.php b/app/Services/Bunq/Object/UserLight.php
new file mode 100644
index 0000000000..fe47df54a7
--- /dev/null
+++ b/app/Services/Bunq/Object/UserLight.php
@@ -0,0 +1,70 @@
+<?php
+/**
+ * UserLight.php
+ * Copyright (c) 2017 [email protected]
+ * This software may be modified and distributed under the terms of the
+ * Creative Commons Attribution-ShareAlike 4.0 International License.
+ *
+ * See the LICENSE file for details.
+ */
+
+declare(strict_types=1);
+
+namespace FireflyIII\Services\Bunq\Object;
+
+use Carbon\Carbon;
+
+/**
+ * Class UserLight
+ *
+ * @package FireflyIII\Services\Bunq\Object
+ */
+class UserLight extends BunqObject
+{
+ /** @var array */
+ private $aliases = [];
+ /** @var Carbon */
+ private $created;
+ /** @var string */
+ private $displayName = '';
+ /** @var string */
+ private $firstName = '';
+ /** @var int */
+ private $id = 0;
+ /** @var string */
+ private $lastName = '';
+ /** @var string */
+ private $legalName = '';
+ /** @var string */
+ private $middleName = '';
+ /** @var string */
+ private $publicNickName = '';
+ /** @var string */
+ private $publicUuid = '';
+ /** @var Carbon */
+ private $updated;
+
+ /**
+ * UserLight constructor.
+ *
+ * @param array $data
+ */
+ public function __construct(array $data)
+ {
+ if(count($data) === 0) {
+ return;
+ }
+ $this->id = intval($data['id']);
+ $this->created = Carbon::createFromFormat('Y-m-d H:i:s.u', $data['created']);
+ $this->updated = Carbon::createFromFormat('Y-m-d H:i:s.u', $data['updated']);
+ $this->publicUuid = $data['public_uuid'];
+ $this->displayName = $data['display_name'];
+ $this->publicNickName = $data['public_nick_name'];
+ $this->firstName = $data['first_name'];
+ $this->middleName = $data['middle_name'];
+ $this->lastName = $data['last_name'];
+ $this->legalName = $data['legal_name'];
+ // aliases
+ }
+
+}
\ No newline at end of file
diff --git a/app/Services/Bunq/Object/UserPerson.php b/app/Services/Bunq/Object/UserPerson.php
index 336d7c9a4f..c9a29ebb4d 100644
--- a/app/Services/Bunq/Object/UserPerson.php
+++ b/app/Services/Bunq/Object/UserPerson.php
@@ -134,4 +134,13 @@ class UserPerson extends BunqObject
// echo '</pre>';
}
+ /**
+ * @return int
+ */
+ public function getId(): int
+ {
+ return $this->id;
+ }
+
+
}
\ No newline at end of file
diff --git a/app/Services/Bunq/Request/ListUserRequest.php b/app/Services/Bunq/Request/ListUserRequest.php
new file mode 100644
index 0000000000..06dbeb96de
--- /dev/null
+++ b/app/Services/Bunq/Request/ListUserRequest.php
@@ -0,0 +1,90 @@
+<?php
+/**
+ * ListUserRequest.php
+ * Copyright (c) 2017 [email protected]
+ * This software may be modified and distributed under the terms of the
+ * Creative Commons Attribution-ShareAlike 4.0 International License.
+ *
+ * See the LICENSE file for details.
+ */
+
+declare(strict_types=1);
+
+namespace FireflyIII\Services\Bunq\Request;
+
+use FireflyIII\Services\Bunq\Object\UserCompany;
+use FireflyIII\Services\Bunq\Object\UserLight;
+use FireflyIII\Services\Bunq\Object\UserPerson;
+use FireflyIII\Services\Bunq\Token\SessionToken;
+
+/**
+ * Class ListUserRequest
+ *
+ * @package FireflyIII\Services\Bunq\Request
+ */
+class ListUserRequest extends BunqRequest
+{
+ /** @var SessionToken */
+ private $sessionToken;
+ /** @var UserCompany */
+ private $userCompany;
+ /** @var UserLight */
+ private $userLight;
+ /** @var UserPerson */
+ private $userPerson;
+
+ /**
+ *
+ */
+ public function call(): void
+ {
+ $uri = '/v1/user';
+ $data = [];
+ $headers = $this->getDefaultHeaders();
+ $headers['X-Bunq-Client-Authentication'] = $this->sessionToken->getToken();
+ $response = $this->sendSignedBunqGet($uri, $data, $headers);
+
+ // create user objects:
+ $light = $this->getKeyFromResponse('UserLight', $response);
+ $company = $this->getKeyFromResponse('UserCompany', $response);
+ $person = $this->getKeyFromResponse('UserPerson', $response);
+ $this->userLight = new UserLight($light);
+ $this->userCompany = new UserCompany($company);
+ $this->userPerson = new UserPerson($person);
+
+ return;
+ }
+
+ /**
+ * @return UserCompany
+ */
+ public function getUserCompany(): UserCompany
+ {
+ return $this->userCompany;
+ }
+
+ /**
+ * @return UserLight
+ */
+ public function getUserLight(): UserLight
+ {
+ return $this->userLight;
+ }
+
+ /**
+ * @return UserPerson
+ */
+ public function getUserPerson(): UserPerson
+ {
+ return $this->userPerson;
+ }
+
+
+ /**
+ * @param SessionToken $sessionToken
+ */
+ public function setSessionToken(SessionToken $sessionToken)
+ {
+ $this->sessionToken = $sessionToken;
+ }
+}
\ No newline at end of file
diff --git a/app/Support/Import/Information/BunqInformation.php b/app/Support/Import/Information/BunqInformation.php
index 971336df75..3c41800fa1 100644
--- a/app/Support/Import/Information/BunqInformation.php
+++ b/app/Support/Import/Information/BunqInformation.php
@@ -14,6 +14,7 @@ namespace FireflyIII\Support\Import\Information;
use FireflyIII\Services\Bunq\Request\DeleteDeviceSessionRequest;
use FireflyIII\Services\Bunq\Request\DeviceSessionRequest;
+use FireflyIII\Services\Bunq\Request\ListUserRequest;
use FireflyIII\Services\Bunq\Token\SessionToken;
use FireflyIII\User;
use Illuminate\Support\Collection;
@@ -40,6 +41,7 @@ class BunqInformation implements InformationInterface
{
Log::debug('Now in getAccounts()');
$sessionToken = $this->startSession();
+ $this->getUserInformation($sessionToken);
// get list of Bunq accounts:
@@ -79,6 +81,31 @@ class BunqInformation implements InformationInterface
return;
}
+ /**
+ * @param SessionToken $sessionToken
+ */
+ private function getUserInformation(SessionToken $sessionToken): void
+ {
+ $apiKey = Preferences::getForUser($this->user, 'bunq_api_key')->data;
+ $serverPublicKey = Preferences::getForUser($this->user, 'bunq_server_public_key')->data;
+ $server = config('firefly.bunq.server');
+ $privateKey = Preferences::getForUser($this->user, 'bunq_private_key')->data;
+ $request = new ListUserRequest;
+ $request->setSessionToken($sessionToken);
+ $request->setSecret($apiKey);
+ $request->setServerPublicKey($serverPublicKey);
+ $request->setServer($server);
+ $request->setPrivateKey($privateKey);
+ $request->call();
+ // return the first that isn't null?
+ // get all objects, try to find ID.
+ var_dump($request->getUserCompany());
+ var_dump($request->getUserLight());
+ var_dump($request->getUserPerson());
+
+ return;
+ }
+
/**
* @return SessionToken
*/