activemerchant 1.28.0 → 1.29.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data.tar.gz.sig +3 -3
  2. data/CHANGELOG +36 -0
  3. data/CONTRIBUTORS +8 -0
  4. data/README.md +5 -0
  5. data/lib/active_merchant/billing/gateway.rb +2 -1
  6. data/lib/active_merchant/billing/gateways.rb +6 -7
  7. data/lib/active_merchant/billing/gateways/authorize_net.rb +3 -2
  8. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +77 -78
  9. data/lib/active_merchant/billing/gateways/balanced.rb +0 -1
  10. data/lib/active_merchant/billing/gateways/banwire.rb +1 -2
  11. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +19 -20
  12. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +35 -36
  13. data/lib/active_merchant/billing/gateways/blue_pay.rb +135 -140
  14. data/lib/active_merchant/billing/gateways/braintree_blue.rb +12 -4
  15. data/lib/active_merchant/billing/gateways/card_stream.rb +54 -59
  16. data/lib/active_merchant/billing/gateways/certo_direct.rb +0 -1
  17. data/lib/active_merchant/billing/gateways/cyber_source.rb +19 -14
  18. data/lib/active_merchant/billing/gateways/data_cash.rb +106 -112
  19. data/lib/active_merchant/billing/gateways/efsnet.rb +29 -34
  20. data/lib/active_merchant/billing/gateways/elavon.rb +7 -1
  21. data/lib/active_merchant/billing/gateways/epay.rb +0 -1
  22. data/lib/active_merchant/billing/gateways/eway.rb +88 -93
  23. data/lib/active_merchant/billing/gateways/eway_managed.rb +47 -51
  24. data/lib/active_merchant/billing/gateways/exact.rb +45 -54
  25. data/lib/active_merchant/billing/gateways/federated_canada.rb +3 -4
  26. data/lib/active_merchant/billing/gateways/first_pay.rb +37 -38
  27. data/lib/active_merchant/billing/gateways/garanti.rb +1 -2
  28. data/lib/active_merchant/billing/gateways/hdfc.rb +207 -0
  29. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +5 -8
  30. data/lib/active_merchant/billing/gateways/inspire.rb +52 -52
  31. data/lib/active_merchant/billing/gateways/instapay.rb +10 -11
  32. data/lib/active_merchant/billing/gateways/iridium.rb +38 -39
  33. data/lib/active_merchant/billing/gateways/itransact.rb +7 -9
  34. data/lib/active_merchant/billing/gateways/jetpay.rb +45 -46
  35. data/lib/active_merchant/billing/gateways/linkpoint.rb +104 -108
  36. data/lib/active_merchant/billing/gateways/litle.rb +1 -5
  37. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +153 -155
  38. data/lib/active_merchant/billing/gateways/merchant_ware.rb +49 -50
  39. data/lib/active_merchant/billing/gateways/mercury.rb +272 -0
  40. data/lib/active_merchant/billing/gateways/metrics_global.rb +9 -10
  41. data/lib/active_merchant/billing/gateways/migs.rb +5 -3
  42. data/lib/active_merchant/billing/gateways/modern_payments.rb +6 -7
  43. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +40 -41
  44. data/lib/active_merchant/billing/gateways/moneris.rb +46 -50
  45. data/lib/active_merchant/billing/gateways/moneris_us.rb +52 -55
  46. data/lib/active_merchant/billing/gateways/nab_transact.rb +0 -5
  47. data/lib/active_merchant/billing/gateways/net_registry.rb +20 -21
  48. data/lib/active_merchant/billing/gateways/netaxept.rb +30 -36
  49. data/lib/active_merchant/billing/gateways/netbilling.rb +2 -2
  50. data/lib/active_merchant/billing/gateways/ogone.rb +0 -5
  51. data/lib/active_merchant/billing/gateways/optimal_payment.rb +1 -6
  52. data/lib/active_merchant/billing/gateways/orbital.rb +25 -21
  53. data/lib/active_merchant/billing/gateways/orbital/avs_result.rb +93 -0
  54. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +1 -6
  55. data/lib/active_merchant/billing/gateways/pay_junction.rb +62 -63
  56. data/lib/active_merchant/billing/gateways/pay_secure.rb +29 -30
  57. data/lib/active_merchant/billing/gateways/paybox_direct.rb +0 -5
  58. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +33 -38
  59. data/lib/active_merchant/billing/gateways/payment_express.rb +48 -51
  60. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +7 -11
  61. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +7 -0
  62. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +3 -0
  63. data/lib/active_merchant/billing/gateways/paystation.rb +62 -64
  64. data/lib/active_merchant/billing/gateways/payway.rb +2 -9
  65. data/lib/active_merchant/billing/gateways/plugnpay.rb +0 -1
  66. data/lib/active_merchant/billing/gateways/psigate.rb +102 -94
  67. data/lib/active_merchant/billing/gateways/psl_card.rb +66 -67
  68. data/lib/active_merchant/billing/gateways/qbms.rb +0 -6
  69. data/lib/active_merchant/billing/gateways/quantum.rb +2 -8
  70. data/lib/active_merchant/billing/gateways/quickpay.rb +2 -3
  71. data/lib/active_merchant/billing/gateways/realex.rb +6 -16
  72. data/lib/active_merchant/billing/gateways/redsys.rb +394 -0
  73. data/lib/active_merchant/billing/gateways/sage.rb +15 -16
  74. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +25 -26
  75. data/lib/active_merchant/billing/gateways/sage_pay.rb +51 -56
  76. data/lib/active_merchant/billing/gateways/sallie_mae.rb +1 -2
  77. data/lib/active_merchant/billing/gateways/samurai.rb +1 -4
  78. data/lib/active_merchant/billing/gateways/secure_net.rb +0 -1
  79. data/lib/active_merchant/billing/gateways/secure_pay.rb +5 -8
  80. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +0 -5
  81. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +17 -18
  82. data/lib/active_merchant/billing/gateways/skip_jack.rb +29 -34
  83. data/lib/active_merchant/billing/gateways/smart_ps.rb +55 -56
  84. data/lib/active_merchant/billing/gateways/stripe.rb +8 -3
  85. data/lib/active_merchant/billing/gateways/trans_first.rb +28 -29
  86. data/lib/active_merchant/billing/gateways/trust_commerce.rb +85 -87
  87. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +27 -28
  88. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +0 -5
  89. data/lib/active_merchant/billing/gateways/verifi.rb +86 -87
  90. data/lib/active_merchant/billing/gateways/viaklix.rb +42 -47
  91. data/lib/active_merchant/billing/gateways/vindicia.rb +30 -28
  92. data/lib/active_merchant/billing/gateways/webpay.rb +45 -0
  93. data/lib/active_merchant/billing/gateways/wirecard.rb +0 -6
  94. data/lib/active_merchant/billing/gateways/worldpay.rb +4 -9
  95. data/lib/active_merchant/billing/integrations/a1agregator.rb +26 -0
  96. data/lib/active_merchant/billing/integrations/a1agregator/helper.rb +31 -0
  97. data/lib/active_merchant/billing/integrations/a1agregator/notification.rb +186 -0
  98. data/lib/active_merchant/billing/integrations/a1agregator/status.rb +38 -0
  99. data/lib/active_merchant/billing/integrations/liqpay.rb +30 -0
  100. data/lib/active_merchant/billing/integrations/liqpay/helper.rb +43 -0
  101. data/lib/active_merchant/billing/integrations/liqpay/notification.rb +89 -0
  102. data/lib/active_merchant/billing/integrations/liqpay/return.rb +83 -0
  103. data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +17 -1
  104. data/lib/active_merchant/billing/integrations/notification.rb +4 -0
  105. data/lib/active_merchant/billing/integrations/pay_fast.rb +70 -0
  106. data/lib/active_merchant/billing/integrations/pay_fast/common.rb +42 -0
  107. data/lib/active_merchant/billing/integrations/pay_fast/helper.rb +50 -0
  108. data/lib/active_merchant/billing/integrations/pay_fast/notification.rb +134 -0
  109. data/lib/active_merchant/billing/integrations/pay_fast/return.rb +10 -0
  110. data/lib/active_merchant/billing/integrations/paypal/notification.rb +64 -0
  111. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +10 -7
  112. data/lib/active_merchant/billing/integrations/webmoney/notification.rb +12 -0
  113. data/lib/active_merchant/billing/response.rb +19 -4
  114. data/lib/active_merchant/version.rb +1 -1
  115. metadata +45 -27
  116. metadata.gz.sig +0 -0
