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

Added DjStripeHTTPClient to handle all Stripe API calls. #1913

Open
wants to merge 29 commits into
base: master
Choose a base branch
from

Conversation

arnav13081994
Copy link
Collaborator

@arnav13081994 arnav13081994 commented Mar 30, 2023

PR #1909 and PR #1910 need to be merged before this PR can be merged.

This PR adds support for DjStripeHTTPClient that provides out of the box the following capabilities:

  1. Built-in retires for rate_limit errors
  2. Built-in retires for lock_timeout errors
  3. Built-in support for using or creating Idempotency keys as the case may be.

@arnav13081994 arnav13081994 changed the title Feature/add http client (TEST) Added DjStripeHTTPClient to handle all Stripe API calls. Mar 30, 2023
@arnav13081994 arnav13081994 force-pushed the feature/add_http_client branch 5 times, most recently from 54f4276 to 3622742 Compare March 31, 2023 04:45
djstripe/http_client.py Fixed Show fixed Hide fixed
djstripe/http_client.py Fixed Show fixed Hide fixed
djstripe/http_client.py Fixed Show fixed Hide fixed
djstripe/http_client.py Fixed Show fixed Hide fixed
djstripe/http_client.py Fixed Show fixed Hide fixed
@arnav13081994 arnav13081994 force-pushed the feature/add_http_client branch 4 times, most recently from 91d768a to 67332d8 Compare April 2, 2023 05:04
@arnav13081994 arnav13081994 changed the title (TEST) Added DjStripeHTTPClient to handle all Stripe API calls. Added DjStripeHTTPClient to handle all Stripe API calls. Apr 13, 2023
@arnav13081994 arnav13081994 changed the title Added DjStripeHTTPClient to handle all Stripe API calls. (Test) Added DjStripeHTTPClient to handle all Stripe API calls. Apr 13, 2023
@arnav13081994 arnav13081994 marked this pull request as draft April 13, 2023 08:51
@arnav13081994 arnav13081994 self-assigned this Apr 13, 2023
… Model

This was done because one can create multiple independent update requests
for the exact same Stripe object.
The _api_update() method now does the following:

1) Generates a new Idempotency Key object if not given one using the
   Stripe object's ID that is being updated.
2) Uses the Idempotency key (from 1)) to make the Stripe API call.
3) Updates the metadata of the Stripe object with the idempotency_key
   key if the Stripe object supports the metadata key.
This was done in order for the STRIPE_TEST_SECRET_KEY env var
to be passed from tox to pytest.
This was done in order to get around RateLimit and
other related errors.
This was done because tests would fail due to low
coverage of tests using the api. This is a temp fix
until more tests can be added.
@arnav13081994 arnav13081994 force-pushed the feature/add_http_client branch 2 times, most recently from 382696b to 2cca5c7 Compare April 13, 2023 09:21
@arnav13081994 arnav13081994 changed the title (Test) Added DjStripeHTTPClient to handle all Stripe API calls. Added DjStripeHTTPClient to handle all Stripe API calls. Apr 13, 2023
@arnav13081994 arnav13081994 marked this pull request as ready for review April 13, 2023 10:48
@samamorgan
Copy link

samamorgan commented Mar 12, 2024

My two cents: I'm not fond of adding an additional layer of abstraction to the Stripe Python client. These are already features that exist in that client, and adding this layer of abstraction absolutely will introduce confusion, as well as increasing maintenance costs.

Additionally, adding test flags is a code smell. If you need flags to test the code, then the code should be refactored to be more appropriately testable.

If having default retries/rate limit handling is desired, a more appropriate approach would be to configure a central stripe-python client instance and force all dj-stripe API call methods to use that client instance.

@jleclanche jleclanche force-pushed the master branch 5 times, most recently from 15e04c3 to 8727894 Compare April 25, 2024 14:48
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

2 participants