diff --git a/CHANGELOG.md b/CHANGELOG.md index 431524f..293b66b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ Check our main [developer changelog](https://developer.paddle.com/?utm_source=dx - Added `product` to `subscription.items[]`, see [related changelog](https://developer.paddle.com/changelog/2024/subscription-items-product?utm_source=dx&utm_medium=paddle-php-sdk) - Added `import_meta` to `transaction` +- Support custom prices when updating and previewing subscriptions, see [related changelog](https://developer.paddle.com/changelog/2024/add-custom-items-subscription) ## [1.1.2] - 2024-08-23 diff --git a/src/Entities/Subscription/SubscriptionNonCatalogPrice.php b/src/Entities/Subscription/SubscriptionNonCatalogPrice.php index 3e3089a..3c3dba0 100644 --- a/src/Entities/Subscription/SubscriptionNonCatalogPrice.php +++ b/src/Entities/Subscription/SubscriptionNonCatalogPrice.php @@ -15,6 +15,7 @@ use Paddle\SDK\Entities\Shared\Money; use Paddle\SDK\Entities\Shared\PriceQuantity; use Paddle\SDK\Entities\Shared\TaxMode; +use Paddle\SDK\Entities\Shared\TimePeriod; use Paddle\SDK\Entities\Shared\UnitPriceOverride; class SubscriptionNonCatalogPrice @@ -31,6 +32,8 @@ public function __construct( public array $unitPriceOverrides, public PriceQuantity $quantity, public CustomData|null $customData, + public TimePeriod|null $billingCycle = null, + public TimePeriod|null $trialPeriod = null, ) { } } diff --git a/src/Entities/Subscription/SubscriptionNonCatalogPriceWithProduct.php b/src/Entities/Subscription/SubscriptionNonCatalogPriceWithProduct.php index a76e2a2..d1a5cbe 100644 --- a/src/Entities/Subscription/SubscriptionNonCatalogPriceWithProduct.php +++ b/src/Entities/Subscription/SubscriptionNonCatalogPriceWithProduct.php @@ -15,6 +15,7 @@ use Paddle\SDK\Entities\Shared\Money; use Paddle\SDK\Entities\Shared\PriceQuantity; use Paddle\SDK\Entities\Shared\TaxMode; +use Paddle\SDK\Entities\Shared\TimePeriod; use Paddle\SDK\Entities\Shared\UnitPriceOverride; class SubscriptionNonCatalogPriceWithProduct @@ -31,6 +32,8 @@ public function __construct( public array $unitPriceOverrides, public PriceQuantity $quantity, public CustomData|null $customData, + public TimePeriod|null $billingCycle = null, + public TimePeriod|null $trialPeriod = null, ) { } } diff --git a/src/Resources/Subscriptions/Operations/PreviewUpdateSubscription.php b/src/Resources/Subscriptions/Operations/PreviewUpdateSubscription.php index fb7c6e8..540a21d 100644 --- a/src/Resources/Subscriptions/Operations/PreviewUpdateSubscription.php +++ b/src/Resources/Subscriptions/Operations/PreviewUpdateSubscription.php @@ -10,6 +10,7 @@ use Paddle\SDK\Entities\Shared\CurrencyCode; use Paddle\SDK\Entities\Shared\CustomData; use Paddle\SDK\Entities\Subscription\SubscriptionItems; +use Paddle\SDK\Entities\Subscription\SubscriptionItemsWithPrice; use Paddle\SDK\Entities\Subscription\SubscriptionOnPaymentFailure; use Paddle\SDK\Entities\Subscription\SubscriptionProrationBillingMode; use Paddle\SDK\FiltersUndefined; @@ -21,7 +22,7 @@ class PreviewUpdateSubscription implements \JsonSerializable use FiltersUndefined; /** - * @param array $items + * @param array $items */ public function __construct( public readonly string|Undefined $customerId = new Undefined(), diff --git a/src/Resources/Subscriptions/Operations/UpdateSubscription.php b/src/Resources/Subscriptions/Operations/UpdateSubscription.php index f332e8e..dbf3f76 100644 --- a/src/Resources/Subscriptions/Operations/UpdateSubscription.php +++ b/src/Resources/Subscriptions/Operations/UpdateSubscription.php @@ -10,6 +10,7 @@ use Paddle\SDK\Entities\Shared\CurrencyCode; use Paddle\SDK\Entities\Shared\CustomData; use Paddle\SDK\Entities\Subscription\SubscriptionItems; +use Paddle\SDK\Entities\Subscription\SubscriptionItemsWithPrice; use Paddle\SDK\Entities\Subscription\SubscriptionOnPaymentFailure; use Paddle\SDK\Entities\Subscription\SubscriptionProrationBillingMode; use Paddle\SDK\FiltersUndefined; @@ -21,7 +22,7 @@ class UpdateSubscription implements \JsonSerializable use FiltersUndefined; /** - * @param array $items + * @param array $items */ public function __construct( public readonly string|Undefined $customerId = new Undefined(), diff --git a/tests/Functional/Resources/Subscriptions/SubscriptionsClientTest.php b/tests/Functional/Resources/Subscriptions/SubscriptionsClientTest.php index a916be3..22a4184 100644 --- a/tests/Functional/Resources/Subscriptions/SubscriptionsClientTest.php +++ b/tests/Functional/Resources/Subscriptions/SubscriptionsClientTest.php @@ -7,11 +7,22 @@ use GuzzleHttp\Psr7\Response; use Http\Mock\Client as MockClient; use Paddle\SDK\Client; +use Paddle\SDK\Entities\Shared\CatalogType; use Paddle\SDK\Entities\Shared\CollectionMode; use Paddle\SDK\Entities\Shared\CurrencyCode; use Paddle\SDK\Entities\Shared\CustomData; +use Paddle\SDK\Entities\Shared\Interval; +use Paddle\SDK\Entities\Shared\Money; +use Paddle\SDK\Entities\Shared\PriceQuantity; +use Paddle\SDK\Entities\Shared\TaxCategory; +use Paddle\SDK\Entities\Shared\TaxMode; +use Paddle\SDK\Entities\Shared\TimePeriod; use Paddle\SDK\Entities\Subscription\SubscriptionEffectiveFrom; use Paddle\SDK\Entities\Subscription\SubscriptionItems; +use Paddle\SDK\Entities\Subscription\SubscriptionItemsWithPrice; +use Paddle\SDK\Entities\Subscription\SubscriptionNonCatalogPrice; +use Paddle\SDK\Entities\Subscription\SubscriptionNonCatalogPriceWithProduct; +use Paddle\SDK\Entities\Subscription\SubscriptionNonCatalogProduct; use Paddle\SDK\Entities\Subscription\SubscriptionOnPaymentFailure; use Paddle\SDK\Entities\Subscription\SubscriptionProrationBillingMode; use Paddle\SDK\Entities\Subscription\SubscriptionResumeEffectiveFrom; @@ -105,6 +116,43 @@ public static function updateOperationsProvider(): \Generator items: [ new SubscriptionItems('pri_01gsz91wy9k1yn7kx82aafwvea', 1), new SubscriptionItems('pri_01gsz91wy9k1yn7kx82bafwvea', 5), + new SubscriptionItemsWithPrice( + new SubscriptionNonCatalogPrice( + 'some description', + 'some name', + 'pro_01gsz4t5hdjse780zja8vvr7jg', + TaxMode::AccountSetting(), + new Money('1', CurrencyCode::GBP()), + [], + new PriceQuantity(1, 3), + new CustomData(['key' => 'value']), + new TimePeriod(Interval::Day(), 1), + new TimePeriod(Interval::Day(), 2), + ), + 2, + ), + new SubscriptionItemsWithPrice( + new SubscriptionNonCatalogPriceWithProduct( + 'some description', + 'some name', + new SubscriptionNonCatalogProduct( + 'some name', + 'some description', + CatalogType::Custom(), + TaxCategory::DigitalGoods(), + 'https://www.example.com/image.jpg', + new CustomData(['key' => 'value']), + ), + TaxMode::AccountSetting(), + new Money('1', CurrencyCode::GBP()), + [], + new PriceQuantity(1, 3), + new CustomData(['key' => 'value']), + new TimePeriod(Interval::Day(), 1), + new TimePeriod(Interval::Day(), 2), + ), + 2, + ), ], customData: new CustomData(['early_access' => true]), prorationBillingMode: SubscriptionProrationBillingMode::FullImmediately(), @@ -575,6 +623,43 @@ public static function previewUpdateOperationsProvider(): \Generator items: [ new SubscriptionItems('pri_01gsz91wy9k1yn7kx82aafwvea', 1), new SubscriptionItems('pri_01gsz91wy9k1yn7kx82bafwvea', 5), + new SubscriptionItemsWithPrice( + new SubscriptionNonCatalogPrice( + 'some description', + 'some name', + 'pro_01gsz4t5hdjse780zja8vvr7jg', + TaxMode::AccountSetting(), + new Money('1', CurrencyCode::GBP()), + [], + new PriceQuantity(1, 3), + new CustomData(['key' => 'value']), + new TimePeriod(Interval::Day(), 1), + new TimePeriod(Interval::Day(), 2), + ), + 2, + ), + new SubscriptionItemsWithPrice( + new SubscriptionNonCatalogPriceWithProduct( + 'some description', + 'some name', + new SubscriptionNonCatalogProduct( + 'some name', + 'some description', + CatalogType::Custom(), + TaxCategory::DigitalGoods(), + 'https://www.example.com/image.jpg', + new CustomData(['key' => 'value']), + ), + TaxMode::AccountSetting(), + new Money('1', CurrencyCode::GBP()), + [], + new PriceQuantity(1, 3), + new CustomData(['key' => 'value']), + new TimePeriod(Interval::Day(), 1), + new TimePeriod(Interval::Day(), 2), + ), + 2, + ), ], customData: new CustomData(['early_access' => true]), prorationBillingMode: SubscriptionProrationBillingMode::FullImmediately(), diff --git a/tests/Functional/Resources/Subscriptions/_fixtures/request/preview_update_full.json b/tests/Functional/Resources/Subscriptions/_fixtures/request/preview_update_full.json index 0201ca7..a1929b8 100644 --- a/tests/Functional/Resources/Subscriptions/_fixtures/request/preview_update_full.json +++ b/tests/Functional/Resources/Subscriptions/_fixtures/request/preview_update_full.json @@ -13,7 +13,74 @@ "scheduled_change": null, "items": [ { "price_id": "pri_01gsz91wy9k1yn7kx82aafwvea", "quantity": 1 }, - { "price_id": "pri_01gsz91wy9k1yn7kx82bafwvea", "quantity": 5 } + { "price_id": "pri_01gsz91wy9k1yn7kx82bafwvea", "quantity": 5 }, + { + "price": { + "custom_data": { + "key": "value" + }, + "description": "some description", + "name": "some name", + "product_id": "pro_01gsz4t5hdjse780zja8vvr7jg", + "quantity": { + "maximum": 3, + "minimum": 1 + }, + "tax_mode": "account_setting", + "unit_price": { + "amount": "1", + "currency_code": "GBP" + }, + "unit_price_overrides": [], + "billing_cycle": { + "frequency": 1, + "interval": "day" + }, + "trial_period": { + "frequency": 2, + "interval": "day" + } + }, + "quantity": 2 + }, + { + "price": { + "custom_data": { + "key": "value" + }, + "description": "some description", + "name": "some name", + "product": { + "custom_data": { + "key": "value" + }, + "description": "some description", + "image_url": "https://www.example.com/image.jpg", + "name": "some name", + "tax_category": "digital-goods", + "type": "custom" + }, + "quantity": { + "maximum": 3, + "minimum": 1 + }, + "tax_mode": "account_setting", + "unit_price": { + "amount": "1", + "currency_code": "GBP" + }, + "unit_price_overrides": [], + "billing_cycle": { + "frequency": 1, + "interval": "day" + }, + "trial_period": { + "frequency": 2, + "interval": "day" + } + }, + "quantity": 2 + } ], "proration_billing_mode": "full_immediately", "custom_data": { diff --git a/tests/Functional/Resources/Subscriptions/_fixtures/request/update_full.json b/tests/Functional/Resources/Subscriptions/_fixtures/request/update_full.json index 0201ca7..a1929b8 100644 --- a/tests/Functional/Resources/Subscriptions/_fixtures/request/update_full.json +++ b/tests/Functional/Resources/Subscriptions/_fixtures/request/update_full.json @@ -13,7 +13,74 @@ "scheduled_change": null, "items": [ { "price_id": "pri_01gsz91wy9k1yn7kx82aafwvea", "quantity": 1 }, - { "price_id": "pri_01gsz91wy9k1yn7kx82bafwvea", "quantity": 5 } + { "price_id": "pri_01gsz91wy9k1yn7kx82bafwvea", "quantity": 5 }, + { + "price": { + "custom_data": { + "key": "value" + }, + "description": "some description", + "name": "some name", + "product_id": "pro_01gsz4t5hdjse780zja8vvr7jg", + "quantity": { + "maximum": 3, + "minimum": 1 + }, + "tax_mode": "account_setting", + "unit_price": { + "amount": "1", + "currency_code": "GBP" + }, + "unit_price_overrides": [], + "billing_cycle": { + "frequency": 1, + "interval": "day" + }, + "trial_period": { + "frequency": 2, + "interval": "day" + } + }, + "quantity": 2 + }, + { + "price": { + "custom_data": { + "key": "value" + }, + "description": "some description", + "name": "some name", + "product": { + "custom_data": { + "key": "value" + }, + "description": "some description", + "image_url": "https://www.example.com/image.jpg", + "name": "some name", + "tax_category": "digital-goods", + "type": "custom" + }, + "quantity": { + "maximum": 3, + "minimum": 1 + }, + "tax_mode": "account_setting", + "unit_price": { + "amount": "1", + "currency_code": "GBP" + }, + "unit_price_overrides": [], + "billing_cycle": { + "frequency": 1, + "interval": "day" + }, + "trial_period": { + "frequency": 2, + "interval": "day" + } + }, + "quantity": 2 + } ], "proration_billing_mode": "full_immediately", "custom_data": {