Skip to content

Add support for the prices API.#246

Open
astex wants to merge 6 commits intoadrienverge:masterfrom
astex:add-prices-api
Open

Add support for the prices API.#246
astex wants to merge 6 commits intoadrienverge:masterfrom
astex:add-prices-api

Conversation

@astex
Copy link

@astex astex commented Aug 6, 2025

Prices is a replacement for the legacy Plans API from Stripe. From their documentation:

You can now model subscriptions more flexibly using the Prices API. It
replaces the Plans API and is backwards compatible to simplify your
migration.

This resolves #160.

@astex astex changed the title Add an initial version of the /prices API. Add support for the prices API. Aug 6, 2025
Copy link
Collaborator

@feliixx feliixx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @astex,

thank you for the PR, it does look like a useful addition !

Before diving into the code, can you please:

  • make sure that the PR doesn't break the existing tests. (Currently the PR breaks some subscription related tests. To make sure that the tests pass, start a Localstripe instance and run ./test.sh, and all tests should pass)
  • add some new tests to cover this code, so we don't break it by accident in the future (you can mimic a few of the existing ones that are already presents for Plans if you want)
  • fix the minor issues noticed by the linter (ie, flake8 . should not raise any error)

(sorry for the extra work 😅)

@astex
Copy link
Author

astex commented Aug 7, 2025

Hi @astex,

thank you for the PR, it does look like a useful addition !

Before diving into the code, can you please:

  • make sure that the PR doesn't break the existing tests. (Currently the PR breaks some subscription related tests. To make sure that the tests pass, start a Localstripe instance and run ./test.sh, and all tests should pass)
  • add some new tests to cover this code, so we don't break it by accident in the future (you can mimic a few of the existing ones that are already presents for Plans if you want)
  • fix the minor issues noticed by the linter (ie, flake8 . should not raise any error)8.

(sorry for the extra work 😅)

Thanks for the response.

I wasn't sure how to run tests locally. I'm more used to setups like tox or pytest. I'll get right on that.

Ditto flake8. I've used it extensively, but wasn't sure if your repo did so. How would you feel about a PR to make it run automatically pre-commit?

@adrienverge
Copy link
Owner

Ditto flake8. I've used it extensively, but wasn't sure if your repo did so. How would you feel about a PR to make it run automatically pre-commit?

Hello @astex, good idea to set this locally on your computer, but no need to commit that (anyone can run linters in their preferred way). Let's keep the repo minimalist and easily understandable.

@astex astex requested a review from feliixx August 8, 2025 01:47
@astex
Copy link
Author

astex commented Aug 8, 2025

Alright. Tests ran locally. This should be ready for review.

astex added 6 commits August 7, 2025 22:14
Prices is a replacement for the legacy Plans API from Stripe. From their
documentation:

> You can now model subscriptions more flexibly using the Prices API. It
> replaces the Plans API and is backwards compatible to simplify your
> migration.

This PR implements a partial version of the Prices API containing only
the fields currently required.
Copy link
Collaborator

@feliixx feliixx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing the tests and adding new ones !
I'm not familiar with the price API (we don't use it yet), so I only have a few minor comments.

Once they are fixed, can you also please squash all commits into a single one ?

(@adrienverge @H--o-l : I ran our company internal test suit with this PR and it works fine)

assert type(plan) is str
if plan is None:
assert isinstance(price, str)
assert plan is None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you meant

Suggested change
assert plan is None
assert price is None

?

and why not adding a similar assert in the elif price is None branch ?

customer_obj = Customer._api_retrieve(customer)
if subscription_items:
for si in subscription_items:
Plan._api_retrieve(si['plan']) # to return 404 if not existant
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the existing comments, here and in the rest of the file (there are two other place where this comment was removed in the rest of the file)

Also, can you add this # to return 404 if not existant to the Price._api_retrieve(si['price']) lines you added ? it looks like you added the comment in some places but not always

assert isinstance(item['price'], str)
assert 'plan' not in item
elif 'plan' in item:
assert isinstance(item['plan'], str)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not adding a similar assert 'price' not in item here ?

@yES
Copy link

yES commented Feb 7, 2026

@astex hello! Could you fix PR comments please? Really need your changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for Prices and attaching Price items to subscriptions

4 participants