diff --git a/src/Objects/MemOrderApp.php b/src/Objects/MemOrderApp.php index c01d8f4..beadda5 100644 --- a/src/Objects/MemOrderApp.php +++ b/src/Objects/MemOrderApp.php @@ -9,7 +9,7 @@ class MemOrderApp { //Номер документа (поле 3). - protected string $DocNo; + protected ?string $DocNo = null; //Дата составления (поле 4). protected string $DocDate; //Свободное поле (поле 5) @@ -39,7 +39,7 @@ class MemOrderApp //Свободное поле (поле 20) protected ?string $SpareField20 = null; - public function getDocNo(): string + public function getDocNo(): ?string { return $this->DocNo; } diff --git a/src/Objects/PaymentDataType.php b/src/Objects/PaymentDataType.php index 3abfdf0..181642d 100644 --- a/src/Objects/PaymentDataType.php +++ b/src/Objects/PaymentDataType.php @@ -7,7 +7,7 @@ class PaymentDataType { //Номер документа (поле 3). - protected string $DocNo; + protected ?string $DocNo = null; //Дата составления (поле 4). protected string $DocDate; //Сумма документа (поле 7). @@ -31,7 +31,7 @@ class PaymentDataType //Назначение платежа (поле 24). protected ?string $Purpose = null; - public function getDocNo(): string + public function getDocNo(): ?string { return $this->DocNo; } @@ -86,7 +86,7 @@ public function getPurpose(): ?string return $this->Purpose; } - public function setDocNo(string $docNo): static + public function setDocNo(?string $docNo): static { $this->DocNo = $docNo; return $this; diff --git a/tests/Fixture/xml/statement_empty_doc_no.xml b/tests/Fixture/xml/statement_empty_doc_no.xml new file mode 100644 index 0000000..082350b --- /dev/null +++ b/tests/Fixture/xml/statement_empty_doc_no.xml @@ -0,0 +1,6 @@ + + + +12024-01-01T00:00:00Z2024-01-02T00:00:00Z40702810500000000001044525888АО "БАНК"3010181040000000088800100.50100.50 +2024-01-02100.50АО "БАНК"770000000230233810000000000001044525888АО "БАНК" г Москва30101810400000000888ООО "КЛИЕНТ"770000000177000100140702810500000000001044525888АО "БАНК"015C000000000000001 Возм. по согл. в СБП № 7700000001 от 2022-01-0122024-01-02 + diff --git a/tests/Objects/StatementTest.php b/tests/Objects/StatementTest.php index 6853984..ccd2474 100644 --- a/tests/Objects/StatementTest.php +++ b/tests/Objects/StatementTest.php @@ -181,6 +181,55 @@ public function testCheckWithSingleDetails() } } + public function payDocWithoutDocNoProvider(): array + { + return [ + 'no element' => [''], + 'empty element' => [''], + ]; + } + + /** + * Банки присылают в выписке документы без номера, хотя по XSD он обязателен + * + * @dataProvider payDocWithoutDocNoProvider + */ + public function testPayDocWithoutDocNo(string $docNo) + { + $xml = str_replace( + '1', + '' . $docNo, + file_get_contents(__DIR__ . '/../Fixture/xml/statement_all_doc_kinds.xml') + ); + + $statement = new Statement(); + $statement->mapFromXml($xml); + + $payDocRu = $statement->getData()->getOperationInfo()[0]->getPayDoc()->getPayDocRu(); + $this->assertNull($payDocRu->getDocNo()); + $this->assertSame(1.5, $payDocRu->getSum()); + } + + /** + * Возмещение по СБП от банка приходит с пустым номером документа, + * фрагмент реальной выписки с заменёнными реквизитами + */ + public function testSbpRefundWithEmptyDocNo() + { + $xml = file_get_contents(__DIR__ . '/../Fixture/xml/statement_empty_doc_no.xml'); + + $this->assertValid($xml); + + $statement = new Statement(); + $statement->mapFromXml($xml); + + $payDocRu = $statement->getData()->getOperationInfo()[0]->getPayDoc()->getPayDocRu(); + $this->assertNull($payDocRu->getDocNo()); + $this->assertSame('2024-01-02', $payDocRu->getDocDate()); + $this->assertSame(100.5, $payDocRu->getSum()); + $this->assertSame('7700000002', $payDocRu->getPayer()->getINN()); + } + public function roundTripProvider(): array { return [