Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Objects/MemOrderApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class MemOrderApp
{
//Номер документа (поле 3).
protected string $DocNo;
protected ?string $DocNo = null;
//Дата составления (поле 4).
protected string $DocDate;
//Свободное поле (поле 5)
Expand Down Expand Up @@ -39,7 +39,7 @@ class MemOrderApp
//Свободное поле (поле 20)
protected ?string $SpareField20 = null;

public function getDocNo(): string
public function getDocNo(): ?string
{
return $this->DocNo;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Objects/PaymentDataType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class PaymentDataType
{
//Номер документа (поле 3).
protected string $DocNo;
protected ?string $DocNo = null;
//Дата составления (поле 4).
protected string $DocDate;
//Сумма документа (поле 7).
Expand All @@ -31,7 +31,7 @@ class PaymentDataType
//Назначение платежа (поле 24).
protected ?string $Purpose = null;

public function getDocNo(): string
public function getDocNo(): ?string
{
return $this->DocNo;
}
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions tests/Fixture/xml/statement_empty_doc_no.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Statement xmlns="http://directbank.1c.ru/XMLSchema" id="11111111-2222-3333-4444-555555555555" formatVersion="2.2.2" creationDate="2024-01-02T01:50:16.556+03:00">
<Sender bic="044525888" name="АО &quot;БАНК&quot;"/><Recipient id="40702810500000000001" name="ООО &quot;КЛИЕНТ&quot;" inn="7700000001" kpp="770001001"/>
<Data><StatementType>1</StatementType><DateFrom>2024-01-01T00:00:00Z</DateFrom><DateTo>2024-01-02T00:00:00Z</DateTo><Account>40702810500000000001</Account><Bank><BIC>044525888</BIC><Name>АО "БАНК"</Name><CorrespAcc>30101810400000000888</CorrespAcc></Bank><OpeningBalance>0</OpeningBalance><TotalDebits>0</TotalDebits><TotalCredits>100.50</TotalCredits><ClosingBalance>100.50</ClosingBalance>
<OperationInfo><PayDoc id="SBP0000000000001" docKind="10"><PayDocRu><DocNo/><DocDate>2024-01-02</DocDate><Sum>100.50</Sum><Payer><Name>АО "БАНК"</Name><INN>7700000002</INN><Account>30233810000000000001</Account><Bank><BIC>044525888</BIC><Name>АО "БАНК" г Москва</Name><CorrespAcc>30101810400000000888</CorrespAcc></Bank></Payer><Payee><Name>ООО "КЛИЕНТ"</Name><INN>7700000001</INN><KPP>770001001</KPP><Account>40702810500000000001</Account><Bank><BIC>044525888</BIC><Name>АО "БАНК"</Name></Bank></Payee><TransitionKind>01</TransitionKind><Priority>5</Priority><Purpose>C000000000000001 Возм. по согл. в СБП № 7700000001 от 2022-01-01</Purpose></PayDocRu></PayDoc><DC>2</DC><Date>2024-01-02</Date></OperationInfo>
</Data></Statement>
49 changes: 49 additions & 0 deletions tests/Objects/StatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,55 @@ public function testCheckWithSingleDetails()
}
}

public function payDocWithoutDocNoProvider(): array
{
return [
'no element' => [''],
'empty element' => ['<DocNo/>'],
];
}

/**
* Банки присылают в выписке документы без номера, хотя по XSD он обязателен
*
* @dataProvider payDocWithoutDocNoProvider
*/
public function testPayDocWithoutDocNo(string $docNo)
{
$xml = str_replace(
'<PayDocRu><DocNo>1</DocNo>',
'<PayDocRu>' . $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 [
Expand Down
Loading