Skip to content

Commit

Permalink
Price Recurring interval_count required when interval set (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasaron authored Feb 5, 2024
1 parent d0bb7a0 commit baa23cd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/resources/stripe_price.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Arguments accepted by this resource include:
Allowed values are `sum` for summing up all usage during a period, `last_during_period` for using the last usage
record reported within a period, `last_ever` for using the last usage record ever (across period bounds) or `max`
which uses the usage record with the maximum reported usage during a period.
* `interval_count` - (Optional) Int. The number of intervals between subscription billings. For
* `interval_count` - (Optional) Int. This parameter is (Required) when interval value is set. The number of intervals between subscription billings. For
example, `interval=month` and `interval_count=3` bills every 3 months. Maximum of one year interval allowed (1 year,
12 months, or 52 weeks).
* `usage_type` - (Optional) String. Configures how the quantity per period should be determined. Can be either `metered`
Expand Down
8 changes: 5 additions & 3 deletions stripe/resource_stripe_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,14 +500,16 @@ func resourceStripePriceCreate(ctx context.Context, d *schema.ResourceData, m in
}
if recurring, set := d.GetOk("recurring"); set {
params.Recurring = &stripe.PriceRecurringParams{}
for k, v := range ToMap(recurring) {
recurringMap := ToMap(recurring)
for k, v := range recurringMap {
switch {
case k == "interval" && ToString(v) != "":
params.Recurring.Interval = stripe.String(ToString(v))
case k == "interval_count" && ToString(recurringMap["interval"]) != "":
params.Recurring.IntervalCount = stripe.Int64(ToInt64(v))
case k == "aggregate_usage" && ToString(v) != "":
params.Recurring.AggregateUsage = stripe.String(ToString(v))
case k == "interval_count" && ToInt64(v) != 0:
params.Recurring.IntervalCount = stripe.Int64(ToInt64(v))

case k == "usage_type" && ToString(v) != "":
params.Recurring.UsageType = stripe.String(ToString(v))
}
Expand Down

0 comments on commit baa23cd

Please sign in to comment.