github.com/stripe/stripe-go/v76@v76.25.0/customerbalancetransaction.go (about) 1 // 2 // 3 // File generated from our OpenAPI spec 4 // 5 // 6 7 package stripe 8 9 import "encoding/json" 10 11 // Transaction type: `adjustment`, `applied_to_invoice`, `credit_note`, `initial`, `invoice_overpaid`, `invoice_too_large`, `invoice_too_small`, `unspent_receiver_credit`, or `unapplied_from_invoice`. See the [Customer Balance page](https://stripe.com/docs/billing/customer/balance#types) to learn more about transaction types. 12 type CustomerBalanceTransactionType string 13 14 // List of values that CustomerBalanceTransactionType can take 15 const ( 16 CustomerBalanceTransactionTypeAdjustment CustomerBalanceTransactionType = "adjustment" 17 CustomerBalanceTransactionTypeAppliedToInvoice CustomerBalanceTransactionType = "applied_to_invoice" 18 CustomerBalanceTransactionTypeCreditNote CustomerBalanceTransactionType = "credit_note" 19 CustomerBalanceTransactionTypeInitial CustomerBalanceTransactionType = "initial" 20 CustomerBalanceTransactionTypeInvoiceOverpaid CustomerBalanceTransactionType = "invoice_overpaid" 21 CustomerBalanceTransactionTypeInvoiceTooLarge CustomerBalanceTransactionType = "invoice_too_large" 22 CustomerBalanceTransactionTypeInvoiceTooSmall CustomerBalanceTransactionType = "invoice_too_small" 23 CustomerBalanceTransactionTypeMigration CustomerBalanceTransactionType = "migration" 24 CustomerBalanceTransactionTypeUnappliedFromInvoice CustomerBalanceTransactionType = "unapplied_from_invoice" 25 CustomerBalanceTransactionTypeUnspentReceiverCredit CustomerBalanceTransactionType = "unspent_receiver_credit" 26 ) 27 28 // Returns a list of transactions that updated the customer's [balances](https://stripe.com/docs/billing/customer/balance). 29 type CustomerBalanceTransactionListParams struct { 30 ListParams `form:"*"` 31 Customer *string `form:"-"` // Included in URL 32 // Specifies which fields in the response should be expanded. 33 Expand []*string `form:"expand"` 34 } 35 36 // AddExpand appends a new field to expand. 37 func (p *CustomerBalanceTransactionListParams) AddExpand(f string) { 38 p.Expand = append(p.Expand, &f) 39 } 40 41 // Creates an immutable transaction that updates the customer's credit [balance](https://stripe.com/docs/billing/customer/balance). 42 type CustomerBalanceTransactionParams struct { 43 Params `form:"*"` 44 Customer *string `form:"-"` // Included in URL 45 // The integer amount in **cents (or local equivalent)** to apply to the customer's credit balance. 46 Amount *int64 `form:"amount"` 47 // 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). Specifies the [`invoice_credit_balance`](https://stripe.com/docs/api/customers/object#customer_object-invoice_credit_balance) that this transaction will apply to. If the customer's `currency` is not set, it will be updated to this value. 48 Currency *string `form:"currency"` 49 // An arbitrary string attached to the object. Often useful for displaying to users. 50 Description *string `form:"description"` 51 // Specifies which fields in the response should be expanded. 52 Expand []*string `form:"expand"` 53 // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`. 54 Metadata map[string]string `form:"metadata"` 55 } 56 57 // AddExpand appends a new field to expand. 58 func (p *CustomerBalanceTransactionParams) AddExpand(f string) { 59 p.Expand = append(p.Expand, &f) 60 } 61 62 // AddMetadata adds a new key-value pair to the Metadata. 63 func (p *CustomerBalanceTransactionParams) AddMetadata(key string, value string) { 64 if p.Metadata == nil { 65 p.Metadata = make(map[string]string) 66 } 67 68 p.Metadata[key] = value 69 } 70 71 // Each customer has a [Balance](https://stripe.com/docs/api/customers/object#customer_object-balance) value, 72 // which denotes a debit or credit that's automatically applied to their next invoice upon finalization. 73 // You may modify the value directly by using the [update customer API](https://stripe.com/docs/api/customers/update), 74 // or by creating a Customer Balance Transaction, which increments or decrements the customer's `balance` by the specified `amount`. 75 // 76 // Related guide: [Customer balance](https://stripe.com/docs/billing/customer/balance) 77 type CustomerBalanceTransaction struct { 78 APIResource 79 // The amount of the transaction. A negative value is a credit for the customer's balance, and a positive value is a debit to the customer's `balance`. 80 Amount int64 `json:"amount"` 81 // Time at which the object was created. Measured in seconds since the Unix epoch. 82 Created int64 `json:"created"` 83 // The ID of the credit note (if any) related to the transaction. 84 CreditNote *CreditNote `json:"credit_note"` 85 // 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). 86 Currency Currency `json:"currency"` 87 // The ID of the customer the transaction belongs to. 88 Customer *Customer `json:"customer"` 89 // An arbitrary string attached to the object. Often useful for displaying to users. 90 Description string `json:"description"` 91 // The customer's `balance` after the transaction was applied. A negative value decreases the amount due on the customer's next invoice. A positive value increases the amount due on the customer's next invoice. 92 EndingBalance int64 `json:"ending_balance"` 93 // Unique identifier for the object. 94 ID string `json:"id"` 95 // The ID of the invoice (if any) related to the transaction. 96 Invoice *Invoice `json:"invoice"` 97 // Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode. 98 Livemode bool `json:"livemode"` 99 // Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. 100 Metadata map[string]string `json:"metadata"` 101 // String representing the object's type. Objects of the same type share the same value. 102 Object string `json:"object"` 103 // Transaction type: `adjustment`, `applied_to_invoice`, `credit_note`, `initial`, `invoice_overpaid`, `invoice_too_large`, `invoice_too_small`, `unspent_receiver_credit`, or `unapplied_from_invoice`. See the [Customer Balance page](https://stripe.com/docs/billing/customer/balance#types) to learn more about transaction types. 104 Type CustomerBalanceTransactionType `json:"type"` 105 } 106 107 // CustomerBalanceTransactionList is a list of CustomerBalanceTransactions as retrieved from a list endpoint. 108 type CustomerBalanceTransactionList struct { 109 APIResource 110 ListMeta 111 Data []*CustomerBalanceTransaction `json:"data"` 112 } 113 114 // UnmarshalJSON handles deserialization of a CustomerBalanceTransaction. 115 // This custom unmarshaling is needed because the resulting 116 // property may be an id or the full struct if it was expanded. 117 func (c *CustomerBalanceTransaction) UnmarshalJSON(data []byte) error { 118 if id, ok := ParseID(data); ok { 119 c.ID = id 120 return nil 121 } 122 123 type customerBalanceTransaction CustomerBalanceTransaction 124 var v customerBalanceTransaction 125 if err := json.Unmarshal(data, &v); err != nil { 126 return err 127 } 128 129 *c = CustomerBalanceTransaction(v) 130 return nil 131 }