gonow-activemerchant 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. data/CHANGELOG +690 -0
  2. data/CONTRIBUTORS +237 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +165 -0
  5. data/gem-public_cert.pem +20 -0
  6. data/lib/active_merchant.rb +47 -0
  7. data/lib/active_merchant/billing.rb +9 -0
  8. data/lib/active_merchant/billing/avs_result.rb +98 -0
  9. data/lib/active_merchant/billing/base.rb +57 -0
  10. data/lib/active_merchant/billing/check.rb +68 -0
  11. data/lib/active_merchant/billing/credit_card.rb +178 -0
  12. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  13. data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
  14. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  15. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  16. data/lib/active_merchant/billing/gateway.rb +170 -0
  17. data/lib/active_merchant/billing/gateways.rb +18 -0
  18. data/lib/active_merchant/billing/gateways/authorize_net.rb +664 -0
  19. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +858 -0
  20. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +308 -0
  21. data/lib/active_merchant/billing/gateways/beanstream.rb +139 -0
  22. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +282 -0
  23. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  24. data/lib/active_merchant/billing/gateways/blue_pay.rb +11 -0
  25. data/lib/active_merchant/billing/gateways/bogus.rb +132 -0
  26. data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
  27. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  28. data/lib/active_merchant/billing/gateways/braintree_blue.rb +293 -0
  29. data/lib/active_merchant/billing/gateways/braintree_orange.rb +17 -0
  30. data/lib/active_merchant/billing/gateways/braspag.rb +188 -0
  31. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  32. data/lib/active_merchant/billing/gateways/cyber_source.rb +430 -0
  33. data/lib/active_merchant/billing/gateways/data_cash.rb +597 -0
  34. data/lib/active_merchant/billing/gateways/efsnet.rb +235 -0
  35. data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
  36. data/lib/active_merchant/billing/gateways/epay.rb +268 -0
  37. data/lib/active_merchant/billing/gateways/eway.rb +277 -0
  38. data/lib/active_merchant/billing/gateways/eway_managed.rb +231 -0
  39. data/lib/active_merchant/billing/gateways/exact.rb +222 -0
  40. data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
  41. data/lib/active_merchant/billing/gateways/first_pay.rb +177 -0
  42. data/lib/active_merchant/billing/gateways/garanti.rb +262 -0
  43. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +250 -0
  44. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  45. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  46. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +55 -0
  47. data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
  48. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  49. data/lib/active_merchant/billing/gateways/iridium.rb +258 -0
  50. data/lib/active_merchant/billing/gateways/jetpay.rb +276 -0
  51. data/lib/active_merchant/billing/gateways/linkpoint.rb +454 -0
  52. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +156 -0
  53. data/lib/active_merchant/billing/gateways/merchant_ware.rb +289 -0
  54. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  55. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  56. data/lib/active_merchant/billing/gateways/moneris.rb +209 -0
  57. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  58. data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
  59. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  60. data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
  61. data/lib/active_merchant/billing/gateways/ogone.rb +292 -0
  62. data/lib/active_merchant/billing/gateways/orbital.rb +321 -0
  63. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
  64. data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
  65. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  66. data/lib/active_merchant/billing/gateways/paybox_direct.rb +207 -0
  67. data/lib/active_merchant/billing/gateways/payflow.rb +253 -0
  68. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -0
  69. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  70. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  71. data/lib/active_merchant/billing/gateways/payflow_express.rb +222 -0
  72. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  73. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  74. data/lib/active_merchant/billing/gateways/payment_express.rb +235 -0
  75. data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
  76. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +351 -0
  77. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -0
  78. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  79. data/lib/active_merchant/billing/gateways/paypal_express.rb +177 -0
  80. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +25 -0
  81. data/lib/active_merchant/billing/gateways/plugnpay.rb +298 -0
  82. data/lib/active_merchant/billing/gateways/psigate.rb +219 -0
  83. data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
  84. data/lib/active_merchant/billing/gateways/qbms.rb +295 -0
  85. data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
  86. data/lib/active_merchant/billing/gateways/quickpay.rb +218 -0
  87. data/lib/active_merchant/billing/gateways/realex.rb +311 -0
  88. data/lib/active_merchant/billing/gateways/sage.rb +146 -0
  89. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  90. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
  91. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  92. data/lib/active_merchant/billing/gateways/sage_pay.rb +320 -0
  93. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  94. data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
  95. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  96. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +193 -0
  97. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  98. data/lib/active_merchant/billing/gateways/skip_jack.rb +453 -0
  99. data/lib/active_merchant/billing/gateways/smart_ps.rb +271 -0
  100. data/lib/active_merchant/billing/gateways/stripe.rb +212 -0
  101. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  102. data/lib/active_merchant/billing/gateways/transax.rb +25 -0
  103. data/lib/active_merchant/billing/gateways/trust_commerce.rb +423 -0
  104. data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
  105. data/lib/active_merchant/billing/gateways/verifi.rb +233 -0
  106. data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
  107. data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
  108. data/lib/active_merchant/billing/gateways/worldpay.rb +280 -0
  109. data/lib/active_merchant/billing/integrations.rb +17 -0
  110. data/lib/active_merchant/billing/integrations/action_view_helper.rb +68 -0
  111. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  112. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  113. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  114. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  115. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  116. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
  117. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
  118. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  119. data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
  120. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +200 -0
  121. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
  122. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
  123. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
  124. data/lib/active_merchant/billing/integrations/directebanking.rb +47 -0
  125. data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
  126. data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
  127. data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
  128. data/lib/active_merchant/billing/integrations/e_payment_plans.rb +48 -0
  129. data/lib/active_merchant/billing/integrations/e_payment_plans/helper.rb +34 -0
  130. data/lib/active_merchant/billing/integrations/e_payment_plans/notification.rb +84 -0
  131. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  132. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  133. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  134. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
  135. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  136. data/lib/active_merchant/billing/integrations/helper.rb +96 -0
  137. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  138. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  139. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  140. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  141. data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
  142. data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +59 -0
  143. data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
  144. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  145. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  146. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  147. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  148. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  149. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  150. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  151. data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
  152. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  153. data/lib/active_merchant/billing/integrations/quickpay.rb +21 -0
  154. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
  155. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  156. data/lib/active_merchant/billing/integrations/return.rb +42 -0
  157. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
  158. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
  159. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +111 -0
  160. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
  161. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -0
  162. data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
  163. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
  164. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
  165. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  166. data/lib/active_merchant/billing/integrations/valitor.rb +33 -0
  167. data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
  168. data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
  169. data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +97 -0
  170. data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
  171. data/lib/active_merchant/billing/integrations/world_pay.rb +27 -0
  172. data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
  173. data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -0
  174. data/lib/active_merchant/billing/response.rb +32 -0
  175. data/lib/active_merchant/common.rb +14 -0
  176. data/lib/active_merchant/common/connection.rb +177 -0
  177. data/lib/active_merchant/common/country.rb +328 -0
  178. data/lib/active_merchant/common/error.rb +26 -0
  179. data/lib/active_merchant/common/post_data.rb +24 -0
  180. data/lib/active_merchant/common/posts_data.rb +63 -0
  181. data/lib/active_merchant/common/requires_parameters.rb +16 -0
  182. data/lib/active_merchant/common/utils.rb +22 -0
  183. data/lib/active_merchant/common/validateable.rb +81 -0
  184. data/lib/active_merchant/version.rb +3 -0
  185. data/lib/activemerchant.rb +1 -0
  186. data/lib/certs/cacert.pem +7815 -0
  187. data/lib/support/gateway_support.rb +58 -0
  188. data/lib/support/outbound_hosts.rb +25 -0
  189. metadata +276 -0
