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..b19f665 100644 --- a/src/Components/Tenant.php +++ b/src/Components/Tenant.php @@ -75,6 +75,8 @@ public function fetchTenant(int $customerId): CloudTenantResponse } /** + * @param array $argeementContact + * * @throws Office365Exception */ public function create( @@ -82,6 +84,7 @@ public function create( string $firstname, string $lastname, string $email, + array $argeementContact, ?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..89943cc 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,12 +16,7 @@ final class CloudLicense implements EntityInterface private int $quantity; - public function getAgreementContact(): AgreementContact - { - return $this->contact; - } - - public function getCloudTenant(): CloudTenant + 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..c18e9eb 100644 --- a/src/Transformer/TenantDataTransformer.php +++ b/src/Transformer/TenantDataTransformer.php @@ -5,13 +5,16 @@ final class TenantDataTransformer { /** - * @return array + * @param array $contact + * + * @return array|string|null> */ public static function transform( string $name, string $firstname, string $lastname, string $email, + array $contact, string $tenantId = null ): array { return [ @@ -20,6 +23,13 @@ public static function transform( 'FirstName' => $firstname, 'LastName' => $lastname, 'EmailAddress' => $email, + '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 895a442..31c7bdf 100644 --- a/tests/Integration/Component/CloudLicenseOrderTest.php +++ b/tests/Integration/Component/CloudLicenseOrderTest.php @@ -28,23 +28,22 @@ public function create(): void 'test.onmicrosoft.com', 'Sandwave', 'Test', - 'john@doe.com' - ); - $contact = $officeClient->contact->agreement->create( - 'sandwave test', - 'john', - 'doe', 'john@doe.com', - '12345', - new \DateTime() + [ + 'firstname' => 'john', + 'lastname' => 'doe', + 'email' => 'john@doe.com', + 'phoneNumber' => '12345', + 'agreed' => (new \DateTime())->format('Y-m-d'), + ] ); $customerResponse = $officeClient->order->cloudLicense->create( - $tenant, - $contact, '507201', '120A00064B', - 1 + 1, + '', + $tenant ); Assert::assertInstanceOf(QueuedResponse::class, $customerResponse); 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()); } });