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

Fix ApplicationFeePercent on SubscriptionSchedule to support floats #1145

Merged
merged 1 commit into from
Jul 27, 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
36 changes: 19 additions & 17 deletions subschedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,25 @@ type SubscriptionSchedulePhaseItemParams struct {
// SubscriptionSchedulePhaseParams is a structure representing the parameters allowed to control
// a phase on a subscription schedule.
type SubscriptionSchedulePhaseParams struct {
AddInvoiceItems []*SubscriptionSchedulePhaseAddInvoiceItemParams `form:"add_invoice_items"`
ApplicationFeePercent *int64 `form:"application_fee_percent"`
BillingCycleAnchor *string `form:"billing_cycle_anchor"`
BillingThresholds *SubscriptionBillingThresholdsParams `form:"billing_thresholds"`
CollectionMethod *string `form:"collection_method"`
Coupon *string `form:"coupon"`
DefaultPaymentMethod *string `form:"default_payment_method"`
DefaultTaxRates []*string `form:"default_tax_rates"`
EndDate *int64 `form:"end_date"`
InvoiceSettings *SubscriptionScheduleInvoiceSettingsParams `form:"invoice_settings"`
Iterations *int64 `form:"iterations"`
Plans []*SubscriptionSchedulePhaseItemParams `form:"plans"`
ProrationBehavior *string `form:"proration_behavior"`
StartDate *int64 `form:"start_date"`
TransferData *SubscriptionTransferDataParams `form:"transfer_data"`
Trial *bool `form:"trial"`
TrialEnd *int64 `form:"trial_end"`
AddInvoiceItems []*SubscriptionSchedulePhaseAddInvoiceItemParams `form:"add_invoice_items"`
// This parameter expects a *float64 but was defined as *int64 so we're adding support for both
// TODO: Remove in the next major
ApplicationFeePercent interface{} `form:"application_fee_percent"`
BillingCycleAnchor *string `form:"billing_cycle_anchor"`
BillingThresholds *SubscriptionBillingThresholdsParams `form:"billing_thresholds"`
CollectionMethod *string `form:"collection_method"`
Coupon *string `form:"coupon"`
DefaultPaymentMethod *string `form:"default_payment_method"`
DefaultTaxRates []*string `form:"default_tax_rates"`
EndDate *int64 `form:"end_date"`
InvoiceSettings *SubscriptionScheduleInvoiceSettingsParams `form:"invoice_settings"`
Iterations *int64 `form:"iterations"`
Plans []*SubscriptionSchedulePhaseItemParams `form:"plans"`
ProrationBehavior *string `form:"proration_behavior"`
StartDate *int64 `form:"start_date"`
TransferData *SubscriptionTransferDataParams `form:"transfer_data"`
Trial *bool `form:"trial"`
TrialEnd *int64 `form:"trial_end"`

// This parameter is deprecated and we recommend that you use TaxRates instead.
TaxPercent *float64 `form:"tax_percent"`
Expand Down
30 changes: 30 additions & 0 deletions subschedule/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,36 @@ func TestSubscriptionScheduleNew(t *testing.T) {
assert.Nil(t, err)
assert.NotNil(t, schedule)
}
func TestSubscriptionScheduleNew_ApplicationFeePercent(t *testing.T) {
params := &stripe.SubscriptionScheduleParams{
Customer: stripe.String("cus_123"),
StartDateNow: stripe.Bool(true),
Phases: []*stripe.SubscriptionSchedulePhaseParams{
{
ApplicationFeePercent: stripe.Float64(10.123),
Plans: []*stripe.SubscriptionSchedulePhaseItemParams{
{
Plan: stripe.String("plan_123"),
Quantity: stripe.Int64(10),
},
},
},
{
ApplicationFeePercent: stripe.Int64(10),
Plans: []*stripe.SubscriptionSchedulePhaseItemParams{
{
Plan: stripe.String("plan_789"),
Quantity: stripe.Int64(30),
},
},
},
},
EndBehavior: stripe.String(string(stripe.SubscriptionScheduleEndBehaviorCancel)),
}
schedule, err := New(params)
assert.Nil(t, err)
assert.NotNil(t, schedule)
}

func TestSubscriptionScheduleRelease(t *testing.T) {
params := &stripe.SubscriptionScheduleReleaseParams{
Expand Down