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

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