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

     1  //
     2  //
     3  // File generated from our OpenAPI spec
     4  //
     5  //
     6  
     7  // Package transfer provides the /transfers APIs
     8  package transfer
     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 /transfers APIs.
    18  type Client struct {
    19  	B   stripe.Backend
    20  	Key string
    21  }
    22  
    23  // New creates a new transfer.
    24  func New(params *stripe.TransferParams) (*stripe.Transfer, error) {
    25  	return getC().New(params)
    26  }
    27  
    28  // New creates a new transfer.
    29  func (c Client) New(params *stripe.TransferParams) (*stripe.Transfer, error) {
    30  	transfer := &stripe.Transfer{}
    31  	err := c.B.Call(http.MethodPost, "/v1/transfers", c.Key, params, transfer)
    32  	return transfer, err
    33  }
    34  
    35  // Get returns the details of a transfer.
    36  func Get(id string, params *stripe.TransferParams) (*stripe.Transfer, error) {
    37  	return getC().Get(id, params)
    38  }
    39  
    40  // Get returns the details of a transfer.
    41  func (c Client) Get(id string, params *stripe.TransferParams) (*stripe.Transfer, error) {
    42  	path := stripe.FormatURLPath("/v1/transfers/%s", id)
    43  	transfer := &stripe.Transfer{}
    44  	err := c.B.Call(http.MethodGet, path, c.Key, params, transfer)
    45  	return transfer, err
    46  }
    47  
    48  // Update updates a transfer's properties.
    49  func Update(id string, params *stripe.TransferParams) (*stripe.Transfer, error) {
    50  	return getC().Update(id, params)
    51  }
    52  
    53  // Update updates a transfer's properties.
    54  func (c Client) Update(id string, params *stripe.TransferParams) (*stripe.Transfer, error) {
    55  	path := stripe.FormatURLPath("/v1/transfers/%s", id)
    56  	transfer := &stripe.Transfer{}
    57  	err := c.B.Call(http.MethodPost, path, c.Key, params, transfer)
    58  	return transfer, err
    59  }
    60  
    61  // List returns a list of transfers.
    62  func List(params *stripe.TransferListParams) *Iter {
    63  	return getC().List(params)
    64  }
    65  
    66  // List returns a list of transfers.
    67  func (c Client) List(listParams *stripe.TransferListParams) *Iter {
    68  	return &Iter{
    69  		Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
    70  			list := &stripe.TransferList{}
    71  			err := c.B.CallRaw(http.MethodGet, "/v1/transfers", c.Key, b, p, list)
    72  
    73  			ret := make([]interface{}, len(list.Data))
    74  			for i, v := range list.Data {
    75  				ret[i] = v
    76  			}
    77  
    78  			return ret, list, err
    79  		}),
    80  	}
    81  }
    82  
    83  // Iter is an iterator for transfers.
    84  type Iter struct {
    85  	*stripe.Iter
    86  }
    87  
    88  // Transfer returns the transfer which the iterator is currently pointing to.
    89  func (i *Iter) Transfer() *stripe.Transfer {
    90  	return i.Current().(*stripe.Transfer)
    91  }
    92  
    93  // TransferList returns the current list object which the iterator is
    94  // currently using. List objects will change as new API calls are made to
    95  // continue pagination.
    96  func (i *Iter) TransferList() *stripe.TransferList {
    97  	return i.List().(*stripe.TransferList)
    98  }
    99  
   100  func getC() Client {
   101  	return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
   102  }