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

     1  //
     2  //
     3  // File generated from our OpenAPI spec
     4  //
     5  //
     6  
     7  // Package account provides the /accounts APIs
     8  package account
     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 /accounts APIs.
    18  type Client struct {
    19  	B   stripe.Backend
    20  	Key string
    21  }
    22  
    23  // New creates a new account.
    24  func New(params *stripe.AccountParams) (*stripe.Account, error) {
    25  	return getC().New(params)
    26  }
    27  
    28  // New creates a new account.
    29  func (c Client) New(params *stripe.AccountParams) (*stripe.Account, error) {
    30  	account := &stripe.Account{}
    31  	err := c.B.Call(http.MethodPost, "/v1/accounts", c.Key, params, account)
    32  	return account, err
    33  }
    34  
    35  // Get retrieves the authenticating account.
    36  func Get() (*stripe.Account, error) {
    37  	return getC().Get()
    38  }
    39  
    40  // Get retrieves the authenticating account.
    41  func (c Client) Get() (*stripe.Account, error) {
    42  	account := &stripe.Account{}
    43  	err := c.B.Call(http.MethodGet, "/v1/account", c.Key, nil, account)
    44  	return account, err
    45  }
    46  
    47  // GetByID returns the details of an account.
    48  func GetByID(id string, params *stripe.AccountParams) (*stripe.Account, error) {
    49  	return getC().GetByID(id, params)
    50  }
    51  
    52  // GetByID returns the details of an account.
    53  func (c Client) GetByID(id string, params *stripe.AccountParams) (*stripe.Account, error) {
    54  	path := stripe.FormatURLPath("/v1/accounts/%s", id)
    55  	account := &stripe.Account{}
    56  	err := c.B.Call(http.MethodGet, path, c.Key, params, account)
    57  	return account, err
    58  }
    59  
    60  // Update updates an account's properties.
    61  func Update(id string, params *stripe.AccountParams) (*stripe.Account, error) {
    62  	return getC().Update(id, params)
    63  }
    64  
    65  // Update updates an account's properties.
    66  func (c Client) Update(id string, params *stripe.AccountParams) (*stripe.Account, error) {
    67  	path := stripe.FormatURLPath("/v1/accounts/%s", id)
    68  	account := &stripe.Account{}
    69  	err := c.B.Call(http.MethodPost, path, c.Key, params, account)
    70  	return account, err
    71  }
    72  
    73  // Del removes an account.
    74  func Del(id string, params *stripe.AccountParams) (*stripe.Account, error) {
    75  	return getC().Del(id, params)
    76  }
    77  
    78  // Del removes an account.
    79  func (c Client) Del(id string, params *stripe.AccountParams) (*stripe.Account, error) {
    80  	path := stripe.FormatURLPath("/v1/accounts/%s", id)
    81  	account := &stripe.Account{}
    82  	err := c.B.Call(http.MethodDelete, path, c.Key, params, account)
    83  	return account, err
    84  }
    85  
    86  // Reject is the method for the `POST /v1/accounts/{account}/reject` API.
    87  func Reject(id string, params *stripe.AccountRejectParams) (*stripe.Account, error) {
    88  	return getC().Reject(id, params)
    89  }
    90  
    91  // Reject is the method for the `POST /v1/accounts/{account}/reject` API.
    92  func (c Client) Reject(id string, params *stripe.AccountRejectParams) (*stripe.Account, error) {
    93  	path := stripe.FormatURLPath("/v1/accounts/%s/reject", id)
    94  	account := &stripe.Account{}
    95  	err := c.B.Call(http.MethodPost, path, c.Key, params, account)
    96  	return account, err
    97  }
    98  
    99  // List returns a list of accounts.
   100  func List(params *stripe.AccountListParams) *Iter {
   101  	return getC().List(params)
   102  }
   103  
   104  // List returns a list of accounts.
   105  func (c Client) List(listParams *stripe.AccountListParams) *Iter {
   106  	return &Iter{
   107  		Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
   108  			list := &stripe.AccountList{}
   109  			err := c.B.CallRaw(http.MethodGet, "/v1/accounts", c.Key, b, p, list)
   110  
   111  			ret := make([]interface{}, len(list.Data))
   112  			for i, v := range list.Data {
   113  				ret[i] = v
   114  			}
   115  
   116  			return ret, list, err
   117  		}),
   118  	}
   119  }
   120  
   121  // Iter is an iterator for accounts.
   122  type Iter struct {
   123  	*stripe.Iter
   124  }
   125  
   126  // Account returns the account which the iterator is currently pointing to.
   127  func (i *Iter) Account() *stripe.Account {
   128  	return i.Current().(*stripe.Account)
   129  }
   130  
   131  // AccountList returns the current list object which the iterator is
   132  // currently using. List objects will change as new API calls are made to
   133  // continue pagination.
   134  func (i *Iter) AccountList() *stripe.AccountList {
   135  	return i.List().(*stripe.AccountList)
   136  }
   137  
   138  func getC() Client {
   139  	return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
   140  }