diff --git a/Tests/Feature/Checkout/Mock/CheckoutShowMockClient.php b/Tests/Feature/Checkout/Mock/CheckoutShowMockClient.php index f0bb8ab..c6f1a22 100644 --- a/Tests/Feature/Checkout/Mock/CheckoutShowMockClient.php +++ b/Tests/Feature/Checkout/Mock/CheckoutShowMockClient.php @@ -7,19 +7,23 @@ class CheckoutShowMockClient extends ClientMock { public const BASIC_CHECKOUT = [ + 'created_at' => '2019-01-16T00:00:00.000000Z', + 'deleted_at' => '2019-01-16T00:00:00.000000Z', + 'has_redirects' => false, 'id' => 1, 'is_active' => true, + 'is_blueprint' => false, 'is_expired' => false, 'name' => 'lorem-ipsum-test', + 'pixel' => null, 'preview_url' => 'https://example.com/preview-url', 'primary_color' => '#ff0000', 'return_url' => 'https://example.com/return-url', 'secondary_color' => '#00ff00', 'slug' => 'lorem-ipsum-test', - 'url' => 'https://example.com/url', - 'created_at' => '2019-01-16T00:00:00.000000Z', + 'split_test_id' => null, 'updated_at' => '2019-01-16T00:00:00.000000Z', - 'deleted_at' => '2019-01-16T00:00:00.000000Z', + 'url' => 'https://example.com/url', ]; public const BASIC_PRODUCT = [ 'created_at' => '2019-01-16T00:00:00.000000Z', diff --git a/Tests/Feature/Checkout/ShowCheckoutTest.php b/Tests/Feature/Checkout/ShowCheckoutTest.php index ad4ee66..fe98ab2 100644 --- a/Tests/Feature/Checkout/ShowCheckoutTest.php +++ b/Tests/Feature/Checkout/ShowCheckoutTest.php @@ -53,14 +53,18 @@ public function it_should_return_basic_order(): void $checkout = $service->find(1); static::assertSame(1, $checkout->id()); + static::assertFalse($checkout->hasRedirects()); static::assertTrue($checkout->isActive()); + static::assertFalse($checkout->isBlueprint()); static::assertFalse($checkout->isExpired()); static::assertSame('lorem-ipsum-test', $checkout->name()); + static::assertNull($checkout->pixel()); static::assertSame('https://example.com/preview-url', $checkout->previewUrl()); static::assertSame('#ff0000', $checkout->primaryColor()); static::assertSame('https://example.com/return-url', $checkout->returnUrl()); static::assertSame('#00ff00', $checkout->secondaryColor()); static::assertSame('lorem-ipsum-test', $checkout->slug()); + static::assertNull($checkout->splitTestId()); static::assertSame('https://example.com/url', $checkout->url()); static::assertSame('2019-01-16 00:00:00', $checkout->createdAt()->format('Y-m-d H:i:s')); static::assertSame('2019-01-16 00:00:00', $checkout->updatedAt()->format('Y-m-d H:i:s')); diff --git a/src/Director/BodyTo/BodyToCheckout.php b/src/Director/BodyTo/BodyToCheckout.php index f0a90e0..1d8d558 100644 --- a/src/Director/BodyTo/BodyToCheckout.php +++ b/src/Director/BodyTo/BodyToCheckout.php @@ -26,21 +26,33 @@ public static function build(array $data): Checkout ->setIsExpired($data['is_expired']) ->setName($data['name']) ->setPreviewUrl($data['preview_url']) - ->setPrimaryColor($data['primary_color']) + ->setPrimaryColor($data['primary_color'] ?? null) ->setReturnUrl($data['return_url']) - ->setSecondaryColor($data['secondary_color']) + ->setSecondaryColor($data['secondary_color'] ?? null) ->setSlug($data['slug']) ->setUrl($data['url']) + ->setHasRedirects($data['has_redirects']) + ->setIsBlueprint($data['is_blueprint']) ->setCreatedAt(self::date($data, 'created_at')) ->setUpdatedAt($data['updated_at'] ? self::date($data, 'updated_at') : null) ->setDeletedAt($data['deleted_at'] ? self::date($data, 'deleted_at') : null); + if (array_key_exists('pixel', $data)) { + $checkout->setPixel($data['pixel']); + } + + if (array_key_exists('split_test_id', $data)) { + $checkout->setSplitTestId($data['split_test_id']); + } + + // Handle optional product relation (for backward compatibility with tests) if (isset($data['product'])) { $checkout->setProduct(BodyToProduct::build($data['product'])); } + // Handle optional product pricing relation (for backward compatibility with tests) if (isset($data['productPricing'])) { - $checkout->setProductPricing(BodyToProductPricing::build($data['pricing'])); + $checkout->setProductPricing(BodyToProductPricing::build($data['productPricing'])); } return $checkout; diff --git a/src/Entity/Checkout.php b/src/Entity/Checkout.php index 50613f3..188837c 100644 --- a/src/Entity/Checkout.php +++ b/src/Entity/Checkout.php @@ -14,15 +14,19 @@ class Checkout extends AbstractEntity protected bool $allowEmptyRelations; protected int $id; + protected bool $hasRedirects; protected bool $isActive; + protected bool $isBlueprint; protected bool $isExpired; protected string $name; + protected ?string $pixel; protected string $previewUrl; - protected string $primaryColor; + protected ?string $primaryColor; protected Product $product; protected ProductPricing $productPricing; protected ?string $returnUrl; protected ?string $secondaryColor; + protected ?int $splitTestId; protected string $slug; protected string $url; protected DateTimeImmutable $createdAt; @@ -39,6 +43,18 @@ public function id(): int return $this->id; } + public function hasRedirects(): bool + { + return $this->hasRedirects; + } + + public function setHasRedirects(bool $hasRedirects): self + { + $this->hasRedirects = $hasRedirects; + + return $this; + } + public function isActive(): bool { return $this->isActive; @@ -51,6 +67,18 @@ public function setIsActive(bool $isActive): self return $this; } + public function isBlueprint(): bool + { + return $this->isBlueprint; + } + + public function setIsBlueprint(bool $isBlueprint): self + { + $this->isBlueprint = $isBlueprint; + + return $this; + } + public function isExpired(): bool { return $this->isExpired; @@ -87,12 +115,12 @@ public function setPreviewUrl(string $previewUrl): self return $this; } - public function primaryColor(): string + public function primaryColor(): ?string { return $this->primaryColor; } - public function setPrimaryColor(string $primaryColor): self + public function setPrimaryColor(?string $primaryColor): self { $this->primaryColor = $primaryColor; @@ -134,6 +162,18 @@ public function productPricing(): ProductPricing return $this->productPricing; } + public function pixel(): ?string + { + return $this->pixel; + } + + public function setPixel(?string $pixel): self + { + $this->pixel = $pixel; + + return $this; + } + public function returnUrl(): ?string { return $this->returnUrl; @@ -170,6 +210,18 @@ public function setSlug(string $slug): self return $this; } + public function splitTestId(): ?int + { + return $this->splitTestId; + } + + public function setSplitTestId(?int $splitTestId): self + { + $this->splitTestId = $splitTestId; + + return $this; + } + public function url(): string { return $this->url; diff --git a/src/Entity/CheckoutInternal.php b/src/Entity/CheckoutInternal.php index d9ac045..93151f0 100644 --- a/src/Entity/CheckoutInternal.php +++ b/src/Entity/CheckoutInternal.php @@ -67,4 +67,64 @@ public function setDeletedAt(?DateTimeImmutable $deletedAt): self return $this; } + + /** + * @internal + */ + public function setHasRedirects(bool $hasRedirects): self + { + $this->hasRedirects = $hasRedirects; + + return $this; + } + + /** + * @internal + */ + public function setIsBlueprint(bool $isBlueprint): self + { + $this->isBlueprint = $isBlueprint; + + return $this; + } + + /** + * @internal + */ + public function setPixel(?string $pixel): self + { + $this->pixel = $pixel; + + return $this; + } + + /** + * @internal + */ + public function setPrimaryColor(?string $primaryColor): self + { + $this->primaryColor = $primaryColor; + + return $this; + } + + /** + * @internal + */ + public function setSecondaryColor(?string $secondaryColor): self + { + $this->secondaryColor = $secondaryColor; + + return $this; + } + + /** + * @internal + */ + public function setSplitTestId(?int $splitTestId): self + { + $this->splitTestId = $splitTestId; + + return $this; + } }