From 09b7ba953732e1cd2e9601ae6418b991e66162e1 Mon Sep 17 00:00:00 2001 From: Remi Jannel Date: Mon, 24 Jun 2019 11:59:59 -0700 Subject: [PATCH] Add Billing changes * Add support for `CollectionMethod` on `Invoice`, `Subscription` and `SubscriptionSchedule` * Add support for `UnifiedProration` on `InvoiceLine` --- .travis.yml | 2 +- invoice.go | 40 ++++++++++++++++++++++++++++++---------- invoice/client_test.go | 4 ++-- sub.go | 25 ++++++++++++++++++++++--- sub/client_test.go | 2 +- subschedule.go | 10 ++++++++-- testing/testing.go | 2 +- 7 files changed, 65 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index b985fdddc0..3e58555247 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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" diff --git a/invoice.go b/invoice.go index 8f9fc20a11..bd703b286f 100644 --- a/invoice.go +++ b/invoice.go @@ -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. @@ -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"` @@ -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"` @@ -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"` @@ -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. @@ -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"` @@ -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"` } @@ -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. diff --git a/invoice/client_test.go b/invoice/client_test.go index ab3b4e6cec..18ee151501 100644 --- a/invoice/client_test.go +++ b/invoice/client_test.go @@ -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) diff --git a/sub.go b/sub.go index 6ce9ee12ac..a990532ed5 100644 --- a/sub.go +++ b/sub.go @@ -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. @@ -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"` @@ -41,7 +51,6 @@ 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 @@ -49,6 +58,7 @@ type SubscriptionParams struct { 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"` @@ -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"` } @@ -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"` @@ -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. @@ -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"` @@ -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"` diff --git a/sub/client_test.go b/sub/client_test.go index d57de2b6f3..53bcf82854 100644 --- a/sub/client_test.go +++ b/sub/client_test.go @@ -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) diff --git a/subschedule.go b/subschedule.go index 6e2a21fe2f..5609b43e39 100644 --- a/subschedule.go +++ b/subschedule.go @@ -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"` @@ -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 @@ -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"` @@ -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. diff --git a/testing/testing.go b/testing/testing.go index 2bf46c2960..60f4132764 100644 --- a/testing/testing.go +++ b/testing/testing.go @@ -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.