Skip to content

Commit

Permalink
Merge pull request #668 from stripe/remi-api-version-2018-08-23
Browse files Browse the repository at this point in the history
Move to API version 2018-08-23
  • Loading branch information
brandur-stripe authored Aug 23, 2018
2 parents 9686b72 + 3cf614b commit 8938208
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ cache:
env:
global:
# If changing this number, please also change it in `testing/testing.go`.
- STRIPE_MOCK_VERSION=0.26.0
- STRIPE_MOCK_VERSION=0.27.0

go:
- "1.7"
Expand Down
71 changes: 54 additions & 17 deletions customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,29 @@ import (
"encoding/json"
)

// CustomerTaxInfoType is the type of tax info associated with a customer.
type CustomerTaxInfoType string

// List of values that CustomerTaxInfoType can take.
const (
CustomerTaxInfoTypeVAT CustomerTaxInfoType = "vat"
)

// CustomerTaxInfoVerificationStatus is the type of tax info associated with a customer.
type CustomerTaxInfoVerificationStatus string

// List of values that CustomerTaxInfoType can take.
const (
CustomerTaxInfoVerificationStatusPending CustomerTaxInfoVerificationStatus = "pending"
CustomerTaxInfoVerificationStatusUnverified CustomerTaxInfoVerificationStatus = "unverified"
CustomerTaxInfoVerificationStatusVerified CustomerTaxInfoVerificationStatus = "verified"
)

