Class: Hps::ExceptionMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/hps/infrastructure/hps_exception_mapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExceptionMapper

Returns a new instance of ExceptionMapper.



8
9
10
11
12
13
14
# File 'lib/hps/infrastructure/hps_exception_mapper.rb', line 8

def initialize
	path = File.join( File.dirname(__FILE__), "exceptions.json")

	File.open(path, "r") do |f|
		@exceptions = JSON.load(f)
	end
end

Instance Attribute Details

#exceptionsObject (readonly)

Returns the value of attribute exceptions.



6
7
8
# File 'lib/hps/infrastructure/hps_exception_mapper.rb', line 6

def exceptions
  @exceptions
end

Instance Method Details

#map_gateway_exception(transaction_id, response_code, response_text) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/hps/infrastructure/hps_exception_mapper.rb', line 45

def map_gateway_exception(transaction_id, response_code, response_text)

	mapping = exception_for_category_and_code("gateway", response_code)
	message = message_for_mapping(mapping, response_text)

	unless mapping.nil?

		code = mapping["mapping_code"]
		exception_type = mapping["mapping_type"]

		if exception_type == "AuthenticationException"

			return AuthenticationException.new(message)

		elsif exception_type == "CardException"

			return CardException.new(transaction_id, code, message)

		elsif exception_type == "InvalidRequestException"

			return InvalidRequestException.new(message, mapping["param"], code)

		elsif !code.nil?

			return HpsException.new(response_text, code)

		end

	end

	HpsException.new(message, "unknown")
end

#map_gift_card_exception(transaction_id, response_code, response_text) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/hps/infrastructure/hps_exception_mapper.rb', line 34

def map_gift_card_exception(transaction_id, response_code, response_text)
 mapping = exception_for_category_and_code("gift", response_code)
 unless mapping.nil?
	 message = message_for_mapping(mapping, response_text)
	 code = mapping["mapping_code"]
	 return CardException.new(transaction_id, code, message)
 else
	 return CardException.new(transaction_id, "unknown_card_exception", response_text)
 end
end

#map_issuer_exception(transaction_id, response_code, response_text) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/hps/infrastructure/hps_exception_mapper.rb', line 20

def map_issuer_exception(transaction_id, response_code, response_text)

	mapping = exception_for_category_and_code("issuer", response_code)

	unless mapping.nil?
		message = message_for_mapping(mapping, response_text)
		code = mapping["mapping_code"]
		return CardException.new(transaction_id, code, message)
	else
		return CardException.new(transaction_id, "unknown_card_exception", response_text)
	end

end

#map_sdk_exception(error_code, inner_exception = nil) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/hps/infrastructure/hps_exception_mapper.rb', line 78

def map_sdk_exception(error_code, inner_exception = nil)

	mapping = exception_for_category_and_code("sdk", error_code)
	sdk_code_name = SdkCodes.instance_methods.detect { |m| SdkCodes.send(m) == error_code }

	if sdk_code_name.nil?
		response_text = "unknown"
	else
		response_text = sdk_code_name
	end

	unless mapping.nil?

			message = message_for_mapping(mapping, response_text)
			code = mapping["mapping_code"]
			exception_type = mapping["mapping_type"]

			if exception_type == "InvalidRequestException"

				return InvalidRequestException.new(message, mapping["param"], code)

			elsif exception_type == "ApiConnectionException"

				return ApiConnectionException.new(message, inner_exception, code)

			elsif !code.nil?

				return HpsException.new(message, code)

			end

	end

	HpsException.new("unknown", "unknown", inner_exception)

end

#version_numberObject



16
17
18
# File 'lib/hps/infrastructure/hps_exception_mapper.rb', line 16

def version_number
	@exceptions["version"]
end