activemerchant-kiddy 1.15.0.kiddy
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +688 -0
- data/CONTRIBUTORS +233 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +164 -0
- data/gem-public_cert.pem +20 -0
- data/lib/active_merchant/billing/avs_result.rb +98 -0
- data/lib/active_merchant/billing/base.rb +57 -0
- data/lib/active_merchant/billing/check.rb +68 -0
- data/lib/active_merchant/billing/credit_card.rb +172 -0
- data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
- data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
- data/lib/active_merchant/billing/cvv_result.rb +38 -0
- data/lib/active_merchant/billing/expiry_date.rb +34 -0
- data/lib/active_merchant/billing/gateway.rb +170 -0
- data/lib/active_merchant/billing/gateways/authorize_net.rb +671 -0
- data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +858 -0
- data/lib/active_merchant/billing/gateways/barclays_epdq.rb +309 -0
- data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +282 -0
- data/lib/active_merchant/billing/gateways/beanstream.rb +139 -0
- data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
- data/lib/active_merchant/billing/gateways/blue_pay.rb +11 -0
- data/lib/active_merchant/billing/gateways/bogus.rb +132 -0
- data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
- data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
- data/lib/active_merchant/billing/gateways/braintree_blue.rb +293 -0
- data/lib/active_merchant/billing/gateways/braintree_orange.rb +17 -0
- data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
- data/lib/active_merchant/billing/gateways/cyber_source.rb +410 -0
- data/lib/active_merchant/billing/gateways/data_cash.rb +597 -0
- data/lib/active_merchant/billing/gateways/efsnet.rb +235 -0
- data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
- data/lib/active_merchant/billing/gateways/epay.rb +268 -0
- data/lib/active_merchant/billing/gateways/eway.rb +277 -0
- data/lib/active_merchant/billing/gateways/eway_managed.rb +231 -0
- data/lib/active_merchant/billing/gateways/exact.rb +222 -0
- data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
- data/lib/active_merchant/billing/gateways/first_pay.rb +177 -0
- data/lib/active_merchant/billing/gateways/garanti.rb +262 -0
- data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +250 -0
- data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
- data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
- data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +55 -0
- data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
- data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
- data/lib/active_merchant/billing/gateways/iridium.rb +258 -0
- data/lib/active_merchant/billing/gateways/jetpay.rb +276 -0
- data/lib/active_merchant/billing/gateways/linkpoint.rb +454 -0
- data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +156 -0
- data/lib/active_merchant/billing/gateways/merchant_ware.rb +289 -0
- data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
- data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
- data/lib/active_merchant/billing/gateways/moneris.rb +209 -0
- data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
- data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
- data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
- data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
- data/lib/active_merchant/billing/gateways/ogone.rb +292 -0
- data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
- data/lib/active_merchant/billing/gateways/orbital.rb +317 -0
- data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
- data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
- data/lib/active_merchant/billing/gateways/paybox_direct.rb +207 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
- data/lib/active_merchant/billing/gateways/payflow.rb +253 -0
- data/lib/active_merchant/billing/gateways/payflow_express.rb +222 -0
- data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
- data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
- data/lib/active_merchant/billing/gateways/payment_express.rb +235 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +351 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -0
- data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
- data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
- data/lib/active_merchant/billing/gateways/paypal_express.rb +177 -0
- data/lib/active_merchant/billing/gateways/paypal_express_common.rb +25 -0
- data/lib/active_merchant/billing/gateways/plugnpay.rb +298 -0
- data/lib/active_merchant/billing/gateways/psigate.rb +219 -0
- data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
- data/lib/active_merchant/billing/gateways/qbms.rb +295 -0
- data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
- data/lib/active_merchant/billing/gateways/quickpay.rb +218 -0
- data/lib/active_merchant/billing/gateways/realex.rb +311 -0
- data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
- data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
- data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
- data/lib/active_merchant/billing/gateways/sage.rb +146 -0
- data/lib/active_merchant/billing/gateways/sage_pay.rb +320 -0
- data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
- data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
- data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
- data/lib/active_merchant/billing/gateways/secure_pay_au.rb +193 -0
- data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
- data/lib/active_merchant/billing/gateways/skip_jack.rb +453 -0
- data/lib/active_merchant/billing/gateways/smart_ps.rb +271 -0
- data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
- data/lib/active_merchant/billing/gateways/transax.rb +25 -0
- data/lib/active_merchant/billing/gateways/trust_commerce.rb +423 -0
- data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
- data/lib/active_merchant/billing/gateways/verifi.rb +233 -0
- data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
- data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
- data/lib/active_merchant/billing/gateways/worldpay.rb +280 -0
- data/lib/active_merchant/billing/gateways.rb +18 -0
- data/lib/active_merchant/billing/integrations/action_view_helper.rb +68 -0
- data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
- data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
- data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
- data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
- data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
- data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
- data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +200 -0
- data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
- data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
- data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
- data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
- data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
- data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
- data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
- data/lib/active_merchant/billing/integrations/directebanking.rb +47 -0
- data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
- data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
- data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
- data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
- data/lib/active_merchant/billing/integrations/helper.rb +96 -0
- data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
- data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
- data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
- data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
- data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +48 -0
- data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
- data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
- data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
- data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
- data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
- data/lib/active_merchant/billing/integrations/notification.rb +62 -0
- data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
- data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
- data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
- data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
- data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
- data/lib/active_merchant/billing/integrations/quickpay.rb +21 -0
- data/lib/active_merchant/billing/integrations/return.rb +42 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +111 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
- data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
- data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
- data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
- data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
- data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
- data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
- data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +88 -0
- data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
- data/lib/active_merchant/billing/integrations/valitor.rb +33 -0
- data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
- data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -0
- data/lib/active_merchant/billing/integrations/world_pay.rb +38 -0
- data/lib/active_merchant/billing/integrations.rb +17 -0
- data/lib/active_merchant/billing/response.rb +32 -0
- data/lib/active_merchant/billing.rb +9 -0
- data/lib/active_merchant/common/connection.rb +177 -0
- data/lib/active_merchant/common/country.rb +328 -0
- data/lib/active_merchant/common/error.rb +26 -0
- data/lib/active_merchant/common/post_data.rb +24 -0
- data/lib/active_merchant/common/posts_data.rb +63 -0
- data/lib/active_merchant/common/requires_parameters.rb +16 -0
- data/lib/active_merchant/common/utils.rb +22 -0
- data/lib/active_merchant/common/validateable.rb +81 -0
- data/lib/active_merchant/common.rb +14 -0
- data/lib/active_merchant/version.rb +3 -0
- data/lib/active_merchant.rb +50 -0
- data/lib/activemerchant.rb +1 -0
- data/lib/certs/cacert.pem +7815 -0
- data/lib/support/gateway_support.rb +58 -0
- data/lib/support/outbound_hosts.rb +25 -0
- metadata +273 -0
@@ -0,0 +1,671 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
# For more information on the Authorize.Net Gateway please visit their {Integration Center}[http://developer.authorize.net/]
|
4
|
+
#
|
5
|
+
# The login and password are not the username and password you use to
|
6
|
+
# login to the Authorize.Net Merchant Interface. Instead, you will
|
7
|
+
# use the API Login ID as the login and Transaction Key as the
|
8
|
+
# password.
|
9
|
+
#
|
10
|
+
# ==== How to Get Your API Login ID and Transaction Key
|
11
|
+
#
|
12
|
+
# 1. Log into the Merchant Interface
|
13
|
+
# 2. Select Settings from the Main Menu
|
14
|
+
# 3. Click on API Login ID and Transaction Key in the Security section
|
15
|
+
# 4. Type in the answer to the secret question configured on setup
|
16
|
+
# 5. Click Submit
|
17
|
+
#
|
18
|
+
# ==== Automated Recurring Billing (ARB)
|
19
|
+
#
|
20
|
+
# Automated Recurring Billing (ARB) is an optional service for submitting and managing recurring, or subscription-based, transactions.
|
21
|
+
#
|
22
|
+
# To use recurring, update_recurring, and cancel_recurring ARB must be enabled for your account.
|
23
|
+
#
|
24
|
+
# Information about ARB is available on the {Authorize.Net website}[http://www.authorize.net/solutions/merchantsolutions/merchantservices/automatedrecurringbilling/].
|
25
|
+
# Information about the ARB API is available at the {Authorize.Net Integration Center}[http://developer.authorize.net/]
|
26
|
+
class AuthorizeNetGateway < Gateway
|
27
|
+
API_VERSION = '3.1'
|
28
|
+
|
29
|
+
class_attribute :test_url, :live_url, :arb_test_url, :arb_live_url
|
30
|
+
|
31
|
+
self.test_url = "https://test.authorize.net/gateway/transact.dll"
|
32
|
+
self.live_url = "https://secure.authorize.net/gateway/transact.dll"
|
33
|
+
|
34
|
+
self.arb_test_url = 'https://apitest.authorize.net/xml/v1/request.api'
|
35
|
+
self.arb_live_url = 'https://api.authorize.net/xml/v1/request.api'
|
36
|
+
|
37
|
+
class_attribute :duplicate_window
|
38
|
+
|
39
|
+
APPROVED, DECLINED, ERROR, FRAUD_REVIEW = 1, 2, 3, 4
|
40
|
+
|
41
|
+
RESPONSE_CODE, RESPONSE_REASON_CODE, RESPONSE_REASON_TEXT = 0, 2, 3
|
42
|
+
AVS_RESULT_CODE, TRANSACTION_ID, CARD_CODE_RESPONSE_CODE = 5, 6, 38
|
43
|
+
|
44
|
+
self.supported_countries = ['US']
|
45
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :discover]
|
46
|
+
self.homepage_url = 'http://www.authorize.net/'
|
47
|
+
self.display_name = 'Authorize.Net'
|
48
|
+
|
49
|
+
CARD_CODE_ERRORS = %w( N S )
|
50
|
+
AVS_ERRORS = %w( A E N R W Z )
|
51
|
+
AVS_REASON_CODES = %w(27 45)
|
52
|
+
|
53
|
+
AUTHORIZE_NET_ARB_NAMESPACE = 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'
|
54
|
+
|
55
|
+
RECURRING_ACTIONS = {
|
56
|
+
:create => 'ARBCreateSubscription',
|
57
|
+
:update => 'ARBUpdateSubscription',
|
58
|
+
:cancel => 'ARBCancelSubscription'
|
59
|
+
}
|
60
|
+
|
61
|
+
# Creates a new AuthorizeNetGateway
|
62
|
+
#
|
63
|
+
# The gateway requires that a valid login and password be passed
|
64
|
+
# in the +options+ hash.
|
65
|
+
#
|
66
|
+
# ==== Options
|
67
|
+
#
|
68
|
+
# * <tt>:login</tt> -- The Authorize.Net API Login ID (REQUIRED)
|
69
|
+
# * <tt>:password</tt> -- The Authorize.Net Transaction Key. (REQUIRED)
|
70
|
+
# * <tt>:test</tt> -- +true+ or +false+. If true, perform transactions against the test server.
|
71
|
+
# Otherwise, perform transactions against the production server.
|
72
|
+
def initialize(options = {})
|
73
|
+
requires!(options, :login, :password)
|
74
|
+
@options = options
|
75
|
+
super
|
76
|
+
end
|
77
|
+
|
78
|
+
# Performs an authorization, which reserves the funds on the customer's credit card, but does not
|
79
|
+
# charge the card.
|
80
|
+
#
|
81
|
+
# ==== Parameters
|
82
|
+
#
|
83
|
+
# * <tt>money</tt> -- The amount to be authorized as an Integer value in cents.
|
84
|
+
# * <tt>creditcard</tt> -- The CreditCard details for the transaction.
|
85
|
+
# * <tt>options</tt> -- A hash of optional parameters.
|
86
|
+
def authorize(money, creditcard, options = {})
|
87
|
+
post = {}
|
88
|
+
add_invoice(post, options)
|
89
|
+
add_creditcard(post, creditcard)
|
90
|
+
add_address(post, options)
|
91
|
+
add_customer_data(post, options)
|
92
|
+
add_duplicate_window(post)
|
93
|
+
|
94
|
+
commit('AUTH_ONLY', money, post)
|
95
|
+
end
|
96
|
+
|
97
|
+
# Perform a purchase, which is essentially an authorization and capture in a single operation.
|
98
|
+
#
|
99
|
+
# ==== Parameters
|
100
|
+
#
|
101
|
+
# * <tt>money</tt> -- The amount to be purchased as an Integer value in cents.
|
102
|
+
# * <tt>creditcard</tt> -- The CreditCard details for the transaction.
|
103
|
+
# * <tt>options</tt> -- A hash of optional parameters.
|
104
|
+
def purchase(money, creditcard, options = {})
|
105
|
+
post = {}
|
106
|
+
add_invoice(post, options)
|
107
|
+
add_creditcard(post, creditcard)
|
108
|
+
add_address(post, options)
|
109
|
+
add_customer_data(post, options)
|
110
|
+
add_duplicate_window(post)
|
111
|
+
|
112
|
+
commit('AUTH_CAPTURE', money, post)
|
113
|
+
end
|
114
|
+
|
115
|
+
# Captures the funds from an authorized transaction.
|
116
|
+
#
|
117
|
+
# ==== Parameters
|
118
|
+
#
|
119
|
+
# * <tt>money</tt> -- The amount to be captured as an Integer value in cents.
|
120
|
+
# * <tt>authorization</tt> -- The authorization returned from the previous authorize request.
|
121
|
+
def capture(money, authorization, options = {})
|
122
|
+
post = {:trans_id => authorization}
|
123
|
+
add_customer_data(post, options)
|
124
|
+
commit('PRIOR_AUTH_CAPTURE', money, post)
|
125
|
+
end
|
126
|
+
|
127
|
+
# Void a previous transaction
|
128
|
+
#
|
129
|
+
# ==== Parameters
|
130
|
+
#
|
131
|
+
# * <tt>authorization</tt> - The authorization returned from the previous authorize request.
|
132
|
+
def void(authorization, options = {})
|
133
|
+
post = {:trans_id => authorization}
|
134
|
+
add_duplicate_window(post)
|
135
|
+
commit('VOID', nil, post)
|
136
|
+
end
|
137
|
+
|
138
|
+
# Refund a transaction.
|
139
|
+
#
|
140
|
+
# This transaction indicates to the gateway that
|
141
|
+
# money should flow from the merchant to the customer.
|
142
|
+
#
|
143
|
+
# ==== Parameters
|
144
|
+
#
|
145
|
+
# * <tt>money</tt> -- The amount to be credited to the customer as an Integer value in cents.
|
146
|
+
# * <tt>identification</tt> -- The ID of the original transaction against which the refund is being issued.
|
147
|
+
# * <tt>options</tt> -- A hash of parameters.
|
148
|
+
#
|
149
|
+
# ==== Options
|
150
|
+
#
|
151
|
+
# * <tt>:card_number</tt> -- The credit card number the refund is being issued to. (REQUIRED)
|
152
|
+
def refund(money, identification, options = {})
|
153
|
+
requires!(options, :card_number)
|
154
|
+
|
155
|
+
post = { :trans_id => identification,
|
156
|
+
:card_num => options[:card_number]
|
157
|
+
}
|
158
|
+
add_invoice(post, options)
|
159
|
+
add_duplicate_window(post)
|
160
|
+
add_market_type(post, options)
|
161
|
+
|
162
|
+
commit('CREDIT', money, post)
|
163
|
+
end
|
164
|
+
|
165
|
+
def credit(money, identification, options = {})
|
166
|
+
deprecated CREDIT_DEPRECATION_MESSAGE
|
167
|
+
refund(money, identification, options)
|
168
|
+
end
|
169
|
+
|
170
|
+
# Create a recurring payment.
|
171
|
+
#
|
172
|
+
# This transaction creates a new Automated Recurring Billing (ARB) subscription. Your account must have ARB enabled.
|
173
|
+
#
|
174
|
+
# ==== Parameters
|
175
|
+
#
|
176
|
+
# * <tt>money</tt> -- The amount to be charged to the customer at each interval as an Integer value in cents.
|
177
|
+
# * <tt>creditcard</tt> -- The CreditCard details for the transaction.
|
178
|
+
# * <tt>options</tt> -- A hash of parameters.
|
179
|
+
#
|
180
|
+
# ==== Options
|
181
|
+
#
|
182
|
+
# * <tt>:interval</tt> -- A hash containing information about the interval of time between payments. Must
|
183
|
+
# contain the keys <tt>:length</tt> and <tt>:unit</tt>. <tt>:unit</tt> can be either <tt>:months</tt> or <tt>:days</tt>.
|
184
|
+
# If <tt>:unit</tt> is <tt>:months</tt> then <tt>:length</tt> must be an integer between 1 and 12 inclusive.
|
185
|
+
# If <tt>:unit</tt> is <tt>:days</tt> then <tt>:length</tt> must be an integer between 7 and 365 inclusive.
|
186
|
+
# For example, to charge the customer once every three months the hash would be
|
187
|
+
# +:interval => { :unit => :months, :length => 3 }+ (REQUIRED)
|
188
|
+
# * <tt>:duration</tt> -- A hash containing keys for the <tt>:start_date</tt> the subscription begins (also the date the
|
189
|
+
# initial billing occurs) and the total number of billing <tt>:occurences</tt> or payments for the subscription. (REQUIRED)
|
190
|
+
def recurring(money, creditcard, options={})
|
191
|
+
requires!(options, :interval, :duration, :billing_address)
|
192
|
+
requires!(options[:interval], :length, [:unit, :days, :months])
|
193
|
+
requires!(options[:duration], :start_date, :occurrences)
|
194
|
+
requires!(options[:billing_address], :first_name, :last_name)
|
195
|
+
|
196
|
+
options[:credit_card] = creditcard
|
197
|
+
options[:amount] = money
|
198
|
+
|
199
|
+
request = build_recurring_request(:create, options)
|
200
|
+
recurring_commit(:create, request)
|
201
|
+
end
|
202
|
+
|
203
|
+
# Update a recurring payment's details.
|
204
|
+
#
|
205
|
+
# This transaction updates an existing Automated Recurring Billing (ARB) subscription. Your account must have ARB enabled
|
206
|
+
# and the subscription must have already been created previously by calling +recurring()+. The ability to change certain
|
207
|
+
# details about a recurring payment is dependent on transaction history and cannot be determined until after calling
|
208
|
+
# +update_recurring()+. See the ARB XML Guide for such conditions.
|
209
|
+
#
|
210
|
+
# ==== Parameters
|
211
|
+
#
|
212
|
+
# * <tt>options</tt> -- A hash of parameters.
|
213
|
+
#
|
214
|
+
# ==== Options
|
215
|
+
#
|
216
|
+
# * <tt>:subscription_id</tt> -- A string containing the <tt>:subscription_id</tt> of the recurring payment already in place
|
217
|
+
# for a given credit card. (REQUIRED)
|
218
|
+
def update_recurring(options={})
|
219
|
+
requires!(options, :subscription_id)
|
220
|
+
request = build_recurring_request(:update, options)
|
221
|
+
recurring_commit(:update, request)
|
222
|
+
end
|
223
|
+
|
224
|
+
# Cancel a recurring payment.
|
225
|
+
#
|
226
|
+
# This transaction cancels an existing Automated Recurring Billing (ARB) subscription. Your account must have ARB enabled
|
227
|
+
# and the subscription must have already been created previously by calling recurring()
|
228
|
+
#
|
229
|
+
# ==== Parameters
|
230
|
+
#
|
231
|
+
# * <tt>subscription_id</tt> -- A string containing the +subscription_id+ of the recurring payment already in place
|
232
|
+
# for a given credit card. (REQUIRED)
|
233
|
+
def cancel_recurring(subscription_id)
|
234
|
+
request = build_recurring_request(:cancel, :subscription_id => subscription_id)
|
235
|
+
recurring_commit(:cancel, request)
|
236
|
+
end
|
237
|
+
|
238
|
+
private
|
239
|
+
|
240
|
+
def commit(action, money, parameters)
|
241
|
+
parameters[:amount] = amount(money) unless action == 'VOID'
|
242
|
+
|
243
|
+
# Only activate the test_request when the :test option is passed in
|
244
|
+
parameters[:test_request] = @options[:test] ? 'TRUE' : 'FALSE'
|
245
|
+
|
246
|
+
url = test? ? self.test_url : self.live_url
|
247
|
+
data = ssl_post url, post_data(action, parameters)
|
248
|
+
|
249
|
+
response = parse(data)
|
250
|
+
|
251
|
+
message = message_from(response)
|
252
|
+
|
253
|
+
# Return the response. The authorization can be taken out of the transaction_id
|
254
|
+
# Test Mode on/off is something we have to parse from the response text.
|
255
|
+
# It usually looks something like this
|
256
|
+
#
|
257
|
+
# (TESTMODE) Successful Sale
|
258
|
+
test_mode = test? || message =~ /TESTMODE/
|
259
|
+
|
260
|
+
Response.new(success?(response), message, response,
|
261
|
+
:test => test_mode,
|
262
|
+
:authorization => response[:transaction_id],
|
263
|
+
:fraud_review => fraud_review?(response),
|
264
|
+
:avs_result => { :code => response[:avs_result_code] },
|
265
|
+
:cvv_result => response[:card_code]
|
266
|
+
)
|
267
|
+
end
|
268
|
+
|
269
|
+
def success?(response)
|
270
|
+
response[:response_code] == APPROVED
|
271
|
+
end
|
272
|
+
|
273
|
+
def fraud_review?(response)
|
274
|
+
response[:response_code] == FRAUD_REVIEW
|
275
|
+
end
|
276
|
+
|
277
|
+
def parse(body)
|
278
|
+
fields = split(body)
|
279
|
+
|
280
|
+
results = {
|
281
|
+
:response_code => fields[RESPONSE_CODE].to_i,
|
282
|
+
:response_reason_code => fields[RESPONSE_REASON_CODE],
|
283
|
+
:response_reason_text => fields[RESPONSE_REASON_TEXT],
|
284
|
+
:avs_result_code => fields[AVS_RESULT_CODE],
|
285
|
+
:transaction_id => fields[TRANSACTION_ID],
|
286
|
+
:card_code => fields[CARD_CODE_RESPONSE_CODE]
|
287
|
+
}
|
288
|
+
results
|
289
|
+
end
|
290
|
+
|
291
|
+
def post_data(action, parameters = {})
|
292
|
+
post = {}
|
293
|
+
|
294
|
+
post[:version] = API_VERSION
|
295
|
+
post[:login] = @options[:login]
|
296
|
+
post[:tran_key] = @options[:password]
|
297
|
+
post[:relay_response] = "FALSE"
|
298
|
+
post[:type] = action
|
299
|
+
post[:delim_data] = "TRUE"
|
300
|
+
post[:delim_char] = ","
|
301
|
+
post[:encap_char] = "$"
|
302
|
+
|
303
|
+
request = post.merge(parameters).collect { |key, value| "x_#{key}=#{CGI.escape(value.to_s)}" }.join("&")
|
304
|
+
request
|
305
|
+
end
|
306
|
+
|
307
|
+
def add_invoice(post, options)
|
308
|
+
post[:invoice_num] = options[:order_id]
|
309
|
+
post[:description] = options[:description]
|
310
|
+
end
|
311
|
+
|
312
|
+
def add_creditcard(post, creditcard)
|
313
|
+
post[:card_num] = creditcard.number
|
314
|
+
post[:card_code] = creditcard.verification_value if creditcard.verification_value?
|
315
|
+
post[:exp_date] = expdate(creditcard)
|
316
|
+
post[:first_name] = creditcard.first_name
|
317
|
+
post[:last_name] = creditcard.last_name
|
318
|
+
end
|
319
|
+
|
320
|
+
def add_customer_data(post, options)
|
321
|
+
if options.has_key? :email
|
322
|
+
post[:email] = options[:email]
|
323
|
+
post[:email_customer] = false
|
324
|
+
end
|
325
|
+
|
326
|
+
if options.has_key? :customer
|
327
|
+
post[:cust_id] = options[:customer]
|
328
|
+
end
|
329
|
+
|
330
|
+
if options.has_key? :ip
|
331
|
+
post[:customer_ip] = options[:ip]
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
# x_duplicate_window won't be sent by default, because sending it changes the response.
|
336
|
+
# "If this field is present in the request with or without a value, an enhanced duplicate transaction response will be sent."
|
337
|
+
# (as of 2008-12-30) http://www.authorize.net/support/AIM_guide_SCC.pdf
|
338
|
+
def add_duplicate_window(post)
|
339
|
+
unless duplicate_window.nil?
|
340
|
+
post[:duplicate_window] = duplicate_window
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
def add_market_type(post, options)
|
345
|
+
if options[:market_type]
|
346
|
+
post[:market_type] = options[:market_type].to_s
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
def add_address(post, options)
|
351
|
+
if address = options[:billing_address] || options[:address]
|
352
|
+
post[:address] = address[:address1].to_s
|
353
|
+
post[:company] = address[:company].to_s
|
354
|
+
post[:phone] = address[:phone].to_s
|
355
|
+
post[:zip] = address[:zip].to_s
|
356
|
+
post[:city] = address[:city].to_s
|
357
|
+
post[:country] = address[:country].to_s
|
358
|
+
post[:state] = address[:state].blank? ? 'n/a' : address[:state]
|
359
|
+
end
|
360
|
+
|
361
|
+
if address = options[:shipping_address]
|
362
|
+
post[:ship_to_first_name] = address[:first_name].to_s
|
363
|
+
post[:ship_to_last_name] = address[:last_name].to_s
|
364
|
+
post[:ship_to_address] = address[:address1].to_s
|
365
|
+
post[:ship_to_company] = address[:company].to_s
|
366
|
+
post[:ship_to_phone] = address[:phone].to_s
|
367
|
+
post[:ship_to_zip] = address[:zip].to_s
|
368
|
+
post[:ship_to_city] = address[:city].to_s
|
369
|
+
post[:ship_to_country] = address[:country].to_s
|
370
|
+
post[:ship_to_state] = address[:state].blank? ? 'n/a' : address[:state]
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
# Make a ruby type out of the response string
|
375
|
+
def normalize(field)
|
376
|
+
case field
|
377
|
+
when "true" then true
|
378
|
+
when "false" then false
|
379
|
+
when "" then nil
|
380
|
+
when "null" then nil
|
381
|
+
else field
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
def message_from(results)
|
386
|
+
if results[:response_code] == DECLINED
|
387
|
+
return CVVResult.messages[ results[:card_code] ] if CARD_CODE_ERRORS.include?(results[:card_code])
|
388
|
+
if AVS_REASON_CODES.include?(results[:response_reason_code]) && AVS_ERRORS.include?(results[:avs_result_code])
|
389
|
+
return AVSResult.messages[ results[:avs_result_code] ]
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
(results[:response_reason_text] ? results[:response_reason_text].chomp('.') : '')
|
394
|
+
end
|
395
|
+
|
396
|
+
def expdate(creditcard)
|
397
|
+
year = sprintf("%.4i", creditcard.year)
|
398
|
+
month = sprintf("%.2i", creditcard.month)
|
399
|
+
|
400
|
+
"#{month}#{year[-2..-1]}"
|
401
|
+
end
|
402
|
+
|
403
|
+
def split(response)
|
404
|
+
response[1..-2].split(/\$,\$/)
|
405
|
+
end
|
406
|
+
|
407
|
+
# ARB
|
408
|
+
|
409
|
+
# Builds recurring billing request
|
410
|
+
def build_recurring_request(action, options = {})
|
411
|
+
unless RECURRING_ACTIONS.include?(action)
|
412
|
+
raise StandardError, "Invalid Automated Recurring Billing Action: #{action}"
|
413
|
+
end
|
414
|
+
|
415
|
+
xml = Builder::XmlMarkup.new(:indent => 2)
|
416
|
+
xml.instruct!(:xml, :version => '1.0', :encoding => 'utf-8')
|
417
|
+
xml.tag!("#{RECURRING_ACTIONS[action]}Request", :xmlns => AUTHORIZE_NET_ARB_NAMESPACE) do
|
418
|
+
add_arb_merchant_authentication(xml)
|
419
|
+
# Merchant-assigned reference ID for the request
|
420
|
+
xml.tag!('refId', options[:ref_id]) if options[:ref_id]
|
421
|
+
send("build_arb_#{action}_subscription_request", xml, options)
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
# Contains the merchant’s payment gateway account authentication information
|
426
|
+
def add_arb_merchant_authentication(xml)
|
427
|
+
xml.tag!('merchantAuthentication') do
|
428
|
+
xml.tag!('name', @options[:login])
|
429
|
+
xml.tag!('transactionKey', @options[:password])
|
430
|
+
end
|
431
|
+
end
|
432
|
+
|
433
|
+
# Builds body for ARBCreateSubscriptionRequest
|
434
|
+
def build_arb_create_subscription_request(xml, options)
|
435
|
+
# Subscription
|
436
|
+
add_arb_subscription(xml, options)
|
437
|
+
|
438
|
+
xml.target!
|
439
|
+
end
|
440
|
+
|
441
|
+
# Builds body for ARBUpdateSubscriptionRequest
|
442
|
+
def build_arb_update_subscription_request(xml, options)
|
443
|
+
xml.tag!('subscriptionId', options[:subscription_id])
|
444
|
+
# Adds Subscription
|
445
|
+
add_arb_subscription(xml, options)
|
446
|
+
|
447
|
+
xml.target!
|
448
|
+
end
|
449
|
+
|
450
|
+
# Builds body for ARBCancelSubscriptionRequest
|
451
|
+
def build_arb_cancel_subscription_request(xml, options)
|
452
|
+
xml.tag!('subscriptionId', options[:subscription_id])
|
453
|
+
|
454
|
+
xml.target!
|
455
|
+
end
|
456
|
+
|
457
|
+
# Adds subscription information
|
458
|
+
def add_arb_subscription(xml, options)
|
459
|
+
xml.tag!('subscription') do
|
460
|
+
# Merchant-assigned name for the subscription (optional)
|
461
|
+
xml.tag!('name', options[:subscription_name]) if options[:subscription_name]
|
462
|
+
# Contains information about the payment schedule
|
463
|
+
add_arb_payment_schedule(xml, options)
|
464
|
+
# The amount to be billed to the customer
|
465
|
+
# for each payment in the subscription
|
466
|
+
xml.tag!('amount', amount(options[:amount])) if options[:amount]
|
467
|
+
if trial = options[:trial]
|
468
|
+
# The amount to be charged for each payment during a trial period (conditional)
|
469
|
+
xml.tag!('trialAmount', amount(trial[:amount])) if trial[:amount]
|
470
|
+
end
|
471
|
+
# Contains either the customer’s credit card
|
472
|
+
# or bank account payment information
|
473
|
+
add_arb_payment(xml, options)
|
474
|
+
# Contains order information (optional)
|
475
|
+
add_arb_order(xml, options)
|
476
|
+
# Contains information about the customer
|
477
|
+
add_arb_customer(xml, options)
|
478
|
+
# Contains the customer's billing address information
|
479
|
+
add_arb_address(xml, 'billTo', options[:billing_address])
|
480
|
+
# Contains the customer's shipping address information (optional)
|
481
|
+
add_arb_address(xml, 'shipTo', options[:shipping_address])
|
482
|
+
end
|
483
|
+
end
|
484
|
+
|
485
|
+
# Adds information about the interval of time between payments
|
486
|
+
def add_arb_interval(xml, options)
|
487
|
+
interval = options[:interval]
|
488
|
+
return unless interval
|
489
|
+
xml.tag!('interval') do
|
490
|
+
# The measurement of time, in association with the Interval Unit,
|
491
|
+
# that is used to define the frequency of the billing occurrences
|
492
|
+
xml.tag!('length', interval[:length])
|
493
|
+
# The unit of time, in association with the Interval Length,
|
494
|
+
# between each billing occurrence
|
495
|
+
xml.tag!('unit', interval[:unit].to_s)
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
499
|
+
# Adds information about the subscription duration
|
500
|
+
def add_arb_duration(xml, options)
|
501
|
+
duration = options[:duration]
|
502
|
+
return unless duration
|
503
|
+
# The date the subscription begins
|
504
|
+
# (also the date the initial billing occurs)
|
505
|
+
xml.tag!('startDate', duration[:start_date]) if duration[:start_date]
|
506
|
+
# Number of billing occurrences or payments for the subscription
|
507
|
+
xml.tag!('totalOccurrences', duration[:occurrences]) if duration[:occurrences]
|
508
|
+
end
|
509
|
+
|
510
|
+
def add_arb_payment_schedule(xml, options)
|
511
|
+
return unless options[:interval] || options[:duration]
|
512
|
+
xml.tag!('paymentSchedule') do
|
513
|
+
# Contains information about the interval of time between payments
|
514
|
+
add_arb_interval(xml, options)
|
515
|
+
add_arb_duration(xml, options)
|
516
|
+
if trial = options[:trial]
|
517
|
+
# Number of billing occurrences or payments in the trial period (optional)
|
518
|
+
xml.tag!('trialOccurrences', trial[:occurrences]) if trial[:occurrences]
|
519
|
+
end
|
520
|
+
end
|
521
|
+
end
|
522
|
+
|
523
|
+
# Adds customer's credit card or bank account payment information
|
524
|
+
def add_arb_payment(xml, options)
|
525
|
+
return unless options[:credit_card] || options[:bank_account]
|
526
|
+
xml.tag!('payment') do
|
527
|
+
# Contains the customer’s credit card information
|
528
|
+
add_arb_credit_card(xml, options)
|
529
|
+
# Contains the customer’s bank account information
|
530
|
+
add_arb_bank_account(xml, options)
|
531
|
+
end
|
532
|
+
end
|
533
|
+
|
534
|
+
# Adds customer’s credit card information
|
535
|
+
# Note: This element should only be included
|
536
|
+
# when the payment method is credit card.
|
537
|
+
def add_arb_credit_card(xml, options)
|
538
|
+
credit_card = options[:credit_card]
|
539
|
+
return unless credit_card
|
540
|
+
xml.tag!('creditCard') do
|
541
|
+
# The credit card number used for payment of the subscription
|
542
|
+
xml.tag!('cardNumber', credit_card.number)
|
543
|
+
# The expiration date of the credit card used for the subscription
|
544
|
+
xml.tag!('expirationDate', arb_expdate(credit_card))
|
545
|
+
end
|
546
|
+
end
|
547
|
+
|
548
|
+
# Adds customer’s bank account information
|
549
|
+
# Note: This element should only be included
|
550
|
+
# when the payment method is bank account.
|
551
|
+
def add_arb_bank_account(xml, options)
|
552
|
+
bank_account = options[:bank_account]
|
553
|
+
return unless bank_account
|
554
|
+
xml.tag!('bankAccount') do
|
555
|
+
# The type of bank account used for payment of the subscription
|
556
|
+
xml.tag!('accountType', bank_account[:account_type])
|
557
|
+
# The routing number of the customer’s bank
|
558
|
+
xml.tag!('routingNumber', bank_account[:routing_number])
|
559
|
+
# The bank account number used for payment of the subscription
|
560
|
+
xml.tag!('accountNumber', bank_account[:account_number])
|
561
|
+
# The full name of the individual associated
|
562
|
+
# with the bank account number
|
563
|
+
xml.tag!('nameOfAccount', bank_account[:name_of_account])
|
564
|
+
# The full name of the individual associated
|
565
|
+
# with the bank account number (optional)
|
566
|
+
xml.tag!('bankName', bank_account[:bank_name]) if bank_account[:bank_name]
|
567
|
+
# The type of electronic check transaction used for the subscription
|
568
|
+
xml.tag!('echeckType', bank_account[:echeck_type])
|
569
|
+
end
|
570
|
+
end
|
571
|
+
|
572
|
+
# Adds order information (optional)
|
573
|
+
def add_arb_order(xml, options)
|
574
|
+
order = options[:order]
|
575
|
+
return unless order
|
576
|
+
xml.tag!('order') do
|
577
|
+
# Merchant-assigned invoice number for the subscription (optional)
|
578
|
+
xml.tag!('invoiceNumber', order[:invoice_number])
|
579
|
+
# Description of the subscription (optional)
|
580
|
+
xml.tag!('description', order[:description])
|
581
|
+
end
|
582
|
+
end
|
583
|
+
|
584
|
+
# Adds information about the customer
|
585
|
+
def add_arb_customer(xml, options)
|
586
|
+
customer = options[:customer]
|
587
|
+
return unless customer
|
588
|
+
xml.tag!('customer') do
|
589
|
+
xml.tag!('type', customer[:type]) if customer[:type]
|
590
|
+
xml.tag!('id', customer[:id]) if customer[:id]
|
591
|
+
xml.tag!('email', customer[:email]) if customer[:email]
|
592
|
+
xml.tag!('phoneNumber', customer[:phone_number]) if customer[:phone_number]
|
593
|
+
xml.tag!('faxNumber', customer[:fax_number]) if customer[:fax_number]
|
594
|
+
add_arb_drivers_license(xml, options)
|
595
|
+
xml.tag!('taxId', customer[:tax_id]) if customer[:tax_id]
|
596
|
+
end
|
597
|
+
end
|
598
|
+
|
599
|
+
# Adds the customer's driver's license information (conditional)
|
600
|
+
def add_arb_drivers_license(xml, options)
|
601
|
+
return unless customer = options[:customer]
|
602
|
+
return unless drivers_license = customer[:drivers_license]
|
603
|
+
xml.tag!('driversLicense') do
|
604
|
+
# The customer's driver's license number
|
605
|
+
xml.tag!('number', drivers_license[:number])
|
606
|
+
# The customer's driver's license state
|
607
|
+
xml.tag!('state', drivers_license[:state])
|
608
|
+
# The customer's driver's license date of birth
|
609
|
+
xml.tag!('dateOfBirth', drivers_license[:date_of_birth])
|
610
|
+
end
|
611
|
+
end
|
612
|
+
|
613
|
+
# Adds address information
|
614
|
+
def add_arb_address(xml, container_name, address)
|
615
|
+
return if address.blank?
|
616
|
+
xml.tag!(container_name) do
|
617
|
+
xml.tag!('firstName', address[:first_name])
|
618
|
+
xml.tag!('lastName', address[:last_name])
|
619
|
+
xml.tag!('company', address[:company])
|
620
|
+
xml.tag!('address', address[:address1])
|
621
|
+
xml.tag!('city', address[:city])
|
622
|
+
xml.tag!('state', address[:state])
|
623
|
+
xml.tag!('zip', address[:zip])
|
624
|
+
xml.tag!('country', address[:country])
|
625
|
+
end
|
626
|
+
end
|
627
|
+
|
628
|
+
def arb_expdate(credit_card)
|
629
|
+
sprintf('%04d-%02d', credit_card.year, credit_card.month)
|
630
|
+
end
|
631
|
+
|
632
|
+
def recurring_commit(action, request)
|
633
|
+
url = test? ? arb_test_url : arb_live_url
|
634
|
+
xml = ssl_post(url, request, "Content-Type" => "text/xml")
|
635
|
+
|
636
|
+
response = recurring_parse(action, xml)
|
637
|
+
|
638
|
+
message = response[:message] || response[:text]
|
639
|
+
test_mode = test? || message =~ /Test Mode/
|
640
|
+
success = response[:result_code] == 'Ok'
|
641
|
+
|
642
|
+
Response.new(success, message, response,
|
643
|
+
:test => test_mode,
|
644
|
+
:authorization => response[:subscription_id]
|
645
|
+
)
|
646
|
+
end
|
647
|
+
|
648
|
+
def recurring_parse(action, xml)
|
649
|
+
response = {}
|
650
|
+
xml = REXML::Document.new(xml)
|
651
|
+
root = REXML::XPath.first(xml, "//#{RECURRING_ACTIONS[action]}Response") ||
|
652
|
+
REXML::XPath.first(xml, "//ErrorResponse")
|
653
|
+
if root
|
654
|
+
root.elements.to_a.each do |node|
|
655
|
+
recurring_parse_element(response, node)
|
656
|
+
end
|
657
|
+
end
|
658
|
+
|
659
|
+
response
|
660
|
+
end
|
661
|
+
|
662
|
+
def recurring_parse_element(response, node)
|
663
|
+
if node.has_elements?
|
664
|
+
node.elements.each{|e| recurring_parse_element(response, e) }
|
665
|
+
else
|
666
|
+
response[node.name.underscore.to_sym] = node.text
|
667
|
+
end
|
668
|
+
end
|
669
|
+
end
|
670
|
+
end
|
671
|
+
end
|