Skip to content
Open
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
43 changes: 43 additions & 0 deletions src/PayerFinancialAccount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace NumNum\UBL;

use Sabre\Xml\Reader;
use Sabre\Xml\Writer;
use Sabre\Xml\XmlDeserializable;
use Sabre\Xml\XmlSerializable;

use function Sabre\Xml\Deserializer\keyValue;

class PayerFinancialAccount implements XmlSerializable, XmlDeserializable
{
public $xmlTagName = 'PayerFinancialAccount';
private $id;

public static function xmlDeserialize(Reader $reader)
{
$keyValues = keyValue($reader);

return (new static())
->setId($keyValues[Schema::CBC . 'ID'] ?? null);
}

public function xmlSerialize(Writer $writer): void
{
$writer->write([
Schema::CBC . 'ID' => $this->id,
]);
}

public function getId(): string
{
return $this->id;
}

public function setId(string $id): self
{
$this->id = $id;

return $this;
}
}
59 changes: 20 additions & 39 deletions src/PaymentMandate.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,71 +11,52 @@

class PaymentMandate implements XmlSerializable, XmlDeserializable
{
public $xmlTagName = 'PaymentMandate';

private $id;
private $payeeFinancialAccount;
private $payerFinancialAccount;

/**
* @return string
*/
public function getId(): ?string
{
return $this->id;
}

/**
* @param string $id
* @return static
*/
public function setId(?string $id)
public function setId(?string $id): self
{
$this->id = $id;
return $this;
}

/**
* @return PayeeFinancialAccount
*/
public function getPayeeFinancialAccount(): ?PayeeFinancialAccount
public function xmlSerialize(Writer $writer): void
{
return $this->payeeFinancialAccount;
if ($this->id !== null) {
$writer->write([
Schema::CBC . 'ID' => $this->id,
]);
}

if ($this->getPayerFinancialAccount() !== null) {
$writer->write([
Schema::CAC . $this->payerFinancialAccount->xmlTagName => $this->getPayerFinancialAccount(),
]);
}
}

/**
* @param PayeeFinancialAccount $payeeFinancialAccount
* @return static
*/
public function setPayeeFinancialAccount(?PayeeFinancialAccount $payeeFinancialAccount)
public function getPayerFinancialAccount(): ?PayerFinancialAccount
{
$this->payeeFinancialAccount = $payeeFinancialAccount;
return $this;
return $this->payerFinancialAccount;
}

public function xmlSerialize(Writer $writer): void
public function setPayerFinancialAccount(?PayerFinancialAccount $payerFinancialAccount): self
{
$writer->write([
Schema::CBC . 'ID' => $this->id
]);

if ($this->getPayeeFinancialAccount() !== null) {
$writer->write([
Schema::CAC . 'PayeeFinancialAccount' => $this->getPayeeFinancialAccount()
]);
}
$this->payerFinancialAccount = $payerFinancialAccount;
return $this;
}

/**
* The xmlDeserialize method is called during xml reading.
* @param Reader $reader
* @return static
*/
public static function xmlDeserialize(Reader $reader)
{
$keyValues = keyValue($reader);

return (new static())
->setId($keyValues[Schema::CBC . 'ID'] ?? null)
->setPayeeFinancialAccount($keyValues[Schema::CAC . 'PayeeFinancialAccount'] ?? null);
->setPayerFinancialAccount($keyValues[Schema::CAC . 'PayerFinancialAccount'] ?? null);
}
}
Loading