Skip to content

Commit

Permalink
- added subscription deletion webhook code
Browse files Browse the repository at this point in the history
  • Loading branch information
747project committed Feb 4, 2015
1 parent 35ef679 commit 9123bad
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion djstripe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,12 @@ def process(self):
if not self.customer:
self.link_customer()
if self.customer:
self.customer.sync_current_subscription()
if self.kind == 'customer.subscription.deleted':
self.customer.delete_current_subscription(
self.message["data"]["object"]["plan"]["id"]
)
else:
self.customer.sync_current_subscription()
elif self.kind == "customer.deleted":
if not self.customer:
self.link_customer()
Expand Down Expand Up @@ -478,6 +483,15 @@ def sync_charges(self, cu=None, **kwargs):
for charge in cu.charges(**kwargs).data:
self.record_charge(charge.id)

def delete_current_subscription(self, plan_id, cu=None):
cu = cu or self.stripe_customer
try:
sub_obj = self.current_subscription
if sub_obj.plan == plan_id:
sub_obj.delete()
except CurrentSubscription.DoesNotExist:
pass

def sync_current_subscription(self, cu=None):
cu = cu or self.stripe_customer
sub = cu.subscription
Expand Down

0 comments on commit 9123bad

Please sign in to comment.