~singpolyma/sgx-jmp

ref: 938e2d7a1a3f27c34baac60a6debcd55cff1bcf7 sgx-jmp/lib/command_list.rb -rw-r--r-- 1.3 KiB
938e2d7aStephen Paul Weber Command to get to the credit card settings page 1 year, 1 month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# frozen_string_literal: true

class CommandList
	include Enumerable

	def self.for(jid)
		Customer.for_jid(jid).catch { nil }.then do |customer|
			EMPromise.resolve(customer&.registered?).catch { nil }.then do |reg|
				next Registered.for(customer, reg.phone) if reg
				CommandList.new
			end
		end
	end

	def each
		yield node: "jabber:iq:register", name: "Register"
	end

	class Registered < CommandList
		def self.for(customer, tel)
			EMPromise.all([
				REDIS.get("catapult_fwd-#{tel}"),
				customer.plan_name ? customer.payment_methods : []
			]).then do |(fwd, payment_methods)|
				klass = Class.new(Registered)
				klass.include(HasBilling) unless payment_methods.empty?
				klass.include(HasForwarding) if fwd
				klass.new
			end
		end

		def each
			super
			yield node: "number-display", name: "Display JMP Number"
			yield node: "configure-calls", name: "Configure Calls"
			yield node: "usage", name: "Show Monthly Usage"
			yield node: "reset sip account", name: "Create or Reset SIP Account"
			yield(
				node: "credit cards",
				name: "Credit Card Settings and Management"
			)
		end
	end

	module HasForwarding
		def each
			super
			yield(
				node: "record-voicemail-greeting",
				name: "Record Voicemail Greeting"
			)
		end
	end

	module HasBilling
		def each
			super
			yield node: "buy credit", name: "Buy account credit"
		end
	end
end