@@ -0,0 +1,38 @@
1
+ module ActiveMerchant
2
+ module Billing
3
+ # Result of the Card Verification Value check
4
+ # http://www.bbbonline.org/eExport/doc/MerchantGuide_cvv2.pdf
5
+ # Check additional codes from cybersource website
6
+ class CVVResult
7
+
8
+ MESSAGES = {
9
+ 'D' => 'Suspicious transaction',
10
+ 'I' => 'Failed data validation check',
11
+ 'M' => 'Match',
12
+ 'N' => 'No Match',
13
+ 'P' => 'Not Processed',
14
+ 'S' => 'Should have been present',
15
+ 'U' => 'Issuer unable to process request',
16
+ 'X' => 'Card does not support verification'
17
+ }
18
+
19
+ def self.messages
20
+ MESSAGES
21
+ end
22
+
23
+ attr_reader :code, :message
24
+
25
+ def initialize(code)
26
+ @code = code.upcase unless code.blank?
27
+ @message = MESSAGES[@code]
28
+ end
29
+
30
+ def to_hash
31
+ {
32
+ 'code' => code,
33
+ 'message' => message
34
+ }
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,34 @@
1
+ require 'date'
2
+
3
+ module ActiveMerchant
4
+ module Billing
5
+ class CreditCard
6
+ class ExpiryDate #:nodoc:
7
+ attr_reader :month, :year
8
+ def initialize(month, year)
9
+ @month = month.to_i
10
+ @year = year.to_i
11
+ end
12
+
13
+ def expired? #:nodoc:
14
+ Time.now.utc > expiration
15
+ end
16
+
17
+ def expiration #:nodoc:
18
+ begin
19
+ Time.utc(year, month, month_days, 23, 59, 59)
20
+ rescue ArgumentError
21
+ Time.at(0).utc
22
+ end
23
+ end
24
+
25
+ private
26
+ def month_days
27
+ mdays = [nil,31,28,31,30,31,30,31,31,30,31,30,31]
28
+ mdays[2] = 29 if Date.leap?(year)
29
+ mdays[month]
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,170 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'active_merchant/billing/response'
4
+
5
+ module ActiveMerchant #:nodoc:
6
+ module Billing #:nodoc:
7
+ #
8
+ # == Description
9
+ # The Gateway class is the base class for all ActiveMerchant gateway implementations.
10
+ #
11
+ # The standard list of gateway functions that most concrete gateway subclasses implement is:
12
+ #
13
+ # * <tt>purchase(money, creditcard, options = {})</tt>
14
+ # * <tt>authorize(money, creditcard, options = {})</tt>
15
+ # * <tt>capture(money, authorization, options = {})</tt>
16
+ # * <tt>void(identification, options = {})</tt>
17
+ # * <tt>credit(money, identification, options = {})</tt>
18
+ #
19
+ # Some gateways include features for recurring billing
20
+ #
21
+ # * <tt>recurring(money, creditcard, options = {})</tt>
22
+ #
23
+ # Some gateways also support features for storing credit cards:
24
+ #
25
+ # * <tt>store(creditcard, options = {})</tt>
26
+ # * <tt>unstore(identification, options = {})</tt>
27
+ #
28
+ # === Gateway Options
29
+ # The options hash consists of the following options:
30
+ #
31
+ # * <tt>:order_id</tt> - The order number
32
+ # * <tt>:ip</tt> - The IP address of the customer making the purchase
33
+ # * <tt>:customer</tt> - The name, customer number, or other information that identifies the customer
34
+ # * <tt>:invoice</tt> - The invoice number
35
+ # * <tt>:merchant</tt> - The name or description of the merchant offering the product
36
+ # * <tt>:description</tt> - A description of the transaction
37
+ # * <tt>:email</tt> - The email address of the customer
38
+ # * <tt>:currency</tt> - The currency of the transaction. Only important when you are using a currency that is not the default with a gateway that supports multiple currencies.
39
+ # * <tt>:billing_address</tt> - A hash containing the billing address of the customer.
40
+ # * <tt>:shipping_address</tt> - A hash containing the shipping address of the customer.
41
+ #
42
+ # The <tt>:billing_address</tt>, and <tt>:shipping_address</tt> hashes can have the following keys:
43
+ #
44
+ # * <tt>:name</tt> - The full name of the customer.
45
+ # * <tt>:company</tt> - The company name of the customer.
46
+ # * <tt>:address1</tt> - The primary street address of the customer.
47
+ # * <tt>:address2</tt> - Additional line of address information.
48
+ # * <tt>:city</tt> - The city of the customer.
49
+ # * <tt>:state</tt> - The state of the customer. The 2 digit code for US and Canadian addresses. The full name of the state or province for foreign addresses.
50
+ # * <tt>:country</tt> - The [ISO 3166-1-alpha-2 code](http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm) for the customer.
51
+ # * <tt>:zip</tt> - The zip or postal code of the customer.
52
+ # * <tt>:phone</tt> - The phone number of the customer.
53
+ #
54
+ # == Implmenting new gateways
55
+ #
56
+ # See the {ActiveMerchant Guide to Contributing}[http://code.google.com/p/activemerchant/wiki/Contributing]
57
+ #
58
+ class Gateway
59
+ include PostsData
60
+ include RequiresParameters
61
+ include CreditCardFormatting
62
+ include Utils
63
+
64
+ DEBIT_CARDS = [ :switch, :solo ]
65
+ CURRENCIES_WITHOUT_FRACTIONS = [ 'JPY' ]
66
+ CREDIT_DEPRECATION_MESSAGE = "Support for using credit to refund existing transactions is deprecated and will be removed from a future release of ActiveMerchant. Please use the refund method instead."
67
+
68
+ cattr_reader :implementations
69
+ @@implementations = []
70
+
71
+ def self.inherited(subclass)
72
+ super
73
+ @@implementations << subclass
74
+ end
75
+
76
+ # The format of the amounts used by the gateway
77
+ # :dollars => '12.50'
78
+ # :cents => '1250'
79
+ class_attribute :money_format
80
+ self.money_format = :dollars
81
+
82
+ # The default currency for the transactions if no currency is provided
83
+ class_attribute :default_currency
84
+
85
+ # The countries of merchants the gateway supports
86
+ class_attribute :supported_countries
87
+ self.supported_countries = []
88
+
89
+ # The supported card types for the gateway
90
+ class_attribute :supported_cardtypes
91
+ self.supported_cardtypes = []
92
+
93
+ class_attribute :homepage_url
94
+ class_attribute :display_name
95
+
96
+ # The application making the calls to the gateway
97
+ # Useful for things like the PayPal build notation (BN) id fields
98
+ superclass_delegating_accessor :application_id
99
+ self.application_id = 'ActiveMerchant'
100
+
101
+ attr_reader :options
102
+
103
+ # Use this method to check if your gateway of interest supports a credit card of some type
104
+ def self.supports?(card_type)
105
+ supported_cardtypes.include?(card_type.to_sym)
106
+ end
107
+
108
+ def self.card_brand(source)
109
+ result = source.respond_to?(:brand) ? source.brand : source.type
110
+ result.to_s.downcase
111
+ end
112
+
113
+ def card_brand(source)
114
+ self.class.card_brand(source)
115
+ end
116
+
117
+ # Initialize a new gateway.
118
+ #
119
+ # See the documentation for the gateway you will be using to make sure there are no other
120
+ # required options.
121
+ def initialize(options = {})
122
+ end
123
+
124
+ # Are we running in test mode?
125
+ def test?
126
+ Base.gateway_mode == :test
127
+ end
128
+
129
+ private # :nodoc: all
130
+
131
+ def name
132
+ self.class.name.scan(/\:\:(\w+)Gateway/).flatten.first
133
+ end
134
+
135
+ def amount(money)
136
+ return nil if money.nil?
137
+ cents = if money.respond_to?(:cents)
138
+ deprecated "Support for Money objects is deprecated and will be removed from a future release of ActiveMerchant. Please use an Integer value in cents"
139
+ money.cents
140
+ else
141
+ money
142
+ end
143
+
144
+ if money.is_a?(String)
145
+ raise ArgumentError, 'money amount must be a positive Integer in cents.'
146
+ end
147
+
148
+ if self.money_format == :cents
149
+ cents.to_s
150
+ else
151
+ sprintf("%.2f", cents.to_f / 100)
152
+ end
153
+ end
154
+
155
+ def localized_amount(money, currency)
156
+ amount = amount(money)
157
+ CURRENCIES_WITHOUT_FRACTIONS.include?(currency.to_s) ? amount.split('.').first : amount
158
+ end
159
+
160
+ def currency(money)
161
+ money.respond_to?(:currency) ? money.currency : self.default_currency
162
+ end
163
+
164
+ def requires_start_date_or_issue_number?(credit_card)
165
+ return false if card_brand(credit_card).blank?
166
+ DEBIT_CARDS.include?(card_brand(credit_card).to_sym)
167
+ end
168
+ end
169
+ end
170
+ end
@@ -0,0 +1,18 @@
1
+ module ActiveMerchant
2
+ module Billing
3
+ autoload :Gateway, 'active_merchant/billing/gateway'
4
+
5
+ Dir[File.dirname(__FILE__) + '/gateways/**/*.rb'].each do |f|
6
+
7
+ # Get camelized class name
8
+ filename = File.basename(f, '.rb')
9
+ # Add _gateway suffix
10
+ gateway_name = filename + '_gateway'
11
+ # Camelize the string to get the class name
12
+ gateway_class = gateway_name.camelize
13
+
14
+ # Register for autoloading
15
+ autoload gateway_class, f
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,664 @@
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, :diners_club, :jcb]
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
+
161
+ commit('CREDIT', money, post)
162
+ end
163
+
164
+ def credit(money, identification, options = {})
165
+ deprecated CREDIT_DEPRECATION_MESSAGE
166
+ refund(money, identification, options)
167
+ end
168
+
169
+ # Create a recurring payment.
170
+ #
171
+ # This transaction creates a new Automated Recurring Billing (ARB) subscription. Your account must have ARB enabled.
172
+ #
173
+ # ==== Parameters
174
+ #
175
+ # * <tt>money</tt> -- The amount to be charged to the customer at each interval as an Integer value in cents.
176
+ # * <tt>creditcard</tt> -- The CreditCard details for the transaction.
177
+ # * <tt>options</tt> -- A hash of parameters.
178
+ #
179
+ # ==== Options
180
+ #
181
+ # * <tt>:interval</tt> -- A hash containing information about the interval of time between payments. Must
182
+ # contain the keys <tt>:length</tt> and <tt>:unit</tt>. <tt>:unit</tt> can be either <tt>:months</tt> or <tt>:days</tt>.
183
+ # If <tt>:unit</tt> is <tt>:months</tt> then <tt>:length</tt> must be an integer between 1 and 12 inclusive.
184
+ # If <tt>:unit</tt> is <tt>:days</tt> then <tt>:length</tt> must be an integer between 7 and 365 inclusive.
185
+ # For example, to charge the customer once every three months the hash would be
186
+ # +:interval => { :unit => :months, :length => 3 }+ (REQUIRED)
187
+ # * <tt>:duration</tt> -- A hash containing keys for the <tt>:start_date</tt> the subscription begins (also the date the
188
+ # initial billing occurs) and the total number of billing <tt>:occurences</tt> or payments for the subscription. (REQUIRED)
189
+ def recurring(money, creditcard, options={})
190
+ requires!(options, :interval, :duration, :billing_address)
191
+ requires!(options[:interval], :length, [:unit, :days, :months])
192
+ requires!(options[:duration], :start_date, :occurrences)
193
+ requires!(options[:billing_address], :first_name, :last_name)
194
+
195
+ options[:credit_card] = creditcard
196
+ options[:amount] = money
197
+
198
+ request = build_recurring_request(:create, options)
199
+ recurring_commit(:create, request)
200
+ end
201
+
202
+ # Update a recurring payment's details.
203
+ #
204
+ # This transaction updates an existing Automated Recurring Billing (ARB) subscription. Your account must have ARB enabled
205
+ # and the subscription must have already been created previously by calling +recurring()+. The ability to change certain
206
+ # details about a recurring payment is dependent on transaction history and cannot be determined until after calling
207
+ # +update_recurring()+. See the ARB XML Guide for such conditions.
208
+ #
209
+ # ==== Parameters
210
+ #
211
+ # * <tt>options</tt> -- A hash of parameters.
212
+ #
213
+ # ==== Options
214
+ #
215
+ # * <tt>:subscription_id</tt> -- A string containing the <tt>:subscription_id</tt> of the recurring payment already in place
216
+ # for a given credit card. (REQUIRED)
217
+ def update_recurring(options={})
218
+ requires!(options, :subscription_id)
219
+ request = build_recurring_request(:update, options)
220
+ recurring_commit(:update, request)
221
+ end
222
+
223
+ # Cancel a recurring payment.
224
+ #
225
+ # This transaction cancels an existing Automated Recurring Billing (ARB) subscription. Your account must have ARB enabled
226
+ # and the subscription must have already been created previously by calling recurring()
227
+ #
228
+ # ==== Parameters
229
+ #
230
+ # * <tt>subscription_id</tt> -- A string containing the +subscription_id+ of the recurring payment already in place
231
+ # for a given credit card. (REQUIRED)
232
+ def cancel_recurring(subscription_id)
233
+ request = build_recurring_request(:cancel, :subscription_id => subscription_id)
234
+ recurring_commit(:cancel, request)
235
+ end
236
+
237
+ private
238
+
239
+ def commit(action, money, parameters)
240
+ parameters[:amount] = amount(money) unless action == 'VOID'
241
+
242
+ # Only activate the test_request when the :test option is passed in
243
+ parameters[:test_request] = @options[:test] ? 'TRUE' : 'FALSE'
244
+
245
+ url = test? ? self.test_url : self.live_url
246
+ data = ssl_post url, post_data(action, parameters)
247
+
248
+ response = parse(data)
249
+
250
+ message = message_from(response)
251
+
252
+ # Return the response. The authorization can be taken out of the transaction_id
253
+ # Test Mode on/off is something we have to parse from the response text.
254
+ # It usually looks something like this
255
+ #
256
+ # (TESTMODE) Successful Sale
257
+ test_mode = test? || message =~ /TESTMODE/
258
+
259
+ Response.new(success?(response), message, response,
260
+ :test => test_mode,
261
+ :authorization => response[:transaction_id],
262
+ :fraud_review => fraud_review?(response),
263
+ :avs_result => { :code => response[:avs_result_code] },
264
+ :cvv_result => response[:card_code]
265
+ )
266
+ end
267
+
268
+ def success?(response)
269
+ response[:response_code] == APPROVED
270
+ end
271
+
272
+ def fraud_review?(response)
273
+ response[:response_code] == FRAUD_REVIEW
274
+ end
275
+
276
+ def parse(body)
277
+ fields = split(body)
278
+
279
+ results = {
280
+ :response_code => fields[RESPONSE_CODE].to_i,
281
+ :response_reason_code => fields[RESPONSE_REASON_CODE],
282
+ :response_reason_text => fields[RESPONSE_REASON_TEXT],
283
+ :avs_result_code => fields[AVS_RESULT_CODE],
284
+ :transaction_id => fields[TRANSACTION_ID],
285
+ :card_code => fields[CARD_CODE_RESPONSE_CODE]
286
+ }
287
+ results
288
+ end
289
+
290
+ def post_data(action, parameters = {})
291
+ post = {}
292
+
293
+ post[:version] = API_VERSION
294
+ post[:login] = @options[:login]
295
+ post[:tran_key] = @options[:password]
296
+ post[:relay_response] = "FALSE"
297
+ post[:type] = action
298
+ post[:delim_data] = "TRUE"
299
+ post[:delim_char] = ","
300
+ post[:encap_char] = "$"
301
+
302
+ request = post.merge(parameters).collect { |key, value| "x_#{key}=#{CGI.escape(value.to_s)}" }.join("&")
303
+ request
304
+ end
305
+
306
+ def add_invoice(post, options)
307
+ post[:invoice_num] = options[:order_id]
308
+ post[:description] = options[:description]
309
+ end
310
+
311
+ def add_creditcard(post, creditcard)
312
+ post[:card_num] = creditcard.number
313
+ post[:card_code] = creditcard.verification_value if creditcard.verification_value?
314
+ post[:exp_date] = expdate(creditcard)
315
+ post[:first_name] = creditcard.first_name
316
+ post[:last_name] = creditcard.last_name
317
+ end
318
+
319
+ def add_customer_data(post, options)
320
+ if options.has_key? :email
321
+ post[:email] = options[:email]
322
+ post[:email_customer] = false
323
+ end
324
+
325
+ if options.has_key? :customer
326
+ post[:cust_id] = options[:customer]
327
+ end
328
+
329
+ if options.has_key? :ip
330
+ post[:customer_ip] = options[:ip]
331
+ end
332
+ end
333
+
334
+ # x_duplicate_window won't be sent by default, because sending it changes the response.
335
+ # "If this field is present in the request with or without a value, an enhanced duplicate transaction response will be sent."
336
+ # (as of 2008-12-30) http://www.authorize.net/support/AIM_guide_SCC.pdf
337
+ def add_duplicate_window(post)
338
+ unless duplicate_window.nil?
339
+ post[:duplicate_window] = duplicate_window
340
+ end
341
+ end
342
+
343
+ def add_address(post, options)
344
+ if address = options[:billing_address] || options[:address]
345
+ post[:address] = address[:address1].to_s
346
+ post[:company] = address[:company].to_s
347
+ post[:phone] = address[:phone].to_s
348
+ post[:zip] = address[:zip].to_s
349
+ post[:city] = address[:city].to_s
350
+ post[:country] = address[:country].to_s
351
+ post[:state] = address[:state].blank? ? 'n/a' : address[:state]
352
+ end
353
+
354
+ if address = options[:shipping_address]
355
+ post[:ship_to_first_name] = address[:first_name].to_s
356
+ post[:ship_to_last_name] = address[:last_name].to_s
357
+ post[:ship_to_address] = address[:address1].to_s
358
+ post[:ship_to_company] = address[:company].to_s
359
+ post[:ship_to_phone] = address[:phone].to_s
360
+ post[:ship_to_zip] = address[:zip].to_s
361
+ post[:ship_to_city] = address[:city].to_s
362
+ post[:ship_to_country] = address[:country].to_s
363
+ post[:ship_to_state] = address[:state].blank? ? 'n/a' : address[:state]
364
+ end
365
+ end
366
+
367
+ # Make a ruby type out of the response string
368
+ def normalize(field)
369
+ case field
370
+ when "true" then true
371
+ when "false" then false
372
+ when "" then nil
373
+ when "null" then nil
374
+ else field
375
+ end
376
+ end
377
+
378
+ def message_from(results)
379
+ if results[:response_code] == DECLINED
380
+ return CVVResult.messages[ results[:card_code] ] if CARD_CODE_ERRORS.include?(results[:card_code])
381
+ if AVS_REASON_CODES.include?(results[:response_reason_code]) && AVS_ERRORS.include?(results[:avs_result_code])
382
+ return AVSResult.messages[ results[:avs_result_code] ]
383
+ end
384
+ end
385
+
386
+ (results[:response_reason_text] ? results[:response_reason_text].chomp('.') : '')
387
+ end
388
+
389
+ def expdate(creditcard)
390
+ year = sprintf("%.4i", creditcard.year)
391
+ month = sprintf("%.2i", creditcard.month)
392
+
393
+ "#{month}#{year[-2..-1]}"
394
+ end
395
+
396
+ def split(response)
397
+ response[1..-2].split(/\$,\$/)
398
+ end
399
+
400
+ # ARB
401
+
402
+ # Builds recurring billing request
403
+ def build_recurring_request(action, options = {})
404
+ unless RECURRING_ACTIONS.include?(action)
405
+ raise StandardError, "Invalid Automated Recurring Billing Action: #{action}"
406
+ end
407
+
408
+ xml = Builder::XmlMarkup.new(:indent => 2)
409
+ xml.instruct!(:xml, :version => '1.0', :encoding => 'utf-8')
410
+ xml.tag!("#{RECURRING_ACTIONS[action]}Request", :xmlns => AUTHORIZE_NET_ARB_NAMESPACE) do
411
+ add_arb_merchant_authentication(xml)
412
+ # Merchant-assigned reference ID for the request
413
+ xml.tag!('refId', options[:ref_id]) if options[:ref_id]
414
+ send("build_arb_#{action}_subscription_request", xml, options)
415
+ end
416
+ end
417
+
418
+ # Contains the merchant’s payment gateway account authentication information
419
+ def add_arb_merchant_authentication(xml)
420
+ xml.tag!('merchantAuthentication') do
421
+ xml.tag!('name', @options[:login])
422
+ xml.tag!('transactionKey', @options[:password])
423
+ end
424
+ end
425
+
426
+ # Builds body for ARBCreateSubscriptionRequest
427
+ def build_arb_create_subscription_request(xml, options)
428
+ # Subscription
429
+ add_arb_subscription(xml, options)
430
+
431
+ xml.target!
432
+ end
433
+
434
+ # Builds body for ARBUpdateSubscriptionRequest
435
+ def build_arb_update_subscription_request(xml, options)
436
+ xml.tag!('subscriptionId', options[:subscription_id])
437
+ # Adds Subscription
438
+ add_arb_subscription(xml, options)
439
+
440
+ xml.target!
441
+ end
442
+
443
+ # Builds body for ARBCancelSubscriptionRequest
444
+ def build_arb_cancel_subscription_request(xml, options)
445
+ xml.tag!('subscriptionId', options[:subscription_id])
446
+
447
+ xml.target!
448
+ end
449
+
450
+ # Adds subscription information
451
+ def add_arb_subscription(xml, options)
452
+ xml.tag!('subscription') do
453
+ # Merchant-assigned name for the subscription (optional)
454
+ xml.tag!('name', options[:subscription_name]) if options[:subscription_name]
455
+ # Contains information about the payment schedule
456
+ add_arb_payment_schedule(xml, options)
457
+ # The amount to be billed to the customer
458
+ # for each payment in the subscription
459
+ xml.tag!('amount', amount(options[:amount])) if options[:amount]
460
+ if trial = options[:trial]
461
+ # The amount to be charged for each payment during a trial period (conditional)
462
+ xml.tag!('trialAmount', amount(trial[:amount])) if trial[:amount]
463
+ end
464
+ # Contains either the customer’s credit card
465
+ # or bank account payment information
466
+ add_arb_payment(xml, options)
467
+ # Contains order information (optional)
468
+ add_arb_order(xml, options)
469
+ # Contains information about the customer
470
+ add_arb_customer(xml, options)
471
+ # Contains the customer's billing address information
472
+ add_arb_address(xml, 'billTo', options[:billing_address])
473
+ # Contains the customer's shipping address information (optional)
474
+ add_arb_address(xml, 'shipTo', options[:shipping_address])
475
+ end
476
+ end
477
+
478
+ # Adds information about the interval of time between payments
479
+ def add_arb_interval(xml, options)
480
+ interval = options[:interval]
481
+ return unless interval
482
+ xml.tag!('interval') do
483
+ # The measurement of time, in association with the Interval Unit,
484
+ # that is used to define the frequency of the billing occurrences
485
+ xml.tag!('length', interval[:length])
486
+ # The unit of time, in association with the Interval Length,
487
+ # between each billing occurrence
488
+ xml.tag!('unit', interval[:unit].to_s)
489
+ end
490
+ end
491
+
492
+ # Adds information about the subscription duration
493
+ def add_arb_duration(xml, options)
494
+ duration = options[:duration]
495
+ return unless duration
496
+ # The date the subscription begins
497
+ # (also the date the initial billing occurs)
498
+ xml.tag!('startDate', duration[:start_date]) if duration[:start_date]
499
+ # Number of billing occurrences or payments for the subscription
500
+ xml.tag!('totalOccurrences', duration[:occurrences]) if duration[:occurrences]
501
+ end
502
+
503
+ def add_arb_payment_schedule(xml, options)
504
+ return unless options[:interval] || options[:duration]
505
+ xml.tag!('paymentSchedule') do
506
+ # Contains information about the interval of time between payments
507
+ add_arb_interval(xml, options)
508
+ add_arb_duration(xml, options)
509
+ if trial = options[:trial]
510
+ # Number of billing occurrences or payments in the trial period (optional)
511
+ xml.tag!('trialOccurrences', trial[:occurrences]) if trial[:occurrences]
512
+ end
513
+ end
514
+ end
515
+
516
+ # Adds customer's credit card or bank account payment information
517
+ def add_arb_payment(xml, options)
518
+ return unless options[:credit_card] || options[:bank_account]
519
+ xml.tag!('payment') do
520
+ # Contains the customer’s credit card information
521
+ add_arb_credit_card(xml, options)
522
+ # Contains the customer’s bank account information
523
+ add_arb_bank_account(xml, options)
524
+ end
525
+ end
526
+
527
+ # Adds customer’s credit card information
528
+ # Note: This element should only be included
529
+ # when the payment method is credit card.
530
+ def add_arb_credit_card(xml, options)
531
+ credit_card = options[:credit_card]
532
+ return unless credit_card
533
+ xml.tag!('creditCard') do
534
+ # The credit card number used for payment of the subscription
535
+ xml.tag!('cardNumber', credit_card.number)
536
+ # The expiration date of the credit card used for the subscription
537
+ xml.tag!('expirationDate', arb_expdate(credit_card))
538
+ end
539
+ end
540
+
541
+ # Adds customer’s bank account information
542
+ # Note: This element should only be included
543
+ # when the payment method is bank account.
544
+ def add_arb_bank_account(xml, options)
545
+ bank_account = options[:bank_account]
546
+ return unless bank_account
547
+ xml.tag!('bankAccount') do
548
+ # The type of bank account used for payment of the subscription
549
+ xml.tag!('accountType', bank_account[:account_type])
550
+ # The routing number of the customer’s bank
551
+ xml.tag!('routingNumber', bank_account[:routing_number])
552
+ # The bank account number used for payment of the subscription
553
+ xml.tag!('accountNumber', bank_account[:account_number])
554
+ # The full name of the individual associated
555
+ # with the bank account number
556
+ xml.tag!('nameOfAccount', bank_account[:name_of_account])
557
+ # The full name of the individual associated
558
+ # with the bank account number (optional)
559
+ xml.tag!('bankName', bank_account[:bank_name]) if bank_account[:bank_name]
560
+ # The type of electronic check transaction used for the subscription
561
+ xml.tag!('echeckType', bank_account[:echeck_type])
562
+ end
563
+ end
564
+
565
+ # Adds order information (optional)
566
+ def add_arb_order(xml, options)
567
+ order = options[:order]
568
+ return unless order
569
+ xml.tag!('order') do
570
+ # Merchant-assigned invoice number for the subscription (optional)
571
+ xml.tag!('invoiceNumber', order[:invoice_number])
572
+ # Description of the subscription (optional)
573
+ xml.tag!('description', order[:description])
574
+ end
575
+ end
576
+
577
+ # Adds information about the customer
578
+ def add_arb_customer(xml, options)
579
+ customer = options[:customer]
580
+ return unless customer
581
+ xml.tag!('customer') do
582
+ xml.tag!('type', customer[:type]) if customer[:type]
583
+ xml.tag!('id', customer[:id]) if customer[:id]
584
+ xml.tag!('email', customer[:email]) if customer[:email]
585
+ xml.tag!('phoneNumber', customer[:phone_number]) if customer[:phone_number]
586
+ xml.tag!('faxNumber', customer[:fax_number]) if customer[:fax_number]
587
+ add_arb_drivers_license(xml, options)
588
+ xml.tag!('taxId', customer[:tax_id]) if customer[:tax_id]
589
+ end
590
+ end
591
+
592
+ # Adds the customer's driver's license information (conditional)
593
+ def add_arb_drivers_license(xml, options)
594
+ return unless customer = options[:customer]
595
+ return unless drivers_license = customer[:drivers_license]
596
+ xml.tag!('driversLicense') do
597
+ # The customer's driver's license number
598
+ xml.tag!('number', drivers_license[:number])
599
+ # The customer's driver's license state
600
+ xml.tag!('state', drivers_license[:state])
601
+ # The customer's driver's license date of birth
602
+ xml.tag!('dateOfBirth', drivers_license[:date_of_birth])
603
+ end
604
+ end
605
+
606
+ # Adds address information
607
+ def add_arb_address(xml, container_name, address)
608
+ return if address.blank?
609
+ xml.tag!(container_name) do
610
+ xml.tag!('firstName', address[:first_name])
611
+ xml.tag!('lastName', address[:last_name])
612
+ xml.tag!('company', address[:company])
613
+ xml.tag!('address', address[:address1])
614
+ xml.tag!('city', address[:city])
615
+ xml.tag!('state', address[:state])
616
+ xml.tag!('zip', address[:zip])
617
+ xml.tag!('country', address[:country])
618
+ end
619
+ end
620
+
621
+ def arb_expdate(credit_card)
622
+ sprintf('%04d-%02d', credit_card.year, credit_card.month)
623
+ end
624
+
625
+ def recurring_commit(action, request)
626
+ url = test? ? arb_test_url : arb_live_url
627
+ xml = ssl_post(url, request, "Content-Type" => "text/xml")
628
+
629
+ response = recurring_parse(action, xml)
630
+
631
+ message = response[:message] || response[:text]
632
+ test_mode = test? || message =~ /Test Mode/
633
+ success = response[:result_code] == 'Ok'
634
+
635
+ Response.new(success, message, response,
636
+ :test => test_mode,
637
+ :authorization => response[:subscription_id]
638
+ )
639
+ end
640
+
641
+ def recurring_parse(action, xml)
642
+ response = {}
643
+ xml = REXML::Document.new(xml)
644
+ root = REXML::XPath.first(xml, "//#{RECURRING_ACTIONS[action]}Response") ||
645
+ REXML::XPath.first(xml, "//ErrorResponse")
646
+ if root
647
+ root.elements.to_a.each do |node|
648
+ recurring_parse_element(response, node)
649
+ end
650
+ end
651
+
652
+ response
653
+ end
654
+
655
+ def recurring_parse_element(response, node)
656
+ if node.has_elements?
657
+ node.elements.each{|e| recurring_parse_element(response, e) }
658
+ else
659
+ response[node.name.underscore.to_sym] = node.text
660
+ end
661
+ end
662
+ end
663
+ end
664
+ end