Skip to content

Commit

Permalink
Codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
yejia-stripe committed Nov 23, 2021
1 parent 5a3f2cc commit 3d896eb
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 137 deletions.
19 changes: 12 additions & 7 deletions creditnote.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//
//
// File generated from our OpenAPI spec
//
//

package stripe

import "encoding/json"
Expand Down Expand Up @@ -57,9 +63,8 @@ type CreditNoteListParams struct {
// CreditNoteLineItemListParams is the set of parameters that can be used when listing credit note line items.
type CreditNoteLineItemListParams struct {
ListParams `form:"*"`

// ID is the credit note ID to list line items for.
ID *string `form:"-"` // Goes in the URL
ID *string `form:"-"` // Included in URL
}

// CreditNoteLineItemListPreviewParams is the set of parameters that can be used when previewing a credit note's line items
Expand Down Expand Up @@ -163,18 +168,18 @@ type CreditNoteList struct {
// UnmarshalJSON handles deserialization of a CreditNote.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
func (i *CreditNote) UnmarshalJSON(data []byte) error {
func (c *CreditNote) UnmarshalJSON(data []byte) error {
if id, ok := ParseID(data); ok {
i.ID = id
c.ID = id
return nil
}

type note CreditNote
var v note
type creditNote CreditNote
var v creditNote
if err := json.Unmarshal(data, &v); err != nil {
return err
}

*i = CreditNote(v)
*c = CreditNote(v)
return nil
}
151 changes: 89 additions & 62 deletions creditnote/client.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//
//
// File generated from our OpenAPI spec
//
//

// Package creditnote provides the /credit_notes APIs
package creditnote

Expand All @@ -8,7 +14,7 @@ import (
"github.com/stripe/stripe-go/v72/form"
)

// Client is the client used to invoke /credit_notes APIs.
// Client is used to invoke /credit_notes APIs.
type Client struct {
B stripe.Backend
Key string
Expand All @@ -21,9 +27,15 @@ func New(params *stripe.CreditNoteParams) (*stripe.CreditNote, error) {

// New creates a new credit note.
func (c Client) New(params *stripe.CreditNoteParams) (*stripe.CreditNote, error) {
cn := &stripe.CreditNote{}
err := c.B.Call(http.MethodPost, "/v1/credit_notes", c.Key, params, cn)
return cn, err
creditnote := &stripe.CreditNote{}
err := c.B.Call(
http.MethodPost,
"/v1/credit_notes",
c.Key,
params,
creditnote,
)
return creditnote, err
}

// Get returns the details of a credit note.
Expand All @@ -34,47 +46,53 @@ func Get(id string, params *stripe.CreditNoteParams) (*stripe.CreditNote, error)
// Get returns the details of a credit note.
func (c Client) Get(id string, params *stripe.CreditNoteParams) (*stripe.CreditNote, error) {
path := stripe.FormatURLPath("/v1/credit_notes/%s", id)
cn := &stripe.CreditNote{}
err := c.B.Call(http.MethodGet, path, c.Key, params, cn)
return cn, err
creditnote := &stripe.CreditNote{}
err := c.B.Call(http.MethodGet, path, c.Key, params, creditnote)
return creditnote, err
}

// Update updates a credit note.
// Update updates a credit note's properties.
func Update(id string, params *stripe.CreditNoteParams) (*stripe.CreditNote, error) {
return getC().Update(id, params)
}

// Update updates a credit note.
// Update updates a credit note's properties.
func (c Client) Update(id string, params *stripe.CreditNoteParams) (*stripe.CreditNote, error) {
path := stripe.FormatURLPath("/v1/credit_notes/%s", id)
cn := &stripe.CreditNote{}
err := c.B.Call(http.MethodPost, path, c.Key, params, cn)
return cn, err
creditnote := &stripe.CreditNote{}
err := c.B.Call(http.MethodPost, path, c.Key, params, creditnote)
return creditnote, err
}

// Preview previews a credit note.
// Preview is the method for the `GET /v1/credit_notes/preview` API.
func Preview(params *stripe.CreditNotePreviewParams) (*stripe.CreditNote, error) {
return getC().Preview(params)
}

// Preview previews a credit note.
// Preview is the method for the `GET /v1/credit_notes/preview` API.
func (c Client) Preview(params *stripe.CreditNotePreviewParams) (*stripe.CreditNote, error) {
cn := &stripe.CreditNote{}
err := c.B.Call(http.MethodGet, "/v1/credit_notes/preview", c.Key, params, cn)
return cn, err
}

// VoidCreditNote voids a credit note.
creditnote := &stripe.CreditNote{}
err := c.B.Call(
http.MethodGet,
"/v1/credit_notes/preview",
c.Key,
params,
creditnote,
)
return creditnote, err
}

// VoidCreditNote is the method for the `POST /v1/credit_notes/{id}/void` API.
func VoidCreditNote(id string, params *stripe.CreditNoteVoidParams) (*stripe.CreditNote, error) {
return getC().VoidCreditNote(id, params)
}

// VoidCreditNote voids a credit note.
// VoidCreditNote is the method for the `POST /v1/credit_notes/{id}/void` API.
func (c Client) VoidCreditNote(id string, params *stripe.CreditNoteVoidParams) (*stripe.CreditNote, error) {
path := stripe.FormatURLPath("/v1/credit_notes/%s/void", id)
cn := &stripe.CreditNote{}
err := c.B.Call(http.MethodPost, path, c.Key, params, cn)
return cn, err
creditnote := &stripe.CreditNote{}
err := c.B.Call(http.MethodPost, path, c.Key, params, creditnote)
return creditnote, err
}

// List returns a list of credit notes.
Expand All @@ -84,25 +102,27 @@ func List(params *stripe.CreditNoteListParams) *Iter {

// List returns a list of credit notes.
func (c Client) List(listParams *stripe.CreditNoteListParams) *Iter {
return &Iter{stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
list := &stripe.CreditNoteList{}
err := c.B.CallRaw(http.MethodGet, "/v1/credit_notes", c.Key, b, p, list)
return &Iter{
Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
list := &stripe.CreditNoteList{}
err := c.B.CallRaw(http.MethodGet, "/v1/credit_notes", c.Key, b, p, list)

ret := make([]interface{}, len(list.Data))
for i, v := range list.Data {
ret[i] = v
}
ret := make([]interface{}, len(list.Data))
for i, v := range list.Data {
ret[i] = v
}

return ret, list, err
})}
return ret, list, err
}),
}
}

// Iter is an iterator for credit notes.
type Iter struct {
*stripe.Iter
}

// CreditNote returns the cn which the iterator is currently pointing to.
// CreditNote returns the credit note which the iterator is currently pointing to.
func (i *Iter) CreditNote() *stripe.CreditNote {
return i.Current().(*stripe.CreditNote)
}
Expand All @@ -114,48 +134,55 @@ func (i *Iter) CreditNoteList() *stripe.CreditNoteList {
return i.List().(*stripe.CreditNoteList)
}

// ListLines returns a list of credit note line items on a credit note.
// ListLines is the method for the `GET /v1/credit_notes/{credit_note}/lines` API.
func ListLines(params *stripe.CreditNoteLineItemListParams) *LineItemIter {
return getC().ListLines(params)
}

// ListLines returns a list of credit note line items on a credit note.
// ListLines is the method for the `GET /v1/credit_notes/{credit_note}/lines` API.
func (c Client) ListLines(listParams *stripe.CreditNoteLineItemListParams) *LineItemIter {
path := stripe.FormatURLPath("/v1/credit_notes/%s/lines", stripe.StringValue(listParams.ID))
return &LineItemIter{stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
list := &stripe.CreditNoteLineItemList{}
err := c.B.CallRaw(http.MethodGet, path, c.Key, b, p, list)

ret := make([]interface{}, len(list.Data))
for i, v := range list.Data {
ret[i] = v
}

return ret, list, err
})}
}

