Skip to content

Commit

Permalink
Rename all properties in the library to match the API reference
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-stripe committed Jun 6, 2018
1 parent 135843e commit fdd38c4
Show file tree
Hide file tree
Showing 108 changed files with 1,376 additions and 1,446 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ i := event.List(nil)
for i.Next() {
e := i.Event()

// access event data via e.GetObjValue("resource_name_based_on_type", "resource_property_name")
// alternatively you can access values via e.Data.Obj["resource_name_based_on_type"].(map[string]interface{})["resource_property_name"]
// access event data via e.GetObjectValue("resource_name_based_on_type", "resource_property_name")
// alternatively you can access values via e.Data.Object["resource_name_based_on_type"].(map[string]interface{})["resource_property_name"]

// access previous attributes via e.GetPrevValue("resource_name_based_on_type", "resource_property_name")
// alternatively you can access values via e.Data.Prev["resource_name_based_on_type"].(map[string]interface{})["resource_property_name"]
// access previous attributes via e.GetPreviousValue("resource_name_based_on_type", "resource_property_name")
// alternatively you can access values via e.Data.PrevPreviousAttributes["resource_name_based_on_type"].(map[string]interface{})["resource_property_name"]
}
```

Expand Down
212 changes: 106 additions & 106 deletions account.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions account/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ func (c Client) List(params *stripe.AccountListParams) *Iter {
list := &stripe.AccountList{}
err := c.B.Call("GET", "/accounts", c.Key, b, p, list)

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

Expand Down
32 changes: 16 additions & 16 deletions account/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ func TestAccountList(t *testing.T) {

func TestAccountNew(t *testing.T) {
account, err := New(&stripe.AccountParams{
Type: stripe.AccountTypeCustom,
Country: "CA",
BusinessUrl: "www.stripe.com",
BusinessName: "Stripe",
BusinessPrimaryColor: "#ffffff",
DebitNegativeBal: true,
SupportEmail: "[email protected]",
SupportUrl: "www.stripe.com",
SupportPhone: "4151234567",
Type: stripe.AccountTypeCustom,
Country: "CA",
BusinessURL: "www.stripe.com",
BusinessName: "Stripe",
BusinessPrimaryColor: "#ffffff",
DebitNegativeBalances: true,
SupportEmail: "[email protected]",
SupportURL: "www.stripe.com",
SupportPhone: "4151234567",
LegalEntity: &stripe.LegalEntity{
Type: stripe.Individual,
BusinessName: "Stripe Go",
AdditionalOwners: []stripe.Owner{
{First: "Jane"},
AdditionalOwners: []stripe.AdditionalOwner{
{FirstName: "Jane"},
},
DOB: stripe.DOB{
Day: 1,
Expand Down Expand Up @@ -80,11 +80,11 @@ func TestAccountUpdate(t *testing.T) {
account, err := Update("acct_123", &stripe.AccountParams{
LegalEntity: &stripe.LegalEntity{
Address: stripe.Address{
Country: "CA",
City: "Montreal",
Zip: "H2Y 1C6",
Line1: "275, rue Notre-Dame Est",
State: "QC",
Country: "CA",
City: "Montreal",
PostalCode: "H2Y 1C6",
Line1: "275, rue Notre-Dame Est",
State: "QC",
},
},
})
Expand Down
8 changes: 4 additions & 4 deletions account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ func TestAccountUnmarshal(t *testing.T) {
assert.NoError(t, err)

assert.Equal(t, "acct_123", account.ID)
assert.Equal(t, true, account.ExternalAccounts.More)
assert.Equal(t, true, account.ExternalAccounts.HasMore)

assert.Equal(t, 2, len(account.ExternalAccounts.Values))
assert.Equal(t, "ba_123", account.ExternalAccounts.Values[0].ID)
assert.Equal(t, "card_123", account.ExternalAccounts.Values[1].ID)
assert.Equal(t, 2, len(account.ExternalAccounts.Data))
assert.Equal(t, "ba_123", account.ExternalAccounts.Data[0].ID)
assert.Equal(t, "card_123", account.ExternalAccounts.Data[1].ID)
}

func TestIdentityDocument_Appendto(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions applepaydomain.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type ApplePayDomain struct {
Deleted bool `json:"deleted"`
DomainName string `json:"domain_name"`
ID string `json:"id"`
Live bool `json:"livemode"`
Livemode bool `json:"livemode"`
}

// ApplePayDomainListParams are the parameters allowed during ApplePayDomain listing.
Expand All @@ -23,5 +23,5 @@ type ApplePayDomainListParams struct {
// ApplePayDomainList is a list of ApplePayDomains as returned from a list endpoint.
type ApplePayDomainList struct {
ListMeta
Values []*ApplePayDomain `json:"data"`
Data []*ApplePayDomain `json:"data"`
}
4 changes: 2 additions & 2 deletions applepaydomain/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ func (c Client) List(params *stripe.ApplePayDomainListParams) *Iter {
list := &stripe.ApplePayDomainList{}
err := c.B.Call("GET", "/apple_pay/domains", c.Key, b, p, list)

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

Expand Down
178 changes: 89 additions & 89 deletions balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,58 @@ package stripe

import "encoding/json"

// TransactionStatus is the list of allowed values for the transaction's status.
// BalanceTransactionStatus is the list of allowed values for the balance transaction's status.
// Allowed values are "available", "pending".
type TransactionStatus string
type BalanceTransactionStatus string

// TransactionType is the list of allowed values for the transaction's type.
// BalanceTransactionType is the list of allowed values for the balance transaction's type.
// Allowed values are "charge", "refund", "adjustment", "application_fee",
// "application_fee_refund", "transfer", "transfer_cancel", "transfer_failure".
type TransactionType string
type BalanceTransactionType string

// TransactionSourceType consts represent valid balance transaction sources.
type TransactionSourceType string
// BalanceTransactionSourceType consts represent valid balance transaction sources.
type BalanceTransactionSourceType string

const (
// TransactionSourceCharge is a constant representing a transaction source of charge
TransactionSourceCharge TransactionSourceType = "charge"
// BalanceTransactionSourceTypeCharge is a constant representing a transaction source of charge
BalanceTransactionSourceTypeCharge BalanceTransactionSourceType = "charge"

// TransactionSourceDispute is a constant representing a transaction source of dispute
TransactionSourceDispute TransactionSourceType = "dispute"
// BalanceTransactionSourceTypeDispute is a constant representing a transaction source of dispute
BalanceTransactionSourceTypeDispute BalanceTransactionSourceType = "dispute"

// TransactionSourceFee is a constant representing a transaction source of application_fee
TransactionSourceFee TransactionSourceType = "application_fee"
// BalanceTransactionSourceTypeApplicationFee is a constant representing a transaction source of application_fee
BalanceTransactionSourceTypeApplicationFee BalanceTransactionSourceType = "application_fee"

// TransactionSourcePayout is a constant representing a transaction source of payout
TransactionSourcePayout TransactionSourceType = "payout"
// BalanceTransactionSourceTypePayout is a constant representing a transaction source of payout
BalanceTransactionSourceTypePayout BalanceTransactionSourceType = "payout"

// TransactionSourceRecipientTransfer is a constant representing a transaction source of recipient_transfer
TransactionSourceRecipientTransfer TransactionSourceType = "recipient_transfer"
// BalanceTransactionSourceTypeRecipientTransfer is a constant representing a transaction source of recipient_transfer
BalanceTransactionSourceTypeRecipientTransfer BalanceTransactionSourceType = "recipient_transfer"

// TransactionSourceRefund is a constant representing a transaction source of refund
TransactionSourceRefund TransactionSourceType = "refund"
// BalanceTransactionSourceTypeRefund is a constant representing a transaction source of refund
BalanceTransactionSourceTypeRefund BalanceTransactionSourceType = "refund"

// TransactionSourceReversal is a constant representing a transaction source of reversal
TransactionSourceReversal TransactionSourceType = "reversal"
// BalanceTransactionSourceTypeReversal is a constant representing a transaction source of reversal
BalanceTransactionSourceTypeReversal BalanceTransactionSourceType = "reversal"

// TransactionSourceTransfer is a constant representing a transaction source of transfer
TransactionSourceTransfer TransactionSourceType = "transfer"
// BalanceTransactionSourceTypeTransfer is a constant representing a transaction source of transfer
BalanceTransactionSourceTypeTransfer BalanceTransactionSourceType = "transfer"
)

// TransactionSource describes the source of a balance Transaction.
// BalanceTransactionSource describes the source of a balance Transaction.
// The Type should indicate which object is fleshed out.
// For more details see https://stripe.com/docs/api#retrieve_balance_transaction
type TransactionSource struct {
Charge *Charge `json:"-"`
Dispute *Dispute `json:"-"`
Fee *Fee `json:"-"`
ID string `json:"id"`
Payout *Payout `json:"-"`
RecipientTransfer *RecipientTransfer `json:"-"`
Refund *Refund `json:"-"`
Reversal *Reversal `json:"-"`
Transfer *Transfer `json:"-"`
Type TransactionSourceType `json:"object"`
type BalanceTransactionSource struct {
ApplicationFee *ApplicationFee `json:"-"`
Charge *Charge `json:"-"`
Dispute *Dispute `json:"-"`
ID string `json:"id"`
Payout *Payout `json:"-"`
RecipientTransfer *RecipientTransfer `json:"-"`
Refund *Refund `json:"-"`
Reversal *Reversal `json:"-"`
Transfer *Transfer `json:"-"`
Type BalanceTransactionSourceType `json:"object"`
}

// BalanceParams is the set of parameters that can be used when retrieving a balance.
Expand All @@ -62,56 +62,56 @@ type BalanceParams struct {
Params `form:"*"`
}

// TxParams is the set of parameters that can be used when retrieving a transaction.
// BalanceTransactionParams is the set of parameters that can be used when retrieving a transaction.
// For more details see https://stripe.com/docs/api#retrieve_balance_transaction.
type TxParams struct {
type BalanceTransactionParams struct {
Params `form:"*"`
}

// TxListParams is the set of parameters that can be used when listing balance transactions.
// BalanceTransactionListParams is the set of parameters that can be used when listing balance transactions.
// For more details see https://stripe.com/docs/api/#balance_history.
type TxListParams struct {
ListParams `form:"*"`
Available int64 `form:"available_on"`
AvailableRange *RangeQueryParams `form:"available_on"`
Created int64 `form:"created"`
CreatedRange *RangeQueryParams `form:"created"`
Currency string `form:"currency"`
Payout string `form:"payout"`
Src string `form:"source"`
Type TransactionType `form:"type"`
type BalanceTransactionListParams struct {
ListParams `form:"*"`
AvailableOn int64 `form:"available_on"`
AvailableOnRange *RangeQueryParams `form:"available_on"`
Created int64 `form:"created"`
CreatedRange *RangeQueryParams `form:"created"`
Currency string `form:"currency"`
Payout string `form:"payout"`
Source string `form:"source"`
Type BalanceTransactionType `form:"type"`
}

// Balance is the resource representing your Stripe balance.
// For more details see https://stripe.com/docs/api/#balance.
type Balance struct {
Available []Amount `json:"available"`
Live bool `json:"livemode"`
Livemode bool `json:"livemode"`
Pending []Amount `json:"pending"`
}

// Transaction is the resource representing the balance transaction.
// BalanceTransaction is the resource representing the balance transaction.
// For more details see https://stripe.com/docs/api/#balance.
type Transaction struct {
Amount int64 `json:"amount"`
Available int64 `json:"available_on"`
Created int64 `json:"created"`
Currency Currency `json:"currency"`
Desc string `json:"description"`
ID string `json:"id"`
Fee int64 `json:"fee"`
FeeDetails []TxFee `json:"fee_details"`
Net int64 `json:"net"`
Recipient string `json:"recipient"`
Src TransactionSource `json:"source"`
Status TransactionStatus `json:"status"`
Type TransactionType `json:"type"`
type BalanceTransaction struct {
Amount int64 `json:"amount"`
AvailableOn int64 `json:"available_on"`
Created int64 `json:"created"`
Currency Currency `json:"currency"`
Description string `json:"description"`
ID string `json:"id"`
Fee int64 `json:"fee"`
FeeDetails []BalanceTransactionFee `json:"fee_details"`
Net int64 `json:"net"`
Recipient string `json:"recipient"`
Source BalanceTransactionSource `json:"source"`
Status BalanceTransactionStatus `json:"status"`
Type BalanceTransactionType `json:"type"`
}

// TransactionList is a list of transactions as returned from a list endpoint.
type TransactionList struct {
// BalanceTransactionList is a list of transactions as returned from a list endpoint.
type BalanceTransactionList struct {
ListMeta
Values []*Transaction `json:"data"`
Data []*BalanceTransaction `json:"data"`
}

// Amount is a structure wrapping an amount value and its currency.
Expand All @@ -120,24 +120,24 @@ type Amount struct {
Currency Currency `json:"currency"`
}

// TxFee is a structure that breaks down the fees in a transaction.
type TxFee struct {
Application string `json:"application"`
// BalanceTransactionFee is a structure that breaks down the fees in a transaction.
type BalanceTransactionFee struct {
Amount int64 `json:"amount"`
Application string `json:"application"`
Currency Currency `json:"currency"`
Desc string `json:"description"`
Description string `json:"description"`
Type string `json:"type"`
}

// UnmarshalJSON handles deserialization of a Transaction.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
func (t *Transaction) UnmarshalJSON(data []byte) error {
type transaction Transaction
var tt transaction
func (t *BalanceTransaction) UnmarshalJSON(data []byte) error {
type bt BalanceTransaction
var tt bt
err := json.Unmarshal(data, &tt)
if err == nil {
*t = Transaction(tt)
*t = BalanceTransaction(tt)
} else {
// the id is surrounded by "\" characters, so strip them
t.ID = string(data[1 : len(data)-1])
Expand All @@ -146,32 +146,32 @@ func (t *Transaction) UnmarshalJSON(data []byte) error {
return nil
}

// UnmarshalJSON handles deserialization of a TransactionSource.
// UnmarshalJSON handles deserialization of a BalanceTransactionSource.
// This custom unmarshaling is needed because the specific
// type of transaction source it refers to is specified in the JSON
func (s *TransactionSource) UnmarshalJSON(data []byte) error {
type source TransactionSource
func (s *BalanceTransactionSource) UnmarshalJSON(data []byte) error {
type source BalanceTransactionSource
var ss source
err := json.Unmarshal(data, &ss)
if err == nil {
*s = TransactionSource(ss)
*s = BalanceTransactionSource(ss)

switch s.Type {
case TransactionSourceCharge:
case BalanceTransactionSourceTypeApplicationFee:
err = json.Unmarshal(data, &s.ApplicationFee)
case BalanceTransactionSourceTypeCharge:
err = json.Unmarshal(data, &s.Charge)
case TransactionSourceDispute:
case BalanceTransactionSourceTypeDispute:
err = json.Unmarshal(data, &s.Dispute)
case TransactionSourceFee:
err = json.Unmarshal(data, &s.Fee)
case TransactionSourcePayout:
case BalanceTransactionSourceTypePayout:
err = json.Unmarshal(data, &s.Payout)
case TransactionSourceRecipientTransfer:
case BalanceTransactionSourceTypeRecipientTransfer:
err = json.Unmarshal(data, &s.RecipientTransfer)
case TransactionSourceRefund:
case BalanceTransactionSourceTypeRefund:
err = json.Unmarshal(data, &s.Refund)
case TransactionSourceReversal:
case BalanceTransactionSourceTypeReversal:
err = json.Unmarshal(data, &s.Reversal)
case TransactionSourceTransfer:
case BalanceTransactionSourceTypeTransfer:
err = json.Unmarshal(data, &s.Transfer)
}

Expand All @@ -186,7 +186,7 @@ func (s *TransactionSource) UnmarshalJSON(data []byte) error {
return nil
}

// MarshalJSON handles serialization of a TransactionSource.
func (s *TransactionSource) MarshalJSON() ([]byte, error) {
// MarshalJSON handles serialization of a BalanceTransactionSource.
func (s *BalanceTransactionSource) MarshalJSON() ([]byte, error) {
return json.Marshal(s.ID)
}
Loading

0 comments on commit fdd38c4

Please sign in to comment.