Skip to content

Commit

Permalink
Merge pull request #880 from stripe/remi-add-collection-method
Browse files Browse the repository at this point in the history
Add support for `CollectionMethod` on Billing resources
  • Loading branch information
remi-stripe authored Jun 25, 2019
2 parents 73810df + 09b7ba9 commit 417168e
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ cache:
env:
global:
# If changing this number, please also change it in `testing/testing.go`.
- STRIPE_MOCK_VERSION=0.58.0
- STRIPE_MOCK_VERSION=0.59.0

go:
- "1.9.x"
Expand Down
40 changes: 30 additions & 10 deletions invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (
)

// InvoiceBilling is the type of billing method for this invoice.
// This is considered deprecated. Use InvoiceCollectionMethod instead.
type InvoiceBilling string

// List of values that InvoiceBilling can take.
Expand Down Expand Up @@ -46,6 +47,15 @@ const (
InvoiceBillingStatusVoid InvoiceBillingStatus = "void"
)

// InvoiceCollectionMethod is the type of billing method for this invoice.
type InvoiceCollectionMethod string

// List of values that InvoiceBilling can take.
const (
InvoiceCollectionMethodChargeAutomatically InvoiceCollectionMethod = "charge_automatically"
InvoiceCollectionMethodSendInvoice InvoiceCollectionMethod = "send_invoice"
)

