From ecf02b5a702086980ef8d629f40826d2d5bbf361 Mon Sep 17 00:00:00 2001 From: Daan Barbiers Date: Tue, 1 Mar 2022 12:25:52 +0100 Subject: [PATCH 1/6] Tenant should be optional while placing an order --- src/Components/Order/CloudLicense.php | 11 +++++----- src/Components/Tenant.php | 2 ++ src/Entity/CloudLicense.php | 14 +------------ src/Transformer/TenantDataTransformer.php | 4 ++++ .../Component/CloudLicenseOrderTest.php | 21 +++++++++++-------- 5 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/Components/Order/CloudLicense.php b/src/Components/Order/CloudLicense.php index 82d4b25..26f11bc 100644 --- a/src/Components/Order/CloudLicense.php +++ b/src/Components/Order/CloudLicense.php @@ -3,7 +3,6 @@ namespace SandwaveIo\Office365\Components\Order; use SandwaveIo\Office365\Components\AbstractComponent; -use SandwaveIo\Office365\Entity\AgreementContact; use SandwaveIo\Office365\Entity\CloudLicense as License; use SandwaveIo\Office365\Entity\CloudTenant; use SandwaveIo\Office365\Entity\Header\PartnerReferenceHeader; @@ -18,12 +17,11 @@ final class CloudLicense extends AbstractComponent * @throws Office365Exception */ public function create( - CloudTenant $tenant, - AgreementContact $contact, string $customerId, string $productCode, int $quantity, - string $partnerReference = '' + string $partnerReference = '', + CloudTenant $tenant = null ): QueuedResponse { /** @var License $license */ $license = EntityHelper::deserialize(License::class, [ @@ -32,8 +30,9 @@ public function create( 'Quantity' => $quantity, ]); - $tenant->setAgreementContact($contact); - $license->setCloudTenant($tenant); + if ($tenant !== null) { + $license->setCloudTenant($tenant); + } if ($partnerReference !== '') { $license->setPartnerReferenceHeader(new PartnerReferenceHeader($partnerReference)); diff --git a/src/Components/Tenant.php b/src/Components/Tenant.php index bba4a7d..34b80b5 100644 --- a/src/Components/Tenant.php +++ b/src/Components/Tenant.php @@ -2,6 +2,7 @@ namespace SandwaveIo\Office365\Components; +use SandwaveIo\Office365\Entity\AgreementContact; use SandwaveIo\Office365\Entity\CloudTenant; use SandwaveIo\Office365\Entity\CloudTenantRequest; use SandwaveIo\Office365\Entity\Tenant as TenantEntity; @@ -82,6 +83,7 @@ public function create( string $firstname, string $lastname, string $email, + AgreementContact $contact, ?string $tenantId = null ): CloudTenant { $tenant = EntityHelper::deserialize(CloudTenant::class, TenantDataTransformer::transform(...func_get_args())); diff --git a/src/Entity/CloudLicense.php b/src/Entity/CloudLicense.php index 0677a23..9d133ec 100644 --- a/src/Entity/CloudLicense.php +++ b/src/Entity/CloudLicense.php @@ -8,9 +8,7 @@ final class CloudLicense implements EntityInterface { private ?PartnerReferenceHeader $header = null; - private AgreementContact $contact; - - private CloudTenant $tenant; + private ?CloudTenant $tenant = null; private string $customerId; @@ -18,11 +16,6 @@ final class CloudLicense implements EntityInterface private int $quantity; - public function getAgreementContact(): AgreementContact - { - return $this->contact; - } - public function getCloudTenant(): CloudTenant { return $this->tenant; @@ -43,11 +36,6 @@ public function setPartnerReferenceHeader(PartnerReferenceHeader $header): void $this->header = $header; } - public function setAgreementContact(AgreementContact $contact): void - { - $this->contact = $contact; - } - public function getCustomerId(): string { return $this->customerId; diff --git a/src/Transformer/TenantDataTransformer.php b/src/Transformer/TenantDataTransformer.php index ce32838..25eb76e 100644 --- a/src/Transformer/TenantDataTransformer.php +++ b/src/Transformer/TenantDataTransformer.php @@ -2,6 +2,8 @@ namespace SandwaveIo\Office365\Transformer; +use SandwaveIo\Office365\Entity\AgreementContact; + final class TenantDataTransformer { /** @@ -12,6 +14,7 @@ public static function transform( string $firstname, string $lastname, string $email, + AgreementContact $contact, string $tenantId = null ): array { return [ @@ -20,6 +23,7 @@ public static function transform( 'FirstName' => $firstname, 'LastName' => $lastname, 'EmailAddress' => $email, + 'CustomerAgreementContact' => $contact, ]; } } diff --git a/tests/Integration/Component/CloudLicenseOrderTest.php b/tests/Integration/Component/CloudLicenseOrderTest.php index 895a442..f2544eb 100644 --- a/tests/Integration/Component/CloudLicenseOrderTest.php +++ b/tests/Integration/Component/CloudLicenseOrderTest.php @@ -24,12 +24,6 @@ public function create(): void $stack = HandlerStack::create($mockHandler); $officeClient = new OfficeClient('example.com', 'test', 'test', ['handler' => $stack]); - $tenant = $officeClient->tenant->create( - 'test.onmicrosoft.com', - 'Sandwave', - 'Test', - 'john@doe.com' - ); $contact = $officeClient->contact->agreement->create( 'sandwave test', 'john', @@ -39,12 +33,21 @@ public function create(): void new \DateTime() ); - $customerResponse = $officeClient->order->cloudLicense->create( - $tenant, + $tenant = $officeClient->tenant->create( + 'test.onmicrosoft.com', + 'Sandwave', + 'Test', + 'john@doe.com', $contact, + ); + + + $customerResponse = $officeClient->order->cloudLicense->create( '507201', '120A00064B', - 1 + 1, + '', + $tenant ); Assert::assertInstanceOf(QueuedResponse::class, $customerResponse); From ee41429984cfcc2ee534baade05a81f02623f64b Mon Sep 17 00:00:00 2001 From: Daan Barbiers Date: Tue, 1 Mar 2022 12:28:16 +0100 Subject: [PATCH 2/6] cs fix --- tests/Integration/Component/CloudLicenseOrderTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Integration/Component/CloudLicenseOrderTest.php b/tests/Integration/Component/CloudLicenseOrderTest.php index f2544eb..1f76926 100644 --- a/tests/Integration/Component/CloudLicenseOrderTest.php +++ b/tests/Integration/Component/CloudLicenseOrderTest.php @@ -41,7 +41,6 @@ public function create(): void $contact, ); - $customerResponse = $officeClient->order->cloudLicense->create( '507201', '120A00064B', From 78d826a23c8c057cd021f295552ecafea81270a4 Mon Sep 17 00:00:00 2001 From: Daan Barbiers Date: Tue, 1 Mar 2022 12:31:50 +0100 Subject: [PATCH 3/6] fixing stan issues --- src/Entity/CloudLicense.php | 2 +- src/Transformer/TenantDataTransformer.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Entity/CloudLicense.php b/src/Entity/CloudLicense.php index 9d133ec..89943cc 100644 --- a/src/Entity/CloudLicense.php +++ b/src/Entity/CloudLicense.php @@ -16,7 +16,7 @@ final class CloudLicense implements EntityInterface private int $quantity; - public function getCloudTenant(): CloudTenant + public function getCloudTenant(): ?CloudTenant { return $this->tenant; } diff --git a/src/Transformer/TenantDataTransformer.php b/src/Transformer/TenantDataTransformer.php index 25eb76e..89d5748 100644 --- a/src/Transformer/TenantDataTransformer.php +++ b/src/Transformer/TenantDataTransformer.php @@ -7,7 +7,7 @@ final class TenantDataTransformer { /** - * @return array + * @return array */ public static function transform( string $name, From 5da0c3f210eaa9ac02603f4b6c4575fbbbabe55c Mon Sep 17 00:00:00 2001 From: Daan Barbiers Date: Tue, 1 Mar 2022 12:36:36 +0100 Subject: [PATCH 4/6] fixing stan issues --- tests/Integration/Webhook/CloudLicenseOrderTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Integration/Webhook/CloudLicenseOrderTest.php b/tests/Integration/Webhook/CloudLicenseOrderTest.php index 37755b7..a07bcb9 100644 --- a/tests/Integration/Webhook/CloudLicenseOrderTest.php +++ b/tests/Integration/Webhook/CloudLicenseOrderTest.php @@ -26,8 +26,8 @@ public function cloudLicenseOrderTest(): void $license = EntityHelper::createFromXML((string) file_get_contents(__DIR__ . '/../Data/Request/NewCloudLicenseOrderRequest.xml')); Assert::assertInstanceOf(CloudLicense::class, $license); - Assert::assertSame('JohnDoe', $license->getCloudTenant()->getName()); - Assert::assertSame('Jane', $license->getCloudTenant()->getAgreementContact()->getFirstName()); + Assert::assertSame('123', $license->getCustomerId()); + Assert::assertSame('PC1', $license->getProductCode()); if ($license->getHeader() !== null) { Assert::assertSame('12345', $license->getHeader()->getPartnerReference()); @@ -49,7 +49,7 @@ public function callbackLicenseOrderCreate(): void $client->webhook->addEventSubscriber(Event::CLOUD_LICENSE_ORDER_CREATE, new class() implements CloudLicenseObserverInterface { public function execute(CloudLicense $license): void { - Assert::assertSame('JohnDoe', $license->getCloudTenant()->getName()); + Assert::assertSame('PC1', $license->getProductCode()); } }); From b445f32ca76c6e4b6853a4017074c81e4334fd4f Mon Sep 17 00:00:00 2001 From: Willem Date: Tue, 1 Mar 2022 13:15:29 +0100 Subject: [PATCH 5/6] refactor tenant creation. AgreementContant MUST be part of tenant --- src/Components/Tenant.php | 3 ++- src/Transformer/TenantDataTransformer.php | 15 ++++++++++----- .../Component/CloudLicenseOrderTest.php | 17 +++++++---------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/Components/Tenant.php b/src/Components/Tenant.php index 34b80b5..69d4763 100644 --- a/src/Components/Tenant.php +++ b/src/Components/Tenant.php @@ -77,13 +77,14 @@ public function fetchTenant(int $customerId): CloudTenantResponse /** * @throws Office365Exception + * @param array $argeementContact */ public function create( string $name, string $firstname, string $lastname, string $email, - AgreementContact $contact, + array $argeementContact, ?string $tenantId = null ): CloudTenant { $tenant = EntityHelper::deserialize(CloudTenant::class, TenantDataTransformer::transform(...func_get_args())); diff --git a/src/Transformer/TenantDataTransformer.php b/src/Transformer/TenantDataTransformer.php index 89d5748..5a28f2c 100644 --- a/src/Transformer/TenantDataTransformer.php +++ b/src/Transformer/TenantDataTransformer.php @@ -2,19 +2,18 @@ namespace SandwaveIo\Office365\Transformer; -use SandwaveIo\Office365\Entity\AgreementContact; - final class TenantDataTransformer { /** - * @return array + * @param array $contact + * @return array|string|null> */ public static function transform( string $name, string $firstname, string $lastname, string $email, - AgreementContact $contact, + array $contact, string $tenantId = null ): array { return [ @@ -23,7 +22,13 @@ public static function transform( 'FirstName' => $firstname, 'LastName' => $lastname, 'EmailAddress' => $email, - 'CustomerAgreementContact' => $contact, + 'CustomerAgreementContact' => [ + 'FirstName' => $contact['firstname'], + 'LastName' => $contact['lastname'], + 'EmailAddress' => $contact['email'], + 'PhoneNumber' => $contact['phoneNumber'], + 'DateAgreed' => $contact['agreed'], + ], ]; } } diff --git a/tests/Integration/Component/CloudLicenseOrderTest.php b/tests/Integration/Component/CloudLicenseOrderTest.php index 1f76926..9c2749e 100644 --- a/tests/Integration/Component/CloudLicenseOrderTest.php +++ b/tests/Integration/Component/CloudLicenseOrderTest.php @@ -24,21 +24,18 @@ public function create(): void $stack = HandlerStack::create($mockHandler); $officeClient = new OfficeClient('example.com', 'test', 'test', ['handler' => $stack]); - $contact = $officeClient->contact->agreement->create( - 'sandwave test', - 'john', - 'doe', - 'john@doe.com', - '12345', - new \DateTime() - ); - $tenant = $officeClient->tenant->create( 'test.onmicrosoft.com', 'Sandwave', 'Test', 'john@doe.com', - $contact, + [ + 'firstname' => 'john', + 'lastname' => 'doe', + 'email' => 'john@doe.com', + 'phoneNumber' => '12345', + 'agreed' => (new \DateTime())->format('Y-m-d') + ] ); $customerResponse = $officeClient->order->cloudLicense->create( From 36af0d0a11ecfa261969e12b3127785420d18903 Mon Sep 17 00:00:00 2001 From: Willem Date: Tue, 1 Mar 2022 13:17:54 +0100 Subject: [PATCH 6/6] cs fixes --- src/Components/Tenant.php | 4 ++-- src/Transformer/TenantDataTransformer.php | 1 + tests/Integration/Component/CloudLicenseOrderTest.php | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Components/Tenant.php b/src/Components/Tenant.php index 69d4763..b19f665 100644 --- a/src/Components/Tenant.php +++ b/src/Components/Tenant.php @@ -2,7 +2,6 @@ namespace SandwaveIo\Office365\Components; -use SandwaveIo\Office365\Entity\AgreementContact; use SandwaveIo\Office365\Entity\CloudTenant; use SandwaveIo\Office365\Entity\CloudTenantRequest; use SandwaveIo\Office365\Entity\Tenant as TenantEntity; @@ -76,8 +75,9 @@ public function fetchTenant(int $customerId): CloudTenantResponse } /** - * @throws Office365Exception * @param array $argeementContact + * + * @throws Office365Exception */ public function create( string $name, diff --git a/src/Transformer/TenantDataTransformer.php b/src/Transformer/TenantDataTransformer.php index 5a28f2c..c18e9eb 100644 --- a/src/Transformer/TenantDataTransformer.php +++ b/src/Transformer/TenantDataTransformer.php @@ -6,6 +6,7 @@ final class TenantDataTransformer { /** * @param array $contact + * * @return array|string|null> */ public static function transform( diff --git a/tests/Integration/Component/CloudLicenseOrderTest.php b/tests/Integration/Component/CloudLicenseOrderTest.php index 9c2749e..31c7bdf 100644 --- a/tests/Integration/Component/CloudLicenseOrderTest.php +++ b/tests/Integration/Component/CloudLicenseOrderTest.php @@ -34,7 +34,7 @@ public function create(): void 'lastname' => 'doe', 'email' => 'john@doe.com', 'phoneNumber' => '12345', - 'agreed' => (new \DateTime())->format('Y-m-d') + 'agreed' => (new \DateTime())->format('Y-m-d'), ] );