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

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