Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Product default price is an array when using tiered prices #40

Closed
okolvik-avento opened this issue Nov 3, 2024 · 2 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@okolvik-avento
Copy link

Description

Default price is an array when using tiered prices.
This causes the getDefaultPrice function on the Product element to return null since it expects data["default_price"] to be the id of the price.
When using tiers the default price is in data["default_price"]["id"].

The easiest way to fix this is to add an additional array check in the price filter function.

Here's the data-json for a default price with no tiers mode (when the first tier is equal to the next tier).

{
    "id": "price_xxx",
    "object": "price",
    "active": true,
    "billing_scheme": "per_unit",
    "created": 1671093832,
    "currency": "nok",
    "custom_unit_amount": null,
    "livemode": false,
    "lookup_key": null,
    "metadata": [],
    "nickname": null,
    "product": "prod_xxx",
    "recurring": {
        "aggregate_usage": null,
        "interval": "month",
        "interval_count": 1,
        "meter": null,
        "trial_period_days": null,
        "usage_type": "licensed"
    },
    "tax_behavior": "unspecified",
    "tiers_mode": null,
    "transform_quantity": null,
    "type": "recurring",
    "unit_amount": 100,
    "unit_amount_decimal": "100"
}

And here is one with tiers mode graduated (when the next tier changes price based on count):

{
    "id": "price_yyy",
    "object": "price",
    "active": true,
    "billing_scheme": "tiered",
    "created": 1678099575,
    "currency": "nok",
    "custom_unit_amount": null,
    "livemode": false,
    "lookup_key": null,
    "metadata": [],
    "nickname": "2023",
    "product": "prod_yyy",
    "recurring": {
        "aggregate_usage": null,
        "interval": "year",
        "interval_count": 1,
        "meter": null,
        "trial_period_days": null,
        "usage_type": "licensed"
    },
    "tax_behavior": "unspecified",
    "tiers_mode": "graduated",
    "transform_quantity": null,
    "type": "recurring",
    "unit_amount": null,
    "unit_amount_decimal": null
}

Steps to reproduce

  1. Set up tiered prices with a default price
  2. Try to run product.defaultPrice
  3. Get null

Additional info

  • Craft version: 5.4.9
  • Stripe version: 1.1.0
@okolvik-avento okolvik-avento added the bug Something isn't working label Nov 3, 2024
@i-just i-just self-assigned this Nov 7, 2024
@i-just
Copy link
Contributor

i-just commented Nov 7, 2024

Hi, thanks for reporting! I raised a PR for this.

@i-just
Copy link
Contributor

i-just commented Nov 20, 2024

Stripe 1.3.0 is out with a fix for that. Thanks again!

@i-just i-just closed this as completed Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants