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

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