Skip to content

Commit

Permalink
Merge pull request #210 from getlago/feat-prog-billing-add-usage-thre…
Browse files Browse the repository at this point in the history
…sholds-to-Plan

feat(ProgressiveBilling) Add usage_thresholds to Resources::Plan
  • Loading branch information
nudded authored Sep 2, 2024
2 parents 3f96ad4 + 717a3eb commit 8ad9b33
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/lago/api/resources/plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def whitelist_params(params)
result_hash[:minimum_commitment] = minimum_commitment
end

whitelist_usage_thresholds(params[:usage_thresholds]).tap do |usage_thresholds|
result_hash[:usage_thresholds] = usage_thresholds unless usage_thresholds.empty?
end

{ root_name => result_hash }
end

Expand Down Expand Up @@ -69,6 +73,23 @@ def whitelist_charges(charges)

processed_charges
end

def whitelist_usage_thresholds(usage_thresholds)
processed_usage_thresholds = []

usage_thresholds&.each do |c|
result = (c || {}).slice(
:id,
:threshold_display_name,
:amount_cents,
:recurring,
)

processed_usage_thresholds << result unless result.empty?
end

processed_usage_thresholds
end
end
end
end
Expand Down

0 comments on commit 8ad9b33

Please sign in to comment.