Debian Codegraph @

stripe/treasury/_transaction.py

raw
1 # -*- coding: utf-8 -*-
2 # File generated from our OpenAPI spec
3 from stripe._list_object import ListObject
4 from stripe._listable_api_resource import ListableAPIResource
5 from stripe._stripe_object import StripeObject
6 from typing import ClassVar, Optional
7 from typing_extensions import Literal, Unpack, TYPE_CHECKING
8
9 if TYPE_CHECKING:
10 from stripe.issuing._authorization import Authorization
11 from stripe.params.treasury._transaction_list_params import (
12 TransactionListParams,
13 )
14 from stripe.params.treasury._transaction_retrieve_params import (
15 TransactionRetrieveParams,
16 )
17 from stripe.treasury._credit_reversal import CreditReversal
18 from stripe.treasury._debit_reversal import DebitReversal
19 from stripe.treasury._inbound_transfer import InboundTransfer
20 from stripe.treasury._outbound_payment import OutboundPayment
21 from stripe.treasury._outbound_transfer import OutboundTransfer
22 from stripe.treasury._received_credit import ReceivedCredit
23 from stripe.treasury._received_debit import ReceivedDebit
24 from stripe.treasury._transaction_entry import TransactionEntry
25
26
27 class Transaction(ListableAPIResource["Transaction"]):
28 """
29 Transactions represent changes to a [FinancialAccount's](https://api.stripe.com#financial_accounts) balance.
30 """
31
32 OBJECT_NAME: ClassVar[Literal["treasury.transaction"]] = (
33 "treasury.transaction"
34 )
35
36 class BalanceImpact(StripeObject):
37 cash: int
38 """
39 The change made to funds the user can spend right now.
40 """
41 inbound_pending: int
42 """
43 The change made to funds that are not spendable yet, but will become available at a later time.
44 """
45 outbound_pending: int
46 """
47 The change made to funds in the account, but not spendable because they are being held for pending outbound flows.
48 """
49
50 class FlowDetails(StripeObject):
51 credit_reversal: Optional["CreditReversal"]
52 """
53 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.
54 """
55 debit_reversal: Optional["DebitReversal"]
56 """
57 You can reverse some [ReceivedDebits](https://api.stripe.com#received_debits) depending on their network and source flow. Reversing a ReceivedDebit leads to the creation of a new object known as a DebitReversal.
58 """
59 inbound_transfer: Optional["InboundTransfer"]
60 """
61 Use [InboundTransfers](https://docs.stripe.com/docs/treasury/moving-money/financial-accounts/into/inbound-transfers) to add funds to your [FinancialAccount](https://api.stripe.com#financial_accounts) via a PaymentMethod that is owned by you. The funds will be transferred via an ACH debit.
62
63 Related guide: [Moving money with Treasury using InboundTransfer objects](https://docs.stripe.com/docs/treasury/moving-money/financial-accounts/into/inbound-transfers)
64 """
65 issuing_authorization: Optional["Authorization"]
66 """
67 When an [issued card](https://docs.stripe.com/issuing) is used to make a purchase, an Issuing `Authorization`
68 object is created. [Authorizations](https://docs.stripe.com/issuing/purchases/authorizations) must be approved for the
69 purchase to be completed successfully.
70
71 Related guide: [Issued card authorizations](https://docs.stripe.com/issuing/purchases/authorizations)
72 """
73 outbound_payment: Optional["OutboundPayment"]
74 """
75 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).
76
77 Simulate OutboundPayment state changes with the `/v1/test_helpers/treasury/outbound_payments` endpoints. These methods can only be called on test mode objects.
78
79 Related guide: [Moving money with Treasury using OutboundPayment objects](https://docs.stripe.com/docs/treasury/moving-money/financial-accounts/out-of/outbound-payments)
80 """
81 outbound_transfer: Optional["OutboundTransfer"]
82 """
83 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.
84
85 Simulate OutboundTransfer state changes with the `/v1/test_helpers/treasury/outbound_transfers` endpoints. These methods can only be called on test mode objects.
86
87 Related guide: [Moving money with Treasury using OutboundTransfer objects](https://docs.stripe.com/docs/treasury/moving-money/financial-accounts/out-of/outbound-transfers)
88 """
89 received_credit: Optional["ReceivedCredit"]
90 """
91 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.
92 """
93 received_debit: Optional["ReceivedDebit"]
94 """
95 ReceivedDebits represent funds pulled from a [FinancialAccount](https://api.stripe.com#financial_accounts). These are not initiated from the FinancialAccount.
96 """
97 type: Literal[
98 "credit_reversal",
99 "debit_reversal",
100 "inbound_transfer",
101 "issuing_authorization",
102 "other",
103 "outbound_payment",
104 "outbound_transfer",
105 "received_credit",
106 "received_debit",
107 ]
108 """
109 Type of the flow that created the Transaction. Set to the same value as `flow_type`.
110 """
111
112 class StatusTransitions(StripeObject):
113 posted_at: Optional[int]
114 """
115 Timestamp describing when the Transaction changed status to `posted`.
116 """
117 void_at: Optional[int]
118 """
119 Timestamp describing when the Transaction changed status to `void`.
120 """
121
122 amount: int
123 """
124 Amount (in cents) transferred.
125 """
126 balance_impact: BalanceImpact
127 """
128 Change to a FinancialAccount's balance
129 """
130 created: int
131 """
132 Time at which the object was created. Measured in seconds since the Unix epoch.
133 """
134 currency: str
135 """
136 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).
137 """
138 description: str
139 """
140 An arbitrary string attached to the object. Often useful for displaying to users.
141 """
142 entries: Optional[ListObject["TransactionEntry"]]
143 """
144 A list of TransactionEntries that are part of this Transaction. This cannot be expanded in any list endpoints.
145 """
146 financial_account: str
147 """
148 The FinancialAccount associated with this object.
149 """
150 flow: Optional[str]
151 """
152 ID of the flow that created the Transaction.
153 """
154 flow_details: Optional[FlowDetails]
155 """
156 Details of the flow that created the Transaction.
157 """
158 flow_type: Literal[
159 "credit_reversal",
160 "debit_reversal",
161 "inbound_transfer",
162 "issuing_authorization",
163 "other",
164 "outbound_payment",
165 "outbound_transfer",
166 "received_credit",
167 "received_debit",
168 ]
169 """
170 Type of the flow that created the Transaction.
171 """
172 id: str
173 """
174 Unique identifier for the object.
175 """
176 livemode: bool
177 """
178 Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
179 """
180 object: Literal["treasury.transaction"]
181 """
182 String representing the object's type. Objects of the same type share the same value.
183 """
184 status: Literal["open", "posted", "void"]
185 """
186 Status of the Transaction.
187 """
188 status_transitions: StatusTransitions
189
190 @classmethod
191 def list(
192 cls, **params: Unpack["TransactionListParams"]
193 ) -> ListObject["Transaction"]:
194 """
195 Retrieves a list of Transaction objects.
196 """
197 result = cls._static_request(
198 "get",
199 cls.class_url(),
200 params=params,
201 )
202 if not isinstance(result, ListObject):
203 raise TypeError(
204 "Expected list object from API, got %s"
205 % (type(result).__name__)
206 )
207
208 return result
209
210 @classmethod
211 async def list_async(
212 cls, **params: Unpack["TransactionListParams"]
213 ) -> ListObject["Transaction"]:
214 """
215 Retrieves a list of Transaction objects.
216 """
217 result = await cls._static_request_async(
218 "get",
219 cls.class_url(),
220 params=params,
221 )
222 if not isinstance(result, ListObject):
223 raise TypeError(
224 "Expected list object from API, got %s"
225 % (type(result).__name__)
226 )
227
228 return result
229
230 @classmethod
231 def retrieve(
232 cls, id: str, **params: Unpack["TransactionRetrieveParams"]
233 ) -> "Transaction":
234 """
235 Retrieves the details of an existing Transaction.
236 """
237 instance = cls(id, **params)
238 instance.refresh()
239 return instance
240
241 @classmethod
242 async def retrieve_async(
243 cls, id: str, **params: Unpack["TransactionRetrieveParams"]
244 ) -> "Transaction":
245 """
246 Retrieves the details of an existing Transaction.
247 """
248 instance = cls(id, **params)
249 await instance.refresh_async()
250 return instance
251
252 _inner_class_types = {
253 "balance_impact": BalanceImpact,
254 "flow_details": FlowDetails,
255 "status_transitions": StatusTransitions,
256 }