Completed
Pull Request — master (#126)
by
unknown
01:39
created

KeyValueResponse.response_reason_text()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
module AuthorizeNet
2
  # The core, key/value response class. You shouldn't instantiate this one.
3
  # Instead you should use AuthorizeNet::AIM::Response or AuthorizeNet::SIM::Response.
4
  class KeyValueResponse < AuthorizeNet::Response
5
    # Defines constants for each response code.
6
    module ResponseCode
7
      APPROVED = '1'.freeze
8
      DECLINED = '2'.freeze
9
      ERROR = '3'.freeze
10
      HELD = '4'.freeze
11
    end
12
13
    # Defines constants for each address verification response code.
14
    module AVSResponseCode
15
      ADDRESS_MATCH_NOT_ZIP = 'A'.freeze
16
      NO_INFO = 'B'.freeze
17
      ERROR = 'E'.freeze
18
      NON_US = 'G'.freeze
19
      NO_MATCH = 'N'.freeze
20
      NOT_APPLICABLE = 'P'.freeze
21
      RETRY = 'R'.freeze
22
      NOT_SUPPOPRTED = 'S'.freeze
23
      UNAVAILABLE = 'U'.freeze
24
      ZIP9_MATCH_NOT_ADDRESS = 'W'.freeze
25
      ADDRESS_AND_ZIP9_MATCH = 'X'.freeze
26
      ADDRESS_AND_ZIP5_MATCH = 'Y'.freeze
27
      ZIP5_MATCH_NOT_ADDRESS = 'Z'.freeze
28
    end
29
30
    # Defines constants for each supported credit card type.
31
    module CardType
32
      VISA = 'Visa'.freeze
33
      MASTER_CARD = 'MasterCard'.freeze
34
      AMEX = 'American Express'.freeze
35
      DISCOVER = 'Discover'.freeze
36
      DINERS_CLUB = 'Diners Club'.freeze
37
      JCB = 'JCB'.freeze
38
    end
39
40
    # Defines constants for CCV code validation responses.
41
    module CCVResponseCode
42
      MATCH = 'M'.freeze
43
      NO_MATCH = 'N'.freeze
44
      NOT_PROCESSED = 'P'.freeze
45
      SHOULD_HAVE_BEEN_PRESENT = 'S'.freeze
46
      UNABLE_TO_PROCESS = 'U'.freeze
47
    end
48
49
    # Defines constants for CAVV code validation responses.
50
    module CAVVResponseCode
51
      ERRONEOUS_DATA = '0'.freeze
52
      FAILED_VALIDATION = '1'.freeze
53
      PASSED_VALIDATION = '2'.freeze
54
      ISSUER_ATTEMPT_INCOMPLETE = '3'.freeze
55
      ISSUER_SYSTEM_ERROR = '4'.freeze
56
      FAILED_ISSUER_AVAILABLE = '7'.freeze
57
      PASSED_ISSUER_AVAILABLE = '8'.freeze
58
      FAILED_ISSUER_UNAVAILABLE = '9'.freeze
59
      PASSED_ISSUER_UNAVAILABLE = 'A'.freeze
60
      PASSED_NO_LIABILITY_SHIFT = 'B'.freeze
61
    end
62
63
    # Check to see if the transaction was approved.
64
    def approved?
65
      @fields[:response_code] == ResponseCode::APPROVED
66
    end
67
68
    # Check to see if the transaction was declined.
69
    def declined?
70
      @fields[:response_code] == ResponseCode::DECLINED
71
    end
72
73
    # Check to see if the transaction was returned with an error.
74
    def error?
75
      @fields[:response_code] == ResponseCode::ERROR
76
    end
77
78
    # Check to see if the transaction was held for review by Authorize.Net.
79
    def held?
80
      @fields[:response_code] == ResponseCode::HELD
81
    end
82
83
    # Returns the response code received from the gateway. Note: its better to use
84
    # success?, approved?, etc. to check the response code.
85
    def response_code
86
      @fields[:response_code]
87
    end
88
89
    # Returns the response reason code received from the gateway. This code can be used
90
    # to identify why something failed by referencing the AIM documentation.
91
    def response_reason_code
92
      @fields[:response_reason_code]
93
    end
94
95
    # Returns the response reason text received from the gateway. This is a brief, human readable
96
    # explanation of why you got the response code that you got. Note that these strings tend to be
97
    # a bit vague. More detail can be gleaned from the response_reason_code.
98
    def response_reason_text
99
      @fields[:response_reason_text]
100
    end
101
102
    # Returns all the fields returned in the response, keyed by their API name. Custom fields are NOT
103
    # included (see custom_fields).
104
    attr_reader :fields
105
106
    # Returns all the custom fields returned in the response, keyed by their field name.
107
    attr_reader :custom_fields
108
  end
109
end
110