Debian Codegraph @

stripe/issuing/_token.py

raw
1 # -*- coding: utf-8 -*-
2 # File generated from our OpenAPI spec
3 from stripe._expandable_field import ExpandableField
4 from stripe._list_object import ListObject
5 from stripe._listable_api_resource import ListableAPIResource
6 from stripe._stripe_object import StripeObject
7 from stripe._updateable_api_resource import UpdateableAPIResource
8 from stripe._util import sanitize_id
9 from typing import ClassVar, List, Optional, cast
10 from typing_extensions import Literal, Unpack, TYPE_CHECKING
11
12 if TYPE_CHECKING:
13 from stripe.issuing._card import Card
14 from stripe.params.issuing._token_list_params import TokenListParams
15 from stripe.params.issuing._token_modify_params import TokenModifyParams
16 from stripe.params.issuing._token_retrieve_params import (
17 TokenRetrieveParams,
18 )
19
20
21 class Token(ListableAPIResource["Token"], UpdateableAPIResource["Token"]):
22 """
23 An issuing token object is created when an issued card is added to a digital wallet. As a [card issuer](https://docs.stripe.com/issuing), you can [view and manage these tokens](https://docs.stripe.com/issuing/controls/token-management) through Stripe.
24 """
25
26 OBJECT_NAME: ClassVar[Literal["issuing.token"]] = "issuing.token"
27
28 class NetworkData(StripeObject):
29 class Device(StripeObject):
30 device_fingerprint: Optional[str]
31 """
32 An obfuscated ID derived from the device ID.
33 """
34 ip_address: Optional[str]
35 """
36 The IP address of the device at provisioning time.
37 """
38 location: Optional[str]
39 """
40 The geographic latitude/longitude coordinates of the device at provisioning time. The format is [+-]decimal/[+-]decimal.
41 """
42 name: Optional[str]
43 """
44 The name of the device used for tokenization.
45 """
46 phone_number: Optional[str]
47 """
48 The phone number of the device used for tokenization.
49 """
50 type: Optional[Literal["other", "phone", "watch"]]
51 """
52 The type of device used for tokenization.
53 """
54
55 class Mastercard(StripeObject):
56 card_reference_id: Optional[str]
57 """
58 A unique reference ID from MasterCard to represent the card account number.
59 """
60 token_reference_id: str
61 """
62 The network-unique identifier for the token.
63 """
64 token_requestor_id: str
65 """
66 The ID of the entity requesting tokenization, specific to MasterCard.
67 """
68 token_requestor_name: Optional[str]
69 """
70 The name of the entity requesting tokenization, if known. This is directly provided from MasterCard.
71 """
72
73 class Visa(StripeObject):
74 card_reference_id: str
75 """
76 A unique reference ID from Visa to represent the card account number.
77 """
78 token_reference_id: str
79 """
80 The network-unique identifier for the token.
81 """
82 token_requestor_id: str
83 """
84 The ID of the entity requesting tokenization, specific to Visa.
85 """
86 token_risk_score: Optional[str]
87 """
88 Degree of risk associated with the token between `01` and `99`, with higher number indicating higher risk. A `00` value indicates the token was not scored by Visa.
89 """
90
91 class WalletProvider(StripeObject):
92 class CardholderAddress(StripeObject):
93 line1: str
94 """
95 The street address of the cardholder tokenizing the card.
96 """
97 postal_code: str
98 """
99 The postal code of the cardholder tokenizing the card.
100 """
101
102 account_id: Optional[str]
103 """
104 The wallet provider-given account ID of the digital wallet the token belongs to.
105 """
106 account_trust_score: Optional[int]
107 """
108 An evaluation on the trustworthiness of the wallet account between 1 and 5. A higher score indicates more trustworthy.
109 """
110 card_number_source: Optional[
111 Literal["app", "manual", "on_file", "other"]
112 ]
113 """
114 The method used for tokenizing a card.
115 """
116 cardholder_address: Optional[CardholderAddress]
117 cardholder_name: Optional[str]
118 """
119 The name of the cardholder tokenizing the card.
120 """
121 device_trust_score: Optional[int]
122 """
123 An evaluation on the trustworthiness of the device. A higher score indicates more trustworthy.
124 """
125 hashed_account_email_address: Optional[str]
126 """
127 The hashed email address of the cardholder's account with the wallet provider.
128 """
129 reason_codes: Optional[
130 List[
131 Literal[
132 "account_card_too_new",
133 "account_recently_changed",
134 "account_too_new",
135 "account_too_new_since_launch",
136 "additional_device",
137 "data_expired",
138 "defer_id_v_decision",
139 "device_recently_lost",
140 "good_activity_history",
141 "has_suspended_tokens",
142 "high_risk",
143 "inactive_account",
144 "long_account_tenure",
145 "low_account_score",
146 "low_device_score",
147 "low_phone_number_score",
148 "network_service_error",
149 "outside_home_territory",
150 "provisioning_cardholder_mismatch",
151 "provisioning_device_and_cardholder_mismatch",
152 "provisioning_device_mismatch",
153 "same_device_no_prior_authentication",
154 "same_device_successful_prior_authentication",
155 "software_update",
156 "suspicious_activity",
157 "too_many_different_cardholders",
158 "too_many_recent_attempts",
159 "too_many_recent_tokens",
160 ]
161 ]
162 ]
163 """
164 The reasons for suggested tokenization given by the card network.
165 """
166 suggested_decision: Optional[
167 Literal["approve", "decline", "require_auth"]
168 ]
169 """
170 The recommendation on responding to the tokenization request.
171 """
172 suggested_decision_version: Optional[str]
173 """
174 The version of the standard for mapping reason codes followed by the wallet provider.
175 """
176 _inner_class_types = {"cardholder_address": CardholderAddress}
177
178 device: Optional[Device]
179 mastercard: Optional[Mastercard]
180 type: Literal["mastercard", "visa"]
181 """
182 The network that the token is associated with. An additional hash is included with a name matching this value, containing tokenization data specific to the card network.
183 """
184 visa: Optional[Visa]
185 wallet_provider: Optional[WalletProvider]
186 _inner_class_types = {
187 "device": Device,
188 "mastercard": Mastercard,
189 "visa": Visa,
190 "wallet_provider": WalletProvider,
191 }
192
193 card: ExpandableField["Card"]
194 """
195 Card associated with this token.
196 """
197 created: int
198 """
199 Time at which the object was created. Measured in seconds since the Unix epoch.
200 """
201 device_fingerprint: Optional[str]
202 """
203 The hashed ID derived from the device ID from the card network associated with the token.
204 """
205 id: str
206 """
207 Unique identifier for the object.
208 """
209 last4: Optional[str]
210 """
211 The last four digits of the token.
212 """
213 livemode: bool
214 """
215 Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
216 """
217 network: Literal["mastercard", "visa"]
218 """
219 The token service provider / card network associated with the token.
220 """
221 network_data: Optional[NetworkData]
222 network_updated_at: int
223 """
224 Time at which the token was last updated by the card network. Measured in seconds since the Unix epoch.
225 """
226 object: Literal["issuing.token"]
227 """
228 String representing the object's type. Objects of the same type share the same value.
229 """
230 status: Literal["active", "deleted", "requested", "suspended"]
231 """
232 The usage state of the token.
233 """
234 wallet_provider: Optional[
235 Literal["apple_pay", "google_pay", "samsung_pay"]
236 ]
237 """
238 The digital wallet for this token, if one was used.
239 """
240
241 @classmethod
242 def list(cls, **params: Unpack["TokenListParams"]) -> ListObject["Token"]:
243 """
244 Lists all Issuing Token objects for a given card.
245 """
246 result = cls._static_request(
247 "get",
248 cls.class_url(),
249 params=params,
250 )
251 if not isinstance(result, ListObject):
252 raise TypeError(
253 "Expected list object from API, got %s"
254 % (type(result).__name__)
255 )
256
257 return result
258
259 @classmethod
260 async def list_async(
261 cls, **params: Unpack["TokenListParams"]
262 ) -> ListObject["Token"]:
263 """
264 Lists all Issuing Token objects for a given card.
265 """
266 result = await cls._static_request_async(
267 "get",
268 cls.class_url(),
269 params=params,
270 )
271 if not isinstance(result, ListObject):
272 raise TypeError(
273 "Expected list object from API, got %s"
274 % (type(result).__name__)
275 )
276
277 return result
278
279 @classmethod
280 def modify(cls, id: str, **params: Unpack["TokenModifyParams"]) -> "Token":
281 """
282 Attempts to update the specified Issuing Token object to the status specified.
283 """
284 url = "%s/%s" % (cls.class_url(), sanitize_id(id))
285 return cast(
286 "Token",
287 cls._static_request(
288 "post",
289 url,
290 params=params,
291 ),
292 )
293
294 @classmethod
295 async def modify_async(
296 cls, id: str, **params: Unpack["TokenModifyParams"]
297 ) -> "Token":
298 """
299 Attempts to update the specified Issuing Token object to the status specified.
300 """
301 url = "%s/%s" % (cls.class_url(), sanitize_id(id))
302 return cast(
303 "Token",
304 await cls._static_request_async(
305 "post",
306 url,
307 params=params,
308 ),
309 )
310
311 @classmethod
312 def retrieve(
313 cls, id: str, **params: Unpack["TokenRetrieveParams"]
314 ) -> "Token":
315 """
316 Retrieves an Issuing Token object.
317 """
318 instance = cls(id, **params)
319 instance.refresh()
320 return instance
321
322 @classmethod
323 async def retrieve_async(
324 cls, id: str, **params: Unpack["TokenRetrieveParams"]
325 ) -> "Token":
326 """
327 Retrieves an Issuing Token object.
328 """
329 instance = cls(id, **params)
330 await instance.refresh_async()
331 return instance
332
333 _inner_class_types = {"network_data": NetworkData}