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

add several list filtering improvements #186

Merged
merged 5 commits into from
Sep 1, 2021

Conversation

thrau
Copy link
Contributor

@thrau thrau commented Aug 21, 2021

This PR adds several improvements to listing products, plans, customers, and subscriptions (stripe features that we use at @localstack)

  • 3e46219: adds a dedicate list method for /v1/products to take the optional active=true|false keyword
  • 92e1e15: same deal, adds filters for /v1/plans
  • dfdccaf: enables the optional object=card filter argument to /v1/customers/{id}/sources
  • 1423038: allows the trial_from_plan boolean flag for /v1/subscriptions

I tried to conform to the semantic commit messages i found in the history, and tried to keep the code style as close to the original code as possible.
Happy to make changes.

Copy link
Owner

@adrienverge adrienverge left a comment

Choose a reason for hiding this comment

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

Hello Thomas, these additions are pretty clean! I have a few comments, but nothing blocking.

localstripe/resources.py Outdated Show resolved Hide resolved
localstripe/resources.py Outdated Show resolved Hide resolved
localstripe/resources.py Outdated Show resolved Hide resolved
localstripe/resources.py Outdated Show resolved Hide resolved
localstripe/resources.py Outdated Show resolved Hide resolved
@thrau
Copy link
Contributor Author

thrau commented Aug 26, 2021

thanks for the comments, will make the changes towards the weekend

@thrau thrau force-pushed the upstream-merge branch 2 times, most recently from 2963005 to 53f0024 Compare August 30, 2021 17:19
@thrau
Copy link
Contributor Author

thrau commented Aug 30, 2021

so i amended the history with the changes as suggested. and sorry in advance for the scope creep: i also added a couple of flake8 fixes and two lines to the gitignore (pycharm directories and the default .venv folder).
also added the implementation of the customers/:id/sources?object= filter

Copy link
Collaborator

@H--o-l H--o-l left a comment

Choose a reason for hiding this comment

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

Hey @thrau!

Awsome PR, these are simple and efficient improvements of localstripe.
I have no doubt they will be integrated soon.

I have a few feedback and proposition for you, I hope it's OK.

Also thanks for fixing flake8!

For .gitignore I'm -0.5 for .venv and -1 for .idea. These are specific to your environment, localstripe doesn't need them and we try to keep things minimal.

localstripe/resources.py Outdated Show resolved Hide resolved
localstripe/resources.py Outdated Show resolved Hide resolved
localstripe/resources.py Show resolved Hide resolved
localstripe/resources.py Show resolved Hide resolved
localstripe/resources.py Show resolved Hide resolved
@thrau
Copy link
Contributor Author

thrau commented Aug 31, 2021

i updated the PR with your change requests @H--o-l, hope to get this over the line now

@thrau
Copy link
Contributor Author

thrau commented Aug 31, 2021

with respect to the if kwargs check:

stripe does return an error on unknown arguments. however the error message is completely different from what localstripe returns:

 % curl "https://api.stripe.com/v1/plans?foo=bar" -u sk_test_4eC39HqLyjWDarjtT1zdp7dc:
{
  "error": {
    "code": "parameter_unknown",
    "doc_url": "https://stripe.com/docs/error-codes/parameter-unknown",
    "message": "Received unknown parameter: foo",
    "param": "foo",
    "type": "invalid_request_error"
  }
}

i mean sure, i'll add the assert to the methods i added (it's your project of course, so your decision). however

  1. some existing code is still inconsistent (e.g., PaymentMethod._api_list_all doesn't do the check either.
  2. i think this impedes the use of localstripe. some list APIs don't have all the existing optional arguments in their signatures, so using any of the query functionality that exists in stripe but isn't implemented in localstripe will break user code, which i think is worse than not getting errors back for requests that have invalid parameters. mostly you will use stripe clients to talk to the stripe server, which will check that stuff anyway.
  3. i'll have to resort using our fork, or spend significant time adding all the optional parameters to make it work

which is all fine i suppose, just something to think about.

anyway. i made all the requested changes.

localstripe/resources.py Outdated Show resolved Hide resolved
Copy link
Owner

@adrienverge adrienverge left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks again Thomas for your contribution.

  • some existing code is still inconsistent (e.g., PaymentMethod._api_list_all doesn't do the check either.

True. PaymentMethod._api_list_all should do it too.

  • i think this impedes the use of localstripe. some list APIs don't have all the existing optional arguments in their signatures, so using any of the query functionality that exists in stripe but isn't implemented in localstripe will break user code, which i think is worse than not getting errors back for requests that have invalid parameters. mostly you will use stripe clients to talk to the stripe server, which will check that stuff anyway.

Also true, but on the other hand it's helpful to get user-friendly error message when developing, e.g. "you passed argument typo, which is not accepted". Maybe the error message should be adapted, for instance like the following?

"Received unknown parameter: foo. It's either incorrect or not yet supported by localstripe."

@H--o-l thanks a lot for the review 🙂

Closes #188.

Comment on lines +953 to +955
if object is not None:
assert type(object) is str
assert object in ['card', 'bank_account']
Copy link
Owner

Choose a reason for hiding this comment

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

Thanks for implementing it in the end 👍

@adrienverge adrienverge merged commit 97f084f into adrienverge:master Sep 1, 2021
@thrau thrau deleted the upstream-merge branch June 29, 2022 18:20
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.

None yet

3 participants