Skip to content

Commit

Permalink
Updated StripeModel._api_update() to use Idempotency Key object
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
arnav13081994 committed Mar 27, 2023
1 parent b2db45e commit ee12925
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions djstripe/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,16 @@ def _api_update(
if not stripe_account:
stripe_account = self._get_stripe_account_id(api_key)

kwargs, idempotency_key = self.__class__.add_idempotency_key_to_metadata(
action="update",
idempotency_key=idempotency_key,
stripe_obj_id=self.id,
**kwargs,
)

# Remove stripe_obj_id if it exists
kwargs.pop("stripe_obj_id", None)

return self.stripe_class.modify(
self.id,
api_key=api_key,
Expand Down
1 change: 1 addition & 0 deletions docs/history/2_8_0.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- `stripe.api_version` is no longer manipulated by dj-stripe.
- Resolved ambiguity between `LineItem` and `InvoiceItem` models. It was incorrectly assumed that the `lines` List object on `Invoice` and `UpcomingInvoice` models only return `InvoiceItem` objects. Moreover `LineItem` objects can also be of type `subscription` if the user adds a Subscription to their `Invoice` as a lineitem.
- Added support for `idempotency` keys. `djstripe` now automatically generates and puts keys in Stripe Object's Metadata (if possible). Users have the option to supply their own as well for `create` calls.
- Added support for `idempotency` keys for `update` calls. `djstripe` now automatically generates and puts keys in Stripe Object's Metadata (if possible). Users have the option to supply their own as well for `create` calls.

## Deprecated features

Expand Down

0 comments on commit ee12925

Please sign in to comment.