|
6 | 6 | class Subscription(Resource): |
7 | 7 | """ |
8 | 8 | https://dev.chartmogul.com/v1.0/reference#list-customer-subscriptions |
| 9 | + https://dev.chartmogul.com/v1.0/reference#list-a-customers-subscriptions |
9 | 10 | """ |
10 | 11 | _path = "/customers{/uuid}/subscriptions" |
11 | 12 | _root_key = 'entries' |
12 | 13 | _many = namedtuple('Subscriptions', [_root_key, "has_more", "per_page", "page"]) |
13 | 14 |
|
14 | 15 | class _Schema(Schema): |
15 | | - id = fields.Int() |
16 | | - plan = fields.String() |
17 | | - quantity = fields.Int() |
18 | | - mrr = fields.Number() |
19 | | - arr = fields.Number() |
20 | | - status = fields.String() |
21 | | - billing_cycle = fields.String(load_from='billing-cycle') |
22 | | - billing_cycle_count = fields.Number(load_from='billing-cycle-count') |
23 | | - start_date = fields.DateTime(load_from='start-date') |
24 | | - end_date = fields.DateTime(load_from='end-date') |
25 | | - currency = fields.String() |
26 | | - currency_sign = fields.String(load_from='currency-sign') |
| 16 | + id = fields.Int(allow_none=True) |
| 17 | + plan = fields.String(allow_none=True) |
| 18 | + quantity = fields.Int(allow_none=True) |
| 19 | + mrr = fields.Number(allow_none=True) |
| 20 | + arr = fields.Number(allow_none=True) |
| 21 | + status = fields.String(allow_none=True) |
| 22 | + billing_cycle = fields.String(load_from='billing-cycle', allow_none=True) |
| 23 | + billing_cycle_count = fields.Number(load_from='billing-cycle-count', allow_none=True) |
| 24 | + start_date = fields.DateTime(load_from='start-date', allow_none=True) |
| 25 | + end_date = fields.DateTime(load_from='end-date', allow_none=True) |
| 26 | + currency = fields.String(allow_none=True) |
| 27 | + currency_sign = fields.String(load_from='currency-sign', allow_none=True) |
| 28 | + |
| 29 | + # /import namespace |
| 30 | + uuid = fields.String(allow_none=True) |
| 31 | + external_id = fields.String(allow_none=True) |
| 32 | + plan_uuid = fields.String(allow_none=True) |
| 33 | + customer_uuid = fields.String(allow_none=True) |
| 34 | + data_source_uuid = fields.String(allow_none=True) |
| 35 | + cancellation_dates = fields.List(fields.DateTime(), allow_none=True) |
27 | 36 |
|
28 | 37 | @post_load |
29 | 38 | def make(self, data): |
30 | 39 | return Subscription(**data) |
31 | 40 |
|
32 | 41 | _schema = _Schema(strict=True) |
| 42 | + |
| 43 | + # /import has different paging |
| 44 | + @classmethod |
| 45 | + def _loadJSON(cls, jsonObj): |
| 46 | + if "subscriptions" in jsonObj: |
| 47 | + _many = namedtuple('Subscriptions', ["subscriptions", "current_page", "total_pages"]) |
| 48 | + return _many(cls._schema.load(jsonObj["subscriptions"], many=True).data, |
| 49 | + jsonObj["current_page"], |
| 50 | + jsonObj["total_pages"]) |
| 51 | + else: |
| 52 | + return super(Subscription, cls)._loadJSON(jsonObj) |
| 53 | + |
| 54 | +# /import namespace |
| 55 | +Subscription.list_imported = Subscription._method('list_imported', 'get', "/import/customers{/uuid}/subscriptions") |
| 56 | +Subscription.cancel = Subscription._method('cancel', 'patch', "/import/subscriptions{/uuid}") |
| 57 | +Subscription.modify = Subscription._method('modify', 'patch', "/import/subscriptions{/uuid}") |
0 commit comments