dj-stripe automatically syncs your Stripe Data to your local database as pre-implemented Django Models allowing you to use the Django ORM, in your code, to work with the data making it easier and faster.
MIT License
Published by jleclanche over 6 years ago
In dj-stripe 1.1.0, we made a lot of changes to models in order to bring the dj-stripe model state much closer to the upstream API objects.
If you are a current user of dj-stripe, you will most likely have to make changes in order to upgrade. Please read the full changelog below.
If you are having trouble upgrading, you may ask for help by filing an issue on GitHub.
The next version of dj-stripe, 1.2.0, will reset all the migrations to 0001_initial
. Migrations are currently in an unmaintainable state.
What this means is you will not be able to upgrade directly to dj-stripe 1.2.0. You must go through 1.1.0 first, run manage.py migrate djstripe
, then upgrade to 1.2.0. Once on 1.2.0, you'll need to clear your migrations table of dj-stripe entries and then run manage.py migrate djstripe --fake
dj-stripe 1.1.0 drops support for Django 1.10 and adds support for Django 2.0. Django 1.11+ and Python 2.7+ or 3.4+ are required.
Support for Python versions older than 3.5, and Django versions older than 2.0, will be dropped in dj-stripe 1.3.0.
The model architecture of dj-stripe has been simplified. Polymorphic models have been dropped and the old base StripeCustomer, StripeCharge, StripeInvoice, etc models have all been merged into the top-level Customer, Charge, Invoice, etc models.
Importing those legacy models from djstripe.stripe_objects
will yield the new ones. This is deprecated and support for this will be dropped in dj-stripe 1.3.0.
Stripe sources (src_XXXX
) are objects that can arbitrarily reference any of the payment method types that Stripe supports.
However, the legacy Card
object (with object IDs like card_XXXX
or cc_XXXX
) is not a Source object, and cannot be turned into a Source object at this time.
In order to support both Card and Source objects in ForeignKeys, a new model PaymentMethod
has been devised. That model can resolve into a Card, a Source, or a BankAccount object.
default_source
attribute on Customer
now refers to a PaymentMethod
object. You will need to call .resolve()
on it to get the Card or Source in question.Customer.sources
expecting a queryset of Card objects should be updated to Customer.legacy_cards
.StripeSource
name refers to the Card
model. This will be removed in dj-stripe 1.3.0. Update your references to either Card
or Source
.enums.SourceType
has been renamed to enums.LegacySourceType
. enums.SourceType
now refers to the actual Stripe Source types enum.id
field has been renamed to djstripe_id
. This avoids a clash with the upstream stripe id. Accessing .id
is deprecated and will reference the upstream stripe_id
in dj-stripe 1.3.0 instead.created
field has been renamed djstripe_created
.modified
field has been renamed djstripe_updated
.stripe_timestamp
field has been renamed created
, to match the upstream field name. stripe_timestamp
is still usable, but will be removed in dj-stripe 1.3.0.The Event
model previously hosted logic for both the stripe Event
model, and whether the event had been processed from a webhook.
Event.validate()
has been moved to the new WebhookEventTrigger
class, which now hosts all webhook-related logicEvent.valid
has been dropped.Event.processed
has been dropped.Event.customer
is no longer mutable, but instead calculated in a property.Event.process
has changed.EventProcessingException
model has been dropped.Event.received_api_version
has been renamed to Event.api_version
.Event.webhook_message
has been renamed to Event.data
exists_by_json()
manager method has been dropped.views.WebHook
has been renamed to views.ProcessWebhookView
The django-rest-framework integration is not used by any of the dj-stripe maintainers and has become unmaintained. We are deprecating it and will most likely be removing it in dj-stripe 1.3.0.
If you are interested in maintaining it, please let us know by filing an issue so that it can be moved to its own library.
The following models have been added:
BankAccount
Dispute
(Note: charge.disputed
is now a property instead of a field)FileUpload
Product
Refund
The following models have been updated to (mostly) match the Stripe upstream models:
Account
Invoice
Plan
Customer.add_coupon()
now supports the idempotency_key
argument.manage.py sync_plans_from_stripe
syncs the plans on Stripe to dj-stripe.STRIPE_API_HOST
. You may set it to an URL of your choice to change the Stripe API server the Stripe library talks to. This is only for local development purposes if you use something such as stripe-mock and will raise a check warning when DEBUG=False
.Card.country
is now nullable. Some cards may not have a country set.utils.get_friendly_currency_amount()
now always shows two decimals (eg. $10.00 USD
).charge.dispute.*
events. This will return once it works.Customer.credits
and Customer.pending_charges
properties parse the multi-purpose account_balance
field to return credits and pending charges, respectively.Subscription.STATUS_*
fields have been dropped.Transfer.STATUS_*
fields have been dropped.Published by kavdev over 6 years ago
We're pushing out a quick cherry-pick bugfix release to fix some blocking issues for new installations:
rk_*
) in checksHuge thanks to @jleclanche for sparing the time to get this out there.
Published by kavdev about 7 years ago
It's finally here! We've made significant changes to the codebase and are now compliant with stripe API version 2017-06-05.
I want to give a huge thanks to all of our contributors for their help in making this happen, especially Bill Huneke (@wahuneke) for his impressive design work and Jerome Leclanche (@jleclanche) for really pushing this release along.
I also want to welcome onboard two more maintainers, Jerome Leclanche (@jleclanche) and Lee Skillen (@lskillen). They've stepped up and have graciously dedicated their resources to making dj-stripe such an amazing package.
Almost all methods now mimic the parameters of those same methods in the stripe API. Note that some methods do not have some parameters implemented. This is intentional. That being said, expect all method signatures to be different than those in previous versions of dj-stripe.
Finally, please note that there is still a bit of work ahead of us. Not everything in the Stripe API is currently supported by dj-stripe -- we're working on it. That said, v1.0.0 has been thoroughly tested and is verified stable in production applications.
livemode
isn't set on your existing customer objects.djstripe.enums
module. The ability to check against model property based choices will be deprecated in 1.12017-04-06
.Documentation. Our original documentation was not very helpful, but it covered the important bits. It will be very out of date after this update and will need to be rewritten. If you feel like helping, we could use all the help we can get to get this pushed out asap.
Master sync re-write. This sounds scary, but really isn't. The current management methods run sync methods on Customer that aren't very helpful and are due for removal. My plan is to write something that first updates local data (via api_retrieve
and sync_from_stripe_data
) and then pulls all objects from Stripe and populates the local database with any records that don't already exist there.
You might be wondering, "Why are they releasing this if there are only a few things left?" Well, that thinking turned this into a two year release... Trust me, this is a good thing.
Customer.get_or_create()
. Idempotency will be enabled for all calls that need it.PLAN_CHOICES
, PLAN_LIST
, and PAYMENT_PLANS
objects are removed. Use Plan.objects.all() instead.plan_from_stripe_id
function is removed. Use Plan.objects.get(stripe_id=)cu
parametersubscriber_passes_pay_test
, be sure to account for this new argument.PaymentsContextMixin
now provides STRIPE_PUBLIC_KEY
and plans
(changed to Plan.objects.all()
). SubscriptionMixin
now provides customer
and is_plans_plural
.@method_decorator("dispatch",
subscription_payment_required)
instead.cancelled
-> WEBHOOK_SIGNALS["customer.subscription.deleted"]
card_changed
-> WEBHOOK_SIGNALS["customer.source.updated"]
subscription_made
-> WEBHOOK_SIGNALS["customer.subscription.created"]
event_handlers.py
and webhooks.py
.SubscriptionUpdateFailure
and SubscriptionCancellationFailure
exceptions are removed. There should no longer be a case where they would have been useful. Catch native stripe errors in their place instead.CHARGE
Charge.charge_created
-> Charge.stripe_timestamp
Charge.card_last_4
and Charge.card_kind
are removed. Use Charge.source.last4
and Charge.source.brand
(if the source is a Card)Charge.invoice
is no longer a foreign key to the Invoice model. Invoice
now has a OneToOne relationship with Charge
. (Charge.invoice
will still work, but will no longer be represented in the database).CUSTOMER
<subscriber_model>.customer
OneToOne reverse relationship is no longer a thing. You should now instead add a customer
property to your subscriber model that checks whether you're in live or test mode (see djstripe.settings.STRIPE_LIVE_MODE as an example) and grabs the customer from <subscriber_model>.djstripe_customers
with a simple livemode=
filter.current_subscription
property. We've added a subscription
property that should suit your needs.Customer.subscribe()
has changed. Before, calling subscribe()
when a customer was already subscribed to a plan would switch the customer to the new plan with an option to prorate. Now calling subscribe()
simply subscribes that customer to a new plan in addition to it's current subsription. Use Subscription.update()
to change a subscription's plan instead.Customer.cancel_subscription()
is removed. Use Subscription.cancel()
instead.Customer.update_plan_quantity()
method is removed. Use Subscription.update()
instead.CustomerManager
is now SubscriptionManager
and works on the Subscription
model instead of the Customer
model.Customer.has_valid_card()
is now Customer.has_valid_source()
.Customer.update_card()
now takes an id. If the id is not supplied, the default source is updated.Customer.stripe_customer
property is removed. Use Customer.api_retrieve()
instead.at_period_end
parameter of Customer.cancel_subscription()
now actually follows the DJSTRIPE_PRORATION_POLICY setting.Customer.card_fingerprint
, Customer.card_last_4
, Customer.card_kind
, Customer.card_exp_month
, Customer.card_exp_year
are all removed. Check Customer.default_source
(if it's a Card) or one of the sources in Customer.sources
(again, if it's a Card) instead.invoice_id
parameter of Customer.add_invoice_item
is now named invoice
and can be either an Invoice object or the stripe_id of an Invoice.EVENT
Event.kind
-> Event.type
Event.validated_message
. Just check if the event is valid
TRANSFER
Transfer.update_status()
Transfer.event
TransferChargeFee
is removed. It hasn't been used in a while due to a broken API version. Use Transfer.fee_details
instead.Transfer.summary
no longer exist and are therefore deprecated (unused but not removed from the database). Because of this, TransferManager
now only aggregates total_sum
INVOICE
Invoice.attempts
-> Invoice.attempt_count
INVOICEITEM
InvoiceItem.line_type
PLAN
stripe_plan
property. Use api_retrieve()
instead.Plan.currency
no longer uses choices. Use the get_supported_currency_choices()
utility and create your own custom choices list instead.Plan.INTERVAL_TYPE_CHOICES
SUBSCRIPTION
Subscription.is_period_current()
now checks for a current trial end if the current period has ended. This change means subscriptions extended with Subscription.extend()
will now be seen as valid.We'll sync your current records with Stripe in a migration. It will take a while, but it's the only way we can ensure data integrity. There were some fields for which we needed to temporarily add placeholder defaults, so just make sure you have a customer with ID 1 and a plan with ID 1 and you shouldn't run into any issues (create dummy values for these if need be and delete them after the migration).
DJSTRIPE_USE_NATIVE_JSONFIELD
setting. (Thanks @jleclanche) #517, #523DJSTRIPE_SEND_INVOICE_RECEIPT_EMAILS
into account (Thanks @r0fls)SubscriptionPaymentMiddleware
(Thanks @pydanny)SubscriptionPaymentMiddleware.process_request()
functionality broken up into multiple methods, making local customizations easier (Thanks @pydanny)tax_percent
to CreateSubscriptionSerializer (Thanks @aleccool213) #349application_fee
in Charge calls (Thanks @kronok) #382Plan.amount_in_cents
(Thanks @jleclanche) #466Subscription.reactivate()
(Thanks @jleclanche) #470Plan.human_readable_price
(Thanks @jleclanche) #498Published by pydanny almost 9 years ago
Best way to install: pip install dj-stripe
Published by pydanny about 9 years ago
Best way to install: pip install dj-stripe
update_plan_quantity
call (Thanks @ctrengove)Published by pydanny over 9 years ago
Best way to install: pip install dj-stripe
Published by pydanny over 9 years ago
Published by pydanny over 9 years ago
Published by pydanny over 9 years ago
Published by pydanny almost 11 years ago
False
).djstripe.utils.user_has_active_subscription
.