1# frozen_string_literal: true
2
3class Plan
4 def self.for(plan_name)
5 plan = CONFIG[:plans].find { |p| p[:name] == plan_name }
6 raise "No plan by that name" unless plan
7
8 new(plan)
9 end
10
11 def initialize(plan)
12 @plan = plan
13 end
14
15 def name
16 @plan[:name]
17 end
18
19 def currency
20 @plan[:currency]
21 end
22
23 def monthly_price
24 BigDecimal(@plan[:monthly_price]) / 10000
25 end
26
27 def merchant_account
28 CONFIG[:braintree][:merchant_accounts].fetch(currency) do
29 raise "No merchant account for this currency"
30 end
31 end
32end