mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-30 04:33:54 -06:00
More code for bunq import, must now wait for reply from bunq itself
This commit is contained in:
parent
4694e31e35
commit
c4fe9a6a51
@ -19,5 +19,13 @@ namespace FireflyIII\Services\Bunq\Object;
|
||||
*/
|
||||
class MonetaryAccountBank extends BunqObject
|
||||
{
|
||||
/**
|
||||
* MonetaryAccountBank constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data) {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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'];
|
||||
|
||||
}
|
||||
|
||||
|
70
app/Services/Bunq/Object/UserLight.php
Normal file
70
app/Services/Bunq/Object/UserLight.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* UserLight.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
* 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
|
||||
}
|
||||
|
||||
}
|
@ -134,4 +134,13 @@ class UserPerson extends BunqObject
|
||||
// echo '</pre>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
|
||||
}
|
90
app/Services/Bunq/Request/ListUserRequest.php
Normal file
90
app/Services/Bunq/Request/ListUserRequest.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* ListUserRequest.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
* 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;
|
||||
}
|
||||
}
|
@ -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
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user