Skip to content

Commit

Permalink
Sync API spec with SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
vifer committed Jan 23, 2024
1 parent 551ded5 commit 60c05c3
Show file tree
Hide file tree
Showing 29 changed files with 158 additions and 18 deletions.
18 changes: 14 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
Check our main [developer changelog](https://developer.paddle.com/?utm_source=dx&utm_medium=paddle-php-sdk) for information about changes to the Paddle Billing platform, the Paddle API, and other developer tools.

## [0.2.1] - 2024-01-24

### Added

- Added `importMeta` to product, price, address, business, customer, discount and subscription entities
- Added `creditToBalance` to `transaction.details.payoutTotals` and `transaction.details.totals`
- Added `origin` query parameter to list transactions, see [related changelog](https://developer.paddle.com/changelog/2023/filter-transactions-origin?utm_source=dx&utm_medium=paddle-php-sdk).
- Added `available_payment_methods` to transaction with includes entity
- Added `email` query parameter to list customers, see [related changelog](https://developer.paddle.com/changelog/2024/filter-customers-email#filter-customers-by-email-address?utm_source=dx&utm_medium=paddle-php-sdk)

## [0.2.0] - 2024-01-23

### Changed
Expand All @@ -25,10 +35,10 @@ Check our main [developer changelog](https://developer.paddle.com/?utm_source=dx

### Added

- Added `available_payment_methods` to [transaction preview and pricing preview](https://developer.paddle.com/changelog/2023/available-payment-methods?utm_source=dx&utm_medium=paddle-node-sdk)
- Added non-catalog items to [subscriptions](https://developer.paddle.com/changelog/2023/bill-custom-items-one-time-subscription-charge?utm_source=dx&utm_medium=paddle-node-sdk)
- Added non catalog items to [transactions](https://developer.paddle.com/changelog/2023/add-custom-items-transaction?utm_source=dx&utm_medium=paddle-node-sdk)
- Added `on_payment_failure` to [subscriptions](https://developer.paddle.com/changelog/2023/payment-failure-behavior-update-subscription?utm_source=dx&utm_medium=paddle-node-sdk)
- Added `available_payment_methods` to [transaction preview and pricing preview](https://developer.paddle.com/changelog/2023/available-payment-methods?utm_source=dx&utm_medium=paddle-php-sdk)
- Added non-catalog items to [subscriptions](https://developer.paddle.com/changelog/2023/bill-custom-items-one-time-subscription-charge?utm_source=dx&utm_medium=paddle-php-sdk)
- Added non catalog items to [transactions](https://developer.paddle.com/changelog/2023/add-custom-items-transaction?utm_source=dx&utm_medium=paddle-php-sdk)
- Added `on_payment_failure` to [subscriptions](https://developer.paddle.com/changelog/2023/payment-failure-behavior-update-subscription?utm_source=dx&utm_medium=paddle-php-sdk)

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

class Client
{
private const SDK_VERSION = '0.2.0';
private const SDK_VERSION = '0.2.1';

public readonly LoggerInterface $logger;
public readonly Options $options;
Expand Down
3 changes: 3 additions & 0 deletions src/Entities/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Paddle\SDK\Entities\Shared\CountryCode;
use Paddle\SDK\Entities\Shared\CustomData;
use Paddle\SDK\Entities\Shared\ImportMeta;
use Paddle\SDK\Entities\Shared\Status;

class Address implements Entity
Expand All @@ -30,6 +31,7 @@ public function __construct(
public Status $status,
public \DateTimeInterface $createdAt,
public \DateTimeInterface $updatedAt,
public ImportMeta|null $importMeta,
) {
}

Expand All @@ -48,6 +50,7 @@ public static function from(array $data): self
status: Status::from($data['status']),
createdAt: DateTime::from($data['created_at']),
updatedAt: DateTime::from($data['updated_at']),
importMeta: isset($data['import_meta']) ? ImportMeta::from($data['import_meta']) : null,
);
}
}
3 changes: 3 additions & 0 deletions src/Entities/Business.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Paddle\SDK\Entities\Shared\Contacts;
use Paddle\SDK\Entities\Shared\CustomData;
use Paddle\SDK\Entities\Shared\ImportMeta;
use Paddle\SDK\Entities\Shared\Status;

class Business implements Entity
Expand All @@ -30,6 +31,7 @@ public function __construct(
public \DateTimeInterface $createdAt,
public \DateTimeInterface $updatedAt,
public CustomData|null $customData,
public ImportMeta|null $importMeta,
) {
}

Expand All @@ -45,6 +47,7 @@ public static function from(array $data): self
createdAt: DateTime::from($data['created_at']),
updatedAt: DateTime::from($data['updated_at']),
customData: isset($data['custom_data']) ? new CustomData($data['custom_data']) : null,
importMeta: isset($data['import_meta']) ? ImportMeta::from($data['import_meta']) : null,
);
}
}
3 changes: 3 additions & 0 deletions src/Entities/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Paddle\SDK\Entities;

use Paddle\SDK\Entities\Shared\CustomData;
use Paddle\SDK\Entities\Shared\ImportMeta;
use Paddle\SDK\Entities\Shared\Status;

class Customer implements Entity
Expand All @@ -26,6 +27,7 @@ public function __construct(
public string $locale,
public \DateTimeInterface $createdAt,
public \DateTimeInterface $updatedAt,
public ImportMeta|null $importMeta,
) {
}

Expand All @@ -41,6 +43,7 @@ public static function from(array $data): self
locale: $data['locale'],
createdAt: DateTime::from($data['created_at']),
updatedAt: DateTime::from($data['updated_at']),
importMeta: isset($data['import_meta']) ? ImportMeta::from($data['import_meta']) : null,
);
}
}
3 changes: 3 additions & 0 deletions src/Entities/Discount.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Paddle\SDK\Entities\Discount\DiscountStatus;
use Paddle\SDK\Entities\Discount\DiscountType;
use Paddle\SDK\Entities\Shared\CurrencyCode;
use Paddle\SDK\Entities\Shared\ImportMeta;

class Discount implements Entity
{
Expand All @@ -34,6 +35,7 @@ public function __construct(
public int $timesUsed,
public \DateTimeInterface $createdAt,
public \DateTimeInterface $updatedAt,
public ImportMeta|null $importMeta,
) {
}

Expand All @@ -56,6 +58,7 @@ public static function from(array $data): self
timesUsed: $data['times_used'],
createdAt: DateTime::from($data['created_at']),
updatedAt: DateTime::from($data['updated_at']),
importMeta: isset($data['import_meta']) ? ImportMeta::from($data['import_meta']) : null,
);
}
}
3 changes: 3 additions & 0 deletions src/Entities/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

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;
Expand All @@ -39,6 +40,7 @@ public function __construct(
public PriceQuantity $quantity,
public Status $status,
public CustomData|null $customData,
public ImportMeta|null $importMeta,
) {
}

Expand All @@ -61,6 +63,7 @@ public static function from(array $data): self
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,
);
}
}
3 changes: 3 additions & 0 deletions src/Entities/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Paddle\SDK\Entities\Shared\CatalogType;
use Paddle\SDK\Entities\Shared\CustomData;
use Paddle\SDK\Entities\Shared\ImportMeta;
use Paddle\SDK\Entities\Shared\Status;
use Paddle\SDK\Entities\Shared\TaxCategory;

