mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 04:03:26 +00:00
Remove import code.
This commit is contained in:
@@ -1,96 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ApiContext.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Bunq;
|
||||
|
||||
use bunq\Context\ApiContext as BunqApiContext;
|
||||
use bunq\Context\BunqContext;
|
||||
use bunq\Util\BunqEnumApiEnvironmentType;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use Log;
|
||||
use Tests\Object\FakeApiContext;
|
||||
|
||||
/**
|
||||
* Special class to hide away bunq's static initialisation methods.
|
||||
*
|
||||
* Class ApiContext
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class ApiContext
|
||||
{
|
||||
|
||||
/**
|
||||
* @param BunqEnumApiEnvironmentType $environmentType
|
||||
* @param string $apiKey
|
||||
* @param string $description
|
||||
* @param array $permittedIps
|
||||
* @param string|null $proxyUrl
|
||||
*
|
||||
* @return BunqApiContext|FakeApiContext
|
||||
*
|
||||
*@throws FireflyException
|
||||
*/
|
||||
public function create(BunqEnumApiEnvironmentType $environmentType, string $apiKey, string $description, array $permittedIps, string $proxyUrl = null
|
||||
) {
|
||||
$permittedIps = $permittedIps ?? [];
|
||||
try {
|
||||
$context = BunqApiContext::create($environmentType, $apiKey, $description, $permittedIps, $proxyUrl);
|
||||
} catch (Exception $e) {
|
||||
$message = $e->getMessage();
|
||||
Log::error($message);
|
||||
Log::error($e->getTraceAsString());
|
||||
|
||||
if (stripos($message, 'Generating a new private key failed')) {
|
||||
$message = 'Could not generate key-material. Please make sure OpenSSL is installed and configured: http://bit.ly/FF3-openSSL';
|
||||
}
|
||||
throw new FireflyException($message);
|
||||
}
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @param string $jsonString
|
||||
*/
|
||||
public function fromJson(string $jsonString): void
|
||||
{
|
||||
try {
|
||||
$apiContext = BunqApiContext::fromJson($jsonString);
|
||||
BunqContext::loadApiContext($apiContext);
|
||||
} catch (Exception $e) {
|
||||
$message = $e->getMessage();
|
||||
Log::error($message);
|
||||
Log::error($e->getTraceAsString());
|
||||
|
||||
if (stripos($message, 'Generating a new private key failed')) {
|
||||
$message = 'Could not generate key-material. Please make sure OpenSSL is installed and configured: http://bit.ly/FF3-openSSL';
|
||||
}
|
||||
throw new FireflyException($message);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* MonetaryAccount.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Bunq;
|
||||
|
||||
|
||||
use bunq\Model\Generated\Endpoint\BunqResponseMonetaryAccountList;
|
||||
use bunq\Model\Generated\Endpoint\MonetaryAccount as BunqMonetaryAccount;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
|
||||
/**
|
||||
* Class MonetaryAccount
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class MonetaryAccount
|
||||
{
|
||||
/**
|
||||
* @param array $params
|
||||
* @param array $customHeaders
|
||||
*
|
||||
* @return BunqResponseMonetaryAccountList
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function listing(array $params = null, array $customHeaders = null): BunqResponseMonetaryAccountList
|
||||
{
|
||||
$params = $params ?? [];
|
||||
$customHeaders = $customHeaders ?? [];
|
||||
try {
|
||||
$result = BunqMonetaryAccount::listing($params, $customHeaders);
|
||||
} catch (Exception $e) {
|
||||
throw new FireflyException($e->getMessage());
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
@@ -1,63 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Payment.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Bunq;
|
||||
|
||||
|
||||
use bunq\Model\Generated\Endpoint\BunqResponsePaymentList;
|
||||
use bunq\Model\Generated\Endpoint\Payment as BunqPayment;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
|
||||
/**
|
||||
* Class Payment
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class Payment
|
||||
{
|
||||
/**
|
||||
* @param int|null $monetaryAccountId
|
||||
* @param array|null $params
|
||||
* @param array|null $customHeaders
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return BunqResponsePaymentList
|
||||
*/
|
||||
public function listing(int $monetaryAccountId = null, array $params = null, array $customHeaders = null): BunqResponsePaymentList
|
||||
{
|
||||
$monetaryAccountId = $monetaryAccountId ?? 0;
|
||||
$params = $params ?? [];
|
||||
$customHeaders = $customHeaders ?? [];
|
||||
try {
|
||||
$result = BunqPayment::listing($monetaryAccountId, $params, $customHeaders);
|
||||
} catch (Exception $e) {
|
||||
throw new FireflyException($e->getMessage());
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* GithubObject.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Github\Object;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* Class GithubObject
|
||||
*/
|
||||
class GithubObject
|
||||
{
|
||||
}
|
@@ -1,94 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Release.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Github\Object;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Class Release
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ShortVariable)
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Release extends GithubObject
|
||||
{
|
||||
/** @var string */
|
||||
private $content;
|
||||
/** @var string */
|
||||
private $id;
|
||||
/** @var string */
|
||||
private $title;
|
||||
/** @var Carbon */
|
||||
private $updated;
|
||||
|
||||
/**
|
||||
* Release constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->id = $data['id'];
|
||||
$this->updated = new Carbon($data['updated']);
|
||||
$this->title = $data['title'];
|
||||
$this->content = $data['content'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getContent(): string
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getId(): string
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle(): string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getUpdated(): Carbon
|
||||
{
|
||||
return $this->updated;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* GithubRequest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Github\Request;
|
||||
|
||||
/**
|
||||
* Interface GithubRequest
|
||||
* @deprecated
|
||||
*/
|
||||
interface GithubRequest
|
||||
{
|
||||
public function call(): void;
|
||||
|
||||
}
|
@@ -1,96 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* UpdateRequest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Github\Request;
|
||||
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Services\Github\Object\Release;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Log;
|
||||
use RuntimeException;
|
||||
use SimpleXMLElement;
|
||||
|
||||
/**
|
||||
* Class UpdateRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class UpdateRequest implements GithubRequest
|
||||
{
|
||||
/** @var array */
|
||||
private $releases = [];
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function call(): void
|
||||
{
|
||||
$uri = 'https://github.com/firefly-iii/firefly-iii/releases.atom';
|
||||
Log::debug(sprintf('Going to call %s', $uri));
|
||||
try {
|
||||
$client = new Client();
|
||||
$res = $client->request('GET', $uri);
|
||||
} catch (GuzzleException|Exception $e) {
|
||||
throw new FireflyException(sprintf('Response error from Github: %s', $e->getMessage()));
|
||||
}
|
||||
|
||||
if (200 !== $res->getStatusCode()) {
|
||||
throw new FireflyException(sprintf('Returned code %d.', $res->getStatusCode()));
|
||||
}
|
||||
try {
|
||||
$releaseXml = new SimpleXMLElement($res->getBody()->getContents(), LIBXML_NOCDATA);
|
||||
} catch (RuntimeException $e) {
|
||||
Log::error(sprintf('Could not get body from github updat result: %s', $e->getMessage()));
|
||||
throw new FireflyException(sprintf('Could not get body from github updat result: %s', $e->getMessage()));
|
||||
}
|
||||
|
||||
//fetch the products for each category
|
||||
if (isset($releaseXml->entry)) {
|
||||
Log::debug(sprintf('Count of entries is: %d', count($releaseXml->entry)));
|
||||
foreach ($releaseXml->entry as $entry) {
|
||||
$array = [
|
||||
'id' => (string)$entry->id,
|
||||
'updated' => (string)$entry->updated,
|
||||
'title' => (string)$entry->title,
|
||||
'content' => (string)$entry->content,
|
||||
];
|
||||
Log::debug(sprintf('Found version %s', $entry->title));
|
||||
$this->releases[] = new Release($array);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getReleases(): array
|
||||
{
|
||||
return $this->releases;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* IPRetrievalInterface.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\IP;
|
||||
|
||||
/**
|
||||
* Interface IPRetrievalInterface
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
interface IPRetrievalInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns the user's IP address.
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getIP(): ?string;
|
||||
}
|
@@ -1,81 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* IpifyOrg.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\IP;
|
||||
|
||||
use Exception;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Log;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class IpifyOrg
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class IpifyOrg implements IPRetrievalInterface
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user's IP address.
|
||||
*
|
||||
* @noinspection MultipleReturnStatementsInspection
|
||||
* @return null|string
|
||||
*/
|
||||
public function getIP(): ?string
|
||||
{
|
||||
try {
|
||||
$client = new Client;
|
||||
$res = $client->request('GET', 'https://api.ipify.org');
|
||||
} catch (GuzzleException|Exception $e) {
|
||||
Log::warning(sprintf('The ipify.org service could not retrieve external IP: %s', $e->getMessage()));
|
||||
Log::warning($e->getTraceAsString());
|
||||
|
||||
return null;
|
||||
}
|
||||
if (200 !== $res->getStatusCode()) {
|
||||
Log::warning(sprintf('Could not retrieve external IP: %d', $res->getStatusCode()));
|
||||
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
$body = (string)$res->getBody()->getContents();
|
||||
} catch (RuntimeException $e) {
|
||||
Log::error(sprintf('Could not get body from ipify.org result: %s', $e->getMessage()));
|
||||
$body = null;
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* DuplicatedCustomerException.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Exception;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* Class DuplicatedCustomerException
|
||||
* @deprecated
|
||||
*/
|
||||
class DuplicatedCustomerException extends SpectreException
|
||||
{
|
||||
|
||||
}
|
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SpectreException.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Exception;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* Class SpectreException
|
||||
* @deprecated
|
||||
*/
|
||||
class SpectreException extends Exception
|
||||
{
|
||||
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* WrongRequestFormatException.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Exception;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* Class WrongRequestFormatException
|
||||
* @deprecated
|
||||
*/
|
||||
class WrongRequestFormatException extends SpectreException
|
||||
{
|
||||
|
||||
}
|
@@ -1,145 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Account.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Object;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Class Account
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @SuppressWarnings(PHPMD.ShortVariable)
|
||||
* @deprecated
|
||||
*/
|
||||
class Account extends SpectreObject
|
||||
{
|
||||
/** @var float */
|
||||
private $balance;
|
||||
/** @var Carbon */
|
||||
private $createdAt;
|
||||
/** @var string */
|
||||
private $currencyCode;
|
||||
/** @var array */
|
||||
private $extra = [];
|
||||
/** @var int */
|
||||
private $id;
|
||||
/** @var int */
|
||||
private $loginId;
|
||||
/** @var string */
|
||||
private $name;
|
||||
/** @var string */
|
||||
private $nature;
|
||||
/** @var Carbon */
|
||||
private $updatedAt;
|
||||
|
||||
/**
|
||||
* Account constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->id = (int)$data['id'];
|
||||
$this->loginId = $data['login_id'];
|
||||
$this->currencyCode = $data['currency_code'];
|
||||
$this->balance = $data['balance'];
|
||||
$this->name = $data['name'];
|
||||
$this->nature = $data['nature'];
|
||||
$this->createdAt = new Carbon($data['created_at']);
|
||||
$this->updatedAt = new Carbon($data['updated_at']);
|
||||
$extraArray = is_array($data['extra']) ? $data['extra'] : [];
|
||||
foreach ($extraArray as $key => $value) {
|
||||
$this->extra[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getBalance(): float
|
||||
{
|
||||
return $this->balance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrencyCode(): string
|
||||
{
|
||||
return $this->currencyCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getExtra(): array
|
||||
{
|
||||
return $this->extra;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getNature(): string
|
||||
{
|
||||
return $this->nature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$array = [
|
||||
'balance' => $this->balance,
|
||||
'created_at' => $this->createdAt->toIso8601String(),
|
||||
'currency_code' => $this->currencyCode,
|
||||
'extra' => $this->extra,
|
||||
'id' => $this->id,
|
||||
'login_id' => $this->loginId,
|
||||
'name' => $this->name,
|
||||
'nature' => $this->nature,
|
||||
'updated_at' => $this->updatedAt->toIso8601String(),
|
||||
];
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
}
|
@@ -1,214 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Attempt.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Object;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class Attempt
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @SuppressWarnings(PHPMD.ShortVariable)
|
||||
* @SuppressWarnings(PHPMD.TooManyFields)
|
||||
* @deprecated
|
||||
*/
|
||||
class Attempt extends SpectreObject
|
||||
{
|
||||
/** @var string */
|
||||
private $apiMode;
|
||||
/** @var int */
|
||||
private $apiVersion;
|
||||
/** @var bool */
|
||||
private $automaticFetch;
|
||||
/** @var bool */
|
||||
private $categorize;
|
||||
/** @var Carbon */
|
||||
private $consentGivenAt;
|
||||
/** @var array */
|
||||
private $consentTypes;
|
||||
/** @var Carbon */
|
||||
private $createdAt;
|
||||
/** @var array */
|
||||
private $customFields;
|
||||
/** @var bool */
|
||||
private $dailyRefresh;
|
||||
/** @var string */
|
||||
private $deviceType;
|
||||
/** @var array */
|
||||
private $excludeAccounts;
|
||||
/** @var Carbon */
|
||||
private $failAt;
|
||||
/** @var string */
|
||||
private $failErrorClass;
|
||||
/** @var string */
|
||||
private $failMessage;
|
||||
/** @var array */
|
||||
private $fetchScopes;
|
||||
/** @var bool */
|
||||
private $finished;
|
||||
/** @var bool */
|
||||
private $finishedRecent;
|
||||
/** @var Carbon */
|
||||
private $fromDate;
|
||||
/** @var int */
|
||||
private $id;
|
||||
/** @var bool */
|
||||
private $interactive;
|
||||
/** @var string */
|
||||
private $locale;
|
||||
/** @var bool */
|
||||
private $partial;
|
||||
/** @var string */
|
||||
private $remoteIp;
|
||||
/** @var bool */
|
||||
private $showConsentInformation;
|
||||
/** @var array */
|
||||
private $stages;
|
||||
/** @var bool */
|
||||
private $storeCredentials;
|
||||
/** @var Carbon */
|
||||
private $successAt;
|
||||
/** @var Carbon */
|
||||
private $toDate;
|
||||
/** @var Carbon */
|
||||
private $updatedAt; // undocumented
|
||||
/** @var string */
|
||||
private $userAgent;
|
||||
|
||||
/**
|
||||
* Attempt constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->apiMode = $data['api_mode'];
|
||||
$this->apiVersion = $data['api_version'];
|
||||
$this->automaticFetch = $data['automatic_fetch'];
|
||||
$this->categorize = $data['categorize'];
|
||||
$this->createdAt = new Carbon($data['created_at']);
|
||||
$this->consentGivenAt = new Carbon($data['consent_given_at']);
|
||||
$this->consentTypes = $data['consent_types'];
|
||||
$this->customFields = $data['custom_fields'];
|
||||
$this->dailyRefresh = $data['daily_refresh'];
|
||||
$this->deviceType = $data['device_type'];
|
||||
$this->userAgent = $data['user_agent'] ?? '';
|
||||
$this->remoteIp = $data['remote_ip'];
|
||||
$this->excludeAccounts = $data['exclude_accounts'];
|
||||
$this->failAt = new Carbon($data['fail_at']);
|
||||
$this->failErrorClass = $data['fail_error_class'];
|
||||
$this->failMessage = $data['fail_message'];
|
||||
$this->fetchScopes = $data['fetch_scopes'];
|
||||
$this->finished = $data['finished'];
|
||||
$this->finishedRecent = $data['finished_recent'];
|
||||
$this->fromDate = new Carbon($data['from_date']);
|
||||
$this->id = $data['id'];
|
||||
$this->interactive = $data['interactive'];
|
||||
$this->locale = $data['locale'];
|
||||
$this->partial = $data['partial'];
|
||||
$this->showConsentInformation = $data['show_consent_confirmation'];
|
||||
$this->stages = $data['stages'] ?? [];
|
||||
$this->storeCredentials = $data['store_credentials'];
|
||||
$this->successAt = new Carbon($data['success_at']);
|
||||
$this->toDate = new Carbon($data['to_date']);
|
||||
$this->updatedAt = new Carbon($data['updated_at']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getCreatedAt(): Carbon
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getFailAt(): Carbon
|
||||
{
|
||||
return $this->failAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function getFailErrorClass(): ?string
|
||||
{
|
||||
return $this->failErrorClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function getFailMessage(): ?string
|
||||
{
|
||||
return $this->failMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$array = [
|
||||
'api_mode' => $this->apiMode,
|
||||
'api_version' => $this->apiVersion,
|
||||
'automatic_fetch' => $this->automaticFetch,
|
||||
'categorize' => $this->categorize,
|
||||
'created_at' => $this->createdAt->toIso8601String(),
|
||||
'consent_given_at' => $this->consentGivenAt->toIso8601String(),
|
||||
'consent_types' => $this->consentTypes,
|
||||
'custom_fields' => $this->customFields,
|
||||
'daily_refresh' => $this->dailyRefresh,
|
||||
'device_type' => $this->deviceType,
|
||||
'user_agent' => $this->userAgent,
|
||||
'remote_ip' => $this->remoteIp,
|
||||
'exclude_accounts' => $this->excludeAccounts,
|
||||
'fail_at' => $this->failAt->toIso8601String(),
|
||||
'fail_error_class' => $this->failErrorClass,
|
||||
'fail_message' => $this->failMessage,
|
||||
'fetch_scopes' => $this->fetchScopes,
|
||||
'finished' => $this->finished,
|
||||
'finished_recent' => $this->finishedRecent,
|
||||
'from_date' => $this->fromDate->toIso8601String(),
|
||||
'id' => $this->id,
|
||||
'interactive' => $this->interactive,
|
||||
'locale' => $this->locale,
|
||||
'partial' => $this->partial,
|
||||
'show_consent_confirmation' => $this->showConsentInformation,
|
||||
'stages' => $this->stages,
|
||||
'store_credentials' => $this->storeCredentials,
|
||||
'success_at' => $this->successAt->toIso8601String(),
|
||||
'to_date' => $this->toDate->toIso8601String(),
|
||||
'updated_at' => $this->updatedAt->toIso8601String(),
|
||||
];
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,112 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Customer.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Object;
|
||||
|
||||
/**
|
||||
* Class Customer
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @SuppressWarnings(PHPMD.ShortVariable)
|
||||
* @deprecated
|
||||
*/
|
||||
class Customer extends SpectreObject
|
||||
{
|
||||
/** @var int */
|
||||
private $id;
|
||||
/** @var string */
|
||||
private $identifier;
|
||||
/** @var string */
|
||||
private $secret;
|
||||
|
||||
/**
|
||||
* Customer constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->id = (int)$data['id'];
|
||||
$this->identifier = $data['identifier'];
|
||||
$this->secret = $data['secret'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*/
|
||||
public function setId(int $id): void
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getIdentifier(): string
|
||||
{
|
||||
return $this->identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $identifier
|
||||
*/
|
||||
public function setIdentifier(string $identifier): void
|
||||
{
|
||||
$this->identifier = $identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSecret(): string
|
||||
{
|
||||
return $this->secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $secret
|
||||
*/
|
||||
public function setSecret(string $secret): void
|
||||
{
|
||||
$this->secret = $secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'identifier' => $this->identifier,
|
||||
'secret' => $this->secret,
|
||||
];
|
||||
}
|
||||
}
|
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Holder.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Object;
|
||||
|
||||
/**
|
||||
* Class Holder
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class Holder extends SpectreObject
|
||||
{
|
||||
/**
|
||||
* Holder constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
@@ -1,191 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Login.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Object;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
|
||||
/**
|
||||
* Class Login
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @SuppressWarnings(PHPMD.ShortVariable)
|
||||
* @SuppressWarnings(PHPMD.TooManyFields)
|
||||
* @deprecated
|
||||
*/
|
||||
class Login extends SpectreObject
|
||||
{
|
||||
/** @var Carbon */
|
||||
private $consentGivenAt;
|
||||
/** @var array */
|
||||
private $consentTypes;
|
||||
/** @var string */
|
||||
private $countryCode;
|
||||
/** @var Carbon */
|
||||
private $createdAt;
|
||||
/** @var int */
|
||||
private $customerId;
|
||||
/** @var bool */
|
||||
private $dailyRefresh;
|
||||
/** @var Holder */
|
||||
private $holderInfo;
|
||||
/** @var int */
|
||||
private $id;
|
||||
/** @var Attempt */
|
||||
private $lastAttempt;
|
||||
/** @var Carbon */
|
||||
private $lastSuccessAt;
|
||||
/** @var Carbon */
|
||||
private $nextRefreshPossibleAt;
|
||||
/** @var string */
|
||||
private $providerCode;
|
||||
/** @var int */
|
||||
private $providerId;
|
||||
/** @var string */
|
||||
private $providerName;
|
||||
/** @var bool */
|
||||
private $showConsentConfirmation;
|
||||
/** @var string */
|
||||
private $status;
|
||||
/** @var bool */
|
||||
private $storeCredentials;
|
||||
/** @var Carbon */
|
||||
private $updatedAt;
|
||||
|
||||
/**
|
||||
* Login constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->consentGivenAt = new Carbon($data['consent_given_at']);
|
||||
$this->consentTypes = $data['consent_types'];
|
||||
$this->countryCode = $data['country_code'];
|
||||
$this->createdAt = new Carbon($data['created_at']);
|
||||
$this->updatedAt = new Carbon($data['updated_at']);
|
||||
$this->customerId = $data['customer_id'];
|
||||
$this->dailyRefresh = $data['daily_refresh'];
|
||||
$this->holderInfo = new Holder($data['holder_info']);
|
||||
$this->id = (int)$data['id'];
|
||||
$this->lastAttempt = new Attempt($data['last_attempt']);
|
||||
$this->lastSuccessAt = new Carbon($data['last_success_at']);
|
||||
$this->nextRefreshPossibleAt = new Carbon($data['next_refresh_possible_at']);
|
||||
$this->providerCode = $data['provider_code'];
|
||||
$this->providerId = $data['provider_id'];
|
||||
$this->providerName = $data['provider_name'];
|
||||
$this->showConsentConfirmation = $data['show_consent_confirmation'];
|
||||
$this->status = $data['status'];
|
||||
$this->storeCredentials = $data['store_credentials'];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCountryCode(): string
|
||||
{
|
||||
return $this->countryCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Attempt
|
||||
*/
|
||||
public function getLastAttempt(): Attempt
|
||||
{
|
||||
return $this->lastAttempt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getLastSuccessAt(): Carbon
|
||||
{
|
||||
return $this->lastSuccessAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getProviderName(): string
|
||||
{
|
||||
return $this->providerName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getStatus(): string
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getUpdatedAt(): Carbon
|
||||
{
|
||||
return $this->updatedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$array = [
|
||||
'consent_given_at' => $this->consentGivenAt->toIso8601String(),
|
||||
'consent_types' => $this->consentTypes,
|
||||
'country_code' => $this->countryCode,
|
||||
'created_at' => $this->createdAt->toIso8601String(),
|
||||
'updated_at' => $this->updatedAt->toIso8601String(),
|
||||
'customer_id' => $this->customerId,
|
||||
'daily_refresh' => $this->dailyRefresh,
|
||||
'holder_info' => $this->holderInfo->toArray(),
|
||||
'id' => $this->id,
|
||||
'last_attempt' => $this->lastAttempt->toArray(),
|
||||
'last_success_at' => $this->lastSuccessAt->toIso8601String(),
|
||||
'next_refresh_possible_at' => $this->nextRefreshPossibleAt->toIso8601String(),
|
||||
'provider_code' => $this->providerCode,
|
||||
'provider_id' => $this->providerId,
|
||||
'provider_name' => $this->providerName,
|
||||
'show_consent_confirmation' => $this->showConsentConfirmation,
|
||||
'status' => $this->status,
|
||||
'store_credentials' => $this->storeCredentials,
|
||||
|
||||
];
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SpectreObject.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Object;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* Class SpectreObject
|
||||
* @deprecated
|
||||
*/
|
||||
class SpectreObject
|
||||
{
|
||||
}
|
@@ -1,90 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Token.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Object;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* Class Token
|
||||
* @deprecated
|
||||
*/
|
||||
class Token extends SpectreObject
|
||||
{
|
||||
/** @var string */
|
||||
private $connectUrl;
|
||||
/** @var Carbon */
|
||||
private $expiresAt;
|
||||
/** @var string */
|
||||
private $token;
|
||||
|
||||
/**
|
||||
* Token constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->token = $data['token'];
|
||||
$this->expiresAt = new Carbon($data['expires_at']);
|
||||
$this->connectUrl = $data['connect_url'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getConnectUrl(): string
|
||||
{
|
||||
return $this->connectUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getExpiresAt(): Carbon
|
||||
{
|
||||
return $this->expiresAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getToken(): string
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'connect_url' => $this->connectUrl,
|
||||
'expires_at' => $this->expiresAt->toW3cString(),
|
||||
'token' => $this->token,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@@ -1,227 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Transaction.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Object;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Class Transaction
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ShortVariable)
|
||||
*/
|
||||
class Transaction extends SpectreObject
|
||||
{
|
||||
/** @var int */
|
||||
private $accountId;
|
||||
/** @var string */
|
||||
private $amount;
|
||||
/** @var string */
|
||||
private $category;
|
||||
/** @var Carbon */
|
||||
private $createdAt;
|
||||
/** @var string */
|
||||
private $currencyCode;
|
||||
/** @var string */
|
||||
private $description;
|
||||
/** @var bool */
|
||||
private $duplicated;
|
||||
/** @var TransactionExtra */
|
||||
private $extra;
|
||||
/** @var int */
|
||||
private $id;
|
||||
/** @var Carbon */
|
||||
private $madeOn;
|
||||
/** @var string */
|
||||
private $mode;
|
||||
/** @var string */
|
||||
private $status;
|
||||
/** @var Carbon */
|
||||
private $updatedAt;
|
||||
|
||||
/**
|
||||
* Transaction constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->id = (int)$data['id'];
|
||||
$this->mode = $data['mode'];
|
||||
$this->status = $data['status'];
|
||||
$this->madeOn = new Carbon($data['made_on']);
|
||||
$this->amount = $data['amount'];
|
||||
$this->currencyCode = $data['currency_code'];
|
||||
$this->description = $data['description'];
|
||||
$this->category = $data['category'];
|
||||
$this->duplicated = $data['duplicated'];
|
||||
$this->extra = new TransactionExtra($data['extra'] ?? []);
|
||||
$this->accountId = $data['account_id'];
|
||||
$this->createdAt = new Carbon($data['created_at']);
|
||||
$this->updatedAt = new Carbon($data['updated_at']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAmount(): string
|
||||
{
|
||||
return (string)$this->amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCategory(): string
|
||||
{
|
||||
return $this->category;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrencyCode(): string
|
||||
{
|
||||
return $this->currencyCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TransactionExtra|null
|
||||
*/
|
||||
public function getExtra(): ?TransactionExtra
|
||||
{
|
||||
return $this->extra;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHash(): string
|
||||
{
|
||||
$array = [
|
||||
'id' => $this->id,
|
||||
'mode' => $this->mode,
|
||||
'status' => $this->status,
|
||||
'made_on' => $this->madeOn->toIso8601String(),
|
||||
'amount' => $this->amount,
|
||||
'currency_code' => $this->currencyCode,
|
||||
'description' => $this->description,
|
||||
'category' => $this->category,
|
||||
'duplicated' => $this->duplicated,
|
||||
'extra' => $this->extra->toArray(),
|
||||
'account_id' => $this->accountId,
|
||||
'created_at' => $this->createdAt->toIso8601String(),
|
||||
'updated_at' => $this->updatedAt->toIso8601String(),
|
||||
];
|
||||
|
||||
return hash('sha256', json_encode($array));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getMadeOn(): Carbon
|
||||
{
|
||||
return $this->madeOn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMode(): string
|
||||
{
|
||||
return $this->mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get opposing account data.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public function getOpposingAccountData(): array
|
||||
{
|
||||
$data = [
|
||||
'name' => null,
|
||||
'iban' => null,
|
||||
'number' => null,
|
||||
'bic' => null,
|
||||
];
|
||||
$extra = $this->getExtra();
|
||||
if (null !== $extra) {
|
||||
$arr = $extra->toArray();
|
||||
foreach ($arr as $key => $value) {
|
||||
switch ($key) {
|
||||
case 'account_number':
|
||||
$data['number'] = $value;
|
||||
$data['name'] = $data['name'] ?? (string)trans('import.spectre_account_with_number', ['number' => $value]);
|
||||
break;
|
||||
case 'payee':
|
||||
$data['name'] = $value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getStatus(): string
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isDuplicated(): bool
|
||||
{
|
||||
return $this->duplicated;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,174 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* TransactionExtra.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Object;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Class TransactionExtra
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyFields)
|
||||
* @SuppressWarnings(PHPMD.ShortVariable)
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class TransactionExtra extends SpectreObject
|
||||
{
|
||||
/** @var string */
|
||||
private $accountBalanceSnapshot;
|
||||
/** @var string */
|
||||
private $accountNumber;
|
||||
/** @var string */
|
||||
private $additional;
|
||||
/** @var string */
|
||||
private $assetAmount;
|
||||
/** @var string */
|
||||
private $assetCode;
|
||||
/** @var string */
|
||||
private $categorizationConfidence;
|
||||
/** @var string */
|
||||
private $checkNumber;
|
||||
/** @var string */
|
||||
private $customerCategoryCode;
|
||||
/** @var string */
|
||||
private $customerCategoryName;
|
||||
/** @var string */
|
||||
private $id;
|
||||
/** @var string */
|
||||
private $information;
|
||||
/** @var string */
|
||||
private $mcc;
|
||||
/** @var string */
|
||||
private $originalAmount;
|
||||
/** @var string */
|
||||
private $originalCategory;
|
||||
/** @var string */
|
||||
private $originalCurrencyCode;
|
||||
/** @var string */
|
||||
private $originalSubCategory;
|
||||
/** @var string */
|
||||
private $payee;
|
||||
/** @var bool */
|
||||
private $possibleDuplicate;
|
||||
/** @var Carbon */
|
||||
private $postingDate;
|
||||
/** @var Carbon */
|
||||
private $postingTime;
|
||||
/** @var string */
|
||||
private $recordNumber;
|
||||
/** @var array */
|
||||
private $tags;
|
||||
/** @var Carbon */
|
||||
private $time;
|
||||
/** @var string */
|
||||
private $type;
|
||||
/** @var string */
|
||||
private $unitPrice;
|
||||
/** @var string */
|
||||
private $units;
|
||||
|
||||
/**
|
||||
* TransactionExtra constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->id = $data['id'] ?? null;
|
||||
$this->recordNumber = $data['record_number'] ?? null;
|
||||
$this->information = $data['information'] ?? null;
|
||||
$this->time = isset($data['time']) ? new Carbon($data['time']) : null;
|
||||
$this->postingDate = isset($data['posting_date']) ? new Carbon($data['posting_date']) : null;
|
||||
$this->postingTime = isset($data['posting_time']) ? new Carbon($data['posting_time']) : null;
|
||||
$this->accountNumber = $data['account_number'] ?? null;
|
||||
$this->originalAmount = $data['original_amount'] ?? null;
|
||||
$this->originalCurrencyCode = $data['original_currency_code'] ?? null;
|
||||
$this->assetCode = $data['asset_code'] ?? null;
|
||||
$this->assetAmount = $data['asset_amount'] ?? null;
|
||||
$this->originalCategory = $data['original_category'] ?? null;
|
||||
$this->originalSubCategory = $data['original_subcategory'] ?? null;
|
||||
$this->customerCategoryCode = $data['customer_category_code'] ?? null;
|
||||
$this->customerCategoryName = $data['customer_category_name'] ?? null;
|
||||
$this->possibleDuplicate = $data['possible_duplicate'] ?? null;
|
||||
$this->tags = $data['tags'] ?? null;
|
||||
$this->mcc = $data['mcc'] ?? null;
|
||||
$this->payee = $data['payee'] ?? null;
|
||||
$this->type = $data['type'] ?? null;
|
||||
$this->checkNumber = $data['check_number'] ?? null;
|
||||
$this->units = $data['units'] ?? null;
|
||||
$this->additional = $data['additional'] ?? null;
|
||||
$this->unitPrice = $data['unit_price'] ?? null;
|
||||
$this->accountBalanceSnapshot = $data['account_balance_snapshot'] ?? null;
|
||||
$this->categorizationConfidence = $data['categorization_confidence'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getId(): ?string
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
|
||||
$array = [
|
||||
'id' => $this->id,
|
||||
'record_number' => $this->recordNumber,
|
||||
'information' => $this->information,
|
||||
'time' => null === $this->time ? null : $this->time->toIso8601String(),
|
||||
'posting_date' => null === $this->postingDate ? null : $this->postingDate->toIso8601String(),
|
||||
'posting_time' => null === $this->postingTime ? null : $this->postingTime->toIso8601String(),
|
||||
'account_number' => $this->accountNumber,
|
||||
'original_amount' => $this->originalAmount,
|
||||
'original_currency_code' => $this->originalCurrencyCode,
|
||||
'asset_code' => $this->assetCode,
|
||||
'asset_amount' => $this->assetAmount,
|
||||
'original_category' => $this->originalCategory,
|
||||
'original_subcategory' => $this->originalSubCategory,
|
||||
'customer_category_code' => $this->customerCategoryCode,
|
||||
'customer_category_name' => $this->customerCategoryName,
|
||||
'possible_duplicate' => $this->possibleDuplicate,
|
||||
'tags' => $this->tags,
|
||||
'mcc' => $this->mcc,
|
||||
'payee' => $this->payee,
|
||||
'type' => $this->type,
|
||||
'check_number' => $this->checkNumber,
|
||||
'units' => $this->units,
|
||||
'additional' => $this->additional,
|
||||
'unit_price' => $this->unitPrice,
|
||||
'account_balance_snapshot' => $this->accountBalanceSnapshot,
|
||||
'categorization_confidence' => $this->categorizationConfidence,
|
||||
];
|
||||
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,95 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CreateTokenRequest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Request;
|
||||
|
||||
use FireflyIII\Services\Spectre\Object\Customer;
|
||||
use FireflyIII\Services\Spectre\Object\Token;
|
||||
|
||||
|
||||
/**
|
||||
* Class CreateTokenRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class CreateTokenRequest extends SpectreRequest
|
||||
{
|
||||
/** @var Customer */
|
||||
private $customer;
|
||||
|
||||
/** @var Token */
|
||||
private $token;
|
||||
|
||||
/** @var string */
|
||||
private $uri;
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function call(): void
|
||||
{
|
||||
// add mandatory fields to login object
|
||||
$data = [
|
||||
'data' => [
|
||||
'customer_id' => $this->customer->getId(),
|
||||
'fetch_scopes' => ['accounts', 'transactions'],
|
||||
'daily_refresh' => true,
|
||||
'include_fake_providers' => true,
|
||||
'show_consent_confirmation' => true,
|
||||
'credentials_strategy' => 'ask',
|
||||
'return_to' => $this->uri,
|
||||
],
|
||||
];
|
||||
$uri = '/api/v4/tokens/create';
|
||||
$response = $this->sendSignedSpectrePost($uri, $data);
|
||||
$this->token = new Token($response['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Token
|
||||
*/
|
||||
public function getToken(): Token
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Customer $customer
|
||||
*/
|
||||
public function setCustomer(Customer $customer): void
|
||||
{
|
||||
$this->customer = $customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
*/
|
||||
public function setUri(string $uri): void
|
||||
{
|
||||
$this->uri = $uri;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,93 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ListAccountsRequest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Request;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Services\Spectre\Object\Account;
|
||||
use FireflyIII\Services\Spectre\Object\Login;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class ListAccountsRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class ListAccountsRequest extends SpectreRequest
|
||||
{
|
||||
/** @var array */
|
||||
private $accounts = [];
|
||||
/** @var Login */
|
||||
private $login;
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*
|
||||
*/
|
||||
public function call(): void
|
||||
{
|
||||
$hasNextPage = true;
|
||||
$nextId = 0;
|
||||
while ($hasNextPage) {
|
||||
Log::debug(sprintf('Now calling ListAccountsRequest for next_id %d', $nextId));
|
||||
$parameters = ['from_id' => $nextId, 'login_id' => $this->login->getId()];
|
||||
$uri = '/api/v4/accounts?' . http_build_query($parameters);
|
||||
$response = $this->sendSignedSpectreGet($uri, []);
|
||||
|
||||
// count entries:
|
||||
Log::debug(sprintf('Found %d entries in data-array', count($response['data'])));
|
||||
|
||||
// extract next ID
|
||||
$hasNextPage = false;
|
||||
if (isset($response['meta']['next_id']) && (int)$response['meta']['next_id'] > $nextId) {
|
||||
$hasNextPage = true;
|
||||
$nextId = $response['meta']['next_id'];
|
||||
Log::debug(sprintf('Next ID is now %d.', $nextId));
|
||||
}
|
||||
|
||||
// store customers:
|
||||
foreach ($response['data'] as $accountArray) {
|
||||
$this->accounts[] = new Account($accountArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAccounts(): array
|
||||
{
|
||||
return $this->accounts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Login $login
|
||||
*/
|
||||
public function setLogin(Login $login): void
|
||||
{
|
||||
$this->login = $login;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,83 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ListCustomersRequest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Request;
|
||||
|
||||
use FireflyIII\Services\Spectre\Object\Customer;
|
||||
use Log;
|
||||
|
||||
|
||||
/**
|
||||
* Class ListCustomersRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class ListCustomersRequest extends SpectreRequest
|
||||
{
|
||||
/** @var array */
|
||||
private $customers = [];
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*
|
||||
*/
|
||||
public function call(): void
|
||||
{
|
||||
$hasNextPage = true;
|
||||
$nextId = 0;
|
||||
while ($hasNextPage) {
|
||||
Log::debug(sprintf('Now calling ListCustomersRequest for next_id %d', $nextId));
|
||||
$parameters = ['from_id' => $nextId];
|
||||
$uri = '/api/v4/customers/?' . http_build_query($parameters);
|
||||
$response = $this->sendSignedSpectreGet($uri, []);
|
||||
|
||||
// count entries:
|
||||
Log::debug(sprintf('Found %d entries in data-array', count($response['data'])));
|
||||
|
||||
// extract next ID
|
||||
$hasNextPage = false;
|
||||
if (isset($response['meta']['next_id']) && (int)$response['meta']['next_id'] > $nextId) {
|
||||
$hasNextPage = true;
|
||||
$nextId = $response['meta']['next_id'];
|
||||
Log::debug(sprintf('Next ID is now %d.', $nextId));
|
||||
}
|
||||
|
||||
// store customers:
|
||||
foreach ($response['data'] as $customerArray) {
|
||||
$this->customers[] = new Customer($customerArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCustomers(): array
|
||||
{
|
||||
return $this->customers;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,103 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ListLoginsRequest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Request;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Services\Spectre\Object\Customer;
|
||||
use FireflyIII\Services\Spectre\Object\Login;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class ListLoginsRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class ListLoginsRequest extends SpectreRequest
|
||||
{
|
||||
/** @var Customer */
|
||||
private $customer;
|
||||
|
||||
/** @var array */
|
||||
private $logins = [];
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*
|
||||
*/
|
||||
public function call(): void
|
||||
{
|
||||
$hasNextPage = true;
|
||||
$nextId = 0;
|
||||
while ($hasNextPage) {
|
||||
Log::debug(sprintf('Now calling ListLoginsRequest for next_id %d', $nextId));
|
||||
$parameters = ['from_id' => $nextId, 'customer_id' => $this->customer->getId()];
|
||||
$uri = '/api/v4/logins/?' . http_build_query($parameters);
|
||||
$response = $this->sendSignedSpectreGet($uri, []);
|
||||
|
||||
// count entries:
|
||||
Log::debug(sprintf('Found %d entries in data-array', count($response['data'])));
|
||||
|
||||
// extract next ID
|
||||
$hasNextPage = false;
|
||||
if (isset($response['meta']['next_id']) && (int)$response['meta']['next_id'] > $nextId) {
|
||||
$hasNextPage = true;
|
||||
$nextId = $response['meta']['next_id'];
|
||||
Log::debug(sprintf('Next ID is now %d.', $nextId));
|
||||
}
|
||||
$collection = new Collection;
|
||||
// store logins:
|
||||
/** @var array $loginArray */
|
||||
foreach ($response['data'] as $loginArray) {
|
||||
$collection->push(new Login($loginArray));
|
||||
}
|
||||
// sort logins by date created:
|
||||
$sorted = $collection->sortByDesc(
|
||||
static function (Login $login) {
|
||||
return $login->getUpdatedAt()->timestamp;
|
||||
}
|
||||
);
|
||||
$this->logins = $sorted->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getLogins(): array
|
||||
{
|
||||
return $this->logins;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Customer $customer
|
||||
*/
|
||||
public function setCustomer(Customer $customer): void
|
||||
{
|
||||
$this->customer = $customer;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,94 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ListTransactionsRequest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Request;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Services\Spectre\Object\Account;
|
||||
use FireflyIII\Services\Spectre\Object\Transaction;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class ListTransactionsRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class ListTransactionsRequest extends SpectreRequest
|
||||
{
|
||||
/** @var Account */
|
||||
private $account;
|
||||
/** @var array */
|
||||
private $transactions = [];
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*
|
||||
*/
|
||||
public function call(): void
|
||||
{
|
||||
$hasNextPage = true;
|
||||
$nextId = 0;
|
||||
while ($hasNextPage) {
|
||||
Log::debug(sprintf('Now calling ListTransactionsRequest for next_id %d', $nextId));
|
||||
$parameters = ['from_id' => $nextId, 'account_id' => $this->account->getId()];
|
||||
$uri = '/api/v4/transactions?' . http_build_query($parameters);
|
||||
$response = $this->sendSignedSpectreGet($uri, []);
|
||||
|
||||
// count entries:
|
||||
Log::debug(sprintf('Found %d entries in data-array', count($response['data'])));
|
||||
|
||||
// extract next ID
|
||||
$hasNextPage = false;
|
||||
if (isset($response['meta']['next_id']) && (int)$response['meta']['next_id'] > $nextId) {
|
||||
$hasNextPage = true;
|
||||
$nextId = $response['meta']['next_id'];
|
||||
Log::debug(sprintf('Next ID is now %d.', $nextId));
|
||||
}
|
||||
|
||||
// store customers:
|
||||
foreach ($response['data'] as $transactionArray) {
|
||||
$this->transactions[] = new Transaction($transactionArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTransactions(): array
|
||||
{
|
||||
return $this->transactions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*/
|
||||
public function setAccount(Account $account): void
|
||||
{
|
||||
$this->account = $account;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,63 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* NewCustomerRequest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Request;
|
||||
|
||||
use FireflyIII\Services\Spectre\Object\Customer;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class NewCustomerRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class NewCustomerRequest extends SpectreRequest
|
||||
{
|
||||
/** @var Customer */
|
||||
protected $customer;
|
||||
|
||||
/**
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function call(): void
|
||||
{
|
||||
$data = [
|
||||
'data' => [
|
||||
'identifier' => 'default_ff3_customer',
|
||||
],
|
||||
];
|
||||
$uri = '/api/v4/customers/';
|
||||
Log::debug(sprintf('Going to call %s with info:', $uri), $data);
|
||||
$response = $this->sendSignedSpectrePost($uri, $data);
|
||||
// create customer:
|
||||
$this->customer = new Customer($response['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Customer
|
||||
*/
|
||||
public function getCustomer(): Customer
|
||||
{
|
||||
return $this->customer;
|
||||
}
|
||||
}
|
@@ -1,308 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SpectreRequest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Request;
|
||||
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\User;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Log;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class SpectreRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
abstract class SpectreRequest
|
||||
{
|
||||
/** @var int */
|
||||
protected $expiresAt = 0;
|
||||
/** @var string */
|
||||
private $appId;
|
||||
/** @var string */
|
||||
private $privateKey;
|
||||
/** @var string */
|
||||
private $secret;
|
||||
/** @var string */
|
||||
private $server;
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
abstract public function call(): void;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return string
|
||||
*/
|
||||
public function getAppId(): string
|
||||
{
|
||||
return $this->appId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param string $appId
|
||||
*/
|
||||
public function setAppId(string $appId): void
|
||||
{
|
||||
$this->appId = $appId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return string
|
||||
*/
|
||||
public function getSecret(): string
|
||||
{
|
||||
return $this->secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param string $secret
|
||||
*/
|
||||
public function setSecret(string $secret): void
|
||||
{
|
||||
$this->secret = $secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return string
|
||||
*/
|
||||
public function getServer(): string
|
||||
{
|
||||
return $this->server;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param string $privateKey
|
||||
*/
|
||||
public function setPrivateKey(string $privateKey): void
|
||||
{
|
||||
$this->privateKey = $privateKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->server = 'https://' . config('import.options.spectre.server');
|
||||
$this->expiresAt = time() + 180;
|
||||
$privateKey = app('preferences')->getForUser($user, 'spectre_private_key', null);
|
||||
$this->privateKey = $privateKey->data;
|
||||
|
||||
// set client ID
|
||||
$appId = app('preferences')->getForUser($user, 'spectre_app_id', null);
|
||||
if (null !== $appId && '' !== (string)$appId->data) {
|
||||
$this->appId = $appId->data;
|
||||
}
|
||||
|
||||
// set service secret
|
||||
$secret = app('preferences')->getForUser($user, 'spectre_secret', null);
|
||||
if (null !== $secret && '' !== (string)$secret->data) {
|
||||
$this->secret = $secret->data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @param string $uri
|
||||
* @param string $data
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function generateSignature(string $method, string $uri, string $data): string
|
||||
{
|
||||
if ('' === $this->privateKey) {
|
||||
throw new FireflyException('No private key present.');
|
||||
}
|
||||
$method = strtolower($method);
|
||||
if ('get' === $method || 'delete' === $method) {
|
||||
$data = '';
|
||||
}
|
||||
$toSign = $this->expiresAt . '|' . strtoupper($method) . '|' . $uri . '|' . $data . ''; // no file so no content there.
|
||||
Log::debug(sprintf('String to sign: "%s"', $toSign));
|
||||
$signature = '';
|
||||
|
||||
// Sign the data
|
||||
openssl_sign($toSign, $signature, $this->privateKey, OPENSSL_ALGO_SHA256);
|
||||
$signature = base64_encode($signature);
|
||||
|
||||
return $signature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getDefaultHeaders(): array
|
||||
{
|
||||
$userAgent = sprintf('FireflyIII v%s', config('firefly.version'));
|
||||
|
||||
return [
|
||||
'App-id' => $this->getAppId(),
|
||||
'Secret' => $this->getSecret(),
|
||||
'Accept' => 'application/json',
|
||||
'Content-type' => 'application/json',
|
||||
'Cache-Control' => 'no-cache',
|
||||
'User-Agent' => $userAgent,
|
||||
'Expires-at' => $this->expiresAt,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function sendSignedSpectreGet(string $uri, array $data): array
|
||||
{
|
||||
if ('' === $this->server) {
|
||||
throw new FireflyException('No Spectre server defined');
|
||||
}
|
||||
|
||||
$headers = $this->getDefaultHeaders();
|
||||
$sendBody = json_encode($data); // OK
|
||||
$fullUri = $this->server . $uri;
|
||||
$signature = $this->generateSignature('get', $fullUri, $sendBody);
|
||||
$headers['Signature'] = $signature;
|
||||
|
||||
Log::debug('Final headers for spectre signed get request:', $headers);
|
||||
try {
|
||||
$client = new Client;
|
||||
$res = $client->request('GET', $fullUri, ['headers' => $headers]);
|
||||
} catch (GuzzleException|Exception $e) {
|
||||
throw new FireflyException(sprintf('Guzzle Exception: %s', $e->getMessage()));
|
||||
}
|
||||
$statusCode = $res->getStatusCode();
|
||||
try {
|
||||
$returnBody = $res->getBody()->getContents();
|
||||
} catch (RuntimeException $e) {
|
||||
Log::error(sprintf('Could not get body from SpectreRequest::GET result: %s', $e->getMessage()));
|
||||
$returnBody = '';
|
||||
}
|
||||
$this->detectError($returnBody, $statusCode);
|
||||
|
||||
$array = json_decode($returnBody, true);
|
||||
$responseHeaders = $res->getHeaders();
|
||||
$array['ResponseHeaders'] = $responseHeaders;
|
||||
$array['ResponseStatusCode'] = $statusCode;
|
||||
|
||||
if (isset($array['error_class'])) {
|
||||
$message = $array['error_message'] ?? '(no message)';
|
||||
throw new FireflyException(sprintf('Error of class %s: %s', $array['error_class'], $message));
|
||||
}
|
||||
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function sendSignedSpectrePost(string $uri, array $data): array
|
||||
{
|
||||
if ('' === $this->server) {
|
||||
throw new FireflyException('No Spectre server defined');
|
||||
}
|
||||
|
||||
$headers = $this->getDefaultHeaders();
|
||||
$body = json_encode($data);
|
||||
$fullUri = $this->server . $uri;
|
||||
$signature = $this->generateSignature('post', $fullUri, $body);
|
||||
$headers['Signature'] = $signature;
|
||||
|
||||
Log::debug('Final headers for spectre signed POST request:', $headers);
|
||||
try {
|
||||
$client = new Client;
|
||||
$res = $client->request('POST', $fullUri, ['headers' => $headers, 'body' => $body]);
|
||||
} catch (GuzzleException|Exception $e) {
|
||||
throw new FireflyException(sprintf('Guzzle Exception: %s', $e->getMessage()));
|
||||
}
|
||||
|
||||
try {
|
||||
$body = $res->getBody()->getContents();
|
||||
} catch (RuntimeException $e) {
|
||||
Log::error(sprintf('Could not get body from SpectreRequest::POST result: %s', $e->getMessage()));
|
||||
$body = '';
|
||||
}
|
||||
|
||||
$statusCode = $res->getStatusCode();
|
||||
$this->detectError($body, $statusCode);
|
||||
|
||||
$array = json_decode($body, true);
|
||||
$responseHeaders = $res->getHeaders();
|
||||
$array['ResponseHeaders'] = $responseHeaders;
|
||||
$array['ResponseStatusCode'] = $statusCode;
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $body
|
||||
*
|
||||
* @param int $statusCode
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function detectError(string $body, int $statusCode): void
|
||||
{
|
||||
$array = json_decode($body, true);
|
||||
if (isset($array['error_class'])) {
|
||||
$message = $array['error_message'] ?? '(no message)';
|
||||
$errorClass = $array['error_class'];
|
||||
$class = sprintf('\\FireflyIII\\Services\\Spectre\Exception\\%sException', $errorClass);
|
||||
if (class_exists($class)) {
|
||||
throw new $class($message);
|
||||
}
|
||||
|
||||
throw new FireflyException(sprintf('Error of class %s: %s', $errorClass, $message));
|
||||
}
|
||||
|
||||
if (200 !== $statusCode) {
|
||||
throw new FireflyException(sprintf('Status code %d: %s', $statusCode, $body));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,57 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* GetAccountsRequest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Ynab\Request;
|
||||
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class GetAccountsRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class GetAccountsRequest extends YnabRequest
|
||||
{
|
||||
/** @var array */
|
||||
public $accounts;
|
||||
/** @var string */
|
||||
public $budgetId;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function call(): void
|
||||
{
|
||||
Log::debug('Now in GetAccountsRequest::call()');
|
||||
$uri = $this->api . sprintf('/budgets/%s/accounts', $this->budgetId);
|
||||
|
||||
Log::debug(sprintf('URI is %s', $uri));
|
||||
|
||||
$result = $this->authenticatedGetRequest($uri, []);
|
||||
//Log::debug('Raw GetAccountsRequest result', $result);
|
||||
|
||||
// expect data in [data][accounts]
|
||||
$this->accounts = $result['data']['accounts'] ?? [];
|
||||
}
|
||||
}
|
@@ -1,73 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* GetBudgetsRequest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Ynab\Request;
|
||||
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class GetBudgetsRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class GetBudgetsRequest extends YnabRequest
|
||||
{
|
||||
/** @var array */
|
||||
public $budgets;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->budgets = [];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function call(): void
|
||||
{
|
||||
Log::debug('Now in GetBudgetsRequest::call()');
|
||||
$uri = $this->api . '/budgets';
|
||||
|
||||
Log::debug(sprintf('URI is %s', $uri));
|
||||
|
||||
$result = $this->authenticatedGetRequest($uri, []);
|
||||
Log::debug('Raw GetBudgetsRequest result', $result);
|
||||
|
||||
// expect data in [data][budgets]
|
||||
$rawBudgets = $result['data']['budgets'] ?? [];
|
||||
$freshBudgets = [];
|
||||
foreach ($rawBudgets as $rawBudget) {
|
||||
Log::debug(sprintf('Raw content of budget is: %s', json_encode($rawBudget)));
|
||||
Log::debug(sprintf('Content of currency format is: %s', json_encode($rawBudget['currency_format'] ?? [])));
|
||||
Log::debug(sprintf('ISO code is: %s', $rawBudget['currency_format']['iso_code'] ?? '(none)'));
|
||||
$freshBudgets[] = [
|
||||
'id' => $rawBudget['id'],
|
||||
'name' => $rawBudget['name'],
|
||||
'currency_code' => $rawBudget['currency_format']['iso_code'] ?? null,
|
||||
];
|
||||
}
|
||||
$this->budgets = $freshBudgets;
|
||||
}
|
||||
}
|
@@ -1,61 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* GetTransactionsRequest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Ynab\Request;
|
||||
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class GetTransactionsRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
class GetTransactionsRequest extends YnabRequest
|
||||
{
|
||||
/** @var string */
|
||||
public $accountId;
|
||||
/** @var array */
|
||||
public $accounts;
|
||||
/** @var string */
|
||||
public $budgetId;
|
||||
/** @var array */
|
||||
public $transactions;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function call(): void
|
||||
{
|
||||
Log::debug('Now in GetTransactionsRequest::call()');
|
||||
$uri = $this->api . sprintf('/budgets/%s/accounts/%s/transactions', $this->budgetId, $this->accountId);
|
||||
|
||||
Log::debug(sprintf('URI is %s', $uri));
|
||||
|
||||
$result = $this->authenticatedGetRequest($uri, []);
|
||||
//Log::debug('Raw GetTransactionsRequest result', $result);
|
||||
|
||||
// expect data in [data][transactions]
|
||||
$this->transactions = $result['data']['transactions'] ?? [];
|
||||
}
|
||||
}
|
@@ -1,104 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* YnabRequest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Ynab\Request;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Log;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class YnabRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
abstract class YnabRequest
|
||||
{
|
||||
/** @var string */
|
||||
protected $api;
|
||||
|
||||
/** @var string */
|
||||
protected $token;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->api = 'https://' . config('import.options.ynab.live') . '/' . config('import.options.ynab.version');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
* @param array|null $params
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function authenticatedGetRequest(string $uri, array $params = null): array
|
||||
{
|
||||
Log::debug(sprintf('Now in YnabRequest::authenticatedGetRequest(%s)', $uri), $params);
|
||||
$client = new Client;
|
||||
$params = $params ?? [];
|
||||
$options = [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . $this->token,
|
||||
],
|
||||
];
|
||||
if (count($params) > 0) {
|
||||
$uri = $uri . '?' . http_build_query($params);
|
||||
}
|
||||
Log::debug(sprintf('Going to call YNAB on URI: %s', $uri), $options);
|
||||
try {
|
||||
$res = $client->request('get', $uri, $options);
|
||||
} catch (GuzzleException $e) {
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
|
||||
return [];
|
||||
}
|
||||
try {
|
||||
$content = trim($res->getBody()->getContents());
|
||||
Log::debug(sprintf('Raw body is: %s', $content));
|
||||
} catch (RuntimeException $e) {
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
return json_decode($content, true) ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
abstract public function call(): void;
|
||||
|
||||
/**
|
||||
* @param string $token
|
||||
*/
|
||||
public function setAccessToken(string $token): void
|
||||
{
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user