@@ -51,7 +51,7 @@ module ActiveMerchant #:nodoc:
51
51
  #
52
52
  # ==== Parameters
53
53
  # * <tt>options</tt> - A Hash of options
54
- #
54
+ #
55
55
  # ==== Options Hash
56
56
  # * <tt>:login</tt> - A String containing your PaymentClearing assigned API Access Username
57
57
  # * <tt>:password</tt> - A String containing your PaymentClearing assigned API Access Key
@@ -60,7 +60,6 @@ module ActiveMerchant #:nodoc:
60
60
  #
61
61
  def initialize(options = {})
62
62
  requires!(options, :login, :password, :gateway_id)
63
- @options = options
64
63
  super
65
64
  end
66
65
 
@@ -196,7 +195,6 @@ module ActiveMerchant #:nodoc:
196
195
  # This will reverse a previously run transaction which *has* *not* settled.
197
196
  #
198
197
  # ==== Parameters
199
- # * <tt>money</tt> - This parameter is ignored -- the PaymentClearing gateway does not allow partial voids.
200
198
  # * <tt>authorization</tt> - The authorization returned from the previous capture or purchase request
201
199
  # * <tt>options</tt> - A Hash of options, all are optional
202
200
  #
@@ -209,7 +207,7 @@ module ActiveMerchant #:nodoc:
209
207
  # * <tt>:test_mode</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'TestMode' element set to 'TRUE' or 'FALSE'.
