|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace EbicsApi\Ebics\Orders; |
| 4 | + |
| 5 | +use DateTimeInterface; |
| 6 | +use EbicsApi\Ebics\Builders\Request\HeaderBuilder; |
| 7 | +use EbicsApi\Ebics\Builders\Request\MutableBuilder; |
| 8 | +use EbicsApi\Ebics\Builders\Request\OrderDetailsBuilder; |
| 9 | +use EbicsApi\Ebics\Builders\Request\RootBuilder; |
| 10 | +use EbicsApi\Ebics\Builders\Request\StaticBuilder; |
| 11 | +use EbicsApi\Ebics\Contexts\RequestContext; |
| 12 | +use EbicsApi\Ebics\Contracts\EbicsClientInterface; |
| 13 | +use EbicsApi\Ebics\Exceptions\MethodNotImplemented; |
| 14 | +use EbicsApi\Ebics\Models\Http\Request; |
| 15 | +use EbicsApi\Ebics\Models\Keyring; |
| 16 | +use EbicsApi\Ebics\Models\Order\DownloadOrder; |
| 17 | + |
| 18 | +/** |
| 19 | + * Download transaction status (XML). |
| 20 | + * |
| 21 | + * @license http://www.opensource.org/licenses/mit-license.html MIT License |
| 22 | + * @author Andrew Svirin |
| 23 | + */ |
| 24 | +final class HAC extends DownloadOrder |
| 25 | +{ |
| 26 | + private ?DateTimeInterface $startDateTime; |
| 27 | + |
| 28 | + private ?DateTimeInterface $endDateTime; |
| 29 | + |
| 30 | + public function __construct( |
| 31 | + ?DateTimeInterface $startDateTime = null, |
| 32 | + ?DateTimeInterface $endDateTime = null, |
| 33 | + ?RequestContext $context = null |
| 34 | + ) { |
| 35 | + $this->startDateTime = $startDateTime; |
| 36 | + $this->endDateTime = $endDateTime; |
| 37 | + $this->context = $context; |
| 38 | + } |
| 39 | + |
| 40 | + public function prepareContext(): void |
| 41 | + { |
| 42 | + parent::prepareContext(); |
| 43 | + $this->context |
| 44 | + ->setStartDateTime($this->startDateTime) |
| 45 | + ->setEndDateTime($this->endDateTime); |
| 46 | + } |
| 47 | + |
| 48 | + public function createRequest(): Request |
| 49 | + { |
| 50 | + return $this->buildRequest(); |
| 51 | + } |
| 52 | + |
| 53 | + public function getParserFormat(): string |
| 54 | + { |
| 55 | + return EbicsClientInterface::FILE_PARSER_FORMAT_TEXT; |
| 56 | + } |
| 57 | + |
| 58 | + private function buildRequest(): Request |
| 59 | + { |
| 60 | + $this->context |
| 61 | + ->setOrderType('HAC'); |
| 62 | + |
| 63 | + return $this |
| 64 | + ->requestFactory->createRequestBuilderInstance() |
| 65 | + ->addContainerSecured(function (RootBuilder $builder) { |
| 66 | + $builder->addHeader(function (HeaderBuilder $builder) { |
| 67 | + $builder->addStatic(function (StaticBuilder $builder) { |
| 68 | + $builder |
| 69 | + ->addHostId($this->context->getBank()->getHostId()) |
| 70 | + ->addRandomNonce() |
| 71 | + ->addTimestamp($this->context->getDateTime()) |
| 72 | + ->addPartnerId($this->context->getUser()->getPartnerId()) |
| 73 | + ->addUserId($this->context->getUser()->getUserId()) |
| 74 | + ->addProduct($this->context->getProduct(), $this->context->getLanguage()) |
| 75 | + ->addOrderDetails(function (OrderDetailsBuilder $orderDetailsBuilder) { |
| 76 | + $this->requestFactory |
| 77 | + ->addOrderType( |
| 78 | + $orderDetailsBuilder, |
| 79 | + $this->context->getOrderType(), |
| 80 | + $this->context->getWithES() ? |
| 81 | + OrderDetailsBuilder::ORDER_ATTRIBUTE_OZHNN : |
| 82 | + OrderDetailsBuilder::ORDER_ATTRIBUTE_DZHNN |
| 83 | + ) |
| 84 | + ->addStandardOrderParams( |
| 85 | + $this->context->getStartDateTime(), |
| 86 | + $this->context->getEndDateTime() |
| 87 | + ); |
| 88 | + }) |
| 89 | + ->addBankPubKeyDigests( |
| 90 | + $this->context->getKeyring()->getBankSignatureXVersion(), |
| 91 | + $this->requestFactory->signDigest($this->context->getKeyring()->getBankSignatureX()), |
| 92 | + $this->context->getKeyring()->getBankSignatureEVersion(), |
| 93 | + $this->requestFactory->signDigest($this->context->getKeyring()->getBankSignatureE()) |
| 94 | + ) |
| 95 | + ->addSecurityMedium(StaticBuilder::SECURITY_MEDIUM_0000); |
| 96 | + })->addMutable(function (MutableBuilder $builder) { |
| 97 | + $builder |
| 98 | + ->addTransactionPhase(MutableBuilder::PHASE_INITIALIZATION); |
| 99 | + }); |
| 100 | + })->addBody(); |
| 101 | + }) |
| 102 | + ->popInstance(); |
| 103 | + } |
| 104 | +} |
0 commit comments