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

     1  //
     2  //
     3  // File generated from our OpenAPI spec
     4  //
     5  //
     6  
     7  // Package feerefund provides the /application_fees/{id}/refunds APIs
     8  package feerefund
     9  
    10  import (
    11  	"fmt"
    12  	"net/http"
    13  
    14  	stripe "github.com/stripe/stripe-go/v76"
    15  	"github.com/stripe/stripe-go/v76/form"
    16  )
    17  
    18  // Client is used to invoke /application_fees/{id}/refunds APIs.
    19  type Client struct {
    20  	B   stripe.Backend
    21  	Key string
    22  }
    23  
    24  // New creates a new fee refund.
    25  func New(params *stripe.FeeRefundParams) (*stripe.FeeRefund, error) {
    26  	return getC().New(params)
    27  }
    28  
    29  // New creates a new fee refund.
    30  func (c Client) New(params *stripe.FeeRefundParams) (*stripe.FeeRefund, error) {
    31  	if params == nil {
    32  		return nil, fmt.Errorf("params cannot be nil")
    33  	}
    34  	if params.ID == nil {
    35  		return nil, fmt.Errorf("params.ID must be set")
    36  	}
    37  	path := stripe.FormatURLPath(
    38  		"/v1/application_fees/%s/refunds",
    39  		stripe.StringValue(params.ID),
    40  	)
    41  	feerefund := &stripe.FeeRefund{}
    42  	err := c.B.Call(http.MethodPost, path, c.Key, params, feerefund)
    43  	return feerefund, err
    44  }
    45  
    46  // Get returns the details of a fee refund.
    47  func Get(id string, params *stripe.FeeRefundParams) (*stripe.FeeRefund, error) {
    48  	return getC().Get(id, params)
    49  }
    50  
    51  // Get returns the details of a fee refund.
    52  func (c Client) Get(id string, params *stripe.FeeRefundParams) (*stripe.FeeRefund, error) {
    53  	if params == nil {
    54  		return nil, fmt.Errorf("params cannot be nil")
    55  	}
    56  	if params.Fee == nil {
    57  		return nil, fmt.Errorf("params.Fee must be set")
    58  	}
    59  	path := stripe.FormatURLPath(
    60  		"/v1/application_fees/%s/refunds/%s",
    61  		stripe.StringValue(params.Fee),
    62  		id,
    63  	)
    64  	feerefund := &stripe.FeeRefund{}
    65  	err := c.B.Call(http.MethodGet, path, c.Key, params, feerefund)
    66  	return feerefund, err
    67  }
    68  
    69  // Update updates a fee refund's properties.
    70  func Update(id string, params *stripe.FeeRefundParams) (*stripe.FeeRefund, error) {
    71  	return getC().Update(id, params)
    72  }
    73  
    74  // Update updates a fee refund's properties.
    75  func (c Client) Update(id string, params *stripe.FeeRefundParams) (*stripe.FeeRefund, error) {
    76  	if params == nil {
    77  		return nil, fmt.Errorf("params cannot be nil")
    78  	}
    79  	if params.Fee == nil {
    80  		return nil, fmt.Errorf("params.Fee must be set")
    81  	}
    82  	path := stripe.FormatURLPath(
    83  		"/v1/application_fees/%s/refunds/%s",
    84  		stripe.StringValue(params.Fee),
    85  		id,
    86  	)
    87  	feerefund := &stripe.FeeRefund{}
    88  	err := c.B.Call(http.MethodPost, path, c.Key, params, feerefund)
    89  	return feerefund, err
    90  }
    91  
    92  // List returns a list of fee refunds.
    93  func List(params *stripe.FeeRefundListParams) *Iter {
    94  	return getC().List(params)
    95  }
    96  
    97  // List returns a list of fee refunds.
    98  func (c Client) List(listParams *stripe.FeeRefundListParams) *Iter {
    99  	path := stripe.FormatURLPath(
   100  		"/v1/application_fees/%s/refunds",
   101  		stripe.StringValue(listParams.ID),
   102  	)
   103  	return &Iter{
   104  		Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
   105  			list := &stripe.FeeRefundList{}
   106  			err := c.B.CallRaw(http.MethodGet, path, c.Key, b, p, list)
   107  
   108  			ret := make([]interface{}, len(list.Data))
   109  			for i, v := range list.Data {
   110  				ret[i] = v
   111  			}
   112  
   113  			return ret, list, err
   114  		}),
   115  	}
   116  }
   117  
   118  // Iter is an iterator for fee refunds.
   119  type Iter struct {
   120  	*stripe.Iter
   121  }
   122  
   123  // FeeRefund returns the fee refund which the iterator is currently pointing to.
   124  func (i *Iter) FeeRefund() *stripe.FeeRefund {
   125  	return i.Current().(*stripe.FeeRefund)
   126  }
   127  
   128  // FeeRefundList returns the current list object which the iterator is
   129  // currently using. List objects will change as new API calls are made to
   130  // continue pagination.
   131  func (i *Iter) FeeRefundList() *stripe.FeeRefundList {
   132  	return i.List().(*stripe.FeeRefundList)
   133  }
   134  
   135  func getC() Client {
   136  	return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
   137  }