210
208
  #
211
209
  # ==== Examples
212
- # response = gateway.void(nil, '9999999999',
210
+ # response = gateway.void('9999999999',
213
211
  # :vendor_data => [{'repId' => '1234567'}, {'customerId' => '9886'}],
214
212
  # :send_customer_email => true,
215
213
  # :send_merchant_email => true,
@@ -217,7 +215,7 @@ module ActiveMerchant #:nodoc:
217
215
  # :test_mode => true
218
216
  # )
219
217
  #
220
- def void(money, authorization, options = {})
218
+ def void(authorization, options = {})
221
219
  payload = Nokogiri::XML::Builder.new do |xml|
222
220
  xml.VoidTransaction {
223
221
  xml.OperationXID(authorization)
@@ -232,7 +230,7 @@ module ActiveMerchant #:nodoc:
232
230
  # This will reverse a previously run transaction which *has* settled.
233
231
  #
234
232
  # ==== Parameters
235
- # * <tt>money</tt> - The amount to be credited. Should be <tt>nil</tt> or an Integer amount in cents
233
+ # * <tt>money</tt> - The amount to be credited. Should be an Integer amount in cents
236
234
  # * <tt>authorization</tt> - The authorization returned from the previous capture or purchase request
237
235
  # * <tt>options</tt> - A Hash of options, all are optional
238
236
  #
@@ -245,7 +243,7 @@ module ActiveMerchant #:nodoc:
245
243
  # * <tt>:test_mode</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'TestMode' element set to 'TRUE' or 'FALSE'.
246
244
  #
247
245
  # ==== Examples
248
- # response = gateway.credit(nil, '9999999999',
246
+ # response = gateway.refund(555, '9999999999',
249
247
  # :vendor_data => [{'repId' => '1234567'}, {'customerId' => '9886'}],
250
248
  # :send_customer_email => true,
251
249
  # :send_merchant_email => true,
@@ -253,9 +251,9 @@ module ActiveMerchant #:nodoc:
253
251
  # :test_mode => true
254
252
  # )
255
253
  #
256
- def credit(money, authorization, options = {})
254
+ def refund(money, authorization, options = {})
257
255
  payload = Nokogiri::XML::Builder.new do |xml|
258
- xml.TranCreditTransaction {
256
+ xml.TranCredTransaction {
259
257
  xml.OperationXID(authorization)
260
258
  add_invoice(xml, money, options)
261
259
  add_transaction_control(xml, options)
@@ -3,22 +3,22 @@ module ActiveMerchant #:nodoc:
3
3
  class JetpayGateway < Gateway
4
4
  self.test_url = 'https://test1.jetpay.com/jetpay'
5
5
  self.live_url = 'https://gateway17.jetpay.com/jetpay'
6
-
6
+
7
7
  # The countries the gateway supports merchants from as 2 digit ISO country codes
8
8
  self.supported_countries = ['US']
9
-
9
+
10
10
  # The card types supported by the payment gateway
11
11
  self.supported_cardtypes = [:visa, :master, :american_express, :discover]
12
-
12
+
13
13
  # The homepage URL of the gateway
14
14
  self.homepage_url = 'http://www.jetpay.com/'
15
-
15
+
16
16
  # The name of the gateway
17
17
  self.display_name = 'JetPay'
18
-
18
+
19
19
  # all transactions are in cents
20
20
  self.money_format = :cents
21
-
21
+
22
22
  ACTION_CODE_MESSAGES = {
23
23
  "001" => "Refer to card issuer.",
24
24
  "002" => "Refer to card issuer, special condition.",
@@ -61,25 +61,24 @@ module ActiveMerchant #:nodoc:
61
61
  "996" => "Terminal ID Not Found.",
62
62
  nil => "No response returned (missing credentials?)."
63
63
  }
64
-
64
+
65
65
  def initialize(options = {})
66
66
  requires!(options, :login)
67
- @options = options
68
67
  super
69
- end
70
-
68
+ end
69
+
71
70
  def purchase(money, credit_card, options = {})
72
71
  commit(money, build_sale_request(money, credit_card, options))
73
72
  end
74
-
73
+
75
74
  def authorize(money, credit_card, options = {})
76
75
  commit(money, build_authonly_request(money, credit_card, options))
77
76
  end
78
-
77
+
79
78
  def capture(money, reference, options = {})
80
79
  commit(money, build_capture_request('CAPT', reference.split(";").first))
81
80
  end
82
-
81
+
83
82
  def void(reference, options = {})
84
83
  transaction_id, approval, amount = reference.split(";")
85
84
  commit(amount.to_i, build_void_request(amount.to_i, transaction_id, approval))
@@ -100,9 +99,9 @@ module ActiveMerchant #:nodoc:
100
99
  commit(money, build_credit_request('CREDIT', money, transaction_id, credit_card))
101
100
  end
102
101
 
103
-
102
+
104
103
  private
105
-
104
+
106
105
  def build_xml_request(transaction_type, transaction_id = nil, &block)
107
106
  xml = Builder::XmlMarkup.new
108
107
  xml.tag! 'JetPay' do
@@ -110,15 +109,15 @@ module ActiveMerchant #:nodoc:
110
109
  xml.tag! 'TerminalID', @options[:login]
111
110
  xml.tag! 'TransactionType', transaction_type
112
111
  xml.tag! 'TransactionID', transaction_id.nil? ? generate_unique_id.slice(0, 18) : transaction_id
113
-
112
+
114
113
  if block_given?
115
114
  yield xml
116
- else
115
+ else
117
116
  xml.target!
118
117
  end
119
118
  end
120
119
  end
121
-
120
+
122
121
  def build_sale_request(money, credit_card, options)
123
122
  build_xml_request('SALE') do |xml|
124
123
  add_credit_card(xml, credit_card)
@@ -126,11 +125,11 @@ module ActiveMerchant #:nodoc:
126
125
  add_customer_data(xml, options)
127
126
  add_invoice_data(xml, options)
128
127
  xml.tag! 'TotalAmount', amount(money)
129
-
128
+
130
129
  xml.target!
131
130
  end
132
131
  end
133
-
132
+
134
133
  def build_authonly_request(money, credit_card, options)
135
134
  build_xml_request('AUTHONLY') do |xml|
136
135
  add_credit_card(xml, credit_card)
@@ -138,22 +137,22 @@ module ActiveMerchant #:nodoc:
138
137
  add_customer_data(xml, options)
139
138
  add_invoice_data(xml, options)
140
139
  xml.tag! 'TotalAmount', amount(money)
141
-
140
+
142
141
  xml.target!
143
142
  end
144
143
  end
145
-
144
+
146
145
  def build_capture_request(transaction_type, transaction_id)
147
146
  build_xml_request(transaction_type, transaction_id)
148
147
  end
149
-
148
+
150
149
  def build_void_request(money, transaction_id, approval)
151
150
  build_xml_request('VOID', transaction_id) do |xml|
152
151
  xml.tag! 'Approval', approval
153
152
  xml.tag! 'TotalAmount', amount(money)
154
-
153
+
155
154
  xml.target!
156
- end
155
+ end
157
156
  end
158
157
 
159
158
  # `transaction_id` may be nil for unlinked credit transactions.
@@ -161,37 +160,37 @@ module ActiveMerchant #:nodoc:
161
160
  build_xml_request(transaction_type, transaction_id) do |xml|
162
161
  add_credit_card(xml, card) if card
163
162
  xml.tag! 'TotalAmount', amount(money)
164
-
163
+
165
164
  xml.target!
166
165
  end
167
166
  end
168
-
167
+
169
168
  def commit(money, request)
170
169
  response = parse(ssl_post(test? ? self.test_url : self.live_url, request))
171
-
170
+
172
171
  success = success?(response)
173
- Response.new(success,
174
- success ? 'APPROVED' : message_from(response),
175
- response,
176
- :test => test?,
172
+ Response.new(success,
173
+ success ? 'APPROVED' : message_from(response),
174
+ response,
175
+ :test => test?,
177
176
  :authorization => authorization_from(response, money),
178
177
  :avs_result => { :code => response[:avs] },
179
178
  :cvv_result => response[:cvv2]
180
179
  )
181
180
  end
182
-
181
+
183
182
  def parse(body)
184
183
  return {} if body.blank?
185
184
 
186
185
  xml = REXML::Document.new(body)
187
-
186
+
188
187
  response = {}
189
188
  xml.root.elements.to_a.each do |node|
190
189
  parse_element(response, node)
191
190
  end
192
191
  response
193
192
  end
194
-
193
+
195
194
  def parse_element(response, node)
196
195
  if node.has_elements?
197
196
  node.elements.each{|element| parse_element(response, element) }
@@ -199,24 +198,24 @@ module ActiveMerchant #:nodoc:
199
198
  response[node.name.underscore.to_sym] = node.text
200
199
  end
201
200
  end
202
-
201
+
203
202
  def format_exp(value)
204
203
  format(value, :two_digits)
205
204
  end
206
-
205
+
207
206
  def success?(response)
208
207
  response[:action_code] == "000"
209
208
  end
210
-
209
+
211
210
  def message_from(response)
212
211
  ACTION_CODE_MESSAGES[response[:action_code]]
213
212
  end
214
-
213
+
215
214
  def authorization_from(response, money)
216
215
  original_amount = amount(money) if money
217
216
  [ response[:transaction_id], response[:approval], original_amount ].join(";")
218
217
  end
219
-
218
+
220
219
  def add_credit_card(xml, credit_card)
221
220
  xml.tag! 'CardNum', credit_card.number
222
221
  xml.tag! 'CardExpMonth', format_exp(credit_card.month)
@@ -230,7 +229,7 @@ module ActiveMerchant #:nodoc:
230
229
  xml.tag! 'CVV2', credit_card.verification_value
231
230
  end
232
231
  end
233
-
232
+
234
233
  def add_addresses(xml, options)
235
234
  if billing_address = options[:billing_address] || options[:address]
236
235
  xml.tag! 'BillingAddress', [billing_address[:address1], billing_address[:address2]].compact.join(" ")
@@ -240,11 +239,11 @@ module ActiveMerchant #:nodoc:
240
239
  xml.tag! 'BillingCountry', lookup_country_code(billing_address[:country])
241
240
  xml.tag! 'BillingPhone', billing_address[:phone]
242
241
  end
243
-
242
+
244
243
  if shipping_address = options[:shipping_address]
245
244
  xml.tag! 'ShippingInfo' do
246
245
  xml.tag! 'ShippingName', shipping_address[:name]
247
-
246
+
248
247
  xml.tag! 'ShippingAddr' do
249
248
  xml.tag! 'Address', [shipping_address[:address1], shipping_address[:address2]].compact.join(" ")
250
249
  xml.tag! 'City', shipping_address[:city]
@@ -260,14 +259,14 @@ module ActiveMerchant #:nodoc:
260
259
  xml.tag! 'Email', options[:email] if options[:email]
261
260
  xml.tag! 'UserIPAddress', options[:ip] if options[:ip]
262
261
  end
263
-
262
+
264
263
  def add_invoice_data(xml, options)
265
264
  xml.tag! 'OrderNumber', options[:order_id] if options[:order_id]
266
265
  xml.tag! 'TaxAmount', amount(options[:tax]) if options[:tax]
267
266
  end
268
-
267
+
269
268
  def lookup_country_code(code)
270
- country = Country.find(code) rescue nil
269
+ country = Country.find(code) rescue nil
271
270
  country && country.code(:alpha3)
272
271
  end
273
272
  end
@@ -2,36 +2,36 @@ require 'rexml/document'
2
2
 
3
3
  module ActiveMerchant #:nodoc:
4
4
  module Billing #:nodoc:
5
-
5
+
6
6
  # Initialization Options
7
7
  # :login Your store number
8
8
  # :pem The text of your linkpoint PEM file. Note
9
9
  # this is not the path to file, but its
10
10
  # contents. If you are only using one PEM
11
- # file on your site you can declare it
11
+ # file on your site you can declare it
12
12
  # globally and then you won't need to
13
13
  # include this option
14
14
  #
15
15
  #
16
- # A valid store number is required. Unfortunately, with LinkPoint
17
- # YOU CAN'T JUST USE ANY OLD STORE NUMBER. Also, you can't just
18
- # generate your own PEM file. You'll need to use a special PEM file
19
- # provided by LinkPoint.
16
+ # A valid store number is required. Unfortunately, with LinkPoint
17
+ # YOU CAN'T JUST USE ANY OLD STORE NUMBER. Also, you can't just
18
+ # generate your own PEM file. You'll need to use a special PEM file
19
+ # provided by LinkPoint.
20
20
  #
21
- # Go to http://www.linkpoint.com/support/sup_teststore.asp to set up
21
+ # Go to http://www.linkpoint.com/support/sup_teststore.asp to set up
22
22
  # a test account and obtain your PEM file.
23
23
  #
24
24
  # Declaring PEM file Globally
25
25
  # ActiveMerchant::Billing::LinkpointGateway.pem_file = File.read( File.dirname(__FILE__) + '/../mycert.pem' )
26
- #
27
- #
26
+ #
27
+ #
28
28
  # Valid Order Options
29
- # :result =>
29
+ # :result =>
30
30
  # LIVE Production mode
31
31
  # GOOD Approved response in test mode
32
32
  # DECLINE Declined response in test mode
33
33
  # DUPLICATE Duplicate response in test mode
34
- #
34
+ #
35
35
  # :ponumber Order number
36
36
  #
37
37
  # :transactionorigin => Source of the transaction
@@ -41,35 +41,35 @@ module ActiveMerchant #:nodoc:
41
41
  # TELEPHONE Telephone
42
42
  # RETAIL Face-to-face
43
43
  #
44
- # :ordertype =>
44
+ # :ordertype =>
45
45
  # SALE Real live sale
46
46
  # PREAUTH Authorize only
47
47
  # POSTAUTH Forced Ticket or Ticket Only transaction
48
- # VOID
49
- # CREDIT
48
+ # VOID
49
+ # CREDIT
50
50
  # CALCSHIPPING For shipping charges calculations
51
51
  # CALCTAX For sales tax calculations
52
- #
53
- # Recurring Options
54
- # :action =>
55
- # SUBMIT
56
- # MODIFY
57
- # CANCEL
58
- #
52
+ #
53
+ # Recurring Options
54
+ # :action =>
55
+ # SUBMIT
56
+ # MODIFY
57
+ # CANCEL
58
+ #
59
59
  # :installments Identifies how many recurring payments to charge the customer
60
60
  # :startdate Date to begin charging the recurring payments. Format: YYYYMMDD or "immediate"
61
- # :periodicity =>
62
- # MONTHLY
63
- # BIMONTHLY
64
- # WEEKLY
65
- # BIWEEKLY
66
- # YEARLY
67
- # DAILY
61
+ # :periodicity =>
62
+ # MONTHLY
63
+ # BIMONTHLY
64
+ # WEEKLY
65
+ # BIWEEKLY
66
+ # YEARLY
67
+ # DAILY
68
68
  # :threshold Tells how many times to retry the transaction (if it fails) before contacting the merchant.
69
69
  # :comments Uh... comments
70
70
  #
71
71
  #
72
- # For reference:
72
+ # For reference:
73
73
  #
74
74
  # https://www.linkpointcentral.com/lpc/docs/Help/APIHelp/lpintguide.htm
75
75
  #
@@ -85,7 +85,7 @@ module ActiveMerchant #:nodoc:
85
85
  # :items => [:item => [:price, :quantity, :description, :id, :options => [:option => [:name, :value]]]]
86
86
  # }
87
87
  #
88
- #
88
+ #
89
89
  # LinkPoint's Items entity is an optional entity that can be attached to orders.
90
90
  # It is entered as :line_items to be consistent with the CyberSource implementation
91
91
  #
@@ -117,57 +117,57 @@ module ActiveMerchant #:nodoc:
117
117
  # ]
118
118
  # This functionality is only supported by this particular gateway may
119
119
  # be changed at any time
120
- #
121
- class LinkpointGateway < Gateway
120
+ #
121
+ class LinkpointGateway < Gateway
122
122
  # Your global PEM file. This will be assigned to you by linkpoint
123
- #
124
- # Example:
125
- #
123
+ #
124
+ # Example:
125
+ #
126
126
  # ActiveMerchant::Billing::LinkpointGateway.pem_file = File.read( File.dirname(__FILE__) + '/../mycert.pem' )
127
- #
127
+ #
128
128
  cattr_accessor :pem_file
129
-
129
+
130
130
  self.test_url = 'https://staging.linkpt.net:1129/'
131
131
  self.live_url = 'https://secure.linkpt.net:1129/'
132
-
132
+
133
133
  self.supported_countries = ['US']
134
134
  self.supported_cardtypes = [:visa, :master, :american_express, :discover, :jcb, :diners_club]
135
135
  self.homepage_url = 'http://www.linkpoint.com/'
136
136
  self.display_name = 'LinkPoint'
137
-
137
+
138
138
  def initialize(options = {})
139
139
  requires!(options, :login)
140
-
140
+
141
141
  @options = {
142
142
  :result => 'LIVE',
143
143
  :pem => LinkpointGateway.pem_file
144
144
  }.update(options)
145
-
145
+
146
146
  raise ArgumentError, "You need to pass in your pem file using the :pem parameter or set it globally using ActiveMerchant::Billing::LinkpointGateway.pem_file = File.read( File.dirname(__FILE__) + '/../mycert.pem' ) or similar" if @options[:pem].blank?
147
147
  end
148
-
148
+
149
149
  # Send a purchase request with periodic options
150
- # Recurring Options
151
- # :action =>
152
- # SUBMIT
153
- # MODIFY
154
- # CANCEL
155
- #
150
+ # Recurring Options
151
+ # :action =>
152
+ # SUBMIT
153
+ # MODIFY
154
+ # CANCEL
155
+ #
156
156
  # :installments Identifies how many recurring payments to charge the customer
157
157
  # :startdate Date to begin charging the recurring payments. Format: YYYYMMDD or "immediate"
158
- # :periodicity =>
159
- # :monthly
160
- # :bimonthly
161
- # :weekly
162
- # :biweekly
163
- # :yearly
164
- # :daily
158
+ # :periodicity =>
159
+ # :monthly
160
+ # :bimonthly
161
+ # :weekly
162
+ # :biweekly
163
+ # :yearly
164
+ # :daily
165
165
  # :threshold Tells how many times to retry the transaction (if it fails) before contacting the merchant.
166
166
  # :comments Uh... comments
167
167
  #
168
168
  def recurring(money, creditcard, options={})
169
169
  requires!(options, [:periodicity, :bimonthly, :monthly, :biweekly, :weekly, :yearly, :daily], :installments, :order_id )
170
-
170
+
171
171
  options.update(
172
172
  :ordertype => "SALE",
173
173
  :action => options[:action] || "SUBMIT",
@@ -179,7 +179,7 @@ module ActiveMerchant #:nodoc:
179
179
  )
180
180
  commit(money, creditcard, options)
181
181
  end
182
-
182
+
183
183
  # Buy the thing
184
184
  def purchase(money, creditcard, options={})
185
185
  requires!(options, :order_id)
@@ -188,10 +188,10 @@ module ActiveMerchant #:nodoc:
188
188
  )
189
189
  commit(money, creditcard, options)
190
190
  end
191
-
191
+
192
192
  #
193
193
  # Authorize the transaction
194
- #
194
+ #
195
195
  # Reserves the funds on the customer's credit card, but does not charge the card.
196
196
  #
197
197
  def authorize(money, creditcard, options = {})
@@ -201,21 +201,21 @@ module ActiveMerchant #:nodoc:
201
201
  )
202
202
  commit(money, creditcard, options)
203
203
  end
204
-
204
+
205
205
  #
206
- # Post an authorization.
206
+ # Post an authorization.
207
207
  #
208
- # Captures the funds from an authorized transaction.
208
+ # Captures the funds from an authorized transaction.
209
209
  # Order_id must be a valid order id from a prior authorized transaction.
210
- #
210
+ #
211
211
  def capture(money, authorization, options = {})
212
212
  options.update(
213
213
  :order_id => authorization,
214
214
  :ordertype => "POSTAUTH"
215
215
  )
216
- commit(money, nil, options)
216
+ commit(money, nil, options)
217
217
  end
218
-
218
+
219
219
  # Void a previous transaction
220
220
  def void(identification, options = {})
221
221
  options.update(
@@ -224,10 +224,10 @@ module ActiveMerchant #:nodoc:
224
224
  )
225
225
  commit(nil, nil, options)
226
226
  end
227
-
228
- #
227
+
228
+ #
229
229
  # Refund an order
230
- #
230
+ #
231
231
  # identification must be a valid order id previously submitted by SALE
232
232
  #
233
233
  def refund(money, identification, options = {})
@@ -242,39 +242,35 @@ module ActiveMerchant #:nodoc:
242
242
  deprecated CREDIT_DEPRECATION_MESSAGE
243
243
  refund(money, identification, options)
244
244
  end
245
-
246
- def test?
247
- @options[:test] || super
248
- end
249
-
245
+
250
246
  private
251
247
  # Commit the transaction by posting the XML file to the LinkPoint server
252
248
  def commit(money, creditcard, options = {})
253
249
  response = parse(ssl_post(test? ? self.test_url : self.live_url, post_data(money, creditcard, options)))
254
-
255
- Response.new(successful?(response), response[:message], response,
250
+
251
+ Response.new(successful?(response), response[:message], response,
256
252
  :test => test?,
257
253
  :authorization => response[:ordernum],
258
254
  :avs_result => { :code => response[:avs].to_s[2,1] },
259
255
  :cvv_result => response[:avs].to_s[3,1]
260
256
  )
261
257
  end
262
-
258
+
263
259
  def successful?(response)
264
260
  response[:approved] == "APPROVED"
265
261
  end
266
-
262
+
267
263
  # Build the XML file
268
264
  def post_data(money, creditcard, options)
269
265
  params = parameters(money, creditcard, options)
270
-
266
+
271
267
  xml = REXML::Document.new
272
268
  order = xml.add_element("order")
273
-
269
+
274
270
  # Merchant Info
275
271
  merchantinfo = order.add_element("merchantinfo")
276
272
  merchantinfo.add_element("configfile").text = @options[:login]
277
-
273
+
278
274
  # Loop over the params hash to construct the XML string
279
275
  for key, value in params
280
276
  elem = order.add_element(key.to_s)
@@ -285,7 +281,7 @@ module ActiveMerchant #:nodoc:
285
281
  elem.add_element(k.to_s).text = params[key][k].to_s if params[key][k]
286
282
  end
287
283
  end
288
- # Linkpoint doesn't understand empty elements:
284
+ # Linkpoint doesn't understand empty elements:
289
285
  order.delete(elem) if elem.size == 0
290
286
  end
291
287
  return xml.to_s
@@ -311,9 +307,9 @@ module ActiveMerchant #:nodoc:
311
307
  end
312
308
 
313
309
  # Set up the parameters hash just once so we don't have to do it
314
- # for every action.
310
+ # for every action.
315
311
  def parameters(money, creditcard, options = {})
316
-
312
+
317
313
  params = {
318
314
  :payment => {
319
315
  :subtotal => amount(options[:subtotal]),
@@ -330,7 +326,7 @@ module ActiveMerchant #:nodoc:
330
326
  :terminaltype => options[:terminaltype],
331
327
  :ip => options[:ip],
332
328
  :reference_number => options[:reference_number],
333
- :recurring => options[:recurring] || "NO", #DO NOT USE if you are using the periodic billing option.
329
+ :recurring => options[:recurring] || "NO", #DO NOT USE if you are using the periodic billing option.
334
330
  :tdate => options[:tdate]
335
331
  },
336
332
  :orderoptions => {
@@ -339,10 +335,10 @@ module ActiveMerchant #:nodoc:
339
335
  },
340
336
  :periodic => {
341
337
  :action => options[:action],
342
- :installments => options[:installments],
343
- :threshold => options[:threshold],
344
- :startdate => options[:startdate],
345
- :periodicity => options[:periodicity],
338
+ :installments => options[:installments],
339
+ :threshold => options[:threshold],
340
+ :startdate => options[:startdate],
341
+ :periodicity => options[:periodicity],
346
342
  :comments => options[:comments]
347
343
  },
348
344
  :telecheck => {
@@ -357,7 +353,7 @@ module ActiveMerchant #:nodoc:
357
353
  :ssn => options[:telecheck_ssn],
358
354
  }
359
355
  }
360
-
356
+
361
357
  if creditcard
362
358
  params[:creditcard] = {
363
359
  :cardnumber => creditcard.number,
@@ -365,18 +361,18 @@ module ActiveMerchant #:nodoc:
365
361
  :cardexpyear => format_creditcard_expiry_year(creditcard.year),
366
362
  :track => nil
367
363
  }
368
-
364
+
369
365
  if creditcard.verification_value?
370
366
  params[:creditcard][:cvmvalue] = creditcard.verification_value
371
367
  params[:creditcard][:cvmindicator] = 'provided'
372
368
  else
373
369
  params[:creditcard][:cvmindicator] = 'not_provided'
374
- end
370
+ end
375
371
  end
376
-
377
- if billing_address = options[:billing_address] || options[:address]
378
-
379
- params[:billing] = {}
372
+
373
+ if billing_address = options[:billing_address] || options[:address]
374
+
375
+ params[:billing] = {}
380
376
  params[:billing][:name] = billing_address[:name] || (creditcard ? creditcard.name : nil)
381
377
  params[:billing][:address1] = billing_address[:address1] unless billing_address[:address1].blank?
382
378
  params[:billing][:address2] = billing_address[:address2] unless billing_address[:address2].blank?
@@ -387,27 +383,27 @@ module ActiveMerchant #:nodoc:
387
383
  params[:billing][:company] = billing_address[:company] unless billing_address[:company].blank?
388
384
  params[:billing][:phone] = billing_address[:phone] unless billing_address[:phone].blank?
389
385
  params[:billing][:email] = options[:email] unless options[:email].blank?
390
- end
386
+ end
391
387
 
392
- if shipping_address = options[:shipping_address]
388
+ if shipping_address = options[:shipping_address]
393
389
 
394
390
  params[:shipping] = {}
395
- params[:shipping][:name] = shipping_address[:name] || creditcard ? creditcard.name : nil
391
+ params[:shipping][:name] = shipping_address[:name] || (creditcard ? creditcard.name : nil)
396
392
  params[:shipping][:address1] = shipping_address[:address1] unless shipping_address[:address1].blank?
397
393
  params[:shipping][:address2] = shipping_address[:address2] unless shipping_address[:address2].blank?
398
394
  params[:shipping][:city] = shipping_address[:city] unless shipping_address[:city].blank?
399
395
  params[:shipping][:state] = shipping_address[:state] unless shipping_address[:state].blank?
400
396
  params[:shipping][:zip] = shipping_address[:zip] unless shipping_address[:zip].blank?
401
397
  params[:shipping][:country] = shipping_address[:country] unless shipping_address[:country].blank?
402
- end
398
+ end
403
399
 
404
400
  params[:items] = options[:line_items] if options[:line_items]
405
-
401
+
406
402
  return params
407
403
  end
408
-
404
+
409
405
  def parse(xml)
410
-
406
+
411
407
  # For reference, a typical response...
412
408
  # <r_csp></r_csp>
413
409
  # <r_time></r_time>
@@ -421,17 +417,17 @@ module ActiveMerchant #:nodoc:
421
417
  # <r_authresponse></r_authresponse>
422
418
  # <r_approved>APPROVED</r_approved>
423
419
  # <r_avs></r_avs>
424
-
420
+
425
421
  response = {:message => "Global Error Receipt", :complete => false}
426
-
422
+
427
423
  xml = REXML::Document.new("<response>#{xml}</response>")
428
424
  xml.root.elements.each do |node|
429
425
  response[node.name.downcase.sub(/^r_/, '').to_sym] = normalize(node.text)
430
426
  end unless xml.root.nil?
431
-
427
+
432
428
  response
433
429
  end
434
-
430
+
435
431
  # Make a ruby type out of the response string
436
432
  def normalize(field)
437
433
  case field
@@ -440,12 +436,12 @@ module ActiveMerchant #:nodoc:
440
436
  when "" then nil
441
437
  when "null" then nil
442
438
  else field
443
- end
439
+ end
444
440
  end
445
441
 
446
442
  def format_creditcard_expiry_year(year)
447
443
  sprintf("%.4i", year)[-2..-1]
448
- end
444
+ end
449
445
  end
450
446
  end
451
447
  end