github.com/stripe/stripe-go/v76@v76.25.0/refund.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 type of refund. This can be `refund`, `reversal`, or `pending`. 12 type RefundDestinationDetailsCardType string 13 14 // List of values that RefundDestinationDetailsCardType can take 15 const ( 16 RefundDestinationDetailsCardTypePending RefundDestinationDetailsCardType = "pending" 17 RefundDestinationDetailsCardTypeRefund RefundDestinationDetailsCardType = "refund" 18 RefundDestinationDetailsCardTypeReversal RefundDestinationDetailsCardType = "reversal" 19 ) 20 21 // Provides the reason for the refund failure. Possible values are: `lost_or_stolen_card`, `expired_or_canceled_card`, `charge_for_pending_refund_disputed`, `insufficient_funds`, `declined`, `merchant_request`, or `unknown`. 22 type RefundFailureReason string 23 24 // List of values that RefundFailureReason can take 25 const ( 26 RefundFailureReasonExpiredOrCanceledCard RefundFailureReason = "expired_or_canceled_card" 27 RefundFailureReasonLostOrStolenCard RefundFailureReason = "lost_or_stolen_card" 28 RefundFailureReasonUnknown RefundFailureReason = "unknown" 29 ) 30 31 // Reason for the refund, which is either user-provided (`duplicate`, `fraudulent`, or `requested_by_customer`) or generated by Stripe internally (`expired_uncaptured_charge`). 32 type RefundReason string 33 34 // List of values that RefundReason can take 35 const ( 36 RefundReasonDuplicate RefundReason = "duplicate" 37 RefundReasonExpiredUncapturedCharge RefundReason = "expired_uncaptured_charge" 38 RefundReasonFraudulent RefundReason = "fraudulent" 39 RefundReasonRequestedByCustomer RefundReason = "requested_by_customer" 40 ) 41 42 // Status of the refund. This can be `pending`, `requires_action`, `succeeded`, `failed`, or `canceled`. Learn more about [failed refunds](https://stripe.com/docs/refunds#failed-refunds). 43 type RefundStatus string 44 45 // List of values that RefundStatus can take 46 const ( 47 RefundStatusCanceled RefundStatus = "canceled" 48 RefundStatusFailed RefundStatus = "failed" 49 RefundStatusPending RefundStatus = "pending" 50 RefundStatusSucceeded RefundStatus = "succeeded" 51 RefundStatusRequiresAction RefundStatus = "requires_action" 52 ) 53 54 // Returns a list of all refunds you created. We return the refunds in sorted order, with the most recent refunds appearing first The 10 most recent refunds are always available by default on the Charge object. 55 type RefundListParams struct { 56 ListParams `form:"*"` 57 // Only return refunds for the charge specified by this charge ID. 58 Charge *string `form:"charge"` 59 // Only return refunds that were created during the given date interval. 60 Created *int64 `form:"created"` 61 // Only return refunds that were created during the given date interval. 62 CreatedRange *RangeQueryParams `form:"created"` 63 // Specifies which fields in the response should be expanded. 64 Expand []*string `form:"expand"` 65 // Only return refunds for the PaymentIntent specified by this ID. 66 PaymentIntent *string `form:"payment_intent"` 67 } 68 69 // AddExpand appends a new field to expand. 70 func (p *RefundListParams) AddExpand(f string) { 71 p.Expand = append(p.Expand, &f) 72 } 73 74 // When you create a new refund, you must specify a Charge or a PaymentIntent object on which to create it. 75 // 76 // Creating a new refund will refund a charge that has previously been created but not yet refunded. 77 // Funds will be refunded to the credit or debit card that was originally charged. 78 // 79 // You can optionally refund only part of a charge. 80 // You can do so multiple times, until the entire charge has been refunded. 81 // 82 // Once entirely refunded, a charge can't be refunded again. 83 // This method will raise an error when called on an already-refunded charge, 84 // or when trying to refund more money than is left on a charge. 85 type RefundParams struct { 86 Params `form:"*"` 87 Amount *int64 `form:"amount"` 88 // The identifier of the charge to refund. 89 Charge *string `form:"charge"` 90 // 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). 91 Currency *string `form:"currency"` 92 // Customer whose customer balance to refund from. 93 Customer *string `form:"customer"` 94 // Specifies which fields in the response should be expanded. 95 Expand []*string `form:"expand"` 96 // For payment methods without native refund support (e.g., Konbini, PromptPay), use this email from the customer to receive refund instructions. 97 InstructionsEmail *string `form:"instructions_email"` 98 // 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`. 99 Metadata map[string]string `form:"metadata"` 100 // Origin of the refund 101 Origin *string `form:"origin"` 102 // The identifier of the PaymentIntent to refund. 103 PaymentIntent *string `form:"payment_intent"` 104 // String indicating the reason for the refund. If set, possible values are `duplicate`, `fraudulent`, and `requested_by_customer`. If you believe the charge to be fraudulent, specifying `fraudulent` as the reason will add the associated card and email to your [block lists](https://stripe.com/docs/radar/lists), and will also help us improve our fraud detection algorithms. 105 Reason *string `form:"reason"` 106 // Boolean indicating whether the application fee should be refunded when refunding this charge. If a full charge refund is given, the full application fee will be refunded. Otherwise, the application fee will be refunded in an amount proportional to the amount of the charge refunded. An application fee can be refunded only by the application that created the charge. 107 RefundApplicationFee *bool `form:"refund_application_fee"` 108 // Boolean indicating whether the transfer should be reversed when refunding this charge. The transfer will be reversed proportionally to the amount being refunded (either the entire or partial amount). 109 // 110 // A transfer can be reversed only by the application that created the charge. 111 ReverseTransfer *bool `form:"reverse_transfer"` 112 } 113 114 // AddExpand appends a new field to expand. 115 func (p *RefundParams) AddExpand(f string) { 116 p.Expand = append(p.Expand, &f) 117 } 118 119 // AddMetadata adds a new key-value pair to the Metadata. 120 func (p *RefundParams) AddMetadata(key string, value string) { 121 if p.Metadata == nil { 122 p.Metadata = make(map[string]string) 123 } 124 125 p.Metadata[key] = value 126 } 127 128 // Cancels a refund with a status of requires_action. 129 // 130 // You can't cancel refunds in other states. Only refunds for payment methods that require customer action can enter the requires_action state. 131 type RefundCancelParams struct { 132 Params `form:"*"` 133 // Specifies which fields in the response should be expanded. 134 Expand []*string `form:"expand"` 135 } 136 137 // AddExpand appends a new field to expand. 138 func (p *RefundCancelParams) AddExpand(f string) { 139 p.Expand = append(p.Expand, &f) 140 } 141 142 type RefundDestinationDetailsAffirm struct{} 143 type RefundDestinationDetailsAfterpayClearpay struct{} 144 type RefundDestinationDetailsAlipay struct{} 145 type RefundDestinationDetailsAuBankTransfer struct{} 146 type RefundDestinationDetailsBLIK struct { 147 // The reference assigned to the refund. 148 Reference string `json:"reference"` 149 // Status of the reference on the refund. This can be `pending`, `available` or `unavailable`. 150 ReferenceStatus string `json:"reference_status"` 151 } 152 type RefundDestinationDetailsBrBankTransfer struct { 153 // The reference assigned to the refund. 154 Reference string `json:"reference"` 155 // Status of the reference on the refund. This can be `pending`, `available` or `unavailable`. 156 ReferenceStatus string `json:"reference_status"` 157 } 158 type RefundDestinationDetailsCard struct { 159 // Value of the reference number assigned to the refund. 160 Reference string `json:"reference"` 161 // Status of the reference number on the refund. This can be `pending`, `available` or `unavailable`. 162 ReferenceStatus string `json:"reference_status"` 163 // Type of the reference number assigned to the refund. 164 ReferenceType string `json:"reference_type"` 165 // The type of refund. This can be `refund`, `reversal`, or `pending`. 166 Type RefundDestinationDetailsCardType `json:"type"` 167 } 168 type RefundDestinationDetailsCashApp struct{} 169 type RefundDestinationDetailsCustomerCashBalance struct{} 170 type RefundDestinationDetailsEPS struct{} 171 type RefundDestinationDetailsEUBankTransfer struct { 172 // The reference assigned to the refund. 173 Reference string `json:"reference"` 174 // Status of the reference on the refund. This can be `pending`, `available` or `unavailable`. 175 ReferenceStatus string `json:"reference_status"` 176 } 177 type RefundDestinationDetailsGBBankTransfer struct { 178 // The reference assigned to the refund. 179 Reference string `json:"reference"` 180 // Status of the reference on the refund. This can be `pending`, `available` or `unavailable`. 181 ReferenceStatus string `json:"reference_status"` 182 } 183 type RefundDestinationDetailsGiropay struct{} 184 type RefundDestinationDetailsGrabpay struct{} 185 type RefundDestinationDetailsJPBankTransfer struct { 186 // The reference assigned to the refund. 187 Reference string `json:"reference"` 188 // Status of the reference on the refund. This can be `pending`, `available` or `unavailable`. 189 ReferenceStatus string `json:"reference_status"` 190 } 191 type RefundDestinationDetailsKlarna struct{} 192 type RefundDestinationDetailsMXBankTransfer struct { 193 // The reference assigned to the refund. 194 Reference string `json:"reference"` 195 // Status of the reference on the refund. This can be `pending`, `available` or `unavailable`. 196 ReferenceStatus string `json:"reference_status"` 197 } 198 type RefundDestinationDetailsP24 struct { 199 // The reference assigned to the refund. 200 Reference string `json:"reference"` 201 // Status of the reference on the refund. This can be `pending`, `available` or `unavailable`. 202 ReferenceStatus string `json:"reference_status"` 203 } 204 type RefundDestinationDetailsPayNow struct{} 205 type RefundDestinationDetailsPaypal struct{} 206 type RefundDestinationDetailsPix struct{} 207 type RefundDestinationDetailsRevolut struct{} 208 type RefundDestinationDetailsSofort struct{} 209 type RefundDestinationDetailsSwish struct { 210 // The reference assigned to the refund. 211 Reference string `json:"reference"` 212 // Status of the reference on the refund. This can be `pending`, `available` or `unavailable`. 213 ReferenceStatus string `json:"reference_status"` 214 } 215 type RefundDestinationDetailsTHBankTransfer struct { 216 // The reference assigned to the refund. 217 Reference string `json:"reference"` 218 // Status of the reference on the refund. This can be `pending`, `available` or `unavailable`. 219 ReferenceStatus string `json:"reference_status"` 220 } 221 type RefundDestinationDetailsUSBankTransfer struct { 222 // The reference assigned to the refund. 223 Reference string `json:"reference"` 224 // Status of the reference on the refund. This can be `pending`, `available` or `unavailable`. 225 ReferenceStatus string `json:"reference_status"` 226 } 227 type RefundDestinationDetailsWeChatPay struct{} 228 type RefundDestinationDetailsZip struct{} 229 type RefundDestinationDetails struct { 230 Affirm *RefundDestinationDetailsAffirm `json:"affirm"` 231 AfterpayClearpay *RefundDestinationDetailsAfterpayClearpay `json:"afterpay_clearpay"` 232 Alipay *RefundDestinationDetailsAlipay `json:"alipay"` 233 AuBankTransfer *RefundDestinationDetailsAuBankTransfer `json:"au_bank_transfer"` 234 BLIK *RefundDestinationDetailsBLIK `json:"blik"` 235 BrBankTransfer *RefundDestinationDetailsBrBankTransfer `json:"br_bank_transfer"` 236 Card *RefundDestinationDetailsCard `json:"card"` 237 CashApp *RefundDestinationDetailsCashApp `json:"cashapp"` 238 CustomerCashBalance *RefundDestinationDetailsCustomerCashBalance `json:"customer_cash_balance"` 239 EPS *RefundDestinationDetailsEPS `json:"eps"` 240 EUBankTransfer *RefundDestinationDetailsEUBankTransfer `json:"eu_bank_transfer"` 241 GBBankTransfer *RefundDestinationDetailsGBBankTransfer `json:"gb_bank_transfer"` 242 Giropay *RefundDestinationDetailsGiropay `json:"giropay"` 243 Grabpay *RefundDestinationDetailsGrabpay `json:"grabpay"` 244 JPBankTransfer *RefundDestinationDetailsJPBankTransfer `json:"jp_bank_transfer"` 245 Klarna *RefundDestinationDetailsKlarna `json:"klarna"` 246 MXBankTransfer *RefundDestinationDetailsMXBankTransfer `json:"mx_bank_transfer"` 247 P24 *RefundDestinationDetailsP24 `json:"p24"` 248 PayNow *RefundDestinationDetailsPayNow `json:"paynow"` 249 Paypal *RefundDestinationDetailsPaypal `json:"paypal"` 250 Pix *RefundDestinationDetailsPix `json:"pix"` 251 Revolut *RefundDestinationDetailsRevolut `json:"revolut"` 252 Sofort *RefundDestinationDetailsSofort `json:"sofort"` 253 Swish *RefundDestinationDetailsSwish `json:"swish"` 254 THBankTransfer *RefundDestinationDetailsTHBankTransfer `json:"th_bank_transfer"` 255 // The type of transaction-specific details of the payment method used in the refund (e.g., `card`). An additional hash is included on `destination_details` with a name matching this value. It contains information specific to the refund transaction. 256 Type string `json:"type"` 257 USBankTransfer *RefundDestinationDetailsUSBankTransfer `json:"us_bank_transfer"` 258 WeChatPay *RefundDestinationDetailsWeChatPay `json:"wechat_pay"` 259 Zip *RefundDestinationDetailsZip `json:"zip"` 260 } 261 type RefundNextActionDisplayDetailsEmailSent struct { 262 // The timestamp when the email was sent. 263 EmailSentAt int64 `json:"email_sent_at"` 264 // The recipient's email address. 265 EmailSentTo string `json:"email_sent_to"` 266 } 267 268 // Contains the refund details. 269 type RefundNextActionDisplayDetails struct { 270 EmailSent *RefundNextActionDisplayDetailsEmailSent `json:"email_sent"` 271 // The expiry timestamp. 272 ExpiresAt int64 `json:"expires_at"` 273 } 274 type RefundNextAction struct { 275 // Contains the refund details. 276 DisplayDetails *RefundNextActionDisplayDetails `json:"display_details"` 277 // Type of the next action to perform. 278 Type string `json:"type"` 279 } 280 281 // Refund objects allow you to refund a previously created charge that isn't 282 // refunded yet. Funds are refunded to the credit or debit card that's 283 // initially charged. 284 // 285 // Related guide: [Refunds](https://stripe.com/docs/refunds) 286 type Refund struct { 287 APIResource 288 // Amount, in cents (or local equivalent). 289 Amount int64 `json:"amount"` 290 // Balance transaction that describes the impact on your account balance. 291 BalanceTransaction *BalanceTransaction `json:"balance_transaction"` 292 // ID of the charge that's refunded. 293 Charge *Charge `json:"charge"` 294 // Time at which the object was created. Measured in seconds since the Unix epoch. 295 Created int64 `json:"created"` 296 // 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). 297 Currency Currency `json:"currency"` 298 // An arbitrary string attached to the object. You can use this for displaying to users (available on non-card refunds only). 299 Description string `json:"description"` 300 DestinationDetails *RefundDestinationDetails `json:"destination_details"` 301 // After the refund fails, this balance transaction describes the adjustment made on your account balance that reverses the initial balance transaction. 302 FailureBalanceTransaction *BalanceTransaction `json:"failure_balance_transaction"` 303 // Provides the reason for the refund failure. Possible values are: `lost_or_stolen_card`, `expired_or_canceled_card`, `charge_for_pending_refund_disputed`, `insufficient_funds`, `declined`, `merchant_request`, or `unknown`. 304 FailureReason RefundFailureReason `json:"failure_reason"` 305 // Unique identifier for the object. 306 ID string `json:"id"` 307 // For payment methods without native refund support (for example, Konbini, PromptPay), provide an email address for the customer to receive refund instructions. 308 InstructionsEmail string `json:"instructions_email"` 309 // 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. 310 Metadata map[string]string `json:"metadata"` 311 NextAction *RefundNextAction `json:"next_action"` 312 // String representing the object's type. Objects of the same type share the same value. 313 Object string `json:"object"` 314 // ID of the PaymentIntent that's refunded. 315 PaymentIntent *PaymentIntent `json:"payment_intent"` 316 // Reason for the refund, which is either user-provided (`duplicate`, `fraudulent`, or `requested_by_customer`) or generated by Stripe internally (`expired_uncaptured_charge`). 317 Reason RefundReason `json:"reason"` 318 // This is the transaction number that appears on email receipts sent for this refund. 319 ReceiptNumber string `json:"receipt_number"` 320 // The transfer reversal that's associated with the refund. Only present if the charge came from another Stripe account. 321 SourceTransferReversal *TransferReversal `json:"source_transfer_reversal"` 322 // Status of the refund. This can be `pending`, `requires_action`, `succeeded`, `failed`, or `canceled`. Learn more about [failed refunds](https://stripe.com/docs/refunds#failed-refunds). 323 Status RefundStatus `json:"status"` 324 // This refers to the transfer reversal object if the accompanying transfer reverses. This is only applicable if the charge was created using the destination parameter. 325 TransferReversal *TransferReversal `json:"transfer_reversal"` 326 } 327 328 // RefundList is a list of Refunds as retrieved from a list endpoint. 329 type RefundList struct { 330 APIResource 331 ListMeta 332 Data []*Refund `json:"data"` 333 } 334 335 // UnmarshalJSON handles deserialization of a Refund. 336 // This custom unmarshaling is needed because the resulting 337 // property may be an id or the full struct if it was expanded. 338 func (r *Refund) UnmarshalJSON(data []byte) error { 339 if id, ok := ParseID(data); ok { 340 r.ID = id 341 return nil 342 } 343 344 type refund Refund 345 var v refund 346 if err := json.Unmarshal(data, &v); err != nil { 347 return err 348 } 349 350 *r = Refund(v) 351 return nil 352 }