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

     1  //
     2  //
     3  // File generated from our OpenAPI spec
     4  //
     5  //
     6  
     7  // Package receivedcredit provides the /treasury/received_credits APIs
     8  package receivedcredit
     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 /treasury/received_credits APIs.
    18  type Client struct {
    19  	B   stripe.Backend
    20  	Key string
    21  }
    22  
    23  // Get returns the details of a treasury received credit.
    24  func Get(id string, params *stripe.TreasuryReceivedCreditParams) (*stripe.TreasuryReceivedCredit, error) {
    25  	return getC().Get(id, params)
    26  }
    27  
    28  // Get returns the details of a treasury received credit.
    29  func (c Client) Get(id string, params *stripe.TreasuryReceivedCreditParams) (*stripe.TreasuryReceivedCredit, error) {
    30  	path := stripe.FormatURLPath("/v1/treasury/received_credits/%s", id)
    31  	receivedcredit := &stripe.TreasuryReceivedCredit{}
    32  	err := c.B.Call(http.MethodGet, path, c.Key, params, receivedcredit)
    33  	return receivedcredit, err
    34  }
    35  
    36  // List returns a list of treasury received credits.
    37  func List(params *stripe.TreasuryReceivedCreditListParams) *Iter {
    38  	return getC().List(params)
    39  }
    40  
    41  // List returns a list of treasury received credits.
    42  func (c Client) List(listParams *stripe.TreasuryReceivedCreditListParams) *Iter {
    43  	return &Iter{
    44  		Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
    45  			list := &stripe.TreasuryReceivedCreditList{}
    46  			err := c.B.CallRaw(http.MethodGet, "/v1/treasury/received_credits", c.Key, b, p, list)
    47  
    48  			ret := make([]interface{}, len(list.Data))
    49  			for i, v := range list.Data {
    50  				ret[i] = v
    51  			}
    52  
    53  			return ret, list, err
    54  		}),
    55  	}
    56  }
    57  
    58  // Iter is an iterator for treasury received credits.
    59  type Iter struct {
    60  	*stripe.Iter
    61  }
    62  
    63  // TreasuryReceivedCredit returns the treasury received credit which the iterator is currently pointing to.
    64  func (i *Iter) TreasuryReceivedCredit() *stripe.TreasuryReceivedCredit {
    65  	return i.Current().(*stripe.TreasuryReceivedCredit)
    66  }
    67  
    68  // TreasuryReceivedCreditList returns the current list object which the iterator is
    69  // currently using. List objects will change as new API calls are made to
    70  // continue pagination.
    71  func (i *Iter) TreasuryReceivedCreditList() *stripe.TreasuryReceivedCreditList {
    72  	return i.List().(*stripe.TreasuryReceivedCreditList)
    73  }
    74  
    75  func getC() Client {
    76  	return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
    77  }