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 API response accessible on returned API structs #1054

Merged
merged 4 commits into from
Apr 3, 2020
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
3 changes: 3 additions & 0 deletions account.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ type AccountTOSAcceptance struct {
// Account is the resource representing your Stripe account.
// For more details see https://stripe.com/docs/api/#account.
type Account struct {
APIResource
BusinessProfile *AccountBusinessProfile `json:"business_profile"`
BusinessType AccountBusinessType `json:"business_type"`
Capabilities *AccountCapabilities `json:"capabilities"`
Expand Down Expand Up @@ -503,13 +504,15 @@ func (a *Account) UnmarshalJSON(data []byte) error {

// AccountList is a list of accounts as returned from a list endpoint.
type AccountList struct {
APIResource
ListMeta
Data []*Account `json:"data"`
}

// ExternalAccountList is a list of external accounts that may be either bank
// accounts or cards.
type ExternalAccountList struct {
APIResource
ListMeta

// Values contains any external accounts (bank accounts and/or cards)
Expand Down
1 change: 1 addition & 0 deletions accountlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type AccountLinkParams struct {
// AccountLink is the resource representing an account link.
// For more details see https://stripe.com/docs/api/#account_links.
type AccountLink struct {
APIResource
Created int64 `json:"created"`
ExpiresAt int64 `json:"expires_at"`
Object string `json:"object"`
Expand Down
2 changes: 2 additions & 0 deletions applepaydomain.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type ApplePayDomainParams struct {

// ApplePayDomain is the resource representing a Stripe ApplePayDomain object
type ApplePayDomain struct {
APIResource
Created int64 `json:"created"`
Deleted bool `json:"deleted"`
DomainName string `json:"domain_name"`
Expand All @@ -22,6 +23,7 @@ type ApplePayDomainListParams struct {

// ApplePayDomainList is a list of ApplePayDomains as returned from a list endpoint.
type ApplePayDomainList struct {
APIResource
ListMeta
Data []*ApplePayDomain `json:"data"`
}
1 change: 1 addition & 0 deletions balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type BalanceParams struct {
// Balance is the resource representing your Stripe balance.
// For more details see https://stripe.com/docs/api/#balance.
type Balance struct {
APIResource
Available []*Amount `json:"available"`
ConnectReserved []*Amount `json:"connect_reserved"`
Livemode bool `json:"livemode"`
Expand Down
2 changes: 2 additions & 0 deletions balancetransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ type BalanceTransactionListParams struct {
// BalanceTransaction is the resource representing the balance transaction.
// For more details see https://stripe.com/docs/api/#balance.
type BalanceTransaction struct {
APIResource
Amount int64 `json:"amount"`
AvailableOn int64 `json:"available_on"`
Created int64 `json:"created"`
Expand All @@ -145,6 +146,7 @@ type BalanceTransaction struct {

// BalanceTransactionList is a list of transactions as returned from a list endpoint.
type BalanceTransactionList struct {
APIResource
ListMeta
Data []*BalanceTransaction `json:"data"`
}
Expand Down
2 changes: 2 additions & 0 deletions bankaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func (p *BankAccountListParams) AppendTo(body *form.Values, keyParts []string) {

// BankAccount represents a Stripe bank account.
type BankAccount struct {
APIResource
Account *Account `json:"account"`
AccountHolderName string `json:"account_holder_name"`
AccountHolderType BankAccountAccountHolderType `json:"account_holder_type"`
Expand All @@ -160,6 +161,7 @@ type BankAccount struct {

// BankAccountList is a list object for bank accounts.
type BankAccountList struct {
APIResource
ListMeta
Data []*BankAccount `json:"data"`
}
Expand Down
2 changes: 2 additions & 0 deletions bitcoinreceiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type BitcoinReceiverListParams struct {
// BitcoinReceiver is the resource representing a Stripe bitcoin receiver.
// For more details see https://stripe.com/docs/api/#bitcoin_receivers
type BitcoinReceiver struct {
APIResource
Active bool `json:"active"`
Amount int64 `json:"amount"`
AmountReceived int64 `json:"amount_received"`
Expand All @@ -39,6 +40,7 @@ type BitcoinReceiver struct {

// BitcoinReceiverList is a list of bitcoin receivers as retrieved from a list endpoint.
type BitcoinReceiverList struct {
APIResource
ListMeta
Data []*BitcoinReceiver `json:"data"`
}
Expand Down
1 change: 1 addition & 0 deletions bitcointransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type BitcoinTransactionListParams struct {
// It is a child object of BitcoinReceivers
// For more details see https://stripe.com/docs/api/#retrieve_bitcoin_receiver
type BitcoinTransactionList struct {
APIResource
ListMeta
Data []*BitcoinTransaction `json:"data"`
}
Expand Down
2 changes: 2 additions & 0 deletions capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type CapabilityRequirements struct {
// Capability is the resource representing a Stripe capability.
// For more details see https://stripe.com/docs/api/capabilities
type Capability struct {
APIResource
Account *Account `json:"account"`
ID string `json:"id"`
Object string `json:"object"`
Expand All @@ -66,6 +67,7 @@ type Capability struct {

// CapabilityList is a list of capabilities as retrieved from a list endpoint.
type CapabilityList struct {
APIResource
ListMeta
Data []*Capability `json:"data"`
}
Expand Down
3 changes: 3 additions & 0 deletions card.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ func (p *CardListParams) AppendTo(body *form.Values, keyParts []string) {
// Card is the resource representing a Stripe credit/debit card.
// For more details see https://stripe.com/docs/api#cards.
type Card struct {
APIResource

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the extra line on that one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, I was thinking about leaving a comment about this, but didn't think anyone would notice. Should have known better!

It might look a little random whether I double-spaced after or not, but here's the rough heuristic:

  1. If some effort has been made to "sectionize" the struct into various categories (i.e., there are other double newlines in it), then I left an extra newline after the APIResource inclusion.
  2. If the struct is just a solid block of fields, then there's no newline.

An example of the first is Card:

type Card struct {
	APIResource

	AddressCity            string                      `json:"address_city"`
	AddressCountry         string                      `json:"address_country"`
	AddressLine1           string                      `json:"address_line1"`
	AddressLine1Check      CardVerification            `json:"address_line1_check"`
	AddressLine2           string                      `json:"address_line2"`
	AddressState           string                      `json:"address_state"`
	AddressZip             string                      `json:"address_zip"`
	AddressZipCheck        CardVerification            `json:"address_zip_check"`
	AvailablePayoutMethods []CardAvailablePayoutMethod `json:"available_payout_methods"`
	Brand                  CardBrand                   `json:"brand"`
	CVCCheck               CardVerification            `json:"cvc_check"`
	Country                string                      `json:"country"`
	Currency               Currency                    `json:"currency"`
	Customer               *Customer                   `json:"customer"`
	DefaultForCurrency     bool                        `json:"default_for_currency"`
	Deleted                bool                        `json:"deleted"`

	// Description is a succinct summary of the card's information.
	//
	// Please note that this field is for internal use only and is not returned
	// as part of standard API requests.
	Description string `json:"description"`

	DynamicLast4 string      `json:"dynamic_last4"`
	ExpMonth     uint8       `json:"exp_month"`
	ExpYear      uint16      `json:"exp_year"`
	Fingerprint  string      `json:"fingerprint"`
	Funding      CardFunding `json:"funding"`
	ID           string      `json:"id"`

...

An example of the second is Coupon:

type Coupon struct {
	APIResource
	AmountOff        int64             `json:"amount_off"`
	Created          int64             `json:"created"`
	Currency         Currency          `json:"currency"`
	Deleted          bool              `json:"deleted"`
	Duration         CouponDuration    `json:"duration"`
	DurationInMonths int64             `json:"duration_in_months"`
	ID               string            `json:"id"`
	Livemode         bool              `json:"livemode"`
	MaxRedemptions   int64             `json:"max_redemptions"`
	Metadata         map[string]string `json:"metadata"`
	Name             string            `json:"name"`
	PercentOff       float64           `json:"percent_off"`
	RedeemBy         int64             `json:"redeem_by"`
	TimesRedeemed    int64             `json:"times_redeemed"`
	Valid            bool              `json:"valid"`
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly out of curiosity: what is the reasoning doing that? Since it seems to indent exactly the same way I would have expected Go to have an opinion on the only right way. Mostly asking because I'll need to remember when to add/remove lines depending on whether there are specific sections that get added/removed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a purely cosmetic thing for me :) If some attempt at spacing has already been made within a struct, I'll keep that going to give it some more breathing room. Gofmt doesn't have an opinion on it either way.

TBH though, it really doesn't matter that much so if we regress a little bit on this minor style I don't think it'll matter at all.

AddressCity string `json:"address_city"`
AddressCountry string `json:"address_country"`
AddressLine1 string `json:"address_line1"`
Expand Down Expand Up @@ -249,6 +251,7 @@ type Card struct {

// CardList is a list object for cards.
type CardList struct {
APIResource
ListMeta
Data []*Card `json:"data"`
}
Expand Down
2 changes: 2 additions & 0 deletions charge.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ type ChargeTransferData struct {
// Charge is the resource representing a Stripe charge.
// For more details see https://stripe.com/docs/api#charges.
type Charge struct {
APIResource
Amount int64 `json:"amount"`
AmountRefunded int64 `json:"amount_refunded"`
Application *Application `json:"application"`
Expand Down Expand Up @@ -526,6 +527,7 @@ func (c *Charge) UnmarshalJSON(data []byte) error {

// ChargeList is a list of charges as retrieved from a list endpoint.
type ChargeList struct {
APIResource
ListMeta
Data []*Charge `json:"data"`
}
Expand Down
2 changes: 2 additions & 0 deletions checkout_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ type CheckoutSessionShippingAddressCollection struct {
// CheckoutSession is the resource representing a Stripe checkout session.
// For more details see https://stripe.com/docs/api/checkout/sessions/object
type CheckoutSession struct {
APIResource
CancelURL string `json:"cancel_url"`
ClientReferenceID string `json:"client_reference_id"`
Customer *Customer `json:"customer"`
Expand All @@ -187,6 +188,7 @@ type CheckoutSession struct {

// CheckoutSessionList is a list of sessions as retrieved from a list endpoint.
type CheckoutSessionList struct {
APIResource
ListMeta
Data []*CheckoutSession `json:"data"`
}
Expand Down
2 changes: 2 additions & 0 deletions countryspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type VerificationFieldsList struct {
// CountrySpec is the resource representing the rules required for a Stripe account.
// For more details see https://stripe.com/docs/api/#country_specs.
type CountrySpec struct {
APIResource
DefaultCurrency Currency `json:"default_currency"`
ID string `json:"id"`
SupportedBankAccountCurrencies map[Currency][]Country `json:"supported_bank_account_currencies"`
Expand All @@ -29,6 +30,7 @@ type CountrySpecParams struct {

// CountrySpecList is a list of country specs as retrieved from a list endpoint.
type CountrySpecList struct {
APIResource
ListMeta
Data []*CountrySpec `json:"data"`
}
Expand Down
2 changes: 2 additions & 0 deletions coupon.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type CouponListParams struct {
// Coupon is the resource representing a Stripe coupon.
// For more details see https://stripe.com/docs/api#coupons.
type Coupon struct {
APIResource
AmountOff int64 `json:"amount_off"`
Created int64 `json:"created"`
Currency Currency `json:"currency"`
Expand All @@ -57,6 +58,7 @@ type Coupon struct {

// CouponList is a list of coupons as retrieved from a list endpoint.
type CouponList struct {
APIResource
ListMeta
Data []*Coupon `json:"data"`
}
Expand Down
3 changes: 3 additions & 0 deletions creditnote.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ type CreditNoteTaxAmount struct {
// CreditNote is the resource representing a Stripe credit note.
// For more details see https://stripe.com/docs/api/credit_notes/object.
type CreditNote struct {
APIResource
Amount int64 `json:"amount"`
Created int64 `json:"created"`
Currency Currency `json:"currency"`
Expand Down Expand Up @@ -174,12 +175,14 @@ type CreditNoteLineItem struct {

// 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"`
}
Expand Down
2 changes: 2 additions & 0 deletions customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ type CustomerListParams struct {
// Customer is the resource representing a Stripe customer.
// For more details see https://stripe.com/docs/api#customers.
type Customer struct {
APIResource
Address Address `json:"address"`
Balance int64 `json:"balance"`
Created int64 `json:"created"`
Expand Down Expand Up @@ -134,6 +135,7 @@ type CustomerInvoiceSettings struct {

// CustomerList is a list of customers as retrieved from a list endpoint.
type CustomerList struct {
APIResource
ListMeta
Data []*Customer `json:"data"`
}
Expand Down
2 changes: 2 additions & 0 deletions customerbalancetransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type CustomerBalanceTransactionListParams struct {
// CustomerBalanceTransaction is the resource representing a customer balance transaction.
// For more details see https://stripe.com/docs/api/customers/customer_balance_transaction_object
type CustomerBalanceTransaction struct {
APIResource
Amount int64 `json:"amount"`
Created int64 `json:"created"`
CreditNote *CreditNote `json:"credit_note"`
Expand All @@ -57,6 +58,7 @@ type CustomerBalanceTransaction struct {
// CustomerBalanceTransactionList is a list of customer balance transactions as retrieved from a
// list endpoint.
type CustomerBalanceTransactionList struct {
APIResource
ListMeta
Data []*CustomerBalanceTransaction `json:"data"`
}
Expand Down
1 change: 1 addition & 0 deletions discount.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type DiscountParams struct {
// Discount is the resource representing a Stripe discount.
// For more details see https://stripe.com/docs/api#discounts.
type Discount struct {
APIResource
Coupon *Coupon `json:"coupon"`
Customer string `json:"customer"`
Deleted bool `json:"deleted"`
Expand Down
2 changes: 2 additions & 0 deletions dispute.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type DisputeListParams struct {
// Dispute is the resource representing a Stripe dispute.
// For more details see https://stripe.com/docs/api#disputes.
type Dispute struct {
APIResource
Amount int64 `json:"amount"`
BalanceTransactions []*BalanceTransaction `json:"balance_transactions"`
Charge *Charge `json:"charge"`
Expand All @@ -105,6 +106,7 @@ type Dispute struct {

// DisputeList is a list of disputes as retrieved from a list endpoint.
type DisputeList struct {
APIResource
ListMeta
Data []*Dispute `json:"data"`
}
Expand Down
2 changes: 2 additions & 0 deletions ephemeralkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type EphemeralKeyParams struct {
// EphemeralKey is the resource representing a Stripe ephemeral key. This is used by Mobile SDKs
// to for example manage a Customer's payment methods.
type EphemeralKey struct {
APIResource

AssociatedObjects []struct {
ID string `json:"id"`
Type string `json:"type"`
Expand Down
2 changes: 2 additions & 0 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ const (
// Error is the response returned when a call is unsuccessful.
// For more details see https://stripe.com/docs/api#errors.
type Error struct {
APIResource

ChargeID string `json:"charge,omitempty"`
Code ErrorCode `json:"code,omitempty"`
DeclineCode DeclineCode `json:"decline_code,omitempty"`
Expand Down
2 changes: 2 additions & 0 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
// Event is the resource representing a Stripe event.
// For more details see https://stripe.com/docs/api#events.
type Event struct {
APIResource
Account string `json:"account"`
Created int64 `json:"created"`
Data *EventData `json:"data"`
Expand Down Expand Up @@ -49,6 +50,7 @@ type EventParams struct {

// EventList is a list of events as retrieved from a list endpoint.
type EventList struct {
APIResource
ListMeta
Data []*Event `json:"data"`
}
Expand Down
2 changes: 2 additions & 0 deletions exchangerate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package stripe
// ExchangeRate is the resource representing the currency exchange rates at
// a given time.
type ExchangeRate struct {
APIResource
ID string `json:"id"`
Rates map[Currency]float64 `json:"rates"`
}
Expand All @@ -15,6 +16,7 @@ type ExchangeRateParams struct {

// ExchangeRateList is a list of exchange rates as retrieved from a list endpoint.
type ExchangeRateList struct {
APIResource
ListMeta
Data []*ExchangeRate `json:"data"`
}
Expand Down
2 changes: 2 additions & 0 deletions fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type ApplicationFeeListParams struct {
// ApplicationFee is the resource representing a Stripe application fee.
// For more details see https://stripe.com/docs/api#application_fees.
type ApplicationFee struct {
APIResource
Account *Account `json:"account"`
Amount int64 `json:"amount"`
AmountRefunded int64 `json:"amount_refunded"`
Expand All @@ -37,6 +38,7 @@ type ApplicationFee struct {

//ApplicationFeeList is a list of application fees as retrieved from a list endpoint.
type ApplicationFeeList struct {
APIResource
ListMeta
Data []*ApplicationFee `json:"data"`
}
Expand Down
2 changes: 2 additions & 0 deletions feerefund.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type FeeRefundListParams struct {
// FeeRefund is the resource representing a Stripe application fee refund.
// For more details see https://stripe.com/docs/api#fee_refunds.
type FeeRefund struct {
APIResource
Amount int64 `json:"amount"`
BalanceTransaction *BalanceTransaction `json:"balance_transaction"`
Created int64 `json:"created"`
Expand All @@ -33,6 +34,7 @@ type FeeRefund struct {

// FeeRefundList is a list object for application fee refunds.
type FeeRefundList struct {
APIResource
ListMeta
Data []*FeeRefund `json:"data"`
}
Expand Down
2 changes: 2 additions & 0 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type FileListParams struct {
// File is the resource representing a Stripe file.
// For more details see https://stripe.com/docs/api#file_object.
type File struct {
APIResource
Created int64 `json:"created"`
ID string `json:"id"`
Filename string `json:"filename"`
Expand All @@ -77,6 +78,7 @@ type File struct {

// FileList is a list of files as retrieved from a list endpoint.
type FileList struct {
APIResource
ListMeta
Data []*File `json:"data"`
}
Expand Down
Loading