~singpolyma/jmp-pay

ref: 68ed9c34b0d4a2eaa0e49def372deabe4eb55daf jmp-pay/lib/three_d_secure_repo.rb -rw-r--r-- 924 bytes
68ed9c34Stephen Paul Weber Run billing 3 at a time 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
46
# frozen_string_literal: true

class ThreeDSecureRepo
	class Failed < StandardError; end

	def initialize(redis: REDIS)
		@redis = redis
	end

	def find(customer_id, token)
		redis(:hget, customer_id, token)
	end

	def put(customer_id, token, authid)
		if !authid || authid.empty?
			redis(:hdel, customer_id, token)
		else
			redis(:hset, customer_id, token, authid)
		end
	end

	def put_from_payment_method(customer_id, method)
		return unless method.verification # Already vaulted

		three_d = method.verification.three_d_secure_info
		if !three_d ||
		   (three_d.liability_shift_possible && !three_d.liability_shifted)
			raise Failed, method.token
		end

		put(
			customer_id, method.token,
			three_d.three_d_secure_authentication_id
		)
	end

protected

	def redis(action, customer_id, *args)
		@redis.public_send(
			action,
			"jmp_customer_three_d_secure_authentication_id-#{customer_id}",
			*args
		)
	end
end