Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make more files codegen-able #1383

Merged
merged 3 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 14 additions & 50 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 @@ -31,15 +37,6 @@ const (
CreditNoteTypePrePayment CreditNoteType = "pre_payment"
)

// CreditNoteLineItemType is the list of allowed values for the credit note line item's type.
type CreditNoteLineItemType string

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

// CreditNoteParams is the set of parameters that can be used when creating or updating a credit note.
// For more details see https://stripe.com/docs/api/credit_notes/create, https://stripe.com/docs/api/credit_notes/update.
type CreditNoteParams struct {
Expand All @@ -66,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 All @@ -93,9 +89,9 @@ type CreditNoteLineParams struct {
InvoiceLineItem *string `form:"invoice_line_item"`
Quantity *int64 `form:"quantity"`
TaxRates []*string `form:"tax_rates"`
Type *string `form:"type"`
UnitAmount *int64 `form:"unit_amount"`
UnitAmountDecimal *float64 `form:"unit_amount_decimal,high_precision"`
Type *string `form:"type"`
}

// CreditNotePreviewParams is the set of parameters that can be used when previewing a credit note.
Expand Down Expand Up @@ -142,8 +138,8 @@ type CreditNote struct {
CustomerBalanceTransaction *CustomerBalanceTransaction `json:"customer_balance_transaction"`
DiscountAmount int64 `json:"discount_amount"`
DiscountAmounts []*CreditNoteDiscountAmount `json:"discount_amounts"`
Invoice *Invoice `json:"invoice"`
ID string `json:"id"`
Invoice *Invoice `json:"invoice"`
Lines *CreditNoteLineItemList `json:"lines"`
Livemode bool `json:"livemode"`
Memo string `json:"memo"`
Expand All @@ -162,60 +158,28 @@ type CreditNote struct {
VoidedAt int64 `json:"voided_at"`
}

// CreditNoteLineItemDiscountAmount represents the amount of discount calculated per discount for this line item.
type CreditNoteLineItemDiscountAmount struct {
Amount int64 `json:"amount"`
Discount *Discount `json:"discount"`
}

// CreditNoteLineItem is the resource representing a Stripe credit note line item.
// For more details see https://stripe.com/docs/api/credit_notes/line_item
type CreditNoteLineItem struct {
Amount int64 `json:"amount"`
Description string `json:"description"`
DiscountAmount int64 `json:"discount_amount"`
DiscountAmounts []*CreditNoteLineItemDiscountAmount `json:"discount_amounts"`
ID string `json:"id"`
InvoiceLineItem string `json:"invoice_line_item"`
Livemode bool `json:"livemode"`
Object string `json:"object"`
Quantity int64 `json:"quantity"`
TaxAmounts []*CreditNoteTaxAmount `json:"tax_amounts"`
TaxRates []*TaxRate `json:"tax_rates"`
Type CreditNoteLineItemType `json:"type"`
UnitAmount int64 `json:"unit_amount"`
UnitAmountDecimal float64 `json:"unit_amount_decimal,string"`
}

// CreditNoteList is a list of credit notes as retrieved from a list endpoint.
type CreditNoteList struct {
APIResource
ListMeta
Data []*CreditNote `json:"data"`
}

// CreditNoteLineItemList is a list of credit note line items as retrieved from a list endpoint.
type CreditNoteLineItemList struct {
APIResource
ListMeta
Data []*CreditNoteLineItem `json:"data"`
}

// 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
}
201 changes: 114 additions & 87 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,116 +46,83 @@ 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
}

// List returns a list of credit notes.
func List(params *stripe.CreditNoteListParams) *Iter {
return getC().List(params)
creditnote := &stripe.CreditNote{}
err := c.B.Call(http.MethodPost, path, c.Key, params, creditnote)
return creditnote, err
}

// 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)

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

return ret, list, err
})}
}

// ListLines returns a list of credit note line items on a credit note.
func ListLines(params *stripe.CreditNoteLineItemListParams) *LineItemIter {
return getC().ListLines(params)
}

// ListLines returns a list of credit note line items on a credit note.
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.
func ListPreviewLines(params *stripe.CreditNoteLineItemListPreviewParams) *LineItemIter {
return getC().ListPreviewLines(params)
}

// ListPreviewLines returns a list of lines on a previewed credit note.
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)

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

return ret, list, 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.
func List(params *stripe.CreditNoteListParams) *Iter {
return getC().List(params)
}

// List returns a list of credit notes.
func (c Client) List(listParams *stripe.CreditNoteListParams) *Iter {
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
}

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 @@ -155,7 +134,55 @@ func (i *Iter) CreditNoteList() *stripe.CreditNoteList {
return i.List().(*stripe.CreditNoteList)
}

// LineItemIter is an iterator for 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 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{
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 is the method for the `GET /v1/credit_notes/preview/lines` API.
func (c Client) ListPreviewLines(listParams *stripe.CreditNoteLineItemListPreviewParams) *LineItemIter {
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
}

return ret, list, err
}),
}
}

// LineItemIter is an iterator for credit note line items.
type LineItemIter struct {
*stripe.Iter
}
Expand Down
Loading