Repository navigation
Expand file tree
/
Copy pathsubscriptions.py
More file actions
761 lines (712 loc) · 31.4 KB
/
Copy pathsubscriptions.py
File metadata and controls
761 lines (712 loc) · 31.4 KB
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
# this file is @generated
"""Subscriptions API."""
from __future__ import annotations
import builtins
import typing as t
from datetime import date
from .. import models as _models
from ..models import (
CancelSubscriptionRequest,
CancelSubscriptionResponse,
CreateSubscriptionAddOn,
CreateSubscriptionComponents,
EffectiveEntitlementListResponse,
PaymentMethodsConfig,
PlanId,
Subscription,
SubscriptionActivationConditionEnum,
SubscriptionActivationConditionEnumLiteral,
SubscriptionCreateRequest,
SubscriptionDetails,
SubscriptionListResponse,
SubscriptionStatusEnum,
SubscriptionUpdateRequest,
SubscriptionUpdateResponse,
)
from ..serialization import UNSET, Unset, to_json_value
from ._pages import (
AsyncSubscriptionsListPage,
SubscriptionsListPage,
)
from ._pagination import (
AsyncPaginator,
PagePaging,
step,
)
from ._response import async_to_raw_response_wrapper, to_raw_response_wrapper
from .common import (
ApiBaseAsync,
ApiBaseSync,
ApiRequest,
Timeout,
decode_response,
serialize_query_params,
)
class AsyncSubscriptions(ApiBaseAsync):
"""Subscriptions API, for asyncio."""
@property
def with_raw_response(self) -> AsyncSubscriptionsWithRawResponse:
"""These methods, returning an :class:`APIResponse` with the status and headers."""
return AsyncSubscriptionsWithRawResponse(self)
def list(
self,
*,
customer_id: str | None = None,
plan_id: PlanId | None = None,
statuses: builtins.list[SubscriptionStatusEnum] | None = None,
order_by: str | None = None,
page: int | None = None,
per_page: int | None = None,
extra_headers: t.Mapping[str, str] | None = None,
extra_query: t.Mapping[str, object] | None = None,
extra_body: t.Mapping[str, object] | None = None,
timeout: Timeout | Unset = UNSET,
max_retries: int | None = None,
) -> AsyncPaginator[Subscription, AsyncSubscriptionsListPage]:
"""List subscriptions with optional filtering by customer or plan.
:param customer_id: Filter by customer ID or alias
:param order_by: Sort order. Format: `column.direction`. Allowed columns: `customer_name`, `plan_name`, `mrr_cents`, `billing_start_date`, `end_date`, `status`, `created_at`. Direction: `asc` or `desc`. Default: `created_at.desc`.
:param page: Page number (0-indexed)
:param per_page: Number of items per page"""
async def fetch(page_param: int | None) -> SubscriptionListResponse:
response = await self._request(
ApiRequest(
method="get",
path="/api/v1/subscriptions",
query_params=serialize_query_params(
{
"customer_id": customer_id,
"plan_id": plan_id,
"statuses": statuses,
"order_by": order_by,
"page": page_param,
"per_page": per_page,
},
),
error_types={
"default": _models.RestErrorResponse,
},
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
max_retries=max_retries,
)
)
return decode_response(response, SubscriptionListResponse)
paging = PagePaging[SubscriptionListResponse, Subscription](
items=lambda body: body.data,
total_pages=lambda body: step(
body.pagination_meta, lambda v: v.total_pages
),
first_page=0,
)
return AsyncPaginator(
lambda: AsyncSubscriptionsListPage._first(fetch, page, paging)
)
async def create(
self,
*,
activation_condition: SubscriptionActivationConditionEnum
| SubscriptionActivationConditionEnumLiteral,
customer_id_or_alias: str,
plan_id: PlanId,
start_date: date,
add_ons: builtins.list[CreateSubscriptionAddOn] | None = None,
auto_advance_invoices: bool | None = None,
backdate_invoices: bool | None = None,
billing_day_anchor: int | None | Unset = UNSET,
charge_automatically: bool | None = None,
coupon_codes: builtins.list[str] | None = None,
custom_properties: t.Any = None,
end_date: date | None = None,
invoice_memo: str | None = None,
net_terms: int | None = None,
payment_methods_config: PaymentMethodsConfig | None = None,
price_components: CreateSubscriptionComponents | None = None,
purchase_order: str | None | Unset = UNSET,
skip_past_invoices: bool | None = None,
trial_days: int | None = None,
version: int | None = None,
extra_headers: t.Mapping[str, str] | None = None,
extra_query: t.Mapping[str, object] | None = None,
extra_body: t.Mapping[str, object] | None = None,
timeout: Timeout | Unset = UNSET,
max_retries: int | None = None,
) -> SubscriptionDetails:
"""Create subscription
Create a new subscription for a customer with a specific plan.
:param backdate_invoices: Historical import mode: when true, invoices finalized for this subscription keep their billing-period date as the invoice date instead of being stamped with the emission date.
:param custom_properties: User-defined custom property values, keyed by definition `key`. Validated against the tenant's subscription definitions.
:param payment_methods_config: Payment methods configuration. If not specified, inherits from the invoicing entity.
:param skip_past_invoices: Migration mode: when true with a past start_date, skip creating invoices for past cycles. The subscription will be set to the current billing period with correct cycle_index."""
response = await self._request(
ApiRequest(
method="post",
path="/api/v1/subscriptions",
json_body=to_json_value(
SubscriptionCreateRequest(
activation_condition=t.cast(
"SubscriptionActivationConditionEnum", activation_condition
),
add_ons=add_ons,
auto_advance_invoices=auto_advance_invoices,
backdate_invoices=backdate_invoices,
billing_day_anchor=billing_day_anchor,
charge_automatically=charge_automatically,
coupon_codes=coupon_codes,
custom_properties=custom_properties,
customer_id_or_alias=customer_id_or_alias,
end_date=end_date,
invoice_memo=invoice_memo,
net_terms=net_terms,
payment_methods_config=payment_methods_config,
plan_id=plan_id,
price_components=price_components,
purchase_order=purchase_order,
skip_past_invoices=skip_past_invoices,
start_date=start_date,
trial_days=trial_days,
version=version,
),
SubscriptionCreateRequest,
),
error_types={
"default": _models.RestErrorResponse,
},
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
max_retries=max_retries,
)
)
return decode_response(response, SubscriptionDetails)
async def retrieve(
self,
subscription_id: str,
*,
extra_headers: t.Mapping[str, str] | None = None,
extra_query: t.Mapping[str, object] | None = None,
extra_body: t.Mapping[str, object] | None = None,
timeout: Timeout | Unset = UNSET,
max_retries: int | None = None,
) -> SubscriptionDetails:
"""Get subscription details
Retrieve detailed information about a subscription including price components and schedules."""
response = await self._request(
ApiRequest(
method="get",
path="/api/v1/subscriptions/{subscription_id}",
path_params={
"subscription_id": subscription_id,
},
error_types={
"default": _models.RestErrorResponse,
},
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
max_retries=max_retries,
)
)
return decode_response(response, SubscriptionDetails)
async def update(
self,
subscription_id: str,
*,
auto_advance_invoices: bool | None | Unset = UNSET,
charge_automatically: bool | None | Unset = UNSET,
custom_properties: t.Any = None,
invoice_memo: str | None | Unset = UNSET,
net_terms: int | None | Unset = UNSET,
payment_methods_config: PaymentMethodsConfig | None | Unset = UNSET,
purchase_order: str | None | Unset = UNSET,
extra_headers: t.Mapping[str, str] | None = None,
extra_query: t.Mapping[str, object] | None = None,
extra_body: t.Mapping[str, object] | None = None,
timeout: Timeout | Unset = UNSET,
max_retries: int | None = None,
) -> SubscriptionUpdateResponse:
"""Update subscription settings like payment configuration, billing options, etc.
:param auto_advance_invoices: If false, invoices will stay in Draft until manually reviewed and finalized.
:param charge_automatically: Automatically try to charge the customer's configured payment method on finalize.
:param custom_properties: Partial update of custom property values (merge; send a key with `null` to remove it). Validated against the tenant's `SUBSCRIPTION` property definitions. Omit to leave unchanged.
:param invoice_memo: Default memo for invoices
:param net_terms: Payment terms in days (0 = due on issue)
:param purchase_order: Purchase order number"""
response = await self._request(
ApiRequest(
method="patch",
path="/api/v1/subscriptions/{subscription_id}",
path_params={
"subscription_id": subscription_id,
},
json_body=to_json_value(
SubscriptionUpdateRequest(
auto_advance_invoices=auto_advance_invoices,
charge_automatically=charge_automatically,
custom_properties=custom_properties,
invoice_memo=invoice_memo,
net_terms=net_terms,
payment_methods_config=payment_methods_config,
purchase_order=purchase_order,
),
SubscriptionUpdateRequest,
),
error_types={
"default": _models.RestErrorResponse,
},
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
max_retries=max_retries,
)
)
return decode_response(response, SubscriptionUpdateResponse)
async def cancel(
self,
subscription_id: str,
*,
effective_date: date | None | Unset = UNSET,
reason: str | None | Unset = UNSET,
extra_headers: t.Mapping[str, str] | None = None,
extra_query: t.Mapping[str, object] | None = None,
extra_body: t.Mapping[str, object] | None = None,
timeout: Timeout | Unset = UNSET,
max_retries: int | None = None,
) -> CancelSubscriptionResponse:
"""Cancel subscription
Cancel a subscription either immediately or at the end of the billing period.
:param effective_date: If not provided, the cancellation will be effective at the end of the current billing or committed period."""
response = await self._request(
ApiRequest(
method="post",
path="/api/v1/subscriptions/{subscription_id}/cancel",
path_params={
"subscription_id": subscription_id,
},
json_body=to_json_value(
CancelSubscriptionRequest(
effective_date=effective_date,
reason=reason,
),
CancelSubscriptionRequest,
),
error_types={
"default": _models.RestErrorResponse,
},
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
max_retries=max_retries,
)
)
return decode_response(response, CancelSubscriptionResponse)
async def list_entitlements(
self,
subscription_id: str,
*,
extra_headers: t.Mapping[str, str] | None = None,
extra_query: t.Mapping[str, object] | None = None,
extra_body: t.Mapping[str, object] | None = None,
timeout: Timeout | Unset = UNSET,
max_retries: int | None = None,
) -> EffectiveEntitlementListResponse:
"""List subscription entitlements"""
response = await self._request(
ApiRequest(
method="get",
path="/api/v1/subscriptions/{subscription_id}/entitlements",
path_params={
"subscription_id": subscription_id,
},
error_types={
"default": _models.RestErrorResponse,
},
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
max_retries=max_retries,
)
)
return decode_response(response, EffectiveEntitlementListResponse)
async def retrieve_summary(
self,
subscription_id: str,
*,
extra_headers: t.Mapping[str, str] | None = None,
extra_query: t.Mapping[str, object] | None = None,
extra_body: t.Mapping[str, object] | None = None,
timeout: Timeout | Unset = UNSET,
max_retries: int | None = None,
) -> Subscription:
"""Get subscription summary
Retrieve a subscription without its components, add-ons, coupons and entitlements: the same
shape as list items, for callers that only need status and billing dates."""
response = await self._request(
ApiRequest(
method="get",
path="/api/v1/subscriptions/{subscription_id}/summary",
path_params={
"subscription_id": subscription_id,
},
error_types={
"default": _models.RestErrorResponse,
},
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
max_retries=max_retries,
)
)
return decode_response(response, Subscription)
class AsyncSubscriptionsWithRawResponse:
"""The methods of :class:`AsyncSubscriptions`, returning an :class:`APIResponse`."""
def __init__(self, resource: AsyncSubscriptions) -> None:
self.list = async_to_raw_response_wrapper(resource.list)
self.create = async_to_raw_response_wrapper(resource.create)
self.retrieve = async_to_raw_response_wrapper(resource.retrieve)
self.update = async_to_raw_response_wrapper(resource.update)
self.cancel = async_to_raw_response_wrapper(resource.cancel)
self.list_entitlements = async_to_raw_response_wrapper(
resource.list_entitlements
)
self.retrieve_summary = async_to_raw_response_wrapper(resource.retrieve_summary)
class Subscriptions(ApiBaseSync):
"""Subscriptions API."""
@property
def with_raw_response(self) -> SubscriptionsWithRawResponse:
"""These methods, returning an :class:`APIResponse` with the status and headers."""
return SubscriptionsWithRawResponse(self)
def list(
self,
*,
customer_id: str | None = None,
plan_id: PlanId | None = None,
statuses: builtins.list[SubscriptionStatusEnum] | None = None,
order_by: str | None = None,
page: int | None = None,
per_page: int | None = None,
extra_headers: t.Mapping[str, str] | None = None,
extra_query: t.Mapping[str, object] | None = None,
extra_body: t.Mapping[str, object] | None = None,
timeout: Timeout | Unset = UNSET,
max_retries: int | None = None,
) -> SubscriptionsListPage:
"""List subscriptions with optional filtering by customer or plan.
:param customer_id: Filter by customer ID or alias
:param order_by: Sort order. Format: `column.direction`. Allowed columns: `customer_name`, `plan_name`, `mrr_cents`, `billing_start_date`, `end_date`, `status`, `created_at`. Direction: `asc` or `desc`. Default: `created_at.desc`.
:param page: Page number (0-indexed)
:param per_page: Number of items per page"""
def fetch(page_param: int | None) -> SubscriptionListResponse:
response = self._request(
ApiRequest(
method="get",
path="/api/v1/subscriptions",
query_params=serialize_query_params(
{
"customer_id": customer_id,
"plan_id": plan_id,
"statuses": statuses,
"order_by": order_by,
"page": page_param,
"per_page": per_page,
},
),
error_types={
"default": _models.RestErrorResponse,
},
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
max_retries=max_retries,
)
)
return decode_response(response, SubscriptionListResponse)
paging = PagePaging[SubscriptionListResponse, Subscription](
items=lambda body: body.data,
total_pages=lambda body: step(
body.pagination_meta, lambda v: v.total_pages
),
first_page=0,
)
return SubscriptionsListPage._first(fetch, page, paging)
def create(
self,
*,
activation_condition: SubscriptionActivationConditionEnum
| SubscriptionActivationConditionEnumLiteral,
customer_id_or_alias: str,
plan_id: PlanId,
start_date: date,
add_ons: builtins.list[CreateSubscriptionAddOn] | None = None,
auto_advance_invoices: bool | None = None,
backdate_invoices: bool | None = None,
billing_day_anchor: int | None | Unset = UNSET,
charge_automatically: bool | None = None,
coupon_codes: builtins.list[str] | None = None,
custom_properties: t.Any = None,
end_date: date | None = None,
invoice_memo: str | None = None,
net_terms: int | None = None,
payment_methods_config: PaymentMethodsConfig | None = None,
price_components: CreateSubscriptionComponents | None = None,
purchase_order: str | None | Unset = UNSET,
skip_past_invoices: bool | None = None,
trial_days: int | None = None,
version: int | None = None,
extra_headers: t.Mapping[str, str] | None = None,
extra_query: t.Mapping[str, object] | None = None,
extra_body: t.Mapping[str, object] | None = None,
timeout: Timeout | Unset = UNSET,
max_retries: int | None = None,
) -> SubscriptionDetails:
"""Create subscription
Create a new subscription for a customer with a specific plan.
:param backdate_invoices: Historical import mode: when true, invoices finalized for this subscription keep their billing-period date as the invoice date instead of being stamped with the emission date.
:param custom_properties: User-defined custom property values, keyed by definition `key`. Validated against the tenant's subscription definitions.
:param payment_methods_config: Payment methods configuration. If not specified, inherits from the invoicing entity.
:param skip_past_invoices: Migration mode: when true with a past start_date, skip creating invoices for past cycles. The subscription will be set to the current billing period with correct cycle_index."""
response = self._request(
ApiRequest(
method="post",
path="/api/v1/subscriptions",
json_body=to_json_value(
SubscriptionCreateRequest(
activation_condition=t.cast(
"SubscriptionActivationConditionEnum", activation_condition
),
add_ons=add_ons,
auto_advance_invoices=auto_advance_invoices,
backdate_invoices=backdate_invoices,
billing_day_anchor=billing_day_anchor,
charge_automatically=charge_automatically,
coupon_codes=coupon_codes,
custom_properties=custom_properties,
customer_id_or_alias=customer_id_or_alias,
end_date=end_date,
invoice_memo=invoice_memo,
net_terms=net_terms,
payment_methods_config=payment_methods_config,
plan_id=plan_id,
price_components=price_components,
purchase_order=purchase_order,
skip_past_invoices=skip_past_invoices,
start_date=start_date,
trial_days=trial_days,
version=version,
),
SubscriptionCreateRequest,
),
error_types={
"default": _models.RestErrorResponse,
},
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
max_retries=max_retries,
)
)
return decode_response(response, SubscriptionDetails)
def retrieve(
self,
subscription_id: str,
*,
extra_headers: t.Mapping[str, str] | None = None,
extra_query: t.Mapping[str, object] | None = None,
extra_body: t.Mapping[str, object] | None = None,
timeout: Timeout | Unset = UNSET,
max_retries: int | None = None,
) -> SubscriptionDetails:
"""Get subscription details
Retrieve detailed information about a subscription including price components and schedules."""
response = self._request(
ApiRequest(
method="get",
path="/api/v1/subscriptions/{subscription_id}",
path_params={
"subscription_id": subscription_id,
},
error_types={
"default": _models.RestErrorResponse,
},
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
max_retries=max_retries,
)
)
return decode_response(response, SubscriptionDetails)
def update(
self,
subscription_id: str,
*,
auto_advance_invoices: bool | None | Unset = UNSET,
charge_automatically: bool | None | Unset = UNSET,
custom_properties: t.Any = None,
invoice_memo: str | None | Unset = UNSET,
net_terms: int | None | Unset = UNSET,
payment_methods_config: PaymentMethodsConfig | None | Unset = UNSET,
purchase_order: str | None | Unset = UNSET,
extra_headers: t.Mapping[str, str] | None = None,
extra_query: t.Mapping[str, object] | None = None,
extra_body: t.Mapping[str, object] | None = None,
timeout: Timeout | Unset = UNSET,
max_retries: int | None = None,
) -> SubscriptionUpdateResponse:
"""Update subscription settings like payment configuration, billing options, etc.
:param auto_advance_invoices: If false, invoices will stay in Draft until manually reviewed and finalized.
:param charge_automatically: Automatically try to charge the customer's configured payment method on finalize.
:param custom_properties: Partial update of custom property values (merge; send a key with `null` to remove it). Validated against the tenant's `SUBSCRIPTION` property definitions. Omit to leave unchanged.
:param invoice_memo: Default memo for invoices
:param net_terms: Payment terms in days (0 = due on issue)
:param purchase_order: Purchase order number"""
response = self._request(
ApiRequest(
method="patch",
path="/api/v1/subscriptions/{subscription_id}",
path_params={
"subscription_id": subscription_id,
},
json_body=to_json_value(
SubscriptionUpdateRequest(
auto_advance_invoices=auto_advance_invoices,
charge_automatically=charge_automatically,
custom_properties=custom_properties,
invoice_memo=invoice_memo,
net_terms=net_terms,
payment_methods_config=payment_methods_config,
purchase_order=purchase_order,
),
SubscriptionUpdateRequest,
),
error_types={
"default": _models.RestErrorResponse,
},
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
max_retries=max_retries,
)
)
return decode_response(response, SubscriptionUpdateResponse)
def cancel(
self,
subscription_id: str,
*,
effective_date: date | None | Unset = UNSET,
reason: str | None | Unset = UNSET,
extra_headers: t.Mapping[str, str] | None = None,
extra_query: t.Mapping[str, object] | None = None,
extra_body: t.Mapping[str, object] | None = None,
timeout: Timeout | Unset = UNSET,
max_retries: int | None = None,
) -> CancelSubscriptionResponse:
"""Cancel subscription
Cancel a subscription either immediately or at the end of the billing period.
:param effective_date: If not provided, the cancellation will be effective at the end of the current billing or committed period."""
response = self._request(
ApiRequest(
method="post",
path="/api/v1/subscriptions/{subscription_id}/cancel",
path_params={
"subscription_id": subscription_id,
},
json_body=to_json_value(
CancelSubscriptionRequest(
effective_date=effective_date,
reason=reason,
),
CancelSubscriptionRequest,
),
error_types={
"default": _models.RestErrorResponse,
},
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
max_retries=max_retries,
)
)
return decode_response(response, CancelSubscriptionResponse)
def list_entitlements(
self,
subscription_id: str,
*,
extra_headers: t.Mapping[str, str] | None = None,
extra_query: t.Mapping[str, object] | None = None,
extra_body: t.Mapping[str, object] | None = None,
timeout: Timeout | Unset = UNSET,
max_retries: int | None = None,
) -> EffectiveEntitlementListResponse:
"""List subscription entitlements"""
response = self._request(
ApiRequest(
method="get",
path="/api/v1/subscriptions/{subscription_id}/entitlements",
path_params={
"subscription_id": subscription_id,
},
error_types={
"default": _models.RestErrorResponse,
},
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
max_retries=max_retries,
)
)
return decode_response(response, EffectiveEntitlementListResponse)
def retrieve_summary(
self,
subscription_id: str,
*,
extra_headers: t.Mapping[str, str] | None = None,
extra_query: t.Mapping[str, object] | None = None,
extra_body: t.Mapping[str, object] | None = None,
timeout: Timeout | Unset = UNSET,
max_retries: int | None = None,
) -> Subscription:
"""Get subscription summary
Retrieve a subscription without its components, add-ons, coupons and entitlements: the same
shape as list items, for callers that only need status and billing dates."""
response = self._request(
ApiRequest(
method="get",
path="/api/v1/subscriptions/{subscription_id}/summary",
path_params={
"subscription_id": subscription_id,
},
error_types={
"default": _models.RestErrorResponse,
},
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
max_retries=max_retries,
)
)
return decode_response(response, Subscription)
class SubscriptionsWithRawResponse:
"""The methods of :class:`Subscriptions`, returning an :class:`APIResponse`."""
def __init__(self, resource: Subscriptions) -> None:
self.list = to_raw_response_wrapper(resource.list)
self.create = to_raw_response_wrapper(resource.create)
self.retrieve = to_raw_response_wrapper(resource.retrieve)
self.update = to_raw_response_wrapper(resource.update)
self.cancel = to_raw_response_wrapper(resource.cancel)
self.list_entitlements = to_raw_response_wrapper(resource.list_entitlements)
self.retrieve_summary = to_raw_response_wrapper(resource.retrieve_summary)