Class: Lago::Api::Resources::Plan
- Inherits:
-
Base
- Object
- Base
- Lago::Api::Resources::Plan
show all
- Defined in:
- lib/lago/api/resources/plan.rb
Instance Attribute Summary
Attributes inherited from Base
#client
Instance Method Summary
collapse
Methods inherited from Base
#create, #destroy, #get, #get_all, #initialize, #update
Instance Method Details
#api_resource ⇒ Object
7
8
9
|
# File 'lib/lago/api/resources/plan.rb', line 7
def api_resource
'plans'
end
|
#root_name ⇒ Object
11
12
13
|
# File 'lib/lago/api/resources/plan.rb', line 11
def root_name
'plan'
end
|
#whitelist_charges(charges) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/lago/api/resources/plan.rb', line 53
def whitelist_charges(charges)
processed_charges = []
charges&.each do |c|
result = (c || {}).slice(
:id,
:billable_metric_id,
:charge_model,
:pay_in_advance,
:invoiceable,
:regroup_paid_fees,
:invoice_display_name,
:min_amount_cents,
:properties,
:filters,
:tax_codes,
)
processed_charges << result unless result.empty?
end
processed_charges
end
|
#whitelist_minimum_commitment(minimum_commitment) ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/lago/api/resources/plan.rb', line 45
def whitelist_minimum_commitment(minimum_commitment)
minimum_commitment&.slice(
:amount_cents,
:invoice_display_name,
:tax_codes,
)
end
|
#whitelist_params(params) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/lago/api/resources/plan.rb', line 15
def whitelist_params(params)
result_hash = {
name: params[:name],
invoice_display_name: params[:invoice_display_name],
code: params[:code],
interval: params[:interval],
description: params[:description],
amount_cents: params[:amount_cents],
amount_currency: params[:amount_currency],
trial_period: params[:trial_period],
pay_in_advance: params[:pay_in_advance],
bill_charges_monthly: params[:bill_charges_monthly],
tax_codes: params[:tax_codes],
}.compact
whitelist_charges(params[:charges]).tap do |charges|
result_hash[:charges] = charges unless charges.empty?
end
whitelist_minimum_commitment(params[:minimum_commitment]).tap do |minimum_commitment|
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
|
#whitelist_usage_thresholds(usage_thresholds) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/lago/api/resources/plan.rb', line 77
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
|