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

     1  //
     2  //
     3  // File generated from our OpenAPI spec
     4  //
     5  //
     6  
     7  package stripe
     8  
     9  import "encoding/json"
    10  
    11  // You can see a list of the reversals belonging to a specific transfer. Note that the 10 most recent reversals are always available by default on the transfer object. If you need more than those 10, you can use this API method and the limit and starting_after parameters to page through additional reversals.
    12  type TransferReversalListParams struct {
    13  	ListParams `form:"*"`
    14  	ID         *string `form:"-"` // Included in URL
    15  	// Specifies which fields in the response should be expanded.
    16  	Expand []*string `form:"expand"`
    17  }
    18  
    19  // AddExpand appends a new field to expand.
    20  func (p *TransferReversalListParams) AddExpand(f string) {
    21  	p.Expand = append(p.Expand, &f)
    22  }
    23  
    24  // When you create a new reversal, you must specify a transfer to create it on.
    25  //
    26  // When reversing transfers, you can optionally reverse part of the transfer. You can do so as many times as you wish until the entire transfer has been reversed.
    27  //
    28  // Once entirely reversed, a transfer can't be reversed again. This method will return an error when called on an already-reversed transfer, or when trying to reverse more money than is left on a transfer.
    29  type TransferReversalParams struct {
    30  	Params `form:"*"`
    31  	ID     *string `form:"-"` // Included in URL
    32  	// A positive integer in cents (or local equivalent) representing how much of this transfer to reverse. Can only reverse up to the unreversed amount remaining of the transfer. Partial transfer reversals are only allowed for transfers to Stripe Accounts. Defaults to the entire transfer amount.
    33  	Amount *int64 `form:"amount"`
    34  	// An arbitrary string which you can attach to a reversal object. It is displayed alongside the reversal in the Dashboard. This will be unset if you POST an empty value.
    35  	Description *string `form:"description"`
    36  	// Specifies which fields in the response should be expanded.
    37  	Expand []*string `form:"expand"`
    38  	// 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`.
    39  	Metadata map[string]string `form:"metadata"`
    40  	// Boolean indicating whether the application fee should be refunded when reversing this transfer. If a full transfer reversal is given, the full application fee will be refunded. Otherwise, the application fee will be refunded with an amount proportional to the amount of the transfer reversed.
    41  	RefundApplicationFee *bool `form:"refund_application_fee"`
    42  }
    43  
    44  // AddExpand appends a new field to expand.
    45  func (p *TransferReversalParams) AddExpand(f string) {
    46  	p.Expand = append(p.Expand, &f)
    47  }
    48  
    49  // AddMetadata adds a new key-value pair to the Metadata.
    50  func (p *TransferReversalParams) AddMetadata(key string, value string) {
    51  	if p.Metadata == nil {
    52  		p.Metadata = make(map[string]string)
    53  	}
    54  
    55  	p.Metadata[key] = value
    56  }
    57  
    58  // [Stripe Connect](https://stripe.com/docs/connect) platforms can reverse transfers made to a
    59  // connected account, either entirely or partially, and can also specify whether
    60  // to refund any related application fees. Transfer reversals add to the
    61  // platform's balance and subtract from the destination account's balance.
    62  //
    63  // Reversing a transfer that was made for a [destination
    64  // charge](https://stripe.com/docs/connect/destination-charges) is allowed only up to the amount of
    65  // the charge. It is possible to reverse a
    66  // [transfer_group](https://stripe.com/docs/connect/separate-charges-and-transfers#transfer-options)
    67  // transfer only if the destination account has enough balance to cover the
    68  // reversal.
    69  //
    70  // Related guide: [Reversing transfers](https://stripe.com/docs/connect/separate-charges-and-transfers#reversing-transfers)
    71  type TransferReversal struct {
    72  	APIResource
    73  	// Amount, in cents (or local equivalent).
    74  	Amount int64 `json:"amount"`
    75  	// Balance transaction that describes the impact on your account balance.
    76  	BalanceTransaction *BalanceTransaction `json:"balance_transaction"`
    77  	// Time at which the object was created. Measured in seconds since the Unix epoch.
    78  	Created int64 `json:"created"`
    79  	// 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).
    80  	Currency Currency `json:"currency"`
    81  	// Linked payment refund for the transfer reversal.
    82  	DestinationPaymentRefund *Refund `json:"destination_payment_refund"`
    83  	// Unique identifier for the object.
    84  	ID string `json:"id"`
    85  	// 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.
    86  	Metadata map[string]string `json:"metadata"`
    87  	// String representing the object's type. Objects of the same type share the same value.
    88  	Object string `json:"object"`
    89  	// ID of the refund responsible for the transfer reversal.
    90  	SourceRefund *Refund `json:"source_refund"`
    91  	// ID of the transfer that was reversed.
    92  	Transfer *Transfer `json:"transfer"`
    93  }
    94  
    95  // TransferReversalList is a list of TransferReversals as retrieved from a list endpoint.
    96  type TransferReversalList struct {
    97  	APIResource
    98  	ListMeta
    99  	Data []*TransferReversal `json:"data"`
   100  }
   101  
   102  // UnmarshalJSON handles deserialization of a TransferReversal.
   103  // This custom unmarshaling is needed because the resulting
   104  // property may be an id or the full struct if it was expanded.
   105  func (t *TransferReversal) UnmarshalJSON(data []byte) error {
   106  	if id, ok := ParseID(data); ok {
   107  		t.ID = id
   108  		return nil
   109  	}
   110  
   111  	type transferReversal TransferReversal
   112  	var v transferReversal
   113  	if err := json.Unmarshal(data, &v); err != nil {
   114  		return err
   115  	}
   116  
   117  	*t = TransferReversal(v)
   118  	return nil
   119  }