mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 01:42:32 +00:00
Improving bunq import.
This commit is contained in:
@@ -21,6 +21,7 @@ use Session;
|
||||
|
||||
class BankController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* This method must ask the user all parameters necessary to start importing data. This may not be enough
|
||||
* to finish the import itself (ie. mapping) but it should be enough to begin: accounts to import from,
|
||||
@@ -42,6 +43,49 @@ class BankController extends Controller
|
||||
$object->setUser(auth()->user());
|
||||
$remoteAccounts = $object->getAccounts();
|
||||
|
||||
return view('import.bank.form', compact('remoteAccounts', 'bank'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* With the information given in the submitted form Firefly III will call upon the bank's classes to return transaction
|
||||
* information as requested. The user will be able to map unknown data and continue. Or maybe, it's put into some kind of
|
||||
* fake CSV file and forwarded to the import routine.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param string $bank
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function postForm(Request $request, string $bank)
|
||||
{
|
||||
|
||||
$class = config(sprintf('firefly.import_pre.%s', $bank));
|
||||
/** @var PrerequisitesInterface $object */
|
||||
$object = app($class);
|
||||
$object->setUser(auth()->user());
|
||||
|
||||
if ($object->hasPrerequisites()) {
|
||||
return redirect(route('import.bank.prerequisites', [$bank]));
|
||||
}
|
||||
$remoteAccounts = $request->get('do_import');
|
||||
if (!is_array($remoteAccounts) || count($remoteAccounts) === 0) {
|
||||
Session::flash('error', 'Must select accounts');
|
||||
|
||||
return redirect(route('import.bank.form', [$bank]));
|
||||
}
|
||||
$remoteAccounts = array_keys($remoteAccounts);
|
||||
|
||||
$class = config(sprintf('firefly.import_pre.%s', $bank));
|
||||
|
||||
var_dump($remoteAccounts);exit;
|
||||
|
||||
// get import file
|
||||
|
||||
// get import config
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,6 +110,7 @@ class BankController extends Controller
|
||||
$object->setUser(auth()->user());
|
||||
if (!$object->hasPrerequisites()) {
|
||||
Log::debug(sprintf('No more prerequisites for %s, move to form.', $bank));
|
||||
|
||||
return redirect(route('import.bank.form', [$bank]));
|
||||
}
|
||||
Log::debug('Going to store entered preprerequisites.');
|
||||
@@ -102,7 +147,8 @@ class BankController extends Controller
|
||||
|
||||
return view($view, $parameters);
|
||||
}
|
||||
return redirect(route('import.bank.form', [$bank]));
|
||||
|
||||
return redirect(route('import.bank.form', [$bank]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -65,5 +65,4 @@ class Alias extends BunqObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -54,5 +54,4 @@ class Amount extends BunqObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -62,56 +62,6 @@ class MonetaryAccountBank extends BunqObject
|
||||
/** @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.
|
||||
*
|
||||
@@ -150,4 +100,52 @@ class MonetaryAccountBank extends BunqObject
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAliases(): array
|
||||
{
|
||||
return $this->aliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Amount
|
||||
*/
|
||||
public function getBalance(): Amount
|
||||
{
|
||||
return $this->balance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrency(): string
|
||||
{
|
||||
return $this->currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MonetaryAccountSetting
|
||||
*/
|
||||
public function getSetting(): MonetaryAccountSetting
|
||||
{
|
||||
return $this->setting;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -37,6 +37,7 @@ class MonetaryAccountProfile extends BunqObject
|
||||
$this->profileFill = null;
|
||||
$this->profileActionRequired = $data['profile_action_required'];
|
||||
$this->profileAmountRequired = new Amount($data['profile_amount_required']);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ class MonetaryAccountSetting extends BunqObject
|
||||
$this->color = $data['color'];
|
||||
$this->defaultAvatarStatus = $data['default_avatar_status'];
|
||||
$this->restrictionChat = $data['restriction_chat'];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,8 @@ class NotificationFilter extends BunqObject
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data) {
|
||||
public function __construct(array $data)
|
||||
{
|
||||
var_dump($data);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -27,16 +27,9 @@ class ServerPublicKey extends BunqObject
|
||||
*
|
||||
* @param array $response
|
||||
*/
|
||||
public function __construct(array $response) {
|
||||
$this->publicKey = $response['server_public_key'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $publicKey
|
||||
*/
|
||||
public function setPublicKey(string $publicKey)
|
||||
public function __construct(array $response)
|
||||
{
|
||||
$this->publicKey = $publicKey;
|
||||
$this->publicKey = $response['server_public_key'];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,5 +40,13 @@ class ServerPublicKey extends BunqObject
|
||||
return $this->publicKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $publicKey
|
||||
*/
|
||||
public function setPublicKey(string $publicKey)
|
||||
{
|
||||
$this->publicKey = $publicKey;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -103,5 +103,4 @@ class UserCompany extends BunqObject
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -51,7 +51,7 @@ class UserLight extends BunqObject
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
if(count($data) === 0) {
|
||||
if (count($data) === 0) {
|
||||
return;
|
||||
}
|
||||
$this->id = intval($data['id']);
|
||||
|
||||
@@ -45,6 +45,7 @@ abstract class BunqRequest
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->server = config('firefly.bunq.server');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,14 +61,6 @@ abstract class BunqRequest
|
||||
return $this->server;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $server
|
||||
*/
|
||||
public function setServer(string $server)
|
||||
{
|
||||
$this->server = $server;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $privateKey
|
||||
*/
|
||||
|
||||
@@ -13,6 +13,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Support\Import\Information;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Services\Bunq\Object\Alias;
|
||||
use FireflyIII\Services\Bunq\Object\MonetaryAccountBank;
|
||||
use FireflyIII\Services\Bunq\Request\DeleteDeviceSessionRequest;
|
||||
@@ -20,6 +21,7 @@ use FireflyIII\Services\Bunq\Request\DeviceSessionRequest;
|
||||
use FireflyIII\Services\Bunq\Request\ListMonetaryAccountRequest;
|
||||
use FireflyIII\Services\Bunq\Request\ListUserRequest;
|
||||
use FireflyIII\Services\Bunq\Token\SessionToken;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
@@ -56,22 +58,28 @@ class BunqInformation implements InformationInterface
|
||||
*/
|
||||
public function getAccounts(): array
|
||||
{
|
||||
// cache for an hour:
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('bunq.get-accounts');
|
||||
$cache->addProperty(date('dmy h'));
|
||||
if ($cache->has()) {
|
||||
return $cache->get(); // @codeCoverageIgnore
|
||||
}
|
||||
Log::debug('Now in getAccounts()');
|
||||
$sessionToken = $this->startSession();
|
||||
$id = $this->getUserInformation($sessionToken);
|
||||
|
||||
// get list of Bunq accounts:
|
||||
$accounts = $this->getMonetaryAccounts($sessionToken, $id);
|
||||
$return = [];
|
||||
/** @var MonetaryAccountBank $account */
|
||||
foreach ($accounts as $account) {
|
||||
|
||||
$current = [
|
||||
'id' => $account->getId(),
|
||||
'name' => $account->getDescription(),
|
||||
'currency' => $account->getCurrency(),
|
||||
'balance' => $account->getBalance()->getValue(),
|
||||
'color' => $account->getSetting()->getColor(),
|
||||
|
||||
];
|
||||
/** @var Alias $alias */
|
||||
foreach ($account->getAliases() as $alias) {
|
||||
@@ -81,6 +89,7 @@ class BunqInformation implements InformationInterface
|
||||
}
|
||||
$return[] = $current;
|
||||
}
|
||||
$cache->store($return);
|
||||
|
||||
$this->closeSession($sessionToken);
|
||||
|
||||
@@ -105,11 +114,9 @@ class BunqInformation implements InformationInterface
|
||||
Log::debug('Going to close session');
|
||||
$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 DeleteDeviceSessionRequest();
|
||||
$request->setSecret($apiKey);
|
||||
$request->setServer($server);
|
||||
$request->setPrivateKey($privateKey);
|
||||
$request->setServerPublicKey($serverPublicKey);
|
||||
$request->setSessionToken($sessionToken);
|
||||
@@ -128,14 +135,12 @@ class BunqInformation implements InformationInterface
|
||||
{
|
||||
$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 ListMonetaryAccountRequest;
|
||||
|
||||
$request->setSessionToken($sessionToken);
|
||||
$request->setSecret($apiKey);
|
||||
$request->setServerPublicKey($serverPublicKey);
|
||||
$request->setServer($server);
|
||||
$request->setPrivateKey($privateKey);
|
||||
$request->setUserId($userId);
|
||||
$request->call();
|
||||
@@ -154,13 +159,11 @@ class BunqInformation implements InformationInterface
|
||||
{
|
||||
$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?
|
||||
@@ -183,13 +186,11 @@ class BunqInformation implements InformationInterface
|
||||
Log::debug('Now in startSession.');
|
||||
$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;
|
||||
$installationToken = Preferences::getForUser($this->user, 'bunq_installation_token')->data;
|
||||
$request = new DeviceSessionRequest();
|
||||
$request->setSecret($apiKey);
|
||||
$request->setServerPublicKey($serverPublicKey);
|
||||
$request->setServer($server);
|
||||
$request->setPrivateKey($privateKey);
|
||||
$request->setInstallationToken($installationToken);
|
||||
$request->call();
|
||||
|
||||
@@ -157,7 +157,6 @@ class BunqPrerequisites implements PrerequisitesInterface
|
||||
$request->setInstallationToken($installationToken);
|
||||
$request->setServerPublicKey($serverPublicKey);
|
||||
$request->setPrivateKey($this->getPrivateKey());
|
||||
$request->setServer(config('firefly.bunq.server'));
|
||||
$request->call();
|
||||
$devices = $request->getDevices();
|
||||
/** @var DeviceServer $device */
|
||||
@@ -186,7 +185,6 @@ class BunqPrerequisites implements PrerequisitesInterface
|
||||
// verify bunq api code:
|
||||
$publicKey = $this->getPublicKey();
|
||||
$request = new InstallationTokenRequest;
|
||||
$request->setServer(strval(config('firefly.bunq.server')));
|
||||
$request->setPublicKey($publicKey);
|
||||
$request->call();
|
||||
Log::debug('Sent request');
|
||||
@@ -301,7 +299,6 @@ class BunqPrerequisites implements PrerequisitesInterface
|
||||
$serverPublicKey = $this->getServerPublicKey();
|
||||
$apiKey = Preferences::getForUser($this->user, 'bunq_api_key', '');
|
||||
$request = new DeviceServerRequest;
|
||||
$request->setServer(strval(config('firefly.bunq.server')));
|
||||
$request->setPrivateKey($this->getPrivateKey());
|
||||
$request->setDescription('Firefly III v' . config('firefly.version') . ' for ' . $this->user->email);
|
||||
$request->setSecret($apiKey->data);
|
||||
|
||||
Reference in New Issue
Block a user