// ListPreviewLines returns a list of lines on a previewed credit note.
path := stripe.FormatURLPath(
"/v1/credit_notes/%s/lines",
stripe.StringValue(listParams.ID),
)
return &LineItemIter{
Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
list := &stripe.CreditNoteLineItemList{}
err := c.B.CallRaw(http.MethodGet, path, c.Key, b, p, list)

ret := make([]interface{}, len(list.Data))
for i, v := range list.Data {
ret[i] = v
}

return ret, list, err
}),
}
}

// ListPreviewLines is the method for the `GET /v1/credit_notes/preview/lines` API.
func ListPreviewLines(params *stripe.CreditNoteLineItemListPreviewParams) *LineItemIter {
return getC().ListPreviewLines(params)
}

// ListPreviewLines returns a list of lines on a previewed credit note.
// ListPreviewLines is the method for the `GET /v1/credit_notes/preview/lines` API.
func (c Client) ListPreviewLines(listParams *stripe.CreditNoteLineItemListPreviewParams) *LineItemIter {
return &LineItemIter{stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
list := &stripe.CreditNoteLineItemList{}
err := c.B.CallRaw(http.MethodGet, "/v1/credit_notes/preview/lines", c.Key, b, p, list)
return &LineItemIter{
Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
list := &stripe.CreditNoteLineItemList{}
err := c.B.CallRaw(http.MethodGet, "/v1/credit_notes/preview/lines", c.Key, b, p, list)

ret := make([]interface{}, len(list.Data))
for i, v := range list.Data {
ret[i] = v
}
ret := make([]interface{}, len(list.Data))
for i, v := range list.Data {
ret[i] = v
}

return ret, list, err
})}
return ret, list, err
}),
}
}

// LineItemIter is an iterator for credit note line items on a credit note.
// LineItemIter is an iterator for credit note line items.
type LineItemIter struct {
*stripe.Iter
}
Expand Down
14 changes: 10 additions & 4 deletions creditnotelineitem.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
//
//
// File generated from our OpenAPI spec
//
//

package stripe

// CreditNoteLineItemType is the list of allowed values for the credit note line item's type.
// The type of the credit note line item, one of `invoice_line_item` or `custom_line_item`. When the type is `invoice_line_item` there is an additional `invoice_line_item` property on the resource the value of which is the id of the credited line item on the invoice.
type CreditNoteLineItemType string

// List of values that CreditNoteType can take.
// List of values that CreditNoteLineItemType can take
const (
CreditNoteLineItemTypeCustomLineItem CreditNoteLineItemType = "custom_line_item"
CreditNoteLineItemTypeInvoiceLineItem CreditNoteLineItemType = "invoice_line_item"
)

// CreditNoteLineItemDiscountAmount represents the amount of discount calculated per discount for this line item.
// The integer amount in %s representing the discount being credited for this line item.
type CreditNoteLineItemDiscountAmount struct {
Amount int64 `json:"amount"`
Discount *Discount `json:"discount"`
Expand All @@ -34,7 +40,7 @@ type CreditNoteLineItem struct {
UnitAmountDecimal float64 `json:"unit_amount_decimal,string"`
}

// CreditNoteLineItemList is a list of credit note line items as retrieved from a list endpoint.
// CreditNoteLineItemList is a list of CreditNoteLineItems as retrieved from a list endpoint.
type CreditNoteLineItemList struct {
APIResource
ListMeta
Expand Down
Loading

0 comments on commit 3d896eb

Please sign in to comment.