Skip to content

Commit

Permalink
fix!: Unify include entities (#15)
Browse files Browse the repository at this point in the history
Adds missing import meta where it was missing
Removes legacy entities
Rename "WithIncludes" entities to simpler entity names
Refactor uses

BREAKING CHANGE: Classes <Entity>WithIncludes will now be <Entity>
  • Loading branch information
mikeymike authored Feb 2, 2024
1 parent 9a5f316 commit 92af891
Show file tree
Hide file tree
Showing 35 changed files with 129 additions and 615 deletions.
3 changes: 1 addition & 2 deletions examples/catalog_management.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

use Paddle\SDK\Entities\Price;
use Paddle\SDK\Entities\PriceWithIncludes;
use Paddle\SDK\Entities\Shared\CountryCode;
use Paddle\SDK\Entities\Shared\CurrencyCode;
use Paddle\SDK\Entities\Shared\CustomData;
Expand Down Expand Up @@ -135,7 +134,7 @@
echo sprintf(
"Read product '%s' with prices %s \n",
$product->id,
implode(', ', array_map(fn (PriceWithIncludes $price) => $price->id, iterator_to_array($product->prices))),
implode(', ', array_map(fn (Price $price) => $price->id, iterator_to_array($product->prices))),
);

// ┌───
Expand Down
30 changes: 0 additions & 30 deletions src/Entities/Collections/CustomerIncludesCollection.php

This file was deleted.

30 changes: 0 additions & 30 deletions src/Entities/Collections/PriceWithIncludesCollection.php

This file was deleted.

30 changes: 0 additions & 30 deletions src/Entities/Collections/ProductWithIncludesCollection.php

This file was deleted.

30 changes: 0 additions & 30 deletions src/Entities/Collections/SubscriptionWithIncludesCollection.php

This file was deleted.

30 changes: 0 additions & 30 deletions src/Entities/Collections/TransactionWithIncludesCollection.php

This file was deleted.

46 changes: 0 additions & 46 deletions src/Entities/CustomerIncludes.php

This file was deleted.

6 changes: 4 additions & 2 deletions src/Entities/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ public function __construct(
public CatalogType|null $type,
public TimePeriod|null $billingCycle,
public TimePeriod|null $trialPeriod,
public TaxMode $taxMode,
public TaxMode|null $taxMode,
public Money $unitPrice,
public array $unitPriceOverrides,
public PriceQuantity $quantity,
public Status $status,
public CustomData|null $customData,
public ImportMeta|null $importMeta,
public Product|null $product,
) {
}

Expand All @@ -51,7 +52,7 @@ public static function from(array $data): self
productId: $data['product_id'],
name: $data['name'] ?? null,
description: $data['description'],
type: CatalogType::tryFrom($data['type'] ?? CatalogType::Standard->value),
type: CatalogType::tryFrom($data['type'] ?? ''),
billingCycle: isset($data['billing_cycle']) ? TimePeriod::from($data['billing_cycle']) : null,
trialPeriod: isset($data['trial_period']) ? TimePeriod::from($data['trial_period']) : null,
taxMode: isset($data['tax_mode']) ? TaxMode::from($data['tax_mode']) : null,
Expand All @@ -64,6 +65,7 @@ public static function from(array $data): self
status: Status::from($data['status']),
customData: isset($data['custom_data']) ? new CustomData($data['custom_data']) : null,
importMeta: isset($data['import_meta']) ? ImportMeta::from($data['import_meta']) : null,
product: isset($data['product']) ? Product::from($data['product']) : null,
);
}
}
68 changes: 0 additions & 68 deletions src/Entities/PriceWithIncludes.php

This file was deleted.

3 changes: 3 additions & 0 deletions src/Entities/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Paddle\SDK\Entities;

use Paddle\SDK\Entities\Collections\PriceCollection;
use Paddle\SDK\Entities\Shared\CatalogType;
use Paddle\SDK\Entities\Shared\CustomData;
use Paddle\SDK\Entities\Shared\ImportMeta;
Expand All @@ -30,6 +31,7 @@ public function __construct(
public Status $status,
public \DateTimeInterface|null $createdAt,
public ImportMeta|null $importMeta,
public PriceCollection $prices,
) {
}

Expand All @@ -46,6 +48,7 @@ public static function from(array $data): self
status: Status::from($data['status']),
createdAt: isset($data['created_at']) ? DateTime::from($data['created_at']) : null,
importMeta: isset($data['import_meta']) ? ImportMeta::from($data['import_meta']) : null,
prices: PriceCollection::from($data['prices'] ?? []),
);
}
}
51 changes: 0 additions & 51 deletions src/Entities/ProductWithIncludes.php

This file was deleted.

Loading

0 comments on commit 92af891

Please sign in to comment.