Skip to content

Commit

Permalink
Added ability to add TaxDetail into Tax node (having multiple differe…
Browse files Browse the repository at this point in the history
…nt tax rates)
  • Loading branch information
mathielen committed Sep 17, 2024
1 parent 9bc55a6 commit 6e81247
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
18 changes: 15 additions & 3 deletions src/CXml/Builder/OrderRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use CXml\Model\ShipTo;
use CXml\Model\SupplierOrderInfo;
use CXml\Model\Tax;
use CXml\Model\TaxDetail;
use CXml\Model\TransportInformation;
use DateTimeInterface;
use LogicException;
Expand Down Expand Up @@ -174,14 +175,25 @@ public function shipping(int $costs, string $description): self
return $this;
}

public function tax(int $costs, string $description): self
public function tax(int $costs, string $description, array $taxDetails = []): self
{
$this->tax = new Tax(
$this->currency,
$costs,
new MultilanguageString($description, null, $this->language),
);

foreach ($taxDetails as $taxDetail) {
$this->tax->addTaxDetail(
new TaxDetail(
$taxDetail['category'],
new MoneyWrapper($this->currency, $taxDetail['amount']),
$taxDetail['rate'],
$taxDetail['type'],
),
);
}

return $this;
}

Expand Down Expand Up @@ -256,9 +268,9 @@ public function addContact(string $name, string $email, string $role = Contact::
return $this;
}

public function addExtrinsic(Extrinsic $extrinsic): self
public function addExtrinsic(string $key, string $value): self
{
$this->extrinsics[] = $extrinsic;
$this->extrinsics[] = new Extrinsic($key, $value);

return $this;
}
Expand Down
14 changes: 13 additions & 1 deletion src/CXml/Model/Tax.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
use JMS\Serializer\Annotation as Serializer;

#[Serializer\AccessorOrder(order: 'custom', custom: ['money', 'description'])]
readonly class Tax
class Tax
{
#[Serializer\SerializedName('Money')]
private Money $money;

/**
* @var TaxDetail[]
*/
#[Serializer\XmlList(entry: 'TaxDetail', inline: true)]
#[Serializer\Type('array<CXml\Model\TaxDetail>')]
private array $taxDetails = [];

public function __construct(
string $currency,
int $value,
Expand All @@ -31,4 +38,9 @@ public function getDescription(): MultilanguageString
{
return $this->description;
}

public function addTaxDetail(TaxDetail $taxDetail): void
{
$this->taxDetails[] = $taxDetail;
}
}
22 changes: 22 additions & 0 deletions src/CXml/Model/TaxDetail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace CXml\Model;

use JMS\Serializer\Annotation as Serializer;

readonly class TaxDetail
{
public function __construct(
#[Serializer\XmlAttribute]
private string $category,
#[Serializer\SerializedName('TaxAmount')]
private MoneyWrapper $taxAmount,
#[Serializer\XmlAttribute]
private ?int $percentageRate = null,
#[Serializer\XmlAttribute]
private ?string $taxRateType = null,
) {
}
}

0 comments on commit 6e81247

Please sign in to comment.