~singpolyma/sgx-jmp

ref: 8dd92b96258d14d431e9966d0534631c7fdc0214 sgx-jmp/lib/admin_actions/financial.rb -rw-r--r-- 943 bytes
8dd92b96Stephen Paul Weber Merge branch 'admin-actions' 5 months 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
# frozen_string_literal: true

require_relative "../admin_action"
require_relative "../financial_info"
require_relative "../form_template"

class AdminAction
	class Financial
		def self.call(customer_id, reply:, **)
			new(customer_id, reply: reply).call
		end

		def initialize(customer_id, reply:)
			@customer_id = customer_id
			@reply = reply
		end

		def call
			AdminFinancialInfo.for(@customer_id).then do |financial_info|
				@reply.call(FormTemplate.render(
					"admin_financial_info",
					info: financial_info
				)).then {
					pay_methods(financial_info)
				}.then {
					transactions(financial_info)
				}
			end
		end

		def pay_methods(financial_info)
			@reply.call(FormTemplate.render(
				"admin_payment_methods",
				**financial_info.to_h
			))
		end

		def transactions(financial_info)
			@reply.call(FormTemplate.render(
				"admin_transaction_list",
				transactions: financial_info.transactions
			))
		end
	end
end