Debian Codegraph @

stripe/climate/_order.py

raw
1 # -*- coding: utf-8 -*-
2 # File generated from our OpenAPI spec
3 from stripe._createable_api_resource import CreateableAPIResource
4 from stripe._expandable_field import ExpandableField
5 from stripe._list_object import ListObject
6 from stripe._listable_api_resource import ListableAPIResource
7 from stripe._stripe_object import StripeObject
8 from stripe._updateable_api_resource import UpdateableAPIResource
9 from stripe._util import class_method_variant, sanitize_id
10 from typing import ClassVar, Dict, List, Optional, cast, overload
11 from typing_extensions import Literal, Unpack, TYPE_CHECKING
12
13 if TYPE_CHECKING:
14 from stripe.climate._product import Product
15 from stripe.climate._supplier import Supplier
16 from stripe.params.climate._order_cancel_params import OrderCancelParams
17 from stripe.params.climate._order_create_params import OrderCreateParams
18 from stripe.params.climate._order_list_params import OrderListParams
19 from stripe.params.climate._order_modify_params import OrderModifyParams
20 from stripe.params.climate._order_retrieve_params import (
21 OrderRetrieveParams,
22 )
23
24
25 class Order(
26 CreateableAPIResource["Order"],
27 ListableAPIResource["Order"],
28 UpdateableAPIResource["Order"],
29 ):
30 """
31 Orders represent your intent to purchase a particular Climate product. When you create an order, the
32 payment is deducted from your merchant balance.
33 """
34
35 OBJECT_NAME: ClassVar[Literal["climate.order"]] = "climate.order"
36
37 class Beneficiary(StripeObject):
38 public_name: str
39 """
40 Publicly displayable name for the end beneficiary of carbon removal.
41 """
42
43 class DeliveryDetail(StripeObject):
44 class Location(StripeObject):
45 city: Optional[str]
46 """
47 The city where the supplier is located.
48 """
49 country: str
50 """
51 Two-letter ISO code representing the country where the supplier is located.
52 """
53 latitude: Optional[float]
54 """
55 The geographic latitude where the supplier is located.
56 """
57 longitude: Optional[float]
58 """
59 The geographic longitude where the supplier is located.
60 """
61 region: Optional[str]
62 """
63 The state/county/province/region where the supplier is located.
64 """
65
66 delivered_at: int
67 """
68 Time at which the delivery occurred. Measured in seconds since the Unix epoch.
69 """
70 location: Optional[Location]
71 """
72 Specific location of this delivery.
73 """
74 metric_tons: str
75 """
76 Quantity of carbon removal supplied by this delivery.
77 """
78 registry_url: Optional[str]
79 """
80 Once retired, a URL to the registry entry for the tons from this delivery.
81 """
82 supplier: "Supplier"
83 """
84 A supplier of carbon removal.
85 """
86 _inner_class_types = {"location": Location}
87
88 amount_fees: int
89 """
90 Total amount of [Frontier](https://frontierclimate.com/)'s service fees in the currency's smallest unit.
91 """
92 amount_subtotal: int
93 """
94 Total amount of the carbon removal in the currency's smallest unit.
95 """
96 amount_total: int
97 """
98 Total amount of the order including fees in the currency's smallest unit.
99 """
100 beneficiary: Optional[Beneficiary]
101 canceled_at: Optional[int]
102 """
103 Time at which the order was canceled. Measured in seconds since the Unix epoch.
104 """
105 cancellation_reason: Optional[
106 Literal["expired", "product_unavailable", "requested"]
107 ]
108 """
109 Reason for the cancellation of this order.
110 """
111 certificate: Optional[str]
112 """
113 For delivered orders, a URL to a delivery certificate for the order.
114 """
115 confirmed_at: Optional[int]
116 """
117 Time at which the order was confirmed. Measured in seconds since the Unix epoch.
118 """
119 created: int
120 """
121 Time at which the object was created. Measured in seconds since the Unix epoch.
122 """
123 currency: str
124 """
125 Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase, representing the currency for this order.
126 """
127 delayed_at: Optional[int]
128 """
129 Time at which the order's expected_delivery_year was delayed. Measured in seconds since the Unix epoch.
130 """
131 delivered_at: Optional[int]
132 """
133 Time at which the order was delivered. Measured in seconds since the Unix epoch.
134 """
135 delivery_details: List[DeliveryDetail]
136 """
137 Details about the delivery of carbon removal for this order.
138 """
139 expected_delivery_year: int
140 """
141 The year this order is expected to be delivered.
142 """
143 id: str
144 """
145 Unique identifier for the object.
146 """
147 livemode: bool
148 """
149 Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
150 """
151 metadata: Dict[str, str]
152 """
153 Set of [key-value pairs](https://docs.stripe.com/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
154 """
155 metric_tons: str
156 """
157 Quantity of carbon removal that is included in this order.
158 """
159 object: Literal["climate.order"]
160 """
161 String representing the object's type. Objects of the same type share the same value.
162 """
163 product: ExpandableField["Product"]
164 """
165 Unique ID for the Climate `Product` this order is purchasing.
166 """
167 product_substituted_at: Optional[int]
168 """
169 Time at which the order's product was substituted for a different product. Measured in seconds since the Unix epoch.
170 """
171 status: Literal[
172 "awaiting_funds", "canceled", "confirmed", "delivered", "open"
173 ]
174 """
175 The current status of this order.
176 """
177
178 @classmethod
179 def _cls_cancel(
180 cls, order: str, **params: Unpack["OrderCancelParams"]
181 ) -> "Order":
182 """
183 Cancels a Climate order. You can cancel an order within 24 hours of creation. Stripe refunds the
184 reservation amount_subtotal, but not the amount_fees for user-triggered cancellations. Frontier
185 might cancel reservations if suppliers fail to deliver. If Frontier cancels the reservation, Stripe
186 provides 90 days advance notice and refunds the amount_total.
187 """
188 return cast(
189 "Order",
190 cls._static_request(
191 "post",
192 "/v1/climate/orders/{order}/cancel".format(
193 order=sanitize_id(order)
194 ),
195 params=params,
196 ),
197 )
198
199 @overload
200 @staticmethod
201 def cancel(order: str, **params: Unpack["OrderCancelParams"]) -> "Order":
202 """
203 Cancels a Climate order. You can cancel an order within 24 hours of creation. Stripe refunds the
204 reservation amount_subtotal, but not the amount_fees for user-triggered cancellations. Frontier
205 might cancel reservations if suppliers fail to deliver. If Frontier cancels the reservation, Stripe
206 provides 90 days advance notice and refunds the amount_total.
207 """
208 ...
209
210 @overload
211 def cancel(self, **params: Unpack["OrderCancelParams"]) -> "Order":
212 """
213 Cancels a Climate order. You can cancel an order within 24 hours of creation. Stripe refunds the
214 reservation amount_subtotal, but not the amount_fees for user-triggered cancellations. Frontier
215 might cancel reservations if suppliers fail to deliver. If Frontier cancels the reservation, Stripe
216 provides 90 days advance notice and refunds the amount_total.
217 """
218 ...
219
220 @class_method_variant("_cls_cancel")
221 def cancel( # pyright: ignore[reportGeneralTypeIssues]
222 self, **params: Unpack["OrderCancelParams"]
223 ) -> "Order":
224 """
225 Cancels a Climate order. You can cancel an order within 24 hours of creation. Stripe refunds the
226 reservation amount_subtotal, but not the amount_fees for user-triggered cancellations. Frontier
227 might cancel reservations if suppliers fail to deliver. If Frontier cancels the reservation, Stripe
228 provides 90 days advance notice and refunds the amount_total.
229 """
230 return cast(
231 "Order",
232 self._request(
233 "post",
234 "/v1/climate/orders/{order}/cancel".format(
235 order=sanitize_id(self.get("id"))
236 ),
237 params=params,
238 ),
239 )
240
241 @classmethod
242 async def _cls_cancel_async(
243 cls, order: str, **params: Unpack["OrderCancelParams"]
244 ) -> "Order":
245 """
246 Cancels a Climate order. You can cancel an order within 24 hours of creation. Stripe refunds the
247 reservation amount_subtotal, but not the amount_fees for user-triggered cancellations. Frontier
248 might cancel reservations if suppliers fail to deliver. If Frontier cancels the reservation, Stripe
249 provides 90 days advance notice and refunds the amount_total.
250 """
251 return cast(
252 "Order",
253 await cls._static_request_async(
254 "post",
255 "/v1/climate/orders/{order}/cancel".format(
256 order=sanitize_id(order)
257 ),
258 params=params,
259 ),
260 )
261
262 @overload
263 @staticmethod
264 async def cancel_async(
265 order: str, **params: Unpack["OrderCancelParams"]
266 ) -> "Order":
267 """
268 Cancels a Climate order. You can cancel an order within 24 hours of creation. Stripe refunds the
269 reservation amount_subtotal, but not the amount_fees for user-triggered cancellations. Frontier
270 might cancel reservations if suppliers fail to deliver. If Frontier cancels the reservation, Stripe
271 provides 90 days advance notice and refunds the amount_total.
272 """
273 ...
274
275 @overload
276 async def cancel_async(
277 self, **params: Unpack["OrderCancelParams"]
278 ) -> "Order":
279 """
280 Cancels a Climate order. You can cancel an order within 24 hours of creation. Stripe refunds the
281 reservation amount_subtotal, but not the amount_fees for user-triggered cancellations. Frontier
282 might cancel reservations if suppliers fail to deliver. If Frontier cancels the reservation, Stripe
283 provides 90 days advance notice and refunds the amount_total.
284 """
285 ...
286
287 @class_method_variant("_cls_cancel_async")
288 async def cancel_async( # pyright: ignore[reportGeneralTypeIssues]
289 self, **params: Unpack["OrderCancelParams"]
290 ) -> "Order":
291 """
292 Cancels a Climate order. You can cancel an order within 24 hours of creation. Stripe refunds the
293 reservation amount_subtotal, but not the amount_fees for user-triggered cancellations. Frontier
294 might cancel reservations if suppliers fail to deliver. If Frontier cancels the reservation, Stripe
295 provides 90 days advance notice and refunds the amount_total.
296 """
297 return cast(
298 "Order",
299 await self._request_async(
300 "post",
301 "/v1/climate/orders/{order}/cancel".format(
302 order=sanitize_id(self.get("id"))
303 ),
304 params=params,
305 ),
306 )
307
308 @classmethod
309 def create(cls, **params: Unpack["OrderCreateParams"]) -> "Order":
310 """
311 Creates a Climate order object for a given Climate product. The order will be processed immediately
312 after creation and payment will be deducted your Stripe balance.
313 """
314 return cast(
315 "Order",
316 cls._static_request(
317 "post",
318 cls.class_url(),
319 params=params,
320 ),
321 )
322
323 @classmethod
324 async def create_async(
325 cls, **params: Unpack["OrderCreateParams"]
326 ) -> "Order":
327 """
328 Creates a Climate order object for a given Climate product. The order will be processed immediately
329 after creation and payment will be deducted your Stripe balance.
330 """
331 return cast(
332 "Order",
333 await cls._static_request_async(
334 "post",
335 cls.class_url(),
336 params=params,
337 ),
338 )
339
340 @classmethod
341 def list(cls, **params: Unpack["OrderListParams"]) -> ListObject["Order"]:
342 """
343 Lists all Climate order objects. The orders are returned sorted by creation date, with the
344 most recently created orders appearing first.
345 """
346 result = cls._static_request(
347 "get",
348 cls.class_url(),
349 params=params,
350 )
351 if not isinstance(result, ListObject):
352 raise TypeError(
353 "Expected list object from API, got %s"
354 % (type(result).__name__)
355 )
356
357 return result
358
359 @classmethod
360 async def list_async(
361 cls, **params: Unpack["OrderListParams"]
362 ) -> ListObject["Order"]:
363 """
364 Lists all Climate order objects. The orders are returned sorted by creation date, with the
365 most recently created orders appearing first.
366 """
367 result = await cls._static_request_async(
368 "get",
369 cls.class_url(),
370 params=params,
371 )
372 if not isinstance(result, ListObject):
373 raise TypeError(
374 "Expected list object from API, got %s"
375 % (type(result).__name__)
376 )
377
378 return result
379
380 @classmethod
381 def modify(cls, id: str, **params: Unpack["OrderModifyParams"]) -> "Order":
382 """
383 Updates the specified order by setting the values of the parameters passed.
384 """
385 url = "%s/%s" % (cls.class_url(), sanitize_id(id))
386 return cast(
387 "Order",
388 cls._static_request(
389 "post",
390 url,
391 params=params,
392 ),
393 )
394
395 @classmethod
396 async def modify_async(
397 cls, id: str, **params: Unpack["OrderModifyParams"]
398 ) -> "Order":
399 """
400 Updates the specified order by setting the values of the parameters passed.
401 """
402 url = "%s/%s" % (cls.class_url(), sanitize_id(id))
403 return cast(
404 "Order",
405 await cls._static_request_async(
406 "post",
407 url,
408 params=params,
409 ),
410 )
411
412 @classmethod
413 def retrieve(
414 cls, id: str, **params: Unpack["OrderRetrieveParams"]
415 ) -> "Order":
416 """
417 Retrieves the details of a Climate order object with the given ID.
418 """
419 instance = cls(id, **params)
420 instance.refresh()
421 return instance
422
423 @classmethod
424 async def retrieve_async(
425 cls, id: str, **params: Unpack["OrderRetrieveParams"]
426 ) -> "Order":
427 """
428 Retrieves the details of a Climate order object with the given ID.
429 """
430 instance = cls(id, **params)
431 await instance.refresh_async()
432 return instance
433
434 _inner_class_types = {
435 "beneficiary": Beneficiary,
436 "delivery_details": DeliveryDetail,
437 }