Skip to content

Commit

Permalink
Added option to specify custom PDF Factory.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-svirin committed May 27, 2024
1 parent a735e38 commit 45b3938
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 210 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Add 'xml_files' parser for order data.
* Updated BTD method signature.
* Added support for EBICS version 2.4.
* Added option to specify custom PDF Factory.

## 2.1

Expand Down
6 changes: 5 additions & 1 deletion src/Contracts/EbicsClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,11 @@ public function Z54(
*
* @return DownloadOrderResult
*/
public function ZSR(): DownloadOrderResult;
public function ZSR(
DateTimeInterface $dateTime = null,
DateTimeInterface $startDateTime = null,
DateTimeInterface $endDateTime = null
): DownloadOrderResult;

/**
* Download subscriber's customer and subscriber information.
Expand Down
17 changes: 17 additions & 0 deletions src/Contracts/PdfFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace AndrewSvirin\Ebics\Contracts;

/**
* PdfFactory class representation.
*
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @author Andrew Svirin
*/
interface PdfFactoryInterface
{
/**
* Create PDF document from HTML.
*/
public function createFromHtml(string $html): PdfInterface;
}
4 changes: 1 addition & 3 deletions src/Contracts/PdfInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace AndrewSvirin\Ebics\Contracts;

use Mpdf\HTMLParserMode;

/**
* PDF class representation.
*
Expand All @@ -23,7 +21,7 @@ interface PdfInterface
*
* @see \Mpdf\Mpdf::WriteHTML()
*/
public function writeHTML($html, $mode = HTMLParserMode::DEFAULT_MODE, $init = true, $close = true);
public function writeHTML($html, $mode = 0, $init = true, $close = true);

/**
* @return string
Expand Down
11 changes: 10 additions & 1 deletion src/EbicsBankLetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace AndrewSvirin\Ebics;

use AndrewSvirin\Ebics\Contracts\BankLetter\FormatterInterface;
use AndrewSvirin\Ebics\Contracts\PdfFactoryInterface;
use AndrewSvirin\Ebics\Factories\BankLetterFactory;
use AndrewSvirin\Ebics\Factories\PdfFactory;
use AndrewSvirin\Ebics\Models\Bank;
use AndrewSvirin\Ebics\Models\BankLetter;
use AndrewSvirin\Ebics\Models\Keyring;
Expand All @@ -29,11 +31,13 @@ final class EbicsBankLetter
{
private BankLetterService $bankLetterService;
private BankLetterFactory $bankLetterFactory;
private PdfFactoryInterface $pdfFactory;

public function __construct()
{
$this->bankLetterService = new BankLetterService();
$this->bankLetterFactory = new BankLetterFactory();
$this->pdfFactory = new PdfFactory();
}

/**
Expand Down Expand Up @@ -107,8 +111,13 @@ public function createHtmlBankLetterFormatter(): HtmlBankLetterFormatter
return new HtmlBankLetterFormatter();
}

public function setPdfFactory(PdfFactoryInterface $pdfFactory): void
{
$this->pdfFactory = $pdfFactory;
}

public function createPdfBankLetterFormatter(): PdfBankLetterFormatter
{
return new PdfBankLetterFormatter();
return new PdfBankLetterFormatter($this->pdfFactory);
}
}
3 changes: 2 additions & 1 deletion src/Factories/PdfFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace AndrewSvirin\Ebics\Factories;

use AndrewSvirin\Ebics\Contracts\PdfFactoryInterface;
use AndrewSvirin\Ebics\Contracts\PdfInterface;
use AndrewSvirin\Ebics\Models\Pdf;

Expand All @@ -11,7 +12,7 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @author Andrew Svirin
*/
final class PdfFactory
final class PdfFactory implements PdfFactoryInterface
{
public function createFromHtml(string $html): PdfInterface
{
Expand Down
8 changes: 4 additions & 4 deletions src/Services/BankLetter/Formatter/PdfBankLetterFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace AndrewSvirin\Ebics\Services\BankLetter\Formatter;

use AndrewSvirin\Ebics\Contracts\BankLetter\FormatterInterface;
use AndrewSvirin\Ebics\Factories\PdfFactory;
use AndrewSvirin\Ebics\Contracts\PdfFactoryInterface;
use AndrewSvirin\Ebics\Models\BankLetter;

/**
Expand All @@ -17,12 +17,12 @@
final class PdfBankLetterFormatter implements FormatterInterface
{
private HtmlBankLetterFormatter $bankLetterFormatterHtml;
private PdfFactory $pdfFactory;
private PdfFactoryInterface $pdfFactory;

public function __construct()
public function __construct(PdfFactoryInterface $pdfFactory)
{
$this->bankLetterFormatterHtml = new HtmlBankLetterFormatter();
$this->pdfFactory = new PdfFactory();
$this->pdfFactory = $pdfFactory;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/EbicsClientV24Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ public function testFDL(int $credentialsId, array $codes, X509GeneratorInterface
$fileFormat,
'text',
'FR',
new DateTime(),
(new DateTime())->modify('-30 day'),
(new DateTime())->modify('-1 day')
null,
new DateTime('2020-03-21'),
new DateTime('2020-04-21')
);

$parser = new CfonbParser();
Expand Down
39 changes: 12 additions & 27 deletions tests/EbicsClientV25Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ public function testHTD(int $credentialsId, array $codes, X509GeneratorInterface
* @dataProvider serversDataProvider
*
* @group PTK
* @group PTK-V2
*
* @param int $credentialsId
* @param array $codes
Expand Down Expand Up @@ -337,7 +338,7 @@ public function testVMK(int $credentialsId, array $codes, X509GeneratorInterface
$client = $this->setupClientV25($credentialsId, $x509Generator, $codes['VMK']['fake']);

$this->assertExceptionCode($codes['VMK']['code']);
$vmk = $client->VMK();
$vmk = $client->VMK(null, new DateTime('2020-03-21'), new DateTime('2020-04-21'));

$responseHandler = $client->getResponseHandler();
$code = $responseHandler->retrieveH00XReturnCode($vmk->getTransaction()->getLastSegment()->getResponse());
Expand Down Expand Up @@ -366,7 +367,7 @@ public function testSTA(int $credentialsId, array $codes, X509GeneratorInterface
$client = $this->setupClientV25($credentialsId, $x509Generator, $codes['STA']['fake']);

$this->assertExceptionCode($codes['STA']['code']);
$sta = $client->STA();
$sta = $client->STA(null, new DateTime('2020-03-21'), new DateTime('2020-04-21'));

$responseHandler = $client->getResponseHandler();
$code = $responseHandler->retrieveH00XReturnCode($sta->getTransaction()->getLastSegment()->getResponse());
Expand Down Expand Up @@ -395,7 +396,7 @@ public function testC52(int $credentialsId, array $codes, X509GeneratorInterface
$client = $this->setupClientV25($credentialsId, $x509Generator, $codes['C52']['fake']);

$this->assertExceptionCode($codes['C52']['code']);
$c52 = $client->C52();
$c52 = $client->C52(null, new DateTime('2020-03-21'), new DateTime('2020-04-21'));

$responseHandler = $client->getResponseHandler();
$code = $responseHandler->retrieveH00XReturnCode($c52->getTransaction()->getLastSegment()->getResponse());
Expand Down Expand Up @@ -424,11 +425,7 @@ public function testC53(int $credentialsId, array $codes, X509GeneratorInterface
$client = $this->setupClientV25($credentialsId, $x509Generator, $codes['C53']['fake']);

$this->assertExceptionCode($codes['C53']['code']);
$c53 = $client->C53(
new DateTime(),
(new DateTime())->modify('-30 day'),
(new DateTime())->modify('-1 day')
);
$c53 = $client->C53(null, new DateTime('2020-03-21'), new DateTime('2020-04-21'));

$responseHandler = $client->getResponseHandler();
$code = $responseHandler->retrieveH00XReturnCode($c53->getTransaction()->getLastSegment()->getResponse());
Expand Down Expand Up @@ -457,11 +454,7 @@ public function testC54(int $credentialsId, array $codes, X509GeneratorInterface
$client = $this->setupClientV25($credentialsId, $x509Generator, $codes['C54']['fake']);

$this->assertExceptionCode($codes['C54']['code']);
$c54 = $client->C53(
new DateTime(),
(new DateTime())->modify('-30 day'),
(new DateTime())->modify('-1 day')
);
$c54 = $client->C54(null, new DateTime('2020-03-21'), new DateTime('2020-04-21'));

$responseHandler = $client->getResponseHandler();
$code = $responseHandler->retrieveH00XReturnCode($c54->getTransaction()->getLastSegment()->getResponse());
Expand Down Expand Up @@ -490,7 +483,7 @@ public function testZ52(int $credentialsId, array $codes, X509GeneratorInterface
$client = $this->setupClientV25($credentialsId, $x509Generator, $codes['Z52']['fake']);

$this->assertExceptionCode($codes['Z52']['code']);
$z52 = $client->Z52();
$z52 = $client->Z52(null, new DateTime('2020-03-21'), new DateTime('2020-04-21'));

$responseHandler = $client->getResponseHandler();
$code = $responseHandler->retrieveH00XReturnCode($z52->getTransaction()->getLastSegment()->getResponse());
Expand Down Expand Up @@ -519,11 +512,7 @@ public function testZ53(int $credentialsId, array $codes, X509GeneratorInterface
$client = $this->setupClientV25($credentialsId, $x509Generator, $codes['Z53']['fake']);

$this->assertExceptionCode($codes['Z53']['code']);
$z53 = $client->Z53(
new DateTime(),
(new DateTime())->modify('-30 day'),
(new DateTime())->modify('-1 day')
);
$z53 = $client->Z53(null, new DateTime('2020-03-21'), new DateTime('2020-04-21'));

$responseHandler = $client->getResponseHandler();
$code = $responseHandler->retrieveH00XReturnCode($z53->getTransaction()->getLastSegment()->getResponse());
Expand Down Expand Up @@ -552,11 +541,7 @@ public function testZ54(int $credentialsId, array $codes, X509GeneratorInterface
$client = $this->setupClientV25($credentialsId, $x509Generator, $codes['Z54']['fake']);

$this->assertExceptionCode($codes['Z54']['code']);
$z54 = $client->Z54(
new DateTime(),
(new DateTime())->modify('-30 day'),
(new DateTime())->modify('-1 day')
);
$z54 = $client->Z54(null, new DateTime('2020-03-21'), new DateTime('2020-04-21'));

$responseHandler = $client->getResponseHandler();
$code = $responseHandler->retrieveH00XReturnCode($z54->getTransaction()->getLastSegment()->getResponse());
Expand Down Expand Up @@ -591,9 +576,9 @@ public function testFDL(int $credentialsId, array $codes, X509GeneratorInterface
$fileFormat,
EbicsClient::FILE_PARSER_FORMAT_TEXT,
EbicsClient::COUNTRY_CODE_FR,
new DateTime(),
(new DateTime())->modify('-30 day'),
(new DateTime())->modify('-1 day')
null,
new DateTime('2020-03-21'),
new DateTime('2020-04-21')
);

$parser = new CfonbParser();
Expand Down
Loading

0 comments on commit 45b3938

Please sign in to comment.