Skip to content

Commit

Permalink
+Payment, PaymentTerm, PaymentService
Browse files Browse the repository at this point in the history
+Custom DTD
  • Loading branch information
mathielen committed Jan 27, 2025
1 parent 1e6069b commit b99c7d6
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/CXml/Model/Classification.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use JMS\Serializer\Annotation as Serializer;

#[Serializer\AccessorOrder(order: 'custom', custom: ['value'])]
readonly class Classification
{
public function __construct(
Expand Down
22 changes: 22 additions & 0 deletions src/CXml/Model/Payment.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;

class Payment
{
public function __construct(
#[Serializer\XmlElement]
#[Serializer\SerializedName('PaymentService')]
private PaymentService $paymentService,
) {
}

public function getPaymentService(): PaymentService
{
return $this->paymentService;
}
}
31 changes: 31 additions & 0 deletions src/CXml/Model/PaymentService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace CXml\Model;

use JMS\Serializer\Annotation as Serializer;

class PaymentService
{
use IdReferencesTrait;
use ExtrinsicsTrait;

public function __construct(
#[Serializer\XmlAttribute]
readonly private string $method,
#[Serializer\XmlAttribute]
readonly private ?string $provider = null,
) {
}

public function getMethod(): string
{
return $this->method;
}

public function getProvider(): ?string
{
return $this->provider;
}
}
18 changes: 18 additions & 0 deletions src/CXml/Model/PaymentTerm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace CXml\Model;

use JMS\Serializer\Annotation as Serializer;

class PaymentTerm
{
use ExtrinsicsTrait;

public function __construct(
#[Serializer\XmlAttribute]
private int $payInNumberOfDays,
) {
}
}
32 changes: 31 additions & 1 deletion src/CXml/Model/Request/OrderRequestHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
use CXml\Model\ExtrinsicsTrait;
use CXml\Model\IdReferencesTrait;
use CXml\Model\MoneyWrapper;
use CXml\Model\Payment;
use CXml\Model\PaymentTerm;
use CXml\Model\Shipping;
use CXml\Model\ShipTo;
use CXml\Model\SupplierOrderInfo;
use CXml\Model\Tax;
use DateTimeInterface;
use JMS\Serializer\Annotation as Serializer;

#[Serializer\AccessorOrder(order: 'custom', custom: ['total', 'shipTo', 'billTo', 'businessPartners', 'shipping', 'tax', 'contacts', 'comments', 'supplierOrderInfo', 'idReferences', 'extrinsics'])]
#[Serializer\AccessorOrder(order: 'custom', custom: ['total', 'shipTo', 'billTo', 'businessPartners', 'shipping', 'tax', 'payment', 'paymentTerm', 'contacts', 'comments', 'supplierOrderInfo', 'idReferences', 'extrinsics'])]
class OrderRequestHeader
{
use CommentsTrait;
Expand All @@ -36,6 +38,14 @@ class OrderRequestHeader
#[Serializer\SerializedName('Tax')]
private ?Tax $tax = null;

#[Serializer\XmlElement]
#[Serializer\SerializedName('Payment')]
private ?Payment $payment = null;

#[Serializer\XmlElement]
#[Serializer\SerializedName('PaymentTerm')]
private ?PaymentTerm $paymentTerm = null;

#[Serializer\SerializedName('SupplierOrderInfo')]
private ?SupplierOrderInfo $supplierOrderInfo = null;

Expand Down Expand Up @@ -168,4 +178,24 @@ public function addBusinessPartner(BusinessPartner $businessPartner): void
{
$this->businessPartners[] = $businessPartner;
}

public function getPayment(): ?Payment
{
return $this->payment;
}

public function setPayment(?Payment $payment): void
{
$this->payment = $payment;
}

public function getPaymentTerm(): ?PaymentTerm
{
return $this->paymentTerm;
}

public function setPaymentTerm(?PaymentTerm $paymentTerm): void
{
$this->paymentTerm = $paymentTerm;
}
}
3 changes: 3 additions & 0 deletions src/CXml/Validation/DtdValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public function validateAgainstDtd(string $xml): void
$old->loadXML($xml);

$validateFiles = ['cXML.dtd', 'Fulfill.dtd', 'Quote.dtd'];
if (file_exists($this->pathToCxmlDtds . '/Custom.dtd')) {
$validateFiles[] = 'Custom.dtd';
}

$this->validateAgainstMultipleDtd($validateFiles, $old);

Expand Down
26 changes: 25 additions & 1 deletion tests/CXmlTest/Handling/HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public static function getEndpointData(): iterable
'QuoteMessage',
];

yield [
self::loadFixture('order_request.xml'),
'OrderRequest',
];

// TODO add more cases
}

