# 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