mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-25 21:16:47 +00:00
Improved extraction of bunq data.
This commit is contained in:
69
app/Services/Bunq/Object/Alias.php
Normal file
69
app/Services/Bunq/Object/Alias.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* Alias.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;
|
||||
|
||||
/**
|
||||
* Class Alias
|
||||
*
|
||||
* @package FireflyIII\Services\Bunq\Object
|
||||
*/
|
||||
class Alias extends BunqObject
|
||||
{
|
||||
/** @var string */
|
||||
private $name = '';
|
||||
/** @var string */
|
||||
private $type = '';
|
||||
/** @var string */
|
||||
private $value = '';
|
||||
|
||||
/**
|
||||
* Alias constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->type = $data['type'];
|
||||
$this->name = $data['name'];
|
||||
$this->value = $data['value'];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getValue(): string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
58
app/Services/Bunq/Object/Amount.php
Normal file
58
app/Services/Bunq/Object/Amount.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* Currency.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;
|
||||
|
||||
/**
|
||||
* Class Amount
|
||||
*
|
||||
* @package FireflyIII\Services\Bunq\Object
|
||||
*/
|
||||
class Amount extends BunqObject
|
||||
{
|
||||
/** @var string */
|
||||
private $currency = '';
|
||||
/** @var string */
|
||||
private $value = '';
|
||||
|
||||
/**
|
||||
* Amount constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->currency = $data['currency'];
|
||||
$this->value = $data['value'];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrency(): string
|
||||
{
|
||||
return $this->currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getValue(): string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
23
app/Services/Bunq/Object/Avatar.php
Normal file
23
app/Services/Bunq/Object/Avatar.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Avatar.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;
|
||||
|
||||
/**
|
||||
* Class Avatar
|
||||
*
|
||||
* @package FireflyIII\Services\Bunq\Object
|
||||
*/
|
||||
class Avatar extends BunqObject
|
||||
{
|
||||
|
||||
}
|
||||
@@ -12,6 +12,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Bunq\Object;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Class MonetaryAccountBank
|
||||
*
|
||||
@@ -19,13 +21,133 @@ namespace FireflyIII\Services\Bunq\Object;
|
||||
*/
|
||||
class MonetaryAccountBank extends BunqObject
|
||||
{
|
||||
/** @var array */
|
||||
private $aliases = [];
|
||||
/** @var Avatar */
|
||||
private $avatar;
|
||||
/** @var Amount */
|
||||
private $balance;
|
||||
/** @var Carbon */
|
||||
private $created;
|
||||
/** @var string */
|
||||
private $currency = '';
|
||||
/** @var Amount */
|
||||
private $dailyLimit;
|
||||
/** @var Amount */
|
||||
private $dailySpent;
|
||||
/** @var string */
|
||||
private $description = '';
|
||||
/** @var int */
|
||||
private $id = 0;
|
||||
/** @var MonetaryAccountProfile */
|
||||
private $monetaryAccountProfile;
|
||||
/** @var array */
|
||||
private $notificationFilters = [];
|
||||
/** @var Amount */
|
||||
private $overdraftLimit;
|
||||
/** @var string */
|
||||
private $publicUuid = '';
|
||||
/** @var string */
|
||||
private $reason = '';
|
||||
/** @var string */
|
||||
private $reasonDescription = '';
|
||||
/** @var MonetaryAccountSetting */
|
||||
private $setting;
|
||||
/** @var string */
|
||||
private $status = '';
|
||||
/** @var string */
|
||||
private $subStatus = '';
|
||||
/** @var Carbon */
|
||||
private $updated;
|
||||
/** @var int */
|
||||
private $userId = 0;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAliases(): array
|
||||
{
|
||||
return $this->aliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrency(): string
|
||||
{
|
||||
return $this->currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Amount
|
||||
*/
|
||||
public function getBalance(): Amount
|
||||
{
|
||||
return $this->balance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MonetaryAccountSetting
|
||||
*/
|
||||
public function getSetting(): MonetaryAccountSetting
|
||||
{
|
||||
return $this->setting;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* MonetaryAccountBank constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data) {
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->id = $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->balance = new Amount($data['balance']);
|
||||
$this->currency = $data['currency'];
|
||||
$this->dailyLimit = new Amount($data['daily_limit']);
|
||||
$this->dailySpent = new Amount($data['daily_spent']);
|
||||
$this->description = $data['description'];
|
||||
$this->publicUuid = $data['public_uuid'];
|
||||
$this->status = $data['status'];
|
||||
$this->subStatus = $data['sub_status'];
|
||||
$this->userId = $data['user_id'];
|
||||
$this->status = $data['status'];
|
||||
$this->subStatus = $data['sub_status'];
|
||||
$this->monetaryAccountProfile = new MonetaryAccountProfile($data['monetary_account_profile']);
|
||||
$this->setting = new MonetaryAccountSetting($data['setting']);
|
||||
$this->overdraftLimit = new Amount($data['overdraft_limit']);
|
||||
|
||||
$this->publicUuid = $data['public_uuid'];
|
||||
|
||||
// create aliases:
|
||||
foreach ($data['alias'] as $alias) {
|
||||
$this->aliases[] = new Alias($alias);
|
||||
}
|
||||
foreach ($data['notification_filters'] as $filter) {
|
||||
$this->notificationFilters = new NotificationFilter($filter);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
43
app/Services/Bunq/Object/MonetaryAccountProfile.php
Normal file
43
app/Services/Bunq/Object/MonetaryAccountProfile.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* MonetaryAccountProfile.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;
|
||||
|
||||
/**
|
||||
* Class MonetaryAccountProfile
|
||||
*
|
||||
* @package FireflyIII\Services\Bunq\Object
|
||||
*/
|
||||
class MonetaryAccountProfile extends BunqObject
|
||||
{
|
||||
/** @var string */
|
||||
private $profileActionRequired = '';
|
||||
/** @var Amount */
|
||||
private $profileAmountRequired;
|
||||
private $profileDrain;
|
||||
private $profileFill;
|
||||
|
||||
/**
|
||||
* MonetaryAccountProfile constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->profileDrain = null;
|
||||
$this->profileFill = null;
|
||||
$this->profileActionRequired = $data['profile_action_required'];
|
||||
$this->profileAmountRequired = new Amount($data['profile_amount_required']);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
67
app/Services/Bunq/Object/MonetaryAccountSetting.php
Normal file
67
app/Services/Bunq/Object/MonetaryAccountSetting.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* MonetaryAccountSetting.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;
|
||||
|
||||
/**
|
||||
* Class MonetaryAccountSetting
|
||||
*
|
||||
* @package FireflyIII\Services\Bunq\Object
|
||||
*/
|
||||
class MonetaryAccountSetting extends BunqObject
|
||||
{
|
||||
/** @var string */
|
||||
private $color = '';
|
||||
/** @var string */
|
||||
private $defaultAvatarStatus = '';
|
||||
/** @var string */
|
||||
private $restrictionChat = '';
|
||||
|
||||
/**
|
||||
* MonetaryAccountSetting constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->color = $data['color'];
|
||||
$this->defaultAvatarStatus = $data['default_avatar_status'];
|
||||
$this->restrictionChat = $data['restriction_chat'];
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getColor(): string
|
||||
{
|
||||
return $this->color;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultAvatarStatus(): string
|
||||
{
|
||||
return $this->defaultAvatarStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRestrictionChat(): string
|
||||
{
|
||||
return $this->restrictionChat;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
32
app/Services/Bunq/Object/NotificationFilter.php
Normal file
32
app/Services/Bunq/Object/NotificationFilter.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* NotificationFilter.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;
|
||||
|
||||
/**
|
||||
* Class NotificationFilter
|
||||
*
|
||||
* @package FireflyIII\Services\Bunq\Object
|
||||
*/
|
||||
class NotificationFilter extends BunqObject
|
||||
{
|
||||
/**
|
||||
* NotificationFilter constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data) {
|
||||
var_dump($data);
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -94,4 +94,14 @@ class UserCompany extends BunqObject
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
79
app/Services/Bunq/Request/ListMonetaryAccountRequest.php
Normal file
79
app/Services/Bunq/Request/ListMonetaryAccountRequest.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* ListMonetaryAccountRequest.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\MonetaryAccountBank;
|
||||
use FireflyIII\Services\Bunq\Token\SessionToken;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class ListMonetaryAccountRequest
|
||||
*
|
||||
* @package FireflyIII\Services\Bunq\Request
|
||||
*/
|
||||
class ListMonetaryAccountRequest extends BunqRequest
|
||||
{
|
||||
/** @var Collection */
|
||||
private $monetaryAccounts;
|
||||
/** @var SessionToken */
|
||||
private $sessionToken;
|
||||
/** @var int */
|
||||
private $userId = 0;
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getMonetaryAccounts(): Collection
|
||||
{
|
||||
return $this->monetaryAccounts;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function call(): void
|
||||
{
|
||||
$this->monetaryAccounts = new Collection;
|
||||
$uri = sprintf('/v1/user/%d/monetary-account', $this->userId);
|
||||
$data = [];
|
||||
$headers = $this->getDefaultHeaders();
|
||||
$headers['X-Bunq-Client-Authentication'] = $this->sessionToken->getToken();
|
||||
$response = $this->sendSignedBunqGet($uri, $data, $headers);
|
||||
|
||||
// create device server objects:
|
||||
$raw = $this->getArrayFromResponse('MonetaryAccountBank', $response);
|
||||
foreach ($raw as $entry) {
|
||||
$account = new MonetaryAccountBank($entry);
|
||||
$this->monetaryAccounts->push($account);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SessionToken $sessionToken
|
||||
*/
|
||||
public function setSessionToken(SessionToken $sessionToken)
|
||||
{
|
||||
$this->sessionToken = $sessionToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
*/
|
||||
public function setUserId(int $userId)
|
||||
{
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user