diff --git a/CHANGELOG.md b/CHANGELOG.md index a8f1d28..0dc5bee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Contracts/EbicsClientInterface.php b/src/Contracts/EbicsClientInterface.php index 9b80dda..ffcd0aa 100644 --- a/src/Contracts/EbicsClientInterface.php +++ b/src/Contracts/EbicsClientInterface.php @@ -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. diff --git a/src/Contracts/PdfFactoryInterface.php b/src/Contracts/PdfFactoryInterface.php new file mode 100644 index 0000000..a06a027 --- /dev/null +++ b/src/Contracts/PdfFactoryInterface.php @@ -0,0 +1,17 @@ +bankLetterService = new BankLetterService(); $this->bankLetterFactory = new BankLetterFactory(); + $this->pdfFactory = new PdfFactory(); } /** @@ -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); } } diff --git a/src/Factories/PdfFactory.php b/src/Factories/PdfFactory.php index 160cc33..f435620 100644 --- a/src/Factories/PdfFactory.php +++ b/src/Factories/PdfFactory.php @@ -2,6 +2,7 @@ namespace AndrewSvirin\Ebics\Factories; +use AndrewSvirin\Ebics\Contracts\PdfFactoryInterface; use AndrewSvirin\Ebics\Contracts\PdfInterface; use AndrewSvirin\Ebics\Models\Pdf; @@ -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 { diff --git a/src/Services/BankLetter/Formatter/PdfBankLetterFormatter.php b/src/Services/BankLetter/Formatter/PdfBankLetterFormatter.php index 034a2eb..b9e64b5 100644 --- a/src/Services/BankLetter/Formatter/PdfBankLetterFormatter.php +++ b/src/Services/BankLetter/Formatter/PdfBankLetterFormatter.php @@ -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; /** @@ -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; } /** diff --git a/tests/EbicsClientV24Test.php b/tests/EbicsClientV24Test.php index 0680d3a..1198f6d 100644 --- a/tests/EbicsClientV24Test.php +++ b/tests/EbicsClientV24Test.php @@ -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(); diff --git a/tests/EbicsClientV25Test.php b/tests/EbicsClientV25Test.php index b28e1c0..83d576f 100644 --- a/tests/EbicsClientV25Test.php +++ b/tests/EbicsClientV25Test.php @@ -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 @@ -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()); @@ -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()); @@ -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()); @@ -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()); @@ -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()); @@ -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()); @@ -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()); @@ -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()); @@ -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(); diff --git a/tests/EbicsClientV3Test.php b/tests/EbicsClientV3Test.php index 410d5f3..400619f 100644 --- a/tests/EbicsClientV3Test.php +++ b/tests/EbicsClientV3Test.php @@ -12,6 +12,7 @@ use AndrewSvirin\Ebics\Factories\DocumentFactory; use AndrewSvirin\Ebics\Tests\Factories\X509\CreditSuisseX509Generator; use AndrewSvirin\Ebics\Tests\Factories\X509\ZKBX509Generator; +use DateTime; /** * Class EbicsClientTest. @@ -211,6 +212,68 @@ public function testHKD(int $credentialsId, array $codes, X509GeneratorInterface $this->assertResponseDone($code, $reportText); } + /** + * @dataProvider serversDataProvider + * + * @group HPD + * @group V3 + * @group HPD-V3 + * + * @param int $credentialsId + * @param array $codes + * @param X509GeneratorInterface|null $x509Generator + * + * @covers + */ + public function testHPD(int $credentialsId, array $codes, X509GeneratorInterface $x509Generator = null) + { + $client = $this->setupClientV3($credentialsId, $x509Generator, $codes['HPD']['fake']); + + $this->assertExceptionCode($codes['HPD']['code']); + $hpd = $client->HPD(); + + $responseHandler = $client->getResponseHandler(); + $code = $responseHandler->retrieveH00XReturnCode($hpd->getTransaction()->getLastSegment()->getResponse()); + $reportText = $responseHandler->retrieveH00XReportText($hpd->getTransaction()->getLastSegment()->getResponse()); + $this->assertResponseOk($code, $reportText); + + $code = $responseHandler->retrieveH00XReturnCode($hpd->getTransaction()->getReceipt()); + $reportText = $responseHandler->retrieveH00XReportText($hpd->getTransaction()->getReceipt()); + + $this->assertResponseDone($code, $reportText); + } + + /** + * @dataProvider serversDataProvider + * + * @group HAA + * @group V3 + * @group HAA-V3 + * + * @param int $credentialsId + * @param array $codes + * @param X509GeneratorInterface|null $x509Generator + * + * @covers + */ + public function testHAA(int $credentialsId, array $codes, X509GeneratorInterface $x509Generator = null) + { + $client = $this->setupClientV3($credentialsId, $x509Generator, $codes['HAA']['fake']); + + $this->assertExceptionCode($codes['HAA']['code']); + $haa = $client->HAA(); + + $responseHandler = $client->getResponseHandler(); + $code = $responseHandler->retrieveH00XReturnCode($haa->getTransaction()->getLastSegment()->getResponse()); + $reportText = $responseHandler->retrieveH00XReportText($haa->getTransaction()->getLastSegment()->getResponse()); + $this->assertResponseOk($code, $reportText); + + $code = $responseHandler->retrieveH00XReturnCode($haa->getTransaction()->getReceipt()); + $reportText = $responseHandler->retrieveH00XReportText($haa->getTransaction()->getReceipt()); + + $this->assertResponseDone($code, $reportText); + } + /** * @dataProvider serversDataProvider * @@ -228,19 +291,6 @@ public function testBTD(int $credentialsId, array $codes, X509GeneratorInterface { $client = $this->setupClientV3($credentialsId, $x509Generator, $codes['BTD']['fake']); - /** - * Method HKD. - * - * BTD - * - * PSR - * CH - * - * pain.002 - * - * CH Payment Status Report - * - */ $context = new BTDContext(); $context->setServiceName('PSR'); $context->setMsgName('pain.002'); @@ -249,7 +299,7 @@ public function testBTD(int $credentialsId, array $codes, X509GeneratorInterface $context->setContainerType('ZIP'); $this->assertExceptionCode($codes['BTD']['code']); - $btd = $client->BTD($context); + $btd = $client->BTD($context, null, new DateTime('2020-03-21'), new DateTime('2020-04-21')); $responseHandler = $client->getResponseHandler(); $code = $responseHandler->retrieveH00XReturnCode($btd->getTransaction()->getLastSegment()->getResponse()); @@ -262,6 +312,99 @@ public function testBTD(int $credentialsId, array $codes, X509GeneratorInterface $this->assertResponseDone($code, $reportText); } + /** + * @dataProvider serversDataProvider + * + * @group PTK + * @group V3 + * @group PTK-V3 + * + * @param int $credentialsId + * @param array $codes + * @param X509GeneratorInterface|null $x509Generator + * + * @covers + */ + public function testPTK(int $credentialsId, array $codes, X509GeneratorInterface $x509Generator = null) + { + $client = $this->setupClientV3($credentialsId, $x509Generator, $codes['PTK']['fake']); + + $this->assertExceptionCode($codes['PTK']['code']); + $ptk = $client->PTK(); + + $responseHandler = $client->getResponseHandler(); + $code = $responseHandler->retrieveH00XReturnCode($ptk->getTransaction()->getLastSegment()->getResponse()); + $reportText = $responseHandler->retrieveH00XReportText($ptk->getTransaction()->getLastSegment()->getResponse()); + $this->assertResponseOk($code, $reportText); + + $code = $responseHandler->retrieveH00XReturnCode($ptk->getTransaction()->getReceipt()); + $reportText = $responseHandler->retrieveH00XReportText($ptk->getTransaction()->getReceipt()); + + $this->assertResponseDone($code, $reportText); + } + + /** + * @dataProvider serversDataProvider + * + * @group Z54 + * @group V3 + * @group Z54-V3 + * + * @param int $credentialsId + * @param array $codes + * @param X509GeneratorInterface|null $x509Generator + * + * @covers + */ + public function testZ54(int $credentialsId, array $codes, X509GeneratorInterface $x509Generator = null) + { + $client = $this->setupClientV3($credentialsId, $x509Generator, $codes['Z54']['fake']); + + $this->assertExceptionCode($codes['Z54']['code']); + $z54 = $client->Z54(null, new DateTime('2020-03-21'), new DateTime('2020-04-21')); + + $responseHandler = $client->getResponseHandler(); + $code = $responseHandler->retrieveH00XReturnCode($z54->getTransaction()->getLastSegment()->getResponse()); + $reportText = $responseHandler->retrieveH00XReportText($z54->getTransaction()->getLastSegment()->getResponse()); + $this->assertResponseOk($code, $reportText); + + $code = $responseHandler->retrieveH00XReturnCode($z54->getTransaction()->getReceipt()); + $reportText = $responseHandler->retrieveH00XReportText($z54->getTransaction()->getReceipt()); + + $this->assertResponseDone($code, $reportText); + } + + /** + * @dataProvider serversDataProvider + * + * @group ZSR + * @group V3 + * @group ZSR-V3 + * + * @param int $credentialsId + * @param array $codes + * @param X509GeneratorInterface|null $x509Generator + * + * @covers + */ + public function testZSR(int $credentialsId, array $codes, X509GeneratorInterface $x509Generator = null) + { + $client = $this->setupClientV3($credentialsId, $x509Generator, $codes['ZSR']['fake']); + + $this->assertExceptionCode($codes['ZSR']['code']); + $zsr = $client->ZSR(null, new DateTime('2020-03-21'), new DateTime('2020-04-21')); + + $responseHandler = $client->getResponseHandler(); + $code = $responseHandler->retrieveH00XReturnCode($zsr->getTransaction()->getLastSegment()->getResponse()); + $reportText = $responseHandler->retrieveH00XReportText($zsr->getTransaction()->getLastSegment()->getResponse()); + $this->assertResponseOk($code, $reportText); + + $code = $responseHandler->retrieveH00XReturnCode($zsr->getTransaction()->getReceipt()); + $reportText = $responseHandler->retrieveH00XReportText($zsr->getTransaction()->getReceipt()); + + $this->assertResponseDone($code, $reportText); + } + /** * @dataProvider serversDataProvider * @@ -472,7 +615,6 @@ public function testHVZ(int $credentialsId, array $codes, X509GeneratorInterface $this->assertResponseDone($code, $reportText); } - /** * @dataProvider serversDataProvider * @@ -601,161 +743,6 @@ public function testHVT(int $credentialsId, array $codes, X509GeneratorInterface $this->assertResponseDone($code, $reportText); } - /** - * @dataProvider serversDataProvider - * - * @group PTK - * @group V3 - * @group PTK-V3 - * - * @param int $credentialsId - * @param array $codes - * @param X509GeneratorInterface|null $x509Generator - * - * @covers - */ - public function testPTK(int $credentialsId, array $codes, X509GeneratorInterface $x509Generator = null) - { - $client = $this->setupClientV3($credentialsId, $x509Generator, $codes['PTK']['fake']); - - $this->assertExceptionCode($codes['PTK']['code']); - $ptk = $client->PTK(); - - $responseHandler = $client->getResponseHandler(); - $code = $responseHandler->retrieveH00XReturnCode($ptk->getTransaction()->getLastSegment()->getResponse()); - $reportText = $responseHandler->retrieveH00XReportText($ptk->getTransaction()->getLastSegment()->getResponse()); - $this->assertResponseOk($code, $reportText); - - $code = $responseHandler->retrieveH00XReturnCode($ptk->getTransaction()->getReceipt()); - $reportText = $responseHandler->retrieveH00XReportText($ptk->getTransaction()->getReceipt()); - - $this->assertResponseDone($code, $reportText); - } - - /** - * @dataProvider serversDataProvider - * - * @group Z54 - * @group V3 - * @group Z54-V3 - * - * @param int $credentialsId - * @param array $codes - * @param X509GeneratorInterface|null $x509Generator - * - * @covers - */ - public function testZ54(int $credentialsId, array $codes, X509GeneratorInterface $x509Generator = null) - { - $client = $this->setupClientV3($credentialsId, $x509Generator, $codes['Z54']['fake']); - - $this->assertExceptionCode($codes['Z54']['code']); - $z54 = $client->Z54(); - - $responseHandler = $client->getResponseHandler(); - $code = $responseHandler->retrieveH00XReturnCode($z54->getTransaction()->getLastSegment()->getResponse()); - $reportText = $responseHandler->retrieveH00XReportText($z54->getTransaction()->getLastSegment()->getResponse()); - $this->assertResponseOk($code, $reportText); - - $code = $responseHandler->retrieveH00XReturnCode($z54->getTransaction()->getReceipt()); - $reportText = $responseHandler->retrieveH00XReportText($z54->getTransaction()->getReceipt()); - - $this->assertResponseDone($code, $reportText); - } - - /** - * @dataProvider serversDataProvider - * - * @group ZSR - * @group V3 - * @group ZSR-V3 - * - * @param int $credentialsId - * @param array $codes - * @param X509GeneratorInterface|null $x509Generator - * - * @covers - */ - public function testZSR(int $credentialsId, array $codes, X509GeneratorInterface $x509Generator = null) - { - $client = $this->setupClientV3($credentialsId, $x509Generator, $codes['ZSR']['fake']); - - $this->assertExceptionCode($codes['ZSR']['code']); - $zsr = $client->ZSR(); - - $responseHandler = $client->getResponseHandler(); - $code = $responseHandler->retrieveH00XReturnCode($zsr->getTransaction()->getLastSegment()->getResponse()); - $reportText = $responseHandler->retrieveH00XReportText($zsr->getTransaction()->getLastSegment()->getResponse()); - $this->assertResponseOk($code, $reportText); - - $code = $responseHandler->retrieveH00XReturnCode($zsr->getTransaction()->getReceipt()); - $reportText = $responseHandler->retrieveH00XReportText($zsr->getTransaction()->getReceipt()); - - $this->assertResponseDone($code, $reportText); - } - - /** - * @dataProvider serversDataProvider - * - * @group HPD - * @group V3 - * @group HPD-V3 - * - * @param int $credentialsId - * @param array $codes - * @param X509GeneratorInterface|null $x509Generator - * - * @covers - */ - public function testHPD(int $credentialsId, array $codes, X509GeneratorInterface $x509Generator = null) - { - $client = $this->setupClientV3($credentialsId, $x509Generator, $codes['HPD']['fake']); - - $this->assertExceptionCode($codes['HPD']['code']); - $hpd = $client->HPD(); - - $responseHandler = $client->getResponseHandler(); - $code = $responseHandler->retrieveH00XReturnCode($hpd->getTransaction()->getLastSegment()->getResponse()); - $reportText = $responseHandler->retrieveH00XReportText($hpd->getTransaction()->getLastSegment()->getResponse()); - $this->assertResponseOk($code, $reportText); - - $code = $responseHandler->retrieveH00XReturnCode($hpd->getTransaction()->getReceipt()); - $reportText = $responseHandler->retrieveH00XReportText($hpd->getTransaction()->getReceipt()); - - $this->assertResponseDone($code, $reportText); - } - - /** - * @dataProvider serversDataProvider - * - * @group HAA - * @group V3 - * @group HAA-V3 - * - * @param int $credentialsId - * @param array $codes - * @param X509GeneratorInterface|null $x509Generator - * - * @covers - */ - public function testHAA(int $credentialsId, array $codes, X509GeneratorInterface $x509Generator = null) - { - $client = $this->setupClientV3($credentialsId, $x509Generator, $codes['HAA']['fake']); - - $this->assertExceptionCode($codes['HAA']['code']); - $haa = $client->HAA(); - - $responseHandler = $client->getResponseHandler(); - $code = $responseHandler->retrieveH00XReturnCode($haa->getTransaction()->getLastSegment()->getResponse()); - $reportText = $responseHandler->retrieveH00XReportText($haa->getTransaction()->getLastSegment()->getResponse()); - $this->assertResponseOk($code, $reportText); - - $code = $responseHandler->retrieveH00XReturnCode($haa->getTransaction()->getReceipt()); - $reportText = $responseHandler->retrieveH00XReportText($haa->getTransaction()->getReceipt()); - - $this->assertResponseDone($code, $reportText); - } - /** * Provider for servers. */