// InvoiceUpcomingInvoiceItemPeriodParams represents the period associated with that invoice item
type InvoiceUpcomingInvoiceItemPeriodParams struct {
End *int64 `form:"end"`
Expand Down Expand Up @@ -84,7 +94,7 @@ type InvoiceParams struct {
Params `form:"*"`
AutoAdvance *bool `form:"auto_advance"`
ApplicationFeeAmount *int64 `form:"application_fee_amount"`
Billing *string `form:"billing"`
CollectionMethod *string `form:"collection_method"`
CustomFields []*InvoiceCustomFieldParams `form:"custom_fields"`
Customer *string `form:"customer"`
DaysUntilDue *int64 `form:"days_until_due"`
Expand Down Expand Up @@ -117,6 +127,9 @@ type InvoiceParams struct {
// This parameter is considered deprecated. Prefer using ApplicationFeeAmount
ApplicationFee *int64 `form:"application_fee"`

// This parameter is considered deprecated. Prefer using CollectionMethod
Billing *string `form:"billing"`

// This parameter is deprecated and we recommend that you use DefaultTaxRates instead.
TaxPercent *float64 `form:"tax_percent"`

Expand All @@ -127,14 +140,17 @@ type InvoiceParams struct {
// InvoiceListParams is the set of parameters that can be used when listing invoices.
// For more details see https://stripe.com/docs/api#list_customer_invoices.
type InvoiceListParams struct {
ListParams `form:"*"`
Billing *string `form:"billing"`
Customer *string `form:"customer"`
Created *int64 `form:"created"`
CreatedRange *RangeQueryParams `form:"created"`
DueDate *int64 `form:"due_date"`
DueDateRange *RangeQueryParams `form:"due_date"`
Subscription *string `form:"subscription"`
ListParams `form:"*"`
CollectionMethod *string `form:"collection_method"`
Customer *string `form:"customer"`
Created *int64 `form:"created"`
CreatedRange *RangeQueryParams `form:"created"`
DueDate *int64 `form:"due_date"`
DueDateRange *RangeQueryParams `form:"due_date"`
Subscription *string `form:"subscription"`

// This parameter is considered deprecated. Prefer using CollectionMethod
Billing *string `form:"billing"`
}

// InvoiceLineListParams is the set of parameters that can be used when listing invoice line items.
Expand Down Expand Up @@ -195,9 +211,9 @@ type Invoice struct {
AttemptCount int64 `json:"attempt_count"`
Attempted bool `json:"attempted"`
AutoAdvance bool `json:"auto_advance"`
Billing InvoiceBilling `json:"billing"`
BillingReason InvoiceBillingReason `json:"billing_reason"`
Charge *Charge `json:"charge"`
CollectionMethod *InvoiceCollectionMethod `json:"collection_method"`
Created int64 `json:"created"`
Currency Currency `json:"currency"`
CustomFields []*InvoiceCustomField `json:"custom_fields"`
Expand Down Expand Up @@ -246,6 +262,9 @@ type Invoice struct {
TransferData *InvoiceTransferData `json:"transfer_data"`
WebhooksDeliveredAt int64 `json:"webhooks_delivered_at"`

// This property is considered deprecated. Prefer using CollectionMethod
Billing *InvoiceBilling `form:"billing"`

// This field is deprecated and we recommend that you use TaxRates instead.
TaxPercent float64 `json:"tax_percent"`
}
Expand Down Expand Up @@ -307,6 +326,7 @@ type InvoiceLine struct {
TaxAmounts []*InvoiceTaxAmount `json:"tax_amounts"`
TaxRates []*TaxRate `json:"tax_rates"`
Type InvoiceLineType `json:"type"`
UnifiedProration bool `json:"unified_proration"`
}

// InvoiceTransferData represents the information for the transfer_data associated with an invoice.
Expand Down
4 changes: 2 additions & 2 deletions invoice/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func TestInvoiceListLines(t *testing.T) {

func TestInvoiceNew(t *testing.T) {
invoice, err := New(&stripe.InvoiceParams{
Billing: stripe.String(string(stripe.InvoiceBillingChargeAutomatically)),
Customer: stripe.String("cus_123"),
CollectionMethod: stripe.String(string(stripe.InvoiceCollectionMethodChargeAutomatically)),
Customer: stripe.String("cus_123"),
})
assert.Nil(t, err)
assert.NotNil(t, invoice)
Expand Down
25 changes: 22 additions & 3 deletions sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
)

// SubscriptionBilling is the type of billing method for this subscription's invoices.
// This is considered deprecated. Use SubscriptionCollectionMethod instead.
type SubscriptionBilling string

// List of values that SubscriptionBilling can take.
Expand All @@ -30,6 +31,15 @@ const (
SubscriptionBillingSendInvoice SubscriptionBilling = "send_invoice"
)

// SubscriptionCollectionMethod is the type of billing method for this subscription's invoices.
type SubscriptionCollectionMethod string

// List of values that SubscriptionBilling can take.
const (
SubscriptionCollectionMethodChargeAutomatically SubscriptionCollectionMethod = "charge_automatically"
SubscriptionCollectionMethodSendInvoice SubscriptionCollectionMethod = "send_invoice"
)

// SubscriptionTransferDataParams is the set of parameters allowed for the transfer_data hash.
type SubscriptionTransferDataParams struct {
Destination *string `form:"destination"`
Expand All @@ -41,14 +51,14 @@ type SubscriptionParams struct {
Params `form:"*"`
ApplicationFeePercent *float64 `form:"application_fee_percent"`
BackdateStartDate *int64 `form:"backdate_start_date"`
Billing *string `form:"billing"`
BillingCycleAnchor *int64 `form:"billing_cycle_anchor"`
BillingCycleAnchorNow *bool `form:"-"` // See custom AppendTo
BillingCycleAnchorUnchanged *bool `form:"-"` // See custom AppendTo
BillingThresholds *SubscriptionBillingThresholdsParams `form:"billing_thresholds"`
CancelAt *int64 `form:"cancel_at"`
CancelAtPeriodEnd *bool `form:"cancel_at_period_end"`
Card *CardParams `form:"card"`
CollectionMethod *string `form:"collection_method"`
Coupon *string `form:"coupon"`
Customer *string `form:"customer"`
DaysUntilDue *int64 `form:"days_until_due"`
Expand All @@ -67,6 +77,9 @@ type SubscriptionParams struct {
TrialFromPlan *bool `form:"trial_from_plan"`
TrialPeriodDays *int64 `form:"trial_period_days"`

// This parameter is deprecated and we recommend that you use CollectionMethod instead.
Billing *string `form:"billing"`

// This parameter is deprecated and we recommend that you use TaxRates instead.
TaxPercent *float64 `form:"tax_percent"`
}
Expand Down Expand Up @@ -120,7 +133,7 @@ type SubscriptionItemsParams struct {
// For more details see https://stripe.com/docs/api#list_subscriptions.
type SubscriptionListParams struct {
ListParams `form:"*"`
Billing string `form:"billing"`
CollectionMethod *string `form:"collection_method"`
Created int64 `form:"created"`
CreatedRange *RangeQueryParams `form:"created"`
CurrentPeriodEnd *int64 `form:"current_period_end"`
Expand All @@ -130,6 +143,9 @@ type SubscriptionListParams struct {
Customer string `form:"customer"`
Plan string `form:"plan"`
Status string `form:"status"`

// This parameter is deprecated and we recommend that you use CollectionMethod instead.
Billing *string `form:"billing"`
}

// SubscriptionTransferData represents the information for the transfer_data associated with a subscription.
Expand All @@ -141,12 +157,12 @@ type SubscriptionTransferData struct {
// For more details see https://stripe.com/docs/api#subscriptions.
type Subscription struct {
ApplicationFeePercent float64 `json:"application_fee_percent"`
Billing SubscriptionBilling `json:"billing"`
BillingCycleAnchor int64 `json:"billing_cycle_anchor"`
BillingThresholds *SubscriptionBillingThresholds `json:"billing_thresholds"`
CancelAt int64 `json:"cancel_at"`
CancelAtPeriodEnd bool `json:"cancel_at_period_end"`
CanceledAt int64 `json:"canceled_at"`
CollectionMethod SubscriptionCollectionMethod `json:"collection_method"`
Created int64 `json:"created"`
CurrentPeriodEnd int64 `json:"current_period_end"`
CurrentPeriodStart int64 `json:"current_period_start"`
Expand All @@ -172,6 +188,9 @@ type Subscription struct {
TrialEnd int64 `json:"trial_end"`
TrialStart int64 `json:"trial_start"`

// This field is deprecated and we recommend that you use CollectionMethod instead.
Billing SubscriptionBilling `json:"billing"`

// This field is deprecated and we recommend that you use StartDate instead.
Start int64 `json:"start"`

Expand Down
2 changes: 1 addition & 1 deletion sub/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestSubscriptionNew(t *testing.T) {
},
},
BillingCycleAnchor: stripe.Int64(time.Now().AddDate(0, 0, 12).Unix()),
Billing: stripe.String(string(stripe.SubscriptionBillingSendInvoice)),
CollectionMethod: stripe.String(string(stripe.SubscriptionCollectionMethodChargeAutomatically)),
DaysUntilDue: stripe.Int64(30),
})
assert.Nil(t, err)
Expand Down
10 changes: 8 additions & 2 deletions subschedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ type SubscriptionScheduleRenewalIntervalParams struct {
// subscription schedule.
type SubscriptionScheduleParams struct {
Params `form:"*"`
Billing *string `form:"billing"`
BillingThresholds *SubscriptionBillingThresholdsParams `form:"billing_thresholds"`
CollectionMethod *string `form:"collection_method"`
Customer *string `form:"customer"`
FromSubscription *string `form:"from_subscription"`
InvoiceSettings *SubscriptionScheduleInvoiceSettingsParams `form:"invoice_settings"`
Expand All @@ -79,6 +79,9 @@ type SubscriptionScheduleParams struct {
RenewalBehavior *string `form:"renewal_behavior"`
RenewalInterval *SubscriptionScheduleRenewalIntervalParams `form:"renewal_interval"`
StartDate *int64 `form:"start_date"`

// This parameter is deprecated and we recommend that you use CollectionMethod instead.
Billing *string `form:"billing"`
}

// SubscriptionScheduleCancelParams is the set of parameters that can be used when canceling a
Expand Down Expand Up @@ -154,9 +157,9 @@ type SubscriptionScheduleRenewalInterval struct {

// SubscriptionSchedule is the resource representing a Stripe subscription schedule.
type SubscriptionSchedule struct {
Billing SubscriptionBilling `json:"billing"`
BillingThresholds *SubscriptionBillingThresholds `json:"billing_thresholds"`
CanceledAt int64 `json:"canceled_at"`
CollectionMethod SubscriptionCollectionMethod `json:"collection_method"`
CompletedAt int64 `json:"completed_at"`
Created int64 `json:"created"`
CurrentPhase *SubscriptionScheduleCurrentPhase `json:"current_phase"`
Expand All @@ -173,6 +176,9 @@ type SubscriptionSchedule struct {
RenewalInterval *SubscriptionScheduleRenewalInterval `json:"renewal_interval"`
Status SubscriptionScheduleStatus `json:"status"`
Subscription *Subscription `json:"subscription"`

// This field is deprecated and we recommend that you use CollectionMethod instead.
Billing SubscriptionBilling `json:"billing"`
}

// SubscriptionScheduleList is a list object for subscription schedules.
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.58.0"
MockMinimumVersion = "0.59.0"

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

0 comments on commit 417168e

Please sign in to comment.