PaddleHQ / paddle-php-sdk

PHP SDK for working with the Paddle API in server-side apps.
https://developer.paddle.com/
Apache License 2.0
28 stars 5 forks source link

Price constructor doesn't accept null #88

Open dutypro opened 1 week ago

dutypro commented 1 week ago

Describe the bug

When posting a Transaction Preview, the response doesn't allow Price to be null but I'm not sure if this is an API bug or an SDK handling bug.

My tested items array workflow:

Non-catalog price for an existing product

Steps to reproduce

  1. Submit a PreviewTransaction with items constructed with TransactionItemPreviewWithNonCatalogPrice.

Expected behavior

I wouldn't expect the Paddle API to generate a price_id for a transaction preview but it does seem to do so. Querying that price_id with the Get Price API returns a 404 so it doesn't seem to persist the ID anywhere.

The price_id also changes with every POST request so all evidence points to it generating a temporary one on the fly for whatever reason.

If this is the expected behaviour

_And it should return a price_id:_

  1. The data.items.price.id value currently returns null. Whereas it is generated in data.details.line_items.price_id. The generated price_id needs to be included as values for both of these objects. This is an API response fix.
  2. This will allow the SDK to work as constructed as the Price constructor expects a string and doesn't allow null.

If this is not the expected behaviour

_And it should not return a price_id:_

  1. The SDK needs to be able to accept a null value in the Price constructor.

Code snippets

// Example request:

{
    "address": {
        "country_code": "US"
    },
    "items": [
        {
            "price": {
                "description": "Test Sandbox Description",
                "name": "Test Price",
                "billing_cycle": {
                    "frequency": 12,
                    "interval": "month"
                },
                "trial_period": null,
                "tax_mode": "account_setting",
                "unit_price": {
                    "amount": "59900",
                    "currency_code": "USD"
                },
                "product_id": "pro_01j8tmpsfsy6qsj6mfvpy6hr87"
            },
            "quantity": 8,
            "include_in_totals": true
        }
    ],
    "customer_id": null,
    "currency_code": "USD",
    "discount_id": null,
    "ignore_trials": true
}

// Response

{
    "data": {
        "customer_id": null,
        "address_id": null,
        "business_id": null,
        "subscription_id": null,
        "currency_code": "USD",
        "address": {
            "postal_code": "",
            "country_code": "US"
        },
        "customer_ip_address": null,
        "discount_id": null,
        "items": [
            {
                "price": {
                    "id": null,
                    "description": "Test Sandbox Description",
                    "type": "custom",
                    "name": "Test Price",
                    "product_id": "pro_01j8tmpsfsy6qsj6mfvpy6hr87",
                    "billing_cycle": {
                        "interval": "month",
                        "frequency": 12
                    },
                    "trial_period": null,
                    "tax_mode": "account_setting",
                    "unit_price": {
                        "amount": "59900",
                        "currency_code": "USD"
                    },
                    "unit_price_overrides": [],
                    "custom_data": null,
                    "quantity": {
                        "minimum": 1,
                        "maximum": 100
                    },
                    "status": "active",
                    "created_at": "2024-10-04T11:05:26.429052975Z",
                    "updated_at": "2024-10-04T11:05:26.429052975Z",
                    "import_meta": null
                },
                "quantity": 8,
                "proration": null,
                "include_in_totals": true
            }
        ],
        "details": {
            "tax_rates_used": [
                {
                    "tax_rate": "0",
                    "totals": {
                        "subtotal": "479200",
                        "discount": "0",
                        "tax": "0",
                        "total": "479200"
                    }
                }
            ],
            "totals": {
                "subtotal": "479200",
                "tax": "0",
                "discount": "0",
                "total": "479200",
                "grand_total": "479200",
                "fee": null,
                "credit": "0",
                "credit_to_balance": "0",
                "balance": "479200",
                "earnings": null,
                "currency_code": "USD"
            },
            "line_items": [
                {
                    "price_id": "pri_01j9bk9em8zcwvsf9zz8w95026",
                    "quantity": 8,
                    "totals": {
                        "subtotal": "479200",
                        "tax": "0",
                        "discount": "0",
                        "total": "479200"
                    },
                    "product": {
                        "id": "pro_01j8tmpsfsy6qsj6mfvpy6hr87",
                        "name": "My Product",
                        "description": "My product description",
                        "type": "standard",
                        "tax_category": "saas",
                        "image_url": null,
                        "custom_data": {
                            "product_id": 1
                        },
                        "status": "active",
                        "import_meta": null,
                        "created_at": "2024-09-27T21:03:06.745Z",
                        "updated_at": "2024-09-29T20:02:30.932Z"
                    },
                    "tax_rate": "0",
                    "unit_totals": {
                        "subtotal": "59900",
                        "tax": "0",
                        "discount": "0",
                        "total": "59900"
                    },
                    "proration": null
                }
            ]
        },
        "ignore_trials": true,
        "ignore_minimum_charge": false,
        "available_payment_methods": [
            "apple_pay",
            "card",
            "paypal",
            "google_pay"
        ]
    },
    "meta": {
        "request_id": "d73dc594-b13c-4586-8301-2dee2bc7c507"
    }
}

PHP version

8.3.10

SDK version

1.3.1

API version

1

Additional context

No response

dutypro commented 1 week ago

See comments on #87