diff --git a/src/Factory/Xml/Order/ExtraBillingAttributesFactory.php b/src/Factory/Xml/Order/ExtraBillingAttributesFactory.php new file mode 100644 index 0000000..9124da1 --- /dev/null +++ b/src/Factory/Xml/Order/ExtraBillingAttributesFactory.php @@ -0,0 +1,30 @@ +LegalId, + (string) $element->FiscalPerson, + (string) $element->DocumentType, + (string) $element->ReceiverRegion, + (string) $element->ReceiverAddress, + (string) $element->ReceiverPostcode, + (string) $element->ReceiverLegalName, + (string) $element->ReceiverMunicipality, + (string) $element->ReceiverTypeRegimen, + (string) $element->CustomerVerifierDigit, + (string) $element->ReceiverLocality, + (string) $element->ReceiverEmail, + (string) $element->ReceiverPhonenumber + ); + } +} diff --git a/src/Factory/Xml/Order/OrderFactory.php b/src/Factory/Xml/Order/OrderFactory.php index 72c6a70..bb81ace 100644 --- a/src/Factory/Xml/Order/OrderFactory.php +++ b/src/Factory/Xml/Order/OrderFactory.php @@ -82,6 +82,9 @@ public static function make(SimpleXMLElement $element): Order : null ); + $extraBillingAttributes = !empty($element->ExtraBillingAttributes) ? + ExtraBillingAttributesFactory::make($element->ExtraBillingAttributes) : null; + return Order::fromData( (int) $element->OrderId, $orderNumber, @@ -106,7 +109,8 @@ public static function make(SimpleXMLElement $element): Order $statuses, $businessInvoiceRequired, $shippingType, - $operatorCode + $operatorCode, + $extraBillingAttributes ); } } diff --git a/src/Model/Order/ExtraBillingAttributes.php b/src/Model/Order/ExtraBillingAttributes.php new file mode 100644 index 0000000..355d471 --- /dev/null +++ b/src/Model/Order/ExtraBillingAttributes.php @@ -0,0 +1,191 @@ +legalId = !empty($legalId) ? $legalId : null; + $this->fiscalPerson = !empty($fiscalPerson) ? $fiscalPerson : null; + $this->documentType = !empty($documentType) ? $documentType : null; + $this->receiverRegion = !empty($receiverRegion) ? $receiverRegion : null; + $this->receiverAddress = !empty($receiverAddress) ? $receiverAddress : null; + $this->receiverPostcode = !empty($receiverPostcode) ? $receiverPostcode : null; + $this->receiverLegalName = !empty($receiverLegalName) ? $receiverLegalName : null; + $this->receiverMunicipality = !empty($receiverMunicipality) ? $receiverMunicipality : null; + $this->receiverTypeRegimen = !empty($receiverTypeRegimen) ? $receiverTypeRegimen : null; + $this->customerVerifierDigit = !empty($customerVerifierDigit) ? $customerVerifierDigit : null; + $this->receiverLocality = !empty($receiverLocality) ? $receiverLocality : null; + $this->receiverEmail = !empty($receiverEmail) ? $receiverEmail : null; + $this->receiverPhonenumber = !empty($receiverPhonenumber) ? $receiverPhonenumber : null; + } + + public function getLegalId(): ?string + { + return $this->legalId; + } + + public function getFiscalPerson(): ?string + { + return $this->fiscalPerson; + } + + public function getDocumentType(): ?string + { + return $this->documentType; + } + + public function getReceiverRegion(): ?string + { + return $this->receiverRegion; + } + + public function getReceiverAddress(): ?string + { + return $this->receiverAddress; + } + + public function getReceiverPostCode(): ?string + { + return $this->receiverPostcode; + } + + public function getReceiverLegalName(): ?string + { + return $this->receiverLegalName; + } + + public function getReceiverMunicipality(): ?string + { + return $this->receiverMunicipality; + } + + public function getReceiverTypeRegimen(): ?string + { + return $this->receiverTypeRegimen; + } + + public function getReceiverEmail(): ?string + { + return $this->receiverEmail; + } + + public function getCustomerVerifierDigit(): ?string + { + return $this->customerVerifierDigit; + } + + public function getReceiverLocality(): ?string + { + return $this->receiverLocality; + } + + public function getReceiverPhoneNumber(): ?string + { + return $this->receiverPhonenumber; + } + + public function jsonSerialize(): stdClass + { + $serialized = new stdClass(); + $serialized->legalId = $this->legalId; + $serialized->fiscalPerson = $this->fiscalPerson; + $serialized->documentType = $this->documentType; + $serialized->receiverRegion = $this->receiverRegion; + $serialized->receiverAddress = $this->receiverAddress; + $serialized->receiverPostcode = $this->receiverPostcode; + $serialized->receiverLegalName = $this->receiverLegalName; + $serialized->receiverMunicipality = $this->receiverMunicipality; + $serialized->receiverTypeRegimen = $this->receiverTypeRegimen; + $serialized->customerVerifierDigit = $this->customerVerifierDigit; + $serialized->receiverLocality = $this->receiverLocality; + $serialized->receiverEmail = $this->receiverEmail; + $serialized->receiverPhonenumber = $this->receiverPhonenumber; + + return $serialized; + } +} diff --git a/src/Model/Order/Order.php b/src/Model/Order/Order.php index 7eab0fa..1149dfe 100644 --- a/src/Model/Order/Order.php +++ b/src/Model/Order/Order.php @@ -135,6 +135,11 @@ class Order implements JsonSerializable */ protected $shippingType; + /** + * @var ExtraBillingAttributes|null + */ + protected $extraBillingAttributes; + /** * @param string[] $statuses * @param string|int $orderNumber @@ -163,7 +168,8 @@ public static function fromData( array $statuses, ?bool $businessInvoiceRequired, ?string $shippingType, - ?string $operatorCode = null + ?string $operatorCode = null, + ?ExtraBillingAttributes $extraBillingAttributes = null ): Order { $order = new self(); @@ -190,6 +196,7 @@ public static function fromData( $order->statuses = $statuses; $order->businessInvoiceRequired = $businessInvoiceRequired; $order->shippingType = $shippingType; + $order->extraBillingAttributes = $extraBillingAttributes; $order->operatorCode = $operatorCode; return $order; @@ -340,6 +347,11 @@ public function getShippingType(): ?string return $this->shippingType; } + public function getExtraBillingAttributes(): ?ExtraBillingAttributes + { + return $this->extraBillingAttributes; + } + public function setOrderItems(OrderItems $orderItems): void { $this->orderItems = $orderItems; @@ -372,6 +384,7 @@ public function jsonSerialize(): stdClass $serialized->orderItems = $this->orderItems; $serialized->businessInvoiceRequired = $this->businessInvoiceRequired; $serialized->shippingType = $this->shippingType; + $serialized->extraBillingAttributes = $this->extraBillingAttributes; $serialized->operatorCode = $this->operatorCode; return $serialized; diff --git a/tests/Unit/Order/ExtraBillingAttributesTest.php b/tests/Unit/Order/ExtraBillingAttributesTest.php new file mode 100644 index 0000000..f35ae56 --- /dev/null +++ b/tests/Unit/Order/ExtraBillingAttributesTest.php @@ -0,0 +1,114 @@ +createXmlStringForBillingInformation()); + + $billingInformation = ExtraBillingAttributesFactory::make($simpleXml); + + $this->assertInstanceOf(ExtraBillingAttributes::class, $billingInformation); + $this->assertEquals($simpleXml->LegalId, $billingInformation->getLegalId()); + $this->assertEquals($simpleXml->FiscalPerson, $billingInformation->getFiscalPerson()); + $this->assertEquals($simpleXml->DocumentType, $billingInformation->getDocumentType()); + $this->assertEquals($simpleXml->ReceiverRegion, $billingInformation->getReceiverRegion()); + $this->assertEquals($simpleXml->ReceiverAddress, $billingInformation->getReceiverAddress()); + $this->assertEquals($simpleXml->ReceiverPostcode, $billingInformation->getReceiverPostCode()); + $this->assertEquals($simpleXml->ReceiverLegalName, $billingInformation->getReceiverLegalName()); + $this->assertEquals($simpleXml->ReceiverMunicipality, $billingInformation->getReceiverMunicipality()); + $this->assertEquals($simpleXml->ReceiverTypeRegimen, $billingInformation->getReceiverTypeRegimen()); + $this->assertEquals($simpleXml->CustomerVerifierDigit, $billingInformation->getCustomerVerifierDigit()); + $this->assertEquals($simpleXml->ReceiverLocality, $billingInformation->getReceiverLocality()); + $this->assertEquals($simpleXml->ReceiverEmail, $billingInformation->getReceiverEmail()); + $this->assertEquals($simpleXml->ReceiverPhonenumber, $billingInformation->getReceiverPhoneNumber()); + } + + public function testItReturnsAJsonRepresentation(): void + { + $xml = $this->createXmlStringForBillingInformation(); + + $simpleXml = simplexml_load_string($xml); + + $billingInformation = ExtraBillingAttributesFactory::make($simpleXml); + + $expectedJson = Json::decode($this->getSchema('Order/ExtraBillingAttributes.json')); + $expectedJson['legalId'] = $this->legalId; + $expectedJson['fiscalPerson'] = $this->fiscalPerson; + $expectedJson['documentType'] = $this->documentType; + $expectedJson['receiverRegion'] = $this->receiverRegion; + $expectedJson['receiverAddress'] = $this->receiverAddress; + $expectedJson['receiverPostcode'] = $this->receiverPostcode; + $expectedJson['receiverLegalName'] = $this->receiverLegalName; + $expectedJson['receiverMunicipality'] = $this->receiverMunicipality; + $expectedJson['receiverTypeRegimen'] = $this->receiverTypeRegimen; + $expectedJson['customerVerifierDigit'] = $this->customerVerifierDigit; + $expectedJson['receiverLocality'] = $this->receiverLocality; + $expectedJson['receiverEmail'] = $this->receiverEmail; + $expectedJson['receiverPhonenumber'] = $this->receiverPhonenumber; + + $this->assertJsonStringEqualsJsonString(Json::encode($expectedJson), Json::encode($billingInformation)); + } + + public function createXmlStringForBillingInformation(string $schema = 'Order/ExtraBillingAttributes.xml'): string + { + return sprintf( + $this->getSchema($schema), + $this->legalId, + $this->fiscalPerson, + $this->documentType, + $this->receiverRegion, + $this->receiverAddress, + $this->receiverPostcode, + $this->receiverLegalName, + $this->receiverMunicipality, + $this->receiverTypeRegimen, + $this->customerVerifierDigit, + $this->receiverLocality, + $this->receiverEmail, + $this->receiverPhonenumber + ); + } + + public function invalidXmlStructure(): array + { + return [ + ['LegalId'], + ['FiscalPerson'], + ['DocumentType'], + ['ReceiverRegion'], + ['ReceiverAddress'], + ['ReceiverPostcode'], + ['ReceiverLegalName'], + ['ReceiverMunicipality'], + ['ReceiverTypeRegimen'], + ['CustomerVerifierDigit'], + ['ReceiverLocality'], + ['ReceiverEmail'], + ['ReceiverPhonenumber'], + ]; + } +} diff --git a/tests/Unit/Order/OrderTest.php b/tests/Unit/Order/OrderTest.php index 74ad9d1..1cebf4c 100644 --- a/tests/Unit/Order/OrderTest.php +++ b/tests/Unit/Order/OrderTest.php @@ -41,7 +41,19 @@ class OrderTest extends LinioTestCase protected $city = 'city'; protected $postCode = '10117'; protected $country = 'country'; - + protected $legalId = '77656276-9'; + protected $fiscalPerson = 'business'; + protected $documentType = 'RUT'; + protected $receiverRegion = 'METROPOLITANA DE SANTIAGO'; + protected $receiverAddress = 'JOSE MANUEL INFANTE 1155, 902 PROVIDENCIA'; + protected $receiverPostcode = '97873'; + protected $receiverLegalName = 'COMERCIALIZADORA VIPAZ SPA'; + protected $receiverMunicipality = 'PROVIDENCIA'; + protected $receiverTypeRegimen = '475201 - VENTA AL POR MENOR DE ARTÍCULOS DE FERRETERÍA Y MATERIALES DE CONSTRUCCIÓN'; + protected $customerVerifierDigit = '9'; + protected $receiverLocality = 'PROVIDENCIA'; + protected $receiverEmail = 'comercializadora.vipaz@gmail.com'; + protected $receiverPhonenumber = '+56999100109'; protected $nationalRegistrationNumber = '72201776'; protected $itemsCount = 1; protected $promisedShippingTime = '2018-07-18 23:59:59'; diff --git a/tests/_schemas/Order/ExtraBillingAttributes.json b/tests/_schemas/Order/ExtraBillingAttributes.json new file mode 100644 index 0000000..b4e8204 --- /dev/null +++ b/tests/_schemas/Order/ExtraBillingAttributes.json @@ -0,0 +1,15 @@ +{ + "legalId": "%s", + "fiscalPerson": "%s", + "documentType": "%s", + "receiverRegion": "%s", + "receiverAddress": "%s", + "receiverPostcode": "%s", + "receiverLegalName": "%s", + "receiverMunicipality": "%s", + "receiverTypeRegimen": "%s", + "customerVerifierDigit": "%s", + "receiverLocality": "%s", + "receiverEmail": "%s", + "receiverPhonenumber": "%s" +} \ No newline at end of file diff --git a/tests/_schemas/Order/ExtraBillingAttributes.xml b/tests/_schemas/Order/ExtraBillingAttributes.xml new file mode 100644 index 0000000..ae2e2bf --- /dev/null +++ b/tests/_schemas/Order/ExtraBillingAttributes.xml @@ -0,0 +1,16 @@ + + + 77656276-9 + business + RUT + METROPOLITANA DE SANTIAGO + JOSE MANUEL INFANTE 1155, 902 PROVIDENCIA + - + COMERCIALIZADORA VIPAZ SPA + PROVIDENCIA + 475201 - VENTA AL POR MENOR DE ARTÍCULOS DE FERRETERÍA Y MATERIALES DE CONSTRUCCIÓN + 9 + PROVIDENCIA + comercializadora.vipaz@gmail.com + +56999100109 + \ No newline at end of file diff --git a/tests/_schemas/Order/Order.json b/tests/_schemas/Order/Order.json index 5ca7bfc..9bd9457 100644 --- a/tests/_schemas/Order/Order.json +++ b/tests/_schemas/Order/Order.json @@ -55,6 +55,21 @@ "%s", "%s" ], + "extraBillingAttributes": { + "legalId": null, + "fiscalPerson": null, + "documentType": null, + "receiverRegion": null, + "receiverAddress": null, + "receiverPostcode": null, + "receiverLegalName":null, + "receiverMunicipality": null, + "receiverTypeRegimen": null, + "customerVerifierDigit": null, + "receiverLocality": null, + "receiverEmail": null, + "receiverPhonenumber": null + }, "businessInvoiceRequired": null, "shippingType": null, "orderItems": null diff --git a/tests/_schemas/Order/Order.xml b/tests/_schemas/Order/Order.xml index 2252499..dd79f6e 100644 --- a/tests/_schemas/Order/Order.xml +++ b/tests/_schemas/Order/Order.xml @@ -52,6 +52,21 @@ %s %s %s + + + + + + + + + + + + + + + %s %s diff --git a/tests/_schemas/Order/OrderResponse.xml b/tests/_schemas/Order/OrderResponse.xml index eba66be..85952b3 100644 --- a/tests/_schemas/Order/OrderResponse.xml +++ b/tests/_schemas/Order/OrderResponse.xml @@ -61,6 +61,21 @@ 1 2018-08-28 16:00:00 + + + + + + + + + + + + + + + delivered pending diff --git a/tests/_schemas/Order/OrderWithOrderItems.json b/tests/_schemas/Order/OrderWithOrderItems.json index 382c975..8b5b024 100644 --- a/tests/_schemas/Order/OrderWithOrderItems.json +++ b/tests/_schemas/Order/OrderWithOrderItems.json @@ -20,6 +20,7 @@ "promisedShippingTime": null, "extraAttributes": null, "statuses": null, + "extraBillingAttributes": null, "businessInvoiceRequired": null, "shippingType": null, "operatorCode": null, diff --git a/tests/_schemas/Order/Orders.xml b/tests/_schemas/Order/Orders.xml index 60891ed..e54d26f 100644 --- a/tests/_schemas/Order/Orders.xml +++ b/tests/_schemas/Order/Orders.xml @@ -112,6 +112,21 @@ 1 2018-08-28 16:00:00 + + + + + + + + + + + + + + + true delivered diff --git a/tests/_schemas/Order/OrdersResponse.xml b/tests/_schemas/Order/OrdersResponse.xml index 00be922..a620ced 100644 --- a/tests/_schemas/Order/OrdersResponse.xml +++ b/tests/_schemas/Order/OrdersResponse.xml @@ -61,6 +61,21 @@ 1 2018-08-28 16:00:00 + + 77656276-9 + business + RUT + METROPOLITANA DE SANTIAGO + JOSE MANUEL INFANTE 1155, 902 PROVIDENCIA + - + COMERCIALIZADORA VIPAZ SPA + PROVIDENCIA + 475201 - VENTA AL POR MENOR DE ARTÍCULOS DE FERRETERÍA Y MATERIALES DE CONSTRUCCIÓN + 9 + PROVIDENCIA + comercializadora.vipaz@gmail.com + +56999100109 + delivered shipped