Skip to content

Commit

Permalink
Updated BTD method by ContainerType attr.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-svirin committed May 22, 2024
1 parent b9222fa commit a735e38
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Remove UTF-8 encoding for content.
* Support EBICS TS mode.
* Add 'xml_files' parser for order data.
* Updated BTD method signature.
* Added support for EBICS version 2.4.

## 2.1
Expand Down
4 changes: 2 additions & 2 deletions src/Builders/Request/OrderDetailsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace AndrewSvirin\Ebics\Builders\Request;

use AndrewSvirin\Ebics\Contexts\BTFContext;
use AndrewSvirin\Ebics\Contexts\BTDContext;
use AndrewSvirin\Ebics\Contexts\BTUContext;
use AndrewSvirin\Ebics\Contexts\FULContext;
use AndrewSvirin\Ebics\Contexts\HVDContext;
Expand Down Expand Up @@ -167,7 +167,7 @@ abstract public function addHVDOrderParams(HVDContext $hvdContext): OrderDetails
abstract public function addHVTOrderParams(HVTContext $hvtContext): OrderDetailsBuilder;

abstract public function addBTDOrderParams(
BTFContext $btfContext,
BTDContext $btfContext,
?DateTimeInterface $startDateTime = null,
?DateTimeInterface $endDateTime = null
): OrderDetailsBuilder;
Expand Down
4 changes: 2 additions & 2 deletions src/Builders/Request/OrderDetailsBuilderV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace AndrewSvirin\Ebics\Builders\Request;

use AndrewSvirin\Ebics\Contexts\BTFContext;
use AndrewSvirin\Ebics\Contexts\BTDContext;
use AndrewSvirin\Ebics\Contexts\BTUContext;
use AndrewSvirin\Ebics\Contexts\HVDContext;
use AndrewSvirin\Ebics\Contexts\HVEContext;
Expand Down Expand Up @@ -42,7 +42,7 @@ public function addOrderAttribute(string $orderAttribute): OrderDetailsBuilder
}

