File tree 1 file changed +17
-3
lines changed
1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -128,14 +128,28 @@ def fetch_order(self, order_id):
128
128
def fetch_subscription (self , subscription_id ):
129
129
return self .fetch ('/subscriptions/{}' .format (subscription_id ))
130
130
131
+ def cancel_subscription (self , subscription_id , immediately = True ):
132
+ params = {}
133
+ if immediately :
134
+ params ['billingPeriod' ] = '0'
135
+ return self .request (
136
+ 'DELETE' ,
137
+ '/subscriptions/{}' .format (subscription_id ),
138
+ params = params )
139
+
131
140
def fetch (self , uri ):
132
- response = requests .get (
141
+ return self .request ('GET' , uri )
142
+
143
+ def request (self , method , uri , params = None ):
144
+ response = requests .request (
145
+ method ,
133
146
'https://api.fastspring.com' + uri ,
134
- auth = (self .username , self .password ))
147
+ auth = (self .username , self .password ),
148
+ params = params )
135
149
if response .status_code != 200 :
136
150
raise APIError (response )
137
151
data = response .json ()
138
- if data ['result' ] != 'success' :
152
+ if 'result' in data and data ['result' ] != 'success' :
139
153
raise APIError (response )
140
154
return data
141
155
You can’t perform that action at this time.
0 commit comments