github.com/stripe/stripe-go/v76@v76.25.0/topup.go (about) 1 // 2 // 3 // File generated from our OpenAPI spec 4 // 5 // 6 7 package stripe 8 9 import "encoding/json" 10 11 // The status of the top-up is either `canceled`, `failed`, `pending`, `reversed`, or `succeeded`. 12 type TopupStatus string 13 14 // List of values that TopupStatus can take 15 const ( 16 TopupStatusCanceled TopupStatus = "canceled" 17 TopupStatusFailed TopupStatus = "failed" 18 TopupStatusPending TopupStatus = "pending" 19 TopupStatusReversed TopupStatus = "reversed" 20 TopupStatusSucceeded TopupStatus = "succeeded" 21 ) 22 23 // Returns a list of top-ups. 24 type TopupListParams struct { 25 ListParams `form:"*"` 26 // A positive integer representing how much to transfer. 27 Amount *int64 `form:"amount"` 28 // A positive integer representing how much to transfer. 29 AmountRange *RangeQueryParams `form:"amount"` 30 // A filter on the list, based on the object `created` field. The value can be a string with an integer Unix timestamp, or it can be a dictionary with a number of different query options. 31 Created *int64 `form:"created"` 32 // A filter on the list, based on the object `created` field. The value can be a string with an integer Unix timestamp, or it can be a dictionary with a number of different query options. 33 CreatedRange *RangeQueryParams `form:"created"` 34 // Specifies which fields in the response should be expanded. 35 Expand []*string `form:"expand"` 36 // Only return top-ups that have the given status. One of `canceled`, `failed`, `pending` or `succeeded`. 37 Status *string `form:"status"` 38 } 39 40 // AddExpand appends a new field to expand. 41 func (p *TopupListParams) AddExpand(f string) { 42 p.Expand = append(p.Expand, &f) 43 } 44 45 // Top up the balance of an account 46 type TopupParams struct { 47 Params `form:"*"` 48 // A positive integer representing how much to transfer. 49 Amount *int64 `form:"amount"` 50 // 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). 51 Currency *string `form:"currency"` 52 // An arbitrary string attached to the object. Often useful for displaying to users. 53 Description *string `form:"description"` 54 // Specifies which fields in the response should be expanded. 55 Expand []*string `form:"expand"` 56 // 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`. 57 Metadata map[string]string `form:"metadata"` 58 // The ID of a source to transfer funds from. For most users, this should be left unspecified which will use the bank account that was set up in the dashboard for the specified currency. In test mode, this can be a test bank token (see [Testing Top-ups](https://stripe.com/docs/connect/testing#testing-top-ups)). 59 Source *string `form:"source"` 60 // Extra information about a top-up for the source's bank statement. Limited to 15 ASCII characters. 61 StatementDescriptor *string `form:"statement_descriptor"` 62 // A string that identifies this top-up as part of a group. 63 TransferGroup *string `form:"transfer_group"` 64 } 65 66 // AddExpand appends a new field to expand. 67 func (p *TopupParams) AddExpand(f string) { 68 p.Expand = append(p.Expand, &f) 69 } 70 71 // AddMetadata adds a new key-value pair to the Metadata. 72 func (p *TopupParams) AddMetadata(key string, value string) { 73 if p.Metadata == nil { 74 p.Metadata = make(map[string]string) 75 } 76 77 p.Metadata[key] = value 78 } 79 80 // To top up your Stripe balance, you create a top-up object. You can retrieve 81 // individual top-ups, as well as list all top-ups. Top-ups are identified by a 82 // unique, random ID. 83 // 84 // Related guide: [Topping up your platform account](https://stripe.com/docs/connect/top-ups) 85 type Topup struct { 86 APIResource 87 // Amount transferred. 88 Amount int64 `json:"amount"` 89 // ID of the balance transaction that describes the impact of this top-up on your account balance. May not be specified depending on status of top-up. 90 BalanceTransaction *BalanceTransaction `json:"balance_transaction"` 91 // Time at which the object was created. Measured in seconds since the Unix epoch. 92 Created int64 `json:"created"` 93 // 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). 94 Currency Currency `json:"currency"` 95 // An arbitrary string attached to the object. Often useful for displaying to users. 96 Description string `json:"description"` 97 // Date the funds are expected to arrive in your Stripe account for payouts. This factors in delays like weekends or bank holidays. May not be specified depending on status of top-up. 98 ExpectedAvailabilityDate int64 `json:"expected_availability_date"` 99 // Error code explaining reason for top-up failure if available (see [the errors section](https://stripe.com/docs/api#errors) for a list of codes). 100 FailureCode string `json:"failure_code"` 101 // Message to user further explaining reason for top-up failure if available. 102 FailureMessage string `json:"failure_message"` 103 // Unique identifier for the object. 104 ID string `json:"id"` 105 // Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode. 106 Livemode bool `json:"livemode"` 107 // 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. 108 Metadata map[string]string `json:"metadata"` 109 // String representing the object's type. Objects of the same type share the same value. 110 Object string `json:"object"` 111 // The source field is deprecated. It might not always be present in the API response. 112 Source *PaymentSource `json:"source"` 113 // Extra information about a top-up. This will appear on your source's bank statement. It must contain at least one letter. 114 StatementDescriptor string `json:"statement_descriptor"` 115 // The status of the top-up is either `canceled`, `failed`, `pending`, `reversed`, or `succeeded`. 116 Status TopupStatus `json:"status"` 117 // A string that identifies this top-up as part of a group. 118 TransferGroup string `json:"transfer_group"` 119 120 // The following property is deprecated 121 ArrivalDate int64 `json:"arrival_date"` 122 } 123 124 // TopupList is a list of Topups as retrieved from a list endpoint. 125 type TopupList struct { 126 APIResource 127 ListMeta 128 Data []*Topup `json:"data"` 129 } 130 131 // UnmarshalJSON handles deserialization of a Topup. 132 // This custom unmarshaling is needed because the resulting 133 // property may be an id or the full struct if it was expanded. 134 func (t *Topup) UnmarshalJSON(data []byte) error { 135 if id, ok := ParseID(data); ok { 136 t.ID = id 137 return nil 138 } 139 140 type topup Topup 141 var v topup 142 if err := json.Unmarshal(data, &v); err != nil { 143 return err 144 } 145 146 *t = Topup(v) 147 return nil 148 }