public function addBTDOrderParams(
BTFContext $btfContext,
BTDContext $btfContext,
?DateTimeInterface $startDateTime = null,
?DateTimeInterface $endDateTime = null
): OrderDetailsBuilder {
Expand Down
11 changes: 9 additions & 2 deletions src/Builders/Request/OrderDetailsBuilderV3.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace AndrewSvirin\Ebics\Builders\Request;

use AndrewSvirin\Ebics\Contexts\BTFContext;
use AndrewSvirin\Ebics\Contexts\BTDContext;
use AndrewSvirin\Ebics\Contexts\BTUContext;
use AndrewSvirin\Ebics\Contexts\HVDContext;
use AndrewSvirin\Ebics\Contexts\HVEContext;
Expand Down Expand Up @@ -39,7 +39,7 @@ public function addOrderAttribute(
}

public function addBTDOrderParams(
BTFContext $btfContext,
BTDContext $btfContext,
?DateTimeInterface $startDateTime = null,
?DateTimeInterface $endDateTime = null
): OrderDetailsBuilder {
Expand Down Expand Up @@ -77,6 +77,13 @@ public function addBTDOrderParams(
$xmlService->appendChild($xmlContainerFlag);
}

if (null !== $btfContext->getContainerType()) {
// Add optional Container to Service.
$xmlContainer = $this->dom->createElement('Container');
$xmlContainer->setAttribute('containerType', $btfContext->getContainerType());
$xmlService->appendChild($xmlContainer);
}

// Add MsgName to Service.
$xmlMsgName = $this->dom->createElement('MsgName');
$xmlMsgName->nodeValue = $btfContext->getMsgName();
Expand Down
13 changes: 13 additions & 0 deletions src/Contexts/BTDContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,17 @@
*/
final class BTDContext extends BTFContext
{
private ?string $containerType = null;

public function setContainerType(string $containerType): BTDContext
{
$this->containerType = $containerType;

return $this;
}

public function getContainerType(): ?string
{
return $this->containerType;
}
}
12 changes: 6 additions & 6 deletions src/Contexts/RequestContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ final class RequestContext
private int $numSegments;
private string $orderData;
private SignatureDataInterface $signatureData;
private BTFContext $btfContext;
private HVEContext $hveContext;
private string $dataDigest;
private string $signatureVersion;
private BTDContext $btdContext;
private BTUContext $btuContext;
private HVEContext $hveContext;
private HVDContext $hvdContext;
private HVTContext $hvtContext;
private FULContext $fulContext;
Expand Down Expand Up @@ -233,16 +233,16 @@ public function getSignatureData(): SignatureDataInterface
return $this->signatureData;
}

public function setBTFContext(BTFContext $btfContext): RequestContext
public function setBTDContext(BTDContext $btdContext): RequestContext
{
$this->btfContext = $btfContext;
$this->btdContext = $btdContext;

return $this;
}

public function getBTFContext(): BTFContext
public function getBTDContext(): BTDContext
{
return $this->btfContext;
return $this->btdContext;
}

public function setHVEContext(HVEContext $hveContext): RequestContext
Expand Down
6 changes: 3 additions & 3 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\Contexts\BTFContext;
use AndrewSvirin\Ebics\Contexts\BTDContext;
use AndrewSvirin\Ebics\Contexts\BTUContext;
use AndrewSvirin\Ebics\Contexts\FULContext;
use AndrewSvirin\Ebics\Contexts\HVDContext;
Expand Down Expand Up @@ -92,15 +92,15 @@ public function HPB(DateTimeInterface $dateTime = null): InitializationOrderResu
/**
* Download request files of any BTF structure.
*
* @param BTFContext $btfContext
* @param BTDContext $btfContext
* @param DateTimeInterface|null $dateTime
* @param DateTimeInterface|null $startDateTime
* @param DateTimeInterface|null $endDateTime
*
* @return DownloadOrderResult
*/
public function BTD(
BTFContext $btfContext,
BTDContext $btfContext,
DateTimeInterface $dateTime = null,
DateTimeInterface $startDateTime = null,
DateTimeInterface $endDateTime = null
Expand Down
4 changes: 2 additions & 2 deletions src/EbicsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace AndrewSvirin\Ebics;

use AndrewSvirin\Ebics\Contexts\BTFContext;
use AndrewSvirin\Ebics\Contexts\BTDContext;
use AndrewSvirin\Ebics\Contexts\BTUContext;
use AndrewSvirin\Ebics\Contexts\FULContext;
use AndrewSvirin\Ebics\Contexts\HVDContext;
Expand Down Expand Up @@ -253,7 +253,7 @@ function () use ($dateTime) {
* @throws Exceptions\EbicsException
*/
public function BTD(
BTFContext $btfContext,
BTDContext $btfContext,
DateTimeInterface $dateTime = null,
DateTimeInterface $startDateTime = null,
DateTimeInterface $endDateTime = null
Expand Down
4 changes: 2 additions & 2 deletions src/Factories/RequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use AndrewSvirin\Ebics\Builders\Request\StaticBuilder;
use AndrewSvirin\Ebics\Builders\Request\TransferReceiptBuilder;
use AndrewSvirin\Ebics\Builders\Request\XmlBuilder;
use AndrewSvirin\Ebics\Contexts\BTFContext;
use AndrewSvirin\Ebics\Contexts\BTDContext;
use AndrewSvirin\Ebics\Contexts\BTUContext;
use AndrewSvirin\Ebics\Contexts\FULContext;
use AndrewSvirin\Ebics\Contexts\HVDContext;
Expand Down Expand Up @@ -685,7 +685,7 @@ public function createHAA(

abstract public function createBTD(
DateTimeInterface $dateTime,
BTFContext $btfContext,
BTDContext $btdContext,
DateTimeInterface $startDateTime = null,
DateTimeInterface $endDateTime = null,
int $segmentNumber = null,
Expand Down
4 changes: 2 additions & 2 deletions src/Factories/RequestFactoryV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace AndrewSvirin\Ebics\Factories;

use AndrewSvirin\Ebics\Contexts\BTFContext;
use AndrewSvirin\Ebics\Contexts\BTDContext;
use AndrewSvirin\Ebics\Contexts\BTUContext;
use AndrewSvirin\Ebics\Models\Http\Request;
use AndrewSvirin\Ebics\Models\UploadTransaction;
Expand All @@ -19,7 +19,7 @@ abstract class RequestFactoryV2 extends RequestFactory
{
public function createBTD(
DateTimeInterface $dateTime,
BTFContext $btfContext,
BTDContext $btdContext,
DateTimeInterface $startDateTime = null,
DateTimeInterface $endDateTime = null,
int $segmentNumber = null,
Expand Down
12 changes: 6 additions & 6 deletions src/Factories/RequestFactoryV3.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use AndrewSvirin\Ebics\Builders\Request\XmlBuilder;
use AndrewSvirin\Ebics\Builders\Request\XmlBuilderV3;
use AndrewSvirin\Ebics\Contexts\BTDContext;
use AndrewSvirin\Ebics\Contexts\BTFContext;
use AndrewSvirin\Ebics\Contexts\BTUContext;
use AndrewSvirin\Ebics\Contexts\RequestContext;
use AndrewSvirin\Ebics\Exceptions\EbicsException;
Expand Down Expand Up @@ -65,7 +64,7 @@ protected function addOrderType(OrderDetailsBuilder $orderDetailsBuilder, string
*/
public function createBTD(
DateTimeInterface $dateTime,
BTFContext $btfContext,
BTDContext $btdContext,
DateTimeInterface $startDateTime = null,
DateTimeInterface $endDateTime = null,
int $segmentNumber = null,
Expand All @@ -76,7 +75,7 @@ public function createBTD(
->setUser($this->user)
->setKeyring($this->keyring)
->setDateTime($dateTime)
->setBTFContext($btfContext)
->setBTDContext($btdContext)
->setStartDateTime($startDateTime)
->setEndDateTime($endDateTime)
->setSegmentNumber($segmentNumber)
Expand All @@ -98,7 +97,7 @@ public function createBTD(
$this
->addOrderType($orderDetailsBuilder, 'BTD')
->addBTDOrderParams(
$context->getBTFContext(),
$context->getBTDContext(),
$context->getStartDateTime(),
$context->getEndDateTime()
);
Expand Down Expand Up @@ -290,7 +289,8 @@ public function createZ54(
$btfContext->setScope('CH');
$btfContext->setMsgName('camt.054');
$btfContext->setMsgNameVersion('04');
$btfContext->setContainerFlag('ZIP');
$btfContext->setContainerType('ZIP');
$btfContext->setServiceOption('XQRR');

return $this->createBTD($dateTime, $btfContext, $startDateTime, $endDateTime, $segmentNumber, $isLastSegment);
}
Expand All @@ -309,7 +309,7 @@ public function createZSR(
$btfContext->setServiceName('PSR');
$btfContext->setScope('BIL');
$btfContext->setMsgName('pain.002');
$btfContext->setContainerFlag('ZIP');
$btfContext->setContainerType('ZIP');

return $this->createBTD($dateTime, $btfContext, $startDateTime, $endDateTime, $segmentNumber, $isLastSegment);
}
Expand Down
26 changes: 21 additions & 5 deletions tests/EbicsClientV3Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,25 @@ public function testBTD(int $credentialsId, array $codes, X509GeneratorInterface
{
$client = $this->setupClientV3($credentialsId, $x509Generator, $codes['BTD']['fake']);

/**
* Method HKD.
* <OrderInfo>
* <AdminOrderType>BTD</AdminOrderType>
* <Service>
* <ServiceName>PSR</ServiceName>
* <Scope>CH</Scope>
* <Container containerType="ZIP"/>
* <MsgName version="03">pain.002</MsgName>
* </Service>
* <Description>CH Payment Status Report</Description>
* </OrderInfo>
*/
$context = new BTDContext();
$context->setServiceName('IZV');
$context->setMsgName('pain.001');
$context->setServiceName('PSR');
$context->setMsgName('pain.002');
$context->setMsgNameVersion('03');
$context->setScope('CH');
$context->setContainerType('ZIP');

$this->assertExceptionCode($codes['BTD']['code']);
$btd = $client->BTD($context);
Expand Down Expand Up @@ -756,7 +772,7 @@ public function serversDataProvider()
'HPB' => ['code' => null, 'fake' => false],
'HKD' => ['code' => null, 'fake' => false],
'CIP' => ['code' => '061099', 'fake' => false],
'BTD' => ['code' => '091005', 'fake' => false],
'BTD' => ['code' => '090005', 'fake' => false],
'HVU' => ['code' => '090003', 'fake' => false],
'HVZ' => ['code' => '090003', 'fake' => false],
'HVE' => ['code' => '090003', 'fake' => false],
Expand All @@ -782,14 +798,14 @@ public function serversDataProvider()
'HPB' => ['code' => null, 'fake' => false],
'HKD' => ['code' => null, 'fake' => false],
'CIP' => ['code' => '061099', 'fake' => false],
'BTD' => ['code' => '091005', 'fake' => false],
'BTD' => ['code' => '090005', 'fake' => false],
'HVU' => ['code' => '090003', 'fake' => false],
'HVZ' => ['code' => '090003', 'fake' => false],
'HVE' => ['code' => '090003', 'fake' => false],
'HVD' => ['code' => '090003', 'fake' => false],
'HVT' => ['code' => '090003', 'fake' => false],
'PTK' => ['code' => null, 'fake' => false],
'Z54' => ['code' => '091005', 'fake' => false],
'Z54' => ['code' => '090005', 'fake' => false],
'ZSR' => ['code' => '091005', 'fake' => false],
'BTU' => ['code' => null, 'fake' => false],
'XE3' => ['code' => null, 'fake' => false],
Expand Down

0 comments on commit a735e38

Please sign in to comment.