sim_pricing.rb

 1# frozen_string_literal: true
 2
 3require "bigdecimal"
 4
 5module SIMPricing
 6	# SIM refill billing records currency amounts in transactions. Use BigDecimal
 7	# because the configured per-GB price is stored in cents.
 8	def self.per_gb_price(currency, config)
 9		configured_price_dollars(:per_gb, currency, config)
10	end
11
12	def self.annual_price(currency, config)
13		configured_price_dollars(:annual, currency, config)
14	end
15
16	def self.configured_price_dollars(price_type, currency, config)
17		BigDecimal(
18			config.fetch(:sims).fetch(price_type).fetch(currency)
19		) / 100
20	end
21	private_class_method :configured_price_dollars
22
23	def self.five_gb_refill_price(currency, config)
24		per_gb_price(currency, config) * 5
25	end
26
27	def self.per_gb_label(currency, config)
28		"$%.2f / GB" % per_gb_price(currency, config)
29	end
30
31	def self.plan_label(currency, config)
32		"$%.2f / GB + $%.2f / year" % [
33			per_gb_price(currency, config),
34			annual_price(currency, config)
35		]
36	end
37
38	# CustomerRepo#put_monthly_limits stores limits with to_i, so render monthly
39	# data limit form steps in that same integer-dollar unit.
40	def self.whole_dollars(price)
41		price.to_i
42	end
43end