Debian Codegraph @

stripe/forwarding/_request.py

raw
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._stripe_object import StripeObject
7 from typing import ClassVar, Dict, List, Optional, cast
8 from typing_extensions import Literal, Unpack, TYPE_CHECKING
9
10 if TYPE_CHECKING:
11 from stripe.params.forwarding._request_create_params import (
12 RequestCreateParams,
13 )
14 from stripe.params.forwarding._request_list_params import RequestListParams
15 from stripe.params.forwarding._request_retrieve_params import (
16 RequestRetrieveParams,
17 )
18
19
20 class Request(
21 CreateableAPIResource["Request"], ListableAPIResource["Request"]
22 ):
23 """
24 Instructs Stripe to make a request on your behalf using the destination URL. The destination URL
25 is activated by Stripe at the time of onboarding. Stripe verifies requests with your credentials
26 provided during onboarding, and injects card details from the payment_method into the request.
27
28 Stripe redacts all sensitive fields and headers, including authentication credentials and card numbers,
29 before storing the request and response data in the forwarding Request object, which are subject to a
30 30-day retention period.
31
32 You can provide a Stripe idempotency key to make sure that requests with the same key result in only one
33 outbound request. The Stripe idempotency key provided should be unique and different from any idempotency
34 keys provided on the underlying third-party request.
35
36 Forwarding Requests are synchronous requests that return a response or time out according to
37 Stripe's limits.
38
39 Related guide: [Forward card details to third-party API endpoints](https://docs.stripe.com/payments/forwarding).
40 """
41
42 OBJECT_NAME: ClassVar[Literal["forwarding.request"]] = "forwarding.request"
43
44 class RequestContext(StripeObject):
45 destination_duration: int
46 """
47 The time it took in milliseconds for the destination endpoint to respond.
48 """
49 destination_ip_address: str
50 """
51 The IP address of the destination.
52 """
53
54 class RequestDetails(StripeObject):
55 class Header(StripeObject):
56 name: str
57 """
58 The header name.
59 """
60 value: str
61 """
62 The header value.
63 """
64
65 body: str
66 """
67 The body payload to send to the destination endpoint.
68 """
69 headers: List[Header]
70 """
71 The headers to include in the forwarded request. Can be omitted if no additional headers (excluding Stripe-generated ones such as the Content-Type header) should be included.
72 """
73 http_method: Literal["POST"]
74 """
75 The HTTP method used to call the destination endpoint.
76 """
77 _inner_class_types = {"headers": Header}
78
79 class ResponseDetails(StripeObject):
80 class Header(StripeObject):
81 name: str
82 """
83 The header name.
84 """
85 value: str
86 """
87 The header value.
88 """
89
90 body: str
91 """
92 The response body from the destination endpoint to Stripe.
93 """
94 headers: List[Header]
95 """
96 HTTP headers that the destination endpoint returned.
97 """
98 status: int
99 """
100 The HTTP status code that the destination endpoint returned.
101 """
102 _inner_class_types = {"headers": Header}
103
104 created: int
105 """
106 Time at which the object was created. Measured in seconds since the Unix epoch.
107 """
108 id: str
109 """
110 Unique identifier for the object.
111 """
112 livemode: bool
113 """
114 Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
115 """
116 metadata: Optional[Dict[str, str]]
117 """
118 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.
119 """
120 object: Literal["forwarding.request"]
121 """
122 String representing the object's type. Objects of the same type share the same value.
123 """
124 payment_method: str
125 """
126 The PaymentMethod to insert into the forwarded request. Forwarding previously consumed PaymentMethods is allowed.
127 """
128 replacements: List[
129 Literal[
130 "card_cvc",
131 "card_expiry",
132 "card_number",
133 "cardholder_name",
134 "request_signature",
135 ]
136 ]
137 """
138 The field kinds to be replaced in the forwarded request.
139 """
140 request_context: Optional[RequestContext]
141 """
142 Context about the request from Stripe's servers to the destination endpoint.
143 """
144 request_details: Optional[RequestDetails]
145 """
146 The request that was sent to the destination endpoint. We redact any sensitive fields.
147 """
148 response_details: Optional[ResponseDetails]
149 """
150 The response that the destination endpoint returned to us. We redact any sensitive fields.
151 """
152 url: Optional[str]
153 """
154 The destination URL for the forwarded request. Must be supported by the config.
155 """
156
157 @classmethod
158 def create(cls, **params: Unpack["RequestCreateParams"]) -> "Request":
159 """
160 Creates a ForwardingRequest object.
161 """
162 return cast(
163 "Request",
164 cls._static_request(
165 "post",
166 cls.class_url(),
167 params=params,
168 ),
169 )
170
171 @classmethod
172 async def create_async(
173 cls, **params: Unpack["RequestCreateParams"]
174 ) -> "Request":
175 """
176 Creates a ForwardingRequest object.
177 """
178 return cast(
179 "Request",
180 await cls._static_request_async(
181 "post",
182 cls.class_url(),
183 params=params,
184 ),
185 )
186
187 @classmethod
188 def list(
189 cls, **params: Unpack["RequestListParams"]
190 ) -> ListObject["Request"]:
191 """
192 Lists all ForwardingRequest objects.
193 """
194 result = cls._static_request(
195 "get",
196 cls.class_url(),
197 params=params,
198 )
199 if not isinstance(result, ListObject):
200 raise TypeError(
201 "Expected list object from API, got %s"
202 % (type(result).__name__)
203 )
204
205 return result
206
207 @classmethod
208 async def list_async(
209 cls, **params: Unpack["RequestListParams"]
210 ) -> ListObject["Request"]:
211 """
212 Lists all ForwardingRequest objects.
213 """
214 result = await cls._static_request_async(
215 "get",
216 cls.class_url(),
217 params=params,
218 )
219 if not isinstance(result, ListObject):
220 raise TypeError(
221 "Expected list object from API, got %s"
222 % (type(result).__name__)
223 )
224
225 return result
226
227 @classmethod
228 def retrieve(
229 cls, id: str, **params: Unpack["RequestRetrieveParams"]
230 ) -> "Request":
231 """
232 Retrieves a ForwardingRequest object.
233 """
234 instance = cls(id, **params)
235 instance.refresh()
236 return instance
237
238 @classmethod
239 async def retrieve_async(
240 cls, id: str, **params: Unpack["RequestRetrieveParams"]
241 ) -> "Request":
242 """
243 Retrieves a ForwardingRequest object.
244 """
245 instance = cls(id, **params)
246 await instance.refresh_async()
247 return instance
248
249 _inner_class_types = {
250 "request_context": RequestContext,
251 "request_details": RequestDetails,
252 "response_details": ResponseDetails,
253 }