Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Tenant should be optional while placing an order #57

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/Components/Order/CloudLicense.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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, [
Expand All @@ -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));
Expand Down
3 changes: 3 additions & 0 deletions src/Components/Tenant.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,16 @@ public function fetchTenant(int $customerId): CloudTenantResponse
}

/**
* @param array<string> $argeementContact
*
* @throws Office365Exception
*/
public function create(
string $name,
string $firstname,
string $lastname,
string $email,
array $argeementContact,
?string $tenantId = null
): CloudTenant {
$tenant = EntityHelper::deserialize(CloudTenant::class, TenantDataTransformer::transform(...func_get_args()));
Expand Down
16 changes: 2 additions & 14 deletions src/Entity/CloudLicense.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,15 @@ final class CloudLicense implements EntityInterface
{
private ?PartnerReferenceHeader $header = null;

private AgreementContact $contact;

private CloudTenant $tenant;
private ?CloudTenant $tenant = null;

private string $customerId;

private string $productCode;

private int $quantity;

public function getAgreementContact(): AgreementContact
{
return $this->contact;
}

public function getCloudTenant(): CloudTenant
public function getCloudTenant(): ?CloudTenant
{
return $this->tenant;
}
Expand All @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion src/Transformer/TenantDataTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
final class TenantDataTransformer
{
/**
* @return array<string, string|null>
* @param array<string> $contact
*
* @return array<string, array<string,string>|string|null>
*/
public static function transform(
string $name,
string $firstname,
string $lastname,
string $email,
array $contact,
string $tenantId = null
): array {
return [
Expand All @@ -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'],
],
];
}
}
21 changes: 10 additions & 11 deletions tests/Integration/Component/CloudLicenseOrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions tests/Integration/Webhook/CloudLicenseOrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
}
});

Expand Down