Skip to content

Commit

Permalink
Feature: Support custom prices when updating and previewing subscript…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
davidgrayston-paddle committed Sep 12, 2024
1 parent 0f51f7f commit 6e2e7fe
Show file tree
Hide file tree
Showing 8 changed files with 232 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions src/Entities/Subscription/SubscriptionNonCatalogPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,7 +22,7 @@ class PreviewUpdateSubscription implements \JsonSerializable
use FiltersUndefined;

/**
* @param array<SubscriptionItems> $items
* @param array<SubscriptionItems|SubscriptionItemsWithPrice> $items
*/
public function __construct(
public readonly string|Undefined $customerId = new Undefined(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,7 +22,7 @@ class UpdateSubscription implements \JsonSerializable
use FiltersUndefined;

/**
* @param array<SubscriptionItems> $items
* @param array<SubscriptionItems|SubscriptionItemsWithPrice> $items
*/
public function __construct(
public readonly string|Undefined $customerId = new Undefined(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 6e2e7fe

Please sign in to comment.