Skip to content

Commit

Permalink
Code refactoring. Add PDF letter format.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andriy Svirin committed Jan 5, 2021
1 parent 19ec5dd commit 93b9f81
Show file tree
Hide file tree
Showing 51 changed files with 1,919 additions and 1,010 deletions.
37 changes: 23 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ $keyRingRealPath = __PATH_TO_WORKSPACES_DIR__ . '/workspace/keyring.json';
// Use __IS_CERTIFIED__ true for French banks, otherwise use false.
$keyRingManager = new KeyRingManager($keyRingRealPath, __PASSWORD__);
$keyRing = $keyRingManager->loadKeyRing();
$bank = new Bank(__HOST_ID__, __HOST_URL__, __IS_CERTIFIED__);
$bank = new Bank(__HOST_ID__, __HOST_URL__);
$bank->setIsCertified(__IS_CERTIFIED__);
$user = new User(__PARTNER_ID__, __USER_ID__);
$client = new EbicsClient($bank, $user, $keyRing);
```
Expand All @@ -49,7 +50,10 @@ $client = new EbicsClient($bank, $user, $keyRing);
use AndrewSvirin\Ebics\Contracts\EbicsResponseExceptionInterface;

try {
/* @var \AndrewSvirin\Ebics\EbicsClient $client */
$client->INI();
/* @var \AndrewSvirin\Ebics\Services\KeyRingManager $keyRingManager */
/* @var \AndrewSvirin\Ebics\Models\KeyRing $keyRing */
$keyRingManager->saveKeyRing($keyRing);
} catch (EbicsResponseExceptionInterface $exception) {
echo sprintf(
Expand Down Expand Up @@ -95,7 +99,7 @@ You can achieve this by creating a class which extends the `AbstractX509Generato

namespace App\Factories\X509;

use AndrewSvirin\Ebics\Factories\X509\AbstractX509Generator;
use AndrewSvirin\Ebics\Models\X509\AbstractX509Generator;

