diff --git a/src/CXml/Models/Messages/BillTo.php b/src/CXml/Models/Messages/BillTo.php index 874668f..d13d549 100644 --- a/src/CXml/Models/Messages/BillTo.php +++ b/src/CXml/Models/Messages/BillTo.php @@ -28,19 +28,33 @@ class BillTo implements RequestInterface public function parse(\SimpleXMLElement $billToXml): void { - if ($data = (string) $billToXml->attributes()->isoCountryCode) { + if ($data = (string)$billToXml->attributes()->isoCountryCode) { $this->isoCountryCode = $data; } - if ($data = (string) $billToXml->attributes()->addressID) { + if ($data = (string)$billToXml->attributes()->addressID) { $this->addressId = $data; } - if ($data = (string) $billToXml->attributes()->addressIDDomain) { + if ($data = (string)$billToXml->attributes()->addressIDDomain) { $this->addressIdDomain = $data; } - $this->name = $billToXml->xpath('Name')[0]; + $name = $billToXml->xpath('Name'); - if ($postalAddressElement = current($billToXml->xpath('PostalAddress'))) { + if ($name) { + $this->name = (string)$name[0]; + } + + if (strlen($this->name) === 0) { + $this->name = (string)$billToXml->xpath('Address/Name')[0]; + } + + $postalAddressElement = current($billToXml->xpath('PostalAddress')); + + if (!$postalAddressElement) { + $postalAddressElement = current($billToXml->xpath('Address/PostalAddress')); + } + + if ($postalAddressElement) { $this->postalAddress = new PostalAddress(); $this->postalAddress->parse($postalAddressElement); } diff --git a/src/CXml/Models/Messages/Header.php b/src/CXml/Models/Messages/Header.php index 2146921..d85c37b 100644 --- a/src/CXml/Models/Messages/Header.php +++ b/src/CXml/Models/Messages/Header.php @@ -142,10 +142,18 @@ public function setSenderCredentials(array $senderCredentials): Header return $this; } - public function parse(\SimpleXMLElement $headerXml, $validate = false) : void + public function parse(\SimpleXMLElement $headerXml, $validate = false): void { - $this->senderIdentity = (string)$headerXml->xpath('Sender/Credential/Identity')[0]; - $this->senderSharedSecret = (string)$headerXml->xpath('Sender/Credential/SharedSecret')[0]; + $identity = $headerXml->xpath('Sender/Credential/Identity'); + $sharedSecret = $headerXml->xpath('Sender/Credential/SharedSecret'); + + if ($identity) { + $this->senderIdentity = (string)$identity[0]; + } + + if ($sharedSecret) { + $this->senderSharedSecret = (string)$sharedSecret[0]; + } // cXml Spec as of January 2021 @@ -160,7 +168,7 @@ public function parse(\SimpleXMLElement $headerXml, $validate = false) : void // sends payload that violates this.... if ($fromCredentials = $headerXml->xpath('From/Credential')) { $this->fromIdentity = (string)$fromCredentials[0]->xpath('Identity')[0]; - $this->fromDomain = (string)$fromCredentials[0]->attributes()->domain; + $this->fromDomain = (string)$fromCredentials[0]->attributes()->domain; $domainValidation = []; foreach ($fromCredentials as $fromCredential) { @@ -198,7 +206,7 @@ public function parse(\SimpleXMLElement $headerXml, $validate = false) : void } } - public function render(\SimpleXMLElement $parentNode) : void + public function render(\SimpleXMLElement $parentNode): void { $headerNode = $parentNode->addChild('Header'); @@ -207,8 +215,7 @@ public function render(\SimpleXMLElement $parentNode) : void foreach ($this->fromCredentials as $fromCredential) { $fromCredential->render($fromNode); } - } - else { + } else { $this->addNode($headerNode, 'From', htmlspecialchars($this->fromIdentity ?? 'Unknown', ENT_XML1 | ENT_COMPAT, 'UTF-8')); } @@ -217,8 +224,7 @@ public function render(\SimpleXMLElement $parentNode) : void foreach ($this->toCredentials as $toCredential) { $toCredential->render($toNode); } - } - else { + } else { $this->addNode($headerNode, 'To', 'Unknown'); } @@ -227,14 +233,13 @@ public function render(\SimpleXMLElement $parentNode) : void foreach ($this->senderCredentials as $senderCredential) { $senderCredential->render($senderNode); } - } - else { + } else { $this->addNode($headerNode, 'Sender', $this->getSenderIdentity() ?? 'Unknown') ->addChild('UserAgent', 'Unknown'); } } - private function addNode(\SimpleXMLElement $parentNode, string $nodeName, string $identity) : \SimpleXMLElement + private function addNode(\SimpleXMLElement $parentNode, string $nodeName, string $identity): \SimpleXMLElement { $node = $parentNode->addChild($nodeName); diff --git a/src/CXml/Models/Messages/ItemOut.php b/src/CXml/Models/Messages/ItemOut.php index 97b22eb..1233d5e 100644 --- a/src/CXml/Models/Messages/ItemOut.php +++ b/src/CXml/Models/Messages/ItemOut.php @@ -63,6 +63,10 @@ class ItemOut implements RequestInterface * @var \CXml\Models\Messages\Contact */ protected $contact; + protected $unitPrice; + protected $unitPriceCurrency; + protected $comments; + protected $description; public function parse(\SimpleXMLElement $requestNode): void { @@ -106,16 +110,30 @@ public function parse(\SimpleXMLElement $requestNode): void } if ($node = current($requestNode->xpath('ItemID/SupplierPartID'))) { - $this->itemIdSupplierPartID = (string) $node; + $this->itemIdSupplierPartID = (string)$node; } if ($node = current($requestNode->xpath('ItemID/SupplierPartAuxiliaryID'))) { - $this->itemIdSupplierPartAuxiliaryID = (string) $node; + $this->itemIdSupplierPartAuxiliaryID = (string)$node; } if ($node = current($requestNode->xpath('ItemID/BuyerPartID'))) { - $this->itemIdBuyerPartID = (string) $node; + $this->itemIdBuyerPartID = (string)$node; } if ($node = current($requestNode->xpath('ItemID/IdReference'))) { - $this->itemIdIdReference = (string) $node; + $this->itemIdIdReference = (string)$node; + } + if ($node = current($requestNode->xpath('ItemDetail/UnitPrice/Money'))) { + $this->unitPrice = (string)$node; + $attrs = $node->attributes(); + + if (isset($attrs['currency'])) { + $this->unitPriceCurrency = (string)$attrs['currency']; + } + } + if ($node = current($requestNode->xpath('Comments'))) { + $this->comments = (string)$node; + } + if ($node = current($requestNode->xpath('ItemDetail/Description'))) { + $this->description = (string)$node; } } @@ -191,7 +209,8 @@ public function getItemIdSupplierPartAuxiliaryID() */ public function setItemIdSupplierPartAuxiliaryID( $itemIdSupplierPartAuxiliaryID - ): self { + ): self + { $this->itemIdSupplierPartAuxiliaryID = $itemIdSupplierPartAuxiliaryID; return $this; } @@ -747,4 +766,68 @@ public function setContact(Contact $contact): self return $this; } + /** + * @return mixed + */ + public function getUnitPrice() + { + return $this->unitPrice; + } + + /** + * @param mixed $unitPrice + */ + public function setUnitPrice($unitPrice): void + { + $this->unitPrice = $unitPrice; + } + + /** + * @return mixed + */ + public function getUnitPriceCurrency() + { + return $this->unitPriceCurrency; + } + + /** + * @param mixed $unitPriceCurrency + */ + public function setUnitPriceCurrency($unitPriceCurrency): void + { + $this->unitPriceCurrency = $unitPriceCurrency; + } + + /** + * @return mixed + */ + public function getComments() + { + return $this->comments; + } + + /** + * @param mixed $comments + */ + public function setComments($comments): void + { + $this->comments = $comments; + } + + /** + * @return mixed + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param mixed $description + */ + public function setDescription($description): void + { + $this->description = $description; + } + } diff --git a/src/CXml/Models/Messages/PostalAddress.php b/src/CXml/Models/Messages/PostalAddress.php index ddc58e9..71bca5a 100644 --- a/src/CXml/Models/Messages/PostalAddress.php +++ b/src/CXml/Models/Messages/PostalAddress.php @@ -22,6 +22,8 @@ class PostalAddress implements RequestInterface, MessageInterface * Optional Properties */ + private $isoCountryCode; + /** * @var string[] */ @@ -38,6 +40,11 @@ public function getCountry() return $this->country; } + public function getISOCountryCode() + { + return $this->isoCountryCode; + } + /** * @param string $country * @@ -163,37 +170,45 @@ public function setPostalCode($postalCode) return $this; } - public function parse(\SimpleXMLElement $contactXml) : void + public function parse(\SimpleXMLElement $contactXml): void { if ($data = $contactXml->xpath('Country')) { - $this->country = (string) current($data); + $current = current($data); + + $attr = $current->attributes(); + + if ($attr && isset($attr->isoCountryCode)) { + $this->isoCountryCode = (string)$attr->isoCountryCode; + } + + $this->country = (string)$current; } if ($data = $contactXml->xpath('City')) { - $this->city = (string) current($data); + $this->city = (string)current($data); } if ($data = $contactXml->xpath('Street')) { foreach ($data as $street) { - $this->street[] = (string) $street; + $this->street[] = (string)$street; } } if ($data = $contactXml->xpath('DeliverTo')) { foreach ($data as $deliverTo) { - $this->deliverTo[] = (string) $deliverTo; + $this->deliverTo[] = (string)$deliverTo; } } if ($data = $contactXml->xpath('Municipality')) { - $this->municipality = (string) current($data); + $this->municipality = (string)current($data); } if ($data = $contactXml->xpath('State')) { - $this->state = (string) current($data); + $this->state = (string)current($data); } if ($data = $contactXml->xpath('PostalCode')) { - $this->postalCode = (string) current($data); + $this->postalCode = (string)current($data); } } - public function render(\SimpleXMLElement $parentNode) : void + public function render(\SimpleXMLElement $parentNode): void { if ($this->country) { $parentNode->addChild('Country', htmlspecialchars($this->country, ENT_XML1 | ENT_COMPAT, 'UTF-8')); diff --git a/src/CXml/Models/Messages/ShipTo.php b/src/CXml/Models/Messages/ShipTo.php index 433c6d6..63a8f8a 100644 --- a/src/CXml/Models/Messages/ShipTo.php +++ b/src/CXml/Models/Messages/ShipTo.php @@ -20,30 +20,44 @@ class ShipTo implements RequestInterface /** * @var \CXml\Models\Messages\PostalAddress */ - private $address; + private $postalAddress; protected $isoCountryCode; protected $addressId; protected $addressIdDomain; - public function parse(\SimpleXMLElement $billToXml) : void + public function parse(\SimpleXMLElement $billToXml): void { - if ($data = (string) $billToXml->attributes()->isoCountryCode) { + if ($data = (string)$billToXml->attributes()->isoCountryCode) { $this->isoCountryCode = $data; } - if ($data = (string) $billToXml->attributes()->addressID) { + if ($data = (string)$billToXml->attributes()->addressID) { $this->addressId = $data; } - if ($data = (string) $billToXml->attributes()->addressIDDomain) { + if ($data = (string)$billToXml->attributes()->addressIDDomain) { $this->addressIdDomain = $data; } - $this->name = $billToXml->xpath('Name')[0]; + $name = $billToXml->xpath('Name'); - if ($postalAddressElement = current($billToXml->xpath('PostalAddress'))) { - $this->address = new PostalAddress(); - $this->address->parse($postalAddressElement); + if ($name) { + $this->name = (string)$name[0]; + } + + if (strlen($this->name) === 0 && $billToXml->xpath('Address/Name')) { + $this->name = (string)$billToXml->xpath('Address/Name')[0]; + } + + $postalAddressElement = current($billToXml->xpath('PostalAddress')); + + if (!$postalAddressElement) { + $postalAddressElement = current($billToXml->xpath('Address/PostalAddress')); + } + + if ($postalAddressElement) { + $this->postalAddress = new PostalAddress(); + $this->postalAddress->parse($postalAddressElement); } } @@ -69,7 +83,7 @@ public function setName($name) /** * @return \CXml\Models\Messages\PostalAddress */ - public function getPostalAddress(): PostalAddress + public function getPostalAddress(): ?PostalAddress { return $this->postalAddress; } diff --git a/src/CXml/Models/Requests/OrderRequest.php b/src/CXml/Models/Requests/OrderRequest.php index 2e5fb4d..0fc264d 100644 --- a/src/CXml/Models/Requests/OrderRequest.php +++ b/src/CXml/Models/Requests/OrderRequest.php @@ -16,6 +16,7 @@ class OrderRequest implements RequestInterface protected $orderID; protected $orderDate; + protected $orderVersion; /** * Type of order: @@ -37,17 +38,22 @@ class OrderRequest implements RequestInterface protected $type; /** - * @var float|null + * @var float|null */ protected $total; /** - * @var string|null + * @var string|null + */ + protected $currency; + + /** + * @var ShipTo|null */ protected $shipTo; /** - * @var BillTo + * @var BillTo|null */ protected $billTo; @@ -55,31 +61,42 @@ class OrderRequest implements RequestInterface protected $tax; /** - * @var \CXml\Models\Messages\Contact + * @var \CXml\Models\Messages\Contact */ protected $contact; /** - * @var \CXml\Models\Messages\ItemOut[] + * @var \CXml\Models\Messages\ItemOut[] */ protected $itemOut = []; + protected $comments; /** - * @noinspection PhpUndefinedFieldInspection + * @noinspection PhpUndefinedFieldInspection */ public function parse(\SimpleXMLElement $requestNode): void { + $requestHeader = current($requestNode->xpath('OrderRequestHeader')); + $this->parseAttributes( - $requestNode, [ + $requestHeader, [ 'orderID', 'orderDate', 'orderType', + 'orderVersion', 'type', ] ); + $this->parseAttributes( + current($requestNode->xpath('OrderRequestHeader/Total/Money')), [ + 'currency', + ] + ); + $this->parseEntrinsic($requestNode); + $this->parseEntrinsic($requestHeader); foreach ($requestNode->xpath('ItemOut') as $itemOutElement) { $itemOut = new ItemOut(); @@ -99,9 +116,11 @@ public function parse(\SimpleXMLElement $requestNode): void $this->shipTo = new ShipTo(); $this->shipTo->parse($node); } - $this->total = (string) current($requestNode->xpath('OrderRequestHeader/Total')); - $this->shipping = (string) current($requestNode->xpath('OrderRequestHeader/Shipping')); - $this->tax = (string) current($requestNode->xpath('OrderRequestHeader/Tax')); + $totalMoney = $requestNode->xpath('OrderRequestHeader/Total/Money'); + $this->total = (string) current($totalMoney); + $this->shipping = (string) current($requestNode->xpath('OrderRequestHeader/Shipping/Money')); + $this->tax = (string) current($requestNode->xpath('OrderRequestHeader/Tax/Money')); + $this->comments = (string) current($requestNode->xpath('OrderRequestHeader/Comments')); } /** @@ -109,7 +128,7 @@ public function parse(\SimpleXMLElement $requestNode): void */ public function getOrderId() { - return $this->orderId; + return $this->orderID; } /** @@ -119,7 +138,7 @@ public function getOrderId() */ public function setOrderId($orderId) { - $this->orderId = $orderId; + $this->orderID = $orderId; return $this; } @@ -200,38 +219,38 @@ public function setTotal(?float $total): OrderRequest } /** - * @return string|null + * @return ShipTo|null */ - public function getShipTo(): ?string + public function getShipTo(): ?ShipTo { return $this->shipTo; } /** - * @param string|null $shipTo + * @param ShipTo|null $shipTo * * @return OrderRequest */ - public function setShipTo(?string $shipTo): OrderRequest + public function setShipTo(?ShipTo $shipTo): OrderRequest { $this->shipTo = $shipTo; return $this; } /** - * @return string|null + * @return BillTo|null */ - public function getBillTo(): ?string + public function getBillTo(): ?BillTo { return $this->billTo; } /** - * @param string|null $billTo + * @param BillTo|null $billTo * * @return OrderRequest */ - public function setBillTo(?string $billTo): OrderRequest + public function setBillTo(?BillTo $billTo): OrderRequest { $this->billTo = $billTo; return $this; @@ -579,4 +598,36 @@ public function setItemOut(array $itemOut): OrderRequest return $this; } + /** + * @return mixed + */ + public function getOrderVersion() + { + return $this->orderVersion; + } + + /** + * @param mixed $orderVersion + */ + public function setOrderVersion($orderVersion): void + { + $this->orderVersion = $orderVersion; + } + + /** + * @return string|null + */ + public function getCurrency(): ?string + { + return $this->currency; + } + + /** + * @param string|null $currency + */ + public function setCurrency(?string $currency): void + { + $this->currency = $currency; + } + } diff --git a/src/CXml/Models/Requests/PunchOutSetupRequest.php b/src/CXml/Models/Requests/PunchOutSetupRequest.php index 027000c..cdf5837 100644 --- a/src/CXml/Models/Requests/PunchOutSetupRequest.php +++ b/src/CXml/Models/Requests/PunchOutSetupRequest.php @@ -5,6 +5,7 @@ use CXml\Models\Messages\Contact; use CXml\Models\EntrinsicTrait; use CXml\Models\Messages\SelectedItem; +use CXml\Models\Messages\ShipTo; class PunchOutSetupRequest implements RequestInterface { @@ -30,6 +31,11 @@ class PunchOutSetupRequest implements RequestInterface */ private $contact = []; + /** + * @var \CXml\Models\Messages\ShipTo[] + */ + private $shipTo = []; + /** * @var \CXml\Models\Messages\SelectedItem|null */ @@ -55,6 +61,12 @@ public function parse(\SimpleXMLElement $requestNode): void $contact->parse($contactElement); $this->contact[] = $contact; } + + foreach ($requestNode->xpath('ShipTo/Address') as $shipToElement) { + $shipTo = new ShipTo(); + $shipTo->parse($shipToElement); + $this->shipTo[] = $shipTo; + } } public function getOperation(): ?string @@ -98,6 +110,14 @@ public function getContact(): array return $this->contact; } + /** + * @return \CXml\Models\Messages\ShipTo[] + */ + public function getShipTo(): array + { + return $this->shipTo; + } + /** * @param \CXml\Models\Messages\Contact[] $contact *