Skip to content

Commit

Permalink
sync_subscription_from_stripe_data: use sync_plan
Browse files Browse the repository at this point in the history
This ensures that the plan exists locally, which might not be the case
when it has been deleted in Django, but still exists on Stripe.
  • Loading branch information
blueyed committed Oct 26, 2017
1 parent f1cfb73 commit 11b4239
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions pinax/stripe/actions/plans.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ def sync_plan(plan, event=None):
defaults=defaults
)
utils.update_with_defaults(obj, defaults, created)
return obj
5 changes: 3 additions & 2 deletions pinax/stripe/actions/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import stripe

from .. import hooks, models, utils
from .. import actions, hooks, models, utils
from .coupons import sync_coupon_from_stripe_data


Expand Down Expand Up @@ -145,6 +145,7 @@ def sync_subscription_from_stripe_data(customer, subscription):
Returns:
the pinax.stripe.models.Subscription object created or updated
"""
plan = actions.plans.sync_plan(subscription["plan"])
defaults = dict(
customer=customer,
application_fee_percent=subscription["application_fee_percent"],
Expand All @@ -153,7 +154,7 @@ def sync_subscription_from_stripe_data(customer, subscription):
current_period_start=utils.convert_tstamp(subscription["current_period_start"]),
current_period_end=utils.convert_tstamp(subscription["current_period_end"]),
ended_at=utils.convert_tstamp(subscription["ended_at"]),
plan=models.Plan.objects.get(stripe_id=subscription["plan"]["id"]),
plan=plan,
quantity=subscription["quantity"],
start=utils.convert_tstamp(subscription["start"]),
status=subscription["status"],
Expand Down

0 comments on commit 11b4239

Please sign in to comment.