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

feat(ProgressiveBilling) Add usage_thresholds to Resources::Plan #210

Merged
merged 1 commit into from
Sep 2, 2024
Merged
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
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
Loading