-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
937 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/** | ||
* @link http://www.digitaldeals.cz/ | ||
* @copyright Copyright (c) 2014 Digital Deals s.r.o. | ||
* @license http://www.digitaldeals.cz/license/ | ||
*/ | ||
|
||
namespace dlds\banking; | ||
|
||
use yii\helpers\ArrayHelper; | ||
use dlds\banking\interfaces\ApiBankAdapterInterface; | ||
|
||
/** | ||
* This is the main class of the dlds\mlm component that should be registered as an application component. | ||
* | ||
* @author Jiri Svoboda <[email protected]> | ||
* @package mlm | ||
*/ | ||
class Banking extends \yii\base\Component { | ||
|
||
/** | ||
* @var array adapters | ||
*/ | ||
public $adapters; | ||
|
||
/** | ||
* Retrieves appropriate adapter based on give adapter key | ||
*/ | ||
public function getAdapter($key) | ||
{ | ||
$adapter = ArrayHelper::getValue($this->adapters, $key); | ||
|
||
if ($adapter) | ||
{ | ||
var_dump($adapter); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Downloads transactions list from banks using module adapters | ||
* @return type | ||
*/ | ||
public function downloadTransactionsList($adapter) | ||
{ | ||
$transactions = new adapters\fio\TransactionList; | ||
|
||
foreach ($this->adapters as $key => $adapter) | ||
{ | ||
if ($adapter instanceof ApiBankAdapterInterface) | ||
{ | ||
$transactions[$key] = $adapter->downloadTransactionsList(); | ||
} | ||
} | ||
|
||
return $transactions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace dlds\banking\adapters\fio; | ||
|
||
class Account { | ||
|
||
/** @var string */ | ||
protected $accountNumber; | ||
|
||
/** @var string */ | ||
protected $bankCode; | ||
|
||
/** @var string */ | ||
protected $currency; | ||
|
||
/** @var string */ | ||
protected $iban; | ||
|
||
/** @var string */ | ||
protected $bic; | ||
|
||
/** | ||
* @param string $accountNumber | ||
* @param string $bankCode | ||
* @param string $currency | ||
* @param string $iban | ||
* @param string $bic | ||
*/ | ||
public function __construct($accountNumber, $bankCode, $currency, $iban, $bic) | ||
{ | ||
$this->accountNumber = $accountNumber; | ||
$this->bankCode = $bankCode; | ||
$this->currency = $currency; | ||
$this->iban = $iban; | ||
$this->bic = $bic; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getAccountNumber() | ||
{ | ||
return $this->accountNumber; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getBankCode() | ||
{ | ||
return $this->bankCode; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getCurrency() | ||
{ | ||
return $this->currency; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getIban() | ||
{ | ||
return $this->iban; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getBic() | ||
{ | ||
return $this->bic; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace dlds\apibank\adapters\fio; | ||
|
||
class FioAdapter implements \dlds\banking\interfaces\ApiBankAdapterInterface { | ||
|
||
public function downloadTransactionsLast() | ||
{ | ||
|
||
} | ||
|
||
public function downloadTransactionsSince($datetime) | ||
{ | ||
|
||
} | ||
|
||
public function uploadTransactionsList() | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
namespace dlds\banking\adapters\fio; | ||
|
||
use FioApi\Exceptions\InternalErrorException; | ||
use FioApi\Exceptions\TooGreedyException; | ||
use GuzzleHttp\Client as Guzzle; | ||
|
||
class Downloader { | ||
|
||
/** @var UrlBuilder */ | ||
protected $urlBuilder; | ||
|
||
/** @var \GuzzleHttp\Client */ | ||
protected $client; | ||
|
||
/** @var string */ | ||
protected $certificatePath; | ||
|
||
/** | ||
* @param string $token | ||
*/ | ||
public function __construct($token) | ||
{ | ||
$this->urlBuilder = new UrlBuilder($token); | ||
} | ||
|
||
/** | ||
* @param string $path | ||
*/ | ||
public function setCertificatePath($path) | ||
{ | ||
$this->certificatePath = $path; | ||
} | ||
|
||
public function getCertificatePath() | ||
{ | ||
if ($this->certificatePath) | ||
{ | ||
return $this->certificatePath; | ||
} | ||
|
||
//Key downloaded from https://www.geotrust.com/resources/root-certificates/ | ||
return __DIR__.'/keys/Equifax_Secure_Certificate_Authority.pem'; | ||
} | ||
|
||
/** | ||
* @return Guzzle | ||
*/ | ||
public function getClient() | ||
{ | ||
if (!$this->client) | ||
{ | ||
$this->client = new Guzzle(); | ||
} | ||
return $this->client; | ||
} | ||
|
||
/** | ||
* @param \DateTime $from | ||
* @param \DateTime $to | ||
* @return TransactionList | ||
*/ | ||
public function downloadFromTo(\DateTime $from, \DateTime $to) | ||
{ | ||
$client = $this->getClient(); | ||
$url = $this->urlBuilder->buildPeriodsUrl($from, $to); | ||
|
||
try | ||
{ | ||
$response = $client->get($url, ['verify' => $this->getCertificatePath()]); | ||
} | ||
catch (\GuzzleHttp\Exception\BadResponseException $e) | ||
{ | ||
if ($e->getCode() == 409) | ||
{ | ||
throw new TooGreedyException('You can use one token for API call every 30 seconds', $e->getCode(), $e); | ||
} | ||
if ($e->getCode() == 500) | ||
{ | ||
throw new InternalErrorException('Server returned 500 Internal Error (probably invalid token?)', $e->getCode(), $e); | ||
} | ||
throw $e; | ||
} | ||
|
||
return TransactionList::create($response->json([ | ||
'object' => true, | ||
'big_int_strings' => true, | ||
])->accountStatement); | ||
} | ||
|
||
/** | ||
* @param \DateTime $since | ||
* @return TransactionList | ||
*/ | ||
public function downloadSince(\DateTime $since) | ||
{ | ||
return $this->downloadFromTo($since, new \DateTime()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
namespace dlds\banking\adapters\fio; | ||
|
||
use FioApi\Exceptions\InternalErrorException; | ||
use FioApi\Exceptions\TooGreedyException; | ||
use GuzzleHttp\Client as Guzzle; | ||
|
||
class Uploader { | ||
|
||
/** @var UrlBuilder */ | ||
protected $urlBuilder; | ||
|
||
/** @var \GuzzleHttp\Client */ | ||
protected $client; | ||
|
||
/** @var string */ | ||
protected $certificatePath; | ||
|
||
/** | ||
* @param string $token | ||
*/ | ||
public function __construct($token) | ||
{ | ||
$this->urlBuilder = new UrlBuilder($token); | ||
} | ||
|
||
/** | ||
* @param string $path | ||
*/ | ||
public function setCertificatePath($path) | ||
{ | ||
$this->certificatePath = $path; | ||
} | ||
|
||
public function getCertificatePath() | ||
{ | ||
if ($this->certificatePath) | ||
{ | ||
return $this->certificatePath; | ||
} | ||
|
||
//Key downloaded from https://www.geotrust.com/resources/root-certificates/ | ||
return __DIR__.'/keys/Equifax_Secure_Certificate_Authority.pem'; | ||
} | ||
|
||
/** | ||
* @return Guzzle | ||
*/ | ||
public function getClient() | ||
{ | ||
if (!$this->client) | ||
{ | ||
$this->client = new Guzzle(); | ||
} | ||
return $this->client; | ||
} | ||
|
||
/** | ||
* @param \DateTime $from | ||
* @param \DateTime $to | ||
* @return TransactionList | ||
*/ | ||
public function downloadFromTo(\DateTime $from, \DateTime $to) | ||
{ | ||
$client = $this->getClient(); | ||
$url = $this->urlBuilder->buildPeriodsUrl($from, $to); | ||
|
||
try | ||
{ | ||
$response = $client->get($url, ['verify' => $this->getCertificatePath()]); | ||
} | ||
catch (\GuzzleHttp\Exception\BadResponseException $e) | ||
{ | ||
if ($e->getCode() == 409) | ||
{ | ||
throw new TooGreedyException('You can use one token for API call every 30 seconds', $e->getCode(), $e); | ||
} | ||
if ($e->getCode() == 500) | ||
{ | ||
throw new InternalErrorException('Server returned 500 Internal Error (probably invalid token?)', $e->getCode(), $e); | ||
} | ||
throw $e; | ||
} | ||
|
||
return TransactionList::create($response->json([ | ||
'object' => true, | ||
'big_int_strings' => true, | ||
])->accountStatement); | ||
} | ||
|
||
/** | ||
* @param \DateTime $since | ||
* @return TransactionList | ||
*/ | ||
public function downloadSince(\DateTime $since) | ||
{ | ||
return $this->downloadFromTo($since, new \DateTime()); | ||
} | ||
} |
Oops, something went wrong.