diff --git a/lib/lago/api/resources/plan.rb b/lib/lago/api/resources/plan.rb index 6ee7f29..e92d146 100644 --- a/lib/lago/api/resources/plan.rb +++ b/lib/lago/api/resources/plan.rb @@ -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 @@ -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