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

     1  //
     2  //
     3  // File generated from our OpenAPI spec
     4  //
     5  //
     6  
     7  // Package creditnote provides the /credit_notes APIs
     8  package creditnote
     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 /credit_notes APIs.
    18  type Client struct {
    19  	B   stripe.Backend
    20  	Key string
    21  }
    22  
    23  // New creates a new credit note.
    24  func New(params *stripe.CreditNoteParams) (*stripe.CreditNote, error) {
    25  	return getC().New(params)
    26  }
    27  
    28  // New creates a new credit note.
    29  func (c Client) New(params *stripe.CreditNoteParams) (*stripe.CreditNote, error) {
    30  	creditnote := &stripe.CreditNote{}
    31  	err := c.B.Call(
    32  		http.MethodPost,
    33  		"/v1/credit_notes",
    34  		c.Key,
    35  		params,
    36  		creditnote,
    37  	)
    38  	return creditnote, err
    39  }
    40  
    41  // Get returns the details of a credit note.
    42  func Get(id string, params *stripe.CreditNoteParams) (*stripe.CreditNote, error) {
    43  	return getC().Get(id, params)
    44  }
    45  
    46  // Get returns the details of a credit note.
    47  func (c Client) Get(id string, params *stripe.CreditNoteParams) (*stripe.CreditNote, error) {
    48  	path := stripe.FormatURLPath("/v1/credit_notes/%s", id)
    49  	creditnote := &stripe.CreditNote{}
    50  	err := c.B.Call(http.MethodGet, path, c.Key, params, creditnote)
    51  	return creditnote, err
    52  }
    53  
    54  // Update updates a credit note's properties.
    55  func Update(id string, params *stripe.CreditNoteParams) (*stripe.CreditNote, error) {
    56  	return getC().Update(id, params)
    57  }
    58  
    59  // Update updates a credit note's properties.
    60  func (c Client) Update(id string, params *stripe.CreditNoteParams) (*stripe.CreditNote, error) {
    61  	path := stripe.FormatURLPath("/v1/credit_notes/%s", id)
    62  	creditnote := &stripe.CreditNote{}
    63  	err := c.B.Call(http.MethodPost, path, c.Key, params, creditnote)
    64  	return creditnote, err
    65  }
    66  
    67  // Preview is the method for the `GET /v1/credit_notes/preview` API.
    68  func Preview(params *stripe.CreditNotePreviewParams) (*stripe.CreditNote, error) {
    69  	return getC().Preview(params)
    70  }
    71  
    72  // Preview is the method for the `GET /v1/credit_notes/preview` API.
    73  func (c Client) Preview(params *stripe.CreditNotePreviewParams) (*stripe.CreditNote, error) {
    74  	creditnote := &stripe.CreditNote{}
    75  	err := c.B.Call(
    76  		http.MethodGet,
    77  		"/v1/credit_notes/preview",
    78  		c.Key,
    79  		params,
    80  		creditnote,
    81  	)
    82  	return creditnote, err
    83  }
    84  
    85  // VoidCreditNote is the method for the `POST /v1/credit_notes/{id}/void` API.
    86  func VoidCreditNote(id string, params *stripe.CreditNoteVoidCreditNoteParams) (*stripe.CreditNote, error) {
    87  	return getC().VoidCreditNote(id, params)
    88  }
    89  
    90  // VoidCreditNote is the method for the `POST /v1/credit_notes/{id}/void` API.
    91  func (c Client) VoidCreditNote(id string, params *stripe.CreditNoteVoidCreditNoteParams) (*stripe.CreditNote, error) {
    92  	path := stripe.FormatURLPath("/v1/credit_notes/%s/void", id)
    93  	creditnote := &stripe.CreditNote{}
    94  	err := c.B.Call(http.MethodPost, path, c.Key, params, creditnote)
    95  	return creditnote, err
    96  }
    97  
    98  // List returns a list of credit notes.
    99  func List(params *stripe.CreditNoteListParams) *Iter {
   100  	return getC().List(params)
   101  }
   102  
   103  // List returns a list of credit notes.
   104  func (c Client) List(listParams *stripe.CreditNoteListParams) *Iter {
   105  	return &Iter{
   106  		Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
   107  			list := &stripe.CreditNoteList{}
   108  			err := c.B.CallRaw(http.MethodGet, "/v1/credit_notes", c.Key, b, p, list)
   109  
   110  			ret := make([]interface{}, len(list.Data))
   111  			for i, v := range list.Data {
   112  				ret[i] = v
   113  			}
   114  
   115  			return ret, list, err
   116  		}),
   117  	}
   118  }
   119  
   120  // Iter is an iterator for credit notes.
   121  type Iter struct {
   122  	*stripe.Iter
   123  }
   124  
   125  // CreditNote returns the credit note which the iterator is currently pointing to.
   126  func (i *Iter) CreditNote() *stripe.CreditNote {
   127  	return i.Current().(*stripe.CreditNote)
   128  }
   129  
   130  // CreditNoteList returns the current list object which the iterator is
   131  // currently using. List objects will change as new API calls are made to
   132  // continue pagination.
   133  func (i *Iter) CreditNoteList() *stripe.CreditNoteList {
   134  	return i.List().(*stripe.CreditNoteList)
   135  }
   136  
   137  // ListLines is the method for the `GET /v1/credit_notes/{credit_note}/lines` API.
   138  func ListLines(params *stripe.CreditNoteListLinesParams) *LineItemIter {
   139  	return getC().ListLines(params)
   140  }
   141  
   142  // ListLines is the method for the `GET /v1/credit_notes/{credit_note}/lines` API.
   143  func (c Client) ListLines(listParams *stripe.CreditNoteListLinesParams) *LineItemIter {
   144  	path := stripe.FormatURLPath(
   145  		"/v1/credit_notes/%s/lines",
   146  		stripe.StringValue(listParams.CreditNote),
   147  	)
   148  	return &LineItemIter{
   149  		Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
   150  			list := &stripe.CreditNoteLineItemList{}
   151  			err := c.B.CallRaw(http.MethodGet, path, c.Key, b, p, list)
   152  
   153  			ret := make([]interface{}, len(list.Data))
   154  			for i, v := range list.Data {
   155  				ret[i] = v
   156  			}
   157  
   158  			return ret, list, err
   159  		}),
   160  	}
   161  }
   162  
   163  // PreviewLines is the method for the `GET /v1/credit_notes/preview/lines` API.
   164  func PreviewLines(params *stripe.CreditNotePreviewLinesParams) *LineItemIter {
   165  	return getC().PreviewLines(params)
   166  }
   167  
   168  // PreviewLines is the method for the `GET /v1/credit_notes/preview/lines` API.
   169  func (c Client) PreviewLines(listParams *stripe.CreditNotePreviewLinesParams) *LineItemIter {
   170  	return &LineItemIter{
   171  		Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
   172  			list := &stripe.CreditNoteLineItemList{}
   173  			err := c.B.CallRaw(http.MethodGet, "/v1/credit_notes/preview/lines", c.Key, b, p, list)
   174  
   175  			ret := make([]interface{}, len(list.Data))
   176  			for i, v := range list.Data {
   177  				ret[i] = v
   178  			}
   179  
   180  			return ret, list, err
   181  		}),
   182  	}
   183  }
   184  
   185  // LineItemIter is an iterator for credit note line items.
   186  type LineItemIter struct {
   187  	*stripe.Iter
   188  }
   189  
   190  // CreditNoteLineItem returns the credit note line item which the iterator is currently pointing to.
   191  func (i *LineItemIter) CreditNoteLineItem() *stripe.CreditNoteLineItem {
   192  	return i.Current().(*stripe.CreditNoteLineItem)
   193  }
   194  
   195  // CreditNoteLineItemList returns the current list object which the iterator is
   196  // currently using. List objects will change as new API calls are made to
   197  // continue pagination.
   198  func (i *LineItemIter) CreditNoteLineItemList() *stripe.CreditNoteLineItemList {
   199  	return i.List().(*stripe.CreditNoteLineItemList)
   200  }
   201  
   202  func getC() Client {
   203  	return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
   204  }