// CustomerParams is the set of parameters that can be used when creating or updating a customer.
// For more details see https://stripe.com/docs/api#create_customer and https://stripe.com/docs/api#update_customer.
type CustomerParams struct {
Params `form:"*"`
AccountBalance *int64 `form:"account_balance"`
BusinessVATID *string `form:"business_vat_id"`
Coupon *string `form:"coupon"`
DefaultSource *string `form:"default_source"`
Description *string `form:"description"`
Expand All @@ -18,6 +35,7 @@ type CustomerParams struct {
Quantity *int64 `form:"quantity"`
Shipping *CustomerShippingDetailsParams `form:"shipping"`
Source *SourceParams `form:"*"` // SourceParams has custom encoding so brought to top level with "*"
TaxInfo *CustomerTaxInfoParams `form:"tax_info"`
TaxPercent *float64 `form:"tax_percent"`
Token *string `form:"-"` // This doesn't seem to be used?
TrialEnd *int64 `form:"trial_end"`
Expand All @@ -30,6 +48,12 @@ type CustomerShippingDetailsParams struct {
Phone *string `form:"phone"`
}

// CustomerTaxInfoParams is the structure containing tax information for the customer.
type CustomerTaxInfoParams struct {
TaxID *string `form:"tax_id"`
Type *string `form:"type"`
}

// SetSource adds valid sources to a CustomerParams object,
// returning an error for unsupported sources.
func (cp *CustomerParams) SetSource(sp interface{}) error {
Expand All @@ -49,22 +73,23 @@ type CustomerListParams struct {
// Customer is the resource representing a Stripe customer.
// For more details see https://stripe.com/docs/api#customers.
type Customer struct {
AccountBalance int64 `json:"account_balance"`
BusinessVATID string `json:"business_vat_id"`
Created int64 `json:"created"`
Currency Currency `json:"currency"`
DefaultSource *PaymentSource `json:"default_source"`
Deleted bool `json:"deleted"`
Delinquent bool `json:"delinquent"`
Description string `json:"description"`
Discount *Discount `json:"discount"`
Email string `json:"email"`
ID string `json:"id"`
Livemode bool `json:"livemode"`
Metadata map[string]string `json:"metadata"`
Shipping *CustomerShippingDetails `json:"shipping"`
Sources *SourceList `json:"sources"`
Subscriptions *SubscriptionList `json:"subscriptions"`
AccountBalance int64 `json:"account_balance"`
Created int64 `json:"created"`
Currency Currency `json:"currency"`
DefaultSource *PaymentSource `json:"default_source"`
Deleted bool `json:"deleted"`
Delinquent bool `json:"delinquent"`
Description string `json:"description"`
Discount *Discount `json:"discount"`
Email string `json:"email"`
ID string `json:"id"`
Livemode bool `json:"livemode"`
Metadata map[string]string `json:"metadata"`
Shipping *CustomerShippingDetails `json:"shipping"`
Sources *SourceList `json:"sources"`
Subscriptions *SubscriptionList `json:"subscriptions"`
TaxInfo *CustomerTaxInfo `json:"tax_info"`
TaxInfoVerification *CustomerTaxInfoVerification `json:"tax_info_verification"`
}

// CustomerList is a list of customers as retrieved from a list endpoint.
Expand All @@ -80,6 +105,18 @@ type CustomerShippingDetails struct {
Phone string `json:"phone"`
}

// CustomerTaxInfo is the structure containing tax information for the customer.
type CustomerTaxInfo struct {
TaxID string `json:"tax_info"`
Type CustomerTaxInfoType `json:"type"`
}

// CustomerTaxInfoVerification is the structure containing tax verification for the customer.
type CustomerTaxInfoVerification struct {
Status CustomerTaxInfoVerificationStatus `json:"status"`
VerifiedName string `json:"verified_name"`
}

// UnmarshalJSON handles deserialization of a Customer.
// This custom unmarshaling is needed because the resulting
// property may be an id or the full struct if it was expanded.
Expand Down
12 changes: 6 additions & 6 deletions plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ type PlanParams struct {

// PlanTier configures tiered pricing
type PlanTier struct {
Amount int64 `json:"amount"`
UpTo int64 `json:"up_to"`
UnitAmount int64 `json:"unit_amount"`
UpTo int64 `json:"up_to"`
}

// PlanTransformUsage represents the bucket billing configuration.
Expand All @@ -146,10 +146,10 @@ type PlanTransformUsageParams struct {

// PlanTierParams configures tiered pricing
type PlanTierParams struct {
Params `form:"*"`
Amount *int64 `form:"amount"`
UpTo *int64 `form:"-"` // handled in custom AppendTo
UpToInf *bool `form:"-"` // handled in custom AppendTo
Params `form:"*"`
UnitAmount *int64 `form:"unit_amount"`
UpTo *int64 `form:"-"` // handled in custom AppendTo
UpToInf *bool `form:"-"` // handled in custom AppendTo
}

// AppendTo implements custom up_to serialisation logic for tiers configuration
Expand Down
10 changes: 5 additions & 5 deletions plan/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ func TestPlanNew(t *testing.T) {
StatementDescriptor: stripe.String("statement descriptor"),
},
Tiers: []*stripe.PlanTierParams{
{Amount: stripe.Int64(500), UpTo: stripe.Int64(5)},
{Amount: stripe.Int64(400), UpTo: stripe.Int64(10)},
{Amount: stripe.Int64(300), UpTo: stripe.Int64(15)},
{Amount: stripe.Int64(200), UpTo: stripe.Int64(20)},
{Amount: stripe.Int64(200), UpToInf: stripe.Bool(true)},
{UnitAmount: stripe.Int64(500), UpTo: stripe.Int64(5)},
{UnitAmount: stripe.Int64(400), UpTo: stripe.Int64(10)},
{UnitAmount: stripe.Int64(300), UpTo: stripe.Int64(15)},
{UnitAmount: stripe.Int64(200), UpTo: stripe.Int64(20)},
{UnitAmount: stripe.Int64(200), UpToInf: stripe.Bool(true)},
},
})
assert.Nil(t, err)
Expand Down
8 changes: 4 additions & 4 deletions plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func TestPlanParams_AppendTo(t *testing.T) {
StatementDescriptor: String("SAPPHIRE"),
}
tiers := []*PlanTierParams{
{Amount: Int64(123), UpTo: Int64(321)},
{Amount: Int64(123), UpToInf: Bool(true)}}
{UnitAmount: Int64(123), UpTo: Int64(321)},
{UnitAmount: Int64(123), UpToInf: Bool(true)}}
testCases := []struct {
field string
params *PlanParams
Expand All @@ -62,9 +62,9 @@ func TestPlanParams_AppendTo(t *testing.T) {
{"product[name]", &PlanParams{Product: &productParams}, "Sapphire Elite"},
{"product[statement_descriptor]", &PlanParams{Product: &productParams}, "SAPPHIRE"},
{"product", &PlanParams{ProductID: String("prod_123abc")}, "prod_123abc"}, {"tiers_mode", &PlanParams{TiersMode: String(string(PlanTiersModeVolume))}, "volume"},
{"tiers[0][amount]", &PlanParams{Tiers: tiers}, strconv.FormatUint(123, 10)},
{"tiers[0][unit_amount]", &PlanParams{Tiers: tiers}, strconv.FormatUint(123, 10)},
{"tiers[0][up_to]", &PlanParams{Tiers: tiers}, strconv.FormatUint(321, 10)},
{"tiers[1][amount]", &PlanParams{Tiers: tiers}, strconv.FormatUint(123, 10)},
{"tiers[1][unit_amount]", &PlanParams{Tiers: tiers}, strconv.FormatUint(123, 10)},
{"tiers[1][up_to]", &PlanParams{Tiers: tiers}, "inf"},
{"transform_usage[divide_by]", &PlanParams{TransformUsage: &PlanTransformUsageParams{DivideBy: Int64(123), Round: String("round_up")}}, strconv.FormatUint(123, 10)},
{"transform_usage[round]", &PlanParams{TransformUsage: &PlanTransformUsageParams{DivideBy: Int64(123), Round: String("round_up")}}, "round_up"},
Expand Down
2 changes: 1 addition & 1 deletion stripe.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ func StringValue(v *string) string {
const apiURL = "https://api.stripe.com"

// apiversion is the currently supported API version
const apiversion = "2018-07-27"
const apiversion = "2018-08-23"

// clientversion is the binding version
const clientversion = "42.3.0"
Expand Down
3 changes: 1 addition & 2 deletions sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ type SubscriptionParams struct {
// SubscriptionCancelParams is the set of parameters that can be used when canceling a subscription.
// For more details see https://stripe.com/docs/api#cancel_subscription
type SubscriptionCancelParams struct {
Params `form:"*"`
AtPeriodEnd *bool `form:"at_period_end"`
Params `form:"*"`
}

// AppendTo implements custom encoding logic for SubscriptionParams so that the special
Expand Down
4 changes: 1 addition & 3 deletions sub/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import (
)

func TestSubscriptionCancel(t *testing.T) {
subscription, err := Cancel("sub_123", &stripe.SubscriptionCancelParams{
AtPeriodEnd: stripe.Bool(true),
})
subscription, err := Cancel("sub_123", &stripe.SubscriptionCancelParams{})
assert.Nil(t, err)
assert.NotNil(t, subscription)
}
Expand Down
2 changes: 1 addition & 1 deletion testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
// added in a more recent version of stripe-mock, we can show people a
// better error message instead of the test suite crashing with a bunch of
// confusing 404 errors or the like.
MockMinimumVersion = "0.26.0"
MockMinimumVersion = "0.27.0"

// TestMerchantID is a token that can be used to represent a merchant ID in
// simple tests.
Expand Down

0 comments on commit 8938208

Please sign in to comment.