diff --git a/docs/cXMLReferenceGuide.pdf b/docs/cXMLReferenceGuide.pdf deleted file mode 100644 index 69f7bac..0000000 Binary files a/docs/cXMLReferenceGuide.pdf and /dev/null differ diff --git a/readme.md b/readme.md index f2f6c2e..6901e2b 100644 --- a/readme.md +++ b/readme.md @@ -5,13 +5,6 @@ > > cXML Reference Guide (PDF): http://xml.cxml.org/current/cXMLReferenceGuide.pdf -# Status - -| CXML Version | Status Test | -|--------------|-------------| -| 1.2.050 | OK | -| 1.2.053 | OK | - # Getting Started ## Installation @@ -112,10 +105,10 @@ $cXmlProcessor->process($cXml); ```php $credentialRegistry = new \CXml\Credential\Registry(); -//TODO register... +//TODO register credentials... $handlerRegistry = new \CXml\Handler\HandlerRegistry(); -//TODO register... +//TODO register handler... $builder = \CXml\Builder::create(); @@ -127,9 +120,11 @@ $cXmlProcessor = new \CXml\Processor\Processor( ); $pathToDtd = '.'; //point the directory with extracted contents of zip-file with the DTDs, downloaded from cxml.org -$dtdValidator = new \CXml\Validation\DtdValidator($pathToDtd); +$dtdValidator = \CXml\Validation\DtdValidator::fromDtdDirectory($pathToDtd); +$serializer = \CXml\Serializer::create(); $endpoint = new \CXml\Endpoint( + $serializer, $dtdValidator, $cXmlProcessor ); @@ -167,5 +162,39 @@ value. When parsing a date-property from a cXML document, the `CXml\Model\Date` will be instantiated **if** a date-only value was discovered (Y-m-d). -# Credits -- Markus Thielen (https://github.com/mathielen) +## Extending cXML + +### Add custom elements + +The definition of cXML is open for extension. There are ways to extend the DTD with overriding existing variables and +therefore adding custom elements. With version 2.1.0 we introduced a way to add custom elements to the cXML model. + +To make this happen, we have to build our own DTD file and import the original DTD file in it. We can then add our own +elements and attributes in the variables that are defined in the original DTD file. + +TODO this is only really implemented for the Payment node at the moment. + +#### Example +An example of a custom DTD file that adds a custom element to the `PaymentReference` element: + +```dtd + + + +%elements; + + + +``` + +To use this DTD file for validation as well as for serialization and deserialization, you could save the file next to the +other DTD files from cXML and use `DtdValidator::fromDtdDirectory` just as you would with the original DTD files. Or you +could explicitly load only the new DTD file with `new DtdValidator($arrayOfDtdFilepaths)`. + +Also you would probably want newly generated cXML files to point to your DTD file. You can do this by telling the +serializer to use your DTD file: `Serializer::create('http://...publicUrlToYourDtd')`. + +Now the new element also has to be known by the serializer. Usually the model classes can be found in `CXml\Model`. diff --git a/src/CXml/Authentication/SimpleSharedSecretAuthenticator.php b/src/CXml/Authentication/SimpleSharedSecretAuthenticator.php index 6f55d50..b546a06 100644 --- a/src/CXml/Authentication/SimpleSharedSecretAuthenticator.php +++ b/src/CXml/Authentication/SimpleSharedSecretAuthenticator.php @@ -16,8 +16,8 @@ public function __construct(private string $sharedSecret) public function authenticate(Header $header, Context $context): void { - if ($this->sharedSecret !== $header->getSender()->getCredential()->getSharedSecret()) { - throw new CXmlAuthenticationInvalidException($header->getSender()->getCredential()); + if ($this->sharedSecret !== $header->sender->credential->getSharedSecret()) { + throw new CXmlAuthenticationInvalidException($header->sender->credential); } } } diff --git a/src/CXml/Builder/OrderRequestBuilder.php b/src/CXml/Builder/OrderRequestBuilder.php index dc1e0bc..51b0b0c 100644 --- a/src/CXml/Builder/OrderRequestBuilder.php +++ b/src/CXml/Builder/OrderRequestBuilder.php @@ -18,6 +18,8 @@ use CXml\Model\Message\PunchOutOrderMessage; use CXml\Model\MoneyWrapper; use CXml\Model\MultilanguageString; +use CXml\Model\Payment; +use CXml\Model\PaymentTerm; use CXml\Model\Phone; use CXml\Model\PostalAddress; use CXml\Model\PriceBasisQuantity; @@ -57,6 +59,10 @@ class OrderRequestBuilder private array $businessPartners = []; + private ?Payment $payment = null; + + private ?PaymentTerm $paymentTerm = null; + private function __construct( private readonly string $orderId, private readonly DateTimeInterface $orderDate, @@ -83,12 +89,12 @@ public static function fromPunchOutOrderMessage( ?DateTimeInterface $orderDate = null, string $language = 'en', ): self { - if (($supplierOrderInfo = $punchOutOrderMessage->getPunchOutOrderMessageHeader()->getSupplierOrderInfo()) instanceof SupplierOrderInfo) { - $orderId ??= $supplierOrderInfo->getOrderId(); - $orderDate ??= $supplierOrderInfo->getOrderDate(); + if (($supplierOrderInfo = $punchOutOrderMessage->punchOutOrderMessageHeader->getSupplierOrderInfo()) instanceof SupplierOrderInfo) { + $orderId ??= $supplierOrderInfo->orderId; + $orderDate ??= $supplierOrderInfo->orderDate; } - $currency ??= $punchOutOrderMessage->getPunchOutOrderMessageHeader()->getTotal()->getMoney()->getCurrency(); + $currency ??= $punchOutOrderMessage->punchOutOrderMessageHeader->total->money->currency; if (null === $orderId) { throw new LogicException('orderId should either be given or present in the PunchOutOrderMessage'); @@ -106,15 +112,15 @@ public static function fromPunchOutOrderMessage( null, ); - $orb->setShipTo($punchOutOrderMessage->getPunchOutOrderMessageHeader()->getShipTo()); + $orb->setShipTo($punchOutOrderMessage->punchOutOrderMessageHeader->getShipTo()); foreach ($punchOutOrderMessage->getPunchoutOrderMessageItems() as $item) { $orb->addItem( - $item->getQuantity(), - $item->getItemId(), - $item->getItemDetail()->getDescription()->getValue(), - $item->getItemDetail()->getUnitOfMeasure(), - $item->getItemDetail()->getUnitPrice()->getMoney()->getValueCent(), + $item->quantity, + $item->itemId, + $item->itemDetail->description->value, + $item->itemDetail->unitOfMeasure, + $item->itemDetail->unitPrice->money->getValueCent(), [ new Classification('custom', '0'), // TODO make this configurable ], @@ -156,6 +162,7 @@ public function shipTo( array $carrierIdentifiers = [], ?string $carrierAccountNo = null, ?string $carrierShippingMethod = null, + array $idReferences = [], ): self { $transportInformation = null; if (null !== $carrierAccountNo || null != $carrierShippingMethod) { @@ -174,6 +181,10 @@ public function shipTo( $this->shipTo->addCarrierIdentifier($domain, $identifier); } + foreach ($idReferences as $domain => $identifier) { + $this->shipTo->addIdReference($domain, $identifier); + } + return $this; } @@ -249,13 +260,13 @@ public function addItem( $priceBasisQuantity, ), $requestDeliveryDate, - $parent instanceof ItemOut ? $parent->getLineNumber() : null, + $parent instanceof ItemOut ? $parent->lineNumber : null, ); $this->items[] = $item; - if ($priceBasisQuantity instanceof PriceBasisQuantity && $priceBasisQuantity->getQuantity() > 0) { - $this->total += (int)round($quantity * ($priceBasisQuantity->getConversionFactor() / $priceBasisQuantity->getQuantity()) * $unitPrice); + if ($priceBasisQuantity instanceof PriceBasisQuantity && $priceBasisQuantity->quantity > 0) { + $this->total += (int)round($quantity * ($priceBasisQuantity->conversionFactor / $priceBasisQuantity->quantity) * $unitPrice); } else { $this->total += ($quantity * $unitPrice); } @@ -308,6 +319,8 @@ private function buildOrderRequestHeader(): OrderRequestHeader $this->contacts, ) ->setShipping($this->shipping) + ->setPayment($this->payment) + ->setPaymentTerm($this->paymentTerm) ->setTax($this->tax); foreach ($this->comments as $comment) { @@ -359,4 +372,12 @@ public function addBusinessPartner(string $role, string $name, array $idReferenc $this->businessPartners[] = $bp; } + + public function setPayment(?Payment $payment, ?PaymentTerm $paymentTerm): self + { + $this->payment = $payment; + $this->paymentTerm = $paymentTerm; + + return $this; + } } diff --git a/src/CXml/Builder/PunchOutOrderMessageBuilder.php b/src/CXml/Builder/PunchOutOrderMessageBuilder.php index 5bb4e17..af0dca1 100644 --- a/src/CXml/Builder/PunchOutOrderMessageBuilder.php +++ b/src/CXml/Builder/PunchOutOrderMessageBuilder.php @@ -165,15 +165,15 @@ public function addItem(ItemIn $itemIn): self { $this->punchoutOrderMessageItems[] = $itemIn; - $moneyValueCent = $itemIn->getItemDetail()->getUnitPrice()->getMoney()->getValueCent(); - $itemQty = $itemIn->getQuantity(); + $moneyValueCent = $itemIn->itemDetail->unitPrice->money->getValueCent(); + $itemQty = $itemIn->quantity; if ( - $itemIn->getItemDetail()->getPriceBasisQuantity() instanceof PriceBasisQuantity - && $itemIn->getItemDetail()->getPriceBasisQuantity()->getQuantity() > 0 + $itemIn->itemDetail->priceBasisQuantity instanceof PriceBasisQuantity + && $itemIn->itemDetail->priceBasisQuantity->quantity > 0 ) { - $priceBasisQuantity = $itemIn->getItemDetail()->getPriceBasisQuantity(); - $this->total += (int)round($itemQty * ($priceBasisQuantity->getConversionFactor() / $priceBasisQuantity->getQuantity()) * $moneyValueCent); + $priceBasisQuantity = $itemIn->itemDetail->priceBasisQuantity; + $this->total += (int)round($itemQty * ($priceBasisQuantity->conversionFactor / $priceBasisQuantity->quantity) * $moneyValueCent); } else { $this->total += $moneyValueCent * $itemQty; } diff --git a/src/CXml/Context.php b/src/CXml/Context.php index 1ab1803..cd66adc 100644 --- a/src/CXml/Context.php +++ b/src/CXml/Context.php @@ -61,12 +61,12 @@ public function getSenderUserAgent(): ?string return null; } - $header = $cxml->getHeader(); + $header = $cxml->header; if (!$header instanceof Header) { return null; } - return $header->getSender()->getUserAgent(); + return $header->sender->userAgent; } public function getPayloadId(): ?string @@ -76,6 +76,6 @@ public function getPayloadId(): ?string return null; } - return $cxml->getPayloadId(); + return $cxml->payloadId; } } diff --git a/src/CXml/Credential/Registry.php b/src/CXml/Credential/Registry.php index 9614370..d4b0e53 100644 --- a/src/CXml/Credential/Registry.php +++ b/src/CXml/Credential/Registry.php @@ -31,11 +31,11 @@ public function registerCredential(Credential $credential): void public function getCredentialByDomainAndId(string $domain, string $identity): Credential { foreach ($this->registeredCredentials as $registeredCredential) { - if ($registeredCredential->getDomain() !== $domain) { + if ($registeredCredential->domain !== $domain) { continue; } - if ($registeredCredential->getIdentity() !== $identity) { + if ($registeredCredential->identity !== $identity) { continue; } @@ -51,11 +51,11 @@ public function getCredentialByDomainAndId(string $domain, string $identity): Cr */ public function authenticate(Header $header, Context $context): void { - $senderCredential = $header->getSender()->getCredential(); + $senderCredential = $header->sender->credential; $baseCredential = $this->getCredentialByDomainAndId( - $senderCredential->getDomain(), - $senderCredential->getIdentity(), + $senderCredential->domain, + $senderCredential->identity, ); if ($baseCredential->getSharedSecret() !== $senderCredential->getSharedSecret()) { @@ -70,8 +70,8 @@ public function validate(Credential $credential): void { // provoke an exception if credential was not found $this->getCredentialByDomainAndId( - $credential->getDomain(), - $credential->getIdentity(), + $credential->domain, + $credential->identity, ); } } diff --git a/src/CXml/Jms/CXmlWrappingNodeJmsEventSubscriber.php b/src/CXml/Jms/CXmlWrappingNodeJmsEventSubscriber.php index e2e5418..50beefd 100644 --- a/src/CXml/Jms/CXmlWrappingNodeJmsEventSubscriber.php +++ b/src/CXml/Jms/CXmlWrappingNodeJmsEventSubscriber.php @@ -5,66 +5,69 @@ namespace CXml\Jms; use CXml\Model\Exception\CXmlModelNotFoundException; +use CXml\Model\Extension\PaymentReference; use CXml\Model\Message\Message; +use CXml\Model\Payment; use CXml\Model\Request\Request; use CXml\Model\Response\Response; use JMS\Serializer\EventDispatcher\Events; use JMS\Serializer\EventDispatcher\EventSubscriberInterface; use JMS\Serializer\EventDispatcher\ObjectEvent; use JMS\Serializer\EventDispatcher\PreDeserializeEvent; +use JMS\Serializer\Metadata\ClassMetadata; use JMS\Serializer\Metadata\PropertyMetadata; use JMS\Serializer\Metadata\StaticPropertyMetadata; use JMS\Serializer\XmlSerializationVisitor; -use Metadata\ClassMetadata; use ReflectionClass; -use ReflectionException; use SimpleXMLElement; -use function class_exists; - /** * Certain CXml-nodes have "wrappers"-nodes which this subscriber automatically handles. */ class CXmlWrappingNodeJmsEventSubscriber implements EventSubscriberInterface { + private static array $mainPayloadClasses = [ + Message::class, + Request::class, + Response::class, + ]; + + private ModelClassMapping $modelClassMapping; + + public function __construct(?ModelClassMapping $modelClassMapping = null) + { + $this->modelClassMapping = $modelClassMapping ?? ModelClassMapping::fromDefaultModelPath(); + } + + public static function isEligible(string $incomingType): bool + { + return in_array($incomingType, self::$mainPayloadClasses, true); + } + public static function getSubscribedEvents(): array { return [ [ 'event' => Events::POST_SERIALIZE, - 'method' => 'onPostSerializePayload', - 'class' => Message::class, - 'format' => 'xml', - ], - [ - 'event' => Events::POST_SERIALIZE, - 'method' => 'onPostSerializePayload', - 'class' => Request::class, - 'format' => 'xml', - ], - [ - 'event' => Events::POST_SERIALIZE, - 'method' => 'onPostSerializePayload', - 'class' => Response::class, + 'method' => 'onPostSerializeCXmlMainPayload', 'format' => 'xml', ], - [ 'event' => Events::PRE_DESERIALIZE, - 'method' => 'onPreDeserializePayload', - 'class' => Message::class, + 'method' => 'onPreDeserializeCXmlMainPayload', 'format' => 'xml', ], + [ - 'event' => Events::PRE_DESERIALIZE, - 'method' => 'onPreDeserializePayload', - 'class' => Request::class, + 'event' => Events::POST_SERIALIZE, + 'method' => 'onPostSerializePayment', + 'class' => Payment::class, 'format' => 'xml', ], [ 'event' => Events::PRE_DESERIALIZE, - 'method' => 'onPreDeserializePayload', - 'class' => Response::class, + 'method' => 'onPreDeserializePayment', + 'class' => Payment::class, 'format' => 'xml', ], ]; @@ -84,24 +87,98 @@ private function findPayloadNode(SimpleXMLElement $cXmlNode): ?SimpleXMLElement return null; } + public function onPostSerializePayment(ObjectEvent $event): void + { + /** @var XmlSerializationVisitor $visitor */ + $visitor = $event->getVisitor(); + + /** @var Payment $payment */ + $payment = $event->getObject(); + + $paymentImplList = $payment->paymentImpl; + + if (!is_array($paymentImplList)) { + $paymentImplList = [$paymentImplList]; + } + + foreach ($paymentImplList as $impl) { + $cls = (new ReflectionClass($impl))->getShortName(); + + $visitor->visitProperty( + new StaticPropertyMetadata(Payment::class, $cls, null), + $impl, + ); + } + } + /** - * @throws ReflectionException + * @throws CXmlModelNotFoundException */ - public function onPostSerializePayload(ObjectEvent $event): void + public function onPreDeserializePayment(PreDeserializeEvent $event): void + { + /** @var ClassMetadata $metadata */ + $metadata = $event->getContext()->getMetadataFactory()->getMetadataForClass(Payment::class); + + // manipulate metadata of payload on-the-fly to match xml + + $propertyMetadata = new PropertyMetadata( + Payment::class, + 'paymentImpl', + ); + + /** @var SimpleXMLElement $data */ + $data = $event->getData(); + + $isArray = count($data->children()) > 1; + if ($isArray) { + $propertyMetadata->xmlEntryName = 'PaymentReference'; + $propertyMetadata->xmlCollection = true; + $propertyMetadata->xmlCollectionInline = true; + $propertyMetadata->xmlElementCData = true; + $propertyMetadata->setType([ + 'name' => 'array', + 'params' => [ + [ + 'name' => PaymentReference::class, + 'params' => [], + ], + ], + ]); + } else { + $payloadNode = $data->children()[0]; + $serializedName = $payloadNode->getName(); + $cls = $this->modelClassMapping->findClassForSerializedName($serializedName); + + $propertyMetadata->serializedName = $serializedName; + $propertyMetadata->setType([ + 'name' => $cls, + 'params' => [], + ]); + } + + $metadata->addPropertyMetadata($propertyMetadata); + } + + public function onPostSerializeCXmlMainPayload(ObjectEvent $event): void { + $incomingType = $event->getType()['name']; + if (!self::isEligible($incomingType)) { + return; + } + /** @var XmlSerializationVisitor $visitor */ $visitor = $event->getVisitor(); // this is the actual payload object of type MessagePayloadInterface /** @phpstan-ignore-next-line */ - $payload = $event->getObject()->getPayload(); + $payload = $event->getObject()->payload ?? null; if ($payload) { $cls = (new ReflectionClass($payload))->getShortName(); // tell jms to add the payload value in a wrapped node $visitor->visitProperty( - new StaticPropertyMetadata($event->getType()['name'], $cls, null), + new StaticPropertyMetadata($incomingType, $cls, null), $payload, ); } @@ -109,12 +186,16 @@ public function onPostSerializePayload(ObjectEvent $event): void /** * @throws CXmlModelNotFoundException - * @throws ReflectionException */ - public function onPreDeserializePayload(PreDeserializeEvent $event): void + public function onPreDeserializeCXmlMainPayload(PreDeserializeEvent $event): void { + $incomingType = $event->getType()['name']; + if (!self::isEligible($incomingType)) { + return; + } + /** @var ClassMetadata $metadata */ - $metadata = $event->getContext()->getMetadataFactory()->getMetadataForClass($event->getType()['name']); + $metadata = $event->getContext()->getMetadataFactory()->getMetadataForClass($incomingType); /** @var SimpleXMLElement $data */ $data = $event->getData(); @@ -124,17 +205,12 @@ public function onPreDeserializePayload(PreDeserializeEvent $event): void } $serializedName = $payloadNode->getName(); - $targetNamespace = (new ReflectionClass($event->getType()['name']))->getNamespaceName(); - - $cls = $targetNamespace . '\\' . $serializedName; - if (!class_exists($cls)) { - throw new CXmlModelNotFoundException($serializedName); - } + $cls = $this->modelClassMapping->findClassForSerializedName($serializedName); // manipulate metadata of payload on-the-fly to match xml $propertyMetadata = new PropertyMetadata( - $event->getType()['name'], + $incomingType, 'payload', ); diff --git a/src/CXml/Jms/ModelClassMapping.php b/src/CXml/Jms/ModelClassMapping.php new file mode 100644 index 0000000..1e84e25 --- /dev/null +++ b/src/CXml/Jms/ModelClassMapping.php @@ -0,0 +1,98 @@ +pathToModelFiles, FilesystemIterator::SKIP_DOTS)); + + /** @var SplFileInfo $file */ + foreach ($rii as $file) { + if ('php' !== $file->getExtension()) { + continue; + } + + $subNamespace = substr($file->getPath(), strlen($this->pathToModelFiles)); + $subNamespace = str_replace('/', '\\', $subNamespace); + + /** @var class-string $className */ + $className = 'CXml\Model' . $subNamespace . '\\' . $file->getBasename('.php'); + + $class = new ReflectionClass($className); + if ($class->isAbstract()) { + continue; + } + + if ($class->isInterface()) { + continue; + } + + if ($class->isTrait()) { + continue; + } + + if ($class->isAnonymous()) { + continue; + } + + if ($class->implementsInterface(Throwable::class)) { + continue; + } + + $shortName = $class->getShortName(); + + $this->register($shortName, $className); + } + + self::$initialized = true; + } + + /** + * @throws CXmlModelNotFoundException + */ + public function findClassForSerializedName(string $serializedName): string + { + if (!self::$initialized) { + $this->loadModelClasses(); + } + + return self::$modelRegistry[$serializedName] ?? throw new CXmlModelNotFoundException($serializedName); + } +} diff --git a/src/CXml/Model/Accounting.php b/src/CXml/Model/Accounting.php index b012e77..0da022e 100644 --- a/src/CXml/Model/Accounting.php +++ b/src/CXml/Model/Accounting.php @@ -10,15 +10,15 @@ { private function __construct( #[Serializer\XmlAttribute] - private string $name, + public string $name, /** * @var AccountingSegment[] */ #[Serializer\XmlList(entry: 'AccountingSegment', inline: true)] #[Serializer\Type('array')] - private array $accountingSegments, + public array $accountingSegments, #[Serializer\SerializedName('Charge')] - private MoneyWrapper $charge, + public MoneyWrapper $charge, ) { } } diff --git a/src/CXml/Model/AccountingSegment.php b/src/CXml/Model/AccountingSegment.php index b35242b..62f06b4 100644 --- a/src/CXml/Model/AccountingSegment.php +++ b/src/CXml/Model/AccountingSegment.php @@ -10,13 +10,13 @@ { private function __construct( #[Serializer\XmlAttribute] - private int $id, + public int $id, #[Serializer\SerializedName('Name')] #[Serializer\XmlElement(cdata: false)] - private MultilanguageString $name, + public MultilanguageString $name, #[Serializer\SerializedName('Description')] #[Serializer\XmlElement(cdata: false)] - private MultilanguageString $description, + public MultilanguageString $description, ) { } } diff --git a/src/CXml/Model/Address.php b/src/CXml/Model/Address.php index d431c61..5c4490b 100644 --- a/src/CXml/Model/Address.php +++ b/src/CXml/Model/Address.php @@ -12,67 +12,27 @@ public function __construct( #[Serializer\SerializedName('Name')] #[Serializer\XmlElement(cdata: false)] - private MultilanguageString $name, + public MultilanguageString $name, #[Serializer\SerializedName('PostalAddress')] - private ?PostalAddress $postalAddress = null, + public ?PostalAddress $postalAddress = null, #[Serializer\XmlAttribute] #[Serializer\SerializedName('addressID')] - private ?string $addressId = null, + public ?string $addressId = null, #[Serializer\XmlAttribute] #[Serializer\SerializedName('addressIDDomain')] - private ?string $addressIdDomain = null, + public ?string $addressIdDomain = null, #[Serializer\SerializedName('Email')] #[Serializer\XmlElement(cdata: false)] - private ?string $email = null, + public ?string $email = null, #[Serializer\SerializedName('Phone')] #[Serializer\XmlElement(cdata: false)] - private ?Phone $phone = null, + public ?Phone $phone = null, #[Serializer\SerializedName('Fax')] #[Serializer\XmlElement(cdata: false)] - private ?string $fax = null, + public ?string $fax = null, #[Serializer\SerializedName('URL')] #[Serializer\XmlElement(cdata: false)] - private ?string $url = null, + public ?string $url = null, ) { } - - public function getAddressId(): ?string - { - return $this->addressId; - } - - public function getAddressIdDomain(): ?string - { - return $this->addressIdDomain; - } - - public function getName(): MultilanguageString - { - return $this->name; - } - - public function getPostalAddress(): ?PostalAddress - { - return $this->postalAddress; - } - - public function getEmail(): ?string - { - return $this->email; - } - - public function getPhone(): ?Phone - { - return $this->phone; - } - - public function getFax(): ?string - { - return $this->fax; - } - - public function getUrl(): ?string - { - return $this->url; - } } diff --git a/src/CXml/Model/BillTo.php b/src/CXml/Model/BillTo.php index 0aad89f..1bc9cc9 100644 --- a/src/CXml/Model/BillTo.php +++ b/src/CXml/Model/BillTo.php @@ -4,6 +4,7 @@ namespace CXml\Model; +use CXml\Model\Trait\IdReferencesTrait; use JMS\Serializer\Annotation as Serializer; #[Serializer\AccessorOrder(order: 'custom', custom: ['address', 'idReferences'])] @@ -13,12 +14,7 @@ class BillTo public function __construct( #[Serializer\SerializedName('Address')] - private readonly Address $address, + public readonly Address $address, ) { } - - public function getAddress(): Address - { - return $this->address; - } } diff --git a/src/CXml/Model/BusinessPartner.php b/src/CXml/Model/BusinessPartner.php index 1e25479..de6b010 100644 --- a/src/CXml/Model/BusinessPartner.php +++ b/src/CXml/Model/BusinessPartner.php @@ -4,6 +4,7 @@ namespace CXml\Model; +use CXml\Model\Trait\IdReferencesTrait; use JMS\Serializer\Annotation as Serializer; #[Serializer\AccessorOrder(order: 'custom', custom: ['type', 'role', 'address', 'idReferences'])] @@ -18,11 +19,11 @@ class BusinessPartner public function __construct( #[Serializer\XmlAttribute] - private string $role, + public readonly string $role, #[Serializer\SerializedName('Address')] - private Address $address, + public readonly Address $address, #[Serializer\XmlAttribute] - private string $type = 'organization', + public readonly string $type = 'organization', ) { } } diff --git a/src/CXml/Model/CXml.php b/src/CXml/Model/CXml.php index ed541b8..ee962da 100644 --- a/src/CXml/Model/CXml.php +++ b/src/CXml/Model/CXml.php @@ -14,7 +14,7 @@ #[Serializer\XmlRoot('cXML')] #[Serializer\AccessorOrder(order: 'custom', custom: ['header', 'message', 'request', 'response'])] -class CXml implements Stringable +readonly class CXml implements Stringable { final public const DEPLOYMENT_TEST = 'test'; @@ -23,65 +23,35 @@ class CXml implements Stringable protected function __construct( #[Serializer\XmlAttribute] #[Serializer\SerializedName('payloadID')] - private readonly string $payloadId, + public string $payloadId, #[Serializer\XmlAttribute] - private readonly DateTimeInterface $timestamp, + public DateTimeInterface $timestamp, #[Serializer\SerializedName('Request')] - private readonly ?Request $request = null, + public ?Request $request = null, #[Serializer\SerializedName('Response')] - private readonly ?Response $response = null, + public ?Response $response = null, #[Serializer\SerializedName('Message')] - private readonly ?Message $message = null, + public ?Message $message = null, #[Serializer\SerializedName('Header')] - private readonly ?Header $header = null, + public ?Header $header = null, #[Serializer\XmlAttribute(namespace: 'http://www.w3.org/XML/1998/namespace')] - private readonly ?string $lang = null, + public ?string $lang = null, ) { } public static function forMessage(PayloadIdentity $payloadIdentity, Message $message, Header $header, ?string $lang = null): self { - return new self($payloadIdentity->getPayloadId(), $payloadIdentity->getTimestamp(), null, null, $message, $header, $lang); + return new self($payloadIdentity->payloadId, $payloadIdentity->timestamp, null, null, $message, $header, $lang); } public static function forRequest(PayloadIdentity $payloadIdentity, Request $request, Header $header, ?string $lang = null): self { - return new self($payloadIdentity->getPayloadId(), $payloadIdentity->getTimestamp(), $request, null, null, $header, $lang); + return new self($payloadIdentity->payloadId, $payloadIdentity->timestamp, $request, null, null, $header, $lang); } public static function forResponse(PayloadIdentity $payloadIdentity, Response $response, ?string $lang = null): self { - return new self($payloadIdentity->getPayloadId(), $payloadIdentity->getTimestamp(), null, $response, null, null, $lang); - } - - public function getPayloadId(): string - { - return $this->payloadId; - } - - public function getTimestamp(): DateTimeInterface - { - return $this->timestamp; - } - - public function getHeader(): ?Header - { - return $this->header; - } - - public function getRequest(): ?Request - { - return $this->request; - } - - public function getResponse(): ?Response - { - return $this->response; - } - - public function getMessage(): ?Message - { - return $this->message; + return new self($payloadIdentity->payloadId, $payloadIdentity->timestamp, null, $response, null, null, $lang); } public function __toString(): string @@ -90,7 +60,7 @@ public function __toString(): string $shortName = 'undefined'; if (null !== $wrapper) { - $payload = $wrapper->getPayload(); + $payload = $wrapper->payload; if (null !== $payload) { $shortName = (new ReflectionClass($payload))->getShortName(); @@ -105,15 +75,15 @@ public function __toString(): string public function getStatus(): ?Status { if ($this->request instanceof Request) { - return $this->request->getStatus(); + return $this->request->status; } if ($this->message instanceof Message) { - return $this->message->getStatus(); + return $this->message->status; } if ($this->response instanceof Response) { - return $this->response->getStatus(); + return $this->response->status; } return null; diff --git a/src/CXml/Model/CarrierIdentifier.php b/src/CXml/Model/CarrierIdentifier.php index 9e64a47..be3d9a3 100644 --- a/src/CXml/Model/CarrierIdentifier.php +++ b/src/CXml/Model/CarrierIdentifier.php @@ -7,7 +7,7 @@ use JMS\Serializer\Annotation as Serializer; #[Serializer\AccessorOrder(order: 'custom', custom: ['value'])] -class CarrierIdentifier +readonly class CarrierIdentifier { final public const DOMAIN_COMPANYNAME = 'companyName'; @@ -25,19 +25,9 @@ class CarrierIdentifier public function __construct( #[Serializer\XmlAttribute] - private readonly string $domain, + public string $domain, #[Serializer\XmlValue(cdata: false)] - private readonly string $value, + public string $value, ) { } - - public function getDomain(): string - { - return $this->domain; - } - - public function getValue(): string - { - return $this->value; - } } diff --git a/src/CXml/Model/Classification.php b/src/CXml/Model/Classification.php index 8441a8c..b94ceca 100644 --- a/src/CXml/Model/Classification.php +++ b/src/CXml/Model/Classification.php @@ -11,19 +11,9 @@ { public function __construct( #[Serializer\XmlAttribute] - private string $domain, + public string $domain, #[Serializer\XmlValue(cdata: false)] - private string $value, + public string $value, ) { } - - public function getDomain(): string - { - return $this->domain; - } - - public function getValue(): string - { - return $this->value; - } } diff --git a/src/CXml/Model/Comment.php b/src/CXml/Model/Comment.php index 573b1ab..3889796 100644 --- a/src/CXml/Model/Comment.php +++ b/src/CXml/Model/Comment.php @@ -10,37 +10,17 @@ readonly class Comment { #[Serializer\SerializedName('Attachment')] - private ?Url $attachment; + public ?Url $attachment; public function __construct( #[Serializer\XmlValue(cdata: false)] - private ?string $value = null, + public ?string $value = null, #[Serializer\XmlAttribute] - private ?string $type = null, + public ?string $type = null, #[Serializer\XmlAttribute(namespace: 'http://www.w3.org/XML/1998/namespace')] - private ?string $lang = null, + public ?string $lang = null, ?string $attachment = null, ) { $this->attachment = null !== $attachment && '' !== $attachment && '0' !== $attachment ? new Url($attachment) : null; } - - public function getAttachment(): ?Url - { - return $this->attachment; - } - - public function getValue(): ?string - { - return $this->value; - } - - public function getLang(): ?string - { - return $this->lang; - } - - public function getType(): ?string - { - return $this->type; - } } diff --git a/src/CXml/Model/Contact.php b/src/CXml/Model/Contact.php index 696dcf3..46d5011 100644 --- a/src/CXml/Model/Contact.php +++ b/src/CXml/Model/Contact.php @@ -4,6 +4,8 @@ namespace CXml\Model; +use CXml\Model\Trait\ExtrinsicsTrait; +use CXml\Model\Trait\IdReferencesTrait; use JMS\Serializer\Annotation as Serializer; #[Serializer\AccessorOrder(order: 'custom', custom: ['name', 'postalAddress', 'email', 'phone', 'fax', 'url', 'extrinsics', 'idReferences'])] diff --git a/src/CXml/Model/ControlKeys.php b/src/CXml/Model/ControlKeys.php index c703442..80a8c05 100644 --- a/src/CXml/Model/ControlKeys.php +++ b/src/CXml/Model/ControlKeys.php @@ -10,7 +10,7 @@ { private function __construct( #[Serializer\SerializedName('InvoiceInstruction')] - private InvoiceInstruction $invoiceInstruction, + public InvoiceInstruction $invoiceInstruction, ) { } } diff --git a/src/CXml/Model/Country.php b/src/CXml/Model/Country.php index 52e7c05..a0f5c90 100644 --- a/src/CXml/Model/Country.php +++ b/src/CXml/Model/Country.php @@ -12,19 +12,9 @@ public function __construct( #[Serializer\XmlAttribute] #[Serializer\SerializedName('isoCountryCode')] - private string $isoCountryCode, + public string $isoCountryCode, #[Serializer\XmlValue(cdata: false)] - private ?string $name = null, + public ?string $name = null, ) { } - - public function getIsoCountryCode(): string - { - return $this->isoCountryCode; - } - - public function getName(): ?string - { - return $this->name; - } } diff --git a/src/CXml/Model/CountryCode.php b/src/CXml/Model/CountryCode.php index 05f88ea..6c47459 100644 --- a/src/CXml/Model/CountryCode.php +++ b/src/CXml/Model/CountryCode.php @@ -12,19 +12,9 @@ public function __construct( #[Serializer\XmlAttribute] #[Serializer\SerializedName('isoCountryCode')] - private string $isoCountryCode, + public string $isoCountryCode, #[Serializer\XmlValue(cdata: false)] - private ?string $dialCode = null, + public ?string $dialCode = null, ) { } - - public function getIsoCountryCode(): string - { - return $this->isoCountryCode; - } - - public function getDialCode(): ?string - { - return $this->dialCode; - } } diff --git a/src/CXml/Model/Credential.php b/src/CXml/Model/Credential.php index aa79259..c88a407 100644 --- a/src/CXml/Model/Credential.php +++ b/src/CXml/Model/Credential.php @@ -14,38 +14,30 @@ class Credential implements Stringable { public function __construct( #[Serializer\XmlAttribute] - private readonly string $domain, + public readonly string $domain, #[Serializer\SerializedName('Identity')] #[Serializer\XmlElement(cdata: false)] - private readonly string $identity, + public readonly string $identity, #[Serializer\SerializedName('SharedSecret')] #[Serializer\XmlElement(cdata: false)] private ?string $sharedSecret = null, ) { } - public function getDomain(): string + public function __toString(): string { - return $this->domain; + return sprintf('%s@%s', $this->identity, $this->domain); } - public function getIdentity(): string + public function setSharedSecret(?string $sharedSecret): self { - return $this->identity; + $this->sharedSecret = $sharedSecret; + + return $this; } public function getSharedSecret(): ?string { return $this->sharedSecret; } - - public function setSharedSecret(?string $sharedSecret): void - { - $this->sharedSecret = $sharedSecret; - } - - public function __toString(): string - { - return sprintf('%s@%s', $this->identity, $this->domain); - } } diff --git a/src/CXml/Model/Description.php b/src/CXml/Model/Description.php index 4977055..ddd9d18 100644 --- a/src/CXml/Model/Description.php +++ b/src/CXml/Model/Description.php @@ -7,27 +7,21 @@ use JMS\Serializer\Annotation as Serializer; #[Serializer\AccessorOrder(order: 'custom', custom: ['value', 'shortName'])] -class Description extends MultilanguageString +readonly class Description extends MultilanguageString { #[Serializer\SerializedName('ShortName')] #[Serializer\XmlElement(cdata: false)] - private ?string $shortName = null; + private ?string $shortName; - public function __construct(?string $value, ?string $type = null, string $lang = 'en') + public function __construct(?string $value, ?string $type = null, string $lang = 'en', ?string $shortName = null) { parent::__construct($value, $type, $lang); - } - - public static function createWithShortName(string $shortName, ?string $type = null, string $lang = 'en'): self - { - $new = new self(null, $type, $lang); - $new->setShortname($shortName); - return $new; + $this->shortName = $shortName; } - public function setShortname(?string $shortName): void + public static function createWithShortName(string $shortName, ?string $type = null, string $lang = 'en'): self { - $this->shortName = $shortName; + return new self(null, $type, $lang, $shortName); } } diff --git a/src/CXml/Model/Distribution.php b/src/CXml/Model/Distribution.php index d3291e0..f907a9c 100644 --- a/src/CXml/Model/Distribution.php +++ b/src/CXml/Model/Distribution.php @@ -10,7 +10,7 @@ { private function __construct( #[Serializer\SerializedName('Accounting')] - private Accounting $accounting, + public Accounting $accounting, ) { } } diff --git a/src/CXml/Model/DocumentReference.php b/src/CXml/Model/DocumentReference.php index d1bfcec..bdf4443 100644 --- a/src/CXml/Model/DocumentReference.php +++ b/src/CXml/Model/DocumentReference.php @@ -11,12 +11,7 @@ public function __construct( #[Serializer\XmlAttribute] #[Serializer\SerializedName('payloadID')] - private string $payloadId, + public string $payloadId, ) { } - - public function getPayloadId(): string - { - return $this->payloadId; - } } diff --git a/src/CXml/Model/Extension/PaymentReference.php b/src/CXml/Model/Extension/PaymentReference.php new file mode 100644 index 0000000..a6cdf6e --- /dev/null +++ b/src/CXml/Model/Extension/PaymentReference.php @@ -0,0 +1,33 @@ +name; - } - - public function getValue(): string - { - return $this->value; - } } diff --git a/src/CXml/Model/Header.php b/src/CXml/Model/Header.php index 36256c1..d22f723 100644 --- a/src/CXml/Model/Header.php +++ b/src/CXml/Model/Header.php @@ -11,26 +11,11 @@ { public function __construct( #[Serializer\SerializedName('From')] - private Party $from, + public Party $from, #[Serializer\SerializedName('To')] - private Party $to, + public Party $to, #[Serializer\SerializedName('Sender')] - private Party $sender, + public Party $sender, ) { } - - public function getFrom(): Party - { - return $this->from; - } - - public function getTo(): Party - { - return $this->to; - } - - public function getSender(): Party - { - return $this->sender; - } } diff --git a/src/CXml/Model/IdReference.php b/src/CXml/Model/IdReference.php index 59ec089..99b6aa8 100644 --- a/src/CXml/Model/IdReference.php +++ b/src/CXml/Model/IdReference.php @@ -10,19 +10,9 @@ { public function __construct( #[Serializer\XmlAttribute] - private string $domain, + public string $domain, #[Serializer\XmlAttribute] - private string $identifier, + public string $identifier, ) { } - - public function getDomain(): string - { - return $this->domain; - } - - public function getIdentifier(): string - { - return $this->identifier; - } } diff --git a/src/CXml/Model/InventoryQuantity.php b/src/CXml/Model/InventoryQuantity.php index efa1280..9fcc157 100644 --- a/src/CXml/Model/InventoryQuantity.php +++ b/src/CXml/Model/InventoryQuantity.php @@ -9,23 +9,13 @@ readonly class InventoryQuantity { #[Serializer\SerializedName('UnitOfMeasure')] - private UnitOfMeasure $unitOfMeasure; + public UnitOfMeasure $unitOfMeasure; public function __construct( #[Serializer\XmlAttribute] - private int $quantity, + public int $quantity, string $unitOfMeasure, ) { $this->unitOfMeasure = new UnitOfMeasure($unitOfMeasure); } - - public function getQuantity(): int - { - return $this->quantity; - } - - public function getUnitOfMeasure(): string - { - return $this->unitOfMeasure->getValue(); - } } diff --git a/src/CXml/Model/InvoiceInstruction.php b/src/CXml/Model/InvoiceInstruction.php index 5bef1a6..859e1e0 100644 --- a/src/CXml/Model/InvoiceInstruction.php +++ b/src/CXml/Model/InvoiceInstruction.php @@ -10,9 +10,9 @@ { private function __construct( #[Serializer\XmlAttribute] - private string $verificationType, + public string $verificationType, #[Serializer\XmlAttribute] - private string $value, + public string $value, ) { } } diff --git a/src/CXml/Model/ItemDetail.php b/src/CXml/Model/ItemDetail.php index fa41d84..ce22d5f 100644 --- a/src/CXml/Model/ItemDetail.php +++ b/src/CXml/Model/ItemDetail.php @@ -5,6 +5,7 @@ namespace CXml\Model; use Assert\Assertion; +use CXml\Model\Trait\ExtrinsicsTrait; use JMS\Serializer\Annotation as Serializer; #[Serializer\AccessorOrder(order: 'custom', custom: ['unitPrice', 'description', 'unitOfMeasure', 'priceBasisQuantity', 'classifications', 'manufacturerPartId', 'manufacturerName', 'url', 'leadtime'])] @@ -40,15 +41,15 @@ class ItemDetail protected function __construct( #[Serializer\SerializedName('Description')] #[Serializer\XmlElement(cdata: false)] - private readonly Description $description, + public readonly Description $description, #[Serializer\SerializedName('UnitOfMeasure')] #[Serializer\XmlElement(cdata: false)] - private readonly string $unitOfMeasure, + public readonly string $unitOfMeasure, #[Serializer\SerializedName('UnitPrice')] - private readonly MoneyWrapper $unitPrice, + public readonly MoneyWrapper $unitPrice, #[Serializer\SerializedName('PriceBasisQuantity')] #[Serializer\XmlElement(cdata: false)] - private readonly ?PriceBasisQuantity $priceBasisQuantity = null, + public readonly ?PriceBasisQuantity $priceBasisQuantity = null, ) { } @@ -101,26 +102,6 @@ public function addClassification(Classification $classification): self return $this; } - public function getUnitPrice(): MoneyWrapper - { - return $this->unitPrice; - } - - public function getDescription(): Description - { - return $this->description; - } - - public function getUnitOfMeasure(): string - { - return $this->unitOfMeasure; - } - - public function getPriceBasisQuantity(): ?PriceBasisQuantity - { - return $this->priceBasisQuantity; - } - public function getClassifications(): array { return $this->classifications; diff --git a/src/CXml/Model/ItemId.php b/src/CXml/Model/ItemId.php index e4015a6..36552c0 100644 --- a/src/CXml/Model/ItemId.php +++ b/src/CXml/Model/ItemId.php @@ -4,6 +4,7 @@ namespace CXml\Model; +use CXml\Model\Trait\IdReferencesTrait; use JMS\Serializer\Annotation as Serializer; #[Serializer\AccessorOrder(order: 'custom', custom: ['supplierPartId', 'supplierPartAuxiliaryId', 'buyerPartId', 'idReferences'])] @@ -14,28 +15,13 @@ class ItemId public function __construct( #[Serializer\SerializedName('SupplierPartID')] #[Serializer\XmlElement(cdata: false)] - private readonly string $supplierPartId, + public readonly string $supplierPartId, #[Serializer\SerializedName('SupplierPartAuxiliaryID')] #[Serializer\XmlElement(cdata: false)] - private readonly ?string $supplierPartAuxiliaryId = null, + public readonly ?string $supplierPartAuxiliaryId = null, #[Serializer\SerializedName('BuyerPartID')] #[Serializer\XmlElement(cdata: false)] - private readonly ?string $buyerPartId = null, + public readonly ?string $buyerPartId = null, ) { } - - public function getSupplierPartId(): string - { - return $this->supplierPartId; - } - - public function getSupplierPartAuxiliaryId(): ?string - { - return $this->supplierPartAuxiliaryId; - } - - public function getBuyerPartId(): ?string - { - return $this->buyerPartId; - } } diff --git a/src/CXml/Model/ItemIn.php b/src/CXml/Model/ItemIn.php index 8801af0..0863764 100644 --- a/src/CXml/Model/ItemIn.php +++ b/src/CXml/Model/ItemIn.php @@ -12,11 +12,11 @@ protected function __construct( #[Serializer\XmlAttribute] #[Serializer\SerializedName('quantity')] - private int $quantity, + public int $quantity, #[Serializer\SerializedName('ItemID')] - private ?ItemId $itemId, + public ?ItemId $itemId, #[Serializer\SerializedName('ItemDetail')] - private ItemDetail $itemDetail, + public ItemDetail $itemDetail, ) { } @@ -39,19 +39,4 @@ public function addClassification(string $domain, string $value): self return $this; } - - public function getQuantity(): int - { - return $this->quantity; - } - - public function getItemId(): ?ItemId - { - return $this->itemId; - } - - public function getItemDetail(): ItemDetail - { - return $this->itemDetail; - } } diff --git a/src/CXml/Model/ItemOut.php b/src/CXml/Model/ItemOut.php index 4fc960c..72fa994 100644 --- a/src/CXml/Model/ItemOut.php +++ b/src/CXml/Model/ItemOut.php @@ -4,6 +4,7 @@ namespace CXml\Model; +use CXml\Model\Trait\CommentsTrait; use DateTimeInterface; use JMS\Serializer\Annotation as Serializer; @@ -15,26 +16,26 @@ class ItemOut private function __construct( #[Serializer\XmlAttribute] #[Serializer\SerializedName('lineNumber')] - private int $lineNumber, + public readonly int $lineNumber, #[Serializer\XmlAttribute] #[Serializer\SerializedName('quantity')] - private int $quantity, + public readonly int $quantity, #[Serializer\SerializedName('ItemID')] - private ItemId $itemId, + public readonly ItemId $itemId, #[Serializer\SerializedName('ItemDetail')] - private ItemDetail $itemDetail, + public readonly ItemDetail $itemDetail, #[Serializer\XmlAttribute] - private ?DateTimeInterface $requestedDeliveryDate = null, + public readonly ?DateTimeInterface $requestedDeliveryDate = null, #[Serializer\XmlAttribute] - private ?int $parentLineNumber = null, + public readonly ?int $parentLineNumber = null, #[Serializer\SerializedName('ShipTo')] - private ?ShipTo $shipTo = null, + public readonly ?ShipTo $shipTo = null, #[Serializer\SerializedName('Distribution')] - private ?Distribution $distribution = null, + public readonly ?Distribution $distribution = null, #[Serializer\SerializedName('ControlKeys')] - private ?ControlKeys $controlKeys = null, + public readonly ?ControlKeys $controlKeys = null, #[Serializer\SerializedName('ScheduleLine')] - private ?ScheduleLine $scheduleLine = null, + public readonly ?ScheduleLine $scheduleLine = null, ) { } @@ -63,54 +64,4 @@ public function addClassification(string $domain, string $value): self return $this; } - - public function getLineNumber(): int - { - return $this->lineNumber; - } - - public function getQuantity(): int - { - return $this->quantity; - } - - public function getRequestedDeliveryDate(): ?DateTimeInterface - { - return $this->requestedDeliveryDate; - } - - public function getItemId(): ItemId - { - return $this->itemId; - } - - public function getItemDetail(): ItemDetail - { - return $this->itemDetail; - } - - public function getParentLineNumber(): ?int - { - return $this->parentLineNumber; - } - - public function getShipTo(): ?ShipTo - { - return $this->shipTo; - } - - public function getDistribution(): ?Distribution - { - return $this->distribution; - } - - public function getControlKeys(): ?ControlKeys - { - return $this->controlKeys; - } - - public function getScheduleLine(): ?ScheduleLine - { - return $this->scheduleLine; - } } diff --git a/src/CXml/Model/Message/Message.php b/src/CXml/Model/Message/Message.php index c667142..70c5f9e 100644 --- a/src/CXml/Model/Message/Message.php +++ b/src/CXml/Model/Message/Message.php @@ -13,46 +13,21 @@ { public function __construct( #[Serializer\Exclude] - private MessagePayloadInterface $payload, + public MessagePayloadInterface $payload, #[Serializer\SerializedName('Status')] - private ?Status $status = null, + public ?Status $status = null, #[Serializer\XmlAttribute] #[Serializer\SerializedName('Id')] - private ?string $id = null, + public ?string $id = null, #[Serializer\XmlAttribute] #[Serializer\SerializedName('inReplyTo')] - private ?string $inReplyTo = null, + public ?string $inReplyTo = null, #[Serializer\SerializedName('deploymentMode')] #[Serializer\XmlAttribute] - private ?string $deploymentMode = null, + public ?string $deploymentMode = null, ) { if (null !== $deploymentMode) { Assertion::inArray($deploymentMode, [CXml::DEPLOYMENT_PROD, CXml::DEPLOYMENT_TEST]); } } - - public function getStatus(): ?Status - { - return $this->status; - } - - public function getDeploymentMode(): ?string - { - return $this->deploymentMode; - } - - public function getInReplyTo(): ?string - { - return $this->inReplyTo; - } - - public function getId(): ?string - { - return $this->id; - } - - public function getPayload(): MessagePayloadInterface - { - return $this->payload; - } } diff --git a/src/CXml/Model/Message/ProductActivityDetail.php b/src/CXml/Model/Message/ProductActivityDetail.php index 5655b5c..6b4247f 100644 --- a/src/CXml/Model/Message/ProductActivityDetail.php +++ b/src/CXml/Model/Message/ProductActivityDetail.php @@ -5,10 +5,10 @@ namespace CXml\Model\Message; use CXml\Model\Contact; -use CXml\Model\ExtrinsicsTrait; use CXml\Model\Inventory; use CXml\Model\ItemId; use CXml\Model\MultilanguageString; +use CXml\Model\Trait\ExtrinsicsTrait; use JMS\Serializer\Annotation as Serializer; #[Serializer\AccessorOrder(order: 'custom', custom: ['itemId', 'description', 'contact', 'inventory'])] @@ -18,14 +18,14 @@ class ProductActivityDetail private function __construct( #[Serializer\SerializedName('ItemID')] - private readonly ItemId $itemId, + public readonly ItemId $itemId, #[Serializer\SerializedName('Inventory')] - private readonly ?Inventory $inventory = null, + public readonly ?Inventory $inventory = null, #[Serializer\SerializedName('Contact')] - private readonly ?Contact $contact = null, + public readonly ?Contact $contact = null, #[Serializer\SerializedName('Description')] #[Serializer\XmlElement(cdata: false)] - private readonly ?MultilanguageString $description = null, + public readonly ?MultilanguageString $description = null, ) { } @@ -33,24 +33,4 @@ public static function create(ItemId $itemId, ?Inventory $inventory = null, ?Con { return new self($itemId, $inventory, $contact, $description); } - - public function getItemId(): ItemId - { - return $this->itemId; - } - - public function getDescription(): ?MultilanguageString - { - return $this->description; - } - - public function getInventory(): ?Inventory - { - return $this->inventory; - } - - public function getContact(): ?Contact - { - return $this->contact; - } } diff --git a/src/CXml/Model/Message/ProductActivityHeader.php b/src/CXml/Model/Message/ProductActivityHeader.php index 2da5377..c65aa05 100644 --- a/src/CXml/Model/Message/ProductActivityHeader.php +++ b/src/CXml/Model/Message/ProductActivityHeader.php @@ -16,26 +16,11 @@ public function __construct( #[Serializer\SerializedName('messageID')] #[Serializer\XmlAttribute] - private string $messageId, + public string $messageId, #[Serializer\XmlAttribute] - private ?string $processType = null, + public ?string $processType = null, #[Serializer\XmlAttribute] - private ?DateTimeInterface $creationDate = null, + public ?DateTimeInterface $creationDate = null, ) { } - - public function getMessageId(): string - { - return $this->messageId; - } - - public function getProcessType(): ?string - { - return $this->processType; - } - - public function getCreationDate(): ?DateTimeInterface - { - return $this->creationDate; - } } diff --git a/src/CXml/Model/Message/ProductActivityMessage.php b/src/CXml/Model/Message/ProductActivityMessage.php index 0121e22..38aec58 100644 --- a/src/CXml/Model/Message/ProductActivityMessage.php +++ b/src/CXml/Model/Message/ProductActivityMessage.php @@ -4,7 +4,7 @@ namespace CXml\Model\Message; -use CXml\Model\ExtrinsicsTrait; +use CXml\Model\Trait\ExtrinsicsTrait; use DateTimeInterface; use JMS\Serializer\Annotation as Serializer; diff --git a/src/CXml/Model/Message/PunchOutOrderMessage.php b/src/CXml/Model/Message/PunchOutOrderMessage.php index 5b5e86b..367c31d 100644 --- a/src/CXml/Model/Message/PunchOutOrderMessage.php +++ b/src/CXml/Model/Message/PunchOutOrderMessage.php @@ -19,8 +19,8 @@ class PunchOutOrderMessage implements MessagePayloadInterface private function __construct(#[Serializer\SerializedName('BuyerCookie')] #[Serializer\XmlElement(cdata: false)] - private readonly string $buyerCookie, #[Serializer\SerializedName('PunchOutOrderMessageHeader')] - private readonly PunchOutOrderMessageHeader $punchOutOrderMessageHeader) + public readonly string $buyerCookie, #[Serializer\SerializedName('PunchOutOrderMessageHeader')] + public readonly PunchOutOrderMessageHeader $punchOutOrderMessageHeader) { } @@ -29,16 +29,6 @@ public static function create(string $buyerCookie, PunchOutOrderMessageHeader $p return new self($buyerCookie, $punchOutOrderMessageHeader); } - public function getBuyerCookie(): string - { - return $this->buyerCookie; - } - - public function getPunchOutOrderMessageHeader(): PunchOutOrderMessageHeader - { - return $this->punchOutOrderMessageHeader; - } - public function getPunchoutOrderMessageItems(): array { return $this->punchoutOrderMessageItems; diff --git a/src/CXml/Model/Message/PunchOutOrderMessageHeader.php b/src/CXml/Model/Message/PunchOutOrderMessageHeader.php index eeeaa8c..0ff4b53 100644 --- a/src/CXml/Model/Message/PunchOutOrderMessageHeader.php +++ b/src/CXml/Model/Message/PunchOutOrderMessageHeader.php @@ -33,11 +33,11 @@ class PunchOutOrderMessageHeader public function __construct( #[Serializer\SerializedName('Total')] - private readonly MoneyWrapper $total, + public readonly MoneyWrapper $total, #[Serializer\SerializedName('Shipping')] - private readonly ?Shipping $shipping = null, + public readonly ?Shipping $shipping = null, #[Serializer\SerializedName('Tax')] - private readonly ?Tax $tax = null, + public readonly ?Tax $tax = null, ?string $operationAllowed = null, ) { Assertion::inArray($operationAllowed, [self::OPERATION_CREATE, self::OPERATION_EDIT, self::OPERATION_INSPECT, null]); @@ -68,21 +68,6 @@ public function getOperationAllowed(): ?string return $this->operationAllowed; } - public function getTotal(): MoneyWrapper - { - return $this->total; - } - - public function getShipping(): ?Shipping - { - return $this->shipping; - } - - public function getTax(): ?Tax - { - return $this->tax; - } - public function getSupplierOrderInfo(): ?SupplierOrderInfo { return $this->supplierOrderInfo; diff --git a/src/CXml/Model/Message/QuoteMessage.php b/src/CXml/Model/Message/QuoteMessage.php index ce45d1c..21ee37d 100644 --- a/src/CXml/Model/Message/QuoteMessage.php +++ b/src/CXml/Model/Message/QuoteMessage.php @@ -21,22 +21,17 @@ class QuoteMessage implements MessagePayloadInterface private array $quoteMessageItems = []; private function __construct(#[Serializer\SerializedName('QuoteMessageHeader')] - private readonly QuoteMessageHeader $quoteMessageHeader) + public readonly QuoteMessageHeader $quoteMessageHeader) { } public static function create(OrganizationId $organizationId, MoneyWrapper $total, string $type, string $quoteId, DateTime $quoteDate, string $lang = 'en'): self { return new self( - new QuoteMessageHeader($organizationId, $total, $type, $quoteId, $quoteDate, $total->getMoney()->getCurrency(), $lang), + new QuoteMessageHeader($organizationId, $total, $type, $quoteId, $quoteDate, $total->money->currency, $lang), ); } - public function getQuoteMessageHeader(): QuoteMessageHeader - { - return $this->quoteMessageHeader; - } - public function getItems(): array { return $this->quoteMessageItems; diff --git a/src/CXml/Model/Message/QuoteMessageHeader.php b/src/CXml/Model/Message/QuoteMessageHeader.php index 51f9828..ae503c4 100644 --- a/src/CXml/Model/Message/QuoteMessageHeader.php +++ b/src/CXml/Model/Message/QuoteMessageHeader.php @@ -5,12 +5,12 @@ namespace CXml\Model\Message; use Assert\Assertion; -use CXml\Model\CommentsTrait; use CXml\Model\Contact; -use CXml\Model\ExtrinsicsTrait; use CXml\Model\MoneyWrapper; use CXml\Model\OrganizationId; use CXml\Model\ShipTo; +use CXml\Model\Trait\CommentsTrait; +use CXml\Model\Trait\ExtrinsicsTrait; use DateTimeInterface; use JMS\Serializer\Annotation as Serializer; @@ -44,22 +44,22 @@ class QuoteMessageHeader public function __construct( #[Serializer\SerializedName('OrganizationID')] #[Serializer\XmlElement(cdata: false)] - private readonly OrganizationId $organizationId, + public readonly OrganizationId $organizationId, #[Serializer\SerializedName('Total')] #[Serializer\XmlElement(cdata: false)] - private readonly MoneyWrapper $total, + public readonly MoneyWrapper $total, #[Serializer\XmlAttribute] #[Serializer\SerializedName('type')] - private readonly string $type, + public readonly string $type, #[Serializer\SerializedName('quoteID')] #[Serializer\XmlAttribute] - private readonly string $quoteId, + public readonly string $quoteId, #[Serializer\XmlAttribute] - private readonly DateTimeInterface $quoteDate, + public readonly DateTimeInterface $quoteDate, #[Serializer\XmlAttribute] - private readonly string $currency, + public readonly string $currency, #[Serializer\XmlAttribute(namespace: 'http://www.w3.org/XML/1998/namespace')] - private readonly string $lang = 'en', + public readonly string $lang = 'en', ) { Assertion::inArray($type, [ self::TYPE_ACCEPT, @@ -84,11 +84,6 @@ public function addContact(Contact $contact): self return $this; } - public function getOrganizationId(): OrganizationId - { - return $this->organizationId; - } - /** * @return Contact[] */ @@ -97,36 +92,6 @@ public function getContacts(): array return $this->contacts; } - public function getCurrency(): string - { - return $this->currency; - } - - public function getQuoteId(): string - { - return $this->quoteId; - } - - public function getQuoteDate(): DateTimeInterface - { - return $this->quoteDate; - } - - public function getLang(): string - { - return $this->lang; - } - - public function getTotal(): MoneyWrapper - { - return $this->total; - } - - public function getType(): string - { - return $this->type; - } - public function getShipTo(): ShipTo { return $this->shipTo; diff --git a/src/CXml/Model/Money.php b/src/CXml/Model/Money.php index 7102cc7..cf8450f 100644 --- a/src/CXml/Model/Money.php +++ b/src/CXml/Model/Money.php @@ -11,27 +11,17 @@ readonly class Money { #[Serializer\XmlValue(cdata: false)] - private string $value; + public string $value; public function __construct( #[Serializer\XmlAttribute] - private string $currency, + public string $currency, #[Serializer\Exclude] - private int $valueCent, + public int $valueCent, ) { $this->value = number_format($this->valueCent / 100, 2, '.', ''); } - public function getCurrency(): string - { - return $this->currency; - } - - public function getValue(): string - { - return $this->value; - } - public function getValueCent(): int { return $this->valueCent ?? (int)(((float)$this->value) * 100); diff --git a/src/CXml/Model/MoneyWrapper.php b/src/CXml/Model/MoneyWrapper.php index a5c22f1..c1d5501 100644 --- a/src/CXml/Model/MoneyWrapper.php +++ b/src/CXml/Model/MoneyWrapper.php @@ -9,15 +9,10 @@ readonly class MoneyWrapper { #[Serializer\SerializedName('Money')] - private Money $money; + public Money $money; public function __construct(string $currency, int $value) { $this->money = new Money($currency, $value); } - - public function getMoney(): Money - { - return $this->money; - } } diff --git a/src/CXml/Model/MultilanguageString.php b/src/CXml/Model/MultilanguageString.php index e4462d8..d3ae3a6 100644 --- a/src/CXml/Model/MultilanguageString.php +++ b/src/CXml/Model/MultilanguageString.php @@ -6,30 +6,15 @@ use JMS\Serializer\Annotation as Serializer; -class MultilanguageString +readonly class MultilanguageString { public function __construct( #[Serializer\XmlValue(cdata: false)] - private readonly ?string $value = null, + public ?string $value = null, #[Serializer\XmlAttribute] - private readonly ?string $type = null, + public ?string $type = null, #[Serializer\XmlAttribute(namespace: 'http://www.w3.org/XML/1998/namespace')] - private readonly ?string $lang = 'en', + public ?string $lang = 'en', ) { } - - public function getValue(): ?string - { - return $this->value; - } - - public function getType(): ?string - { - return $this->type; - } - - public function getLang(): ?string - { - return $this->lang; - } } diff --git a/src/CXml/Model/Option.php b/src/CXml/Model/Option.php index c007c64..10fb62c 100644 --- a/src/CXml/Model/Option.php +++ b/src/CXml/Model/Option.php @@ -10,19 +10,9 @@ { public function __construct( #[Serializer\XmlAttribute] - private string $name, + public string $name, #[Serializer\XmlValue(cdata: false)] - private string $value, + public string $value, ) { } - - public function getName(): string - { - return $this->name; - } - - public function getValue(): string - { - return $this->value; - } } diff --git a/src/CXml/Model/OrderReference.php b/src/CXml/Model/OrderReference.php index c16f7a6..272861d 100644 --- a/src/CXml/Model/OrderReference.php +++ b/src/CXml/Model/OrderReference.php @@ -12,12 +12,12 @@ { public function __construct( #[Serializer\SerializedName('DocumentReference')] - private ?DocumentReference $documentReference, + public ?DocumentReference $documentReference, #[Serializer\SerializedName('orderID')] #[Serializer\XmlAttribute] - private ?string $orderId = null, + public ?string $orderId = null, #[Serializer\XmlAttribute] - private ?DateTimeInterface $orderDate = null, + public ?DateTimeInterface $orderDate = null, ) { } @@ -27,19 +27,4 @@ public static function create(string $documentReference): self new DocumentReference($documentReference), ); } - - public function getDocumentReference(): ?DocumentReference - { - return $this->documentReference; - } - - public function getOrderId(): ?string - { - return $this->orderId; - } - - public function getOrderDate(): ?DateTimeInterface - { - return $this->orderDate; - } } diff --git a/src/CXml/Model/OrganizationId.php b/src/CXml/Model/OrganizationId.php index 14cc324..6d02447 100644 --- a/src/CXml/Model/OrganizationId.php +++ b/src/CXml/Model/OrganizationId.php @@ -11,12 +11,7 @@ { public function __construct( #[Serializer\SerializedName('Credential')] - private Credential $credential, + public Credential $credential, ) { } - - public function getCredential(): Credential - { - return $this->credential; - } } diff --git a/src/CXml/Model/PCard.php b/src/CXml/Model/PCard.php new file mode 100644 index 0000000..2434fe8 --- /dev/null +++ b/src/CXml/Model/PCard.php @@ -0,0 +1,22 @@ +credential; - } - - public function getUserAgent(): ?string - { - return $this->userAgent; - } } diff --git a/src/CXml/Model/PayloadIdentity.php b/src/CXml/Model/PayloadIdentity.php index e93d101..bda9627 100644 --- a/src/CXml/Model/PayloadIdentity.php +++ b/src/CXml/Model/PayloadIdentity.php @@ -9,20 +9,12 @@ readonly class PayloadIdentity { - private DateTimeInterface $timestamp; + public DateTimeInterface $timestamp; - public function __construct(private string $payloadId, ?DateTimeInterface $timestamp = null) - { + public function __construct( + public string $payloadId, + ?DateTimeInterface $timestamp = null, + ) { $this->timestamp = $timestamp ?? new DateTime(); } - - public function getPayloadId(): string - { - return $this->payloadId; - } - - public function getTimestamp(): DateTimeInterface - { - return $this->timestamp; - } } diff --git a/src/CXml/Model/Payment.php b/src/CXml/Model/Payment.php new file mode 100644 index 0000000..23147f6 --- /dev/null +++ b/src/CXml/Model/Payment.php @@ -0,0 +1,17 @@ +telephoneNumber; - } - - public function getName(): ?string - { - return $this->name; - } - public function getTelephoneNumberAsString(): ?string { - $countryCode = $this->telephoneNumber->getCountryCode()->getDialCode() ?? ''; - $areaOrCityCode = $this->telephoneNumber->getAreaOrCityCode(); - $telephoneNumber = $this->telephoneNumber->getNumber(); - $extension = null === $this->telephoneNumber->getExtension() ? '' : ' -' . $this->telephoneNumber->getExtension(); + $countryCode = $this->telephoneNumber->countryCode->dialCode ?? ''; + $areaOrCityCode = $this->telephoneNumber->areaOrCityCode; + $telephoneNumber = $this->telephoneNumber->number; + $extension = null === $this->telephoneNumber->extension ? '' : ' -' . $this->telephoneNumber->extension; if ('' === $telephoneNumber) { return null; diff --git a/src/CXml/Model/PostalAddress.php b/src/CXml/Model/PostalAddress.php index 5566037..dd95507 100644 --- a/src/CXml/Model/PostalAddress.php +++ b/src/CXml/Model/PostalAddress.php @@ -4,6 +4,7 @@ namespace CXml\Model; +use CXml\Model\Trait\ExtrinsicsTrait; use JMS\Serializer\Annotation as Serializer; use function array_filter; @@ -17,72 +18,32 @@ public function __construct( #[Serializer\XmlList(entry: 'DeliverTo', inline: true)] #[Serializer\Type('array')] #[Serializer\XmlElement(cdata: false)] - private readonly array $deliverTo, + public readonly array $deliverTo, #[Serializer\XmlList(entry: 'Street', inline: true)] #[Serializer\Type('array')] #[Serializer\XmlElement(cdata: false)] - private readonly array $street, + public readonly array $street, #[Serializer\SerializedName('City')] #[Serializer\XmlElement(cdata: false)] - private readonly string $city, + public readonly string $city, #[Serializer\SerializedName('Country')] #[Serializer\XmlElement(cdata: false)] - private readonly Country $country, + public readonly Country $country, #[Serializer\SerializedName('Municipality')] #[Serializer\XmlElement(cdata: false)] - private readonly ?string $municipality = null, + public readonly ?string $municipality = null, #[Serializer\SerializedName('State')] #[Serializer\XmlElement(cdata: false)] - private readonly ?string $state = null, + public readonly ?string $state = null, #[Serializer\SerializedName('PostalCode')] #[Serializer\XmlElement(cdata: false)] - private readonly ?string $postalCode = null, + public readonly ?string $postalCode = null, #[Serializer\XmlAttribute] #[Serializer\SerializedName('name')] - private readonly ?string $name = null, + public readonly ?string $name = null, ) { } - public function getName(): ?string - { - return $this->name; - } - - public function getDeliverTo(): array - { - return $this->deliverTo; - } - - public function getStreet(): array - { - return $this->street; - } - - public function getCity(): string - { - return $this->city; - } - - public function getMunicipality(): ?string - { - return $this->municipality; - } - - public function getState(): ?string - { - return $this->state; - } - - public function getPostalCode(): ?string - { - return $this->postalCode; - } - - public function getCountry(): Country - { - return $this->country; - } - /** * Convenience method to detect empty-string filled addresses. */ diff --git a/src/CXml/Model/PriceBasisQuantity.php b/src/CXml/Model/PriceBasisQuantity.php index 244d6f1..d45ac22 100644 --- a/src/CXml/Model/PriceBasisQuantity.php +++ b/src/CXml/Model/PriceBasisQuantity.php @@ -11,36 +11,16 @@ public function __construct( #[Serializer\XmlAttribute] #[Serializer\SerializedName('quantity')] - private int $quantity, + public int $quantity, #[Serializer\XmlAttribute] #[Serializer\SerializedName('conversionFactor')] - private float $conversionFactor, + public float $conversionFactor, #[Serializer\SerializedName('UnitOfMeasure')] #[Serializer\XmlElement(cdata: false)] - private string $unitOfMeasure, + public string $unitOfMeasure, #[Serializer\SerializedName('Description')] #[Serializer\XmlElement(cdata: false)] - private MultilanguageString $description, + public MultilanguageString $description, ) { } - - public function getQuantity(): int - { - return $this->quantity; - } - - public function getConversionFactor(): float - { - return $this->conversionFactor; - } - - public function getUnitOfMeasure(): string - { - return $this->unitOfMeasure; - } - - public function getDescription(): MultilanguageString - { - return $this->description; - } } diff --git a/src/CXml/Model/Request/ConfirmationHeader.php b/src/CXml/Model/Request/ConfirmationHeader.php index 6a6d004..5b41464 100644 --- a/src/CXml/Model/Request/ConfirmationHeader.php +++ b/src/CXml/Model/Request/ConfirmationHeader.php @@ -5,8 +5,8 @@ namespace CXml\Model\Request; use Assert\Assertion; -use CXml\Model\ExtrinsicsTrait; -use CXml\Model\IdReferencesTrait; +use CXml\Model\Trait\ExtrinsicsTrait; +use CXml\Model\Trait\IdReferencesTrait; use DateTime; use DateTimeInterface; use JMS\Serializer\Annotation as Serializer; @@ -36,9 +36,9 @@ class ConfirmationHeader public function __construct( #[Serializer\SerializedName('type')] #[Serializer\XmlAttribute] - private readonly string $type, + public readonly string $type, #[Serializer\XmlAttribute] - private readonly DateTimeInterface $noticeDate = new DateTime(), + public readonly DateTimeInterface $noticeDate = new DateTime(), ) { Assertion::inArray($type, [ self::TYPE_ACCEPT, @@ -59,14 +59,4 @@ public static function create(string $type, DateTimeInterface $noticeDate = new $noticeDate, ); } - - public function getType(): string - { - return $this->type; - } - - public function getNoticeDate(): DateTimeInterface - { - return $this->noticeDate; - } } diff --git a/src/CXml/Model/Request/ConfirmationRequest.php b/src/CXml/Model/Request/ConfirmationRequest.php index a5ebbf2..a911f23 100644 --- a/src/CXml/Model/Request/ConfirmationRequest.php +++ b/src/CXml/Model/Request/ConfirmationRequest.php @@ -12,9 +12,9 @@ { public function __construct( #[Serializer\SerializedName('ConfirmationHeader')] - private ConfirmationHeader $confirmationHeader, + public ConfirmationHeader $confirmationHeader, #[Serializer\SerializedName('OrderReference')] - private OrderReference $orderReference, + public OrderReference $orderReference, ) { } @@ -22,14 +22,4 @@ public static function create(ConfirmationHeader $confirmationHeader, OrderRefer { return new self($confirmationHeader, $orderReference); } - - public function getConfirmationHeader(): ConfirmationHeader - { - return $this->confirmationHeader; - } - - public function getOrderReference(): OrderReference - { - return $this->orderReference; - } } diff --git a/src/CXml/Model/Request/OrderRequest.php b/src/CXml/Model/Request/OrderRequest.php index c74e467..3828c02 100644 --- a/src/CXml/Model/Request/OrderRequest.php +++ b/src/CXml/Model/Request/OrderRequest.php @@ -18,7 +18,7 @@ class OrderRequest implements RequestPayloadInterface private array $itemOut = []; protected function __construct(#[Serializer\SerializedName('OrderRequestHeader')] - private readonly OrderRequestHeader $orderRequestHeader) + public readonly OrderRequestHeader $orderRequestHeader) { } @@ -45,11 +45,6 @@ public function addItem(ItemOut $item): self return $this; } - public function getOrderRequestHeader(): OrderRequestHeader - { - return $this->orderRequestHeader; - } - public function getItems(): array { return $this->itemOut; diff --git a/src/CXml/Model/Request/OrderRequestHeader.php b/src/CXml/Model/Request/OrderRequestHeader.php index 2ac534f..f3ca5fb 100644 --- a/src/CXml/Model/Request/OrderRequestHeader.php +++ b/src/CXml/Model/Request/OrderRequestHeader.php @@ -7,19 +7,21 @@ use Assert\Assertion; use CXml\Model\BillTo; use CXml\Model\BusinessPartner; -use CXml\Model\CommentsTrait; use CXml\Model\Contact; -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 CXml\Model\Trait\CommentsTrait; +use CXml\Model\Trait\ExtrinsicsTrait; +use CXml\Model\Trait\IdReferencesTrait; 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; @@ -28,6 +30,10 @@ class OrderRequestHeader final public const TYPE_NEW = 'new'; + final public const TYPE_UPDATE = 'update'; + + final public const TYPE_DELETE = 'delete'; + #[Serializer\XmlElement] #[Serializer\SerializedName('Shipping')] private ?Shipping $shipping = null; @@ -36,6 +42,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; @@ -50,21 +64,21 @@ class OrderRequestHeader protected function __construct( #[Serializer\XmlAttribute] #[Serializer\SerializedName('orderID')] - private readonly string $orderId, + public readonly string $orderId, #[Serializer\XmlAttribute] #[Serializer\SerializedName('orderDate')] - private readonly DateTimeInterface $orderDate, + public readonly DateTimeInterface $orderDate, ?ShipTo $shipTo, /* cant be 'readonly' bc must be initialized with null -> jms deserialization */ #[Serializer\XmlElement] #[Serializer\SerializedName('BillTo')] - private readonly BillTo $billTo, + public readonly BillTo $billTo, #[Serializer\XmlElement] #[Serializer\SerializedName('Total')] - private readonly MoneyWrapper $total, + public readonly MoneyWrapper $total, #[Serializer\XmlAttribute] - private readonly string $type = self::TYPE_NEW, + public readonly string $type = self::TYPE_NEW, #[Serializer\XmlAttribute] - private readonly ?DateTimeInterface $requestedDeliveryDate = null, + public readonly ?DateTimeInterface $requestedDeliveryDate = null, #[Serializer\Type('array')] #[Serializer\XmlList(entry: 'Contact', inline: true)] private ?array $contacts = null, @@ -74,6 +88,8 @@ protected function __construct( if (null !== $contacts) { Assertion::allIsInstanceOf($contacts, Contact::class); } + + Assertion::inArray($type, [self::TYPE_NEW, self::TYPE_UPDATE, self::TYPE_DELETE]); } public static function create( @@ -113,36 +129,11 @@ public function setTax(?Tax $tax): self return $this; } - public function getOrderId(): string - { - return $this->orderId; - } - - public function getOrderDate(): DateTimeInterface - { - return $this->orderDate; - } - - public function getType(): string - { - return $this->type; - } - - public function getTotal(): MoneyWrapper - { - return $this->total; - } - public function getShipTo(): ?ShipTo { return $this->shipTo; } - public function getBillTo(): BillTo - { - return $this->billTo; - } - public function addContact(Contact $contact): self { if (null === $this->contacts) { @@ -164,8 +155,34 @@ public function getSupplierOrderInfo(): ?SupplierOrderInfo return $this->supplierOrderInfo; } - public function addBusinessPartner(BusinessPartner $businessPartner): void + public function addBusinessPartner(BusinessPartner $businessPartner): self { $this->businessPartners[] = $businessPartner; + + return $this; + } + + public function getPayment(): ?Payment + { + return $this->payment; + } + + public function setPayment(?Payment $payment): self + { + $this->payment = $payment; + + return $this; + } + + public function getPaymentTerm(): ?PaymentTerm + { + return $this->paymentTerm; + } + + public function setPaymentTerm(?PaymentTerm $paymentTerm): self + { + $this->paymentTerm = $paymentTerm; + + return $this; } } diff --git a/src/CXml/Model/Request/PunchOutSetupRequest.php b/src/CXml/Model/Request/PunchOutSetupRequest.php index 2dc2cbb..9d1ae9b 100644 --- a/src/CXml/Model/Request/PunchOutSetupRequest.php +++ b/src/CXml/Model/Request/PunchOutSetupRequest.php @@ -4,11 +4,10 @@ namespace CXml\Model\Request; -use CXml\Model\Extrinsic; -use CXml\Model\ExtrinsicsTrait; use CXml\Model\ItemOut; use CXml\Model\SelectedItem; use CXml\Model\ShipTo; +use CXml\Model\Trait\ExtrinsicsTrait; use CXml\Model\Url; use JMS\Serializer\Annotation as Serializer; @@ -17,18 +16,11 @@ class PunchOutSetupRequest implements RequestPayloadInterface { use ExtrinsicsTrait; - /** - * @var Extrinsic[] - */ - #[Serializer\XmlList(entry: 'Extrinsic', inline: true)] - #[Serializer\Type('array')] - protected array $extrinsics = []; - #[Serializer\SerializedName('BrowserFormPost')] - private Url $browserFormPost; + public readonly Url $browserFormPost; #[Serializer\SerializedName('SupplierSetup')] - private Url $supplierSetup; + public readonly Url $supplierSetup; /** * @var ItemOut[] @@ -39,50 +31,20 @@ class PunchOutSetupRequest implements RequestPayloadInterface public function __construct( #[Serializer\SerializedName('BuyerCookie')] - private readonly string $buyerCookie, + public readonly string $buyerCookie, string $browserFormPost, string $supplierSetup, #[Serializer\SerializedName('ShipTo')] - private readonly ?ShipTo $shipTo = null, + public readonly ?ShipTo $shipTo = null, #[Serializer\SerializedName('SelectedItem')] - private readonly ?SelectedItem $selectedItem = null, + public readonly ?SelectedItem $selectedItem = null, #[Serializer\XmlAttribute] - private readonly ?string $operation = 'create', + public readonly ?string $operation = 'create', ) { $this->browserFormPost = new Url($browserFormPost); $this->supplierSetup = new Url($supplierSetup); } - public function getOperation(): ?string - { - return $this->operation; - } - - public function getBuyerCookie(): string - { - return $this->buyerCookie; - } - - public function getBrowserFormPost(): Url - { - return $this->browserFormPost; - } - - public function getSupplierSetup(): Url - { - return $this->supplierSetup; - } - - public function getShipTo(): ?ShipTo - { - return $this->shipTo; - } - - public function getSelectedItem(): ?SelectedItem - { - return $this->selectedItem; - } - public function getItems(): array { return $this->itemOut; diff --git a/src/CXml/Model/Request/Request.php b/src/CXml/Model/Request/Request.php index ada9e28..1ebdcac 100644 --- a/src/CXml/Model/Request/Request.php +++ b/src/CXml/Model/Request/Request.php @@ -14,38 +14,18 @@ { public function __construct( #[Serializer\Exclude] - private RequestPayloadInterface $payload, + public RequestPayloadInterface $payload, #[Serializer\SerializedName('Status')] - private ?Status $status = null, + public ?Status $status = null, #[Serializer\XmlAttribute] #[Serializer\SerializedName('Id')] - private ?string $id = null, + public ?string $id = null, #[Serializer\SerializedName('deploymentMode')] #[Serializer\XmlAttribute] - private ?string $deploymentMode = null, + public ?string $deploymentMode = null, ) { if (null !== $deploymentMode) { Assertion::inArray($deploymentMode, [CXml::DEPLOYMENT_PROD, CXml::DEPLOYMENT_TEST]); } } - - public function getStatus(): ?Status - { - return $this->status; - } - - public function getId(): ?string - { - return $this->id; - } - - public function getDeploymentMode(): ?string - { - return $this->deploymentMode; - } - - public function getPayload(): RequestPayloadInterface - { - return $this->payload; - } } diff --git a/src/CXml/Model/Request/ShipNoticeHeader.php b/src/CXml/Model/Request/ShipNoticeHeader.php index 552a878..4debe0c 100644 --- a/src/CXml/Model/Request/ShipNoticeHeader.php +++ b/src/CXml/Model/Request/ShipNoticeHeader.php @@ -4,10 +4,10 @@ namespace CXml\Model\Request; -use CXml\Model\CommentsTrait; use CXml\Model\DocumentReference; -use CXml\Model\ExtrinsicsTrait; -use CXml\Model\IdReferencesTrait; +use CXml\Model\Trait\CommentsTrait; +use CXml\Model\Trait\ExtrinsicsTrait; +use CXml\Model\Trait\IdReferencesTrait; use DateTime; use DateTimeInterface; use JMS\Serializer\Annotation as Serializer; @@ -20,20 +20,20 @@ class ShipNoticeHeader use CommentsTrait; #[Serializer\XmlAttribute] - private DateTimeInterface $noticeDate; + public readonly DateTimeInterface $noticeDate; #[Serializer\SerializedName('DocumentReference')] - private ?DocumentReference $documentReference; + public readonly ?DocumentReference $documentReference; public function __construct( #[Serializer\XmlAttribute] #[Serializer\SerializedName('shipmentID')] - private readonly string $shipmentId, + public readonly string $shipmentId, ?DateTimeInterface $noticeDate = null, #[Serializer\XmlAttribute] - private readonly ?DateTimeInterface $shipmentDate = null, + public readonly ?DateTimeInterface $shipmentDate = null, #[Serializer\XmlAttribute] - private readonly ?DateTimeInterface $deliveryDate = null, + public readonly ?DateTimeInterface $deliveryDate = null, ?string $documentReference = null, ) { $this->noticeDate = $noticeDate ?? new DateTime(); @@ -44,29 +44,4 @@ public static function create(string $shipmentId, ?DateTimeInterface $noticeDate { return new self($shipmentId, $noticeDate, $shipmentDate, $deliveryDate, $documentReference); } - - public function getDocumentReference(): ?DocumentReference - { - return $this->documentReference; - } - - public function getShipmentId(): string - { - return $this->shipmentId; - } - - public function getNoticeDate(): DateTimeInterface - { - return $this->noticeDate; - } - - public function getShipmentDate(): ?DateTimeInterface - { - return $this->shipmentDate; - } - - public function getDeliveryDate(): ?DateTimeInterface - { - return $this->deliveryDate; - } } diff --git a/src/CXml/Model/Request/ShipNoticeRequest.php b/src/CXml/Model/Request/ShipNoticeRequest.php index 346702d..4d04ee2 100644 --- a/src/CXml/Model/Request/ShipNoticeRequest.php +++ b/src/CXml/Model/Request/ShipNoticeRequest.php @@ -26,7 +26,7 @@ class ShipNoticeRequest implements RequestPayloadInterface private array $shipNoticePortions = []; public function __construct(#[Serializer\SerializedName('ShipNoticeHeader')] - private readonly ShipNoticeHeader $shipNoticeHeader) + public readonly ShipNoticeHeader $shipNoticeHeader) { } @@ -49,11 +49,6 @@ public function addShipNoticePortion(ShipNoticePortion $shipNoticePortion): self return $this; } - public function getShipNoticeHeader(): ShipNoticeHeader - { - return $this->shipNoticeHeader; - } - public function getShipControls(): array { return $this->shipControls; diff --git a/src/CXml/Model/Request/StatusUpdateRequest.php b/src/CXml/Model/Request/StatusUpdateRequest.php index d37e9ac..22a5a34 100644 --- a/src/CXml/Model/Request/StatusUpdateRequest.php +++ b/src/CXml/Model/Request/StatusUpdateRequest.php @@ -5,8 +5,8 @@ namespace CXml\Model\Request; use CXml\Model\DocumentReference; -use CXml\Model\ExtrinsicsTrait; use CXml\Model\Status; +use CXml\Model\Trait\ExtrinsicsTrait; use JMS\Serializer\Annotation as Serializer; #[Serializer\AccessorOrder(order: 'custom', custom: ['documentReference', 'extrinsics'])] @@ -15,11 +15,11 @@ class StatusUpdateRequest implements RequestPayloadInterface use ExtrinsicsTrait; #[Serializer\SerializedName('DocumentReference')] - private ?DocumentReference $documentReference; + public readonly ?DocumentReference $documentReference; public function __construct( #[Serializer\SerializedName('Status')] - private readonly Status $status, + public readonly Status $status, ?string $documentReference = null, ) { $this->documentReference = null !== $documentReference && '' !== $documentReference && '0' !== $documentReference ? new DocumentReference($documentReference) : null; @@ -32,14 +32,4 @@ public static function create(Status $status, ?string $documentReference = null) $documentReference, ); } - - public function getDocumentReference(): ?DocumentReference - { - return $this->documentReference; - } - - public function getStatus(): Status - { - return $this->status; - } } diff --git a/src/CXml/Model/Response/ProfileResponse.php b/src/CXml/Model/Response/ProfileResponse.php index 54f56da..f8236f0 100644 --- a/src/CXml/Model/Response/ProfileResponse.php +++ b/src/CXml/Model/Response/ProfileResponse.php @@ -14,7 +14,7 @@ class ProfileResponse implements ResponsePayloadInterface { #[Serializer\XmlAttribute] - private readonly DateTimeInterface $effectiveDate; + public readonly DateTimeInterface $effectiveDate; /** * @var Option[] @@ -33,7 +33,7 @@ class ProfileResponse implements ResponsePayloadInterface public function __construct( ?DateTimeInterface $effectiveDate = null, #[Serializer\XmlAttribute] - private readonly ?DateTimeInterface $lastRefresh = null, + public readonly ?DateTimeInterface $lastRefresh = null, ) { $this->effectiveDate = $effectiveDate ?? new DateTime(); } diff --git a/src/CXml/Model/Response/PunchOutSetupResponse.php b/src/CXml/Model/Response/PunchOutSetupResponse.php index 9d5a125..9980396 100644 --- a/src/CXml/Model/Response/PunchOutSetupResponse.php +++ b/src/CXml/Model/Response/PunchOutSetupResponse.php @@ -12,7 +12,7 @@ { public function __construct( #[Serializer\SerializedName('StartPage')] - private Url $startPage, + public Url $startPage, ) { } } diff --git a/src/CXml/Model/Response/Response.php b/src/CXml/Model/Response/Response.php index 162a757..3014153 100644 --- a/src/CXml/Model/Response/Response.php +++ b/src/CXml/Model/Response/Response.php @@ -12,27 +12,12 @@ { public function __construct( #[Serializer\SerializedName('Status')] - private Status $status, + public Status $status, #[Serializer\Exclude] - private ?ResponsePayloadInterface $payload = null, + public ?ResponsePayloadInterface $payload = null, #[Serializer\XmlAttribute] #[Serializer\SerializedName('Id')] - private ?string $id = null, + public ?string $id = null, ) { } - - public function getStatus(): Status - { - return $this->status; - } - - public function getId(): ?string - { - return $this->id; - } - - public function getPayload(): ?ResponsePayloadInterface - { - return $this->payload ?? null; - } } diff --git a/src/CXml/Model/Route.php b/src/CXml/Model/Route.php index 7bf7a18..4a0a43b 100644 --- a/src/CXml/Model/Route.php +++ b/src/CXml/Model/Route.php @@ -12,9 +12,9 @@ public function __construct( #[Serializer\XmlValue(cdata: false)] - private string $value, + public string $value, #[Serializer\XmlAttribute] - private string $method = self::METHOD_UNKNOWN, + public string $method = self::METHOD_UNKNOWN, ) { } } diff --git a/src/CXml/Model/ScheduleLine.php b/src/CXml/Model/ScheduleLine.php index 56e6dd4..0b5911b 100644 --- a/src/CXml/Model/ScheduleLine.php +++ b/src/CXml/Model/ScheduleLine.php @@ -11,13 +11,13 @@ { private function __construct( #[Serializer\SerializedName('UnitOfMeasure')] - private UnitOfMeasure $unitOfMeasure, + public UnitOfMeasure $unitOfMeasure, #[Serializer\XmlAttribute] - private int $quantity, + public int $quantity, #[Serializer\XmlAttribute] - private DateTimeInterface $requestedDeliveryDate, + public DateTimeInterface $requestedDeliveryDate, #[Serializer\XmlAttribute] - private ?int $lineNumber = null, + public ?int $lineNumber = null, ) { } } diff --git a/src/CXml/Model/SelectedItem.php b/src/CXml/Model/SelectedItem.php index 032de3a..ab34a3c 100644 --- a/src/CXml/Model/SelectedItem.php +++ b/src/CXml/Model/SelectedItem.php @@ -11,12 +11,7 @@ { public function __construct( #[Serializer\SerializedName('ItemID')] - private ItemId $itemId, + public ItemId $itemId, ) { } - - public function getItemId(): ItemId - { - return $this->itemId; - } } diff --git a/src/CXml/Model/ShipControl.php b/src/CXml/Model/ShipControl.php index c6bba6e..4ddff46 100644 --- a/src/CXml/Model/ShipControl.php +++ b/src/CXml/Model/ShipControl.php @@ -23,8 +23,10 @@ class ShipControl #[Serializer\Type('array')] private array $shipmentIdentifiers = []; - public function __construct(CarrierIdentifier $carrierIdentifier, ShipmentIdentifier $shipmentIdentifier) - { + public function __construct( + CarrierIdentifier $carrierIdentifier, + ShipmentIdentifier $shipmentIdentifier, + ) { $this->carrierIdentifiers[] = $carrierIdentifier; $this->shipmentIdentifiers[] = $shipmentIdentifier; } @@ -44,8 +46,8 @@ public function addCarrierIdentifier(string $domain, string $value): self public function getCarrierIdentifier(string $domain): ?string { foreach ($this->carrierIdentifiers as $carrierIdentifier) { - if ($carrierIdentifier->getDomain() === $domain) { - return $carrierIdentifier->getValue(); + if ($carrierIdentifier->domain === $domain) { + return $carrierIdentifier->value; } } @@ -55,8 +57,8 @@ public function getCarrierIdentifier(string $domain): ?string public function getShipmentIdentifier(?string $domain = null): ?string { foreach ($this->shipmentIdentifiers as $shipmentIdentifier) { - if ($shipmentIdentifier->getDomain() === $domain) { - return $shipmentIdentifier->getValue(); + if ($shipmentIdentifier->domain === $domain) { + return $shipmentIdentifier->value; } } diff --git a/src/CXml/Model/ShipNoticePortion.php b/src/CXml/Model/ShipNoticePortion.php index 46be96a..0546cd9 100644 --- a/src/CXml/Model/ShipNoticePortion.php +++ b/src/CXml/Model/ShipNoticePortion.php @@ -11,7 +11,7 @@ readonly class ShipNoticePortion { #[Serializer\SerializedName('OrderReference')] - private OrderReference $orderReference; + public OrderReference $orderReference; public function __construct(string $documentReference, ?string $orderId = null, ?DateTimeInterface $orderDate = null) { @@ -23,9 +23,4 @@ public function __construct(string $documentReference, ?string $orderId = null, $orderDate, ); } - - public function getOrderReference(): OrderReference - { - return $this->orderReference; - } } diff --git a/src/CXml/Model/ShipTo.php b/src/CXml/Model/ShipTo.php index 1c7a512..7c575bc 100644 --- a/src/CXml/Model/ShipTo.php +++ b/src/CXml/Model/ShipTo.php @@ -4,6 +4,7 @@ namespace CXml\Model; +use CXml\Model\Trait\IdReferencesTrait; use JMS\Serializer\Annotation as Serializer; #[Serializer\AccessorOrder(order: 'custom', custom: ['address', 'carrierIdentifiers', 'transportInformation', 'idReferences'])] @@ -19,8 +20,8 @@ class ShipTo private array $carrierIdentifiers = []; public function __construct(#[Serializer\SerializedName('Address')] - private readonly Address $address, #[Serializer\SerializedName('TransportInformation')] - private readonly ?TransportInformation $transportInformation = null) + public readonly Address $address, #[Serializer\SerializedName('TransportInformation')] + public readonly ?TransportInformation $transportInformation = null) { } @@ -30,9 +31,4 @@ public function addCarrierIdentifier(string $domain, string $identifier): self return $this; } - - public function getAddress(): Address - { - return $this->address; - } } diff --git a/src/CXml/Model/ShipmentIdentifier.php b/src/CXml/Model/ShipmentIdentifier.php index fafaf82..767dd6d 100644 --- a/src/CXml/Model/ShipmentIdentifier.php +++ b/src/CXml/Model/ShipmentIdentifier.php @@ -11,33 +11,13 @@ { public function __construct( #[Serializer\XmlValue(cdata: false)] - private string $value, + public string $value, #[Serializer\XmlAttribute] - private ?string $domain = null, + public ?string $domain = null, #[Serializer\XmlAttribute] - private ?string $trackingNumberDate = null, + public ?string $trackingNumberDate = null, #[Serializer\XmlAttribute] - private ?string $trackingURL = null, + public ?string $trackingURL = null, ) { } - - public function getDomain(): ?string - { - return $this->domain; - } - - public function getValue(): string - { - return $this->value; - } - - public function getTrackingNumberDate(): ?string - { - return $this->trackingNumberDate; - } - - public function getTrackingURL(): ?string - { - return $this->trackingURL; - } } diff --git a/src/CXml/Model/Shipping.php b/src/CXml/Model/Shipping.php index f17de1b..de24403 100644 --- a/src/CXml/Model/Shipping.php +++ b/src/CXml/Model/Shipping.php @@ -10,25 +10,15 @@ readonly class Shipping { #[Serializer\SerializedName('Money')] - private Money $money; + public Money $money; public function __construct( string $currency, int $value, #[Serializer\SerializedName('Description')] #[Serializer\XmlElement(cdata: false)] - private Description $description, + public Description $description, ) { $this->money = new Money($currency, $value); } - - public function getMoney(): Money - { - return $this->money; - } - - public function getDescription(): ?MultilanguageString - { - return $this->description; - } } diff --git a/src/CXml/Model/ShippingContractNumber.php b/src/CXml/Model/ShippingContractNumber.php index 03a9eb5..cfdfce7 100644 --- a/src/CXml/Model/ShippingContractNumber.php +++ b/src/CXml/Model/ShippingContractNumber.php @@ -10,12 +10,7 @@ { public function __construct( #[Serializer\XmlValue(cdata: false)] - private string $value, + public string $value, ) { } - - public function getValue(): string - { - return $this->value; - } } diff --git a/src/CXml/Model/Status.php b/src/CXml/Model/Status.php index 6049b8c..2c6ba6a 100644 --- a/src/CXml/Model/Status.php +++ b/src/CXml/Model/Status.php @@ -10,33 +10,13 @@ { public function __construct( #[Serializer\XmlAttribute] - private int $code = 200, + public int $code = 200, #[Serializer\XmlAttribute] - private string $text = 'OK', + public string $text = 'OK', #[Serializer\XmlValue(cdata: false)] - private ?string $message = null, + public ?string $message = null, #[Serializer\XmlAttribute(namespace: 'http://www.w3.org/XML/1998/namespace')] - private ?string $lang = null, + public ?string $lang = null, ) { } - - public function getCode(): int - { - return $this->code; - } - - public function getText(): string - { - return $this->text; - } - - public function getMessage(): ?string - { - return $this->message; - } - - public function getLang(): ?string - { - return $this->lang; - } } diff --git a/src/CXml/Model/SupplierOrderInfo.php b/src/CXml/Model/SupplierOrderInfo.php index 9d89c16..bb903d8 100644 --- a/src/CXml/Model/SupplierOrderInfo.php +++ b/src/CXml/Model/SupplierOrderInfo.php @@ -12,19 +12,9 @@ public function __construct( #[Serializer\XmlAttribute] #[Serializer\SerializedName('orderID')] - private string $orderId, + public string $orderId, #[Serializer\XmlAttribute] - private ?DateTimeInterface $orderDate = null, + public ?DateTimeInterface $orderDate = null, ) { } - - public function getOrderId(): string - { - return $this->orderId; - } - - public function getOrderDate(): ?DateTimeInterface - { - return $this->orderDate; - } } diff --git a/src/CXml/Model/Tax.php b/src/CXml/Model/Tax.php index 97c52b0..129ff02 100644 --- a/src/CXml/Model/Tax.php +++ b/src/CXml/Model/Tax.php @@ -10,7 +10,7 @@ class Tax { #[Serializer\SerializedName('Money')] - private readonly Money $money; + public readonly Money $money; /** * @var TaxDetail[] @@ -24,21 +24,11 @@ public function __construct( int $value, #[Serializer\SerializedName('Description')] #[Serializer\XmlElement(cdata: false)] - private readonly MultilanguageString $description, + public readonly MultilanguageString $description, ) { $this->money = new Money($currency, $value); } - public function getMoney(): Money - { - return $this->money; - } - - public function getDescription(): MultilanguageString - { - return $this->description; - } - public function addTaxDetail(TaxDetail $taxDetail): void { $this->taxDetails[] = $taxDetail; diff --git a/src/CXml/Model/TaxDetail.php b/src/CXml/Model/TaxDetail.php index 964392c..63e220c 100644 --- a/src/CXml/Model/TaxDetail.php +++ b/src/CXml/Model/TaxDetail.php @@ -10,13 +10,13 @@ { public function __construct( #[Serializer\XmlAttribute] - private string $category, + public string $category, #[Serializer\SerializedName('TaxAmount')] - private MoneyWrapper $taxAmount, + public MoneyWrapper $taxAmount, #[Serializer\XmlAttribute] - private ?int $percentageRate = null, + public ?int $percentageRate = null, #[Serializer\XmlAttribute] - private ?string $taxRateType = null, + public ?string $taxRateType = null, ) { } } diff --git a/src/CXml/Model/TelephoneNumber.php b/src/CXml/Model/TelephoneNumber.php index e145f9a..d93b66f 100644 --- a/src/CXml/Model/TelephoneNumber.php +++ b/src/CXml/Model/TelephoneNumber.php @@ -12,36 +12,16 @@ public function __construct( #[Serializer\SerializedName('CountryCode')] #[Serializer\XmlElement(cdata: false)] - private CountryCode $countryCode, + public CountryCode $countryCode, #[Serializer\SerializedName('AreaOrCityCode')] #[Serializer\XmlElement(cdata: false)] - private string $areaOrCityCode, + public string $areaOrCityCode, #[Serializer\SerializedName('Number')] #[Serializer\XmlElement(cdata: false)] - private string $number, + public string $number, #[Serializer\SerializedName('Extension')] #[Serializer\XmlElement(cdata: false)] - private ?string $extension = null, + public ?string $extension = null, ) { } - - public function getCountryCode(): CountryCode - { - return $this->countryCode; - } - - public function getAreaOrCityCode(): string - { - return $this->areaOrCityCode; - } - - public function getNumber(): string - { - return $this->number; - } - - public function getExtension(): ?string - { - return $this->extension; - } } diff --git a/src/CXml/Model/CommentsTrait.php b/src/CXml/Model/Trait/CommentsTrait.php similarity index 92% rename from src/CXml/Model/CommentsTrait.php rename to src/CXml/Model/Trait/CommentsTrait.php index 11eac83..41c1d8c 100644 --- a/src/CXml/Model/CommentsTrait.php +++ b/src/CXml/Model/Trait/CommentsTrait.php @@ -2,8 +2,9 @@ declare(strict_types=1); -namespace CXml\Model; +namespace CXml\Model\Trait; +use CXml\Model\Comment; use JMS\Serializer\Annotation as Serializer; use function implode; @@ -50,7 +51,7 @@ public function getCommentsAsString(): ?string $comments = $this->getComments(); if (is_array($comments)) { foreach ($comments as $comment) { - $commentStrings[] = $comment->getValue(); + $commentStrings[] = $comment->value; } } diff --git a/src/CXml/Model/ExtrinsicsTrait.php b/src/CXml/Model/Trait/ExtrinsicsTrait.php similarity index 87% rename from src/CXml/Model/ExtrinsicsTrait.php rename to src/CXml/Model/Trait/ExtrinsicsTrait.php index 7465d8a..d655670 100644 --- a/src/CXml/Model/ExtrinsicsTrait.php +++ b/src/CXml/Model/Trait/ExtrinsicsTrait.php @@ -2,8 +2,9 @@ declare(strict_types=1); -namespace CXml\Model; +namespace CXml\Model\Trait; +use CXml\Model\Extrinsic; use JMS\Serializer\Annotation as Serializer; use function trim; @@ -35,7 +36,7 @@ public function getExtrinsics(): array public function getExtrinsicByName(string $name): ?Extrinsic { foreach ($this->extrinsics as $extrinsic) { - if ($extrinsic->getName() === $name) { + if ($extrinsic->name === $name) { return $extrinsic; } } @@ -59,7 +60,7 @@ public function getExtrinsicsAsKeyValue(): array $extrinsics = []; foreach ($this->getExtrinsics() as $extrinsic) { - $extrinsics[trim($extrinsic->getName())] = trim($extrinsic->getValue()); + $extrinsics[trim($extrinsic->name)] = trim($extrinsic->value); } return $extrinsics; diff --git a/src/CXml/Model/IdReferencesTrait.php b/src/CXml/Model/Trait/IdReferencesTrait.php similarity index 82% rename from src/CXml/Model/IdReferencesTrait.php rename to src/CXml/Model/Trait/IdReferencesTrait.php index 186d79c..b9760e9 100644 --- a/src/CXml/Model/IdReferencesTrait.php +++ b/src/CXml/Model/Trait/IdReferencesTrait.php @@ -2,8 +2,9 @@ declare(strict_types=1); -namespace CXml\Model; +namespace CXml\Model\Trait; +use CXml\Model\IdReference; use JMS\Serializer\Annotation as Serializer; trait IdReferencesTrait @@ -30,8 +31,8 @@ public function getIdReferences(): array public function getIdReference(string $domain): ?string { foreach ($this->idReferences as $idReference) { - if ($idReference->getDomain() === $domain) { - return $idReference->getIdentifier(); + if ($idReference->domain === $domain) { + return $idReference->identifier; } } diff --git a/src/CXml/Model/Transaction.php b/src/CXml/Model/Transaction.php index 711310b..3ecd141 100644 --- a/src/CXml/Model/Transaction.php +++ b/src/CXml/Model/Transaction.php @@ -18,10 +18,10 @@ class Transaction public function __construct( #[Serializer\XmlAttribute] - private readonly string $requestName, + public readonly string $requestName, #[Serializer\SerializedName('URL')] #[Serializer\XmlElement(cdata: false)] - private readonly string $url, + public readonly string $url, ) { } diff --git a/src/CXml/Model/TransportInformation.php b/src/CXml/Model/TransportInformation.php index 59dc5f8..5d10c2f 100644 --- a/src/CXml/Model/TransportInformation.php +++ b/src/CXml/Model/TransportInformation.php @@ -11,9 +11,9 @@ { public function __construct( #[Serializer\SerializedName('Route')] - private ?Route $route, + public ?Route $route, #[Serializer\SerializedName('ShippingContractNumber')] - private ?ShippingContractNumber $shippingContractNumber, + public ?ShippingContractNumber $shippingContractNumber, ) { } diff --git a/src/CXml/Model/UnitOfMeasure.php b/src/CXml/Model/UnitOfMeasure.php index 41b2c5e..638f449 100644 --- a/src/CXml/Model/UnitOfMeasure.php +++ b/src/CXml/Model/UnitOfMeasure.php @@ -10,12 +10,7 @@ { public function __construct( #[Serializer\XmlValue(cdata: false)] - private string $value, + public string $value, ) { } - - public function getValue(): string - { - return $this->value; - } } diff --git a/src/CXml/Model/Url.php b/src/CXml/Model/Url.php index 54816a1..bf57f23 100644 --- a/src/CXml/Model/Url.php +++ b/src/CXml/Model/Url.php @@ -11,12 +11,7 @@ public function __construct( #[Serializer\SerializedName('URL')] #[Serializer\XmlElement(cdata: false)] - private string $url, + public string $url, ) { } - - public function getUrl(): string - { - return $this->url; - } } diff --git a/src/CXml/Processor/HeaderProcessor.php b/src/CXml/Processor/HeaderProcessor.php index 557f70e..a22d968 100644 --- a/src/CXml/Processor/HeaderProcessor.php +++ b/src/CXml/Processor/HeaderProcessor.php @@ -35,10 +35,10 @@ public function process(Header $header, Context $context): void */ private function validatePartys(Header $header): void { - $this->credentialValidator->validate($header->getFrom()->getCredential()); + $this->credentialValidator->validate($header->from->credential); - $this->credentialValidator->validate($header->getTo()->getCredential()); + $this->credentialValidator->validate($header->to->credential); - $this->credentialValidator->validate($header->getSender()->getCredential()); + $this->credentialValidator->validate($header->sender->credential); } } diff --git a/src/CXml/Processor/Processor.php b/src/CXml/Processor/Processor.php index 94fc9a5..bcc822e 100644 --- a/src/CXml/Processor/Processor.php +++ b/src/CXml/Processor/Processor.php @@ -39,19 +39,19 @@ public function process(CXml $cxml, ?Context $context = null): ?CXml $this->eventDispatcher?->dispatch(new CXmlProcessEvent($cxml, $context)); - $request = $cxml->getRequest(); + $request = $cxml->request; if ($request instanceof Request) { return $this->processRequest($request, $context); } - $response = $cxml->getResponse(); + $response = $cxml->response; if ($response instanceof Response) { $this->processResponse($response, $context); return null; } - $message = $cxml->getMessage(); + $message = $cxml->message; if ($message instanceof Message) { $this->processMessage($message, $context); @@ -74,7 +74,7 @@ private function getHandlerForPayload(PayloadInterface $payload): HandlerInterfa */ private function processMessage(Message $message, Context $context): void { - $header = $context->getCXml() instanceof CXml ? $context->getCXml()->getHeader() : null; + $header = $context->getCXml() instanceof CXml ? $context->getCXml()->header : null; if (!$header instanceof Header) { throw new CXmlException('Invalid CXml. Header is mandatory for message.'); } @@ -87,7 +87,7 @@ private function processMessage(Message $message, Context $context): void throw new CXmlProcessException($e); } - $payload = $message->getPayload(); + $payload = $message->payload; try { $this->getHandlerForPayload($payload)->handle($payload, $context); } catch (CXmlException $e) { @@ -103,7 +103,7 @@ private function processMessage(Message $message, Context $context): void */ private function processResponse(Response $response, Context $context): void { - $payload = $response->getPayload(); + $payload = $response->payload; if (!$payload instanceof ResponsePayloadInterface) { return; @@ -124,7 +124,7 @@ private function processResponse(Response $response, Context $context): void */ private function processRequest(Request $request, Context $context): CXml { - $header = $context->getCXml() instanceof CXml ? $context->getCXml()->getHeader() : null; + $header = $context->getCXml() instanceof CXml ? $context->getCXml()->header : null; if (!$header instanceof Header) { throw new CXmlException('Invalid CXml. Header is mandatory for request.'); } @@ -137,7 +137,7 @@ private function processRequest(Request $request, Context $context): CXml throw new CXmlProcessException($e); } - $payload = $request->getPayload(); + $payload = $request->payload; $handler = $this->getHandlerForPayload($payload); $response = $handler->handle($payload, $context); diff --git a/src/CXml/Serializer.php b/src/CXml/Serializer.php index 9bc279e..64e2019 100644 --- a/src/CXml/Serializer.php +++ b/src/CXml/Serializer.php @@ -30,11 +30,13 @@ { public const DOC_TYPE_VERSION = '1.2.063'; - private function __construct(private SerializerInterface $jmsSerializer) - { + private function __construct( + private SerializerInterface $jmsSerializer, + private string $dtdUri, + ) { } - public static function create(): self + public static function create(string $dtdUri = 'http://xml.cxml.org/schemas/cXML/' . self::DOC_TYPE_VERSION . '/cXML.dtd'): self { $jmsSerializer = SerializerBuilder::create() ->configureListeners(static function (EventDispatcherInterface $dispatcher): void { @@ -55,7 +57,7 @@ public static function create(): self ) ->build(); - return new self($jmsSerializer); + return new self($jmsSerializer, $dtdUri); } public function deserialize(string $xml): CXml @@ -71,11 +73,11 @@ public function deserialize(string $xml): CXml return $this->jmsSerializer->deserialize($xml, CXml::class, 'xml'); } - public function serialize(CXml $cxml, string $docTypeVersion = self::DOC_TYPE_VERSION): string + public function serialize(CXml $cxml): string { $xml = $this->jmsSerializer->serialize($cxml, 'xml'); - $docType = ''; + $docType = 'dtdUri . '">'; $xmlPrefix = ''; // add doctype, as it is mandatory in cXML diff --git a/src/CXml/Validation/DtdValidator.php b/src/CXml/Validation/DtdValidator.php index 3802923..94bb654 100644 --- a/src/CXml/Validation/DtdValidator.php +++ b/src/CXml/Validation/DtdValidator.php @@ -15,12 +15,20 @@ readonly class DtdValidator { - public function __construct(private string $pathToCxmlDtds) + public function __construct( + private array $pathToDtds, + ) { + Assertion::notEmpty($pathToDtds); + } + + public static function fromDtdDirectory(string $directory): self { - Assertion::directory($pathToCxmlDtds); - Assertion::file($pathToCxmlDtds . '/cXML.dtd'); - Assertion::file($pathToCxmlDtds . '/Fulfill.dtd'); - Assertion::file($pathToCxmlDtds . '/Quote.dtd'); + Assertion::directory($directory); + + $pathToDtds = glob($directory . '/*.dtd'); + Assertion::notEmpty($pathToDtds); + + return new self($pathToDtds); } /** @@ -38,9 +46,7 @@ public function validateAgainstDtd(string $xml): void $old = new DOMDocument(); $old->loadXML($xml); - $validateFiles = ['cXML.dtd', 'Fulfill.dtd', 'Quote.dtd']; - - $this->validateAgainstMultipleDtd($validateFiles, $old); + $this->validateAgainstMultipleDtd($this->pathToDtds, $old); // reset throwing of php errors for libxml libxml_use_internal_errors($internalErrors); @@ -54,7 +60,7 @@ private function injectDtd(DOMDocument $originalDomDocument, string $dtdFilename $creator = new DOMImplementation(); try { - $doctype = $creator->createDocumentType('cXML', '', $this->pathToCxmlDtds . '/' . $dtdFilename); + $doctype = $creator->createDocumentType('cXML', '', $dtdFilename); $new = $creator->createDocument('', '', $doctype); } catch (DOMException $domException) { throw new CXmlInvalidException($domException->getMessage(), (string)$originalDomDocument->saveXML(), $domException); diff --git a/tests/CXmlTest/Builder/OrderRequestBuilderTest.php b/tests/CXmlTest/Builder/OrderRequestBuilderTest.php index 0e53a9c..640bc6a 100644 --- a/tests/CXmlTest/Builder/OrderRequestBuilderTest.php +++ b/tests/CXmlTest/Builder/OrderRequestBuilderTest.php @@ -29,7 +29,7 @@ public function testFromPunchOutOrderMessage(): void $poom = $serializer->deserialize($poomXml); $actualOrderRequest = - OrderRequestBuilder::fromPunchOutOrderMessage($poom->getMessage()->getPayload()) + OrderRequestBuilder::fromPunchOutOrderMessage($poom->message->payload) ->billTo('name') ->build(); diff --git a/tests/CXmlTest/Handling/HandlerTest.php b/tests/CXmlTest/Handling/HandlerTest.php index db51c4b..0e53cc2 100644 --- a/tests/CXmlTest/Handling/HandlerTest.php +++ b/tests/CXmlTest/Handling/HandlerTest.php @@ -35,6 +35,11 @@ public static function getEndpointData(): iterable 'QuoteMessage', ]; + yield [ + self::loadFixture('order_request.xml'), + 'OrderRequest', + ]; + // TODO add more cases } @@ -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 = DtdValidator::fromDtdDirectory(__DIR__ . '/../../metadata/cxml/dtd/1.2.050'); $credentialRepository = new Registry(); $credentialRepository->registerCredential( @@ -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(); diff --git a/tests/CXmlTest/Handling/fixtures/order_request.xml b/tests/CXmlTest/Handling/fixtures/order_request.xml new file mode 100644 index 0000000..94b2ab6 --- /dev/null +++ b/tests/CXmlTest/Handling/fixtures/order_request.xml @@ -0,0 +1,81 @@ + + +
+ + + AN00000123 + + + + + AN00000456 + + + + + AN00000123 + Secret!123 + + Suppliers Super Order Processor + +
+ + + + + 10.00 + + +
+ TEST.USA ACME + + ACME + TEST.USA + 22 E 4th Ave + Columbus + OH + 43201-3551 + United States + +49121255566 + +
+
+ +
+ TEST.USA ACME + + ACME + TEST.USA + 22 E 4th Ave + Columbus + OH + 43201-3551 + United States + +
+
+ + + 10.00 + + + + +
+ + + QA-ACME-AUTOTEST + QA-ACME-AUTOTEST + + + + 10.00 + + Testing + EA + QA-ACME-AUTOTEST + + +
+
+
\ No newline at end of file diff --git a/tests/CXmlTest/Model/OrderRequestTest.php b/tests/CXmlTest/Model/OrderRequestTest.php index 9eb184d..af77b71 100644 --- a/tests/CXmlTest/Model/OrderRequestTest.php +++ b/tests/CXmlTest/Model/OrderRequestTest.php @@ -43,7 +43,7 @@ final class OrderRequestTest extends TestCase implements PayloadIdentityFactoryI protected function setUp(): void { - $this->dtdValidator = new DtdValidator(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/'); + $this->dtdValidator = DtdValidator::fromDtdDirectory(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/'); } public function testMinimumExample(): void diff --git a/tests/CXmlTest/Model/ProductActivityMessageTest.php b/tests/CXmlTest/Model/ProductActivityMessageTest.php index f8100a4..ca4446e 100644 --- a/tests/CXmlTest/Model/ProductActivityMessageTest.php +++ b/tests/CXmlTest/Model/ProductActivityMessageTest.php @@ -31,7 +31,7 @@ final class ProductActivityMessageTest extends TestCase implements PayloadIdenti protected function setUp(): void { - $this->dtdValidator = new DtdValidator(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/'); + $this->dtdValidator = DtdValidator::fromDtdDirectory(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/'); } public function testMinimumExample(): void diff --git a/tests/CXmlTest/Model/PunchOutSetupRequestTest.php b/tests/CXmlTest/Model/PunchOutSetupRequestTest.php index 5cb98fd..0df79a5 100644 --- a/tests/CXmlTest/Model/PunchOutSetupRequestTest.php +++ b/tests/CXmlTest/Model/PunchOutSetupRequestTest.php @@ -41,7 +41,7 @@ final class PunchOutSetupRequestTest extends TestCase implements PayloadIdentity protected function setUp(): void { - $this->dtdValidator = new DtdValidator(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/'); + $this->dtdValidator = DtdValidator::fromDtdDirectory(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/'); } public function testMinimumExample(): void diff --git a/tests/CXmlTest/Model/PunchoutOrderMessageAdvancedPricingTest.php b/tests/CXmlTest/Model/PunchoutOrderMessageAdvancedPricingTest.php index 557ff6a..a2862d6 100644 --- a/tests/CXmlTest/Model/PunchoutOrderMessageAdvancedPricingTest.php +++ b/tests/CXmlTest/Model/PunchoutOrderMessageAdvancedPricingTest.php @@ -32,7 +32,7 @@ final class PunchoutOrderMessageAdvancedPricingTest extends TestCase implements protected function setUp(): void { - $this->dtdValidator = new DtdValidator(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/'); + $this->dtdValidator = DtdValidator::fromDtdDirectory(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/'); } public function testMinimumExampleAdvPricing(): void diff --git a/tests/CXmlTest/Model/PunchoutOrderMessageTest.php b/tests/CXmlTest/Model/PunchoutOrderMessageTest.php index 67abe60..baf2878 100644 --- a/tests/CXmlTest/Model/PunchoutOrderMessageTest.php +++ b/tests/CXmlTest/Model/PunchoutOrderMessageTest.php @@ -32,7 +32,7 @@ final class PunchoutOrderMessageTest extends TestCase implements PayloadIdentity protected function setUp(): void { - $this->dtdValidator = new DtdValidator(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/'); + $this->dtdValidator = DtdValidator::fromDtdDirectory(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/'); } public function testMinimumExample(): void diff --git a/tests/CXmlTest/Model/QuoteMessageTest.php b/tests/CXmlTest/Model/QuoteMessageTest.php index b5ad51c..275bf5f 100644 --- a/tests/CXmlTest/Model/QuoteMessageTest.php +++ b/tests/CXmlTest/Model/QuoteMessageTest.php @@ -37,7 +37,7 @@ final class QuoteMessageTest extends TestCase implements PayloadIdentityFactoryI protected function setUp(): void { - $this->dtdValidator = new DtdValidator(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/'); + $this->dtdValidator = DtdValidator::fromDtdDirectory(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/'); } public function testMinimumExample(): void @@ -104,7 +104,7 @@ public function testMinimumExample(): void ), ); - $quoteMessage->getQuoteMessageHeader() + $quoteMessage->quoteMessageHeader ->addContact($contact) ->setShipTo($shipTo) ->addExtrinsicAsKeyValue('expiry_date', '2023-01-08T23:00:06-08:00') diff --git a/tests/CXmlTest/Model/SerializerTest.php b/tests/CXmlTest/Model/SerializerTest.php index 8dcc3ee..8137269 100644 --- a/tests/CXmlTest/Model/SerializerTest.php +++ b/tests/CXmlTest/Model/SerializerTest.php @@ -5,21 +5,33 @@ namespace CXmlTest\Model; use CXml\Builder\OrderRequestBuilder; +use CXml\Model\Address; +use CXml\Model\BillTo; +use CXml\Model\Country; +use CXml\Model\CountryCode; use CXml\Model\Credential; use CXml\Model\CXml; use CXml\Model\Date; +use CXml\Model\Extension\PaymentReference; use CXml\Model\Header; use CXml\Model\Message\Message; use CXml\Model\Message\PunchOutOrderMessage; use CXml\Model\Message\PunchOutOrderMessageHeader; +use CXml\Model\Money; use CXml\Model\MoneyWrapper; +use CXml\Model\MultilanguageString; use CXml\Model\Party; use CXml\Model\PayloadIdentity; +use CXml\Model\Payment; +use CXml\Model\Phone; +use CXml\Model\PostalAddress; use CXml\Model\Request\OrderRequest; +use CXml\Model\Request\OrderRequestHeader; use CXml\Model\Request\PunchOutSetupRequest; use CXml\Model\Request\Request; use CXml\Model\Response\Response; use CXml\Model\Status; +use CXml\Model\TelephoneNumber; use CXml\Serializer; use DateTime; use PHPUnit\Framework\Attributes\CoversNothing; @@ -262,7 +274,7 @@ public function testDeserializeWithMillisecondsNoTimezone(): void $serializer = Serializer::create(); $cXml = $serializer->deserialize($xmlIn); - $this->assertSame('2022-06-07T10:09:56+00:00', $cXml->getTimestamp()->format('c')); + $this->assertSame('2022-06-07T10:09:56+00:00', $cXml->timestamp->format('c')); } public function testDeserializeWithDateTimeForDate(): void @@ -289,15 +301,15 @@ public function testDeserializeWithDateTimeForDate(): void $cXml = $serializer->deserialize($xmlIn); /** @var OrderRequest $orderRequest */ - $orderRequest = $cXml->getRequest()->getPayload(); + $orderRequest = $cXml->request->payload; - $this->assertSame('2023-02-25 02:30:00', $orderRequest->getItems()[0]->getRequestedDeliveryDate()->format('Y-m-d H:i:s')); - $this->assertInstanceOf(DateTime::class, $orderRequest->getItems()[0]->getRequestedDeliveryDate()); + $this->assertSame('2023-02-25 02:30:00', $orderRequest->getItems()[0]->requestedDeliveryDate->format('Y-m-d H:i:s')); + $this->assertInstanceOf(DateTime::class, $orderRequest->getItems()[0]->requestedDeliveryDate); - $this->assertSame('2023-02-26', $orderRequest->getItems()[1]->getRequestedDeliveryDate()->format('Y-m-d')); - $this->assertInstanceOf(Date::class, $orderRequest->getItems()[1]->getRequestedDeliveryDate()); + $this->assertSame('2023-02-26', $orderRequest->getItems()[1]->requestedDeliveryDate->format('Y-m-d')); + $this->assertInstanceOf(Date::class, $orderRequest->getItems()[1]->requestedDeliveryDate); - $this->assertNull($orderRequest->getItems()[2]->getRequestedDeliveryDate()); + $this->assertNull($orderRequest->getItems()[2]->requestedDeliveryDate); } public function testDeserializeInvalidDate(): void @@ -454,10 +466,180 @@ public function testDeserializeNullProperty(): void $cxml = Serializer::create()->deserialize($xml); /** @var OrderRequest $orderRequest */ - $orderRequest = $cxml->getRequest()->getPayload(); + $orderRequest = $cxml->request->payload; // Error: Typed property CXml\Model\Request\OrderRequestHeader::$shipTo must not be accessed before initialization - $shipTo = $orderRequest->getOrderRequestHeader()->getShipTo(); + $shipTo = $orderRequest->orderRequestHeader->getShipTo(); $this->assertNull($shipTo); } + + public function testSerializePayment(): void + { + $from = new Party( + new Credential('AribaNetworkUserId', 'admin@acme.com'), + ); + $to = new Party( + new Credential('DUNS', '012345678'), + ); + $sender = new Party( + new Credential('AribaNetworkUserId', 'sysadmin@buyer.com', 'abracadabra'), + 'Network Hub 1.1', + ); + + $orderRequestHeader = OrderRequestHeader::create( + 'DO1234', + new DateTime('2000-10-12T18:41:29-08:00'), + null, + new BillTo( + new Address( + new MultilanguageString('Acme GmbH'), + new PostalAddress( + [], + [ + 'Acme Street 18', + ], + 'Solingen', + new Country('DE', 'Deutschland'), + null, + null, + '42699', + 'default', + ), + null, + null, + null, + new Phone( + new TelephoneNumber( + new CountryCode('DE', '49'), + '761', + '1234567', + ), + 'company', + ), + ), + ), + new MoneyWrapper( + 'EUR', + 8500, + ), + ); + + $payment1 = PaymentReference::create( + new Money('EUR', 1000), + 'voucher', + ) + ->addIdReference('code', 'ABC123'); + + $payment2 = PaymentReference::create( + new Money('EUR', 1000), + 'creditcard', + 'stripe', + ) + ->addIdReference('charge-id', 'ch...') + ->addExtrinsicAsKeyValue('some', 'value'); + + $payment = new Payment( + [ + $payment1, + $payment2, + ], + ); + $orderRequestHeader->setPayment($payment); + + $orderRequest = OrderRequest::create( + $orderRequestHeader, + ); + + $request = new Request( + $orderRequest, + ); + + $header = new Header( + $from, + $to, + $sender, + ); + + $msg = CXml::forRequest( + new PayloadIdentity('payload-id', new DateTime('2000-01-01')), + $request, + $header, + ); + + $actualXml = Serializer::create()->serialize($msg); + + // XML copied from cXML Reference Guide + $expectedXml = + ' + +
+ + + admin@acme.com + + + + + 012345678 + + + + + sysadmin@buyer.com + abracadabra + + Network Hub 1.1 + +
+ + + + + 85.00 + + +
+ Acme GmbH + + Acme Street 18 + Solingen + 42699 + Deutschland + + + + 49 + 761 + 1234567 + + +
+
+ + + 10.00 + + + + 10.00 + + value + + +
+
+
+
'; + + $this->assertXmlStringEqualsXmlString($expectedXml, $actualXml); + + $cxml = Serializer::create()->deserialize($actualXml); + $deserializedPayment = $cxml->request->payload->orderRequestHeader->getPayment(); + + $this->assertNotNull($deserializedPayment); + $this->assertIsArray($deserializedPayment->paymentImpl); + + $this->assertSame('voucher', $deserializedPayment->paymentImpl[0]->method); + $this->assertSame('creditcard', $deserializedPayment->paymentImpl[1]->method); + } } diff --git a/tests/CXmlTest/Model/ShipNoticeRequestTest.php b/tests/CXmlTest/Model/ShipNoticeRequestTest.php index 8e44a45..278a477 100644 --- a/tests/CXmlTest/Model/ShipNoticeRequestTest.php +++ b/tests/CXmlTest/Model/ShipNoticeRequestTest.php @@ -30,7 +30,7 @@ final class ShipNoticeRequestTest extends TestCase implements PayloadIdentityFac protected function setUp(): void { - $this->dtdValidator = new DtdValidator(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/'); + $this->dtdValidator = DtdValidator::fromDtdDirectory(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/'); } public function testMinimumExample(): void diff --git a/tests/CXmlTest/Model/StatusUpdateRequestTest.php b/tests/CXmlTest/Model/StatusUpdateRequestTest.php index df2fc92..e78c379 100644 --- a/tests/CXmlTest/Model/StatusUpdateRequestTest.php +++ b/tests/CXmlTest/Model/StatusUpdateRequestTest.php @@ -26,7 +26,7 @@ final class StatusUpdateRequestTest extends TestCase implements PayloadIdentityF protected function setUp(): void { - $this->dtdValidator = new DtdValidator(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/'); + $this->dtdValidator = DtdValidator::fromDtdDirectory(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/'); } public function testMinimumExample(): void diff --git a/tests/CXmlTest/Payload/DefaultPayloadIdentityFactoryTest.php b/tests/CXmlTest/Payload/DefaultPayloadIdentityFactoryTest.php index a3553a5..7792cf2 100644 --- a/tests/CXmlTest/Payload/DefaultPayloadIdentityFactoryTest.php +++ b/tests/CXmlTest/Payload/DefaultPayloadIdentityFactoryTest.php @@ -22,6 +22,6 @@ public function testGenerateNewPayloadId(): void DateTime::createFromFormat('U.v', '1650614400.400')); $actualIdentity = $pif->newPayloadIdentity(); - $this->assertStringStartsWith('1650614400.400', $actualIdentity->getPayloadId()); + $this->assertStringStartsWith('1650614400.400', $actualIdentity->payloadId); } } diff --git a/tests/CXmlTest/Validation/MessageValidatorTest.php b/tests/CXmlTest/Validation/MessageValidatorTest.php index 4d47e1c..d16f4fc 100644 --- a/tests/CXmlTest/Validation/MessageValidatorTest.php +++ b/tests/CXmlTest/Validation/MessageValidatorTest.php @@ -21,7 +21,7 @@ final class MessageValidatorTest extends TestCase protected function setUp(): void { - $this->dtdValidator = new DtdValidator(__DIR__ . '/../../metadata/cxml/dtd/1.2.063'); + $this->dtdValidator = DtdValidator::fromDtdDirectory(__DIR__ . '/../../metadata/cxml/dtd/1.2.063'); } public function testValidateProfileRequestSuccess(): void diff --git a/tests/metadata/cxml/dtd/1.2.050/Custom.dtd b/tests/metadata/cxml/dtd/1.2.050/Custom.dtd new file mode 100644 index 0000000..8b2bd35 --- /dev/null +++ b/tests/metadata/cxml/dtd/1.2.050/Custom.dtd @@ -0,0 +1,10 @@ + + + +%elements; + + + \ No newline at end of file