authorizenet 1.9.6 → 1.9.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/app/helpers/authorize_net_helper.rb +23 -23
- data/lib/authorize_net.rb +107 -107
- data/lib/authorize_net/addresses/address.rb +25 -25
- data/lib/authorize_net/addresses/shipping_address.rb +22 -22
- data/lib/authorize_net/aim/response.rb +120 -120
- data/lib/authorize_net/aim/transaction.rb +171 -171
- data/lib/authorize_net/api/LogHelper.rb +97 -0
- data/lib/authorize_net/api/SensitiveDataFilter.rb +92 -0
- data/lib/authorize_net/api/api_transaction.rb +129 -119
- data/lib/authorize_net/api/constants.yml +1 -1
- data/lib/authorize_net/api/schema.rb +5421 -5165
- data/lib/authorize_net/api/transaction.rb +265 -261
- data/lib/authorize_net/arb/fields.rb +24 -24
- data/lib/authorize_net/arb/paging.rb +29 -29
- data/lib/authorize_net/arb/response.rb +26 -26
- data/lib/authorize_net/arb/sorting.rb +39 -39
- data/lib/authorize_net/arb/subscription.rb +68 -68
- data/lib/authorize_net/arb/subscription_detail.rb +10 -10
- data/lib/authorize_net/arb/subscription_list_response.rb +36 -36
- data/lib/authorize_net/arb/transaction.rb +171 -171
- data/lib/authorize_net/authorize_net.rb +154 -154
- data/lib/authorize_net/cim/customer_profile.rb +15 -15
- data/lib/authorize_net/cim/payment_profile.rb +35 -35
- data/lib/authorize_net/cim/response.rb +111 -111
- data/lib/authorize_net/cim/transaction.rb +721 -721
- data/lib/authorize_net/customer.rb +24 -24
- data/lib/authorize_net/email_receipt.rb +20 -20
- data/lib/authorize_net/fields.rb +760 -760
- data/lib/authorize_net/key_value_response.rb +109 -109
- data/lib/authorize_net/key_value_transaction.rb +281 -281
- data/lib/authorize_net/line_item.rb +21 -21
- data/lib/authorize_net/order.rb +38 -38
- data/lib/authorize_net/payment_methods/credit_card.rb +61 -61
- data/lib/authorize_net/payment_methods/echeck.rb +70 -70
- data/lib/authorize_net/reporting/batch.rb +16 -16
- data/lib/authorize_net/reporting/batch_statistics.rb +15 -15
- data/lib/authorize_net/reporting/fds_filter.rb +8 -8
- data/lib/authorize_net/reporting/response.rb +157 -157
- data/lib/authorize_net/reporting/returned_item.rb +45 -45
- data/lib/authorize_net/reporting/transaction.rb +131 -131
- data/lib/authorize_net/reporting/transaction_details.rb +22 -22
- data/lib/authorize_net/response.rb +25 -25
- data/lib/authorize_net/sim/hosted_payment_form.rb +34 -34
- data/lib/authorize_net/sim/hosted_receipt_page.rb +32 -32
- data/lib/authorize_net/sim/response.rb +133 -133
- data/lib/authorize_net/sim/transaction.rb +128 -128
- data/lib/authorize_net/transaction.rb +66 -66
- data/lib/authorize_net/xml_response.rb +154 -154
- data/lib/authorize_net/xml_transaction.rb +279 -279
- data/lib/authorizenet.rb +4 -4
- data/lib/generators/authorize_net/direct_post/direct_post_generator.rb +52 -52
- data/lib/generators/authorize_net/direct_post/templates/README-AuthorizeNet +48 -48
- data/lib/generators/authorize_net/direct_post/templates/config.yml.erb +8 -8
- data/lib/generators/authorize_net/direct_post/templates/config.yml.rails3.erb +8 -8
- data/lib/generators/authorize_net/direct_post/templates/controller.rb.erb +30 -30
- data/lib/generators/authorize_net/direct_post/templates/initializer.rb +4 -4
- data/lib/generators/authorize_net/direct_post/templates/layout.erb +17 -17
- data/lib/generators/authorize_net/direct_post/templates/payment.erb +9 -9
- data/lib/generators/authorize_net/direct_post/templates/payment.rails3.erb +9 -9
- data/lib/generators/authorize_net/sim/sim_generator.rb +46 -46
- data/lib/generators/authorize_net/sim/templates/README-AuthorizeNet +51 -51
- data/lib/generators/authorize_net/sim/templates/config.yml.erb +8 -8
- data/lib/generators/authorize_net/sim/templates/config.yml.rails3.erb +8 -8
- data/lib/generators/authorize_net/sim/templates/controller.rb.erb +20 -20
- data/lib/generators/authorize_net/sim/templates/initializer.rb +4 -4
- data/lib/generators/authorize_net/sim/templates/layout.erb +17 -17
- data/lib/generators/authorize_net/sim/templates/payment.erb +5 -5
- data/lib/generators/authorize_net/sim/templates/payment.rails3.erb +5 -5
- data/lib/generators/generator_extensions.rb +73 -73
- metadata +5 -3
@@ -1,109 +1,109 @@
|
|
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
|
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
|
@@ -1,281 +1,281 @@
|
|
1
|
-
module AuthorizeNet
|
2
|
-
# The core, key/value transaction class. You shouldn't instantiate this one.
|
3
|
-
# Instead you should use AuthorizeNet::AIM::Transaction or AuthorizeNet::SIM::Transaction.
|
4
|
-
class KeyValueTransaction < AuthorizeNet::Transaction
|
5
|
-
# Constants for both the various Authorize.Net payment gateways are defined here.
|
6
|
-
module Gateway
|
7
|
-
LIVE = 'https://secure2.authorize.net/gateway/transact.dll'.freeze
|
8
|
-
TEST = 'https://test.authorize.net/gateway/transact.dll'.freeze
|
9
|
-
CARD_PRESENT_LIVE = 'https://cardpresent.authorize.net/gateway/transact.dll'.freeze
|
10
|
-
CARD_PRESENT_TEST = 'https://test.authorize.net/gateway/transact.dll'.freeze
|
11
|
-
end
|
12
|
-
|
13
|
-
# Constants for both the various Authorize.Net payment transaction types are defined here.
|
14
|
-
module Type
|
15
|
-
AUTHORIZE_AND_CAPTURE = "AUTH_CAPTURE".freeze
|
16
|
-
AUTHORIZE_ONLY = "AUTH_ONLY".freeze
|
17
|
-
CAPTURE_ONLY = "CAPTURE_ONLY".freeze
|
18
|
-
CREDIT = "CREDIT".freeze
|
19
|
-
PRIOR_AUTHORIZATION_AND_CAPTURE = "PRIOR_AUTH_CAPTURE".freeze
|
20
|
-
VOID = "VOID".freeze
|
21
|
-
end
|
22
|
-
|
23
|
-
# Constants for the various device types used in card present transactions.
|
24
|
-
module DeviceType
|
25
|
-
UNKNOWN = 1
|
26
|
-
UNATTENDED = 2
|
27
|
-
SELF_SERVICE = 3
|
28
|
-
CASH_REGISTER = 4
|
29
|
-
PC_TERMINAL = 5
|
30
|
-
AIRPAY = 6
|
31
|
-
WIRELESS_POS = 7
|
32
|
-
WEBSITE_TERMINAL = 8
|
33
|
-
DIAL_TERMINAL = 9
|
34
|
-
VIRTUAL_TERMINAL = 10
|
35
|
-
end
|
36
|
-
|
37
|
-
# Constants for the various market types used in card present transactions.
|
38
|
-
module MarketType
|
39
|
-
RETAIL = 2
|
40
|
-
end
|
41
|
-
|
42
|
-
# The default options for purchase.
|
43
|
-
@@purchase_option_defaults = {
|
44
|
-
cardholder_auth_value: nil,
|
45
|
-
cardholder_auth_indicator: nil
|
46
|
-
}
|
47
|
-
|
48
|
-
# The default options for authorize.
|
49
|
-
@@authorize_option_defaults = {
|
50
|
-
cardholder_auth_value: nil,
|
51
|
-
cardholder_auth_indicator: nil
|
52
|
-
}
|
53
|
-
|
54
|
-
# Fields to convert to/from booleans.
|
55
|
-
@@boolean_fields = []
|
56
|
-
|
57
|
-
# Fields to convert to/from BigDecimal.
|
58
|
-
@@decimal_fields = []
|
59
|
-
|
60
|
-
# DO NOT USE. Instantiate AuthorizeNet::AIM::Transaction or AuthorizeNet::SIM::Transaction instead.
|
61
|
-
def initialize
|
62
|
-
super
|
63
|
-
@custom_fields ||= {}
|
64
|
-
@test_mode ||= false
|
65
|
-
@version = '3.1'
|
66
|
-
end
|
67
|
-
|
68
|
-
# Checks if the transaction has been configured for test mode or not. Return TRUE if the
|
69
|
-
# transaction is a test transaction, FALSE otherwise. All transactions run against the sandbox
|
70
|
-
# are considered test transactions.
|
71
|
-
def test?
|
72
|
-
!!@test_mode
|
73
|
-
end
|
74
|
-
|
75
|
-
# Returns the current API version that we are adhering to
|
76
|
-
attr_reader :version
|
77
|
-
|
78
|
-
# Sets arbitrary custom fields, overwriting existing values if they exist. Takes a hash of key/value pairs,
|
79
|
-
# where the keys are the field names. You can set a field to Nil to unset it.
|
80
|
-
def set_custom_fields(fields = {})
|
81
|
-
@custom_fields.merge!(fields)
|
82
|
-
end
|
83
|
-
|
84
|
-
# Returns the current hash of custom fields.
|
85
|
-
attr_reader :custom_fields
|
86
|
-
|
87
|
-
# Convenience method for adding line items to a transaction.
|
88
|
-
def add_line_item(id = nil, name = nil, description = nil, quantity = nil, price = nil, taxable = nil)
|
89
|
-
line_item = "#{id}<|>#{name}<|>#{description}<|>#{quantity}<|>#{price}<|>#{taxable}"
|
90
|
-
if @fields.key?(:line_item)
|
91
|
-
@fields[:line_item] = @fields[:line_item].to_a << line_item
|
92
|
-
else
|
93
|
-
@fields[:line_item] = [line_item]
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
# Takes an instance of AuthorizeNet::EmailReceipt and adds it to the transaction.
|
98
|
-
def set_email_receipt(email)
|
99
|
-
@fields.merge!(email.to_hash)
|
100
|
-
end
|
101
|
-
|
102
|
-
# Returns the type of transaction.
|
103
|
-
attr_reader :type
|
104
|
-
|
105
|
-
# Sets the type of transaction.
|
106
|
-
def type=(type)
|
107
|
-
case type
|
108
|
-
when :authorize, :auth_only
|
109
|
-
@type = Type::AUTHORIZE_ONLY
|
110
|
-
when :purchase, :auth_and_capture
|
111
|
-
@type = Type::AUTHORIZE_AND_CAPTURE
|
112
|
-
when :refund, :credit
|
113
|
-
@type = Type::CREDIT
|
114
|
-
when :void
|
115
|
-
@type = Type::VOID
|
116
|
-
when :capture, :capture_only
|
117
|
-
@type = Type::CAPTURE_ONLY
|
118
|
-
when :prior_auth_capture
|
119
|
-
@type = Type::PRIOR_AUTHORIZATION_AND_CAPTURE
|
120
|
-
else
|
121
|
-
@type = type
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
# Sets up and submits a standard purchase (AUTHORIZE_AND_CAPTURE) transaction. Returns a response object. If the transaction
|
126
|
-
# has already been run, it will return nil.
|
127
|
-
#
|
128
|
-
# +amount+:: The amount to charge. Accepts a string in the format "%0.2f", a Float or a BigDecimal.
|
129
|
-
# +credit_card+:: The credit card or eCheck to charge. Accepts an instance of AuthorizeNet::CreditCard, AuthorizeNet::ECheck, or a string of digits (in which case the expiration should be added using set_fields).
|
130
|
-
# +options+:: A hash with any of following keys: cardholder_auth_indicator, cardholder_auth_value. These are for CAVV and can be ignored in most cases.
|
131
|
-
#
|
132
|
-
#
|
133
|
-
# Typical usage:
|
134
|
-
#
|
135
|
-
# credit_card = AuthorizeNet::CreditCard.new('4111111111111111', '1120')
|
136
|
-
# response = transaction.purchase(10.0, credit_card)
|
137
|
-
#
|
138
|
-
def purchase(amount, credit_card, options = {})
|
139
|
-
handle_payment_argument(credit_card)
|
140
|
-
options = @@purchase_option_defaults.merge(options)
|
141
|
-
handle_cavv_options(options)
|
142
|
-
set_fields(amount: amount)
|
143
|
-
self.type = Type::AUTHORIZE_AND_CAPTURE
|
144
|
-
run
|
145
|
-
end
|
146
|
-
|
147
|
-
# Sets up and submits a refund (CREDIT) transaction. Returns a response object. If the transaction
|
148
|
-
# has already been run, it will return nil.
|
149
|
-
#
|
150
|
-
# +amount+:: The amount to refund. Accepts a string in the format "%0.2f", a Float or a BigDecimal.
|
151
|
-
# +transaction+:: The transaction ID to apply the refund to. Accepts a string of the transaction ID, an instance of AuthorizeNet::Transaction or AuthorizeNet::Response.
|
152
|
-
# +credit_card+:: The credit card or eCheck to charge. Accepts an instance of AuthorizeNet::CreditCard, AuthorizeNet::ECheck, or a string of digits. In many cases you only need the last 4 digits of the credit card here.
|
153
|
-
#
|
154
|
-
#
|
155
|
-
# Typical usage:
|
156
|
-
#
|
157
|
-
# response = transaction.refund(10.0, '123456789', '1212')
|
158
|
-
#
|
159
|
-
def refund(amount, transaction, credit_card)
|
160
|
-
handle_payment_argument(credit_card)
|
161
|
-
handle_transaction_argument(transaction)
|
162
|
-
set_fields(amount: amount)
|
163
|
-
self.type = Type::CREDIT
|
164
|
-
run
|
165
|
-
end
|
166
|
-
|
167
|
-
# Sets up and submits a refund (CREDIT) transaction for a transaction that was not originally
|
168
|
-
# submitted via the payment gateway. Note that this is a special feature which requires your
|
169
|
-
# account to support ECC (expanded credits capability) transactions.
|
170
|
-
#
|
171
|
-
# +amount+:: The amount to refund. Accepts a string in the format "%0.2f", a Float or a BigDecimal.
|
172
|
-
# +credit_card+:: The credit card or eCheck to charge. Accepts an instance of AuthorizeNet::CreditCard, AuthorizeNet::ECheck, or a string of digits.
|
173
|
-
#
|
174
|
-
# Typical usage:
|
175
|
-
#
|
176
|
-
# response = transaction.unlinked_credit(10.0, '4111111111111111')
|
177
|
-
#
|
178
|
-
def unlinked_credit(amount, credit_card)
|
179
|
-
handle_payment_argument(credit_card)
|
180
|
-
set_fields(amount: amount)
|
181
|
-
self.type = Type::CREDIT
|
182
|
-
run
|
183
|
-
end
|
184
|
-
|
185
|
-
# Sets up and submits a void (VOID) transaction. Returns a response object. If the transaction
|
186
|
-
# has already been run, it will return nil. Note that you can only void unsettled transactions.
|
187
|
-
#
|
188
|
-
# +transaction+:: The transaction ID of the transaction to void. Accepts a string of the transaction ID, an instance of AuthorizeNet::Transaction or AuthorizeNet::Response.
|
189
|
-
#
|
190
|
-
#
|
191
|
-
# Typical usage:
|
192
|
-
#
|
193
|
-
# response = transaction.void('123456789')
|
194
|
-
#
|
195
|
-
def void(transaction)
|
196
|
-
handle_transaction_argument(transaction)
|
197
|
-
self.type = Type::VOID
|
198
|
-
run
|
199
|
-
end
|
200
|
-
|
201
|
-
# Sets up and submits an authorize (AUTH_ONLY) transaction. Returns a response object. If the transaction
|
202
|
-
# has already been run, it will return nil. Use this to put a hold on funds, but don't actually charge
|
203
|
-
# the card yet.
|
204
|
-
#
|
205
|
-
# +amount+:: The amount to authorize. Accepts a string in the format "%0.2f", a Float or a BigDecimal.
|
206
|
-
# +credit_card+:: The credit card or eCheck to charge. Accepts an instance of AuthorizeNet::CreditCard, AuthorizeNet::ECheck, or a string of digits (in which case the expiration should be added using set_fields).
|
207
|
-
# +options+:: A hash with any of following keys: cardholder_auth_indicator, cardholder_auth_value. These are for CAVV and can be ignored in most cases.
|
208
|
-
#
|
209
|
-
#
|
210
|
-
# Typical usage:
|
211
|
-
#
|
212
|
-
# credit_card = AuthorizeNet::CreditCard.new('4111111111111111', '1120')
|
213
|
-
# response = transaction.authorize(10.0, credit_card)
|
214
|
-
#
|
215
|
-
def authorize(amount, credit_card, options = {})
|
216
|
-
handle_payment_argument(credit_card)
|
217
|
-
options = @@authorize_option_defaults.merge(options)
|
218
|
-
handle_cavv_options(options)
|
219
|
-
set_fields(amount: amount)
|
220
|
-
self.type = Type::AUTHORIZE_ONLY
|
221
|
-
run
|
222
|
-
end
|
223
|
-
|
224
|
-
# Sets up and submits a capture (CAPTURE_ONLY) transaction. Returns a response object. If the transaction
|
225
|
-
# has already been run, it will return nil. Note that you can not capture a transaction that was made
|
226
|
-
# though the AIM API using this method. Use prior_auth_capture instead.
|
227
|
-
#
|
228
|
-
# +amount+:: The amount to capture. Accepts a string in the format "%0.2f", a Float or a BigDecimal.
|
229
|
-
# +authorization_code+:: The authorization code of the transaction to capture. Accepts a string.
|
230
|
-
#
|
231
|
-
#
|
232
|
-
# Typical usage:
|
233
|
-
#
|
234
|
-
# response = transaction.capture(10.0, '123FAKE')
|
235
|
-
#
|
236
|
-
def capture(amount, authorization_code)
|
237
|
-
set_fields(amount: amount, auth_code: authorization_code)
|
238
|
-
self.type = Type::CAPTURE_ONLY
|
239
|
-
run
|
240
|
-
end
|
241
|
-
|
242
|
-
# Sets up and submits a capture (PRIOR_AUTH_CAPTURE) transaction. Returns a response object. Use this method
|
243
|
-
# to actually charge a card that you previously put a hold on (using authorize).
|
244
|
-
#
|
245
|
-
# +transaction+:: The transaction ID to capture. Accepts a string of the transaction ID, an instance of AuthorizeNet::Transaction or AuthorizeNet::Response.
|
246
|
-
# +amount+:: The amount to capture (only if less than the amount originally authorized, otherwise leave as Nil). Accepts a string in the format "%0.2f", a Float, a BigDecimal or Nil.
|
247
|
-
#
|
248
|
-
#
|
249
|
-
# Typical usage:
|
250
|
-
#
|
251
|
-
# response = transaction.prior_auth_capture('123456789')
|
252
|
-
#
|
253
|
-
def prior_auth_capture(transaction, amount = nil)
|
254
|
-
handle_transaction_argument(transaction)
|
255
|
-
set_fields(amount: amount)
|
256
|
-
self.type = Type::PRIOR_AUTHORIZATION_AND_CAPTURE
|
257
|
-
run
|
258
|
-
end
|
259
|
-
|
260
|
-
#:enddoc:
|
261
|
-
protected
|
262
|
-
|
263
|
-
# Internal method to handle multiple types of transaction arguments.
|
264
|
-
def handle_transaction_argument(transaction)
|
265
|
-
case transaction
|
266
|
-
when Transaction
|
267
|
-
set_fields(trans_id: transaction.response.transaction_id)
|
268
|
-
when Response
|
269
|
-
set_fields(trans_id: transaction.transaction_id)
|
270
|
-
else
|
271
|
-
set_fields(trans_id: transaction)
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
# Internal method to handle CAVV options.
|
276
|
-
def handle_cavv_options(options)
|
277
|
-
set_fields(authentication_indicator: options[:cardholder_auth_indicator]) unless options[:cardholder_auth_indicator].nil?
|
278
|
-
set_fields(cardholder_authentication_value: options[:cardholder_auth_value]) unless options[:cardholder_auth_value].nil?
|
279
|
-
end
|
280
|
-
end
|
281
|
-
end
|
1
|
+
module AuthorizeNet
|
2
|
+
# The core, key/value transaction class. You shouldn't instantiate this one.
|
3
|
+
# Instead you should use AuthorizeNet::AIM::Transaction or AuthorizeNet::SIM::Transaction.
|
4
|
+
class KeyValueTransaction < AuthorizeNet::Transaction
|
5
|
+
# Constants for both the various Authorize.Net payment gateways are defined here.
|
6
|
+
module Gateway
|
7
|
+
LIVE = 'https://secure2.authorize.net/gateway/transact.dll'.freeze
|
8
|
+
TEST = 'https://test.authorize.net/gateway/transact.dll'.freeze
|
9
|
+
CARD_PRESENT_LIVE = 'https://cardpresent.authorize.net/gateway/transact.dll'.freeze
|
10
|
+
CARD_PRESENT_TEST = 'https://test.authorize.net/gateway/transact.dll'.freeze
|
11
|
+
end
|
12
|
+
|
13
|
+
# Constants for both the various Authorize.Net payment transaction types are defined here.
|
14
|
+
module Type
|
15
|
+
AUTHORIZE_AND_CAPTURE = "AUTH_CAPTURE".freeze
|
16
|
+
AUTHORIZE_ONLY = "AUTH_ONLY".freeze
|
17
|
+
CAPTURE_ONLY = "CAPTURE_ONLY".freeze
|
18
|
+
CREDIT = "CREDIT".freeze
|
19
|
+
PRIOR_AUTHORIZATION_AND_CAPTURE = "PRIOR_AUTH_CAPTURE".freeze
|
20
|
+
VOID = "VOID".freeze
|
21
|
+
end
|
22
|
+
|
23
|
+
# Constants for the various device types used in card present transactions.
|
24
|
+
module DeviceType
|
25
|
+
UNKNOWN = 1
|
26
|
+
UNATTENDED = 2
|
27
|
+
SELF_SERVICE = 3
|
28
|
+
CASH_REGISTER = 4
|
29
|
+
PC_TERMINAL = 5
|
30
|
+
AIRPAY = 6
|
31
|
+
WIRELESS_POS = 7
|
32
|
+
WEBSITE_TERMINAL = 8
|
33
|
+
DIAL_TERMINAL = 9
|
34
|
+
VIRTUAL_TERMINAL = 10
|
35
|
+
end
|
36
|
+
|
37
|
+
# Constants for the various market types used in card present transactions.
|
38
|
+
module MarketType
|
39
|
+
RETAIL = 2
|
40
|
+
end
|
41
|
+
|
42
|
+
# The default options for purchase.
|
43
|
+
@@purchase_option_defaults = {
|
44
|
+
cardholder_auth_value: nil,
|
45
|
+
cardholder_auth_indicator: nil
|
46
|
+
}
|
47
|
+
|
48
|
+
# The default options for authorize.
|
49
|
+
@@authorize_option_defaults = {
|
50
|
+
cardholder_auth_value: nil,
|
51
|
+
cardholder_auth_indicator: nil
|
52
|
+
}
|
53
|
+
|
54
|
+
# Fields to convert to/from booleans.
|
55
|
+
@@boolean_fields = []
|
56
|
+
|
57
|
+
# Fields to convert to/from BigDecimal.
|
58
|
+
@@decimal_fields = []
|
59
|
+
|
60
|
+
# DO NOT USE. Instantiate AuthorizeNet::AIM::Transaction or AuthorizeNet::SIM::Transaction instead.
|
61
|
+
def initialize
|
62
|
+
super
|
63
|
+
@custom_fields ||= {}
|
64
|
+
@test_mode ||= false
|
65
|
+
@version = '3.1'
|
66
|
+
end
|
67
|
+
|
68
|
+
# Checks if the transaction has been configured for test mode or not. Return TRUE if the
|
69
|
+
# transaction is a test transaction, FALSE otherwise. All transactions run against the sandbox
|
70
|
+
# are considered test transactions.
|
71
|
+
def test?
|
72
|
+
!!@test_mode
|
73
|
+
end
|
74
|
+
|
75
|
+
# Returns the current API version that we are adhering to
|
76
|
+
attr_reader :version
|
77
|
+
|
78
|
+
# Sets arbitrary custom fields, overwriting existing values if they exist. Takes a hash of key/value pairs,
|
79
|
+
# where the keys are the field names. You can set a field to Nil to unset it.
|
80
|
+
def set_custom_fields(fields = {})
|
81
|
+
@custom_fields.merge!(fields)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Returns the current hash of custom fields.
|
85
|
+
attr_reader :custom_fields
|
86
|
+
|
87
|
+
# Convenience method for adding line items to a transaction.
|
88
|
+
def add_line_item(id = nil, name = nil, description = nil, quantity = nil, price = nil, taxable = nil)
|
89
|
+
line_item = "#{id}<|>#{name}<|>#{description}<|>#{quantity}<|>#{price}<|>#{taxable}"
|
90
|
+
if @fields.key?(:line_item)
|
91
|
+
@fields[:line_item] = @fields[:line_item].to_a << line_item
|
92
|
+
else
|
93
|
+
@fields[:line_item] = [line_item]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Takes an instance of AuthorizeNet::EmailReceipt and adds it to the transaction.
|
98
|
+
def set_email_receipt(email)
|
99
|
+
@fields.merge!(email.to_hash)
|
100
|
+
end
|
101
|
+
|
102
|
+
# Returns the type of transaction.
|
103
|
+
attr_reader :type
|
104
|
+
|
105
|
+
# Sets the type of transaction.
|
106
|
+
def type=(type)
|
107
|
+
case type
|
108
|
+
when :authorize, :auth_only
|
109
|
+
@type = Type::AUTHORIZE_ONLY
|
110
|
+
when :purchase, :auth_and_capture
|
111
|
+
@type = Type::AUTHORIZE_AND_CAPTURE
|
112
|
+
when :refund, :credit
|
113
|
+
@type = Type::CREDIT
|
114
|
+
when :void
|
115
|
+
@type = Type::VOID
|
116
|
+
when :capture, :capture_only
|
117
|
+
@type = Type::CAPTURE_ONLY
|
118
|
+
when :prior_auth_capture
|
119
|
+
@type = Type::PRIOR_AUTHORIZATION_AND_CAPTURE
|
120
|
+
else
|
121
|
+
@type = type
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# Sets up and submits a standard purchase (AUTHORIZE_AND_CAPTURE) transaction. Returns a response object. If the transaction
|
126
|
+
# has already been run, it will return nil.
|
127
|
+
#
|
128
|
+
# +amount+:: The amount to charge. Accepts a string in the format "%0.2f", a Float or a BigDecimal.
|
129
|
+
# +credit_card+:: The credit card or eCheck to charge. Accepts an instance of AuthorizeNet::CreditCard, AuthorizeNet::ECheck, or a string of digits (in which case the expiration should be added using set_fields).
|
130
|
+
# +options+:: A hash with any of following keys: cardholder_auth_indicator, cardholder_auth_value. These are for CAVV and can be ignored in most cases.
|
131
|
+
#
|
132
|
+
#
|
133
|
+
# Typical usage:
|
134
|
+
#
|
135
|
+
# credit_card = AuthorizeNet::CreditCard.new('4111111111111111', '1120')
|
136
|
+
# response = transaction.purchase(10.0, credit_card)
|
137
|
+
#
|
138
|
+
def purchase(amount, credit_card, options = {})
|
139
|
+
handle_payment_argument(credit_card)
|
140
|
+
options = @@purchase_option_defaults.merge(options)
|
141
|
+
handle_cavv_options(options)
|
142
|
+
set_fields(amount: amount)
|
143
|
+
self.type = Type::AUTHORIZE_AND_CAPTURE
|
144
|
+
run
|
145
|
+
end
|
146
|
+
|
147
|
+
# Sets up and submits a refund (CREDIT) transaction. Returns a response object. If the transaction
|
148
|
+
# has already been run, it will return nil.
|
149
|
+
#
|
150
|
+
# +amount+:: The amount to refund. Accepts a string in the format "%0.2f", a Float or a BigDecimal.
|
151
|
+
# +transaction+:: The transaction ID to apply the refund to. Accepts a string of the transaction ID, an instance of AuthorizeNet::Transaction or AuthorizeNet::Response.
|
152
|
+
# +credit_card+:: The credit card or eCheck to charge. Accepts an instance of AuthorizeNet::CreditCard, AuthorizeNet::ECheck, or a string of digits. In many cases you only need the last 4 digits of the credit card here.
|
153
|
+
#
|
154
|
+
#
|
155
|
+
# Typical usage:
|
156
|
+
#
|
157
|
+
# response = transaction.refund(10.0, '123456789', '1212')
|
158
|
+
#
|
159
|
+
def refund(amount, transaction, credit_card)
|
160
|
+
handle_payment_argument(credit_card)
|
161
|
+
handle_transaction_argument(transaction)
|
162
|
+
set_fields(amount: amount)
|
163
|
+
self.type = Type::CREDIT
|
164
|
+
run
|
165
|
+
end
|
166
|
+
|
167
|
+
# Sets up and submits a refund (CREDIT) transaction for a transaction that was not originally
|
168
|
+
# submitted via the payment gateway. Note that this is a special feature which requires your
|
169
|
+
# account to support ECC (expanded credits capability) transactions.
|
170
|
+
#
|
171
|
+
# +amount+:: The amount to refund. Accepts a string in the format "%0.2f", a Float or a BigDecimal.
|
172
|
+
# +credit_card+:: The credit card or eCheck to charge. Accepts an instance of AuthorizeNet::CreditCard, AuthorizeNet::ECheck, or a string of digits.
|
173
|
+
#
|
174
|
+
# Typical usage:
|
175
|
+
#
|
176
|
+
# response = transaction.unlinked_credit(10.0, '4111111111111111')
|
177
|
+
#
|
178
|
+
def unlinked_credit(amount, credit_card)
|
179
|
+
handle_payment_argument(credit_card)
|
180
|
+
set_fields(amount: amount)
|
181
|
+
self.type = Type::CREDIT
|
182
|
+
run
|
183
|
+
end
|
184
|
+
|
185
|
+
# Sets up and submits a void (VOID) transaction. Returns a response object. If the transaction
|
186
|
+
# has already been run, it will return nil. Note that you can only void unsettled transactions.
|
187
|
+
#
|
188
|
+
# +transaction+:: The transaction ID of the transaction to void. Accepts a string of the transaction ID, an instance of AuthorizeNet::Transaction or AuthorizeNet::Response.
|
189
|
+
#
|
190
|
+
#
|
191
|
+
# Typical usage:
|
192
|
+
#
|
193
|
+
# response = transaction.void('123456789')
|
194
|
+
#
|
195
|
+
def void(transaction)
|
196
|
+
handle_transaction_argument(transaction)
|
197
|
+
self.type = Type::VOID
|
198
|
+
run
|
199
|
+
end
|
200
|
+
|
201
|
+
# Sets up and submits an authorize (AUTH_ONLY) transaction. Returns a response object. If the transaction
|
202
|
+
# has already been run, it will return nil. Use this to put a hold on funds, but don't actually charge
|
203
|
+
# the card yet.
|
204
|
+
#
|
205
|
+
# +amount+:: The amount to authorize. Accepts a string in the format "%0.2f", a Float or a BigDecimal.
|
206
|
+
# +credit_card+:: The credit card or eCheck to charge. Accepts an instance of AuthorizeNet::CreditCard, AuthorizeNet::ECheck, or a string of digits (in which case the expiration should be added using set_fields).
|
207
|
+
# +options+:: A hash with any of following keys: cardholder_auth_indicator, cardholder_auth_value. These are for CAVV and can be ignored in most cases.
|
208
|
+
#
|
209
|
+
#
|
210
|
+
# Typical usage:
|
211
|
+
#
|
212
|
+
# credit_card = AuthorizeNet::CreditCard.new('4111111111111111', '1120')
|
213
|
+
# response = transaction.authorize(10.0, credit_card)
|
214
|
+
#
|
215
|
+
def authorize(amount, credit_card, options = {})
|
216
|
+
handle_payment_argument(credit_card)
|
217
|
+
options = @@authorize_option_defaults.merge(options)
|
218
|
+
handle_cavv_options(options)
|
219
|
+
set_fields(amount: amount)
|
220
|
+
self.type = Type::AUTHORIZE_ONLY
|
221
|
+
run
|
222
|
+
end
|
223
|
+
|
224
|
+
# Sets up and submits a capture (CAPTURE_ONLY) transaction. Returns a response object. If the transaction
|
225
|
+
# has already been run, it will return nil. Note that you can not capture a transaction that was made
|
226
|
+
# though the AIM API using this method. Use prior_auth_capture instead.
|
227
|
+
#
|
228
|
+
# +amount+:: The amount to capture. Accepts a string in the format "%0.2f", a Float or a BigDecimal.
|
229
|
+
# +authorization_code+:: The authorization code of the transaction to capture. Accepts a string.
|
230
|
+
#
|
231
|
+
#
|
232
|
+
# Typical usage:
|
233
|
+
#
|
234
|
+
# response = transaction.capture(10.0, '123FAKE')
|
235
|
+
#
|
236
|
+
def capture(amount, authorization_code)
|
237
|
+
set_fields(amount: amount, auth_code: authorization_code)
|
238
|
+
self.type = Type::CAPTURE_ONLY
|
239
|
+
run
|
240
|
+
end
|
241
|
+
|
242
|
+
# Sets up and submits a capture (PRIOR_AUTH_CAPTURE) transaction. Returns a response object. Use this method
|
243
|
+
# to actually charge a card that you previously put a hold on (using authorize).
|
244
|
+
#
|
245
|
+
# +transaction+:: The transaction ID to capture. Accepts a string of the transaction ID, an instance of AuthorizeNet::Transaction or AuthorizeNet::Response.
|
246
|
+
# +amount+:: The amount to capture (only if less than the amount originally authorized, otherwise leave as Nil). Accepts a string in the format "%0.2f", a Float, a BigDecimal or Nil.
|
247
|
+
#
|
248
|
+
#
|
249
|
+
# Typical usage:
|
250
|
+
#
|
251
|
+
# response = transaction.prior_auth_capture('123456789')
|
252
|
+
#
|
253
|
+
def prior_auth_capture(transaction, amount = nil)
|
254
|
+
handle_transaction_argument(transaction)
|
255
|
+
set_fields(amount: amount)
|
256
|
+
self.type = Type::PRIOR_AUTHORIZATION_AND_CAPTURE
|
257
|
+
run
|
258
|
+
end
|
259
|
+
|
260
|
+
#:enddoc:
|
261
|
+
protected
|
262
|
+
|
263
|
+
# Internal method to handle multiple types of transaction arguments.
|
264
|
+
def handle_transaction_argument(transaction)
|
265
|
+
case transaction
|
266
|
+
when Transaction
|
267
|
+
set_fields(trans_id: transaction.response.transaction_id)
|
268
|
+
when Response
|
269
|
+
set_fields(trans_id: transaction.transaction_id)
|
270
|
+
else
|
271
|
+
set_fields(trans_id: transaction)
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
# Internal method to handle CAVV options.
|
276
|
+
def handle_cavv_options(options)
|
277
|
+
set_fields(authentication_indicator: options[:cardholder_auth_indicator]) unless options[:cardholder_auth_indicator].nil?
|
278
|
+
set_fields(cardholder_authentication_value: options[:cardholder_auth_value]) unless options[:cardholder_auth_value].nil?
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|