paddle-php-sdk icon indicating copy to clipboard operation
paddle-php-sdk copied to clipboard

$quantity and $unitPriceOverrides in TransactionNonCatalogPrice class should be optional/nullable?

Open dutypro opened this issue 5 months ago • 7 comments

Describe the bug

As per the docs for previewing a transaction: https://developer.paddle.com/api-reference/transactions/preview-transaction

Both price.unit_price_overrides and price.quantity are optional on the 'Non catalog price for an existing product' item requirements.

The TransactionNonCatalogPrice doesn't allow null for the constructor signatures. Same for customData.

Should they be nullable to allow omission (and adopt default values for price.quantity)?

If so, let me know your thoughts and I'll submit a PR. I'm going to be working on the 'Non-catalog price and product' workflow tomorrow so if I find the same, I'll lump it all in to one PR.

Steps to reproduce

Entities > Transaction > TransactionNonCatalogPrice.php

Expected behavior

Allow unitPriceOverrides, quantity and customData to be null as they are optional.

Code snippets

class TransactionNonCatalogPrice
{
    /**
     * @param array<UnitPriceOverride> $unitPriceOverrides
     */
    public function __construct(
        public string $description,
        public string|null $name,
        public TimePeriod|null $billingCycle,
        public TimePeriod|null $trialPeriod,
        public TaxMode $taxMode,
        public Money $unitPrice,
        public array $unitPriceOverrides,
        public PriceQuantity $quantity,
        public CustomData|null $customData,
        public string $productId,
    ) {
    }
}

// I think it should be (keys still need to be passed as API requires them):

class TransactionNonCatalogPrice
{
    /**
     * @param array<UnitPriceOverride> $unitPriceOverrides
     */
    public function __construct(
        public string $description,
        public string|null $name,
        public TimePeriod|null $billingCycle,
        public TimePeriod|null $trialPeriod,
        public TaxMode $taxMode,
        public Money $unitPrice,
        public array|null $unitPriceOverrides,
        public PriceQuantity|null $quantity,
        public CustomData|null $customData,
        public string $productId,
    ) {
    }
}

PHP version

8.3.10

SDK version

1.3.1

API version

1

Additional context

If you agree it's a bug, I'll submit a PR in the next couple of days.

dutypro avatar Oct 04 '24 00:10 dutypro