Expand All @@ -28,6 +29,7 @@ public function __construct(
public CustomData|null $customData,
public Status $status,
public \DateTimeInterface|null $createdAt,
public ImportMeta|null $importMeta,
) {
}

Expand All @@ -43,6 +45,7 @@ public static function from(array $data): self
customData: isset($data['custom_data']) ? new CustomData($data['custom_data']) : null,
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,
);
}
}
29 changes: 29 additions & 0 deletions src/Entities/Shared/ImportMeta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

/**
* |------
* | ! Generated code !
* | Altering this code will result in changes being overwritten |
* |-------------------------------------------------------------|.
*/

namespace Paddle\SDK\Entities\Shared;

class ImportMeta
{
public function __construct(
public readonly string|null $externalId,
public readonly string $importedFrom,
) {
}

public static function from(array $data): self
{
return new self(
externalId: $data['external_id'] ?? null,
importedFrom: $data['imported_from'],
);
}
}
22 changes: 12 additions & 10 deletions src/Entities/Shared/TransactionPayoutTotals.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,24 @@ public function __construct(
public string $fee,
public string $earnings,
public CurrencyCodePayouts $currencyCode,
public string $creditToBalance,
) {
}

public static function from(array $data): self
{
return new self(
$data['subtotal'],
$data['discount'],
$data['tax'],
$data['total'],
$data['credit'],
$data['balance'],
$data['grand_total'],
$data['fee'] ?? null,
$data['earnings'] ?? null,
CurrencyCodePayouts::from($data['currency_code']),
subtotal: $data['subtotal'],
discount: $data['discount'],
tax: $data['tax'],
total: $data['total'],
credit: $data['credit'],
balance: $data['balance'],
grandTotal: $data['grand_total'],
fee: $data['fee'] ?? null,
earnings: $data['earnings'] ?? null,
currencyCode: CurrencyCodePayouts::from($data['currency_code']),
creditToBalance: $data['credit_to_balance'],
);
}
}
2 changes: 2 additions & 0 deletions src/Entities/Shared/TransactionTotals.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function __construct(
public string|null $fee,
public string|null $earnings,
public CurrencyCode $currencyCode,
public string $creditToBalance,
) {
}

