| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# File generated from our OpenAPI spec |
| 3 |
from stripe._createable_api_resource import CreateableAPIResource |
| 4 |
from stripe._list_object import ListObject |
| 5 |
from stripe._listable_api_resource import ListableAPIResource |
| 6 |
from stripe._updateable_api_resource import UpdateableAPIResource |
| 7 |
from stripe._util import sanitize_id |
| 8 |
from typing import ClassVar, Dict, cast |
| 9 |
from typing_extensions import Literal, Unpack, TYPE_CHECKING |
| 10 |
|
| 11 |
if TYPE_CHECKING: |
| 12 |
from stripe.params.entitlements._feature_create_params import ( |
| 13 |
FeatureCreateParams, |
| 14 |
) |
| 15 |
from stripe.params.entitlements._feature_list_params import ( |
| 16 |
FeatureListParams, |
| 17 |
) |
| 18 |
from stripe.params.entitlements._feature_modify_params import ( |
| 19 |
FeatureModifyParams, |
| 20 |
) |
| 21 |
from stripe.params.entitlements._feature_retrieve_params import ( |
| 22 |
FeatureRetrieveParams, |
| 23 |
) |
| 24 |
|
| 25 |
|
| 26 |
class Feature( |
| 27 |
CreateableAPIResource["Feature"], |
| 28 |
ListableAPIResource["Feature"], |
| 29 |
UpdateableAPIResource["Feature"], |
| 30 |
): |
| 31 |
""" |
| 32 |
A feature represents a monetizable ability or functionality in your system. |
| 33 |
Features can be assigned to products, and when those products are purchased, Stripe will create an entitlement to the feature for the purchasing customer. |
| 34 |
""" |
| 35 |
|
| 36 |
OBJECT_NAME: ClassVar[Literal["entitlements.feature"]] = ( |
| 37 |
"entitlements.feature" |
| 38 |
) |
| 39 |
active: bool |
| 40 |
""" |
| 41 |
Inactive features cannot be attached to new products and will not be returned from the features list endpoint. |
| 42 |
""" |
| 43 |
id: str |
| 44 |
""" |
| 45 |
Unique identifier for the object. |
| 46 |
""" |
| 47 |
livemode: bool |
| 48 |
""" |
| 49 |
Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode. |
| 50 |
""" |
| 51 |
lookup_key: str |
| 52 |
""" |
| 53 |
A unique key you provide as your own system identifier. This may be up to 80 characters. |
| 54 |
""" |
| 55 |
metadata: Dict[str, str] |
| 56 |
""" |
| 57 |
Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format. |
| 58 |
""" |
| 59 |
name: str |
| 60 |
""" |
| 61 |
The feature's name, for your own purpose, not meant to be displayable to the customer. |
| 62 |
""" |
| 63 |
object: Literal["entitlements.feature"] |
| 64 |
""" |
| 65 |
String representing the object's type. Objects of the same type share the same value. |
| 66 |
""" |
| 67 |
|
| 68 |
@classmethod |
| 69 |
def create(cls, **params: Unpack["FeatureCreateParams"]) -> "Feature": |
| 70 |
""" |
| 71 |
Creates a feature |
| 72 |
""" |
| 73 |
return cast( |
| 74 |
"Feature", |
| 75 |
cls._static_request( |
| 76 |
"post", |
| 77 |
cls.class_url(), |
| 78 |
params=params, |
| 79 |
), |
| 80 |
) |
| 81 |
|
| 82 |
@classmethod |
| 83 |
async def create_async( |
| 84 |
cls, **params: Unpack["FeatureCreateParams"] |
| 85 |
) -> "Feature": |
| 86 |
""" |
| 87 |
Creates a feature |
| 88 |
""" |
| 89 |
return cast( |
| 90 |
"Feature", |
| 91 |
await cls._static_request_async( |
| 92 |
"post", |
| 93 |
cls.class_url(), |
| 94 |
params=params, |
| 95 |
), |
| 96 |
) |
| 97 |
|
| 98 |
@classmethod |
| 99 |
def list( |
| 100 |
cls, **params: Unpack["FeatureListParams"] |
| 101 |
) -> ListObject["Feature"]: |
| 102 |
""" |
| 103 |
Retrieve a list of features |
| 104 |
""" |
| 105 |
result = cls._static_request( |
| 106 |
"get", |
| 107 |
cls.class_url(), |
| 108 |
params=params, |
| 109 |
) |
| 110 |
if not isinstance(result, ListObject): |
| 111 |
raise TypeError( |
| 112 |
"Expected list object from API, got %s" |
| 113 |
% (type(result).__name__) |
| 114 |
) |
| 115 |
|
| 116 |
return result |
| 117 |
|
| 118 |
@classmethod |
| 119 |
async def list_async( |
| 120 |
cls, **params: Unpack["FeatureListParams"] |
| 121 |
) -> ListObject["Feature"]: |
| 122 |
""" |
| 123 |
Retrieve a list of features |
| 124 |
""" |
| 125 |
result = await cls._static_request_async( |
| 126 |
"get", |
| 127 |
cls.class_url(), |
| 128 |
params=params, |
| 129 |
) |
| 130 |
if not isinstance(result, ListObject): |
| 131 |
raise TypeError( |
| 132 |
"Expected list object from API, got %s" |
| 133 |
% (type(result).__name__) |
| 134 |
) |
| 135 |
|
| 136 |
return result |
| 137 |
|
| 138 |
@classmethod |
| 139 |
def modify( |
| 140 |
cls, id: str, **params: Unpack["FeatureModifyParams"] |
| 141 |
) -> "Feature": |
| 142 |
""" |
| 143 |
Update a feature's metadata or permanently deactivate it. |
| 144 |
""" |
| 145 |
url = "%s/%s" % (cls.class_url(), sanitize_id(id)) |
| 146 |
return cast( |
| 147 |
"Feature", |
| 148 |
cls._static_request( |
| 149 |
"post", |
| 150 |
url, |
| 151 |
params=params, |
| 152 |
), |
| 153 |
) |
| 154 |
|
| 155 |
@classmethod |
| 156 |
async def modify_async( |
| 157 |
cls, id: str, **params: Unpack["FeatureModifyParams"] |
| 158 |
) -> "Feature": |
| 159 |
""" |
| 160 |
Update a feature's metadata or permanently deactivate it. |
| 161 |
""" |
| 162 |
url = "%s/%s" % (cls.class_url(), sanitize_id(id)) |
| 163 |
return cast( |
| 164 |
"Feature", |
| 165 |
await cls._static_request_async( |
| 166 |
"post", |
| 167 |
url, |
| 168 |
params=params, |
| 169 |
), |
| 170 |
) |
| 171 |
|
| 172 |
@classmethod |
| 173 |
def retrieve( |
| 174 |
cls, id: str, **params: Unpack["FeatureRetrieveParams"] |
| 175 |
) -> "Feature": |
| 176 |
""" |
| 177 |
Retrieves a feature |
| 178 |
""" |
| 179 |
instance = cls(id, **params) |
| 180 |
instance.refresh() |
| 181 |
return instance |
| 182 |
|
| 183 |
@classmethod |
| 184 |
async def retrieve_async( |
| 185 |
cls, id: str, **params: Unpack["FeatureRetrieveParams"] |
| 186 |
) -> "Feature": |
| 187 |
""" |
| 188 |
Retrieves a feature |
| 189 |
""" |
| 190 |
instance = cls(id, **params) |
| 191 |
await instance.refresh_async() |
| 192 |
return instance |