github.com/stripe/stripe-go/v76@v76.25.0/treasury_transaction.go (about)

     1  //
     2  //
     3  // File generated from our OpenAPI spec
     4  //
     5  //
     6  
     7  package stripe
     8  
     9  import "encoding/json"
    10  
    11  // Type of the flow that created the Transaction. Set to the same value as `flow_type`.
    12  type TreasuryTransactionFlowDetailsType string
    13  
    14  // List of values that TreasuryTransactionFlowDetailsType can take
    15  const (
    16  	TreasuryTransactionFlowDetailsTypeCreditReversal       TreasuryTransactionFlowDetailsType = "credit_reversal"
    17  	TreasuryTransactionFlowDetailsTypeDebitReversal        TreasuryTransactionFlowDetailsType = "debit_reversal"
    18  	TreasuryTransactionFlowDetailsTypeInboundTransfer      TreasuryTransactionFlowDetailsType = "inbound_transfer"
    19  	TreasuryTransactionFlowDetailsTypeIssuingAuthorization TreasuryTransactionFlowDetailsType = "issuing_authorization"
    20  	TreasuryTransactionFlowDetailsTypeOther                TreasuryTransactionFlowDetailsType = "other"
    21  	TreasuryTransactionFlowDetailsTypeOutboundPayment      TreasuryTransactionFlowDetailsType = "outbound_payment"
    22  	TreasuryTransactionFlowDetailsTypeOutboundTransfer     TreasuryTransactionFlowDetailsType = "outbound_transfer"
    23  	TreasuryTransactionFlowDetailsTypeReceivedCredit       TreasuryTransactionFlowDetailsType = "received_credit"
    24  	TreasuryTransactionFlowDetailsTypeReceivedDebit        TreasuryTransactionFlowDetailsType = "received_debit"
    25  )
    26  
    27  // Type of the flow that created the Transaction.
    28  type TreasuryTransactionFlowType string
    29  
    30  // List of values that TreasuryTransactionFlowType can take
    31  const (
    32  	TreasuryTransactionFlowTypeCreditReversal       TreasuryTransactionFlowType = "credit_reversal"
    33  	TreasuryTransactionFlowTypeDebitReversal        TreasuryTransactionFlowType = "debit_reversal"
    34  	TreasuryTransactionFlowTypeInboundTransfer      TreasuryTransactionFlowType = "inbound_transfer"
    35  	TreasuryTransactionFlowTypeIssuingAuthorization TreasuryTransactionFlowType = "issuing_authorization"
    36  	TreasuryTransactionFlowTypeOther                TreasuryTransactionFlowType = "other"
    37  	TreasuryTransactionFlowTypeOutboundPayment      TreasuryTransactionFlowType = "outbound_payment"
    38  	TreasuryTransactionFlowTypeOutboundTransfer     TreasuryTransactionFlowType = "outbound_transfer"
    39  	TreasuryTransactionFlowTypeReceivedCredit       TreasuryTransactionFlowType = "received_credit"
    40  	TreasuryTransactionFlowTypeReceivedDebit        TreasuryTransactionFlowType = "received_debit"
    41  )
    42  
    43  // Status of the Transaction.
    44  type TreasuryTransactionStatus string
    45  
    46  // List of values that TreasuryTransactionStatus can take
    47  const (
    48  	TreasuryTransactionStatusOpen   TreasuryTransactionStatus = "open"
    49  	TreasuryTransactionStatusPosted TreasuryTransactionStatus = "posted"
    50  	TreasuryTransactionStatusVoid   TreasuryTransactionStatus = "void"
    51  )
    52  
    53  // A filter for the `status_transitions.posted_at` timestamp. When using this filter, `status=posted` and `order_by=posted_at` must also be specified.
    54  type TreasuryTransactionListStatusTransitionsParams struct {
    55  	// Returns Transactions with `posted_at` within the specified range.
    56  	PostedAt *int64 `form:"posted_at"`
    57  	// Returns Transactions with `posted_at` within the specified range.
    58  	PostedAtRange *RangeQueryParams `form:"posted_at"`
    59  }
    60  
    61  // Retrieves a list of Transaction objects.
    62  type TreasuryTransactionListParams struct {
    63  	ListParams `form:"*"`
    64  	// Only return Transactions that were created during the given date interval.
    65  	Created *int64 `form:"created"`
    66  	// Only return Transactions that were created during the given date interval.
    67  	CreatedRange *RangeQueryParams `form:"created"`
    68  	// Specifies which fields in the response should be expanded.
    69  	Expand []*string `form:"expand"`
    70  	// Returns objects associated with this FinancialAccount.
    71  	FinancialAccount *string `form:"financial_account"`
    72  	// The results are in reverse chronological order by `created` or `posted_at`. The default is `created`.
    73  	OrderBy *string `form:"order_by"`
    74  	// Only return Transactions that have the given status: `open`, `posted`, or `void`.
    75  	Status *string `form:"status"`
    76  	// A filter for the `status_transitions.posted_at` timestamp. When using this filter, `status=posted` and `order_by=posted_at` must also be specified.
    77  	StatusTransitions *TreasuryTransactionListStatusTransitionsParams `form:"status_transitions"`
    78  }
    79  
    80  // AddExpand appends a new field to expand.
    81  func (p *TreasuryTransactionListParams) AddExpand(f string) {
    82  	p.Expand = append(p.Expand, &f)
    83  }
    84  
    85  // Retrieves the details of an existing Transaction.
    86  type TreasuryTransactionParams struct {
    87  	Params `form:"*"`
    88  	// Specifies which fields in the response should be expanded.
    89  	Expand []*string `form:"expand"`
    90  }
    91  
    92  // AddExpand appends a new field to expand.
    93  func (p *TreasuryTransactionParams) AddExpand(f string) {
    94  	p.Expand = append(p.Expand, &f)
    95  }
    96  
    97  // Change to a FinancialAccount's balance
    98  type TreasuryTransactionBalanceImpact struct {
    99  	// The change made to funds the user can spend right now.
   100  	Cash int64 `json:"cash"`
   101  	// The change made to funds that are not spendable yet, but will become available at a later time.
   102  	InboundPending int64 `json:"inbound_pending"`
   103  	// The change made to funds in the account, but not spendable because they are being held for pending outbound flows.
   104  	OutboundPending int64 `json:"outbound_pending"`
   105  }
   106  
   107  // Details of the flow that created the Transaction.
   108  type TreasuryTransactionFlowDetails struct {
   109  	// You can reverse some [ReceivedCredits](https://stripe.com/docs/api#received_credits) depending on their network and source flow. Reversing a ReceivedCredit leads to the creation of a new object known as a CreditReversal.
   110  	CreditReversal *TreasuryCreditReversal `json:"credit_reversal"`
   111  	// You can reverse some [ReceivedDebits](https://stripe.com/docs/api#received_debits) depending on their network and source flow. Reversing a ReceivedDebit leads to the creation of a new object known as a DebitReversal.
   112  	DebitReversal *TreasuryDebitReversal `json:"debit_reversal"`
   113  	// Use [InboundTransfers](https://stripe.com/docs/treasury/moving-money/financial-accounts/into/inbound-transfers) to add funds to your [FinancialAccount](https://stripe.com/docs/api#financial_accounts) via a PaymentMethod that is owned by you. The funds will be transferred via an ACH debit.
   114  	InboundTransfer *TreasuryInboundTransfer `json:"inbound_transfer"`
   115  	// When an [issued card](https://stripe.com/docs/issuing) is used to make a purchase, an Issuing `Authorization`
   116  	// object is created. [Authorizations](https://stripe.com/docs/issuing/purchases/authorizations) must be approved for the
   117  	// purchase to be completed successfully.
   118  	//
   119  	// Related guide: [Issued card authorizations](https://stripe.com/docs/issuing/purchases/authorizations)
   120  	IssuingAuthorization *IssuingAuthorization `json:"issuing_authorization"`
   121  	// Use OutboundPayments to send funds to another party's external bank account or [FinancialAccount](https://stripe.com/docs/api#financial_accounts). To send money to an account belonging to the same user, use an [OutboundTransfer](https://stripe.com/docs/api#outbound_transfers).
   122  	//
   123  	// Simulate OutboundPayment state changes with the `/v1/test_helpers/treasury/outbound_payments` endpoints. These methods can only be called on test mode objects.
   124  	OutboundPayment *TreasuryOutboundPayment `json:"outbound_payment"`
   125  	// Use OutboundTransfers to transfer funds from a [FinancialAccount](https://stripe.com/docs/api#financial_accounts) to a PaymentMethod belonging to the same entity. To send funds to a different party, use [OutboundPayments](https://stripe.com/docs/api#outbound_payments) instead. You can send funds over ACH rails or through a domestic wire transfer to a user's own external bank account.
   126  	//
   127  	// Simulate OutboundTransfer state changes with the `/v1/test_helpers/treasury/outbound_transfers` endpoints. These methods can only be called on test mode objects.
   128  	OutboundTransfer *TreasuryOutboundTransfer `json:"outbound_transfer"`
   129  	// ReceivedCredits represent funds sent to a [FinancialAccount](https://stripe.com/docs/api#financial_accounts) (for example, via ACH or wire). These money movements are not initiated from the FinancialAccount.
   130  	ReceivedCredit *TreasuryReceivedCredit `json:"received_credit"`
   131  	// ReceivedDebits represent funds pulled from a [FinancialAccount](https://stripe.com/docs/api#financial_accounts). These are not initiated from the FinancialAccount.
   132  	ReceivedDebit *TreasuryReceivedDebit `json:"received_debit"`
   133  	// Type of the flow that created the Transaction. Set to the same value as `flow_type`.
   134  	Type TreasuryTransactionFlowDetailsType `json:"type"`
   135  }
   136  type TreasuryTransactionStatusTransitions struct {
   137  	// Timestamp describing when the Transaction changed status to `posted`.
   138  	PostedAt int64 `json:"posted_at"`
   139  	// Timestamp describing when the Transaction changed status to `void`.
   140  	VoidAt int64 `json:"void_at"`
   141  }
   142  
   143  // Transactions represent changes to a [FinancialAccount's](https://stripe.com/docs/api#financial_accounts) balance.
   144  type TreasuryTransaction struct {
   145  	APIResource
   146  	// Amount (in cents) transferred.
   147  	Amount int64 `json:"amount"`
   148  	// Change to a FinancialAccount's balance
   149  	BalanceImpact *TreasuryTransactionBalanceImpact `json:"balance_impact"`
   150  	// Time at which the object was created. Measured in seconds since the Unix epoch.
   151  	Created int64 `json:"created"`
   152  	// 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).
   153  	Currency Currency `json:"currency"`
   154  	// An arbitrary string attached to the object. Often useful for displaying to users.
   155  	Description string `json:"description"`
   156  	// A list of TransactionEntries that are part of this Transaction. This cannot be expanded in any list endpoints.
   157  	Entries *TreasuryTransactionEntryList `json:"entries"`
   158  	// The FinancialAccount associated with this object.
   159  	FinancialAccount string `json:"financial_account"`
   160  	// ID of the flow that created the Transaction.
   161  	Flow string `json:"flow"`
   162  	// Details of the flow that created the Transaction.
   163  	FlowDetails *TreasuryTransactionFlowDetails `json:"flow_details"`
   164  	// Type of the flow that created the Transaction.
   165  	FlowType TreasuryTransactionFlowType `json:"flow_type"`
   166  	// Unique identifier for the object.
   167  	ID string `json:"id"`
   168  	// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
   169  	Livemode bool `json:"livemode"`
   170  	// String representing the object's type. Objects of the same type share the same value.
   171  	Object string `json:"object"`
   172  	// Status of the Transaction.
   173  	Status            TreasuryTransactionStatus             `json:"status"`
   174  	StatusTransitions *TreasuryTransactionStatusTransitions `json:"status_transitions"`
   175  }
   176  
   177  // TreasuryTransactionList is a list of Transactions as retrieved from a list endpoint.
   178  type TreasuryTransactionList struct {
   179  	APIResource
   180  	ListMeta
   181  	Data []*TreasuryTransaction `json:"data"`
   182  }
   183  
   184  // UnmarshalJSON handles deserialization of a TreasuryTransaction.
   185  // This custom unmarshaling is needed because the resulting
   186  // property may be an id or the full struct if it was expanded.
   187  func (t *TreasuryTransaction) UnmarshalJSON(data []byte) error {
   188  	if id, ok := ParseID(data); ok {
   189  		t.ID = id
   190  		return nil
   191  	}
   192  
   193  	type treasuryTransaction TreasuryTransaction
   194  	var v treasuryTransaction
   195  	if err := json.Unmarshal(data, &v); err != nil {
   196  		return err
   197  	}
   198  
   199  	*t = TreasuryTransaction(v)
   200  	return nil
   201  }