Expand All @@ -40,6 +41,7 @@ public static function from(array $data): self
fee: $data['fee'] ?? null,
earnings: $data['earnings'] ?? null,
currencyCode: CurrencyCode::from($data['currency_code']),
creditToBalance: $data['credit_to_balance'],
);
}
}
3 changes: 3 additions & 0 deletions src/Entities/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Paddle\SDK\Entities\Shared\CollectionMode;
use Paddle\SDK\Entities\Shared\CurrencyCode;
use Paddle\SDK\Entities\Shared\CustomData;
use Paddle\SDK\Entities\Shared\ImportMeta;
use Paddle\SDK\Entities\Shared\TimePeriod;
use Paddle\SDK\Entities\Subscription\SubscriptionDiscount;
use Paddle\SDK\Entities\Subscription\SubscriptionItem;
Expand Down Expand Up @@ -51,6 +52,7 @@ public function __construct(
public SubscriptionManagementUrls $managementUrls,
public array $items,
public CustomData|null $customData,
public ImportMeta|null $importMeta,
) {
}

Expand Down Expand Up @@ -85,6 +87,7 @@ public static function from(array $data): self
: null,
items: array_map(fn (array $item): SubscriptionItem => SubscriptionItem::from($item), $data['items']),
customData: isset($data['custom_data']) ? new CustomData($data['custom_data']) : null,
importMeta: isset($data['import_meta']) ? ImportMeta::from($data['import_meta']) : null,
);
}
}
4 changes: 4 additions & 0 deletions src/Entities/TransactionWithIncludes.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\Shared\AvailablePaymentMethods;
use Paddle\SDK\Entities\Shared\BillingDetails;
use Paddle\SDK\Entities\Shared\Checkout;
use Paddle\SDK\Entities\Shared\CollectionMode;
Expand All @@ -31,6 +32,7 @@ class TransactionWithIncludes implements Entity
* @param array<TransactionItem> $items
* @param array<TransactionPaymentAttempt> $payments
* @param array<TransactionAdjustment> $adjustments
* @param array<AvailablePaymentMethods> $availablePaymentMethods
*/
public function __construct(
public string $id,
Expand Down Expand Up @@ -61,6 +63,7 @@ public function __construct(
public Business|null $business,
public Customer|null $customer,
public Discount|null $discount,
public array $availablePaymentMethods,
) {
}

Expand Down Expand Up @@ -95,6 +98,7 @@ public static function from(array $data): self
business: isset($data['business']) ? Business::from($data['business']) : null,
customer: isset($data['customer']) ? Customer::from($data['customer']) : null,
discount: isset($data['discount']) ? Discount::from($data['discount']) : null,
availablePaymentMethods: array_map(fn (string $item): AvailablePaymentMethods => AvailablePaymentMethods::from($item), $data['available_payment_methods'] ?? []),
);
}
}
6 changes: 6 additions & 0 deletions src/Resources/Customers/Operations/ListCustomers.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function __construct(
private readonly array $ids = [],
private readonly array $statuses = [],
private readonly ?string $search = null,
private readonly array $emails = [],
) {
if ($invalid = array_filter($this->ids, fn ($value): bool => ! is_string($value))) {
throw InvalidArgumentException::arrayContainsInvalidTypes('ids', 'string', implode(', ', $invalid));
Expand All @@ -30,6 +31,10 @@ public function __construct(
if ($invalid = array_filter($this->statuses, fn ($value): bool => ! $value instanceof Status)) {
throw InvalidArgumentException::arrayContainsInvalidTypes('statuses', Status::class, implode(', ', $invalid));
}

if ($invalid = array_filter($this->emails, fn ($value): bool => ! is_string($value))) {
throw InvalidArgumentException::arrayContainsInvalidTypes('emails', 'string', implode(', ', $invalid));
}
}

public function getParameters(): array
Expand All @@ -42,6 +47,7 @@ public function getParameters(): array
'id' => implode(',', $this->ids),
'status' => implode(',', array_map($enumStringify, $this->statuses)),
'search' => $this->search,
'email' => implode(',', $this->emails),
]),
);
}
Expand Down
1 change: 1 addition & 0 deletions src/Resources/Transactions/Operations/List/Includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ enum Includes: string
case Address = 'address';
case Adjustment = 'adjustment';
case AdjustmentsTotals = 'adjustments_totals';
case AvailablePaymentMethods = 'available_payment_methods';
case Business = 'business';
case Customer = 'customer';
case Discount = 'discount';
Expand Down
15 changes: 15 additions & 0 deletions src/Resources/Transactions/Operations/List/Origin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Paddle\SDK\Resources\Transactions\Operations\List;

enum Origin: string
{
case Api = 'api';
case SubscriptionCharge = 'subscription_charge';
case SubscriptionPaymentMethodChange = 'subscription_payment_method_change';
case SubscriptionRecurring = 'subscription_recurring';
case SubscriptionUpdate = 'subscription_update';
case Web = 'web';
}
Loading

0 comments on commit 60c05c3

Please sign in to comment.