@@ -62,22 +62,31 @@ def invoice_payment_failed(self, invoice: stripe.Invoice) -> None:
62
62
self ._log_updated (updated )
63
63
64
64
def customer_subscription_deleted (self , subscription : stripe .Subscription ) -> None :
65
- log .info (
66
- "Customer Subscription Deleted - Setting free plan and deactivating repos for stripe customer" ,
67
- extra = dict (
68
- stripe_subscription_id = subscription .id ,
65
+ try :
66
+ log .info (
67
+ "Customer Subscription Deleted - Setting free plan and deactivating repos for stripe customer" ,
68
+ extra = dict (
69
+ stripe_subscription_id = subscription .id ,
70
+ stripe_customer_id = subscription .customer ,
71
+ ),
72
+ )
73
+ owner : Owner = Owner .objects .get (
69
74
stripe_customer_id = subscription .customer ,
70
- ),
71
- )
72
- owner : Owner = Owner .objects .get (
73
- stripe_customer_id = subscription .customer ,
74
- stripe_subscription_id = subscription .id ,
75
- )
76
- plan_service = PlanService (current_org = owner )
77
- plan_service .set_default_plan_data ()
78
- owner .repository_set .update (active = False , activated = False )
75
+ stripe_subscription_id = subscription .id ,
76
+ )
77
+ plan_service = PlanService (current_org = owner )
78
+ plan_service .set_default_plan_data ()
79
+ owner .repository_set .update (active = False , activated = False )
79
80
80
- self ._log_updated (1 )
81
+ self ._log_updated (1 )
82
+ except Owner .DoesNotExist :
83
+ log .info (
84
+ "Customer Subscription Deleted - Couldn't find owner, subscription likely already deleted" ,
85
+ extra = dict (
86
+ stripe_subscription_id = subscription .id ,
87
+ stripe_customer_id = subscription .customer ,
88
+ ),
89
+ )
81
90
82
91
def subscription_schedule_created (
83
92
self , schedule : stripe .SubscriptionSchedule
@@ -90,7 +99,7 @@ def subscription_schedule_created(
90
99
extra = dict (
91
100
stripe_customer_id = subscription .customer ,
92
101
stripe_subscription_id = subscription .id ,
93
- ownerid = subscription .metadata [ "obo_organization" ] ,
102
+ ownerid = subscription .metadata . get ( "obo_organization" ) ,
94
103
plan = plan_name ,
95
104
quantity = subscription .quantity ,
96
105
),
@@ -114,7 +123,7 @@ def subscription_schedule_updated(
114
123
extra = dict (
115
124
stripe_customer_id = subscription .customer ,
116
125
stripe_subscription_id = subscription .id ,
117
- ownerid = subscription .metadata [ "obo_organization" ] ,
126
+ ownerid = subscription .metadata . get ( "obo_organization" ) ,
118
127
plan = plan_name ,
119
128
quantity = quantity ,
120
129
),
0 commit comments