Debian Codegraph @

stripe/treasury/_received_credit.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._test_helpers import APIResourceTestHelpers
8 from typing import ClassVar, Optional, cast
9 from typing_extensions import Literal, Type, Unpack, TYPE_CHECKING
10
11 if TYPE_CHECKING:
12 from stripe._payout import Payout
13 from stripe.params.treasury._received_credit_create_params import (
14 ReceivedCreditCreateParams,
15 )
16 from stripe.params.treasury._received_credit_list_params import (
17 ReceivedCreditListParams,
18 )
19 from stripe.params.treasury._received_credit_retrieve_params import (
20 ReceivedCreditRetrieveParams,
21 )
22 from stripe.treasury._credit_reversal import CreditReversal
23 from stripe.treasury._outbound_payment import OutboundPayment
24 from stripe.treasury._outbound_transfer import OutboundTransfer
25 from stripe.treasury._transaction import Transaction
26
27
28 class ReceivedCredit(ListableAPIResource["ReceivedCredit"]):
29 """
30 ReceivedCredits represent funds sent to a [FinancialAccount](https://api.stripe.com#financial_accounts) (for example, via ACH or wire). These money movements are not initiated from the FinancialAccount.
31 """
32
33 OBJECT_NAME: ClassVar[Literal["treasury.received_credit"]] = (
34 "treasury.received_credit"
35 )
36
37 class InitiatingPaymentMethodDetails(StripeObject):
38 class BillingDetails(StripeObject):
39 class Address(StripeObject):
40 city: Optional[str]
41 """
42 City, district, suburb, town, or village.
43 """
44 country: Optional[str]
45 """
46 Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
47 """
48 line1: Optional[str]
49 """
50 Address line 1, such as the street, PO Box, or company name.
51 """
52 line2: Optional[str]
53 """
54 Address line 2, such as the apartment, suite, unit, or building.
55 """
56 postal_code: Optional[str]
57 """
58 ZIP or postal code.
59 """
60 state: Optional[str]
61 """
62 State, county, province, or region ([ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2)).
63 """
64
65 address: Address
66 email: Optional[str]
67 """
68 Email address.
69 """
70 name: Optional[str]
71 """
72 Full name.
73 """
74 _inner_class_types = {"address": Address}
75
76 class FinancialAccount(StripeObject):
77 id: str
78 """
79 The FinancialAccount ID.
80 """
81 network: Literal["stripe"]
82 """
83 The rails the ReceivedCredit was sent over. A FinancialAccount can only send funds over `stripe`.
84 """
85
86 class UsBankAccount(StripeObject):
87 bank_name: Optional[str]
88 """
89 Bank name.
90 """
91 last4: Optional[str]
92 """
93 The last four digits of the bank account number.
94 """
95 routing_number: Optional[str]
96 """
97 The routing number for the bank account.
98 """
99
100 balance: Optional[Literal["payments"]]
101 """
102 Set when `type` is `balance`.
103 """
104 billing_details: BillingDetails
105 financial_account: Optional[FinancialAccount]
106 issuing_card: Optional[str]
107 """
108 Set when `type` is `issuing_card`. This is an [Issuing Card](https://api.stripe.com#issuing_cards) ID.
109 """
110 type: Literal[
111 "balance",
112 "financial_account",
113 "issuing_card",
114 "stripe",
115 "us_bank_account",
116 ]
117 """
118 Polymorphic type matching the originating money movement's source. This can be an external account, a Stripe balance, or a FinancialAccount.
119 """
120 us_bank_account: Optional[UsBankAccount]
121 _inner_class_types = {
122 "billing_details": BillingDetails,
123 "financial_account": FinancialAccount,
124 "us_bank_account": UsBankAccount,
125 }
126
127 class LinkedFlows(StripeObject):
128 class SourceFlowDetails(StripeObject):
129 credit_reversal: Optional["CreditReversal"]
130 """
131 You can reverse some [ReceivedCredits](https://api.stripe.com#received_credits) depending on their network and source flow. Reversing a ReceivedCredit leads to the creation of a new object known as a CreditReversal.
132 """
133 outbound_payment: Optional["OutboundPayment"]
134 """
135 Use [OutboundPayments](https://docs.stripe.com/docs/treasury/moving-money/financial-accounts/out-of/outbound-payments) to send funds to another party's external bank account or [FinancialAccount](https://api.stripe.com#financial_accounts). To send money to an account belonging to the same user, use an [OutboundTransfer](https://api.stripe.com#outbound_transfers).
136
137 Simulate OutboundPayment state changes with the `/v1/test_helpers/treasury/outbound_payments` endpoints. These methods can only be called on test mode objects.
138
139 Related guide: [Moving money with Treasury using OutboundPayment objects](https://docs.stripe.com/docs/treasury/moving-money/financial-accounts/out-of/outbound-payments)
140 """
141 outbound_transfer: Optional["OutboundTransfer"]
142 """
143 Use [OutboundTransfers](https://docs.stripe.com/docs/treasury/moving-money/financial-accounts/out-of/outbound-transfers) to transfer funds from a [FinancialAccount](https://api.stripe.com#financial_accounts) to a PaymentMethod belonging to the same entity. To send funds to a different party, use [OutboundPayments](https://api.stripe.com#outbound_payments) instead. You can send funds over ACH rails or through a domestic wire transfer to a user's own external bank account.
144
145 Simulate OutboundTransfer state changes with the `/v1/test_helpers/treasury/outbound_transfers` endpoints. These methods can only be called on test mode objects.
146
147 Related guide: [Moving money with Treasury using OutboundTransfer objects](https://docs.stripe.com/docs/treasury/moving-money/financial-accounts/out-of/outbound-transfers)
148 """
149 payout: Optional["Payout"]
150 """
151 A `Payout` object is created when you receive funds from Stripe, or when you
152 initiate a payout to either a bank account or debit card of a [connected
153 Stripe account](https://docs.stripe.com/docs/connect/bank-debit-card-payouts). You can retrieve individual payouts,
154 and list all payouts. Payouts are made on [varying
155 schedules](https://docs.stripe.com/docs/connect/manage-payout-schedule), depending on your country and
156 industry.
157
158 Related guide: [Receiving payouts](https://docs.stripe.com/payouts)
159 """
160 type: Literal[
161 "credit_reversal",
162 "other",
163 "outbound_payment",
164 "outbound_transfer",
165 "payout",
166 ]
167 """
168 The type of the source flow that originated the ReceivedCredit.
169 """
170
171 credit_reversal: Optional[str]
172 """
173 The CreditReversal created as a result of this ReceivedCredit being reversed.
174 """
175 issuing_authorization: Optional[str]
176 """
177 Set if the ReceivedCredit was created due to an [Issuing Authorization](https://api.stripe.com#issuing_authorizations) object.
178 """
179 issuing_transaction: Optional[str]
180 """
181 Set if the ReceivedCredit is also viewable as an [Issuing transaction](https://api.stripe.com#issuing_transactions) object.
182 """
183 source_flow: Optional[str]
184 """
185 ID of the source flow. Set if `network` is `stripe` and the source flow is visible to the user. Examples of source flows include OutboundPayments, payouts, or CreditReversals.
186 """
187 source_flow_details: Optional[SourceFlowDetails]
188 """
189 The expandable object of the source flow.
190 """
191 source_flow_type: Optional[str]
192 """
193 The type of flow that originated the ReceivedCredit (for example, `outbound_payment`).
194 """
195 _inner_class_types = {"source_flow_details": SourceFlowDetails}
196
197 class ReversalDetails(StripeObject):
198 deadline: Optional[int]
199 """
200 Time before which a ReceivedCredit can be reversed.
201 """
202 restricted_reason: Optional[
203 Literal[
204 "already_reversed",
205 "deadline_passed",
206 "network_restricted",
207 "other",
208 "source_flow_restricted",
209 ]
210 ]
211 """
212 Set if a ReceivedCredit cannot be reversed.
213 """
214
215 amount: int
216 """
217 Amount (in cents) transferred.
218 """
219 created: int
220 """
221 Time at which the object was created. Measured in seconds since the Unix epoch.
222 """
223 currency: str
224 """
225 Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](https://stripe.com/docs/currencies).
226 """
227 description: str
228 """
229 An arbitrary string attached to the object. Often useful for displaying to users.
230 """
231 failure_code: Optional[
232 Literal[
233 "account_closed",
234 "account_frozen",
235 "international_transaction",
236 "other",
237 ]
238 ]
239 """
240 Reason for the failure. A ReceivedCredit might fail because the receiving FinancialAccount is closed or frozen.
241 """
242 financial_account: Optional[str]
243 """
244 The FinancialAccount that received the funds.
245 """
246 hosted_regulatory_receipt_url: Optional[str]
247 """
248 A [hosted transaction receipt](https://docs.stripe.com/treasury/moving-money/regulatory-receipts) URL that is provided when money movement is considered regulated under Stripe's money transmission licenses.
249 """
250 id: str
251 """
252 Unique identifier for the object.
253 """
254 initiating_payment_method_details: InitiatingPaymentMethodDetails
255 linked_flows: LinkedFlows
256 livemode: bool
257 """
258 Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
259 """
260 network: Literal["ach", "card", "stripe", "us_domestic_wire"]
261 """
262 The rails used to send the funds.
263 """
264 object: Literal["treasury.received_credit"]
265 """
266 String representing the object's type. Objects of the same type share the same value.
267 """
268 reversal_details: Optional[ReversalDetails]
269 """
270 Details describing when a ReceivedCredit may be reversed.
271 """
272 status: Literal["failed", "succeeded"]
273 """
274 Status of the ReceivedCredit. ReceivedCredits are created either `succeeded` (approved) or `failed` (declined). If a ReceivedCredit is declined, the failure reason can be found in the `failure_code` field.
275 """
276 transaction: Optional[ExpandableField["Transaction"]]
277 """
278 The Transaction associated with this object.
279 """
280
281 @classmethod
282 def list(
283 cls, **params: Unpack["ReceivedCreditListParams"]
284 ) -> ListObject["ReceivedCredit"]:
285 """
286 Returns a list of ReceivedCredits.
287 """
288 result = cls._static_request(
289 "get",
290 cls.class_url(),
291 params=params,
292 )
293 if not isinstance(result, ListObject):
294 raise TypeError(
295 "Expected list object from API, got %s"
296 % (type(result).__name__)
297 )
298
299 return result
300
301 @classmethod
302 async def list_async(
303 cls, **params: Unpack["ReceivedCreditListParams"]
304 ) -> ListObject["ReceivedCredit"]:
305 """
306 Returns a list of ReceivedCredits.
307 """
308 result = await cls._static_request_async(
309 "get",
310 cls.class_url(),
311 params=params,
312 )
313 if not isinstance(result, ListObject):
314 raise TypeError(
315 "Expected list object from API, got %s"
316 % (type(result).__name__)
317 )
318
319 return result
320
321 @classmethod
322 def retrieve(
323 cls, id: str, **params: Unpack["ReceivedCreditRetrieveParams"]
324 ) -> "ReceivedCredit":
325 """
326 Retrieves the details of an existing ReceivedCredit by passing the unique ReceivedCredit ID from the ReceivedCredit list.
327 """
328 instance = cls(id, **params)
329 instance.refresh()
330 return instance
331
332 @classmethod
333 async def retrieve_async(
334 cls, id: str, **params: Unpack["ReceivedCreditRetrieveParams"]
335 ) -> "ReceivedCredit":
336 """
337 Retrieves the details of an existing ReceivedCredit by passing the unique ReceivedCredit ID from the ReceivedCredit list.
338 """
339 instance = cls(id, **params)
340 await instance.refresh_async()
341 return instance
342
343 class TestHelpers(APIResourceTestHelpers["ReceivedCredit"]):
344 _resource_cls: Type["ReceivedCredit"]
345
346 @classmethod
347 def create(
348 cls, **params: Unpack["ReceivedCreditCreateParams"]
349 ) -> "ReceivedCredit":
350 """
351 Use this endpoint to simulate a test mode ReceivedCredit initiated by a third party. In live mode, you can't directly create ReceivedCredits initiated by third parties.
352 """
353 return cast(
354 "ReceivedCredit",
355 cls._static_request(
356 "post",
357 "/v1/test_helpers/treasury/received_credits",
358 params=params,
359 ),
360 )
361
362 @classmethod
363 async def create_async(
364 cls, **params: Unpack["ReceivedCreditCreateParams"]
365 ) -> "ReceivedCredit":
366 """
367 Use this endpoint to simulate a test mode ReceivedCredit initiated by a third party. In live mode, you can't directly create ReceivedCredits initiated by third parties.
368 """
369 return cast(
370 "ReceivedCredit",
371 await cls._static_request_async(
372 "post",
373 "/v1/test_helpers/treasury/received_credits",
374 params=params,
375 ),
376 )
377
378 @property
379 def test_helpers(self):
380 return self.TestHelpers(self)
381
382 _inner_class_types = {
383 "initiating_payment_method_details": InitiatingPaymentMethodDetails,
384 "linked_flows": LinkedFlows,
385 "reversal_details": ReversalDetails,
386 }
387
388
389 ReceivedCredit.TestHelpers._resource_cls = ReceivedCredit