class MyCompanyX509Generator extends AbstractX509Generator
{
Expand Down Expand Up @@ -127,12 +131,10 @@ Once your class is created, call the `X509GeneratorFactory::setGeneratorClass()`
```php
<?php

use AndrewSvirin\Ebics\Factories\X509\X509GeneratorFactory;
use App\Factories\X509\MyCompanyX509Generator;

X509GeneratorFactory::setGeneratorClass(MyCompanyX509Generator::class);
//...
/* @var \AndrewSvirin\Ebics\EbicsClient $client */
$client->INI();
$client->setX509Generator(new MyCompanyX509Generator);
```

## Other examples
Expand All @@ -145,6 +147,7 @@ use AndrewSvirin\Ebics\Exceptions\NoDownloadDataAvailableException;
use AndrewSvirin\Ebics\Contracts\EbicsResponseExceptionInterface;

try {
/* @var \AndrewSvirin\Ebics\EbicsClient $client */
//Fetch datas from your bank
$response = $client->FDL('camt.xxx.cfonb120.stm');
foreach($response->getTransactions() as $transaction) {
Expand Down Expand Up @@ -183,12 +186,14 @@ More methods you can find in `tests/EbicsTest`

use AndrewSvirin\Ebics\Contracts\EbicsResponseExceptionInterface;

$client = new EbicsClient(...);
/* @var \AndrewSvirin\Ebics\EbicsClient $client */
// For French bank.
$client->setX509Generator(new MyCompanyX509Generator);

try {
$client->INI();
/* @var \AndrewSvirin\Ebics\Services\KeyRingManager $keyRingManager */
/* @var \AndrewSvirin\Ebics\Models\KeyRing $keyRing */
$keyRingManager->saveKeyRing($keyRing);
} catch (EbicsResponseExceptionInterface $exception) {
echo sprintf(
Expand All @@ -214,15 +219,16 @@ try {

### 2. Generate a EBICS letter
```php
$ebicsBankLetter = new EbicsBankLetter();
/* @var \AndrewSvirin\Ebics\EbicsClient $client */
$ebicsBankLetter = new \AndrewSvirin\Ebics\EbicsBankLetter();

$bankLetter = $ebicsBankLetter->prepareBankLetter(
$client->getBank(),
$client->getUser(),
$client->getKeyRing()
);
$bankLetter = $ebicsBankLetter->prepareBankLetter(
$client->getBank(),
$client->getUser(),
$client->getKeyRing()
);

$txt = $ebicsBankLetter->formatBankLetter($bankLetter, new BankLetterFormatterTxt());
$txt = $ebicsBankLetter->formatBankLetter($bankLetter, new \AndrewSvirin\Ebics\Services\BankLetterFormatterTxt());
```

### 3. Wait for the bank validation and activation access.
Expand All @@ -231,7 +237,10 @@ try {
```php

try {
/* @var \AndrewSvirin\Ebics\EbicsClient $client */
$client->HPB();
/* @var \AndrewSvirin\Ebics\Services\KeyRingManager $keyRingManager */
/* @var \AndrewSvirin\Ebics\Models\KeyRing $keyRing */
$keyRingManager->saveKeyRing($keyRing);
} catch (EbicsResponseExceptionInterface $exception) {
echo sprintf(
Expand Down
14 changes: 10 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
"license": "MIT",
"require": {
"php": "^7.2",
"ext-curl": "*",
"ext-dom": "*",
"ext-openssl": "*",
"ext-zlib": "*",
"ext-json": "*",
"phpseclib/phpseclib": "~2.0",
"symfony/http-client": "^4.3||^5.0"
"phpseclib/phpseclib": "~2.0"
},
"require-dev": {
"mpdf/mpdf": "^8.0",
"phpstan/phpstan": "^0.12.29",
"phpunit/phpunit": "^8.5",
"squizlabs/php_codesniffer": "^3.3"
Expand All @@ -42,8 +43,13 @@
}
},
"suggest": {
"silarhi/cfonb-parser": "If you need to parse CFONB datas from French Bank",
"andrew-svirin/mt942-php": "If you need to parse format MT942 from VMK, STA requests."
"silarhi/cfonb-parser": "If you need to parse CFONB datas from French Bank.",
"andrew-svirin/mt942-php": "If you need to parse format MT942 from VMK, STA requests.",
"mpdf/mpdf": "If you need to generate PDF file letter for Bank."
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
16 changes: 0 additions & 16 deletions src/Contracts/CertificateInterface.php

This file was deleted.

151 changes: 151 additions & 0 deletions src/Contracts/Crypt/X509Interface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?php

namespace AndrewSvirin\Ebics\Contracts\Crypt;

use phpseclib\File\X509;

/**
* Crypt X509 representation.
*
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @author Andrew Svirin
*/
interface X509Interface
{

/**
* @param string $date
*
* @return void
*
* @see \phpseclib\File\X509::setStartDate()
*/
public function setStartDate($date);

/**
* @param string $date
*
* @return void
* @see \phpseclib\File\X509::setEndDate()
*
*/
public function setEndDate($date);

/**
* @param string $serial
* @param int $base optional
*
* @return void
*
* @@see \phpseclib\File\X509::setSerialNumber()
*/
public function setSerialNumber($serial, $base = -256);

/**
* @param X509Interface $issuer
* @param X509Interface $subject
* @param string $signatureAlgorithm optional
*
* @return mixed
*
* @see \phpseclib\File\X509::sign()
*/
public function sign($issuer, $subject, $signatureAlgorithm = 'sha1WithRSAEncryption');

/**
* @param string $cert
* @param int $mode
*
* @return mixed
*
* @see \phpseclib\File\X509::loadX509()
*/
public function loadX509($cert, $mode = X509::FORMAT_AUTO_DETECT);

/**
* @param string $id
* @param mixed $value
* @param bool $critical optional
* @param bool $replace optional
*
* @return bool
*
* @see \phpseclib\File\X509::setExtension()
*/
public function setExtension($id, $value, $critical = false, $replace = true);

/**
* @param array $cert
* @param int $format optional
*
* @return string
*
* @see \phpseclib\File\X509::saveX509()
*/
public function saveX509($cert, $format = X509::FORMAT_PEM);

/**
* @param object $key
*
* @return bool
*
* @see \phpseclib\File\X509::setPublicKey()
*/
public function setPublicKey($key);

/**
* @param object $key
*
* @return void
*
* @see \phpseclib\File\X509::setPrivateKey()
*/
public function setPrivateKey($key);

/**
* @param mixed $dn
* @param bool $merge optional
* @param string $type optional
*
* @return bool
*
* @see \phpseclib\File\X509::setDN()
*/
public function setDN($dn, $merge = false, $type = 'utf8String');

/**
* @param mixed $format optional
* @param array $dn optional
*
* @return bool
*
* @see \phpseclib\File\X509::getDN()
*/
public function getDN($format = X509::DN_ARRAY, $dn = null);

/**
* @return void
*
* @see \phpseclib\File\X509::setDomain()
*/
public function setDomain();

/**
* @param string $value
*
* @return void
*
* @see \phpseclib\File\X509::setKeyIdentifier()
*/
public function setKeyIdentifier($value);

/**
* @param mixed $key optional
* @param int $method optional
*
* @return string binary key identifier
*
* @see \phpseclib\File\X509::computeKeyIdentifier()
*/
public function computeKeyIdentifier($key = null, $method = 1);
}
14 changes: 7 additions & 7 deletions src/Contracts/EbicsClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace AndrewSvirin\Ebics\Contracts;

use AndrewSvirin\Ebics\Models\Response;
use AndrewSvirin\Ebics\Models\Http\Response;
use DateTime;

/**
Expand All @@ -22,8 +22,8 @@ public function HEV(): Response;

/**
* Make INI request.
* Send to the bank public certificate of signature A006.
* Prepare A006 certificates for KeyRing.
* Send to the bank public signature of signature A006.
* Prepare A006 signature for KeyRing.
*
* @param DateTime|null $dateTime current date
*
Expand All @@ -33,8 +33,8 @@ public function INI(DateTime $dateTime = null): Response;

/**
* Make HIA request.
* Send to the bank public certificates of authentication (X002) and encryption (E002).
* Prepare E002 and X002 user certificates for KeyRing.
* Send to the bank public signatures of authentication (X002) and encryption (E002).
* Prepare E002 and X002 user signatures for KeyRing.
*
* @param DateTime|null $dateTime current date
*
Expand All @@ -43,9 +43,9 @@ public function INI(DateTime $dateTime = null): Response;
public function HIA(DateTime $dateTime = null): Response;

/**
* Retrieve the Bank public certificates authentication (X002) and encryption (E002).
* Retrieve the Bank public signatures authentication (X002) and encryption (E002).
* Decrypt OrderData.
* Prepare E002 and X002 bank certificates for KeyRing.
* Prepare E002 and X002 bank signatures for KeyRing.
*
* @param DateTime|null $dateTime current date
*
Expand Down
4 changes: 2 additions & 2 deletions src/Contracts/EbicsResponseExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace AndrewSvirin\Ebics\Contracts;

use AndrewSvirin\Ebics\Models\Request;
use AndrewSvirin\Ebics\Models\Response;
use AndrewSvirin\Ebics\Models\Http\Request;
use AndrewSvirin\Ebics\Models\Http\Response;

/**
* EBICS ResponseExceptionInterface representation.
Expand Down
Loading

0 comments on commit 93b9f81

Please sign in to comment.