-
Notifications
You must be signed in to change notification settings - Fork 4
/
subscriptions.clj
322 lines (280 loc) · 9.57 KB
/
subscriptions.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
(ns happygapi.reseller.subscriptions
"Enterprise Apps Reseller API: subscriptions.
Creates and manages your customers and their subscriptions.
See: https://developers.google.com/google-apps/reseller/api/reference/rest/v1/subscriptions"
(:require [cheshire.core :as json]
[clj-http.client :as http]
[happy.util :as util]))
(defn get$
"https://developers.google.com/google-apps/reseller/api/reference/rest/v1/subscriptions/get
Required parameters: customerId, subscriptionId
Optional parameters: none
Get a specific subscription."
{:scopes ["https://www.googleapis.com/auth/apps.order"
"https://www.googleapis.com/auth/apps.order.readonly"]}
[auth args]
{:pre [(util/has-keys? args #{:customerId :subscriptionId})]}
(util/get-response
(http/get
(util/get-url
"https://www.googleapis.com/apps/reseller/v1/"
"customers/{customerId}/subscriptions/{subscriptionId}"
#{:customerId :subscriptionId}
args)
(merge-with
merge
{:throw-exceptions false,
:query-params args,
:accept :json,
:as :json}
auth))))
(defn insert$
"https://developers.google.com/google-apps/reseller/api/reference/rest/v1/subscriptions/insert
Required parameters: customerId
Optional parameters: customerAuthToken
Body:
{:skuName string,
:creationTime string,
:purchaseOrderId string,
:billingMethod string,
:trialSettings {:isInTrial boolean, :trialEndTime string},
:suspensionReasons [string],
:resourceUiUrl string,
:customerId string,
:transferInfo {:minimumTransferableSeats integer,
:transferabilityExpirationTime string},
:customerDomain string,
:status string,
:kind string,
:skuId string,
:seats {:kind string,
:licensedNumberOfSeats integer,
:maximumNumberOfSeats integer,
:numberOfSeats integer},
:plan {:commitmentInterval {:endTime string, :startTime string},
:isCommitmentPlan boolean,
:planName string},
:renewalSettings {:kind string, :renewalType string},
:dealCode string,
:subscriptionId string}
Create or transfer a subscription."
{:scopes ["https://www.googleapis.com/auth/apps.order"]}
[auth args body]
{:pre [(util/has-keys? args #{:customerId})]}
(util/get-response
(http/post
(util/get-url
"https://www.googleapis.com/apps/reseller/v1/"
"customers/{customerId}/subscriptions"
#{:customerId}
args)
(merge-with
merge
{:content-type :json,
:body (json/generate-string body),
:throw-exceptions false,
:query-params args,
:accept :json,
:as :json}
auth))))
(defn changeRenewalSettings$
"https://developers.google.com/google-apps/reseller/api/reference/rest/v1/subscriptions/changeRenewalSettings
Required parameters: customerId, subscriptionId
Optional parameters: none
Body:
{:kind string, :renewalType string}
Update a user license's renewal settings. This is applicable for accounts with annual commitment plans only."
{:scopes ["https://www.googleapis.com/auth/apps.order"]}
[auth args body]
{:pre [(util/has-keys? args #{:customerId :subscriptionId})]}
(util/get-response
(http/post
(util/get-url
"https://www.googleapis.com/apps/reseller/v1/"
"customers/{customerId}/subscriptions/{subscriptionId}/changeRenewalSettings"
#{:customerId :subscriptionId}
args)
(merge-with
merge
{:content-type :json,
:body (json/generate-string body),
:throw-exceptions false,
:query-params args,
:accept :json,
:as :json}
auth))))
(defn delete$
"https://developers.google.com/google-apps/reseller/api/reference/rest/v1/subscriptions/delete
Required parameters: customerId, deletionType, subscriptionId
Optional parameters: none
Cancel, suspend, or transfer a subscription to direct."
{:scopes ["https://www.googleapis.com/auth/apps.order"]}
[auth args]
{:pre [(util/has-keys?
args
#{:customerId :deletionType :subscriptionId})]}
(util/get-response
(http/delete
(util/get-url
"https://www.googleapis.com/apps/reseller/v1/"
"customers/{customerId}/subscriptions/{subscriptionId}"
#{:customerId :deletionType :subscriptionId}
args)
(merge-with
merge
{:throw-exceptions false,
:query-params args,
:accept :json,
:as :json}
auth))))
(defn suspend$
"https://developers.google.com/google-apps/reseller/api/reference/rest/v1/subscriptions/suspend
Required parameters: customerId, subscriptionId
Optional parameters: none
Suspends an active subscription."
{:scopes ["https://www.googleapis.com/auth/apps.order"]}
[auth args]
{:pre [(util/has-keys? args #{:customerId :subscriptionId})]}
(util/get-response
(http/post
(util/get-url
"https://www.googleapis.com/apps/reseller/v1/"
"customers/{customerId}/subscriptions/{subscriptionId}/suspend"
#{:customerId :subscriptionId}
args)
(merge-with
merge
{:throw-exceptions false,
:query-params args,
:accept :json,
:as :json}
auth))))
(defn list$
"https://developers.google.com/google-apps/reseller/api/reference/rest/v1/subscriptions/list
Required parameters: none
Optional parameters: customerAuthToken, customerId, customerNamePrefix, maxResults, pageToken
List of subscriptions managed by the reseller. The list can be all subscriptions, all of a customer's subscriptions, or all of a customer's transferable subscriptions."
{:scopes ["https://www.googleapis.com/auth/apps.order"
"https://www.googleapis.com/auth/apps.order.readonly"]}
[auth args]
{:pre [(util/has-keys? args #{})]}
(util/get-response
(http/get
(util/get-url
"https://www.googleapis.com/apps/reseller/v1/"
"subscriptions"
#{}
args)
(merge-with
merge
{:throw-exceptions false,
:query-params args,
:accept :json,
:as :json}
auth))))
(defn changePlan$
"https://developers.google.com/google-apps/reseller/api/reference/rest/v1/subscriptions/changePlan
Required parameters: customerId, subscriptionId
Optional parameters: none
Body:
{:dealCode string,
:kind string,
:planName string,
:purchaseOrderId string,
:seats {:kind string,
:licensedNumberOfSeats integer,
:maximumNumberOfSeats integer,
:numberOfSeats integer}}
Update a subscription plan. Use this method to update a plan for a 30-day trial or a flexible plan subscription to an annual commitment plan with monthly or yearly payments."
{:scopes ["https://www.googleapis.com/auth/apps.order"]}
[auth args body]
{:pre [(util/has-keys? args #{:customerId :subscriptionId})]}
(util/get-response
(http/post
(util/get-url
"https://www.googleapis.com/apps/reseller/v1/"
"customers/{customerId}/subscriptions/{subscriptionId}/changePlan"
#{:customerId :subscriptionId}
args)
(merge-with
merge
{:content-type :json,
:body (json/generate-string body),
:throw-exceptions false,
:query-params args,
:accept :json,
:as :json}
auth))))
(defn changeSeats$
"https://developers.google.com/google-apps/reseller/api/reference/rest/v1/subscriptions/changeSeats
Required parameters: customerId, subscriptionId
Optional parameters: none
Body:
{:kind string,
:licensedNumberOfSeats integer,
:maximumNumberOfSeats integer,
:numberOfSeats integer}
Update a subscription's user license settings."
{:scopes ["https://www.googleapis.com/auth/apps.order"]}
[auth args body]
{:pre [(util/has-keys? args #{:customerId :subscriptionId})]}
(util/get-response
(http/post
(util/get-url
"https://www.googleapis.com/apps/reseller/v1/"
"customers/{customerId}/subscriptions/{subscriptionId}/changeSeats"
#{:customerId :subscriptionId}
args)
(merge-with
merge
{:content-type :json,
:body (json/generate-string body),
:throw-exceptions false,
:query-params args,
:accept :json,
:as :json}
auth))))
(defn activate$
"https://developers.google.com/google-apps/reseller/api/reference/rest/v1/subscriptions/activate
Required parameters: customerId, subscriptionId
Optional parameters: none
Activates a subscription previously suspended by the reseller"
{:scopes ["https://www.googleapis.com/auth/apps.order"]}
[auth args]
{:pre [(util/has-keys? args #{:customerId :subscriptionId})]}
(util/get-response
(http/post
(util/get-url
"https://www.googleapis.com/apps/reseller/v1/"
"customers/{customerId}/subscriptions/{subscriptionId}/activate"
#{:customerId :subscriptionId}
args)
(merge-with
merge
{:throw-exceptions false,
:query-params args,
:accept :json,
:as :json}
auth))))
(defn startPaidService$
"https://developers.google.com/google-apps/reseller/api/reference/rest/v1/subscriptions/startPaidService
Required parameters: customerId, subscriptionId
Optional parameters: none
Immediately move a 30-day free trial subscription to a paid service subscription."
{:scopes ["https://www.googleapis.com/auth/apps.order"]}
[auth args]
{:pre [(util/has-keys? args #{:customerId :subscriptionId})]}
(util/get-response
(http/post
(util/get-url
"https://www.googleapis.com/apps/reseller/v1/"
"customers/{customerId}/subscriptions/{subscriptionId}/startPaidService"
#{:customerId :subscriptionId}
args)
(merge-with
merge
{:throw-exceptions false,
:query-params args,
:accept :json,
:as :json}
auth))))