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 @@ +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 ''; } + /** + * @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 @@ +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 */