-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Transaction Preview Price (#89)
* fix: Separate transaction preview operations and nullable preview price IDs * fix: Add TransactionPreviewPrice with nullable ID * fix Add support for transaction update items with optional properties
- Loading branch information
1 parent
29b183e
commit 807fd31
Showing
34 changed files
with
1,074 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* |------ | ||
* | ! Generated code ! | ||
* | Altering this code will result in changes being overwritten | | ||
* |-------------------------------------------------------------|. | ||
*/ | ||
|
||
namespace Paddle\SDK\Entities\Transaction; | ||
|
||
use Paddle\SDK\Entities\DateTime; | ||
use Paddle\SDK\Entities\Entity; | ||
use Paddle\SDK\Entities\Product; | ||
use Paddle\SDK\Entities\Shared\CatalogType; | ||
use Paddle\SDK\Entities\Shared\CustomData; | ||
use Paddle\SDK\Entities\Shared\ImportMeta; | ||
use Paddle\SDK\Entities\Shared\Money; | ||
use Paddle\SDK\Entities\Shared\PriceQuantity; | ||
use Paddle\SDK\Entities\Shared\Status; | ||
use Paddle\SDK\Entities\Shared\TaxMode; | ||
use Paddle\SDK\Entities\Shared\TimePeriod; | ||
use Paddle\SDK\Entities\Shared\UnitPriceOverride; | ||
|
||
class TransactionPreviewPrice implements Entity | ||
{ | ||
/** | ||
* @param array<UnitPriceOverride> $unitPriceOverrides | ||
*/ | ||
private function __construct( | ||
public string|null $id, | ||
public string $productId, | ||
public string|null $name, | ||
public string $description, | ||
public CatalogType|null $type, | ||
public TimePeriod|null $billingCycle, | ||
public TimePeriod|null $trialPeriod, | ||
public TaxMode $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, | ||
public \DateTimeInterface $createdAt, | ||
public \DateTimeInterface $updatedAt, | ||
) { | ||
} | ||
|
||
public static function from(array $data): self | ||
{ | ||
return new self( | ||
id: $data['id'], | ||
productId: $data['product_id'], | ||
name: $data['name'] ?? null, | ||
description: $data['description'], | ||
type: CatalogType::from($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: TaxMode::from($data['tax_mode']), | ||
unitPrice: Money::from($data['unit_price']), | ||
unitPriceOverrides: array_map( | ||
fn (array $override): UnitPriceOverride => UnitPriceOverride::from($override), | ||
$data['unit_price_overrides'] ?? [], | ||
), | ||
quantity: PriceQuantity::from($data['quantity']), | ||
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, | ||
createdAt: DateTime::from($data['created_at']), | ||
updatedAt: DateTime::from($data['updated_at']), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/Resources/Transactions/Operations/Create/TransactionCreateItem.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Paddle\SDK\Resources\Transactions\Operations\Create; | ||
|
||
class TransactionCreateItem | ||
{ | ||
public function __construct( | ||
public string $priceId, | ||
public int $quantity, | ||
) { | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Resources/Transactions/Operations/Create/TransactionCreateItemWithPrice.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Paddle\SDK\Resources\Transactions\Operations\Create; | ||
|
||
use Paddle\SDK\Resources\Transactions\Operations\Price\TransactionNonCatalogPrice; | ||
use Paddle\SDK\Resources\Transactions\Operations\Price\TransactionNonCatalogPriceWithProduct; | ||
|
||
class TransactionCreateItemWithPrice | ||
{ | ||
public function __construct( | ||
public TransactionNonCatalogPrice|TransactionNonCatalogPriceWithProduct $price, | ||
public int $quantity, | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/Resources/Transactions/Operations/Preview/TransactionItemPreviewWithNonCatalogPrice.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Paddle\SDK\Resources\Transactions\Operations\Preview; | ||
|
||
use Paddle\SDK\FiltersUndefined; | ||
use Paddle\SDK\Resources\Transactions\Operations\Price\TransactionNonCatalogPrice; | ||
use Paddle\SDK\Resources\Transactions\Operations\Price\TransactionNonCatalogPriceWithProduct; | ||
use Paddle\SDK\Undefined; | ||
|
||
class TransactionItemPreviewWithNonCatalogPrice implements \JsonSerializable | ||
{ | ||
use FiltersUndefined; | ||
|
||
public function __construct( | ||
public TransactionNonCatalogPrice|TransactionNonCatalogPriceWithProduct $price, | ||
public int $quantity, | ||
public bool|Undefined $includeInTotals = new Undefined(), | ||
) { | ||
} | ||
|
||
public function jsonSerialize(): array | ||
{ | ||
return $this->filterUndefined([ | ||
'price' => $this->price, | ||
'quantity' => $this->quantity, | ||
'include_in_totals' => $this->includeInTotals, | ||
]); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/Resources/Transactions/Operations/Preview/TransactionItemPreviewWithPriceId.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Paddle\SDK\Resources\Transactions\Operations\Preview; | ||
|
||
use Paddle\SDK\FiltersUndefined; | ||
use Paddle\SDK\Undefined; | ||
|
||
class TransactionItemPreviewWithPriceId implements \JsonSerializable | ||
{ | ||
use FiltersUndefined; | ||
|
||
public function __construct( | ||
public string $priceId, | ||
public int $quantity, | ||
public bool|Undefined $includeInTotals = new Undefined(), | ||
) { | ||
} | ||
|
||
public function jsonSerialize(): array | ||
{ | ||
return $this->filterUndefined([ | ||
'price_id' => $this->priceId, | ||
'quantity' => $this->quantity, | ||
'include_in_totals' => $this->includeInTotals, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.