diff --git a/src/PayerFinancialAccount.php b/src/PayerFinancialAccount.php new file mode 100644 index 0000000..3042bfb --- /dev/null +++ b/src/PayerFinancialAccount.php @@ -0,0 +1,43 @@ +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; + } +} diff --git a/src/PaymentMandate.php b/src/PaymentMandate.php index 8c1fd7d..441d5ff 100644 --- a/src/PaymentMandate.php +++ b/src/PaymentMandate.php @@ -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); } }