plan.rb

 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 currency
16		@plan[:currency]
17	end
18
19	def merchant_account
20		CONFIG[:braintree][:merchant_accounts].fetch(currency) do
21			raise "No merchant account for this currency"
22		end
23	end
24end