Expand All @@ -47,7 +52,7 @@ private static function loadFixture(string $filename): ?string
public function testEndpoint(string $requestCxml, string $expectedHandlerCalled): void
{
$serializer = Serializer::create();
$messageValidator = new DtdValidator(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/');
$messageValidator = new DtdValidator(__DIR__ . '/../../metadata/cxml/dtd/1.2.050');

$credentialRepository = new Registry();
$credentialRepository->registerCredential(
Expand Down Expand Up @@ -90,8 +95,27 @@ public function handle(PayloadInterface $payload, Context $context): ?ResponsePa
}
};

$orderRequestHandler = new class($actualHandlerCalled) implements HandlerInterface {
public function __construct(private string &$actualHandlerCalled)
{
}

public static function getRequestName(): string
{
return 'OrderRequest';
}

public function handle(PayloadInterface $payload, Context $context): ?ResponsePayloadInterface
{
$this->actualHandlerCalled = 'OrderRequest';

return null;
}
};

$handlerRegistry = new HandlerRegistry();
$handlerRegistry->register($quoteMessageHandler);
$handlerRegistry->register($orderRequestHandler);

$builder = Builder::create();

Expand Down
80 changes: 80 additions & 0 deletions tests/CXmlTest/Handling/fixtures/order_request.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.2.060/cXML.dtd">
<cXML payloadID="1737963337.319.1846511.7249@eu-hub" timestamp="2025-01-27T07:35:37+00:00">
<Header>
<From>
<Credential domain="NetworkId">
<Identity>AN00000123</Identity>
</Credential>
</From>
<To>
<Credential domain="NetworkId">
<Identity>AN00000456</Identity>
</Credential>
</To>
<Sender>
<Credential domain="NetworkId">
<Identity>AN00000123</Identity>
<SharedSecret>Secret!123</SharedSecret>
</Credential>
<UserAgent>Suppliers Super Order Processor</UserAgent>
</Sender>
</Header>
<Request deploymentMode="test">
<OrderRequest>
<OrderRequestHeader orderID="acme-1-1" orderDate="2025-01-27T07:35:36+00:00" type="new" requestedDeliveryDate="2025-01-28T23:00:00+00:00">
<Total>
<Money currency="USD">10.00</Money>
</Total>
<ShipTo>
<Address>
<Name xml:lang="en">TEST.USA ACME</Name>
<PostalAddress>
<DeliverTo>ACME</DeliverTo>
<DeliverTo>TEST.USA</DeliverTo>
<Street>22 E 4th Ave</Street>
<City>Columbus</City>
<State>OH</State>
<PostalCode>43201-3551</PostalCode>
<Country isoCountryCode="US">United States</Country>
<Extrinsic name="phone">+49121255566</Extrinsic>
</PostalAddress>
</Address>
</ShipTo>
<BillTo>
<Address>
<Name xml:lang="en">TEST.USA ACME</Name>
<PostalAddress>
<DeliverTo>ACME</DeliverTo>
<DeliverTo>TEST.USA</DeliverTo>
<Street>22 E 4th Ave</Street>
<City>Columbus</City>
<State>OH</State>
<PostalCode>43201-3551</PostalCode>
<Country isoCountryCode="US">United States</Country>
</PostalAddress>
</Address>
</BillTo>
<Payment>
<PaymentService method="cc" provider="stripe">
<IdReference identifier="ch_..." domain="charge_id"/>
<IdReference identifier="pi_..." domain="intent_id"/>
</PaymentService>
</Payment>
</OrderRequestHeader>
<ItemOut lineNumber="1" quantity="1">
<ItemID>
<SupplierPartID>QA-ACME-AUTOTEST</SupplierPartID>
<BuyerPartID>QA-ACME-AUTOTEST</BuyerPartID>
</ItemID>
<ItemDetail>
<UnitPrice>
<Money currency="USD">10.00</Money>
</UnitPrice>
<Description xml:lang="en">Testing</Description>
<UnitOfMeasure>EA</UnitOfMeasure>
<Classification domain="supplier_part_id">QA-ACME-AUTOTEST</Classification>
</ItemDetail>
</ItemOut>
</OrderRequest>
</Request>
</cXML>
10 changes: 10 additions & 0 deletions tests/metadata/cxml/dtd/1.2.050/Custom.dtd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!ENTITY % cxml.payment "( PCard | PaymentService )">

<!ENTITY % elements SYSTEM "./cXML.dtd">
%elements;

<!ELEMENT PaymentService (IdReference*, Extrinsic*)>
<!ATTLIST PaymentService
method CDATA #REQUIRED
provider CDATA #IMPLIED
>

0 comments on commit b99c7d6

Please sign in to comment.