activemerchant 1.28.0 → 1.29.1

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 (117) hide show
  1. data/CHANGELOG +41 -0
  2. data/CONTRIBUTORS +12 -0
  3. data/README.md +6 -0
  4. data/lib/active_merchant/billing/gateway.rb +2 -1
  5. data/lib/active_merchant/billing/gateways/authorize_net.rb +3 -2
  6. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +77 -78
  7. data/lib/active_merchant/billing/gateways/balanced.rb +0 -1
  8. data/lib/active_merchant/billing/gateways/banwire.rb +1 -2
  9. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +19 -20
  10. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +35 -36
  11. data/lib/active_merchant/billing/gateways/blue_pay.rb +135 -140
  12. data/lib/active_merchant/billing/gateways/braintree_blue.rb +12 -4
  13. data/lib/active_merchant/billing/gateways/card_stream.rb +54 -59
  14. data/lib/active_merchant/billing/gateways/certo_direct.rb +0 -1
  15. data/lib/active_merchant/billing/gateways/cyber_source.rb +19 -14
  16. data/lib/active_merchant/billing/gateways/data_cash.rb +106 -112
  17. data/lib/active_merchant/billing/gateways/efsnet.rb +29 -34
  18. data/lib/active_merchant/billing/gateways/elavon.rb +7 -1
  19. data/lib/active_merchant/billing/gateways/epay.rb +0 -1
  20. data/lib/active_merchant/billing/gateways/eway.rb +88 -93
  21. data/lib/active_merchant/billing/gateways/eway_managed.rb +47 -51
  22. data/lib/active_merchant/billing/gateways/eway_rapid.rb +300 -0
  23. data/lib/active_merchant/billing/gateways/exact.rb +45 -54
  24. data/lib/active_merchant/billing/gateways/federated_canada.rb +3 -4
  25. data/lib/active_merchant/billing/gateways/first_pay.rb +37 -38
  26. data/lib/active_merchant/billing/gateways/garanti.rb +1 -2
  27. data/lib/active_merchant/billing/gateways/hdfc.rb +207 -0
  28. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +5 -8
  29. data/lib/active_merchant/billing/gateways/inspire.rb +52 -52
  30. data/lib/active_merchant/billing/gateways/instapay.rb +10 -11
  31. data/lib/active_merchant/billing/gateways/iridium.rb +38 -39
  32. data/lib/active_merchant/billing/gateways/itransact.rb +7 -9
  33. data/lib/active_merchant/billing/gateways/jetpay.rb +45 -46
  34. data/lib/active_merchant/billing/gateways/linkpoint.rb +104 -108
  35. data/lib/active_merchant/billing/gateways/litle.rb +1 -5
  36. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +153 -155
  37. data/lib/active_merchant/billing/gateways/merchant_ware.rb +49 -50
  38. data/lib/active_merchant/billing/gateways/mercury.rb +272 -0
  39. data/lib/active_merchant/billing/gateways/metrics_global.rb +9 -10
  40. data/lib/active_merchant/billing/gateways/migs.rb +5 -3
  41. data/lib/active_merchant/billing/gateways/modern_payments.rb +6 -7
  42. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +40 -41
  43. data/lib/active_merchant/billing/gateways/moneris.rb +46 -50
  44. data/lib/active_merchant/billing/gateways/moneris_us.rb +52 -55
  45. data/lib/active_merchant/billing/gateways/nab_transact.rb +0 -5
  46. data/lib/active_merchant/billing/gateways/net_registry.rb +20 -21
  47. data/lib/active_merchant/billing/gateways/netaxept.rb +30 -36
  48. data/lib/active_merchant/billing/gateways/netbilling.rb +2 -2
  49. data/lib/active_merchant/billing/gateways/ogone.rb +0 -5
  50. data/lib/active_merchant/billing/gateways/optimal_payment.rb +1 -6
  51. data/lib/active_merchant/billing/gateways/orbital/avs_result.rb +93 -0
  52. data/lib/active_merchant/billing/gateways/orbital.rb +25 -21
  53. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +1 -6
  54. data/lib/active_merchant/billing/gateways/pay_junction.rb +62 -63
  55. data/lib/active_merchant/billing/gateways/pay_secure.rb +29 -30
  56. data/lib/active_merchant/billing/gateways/paybox_direct.rb +0 -5
  57. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +33 -38
  58. data/lib/active_merchant/billing/gateways/payment_express.rb +48 -51
  59. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +7 -11
  60. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +7 -0
  61. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +3 -0
  62. data/lib/active_merchant/billing/gateways/paystation.rb +62 -64
  63. data/lib/active_merchant/billing/gateways/payway.rb +2 -9
  64. data/lib/active_merchant/billing/gateways/plugnpay.rb +0 -1
  65. data/lib/active_merchant/billing/gateways/psigate.rb +102 -94
  66. data/lib/active_merchant/billing/gateways/psl_card.rb +66 -67
  67. data/lib/active_merchant/billing/gateways/qbms.rb +0 -6
  68. data/lib/active_merchant/billing/gateways/quantum.rb +2 -8
  69. data/lib/active_merchant/billing/gateways/quickpay.rb +2 -3
  70. data/lib/active_merchant/billing/gateways/realex.rb +6 -16
  71. data/lib/active_merchant/billing/gateways/redsys.rb +394 -0
  72. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +25 -26
  73. data/lib/active_merchant/billing/gateways/sage.rb +15 -16
  74. data/lib/active_merchant/billing/gateways/sage_pay.rb +51 -56
  75. data/lib/active_merchant/billing/gateways/sallie_mae.rb +1 -2
  76. data/lib/active_merchant/billing/gateways/samurai.rb +1 -4
  77. data/lib/active_merchant/billing/gateways/secure_net.rb +0 -1
  78. data/lib/active_merchant/billing/gateways/secure_pay.rb +5 -8
  79. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +0 -5
  80. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +17 -18
  81. data/lib/active_merchant/billing/gateways/skip_jack.rb +29 -34
  82. data/lib/active_merchant/billing/gateways/smart_ps.rb +55 -56
  83. data/lib/active_merchant/billing/gateways/stripe.rb +8 -3
  84. data/lib/active_merchant/billing/gateways/trans_first.rb +28 -29
  85. data/lib/active_merchant/billing/gateways/trust_commerce.rb +85 -87
  86. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +27 -28
  87. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +0 -5
  88. data/lib/active_merchant/billing/gateways/verifi.rb +86 -87
  89. data/lib/active_merchant/billing/gateways/viaklix.rb +42 -47
  90. data/lib/active_merchant/billing/gateways/vindicia.rb +30 -28
  91. data/lib/active_merchant/billing/gateways/webpay.rb +45 -0
  92. data/lib/active_merchant/billing/gateways/wirecard.rb +0 -6
  93. data/lib/active_merchant/billing/gateways/worldpay.rb +4 -9
  94. data/lib/active_merchant/billing/gateways.rb +6 -7
  95. data/lib/active_merchant/billing/integrations/a1agregator/helper.rb +31 -0
  96. data/lib/active_merchant/billing/integrations/a1agregator/notification.rb +186 -0
  97. data/lib/active_merchant/billing/integrations/a1agregator/status.rb +38 -0
  98. data/lib/active_merchant/billing/integrations/a1agregator.rb +26 -0
  99. data/lib/active_merchant/billing/integrations/liqpay/helper.rb +43 -0
  100. data/lib/active_merchant/billing/integrations/liqpay/notification.rb +89 -0
  101. data/lib/active_merchant/billing/integrations/liqpay/return.rb +83 -0
  102. data/lib/active_merchant/billing/integrations/liqpay.rb +30 -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/common.rb +42 -0
  106. data/lib/active_merchant/billing/integrations/pay_fast/helper.rb +50 -0
  107. data/lib/active_merchant/billing/integrations/pay_fast/notification.rb +134 -0
  108. data/lib/active_merchant/billing/integrations/pay_fast/return.rb +10 -0
  109. data/lib/active_merchant/billing/integrations/pay_fast.rb +70 -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 +17 -4
  114. data/lib/active_merchant/version.rb +1 -1
  115. data.tar.gz.sig +0 -0
  116. metadata +46 -27
  117. metadata.gz.sig +0 -0
@@ -1,157 +1,155 @@
1
1
  module ActiveMerchant #:nodoc:
2
- module Billing #:nodoc:
3
- class MerchantESolutionsGateway < Gateway
4
-
5
- self.test_url = 'https://cert.merchante-solutions.com/mes-api/tridentApi'
6
- self.live_url = 'https://api.merchante-solutions.com/mes-api/tridentApi'
7
-
8
- # The countries the gateway supports merchants from as 2 digit ISO country codes
9
- self.supported_countries = ['US']
10
-
11
- # The card types supported by the payment gateway
12
- self.supported_cardtypes = [:visa, :master, :american_express, :discover, :jcb]
13
-
14
- # The homepage URL of the gateway
15
- self.homepage_url = 'http://www.merchante-solutions.com/'
16
-
17
- # The name of the gateway
18
- self.display_name = 'Merchant e-Solutions'
19
-
20
- def initialize(options = {})
21
- requires!(options, :login, :password)
22
- @options = options
23
- super
24
- end
25
-
26
- def authorize(money, creditcard_or_card_id, options = {})
27
- post = {}
28
- add_invoice(post, options)
29
- add_payment_source(post, creditcard_or_card_id, options)
30
- add_address(post, options)
31
- commit('P', money, post)
32
- end
33
-
34
- def purchase(money, creditcard_or_card_id, options = {})
35
- post = {}
36
- add_invoice(post, options)
37
- add_payment_source(post, creditcard_or_card_id, options)
38
- add_address(post, options)
39
- commit('D', money, post)
40
- end
41
-
42
- def capture(money, transaction_id, options = {})
43
- post ={}
44
- post[:transaction_id] = transaction_id
45
- commit('S', money, post)
46
- end
47
-
48
- def store(creditcard, options = {})
49
- post = {}
50
- add_creditcard(post, creditcard, options)
51
- commit('T', nil, post)
52
- end
53
-
54
- def unstore(card_id)
55
- post = {}
56
- post[:card_id] = card_id
57
- commit('X', nil, post)
58
- end
59
-
60
- def refund(money, identification, options = {})
61
- commit('U', money, options.merge(:transaction_id => identification))
62
- end
63
-
64
- def credit(money, creditcard_or_card_id, options = {})
65
- post = {}
66
- add_payment_source(post, creditcard_or_card_id, options)
67
- commit('C', money, post)
68
- end
69
-
70
- def void(transaction_id, options = {})
71
- commit('V', nil, options.merge(:transaction_id => transaction_id))
72
- end
73
-
74
- private
75
-
76
- def add_address(post, options)
77
- if address = options[:billing_address] || options[:address]
78
- post[:cardholder_street_address] = address[:address1].to_s.gsub(/[^\w.]/, '+')
79
- post[:cardholder_zip] = address[:zip].to_s
80
- end
81
- end
82
-
83
- def add_invoice(post, options)
84
- if options.has_key? :order_id
85
- post[:invoice_number] = options[:order_id].to_s.gsub(/[^\w.]/, '')
86
- end
87
- end
88
-
89
- def add_payment_source(post, creditcard_or_card_id, options)
90
- if creditcard_or_card_id.is_a?(String)
91
- # using stored card
92
- post[:card_id] = creditcard_or_card_id
93
- post[:card_exp_date] = options[:expiration_date] if options[:expiration_date]
94
- else
95
- # card info is provided
96
- add_creditcard(post, creditcard_or_card_id, options)
97
- end
98
- end
99
-
100
- def add_creditcard(post, creditcard, options)
101
- post[:card_number] = creditcard.number
102
- post[:cvv2] = creditcard.verification_value if creditcard.verification_value?
103
- post[:card_exp_date] = expdate(creditcard)
104
- end
105
-
106
- def parse(body)
107
- results = {}
108
- body.split(/&/).each do |pair|
109
- key,val = pair.split(/=/)
110
- results[key] = val
111
- end
112
- results
113
- end
114
-
115
- def commit(action, money, parameters)
116
-
117
- url = test? ? self.test_url : self.live_url
118
- parameters[:transaction_amount] = amount(money) if money unless action == 'V'
119
-
120
- response = parse( ssl_post(url, post_data(action,parameters)) )
121
-
122
- Response.new(response["error_code"] == "000", message_from(response), response,
123
- :authorization => response["transaction_id"],
124
- :test => test?,
125
- :cvv_result => response["cvv2_result"],
126
- :avs_result => { :code => response["avs_result"] }
127
- )
128
-
129
- end
130
-
131
- def expdate(creditcard)
132
- year = sprintf("%.4i", creditcard.year)
133
- month = sprintf("%.2i", creditcard.month)
134
- "#{month}#{year[-2..-1]}"
135
- end
136
-
137
- def message_from(response)
138
- if response["error_code"] == "000"
139
- "This transaction has been approved"
140
- else
141
- response["auth_response_text"]
142
- end
143
- end
144
-
145
- def post_data(action, parameters = {})
146
- post = {}
147
- post[:profile_id] = @options[:login]
148
- post[:profile_key] = @options[:password]
149
- post[:transaction_type] = action if action
150
-
151
- request = post.merge(parameters).map {|key,value| "#{key}=#{CGI.escape(value.to_s)}"}.join("&")
152
- request
153
- end
154
- end
155
- end
2
+ module Billing #:nodoc:
3
+ class MerchantESolutionsGateway < Gateway
4
+ self.test_url = 'https://cert.merchante-solutions.com/mes-api/tridentApi'
5
+ self.live_url = 'https://api.merchante-solutions.com/mes-api/tridentApi'
6
+
7
+ # The countries the gateway supports merchants from as 2 digit ISO country codes
8
+ self.supported_countries = ['US']
9
+
10
+ # The card types supported by the payment gateway
11
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover, :jcb]
12
+
13
+ # The homepage URL of the gateway
14
+ self.homepage_url = 'http://www.merchante-solutions.com/'
15
+
16
+ # The name of the gateway
17
+ self.display_name = 'Merchant e-Solutions'
18
+
19
+ def initialize(options = {})
20
+ requires!(options, :login, :password)
21
+ super
22
+ end
23
+
24
+ def authorize(money, creditcard_or_card_id, options = {})
25
+ post = {}
26
+ add_invoice(post, options)
27
+ add_payment_source(post, creditcard_or_card_id, options)
28
+ add_address(post, options)
29
+ commit('P', money, post)
30
+ end
31
+
32
+ def purchase(money, creditcard_or_card_id, options = {})
33
+ post = {}
34
+ add_invoice(post, options)
35
+ add_payment_source(post, creditcard_or_card_id, options)
36
+ add_address(post, options)
37
+ commit('D', money, post)
38
+ end
39
+
40
+ def capture(money, transaction_id, options = {})
41
+ post ={}
42
+ post[:transaction_id] = transaction_id
43
+ commit('S', money, post)
44
+ end
45
+
46
+ def store(creditcard, options = {})
47
+ post = {}
48
+ add_creditcard(post, creditcard, options)
49
+ commit('T', nil, post)
50
+ end
51
+
52
+ def unstore(card_id)
53
+ post = {}
54
+ post[:card_id] = card_id
55
+ commit('X', nil, post)
56
+ end
57
+
58
+ def refund(money, identification, options = {})
59
+ commit('U', money, options.merge(:transaction_id => identification))
60
+ end
61
+
62
+ def credit(money, creditcard_or_card_id, options = {})
63
+ post = {}
64
+ add_payment_source(post, creditcard_or_card_id, options)
65
+ commit('C', money, post)
66
+ end
67
+
68
+ def void(transaction_id, options = {})
69
+ commit('V', nil, options.merge(:transaction_id => transaction_id))
70
+ end
71
+
72
+ private
73
+
74
+ def add_address(post, options)
75
+ if address = options[:billing_address] || options[:address]
76
+ post[:cardholder_street_address] = address[:address1].to_s.gsub(/[^\w.]/, '+')
77
+ post[:cardholder_zip] = address[:zip].to_s
78
+ end
79
+ end
80
+
81
+ def add_invoice(post, options)
82
+ if options.has_key? :order_id
83
+ post[:invoice_number] = options[:order_id].to_s.gsub(/[^\w.]/, '')
84
+ end
85
+ end
86
+
87
+ def add_payment_source(post, creditcard_or_card_id, options)
88
+ if creditcard_or_card_id.is_a?(String)
89
+ # using stored card
90
+ post[:card_id] = creditcard_or_card_id
91
+ post[:card_exp_date] = options[:expiration_date] if options[:expiration_date]
92
+ else
93
+ # card info is provided
94
+ add_creditcard(post, creditcard_or_card_id, options)
95
+ end
96
+ end
97
+
98
+ def add_creditcard(post, creditcard, options)
99
+ post[:card_number] = creditcard.number
100
+ post[:cvv2] = creditcard.verification_value if creditcard.verification_value?
101
+ post[:card_exp_date] = expdate(creditcard)
102
+ end
103
+
104
+ def parse(body)
105
+ results = {}
106
+ body.split(/&/).each do |pair|
107
+ key,val = pair.split(/=/)
108
+ results[key] = val
109
+ end
110
+ results
111
+ end
112
+
113
+ def commit(action, money, parameters)
114
+
115
+ url = test? ? self.test_url : self.live_url
116
+ parameters[:transaction_amount] = amount(money) if money unless action == 'V'
117
+
118
+ response = parse( ssl_post(url, post_data(action,parameters)) )
119
+
120
+ Response.new(response["error_code"] == "000", message_from(response), response,
121
+ :authorization => response["transaction_id"],
122
+ :test => test?,
123
+ :cvv_result => response["cvv2_result"],
124
+ :avs_result => { :code => response["avs_result"] }
125
+ )
126
+
127
+ end
128
+
129
+ def expdate(creditcard)
130
+ year = sprintf("%.4i", creditcard.year)
131
+ month = sprintf("%.2i", creditcard.month)
132
+ "#{month}#{year[-2..-1]}"
133
+ end
134
+
135
+ def message_from(response)
136
+ if response["error_code"] == "000"
137
+ "This transaction has been approved"
138
+ else
139
+ response["auth_response_text"]
140
+ end
141
+ end
142
+
143
+ def post_data(action, parameters = {})
144
+ post = {}
145
+ post[:profile_id] = @options[:login]
146
+ post[:profile_key] = @options[:password]
147
+ post[:transaction_type] = action if action
148
+
149
+ request = post.merge(parameters).map {|key,value| "#{key}=#{CGI.escape(value.to_s)}"}.join("&")
150
+ request
151
+ end
152
+ end
153
+ end
156
154
  end
157
-
155
+
@@ -2,18 +2,18 @@ module ActiveMerchant #:nodoc:
2
2
  module Billing #:nodoc:
3
3
  class MerchantWareGateway < Gateway
4
4
  self.live_url = self.test_url = 'https://ps1.merchantware.net/MerchantWARE/ws/RetailTransaction/TXRetail.asmx'
5
-
5
+
6
6
  self.supported_countries = ['US']
7
7
  self.supported_cardtypes = [:visa, :master, :american_express, :discover]
8
8
  self.homepage_url = 'http://merchantwarehouse.com/merchantware'
9
9
  self.display_name = 'MerchantWARE'
10
-
10
+
11
11
  ENV_NAMESPACES = { "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
12
12
  "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema",
13
13
  "xmlns:env" => "http://schemas.xmlsoap.org/soap/envelope/"
14
14
  }
15
15
  TX_NAMESPACE = "http://merchantwarehouse.com/MerchantWARE/Client/TransactionRetail"
16
-
16
+
17
17
  ACTIONS = {
18
18
  :purchase => "IssueKeyedSale",
19
19
  :authorize => "IssueKeyedPreAuth",
@@ -22,12 +22,12 @@ module ActiveMerchant #:nodoc:
22
22
  :credit => "IssueKeyedRefund",
23
23
  :reference_credit => "IssueRefundByReference"
24
24
  }
25
-
25
+
26
26
  # Creates a new MerchantWareGateway
27
- #
27
+ #
28
28
  # The gateway requires that a valid login, password, and name be passed
29
29
  # in the +options+ hash.
30
- #
30
+ #
31
31
  # ==== Options
32
32
  #
33
33
  # * <tt>:login</tt> - The MerchantWARE SiteID.
@@ -35,25 +35,24 @@ module ActiveMerchant #:nodoc:
35
35
  # * <tt>:name</tt> - The MerchantWARE Name.
36
36
  def initialize(options = {})
37
37
  requires!(options, :login, :password, :name)
38
- @options = options
39
38
  super
40
39
  end
41
40
 
42
41
  # Authorize a credit card for a given amount.
43
- #
42
+ #
44
43
  # ==== Parameters
45
44
  # * <tt>money</tt> - The amount to be authorized as an Integer value in cents.
46
45
  # * <tt>credit_card</tt> - The CreditCard details for the transaction.
47
46
  # * <tt>options</tt>
48
47
  # * <tt>:order_id</tt> - A unique reference for this order (required).
49
- # * <tt>:billing_address</tt> - The billing address for the cardholder.
48
+ # * <tt>:billing_address</tt> - The billing address for the cardholder.
50
49
  def authorize(money, credit_card, options = {})
51
50
  request = build_purchase_request(:authorize, money, credit_card, options)
52
51
  commit(:authorize, request)
53
52
  end
54
-
53
+
55
54
  # Authorize and immediately capture funds from a credit card.
56
- #
55
+ #
57
56
  # ==== Parameters
58
57
  # * <tt>money</tt> - The amount to be authorized as anInteger value in cents.
59
58
  # * <tt>credit_card</tt> - The CreditCard details for the transaction.
@@ -63,10 +62,10 @@ module ActiveMerchant #:nodoc:
63
62
  def purchase(money, credit_card, options = {})
64
63
  request = build_purchase_request(:purchase, money, credit_card, options)
65
64
  commit(:purchase, request)
66
- end
65
+ end
67
66
 
68
67
  # Capture authorized funds from a credit card.
69
- #
68
+ #
70
69
  # ==== Parameters
71
70
  # * <tt>money</tt> - The amount to be captured as anInteger value in cents.
72
71
  # * <tt>authorization</tt> - The authorization string returned from the initial authorization.
@@ -76,20 +75,20 @@ module ActiveMerchant #:nodoc:
76
75
  end
77
76
 
78
77
  # Void a transaction.
79
- #
78
+ #
80
79
  # ==== Parameters
81
80
  # * <tt>authorization</tt> - The authorization string returned from the initial authorization or purchase.
82
81
  def void(authorization, options = {})
83
82
  reference, options[:order_id] = split_reference(authorization)
84
-
83
+
85
84
  request = soap_request(:void) do |xml|
86
85
  add_reference(xml, reference)
87
86
  end
88
87
  commit(:void, request)
89
88
  end
90
-
89
+
91
90
  # Refund an amount back a cardholder
92
- #
91
+ #
93
92
  # ==== Parameters
94
93
  #
95
94
  # * <tt>money</tt> - The amount to be refunded as an Integer value in cents.
@@ -97,7 +96,7 @@ module ActiveMerchant #:nodoc:
97
96
  # * <tt>options</tt>
98
97
  # * <tt>:order_id</tt> - A unique reference for this order (required when performing a non-referenced credit)
99
98
  def credit(money, identification, options = {})
100
- if identification.is_a?(String)
99
+ if identification.is_a?(String)
101
100
  deprecated CREDIT_DEPRECATION_MESSAGE
102
101
  refund(money, identification, options)
103
102
  else
@@ -109,9 +108,9 @@ module ActiveMerchant #:nodoc:
109
108
  perform_reference_credit(money, reference, options)
110
109
  end
111
110
 
112
-
111
+
113
112
  private
114
-
113
+
115
114
  def soap_request(action)
116
115
  xml = Builder::XmlMarkup.new :indent => 2
117
116
  xml.instruct!
@@ -125,10 +124,10 @@ module ActiveMerchant #:nodoc:
125
124
  end
126
125
  xml.target!
127
126
  end
128
-
127
+
129
128
  def build_purchase_request(action, money, credit_card, options)
130
129
  requires!(options, :order_id)
131
-
130
+
132
131
  request = soap_request(action) do |xml|
133
132
  add_invoice(xml, options)
134
133
  add_amount(xml, money)
@@ -136,17 +135,17 @@ module ActiveMerchant #:nodoc:
136
135
  add_address(xml, options)
137
136
  end
138
137
  end
139
-
138
+
140
139
  def build_capture_request(action, money, identification, options)
141
140
  reference, options[:order_id] = split_reference(identification)
142
-
141
+
143
142
  request = soap_request(action) do |xml|
144
143
  add_reference(xml, reference)
145
144
  add_invoice(xml, options)
146
145
  add_amount(xml, money)
147
146
  end
148
147
  end
149
-
148
+
150
149
  def perform_reference_credit(money, identification, options)
151
150
  reference, options[:order_id] = split_reference(identification)
152
151
 
@@ -155,19 +154,19 @@ module ActiveMerchant #:nodoc:
155
154
  add_invoice(xml, options)
156
155
  add_amount(xml, money, "strOverrideAmount")
157
156
  end
158
-
157
+
159
158
  commit(:reference_credit, request)
160
159
  end
161
-
160
+
162
161
  def perform_credit(money, credit_card, options)
163
162
  requires!(options, :order_id)
164
-
163
+
165
164
  request = soap_request(:credit) do |xml|
166
165
  add_invoice(xml, options)
167
166
  add_amount(xml, money)
168
167
  add_credit_card(xml, credit_card)
169
168
  end
170
-
169
+
171
170
  commit(:credit, request)
172
171
  end
173
172
 
@@ -176,18 +175,18 @@ module ActiveMerchant #:nodoc:
176
175
  xml.tag! "strKey", @options[:password]
177
176
  xml.tag! "strName", @options[:name]
178
177
  end
179
-
178
+
180
179
  def expdate(credit_card)
181
180
  year = sprintf("%.4i", credit_card.year)
182
181
  month = sprintf("%.2i", credit_card.month)
183
182
 
184
183
  "#{month}#{year[-2..-1]}"
185
184
  end
186
-
185
+
187
186
  def add_invoice(xml, options)
188
187
  xml.tag! "strOrderNumber", options[:order_id].to_s.gsub(/[^\w]/, '').slice(0, 25)
189
188
  end
190
-
189
+
191
190
  def add_amount(xml, money, tag = "strAmount")
192
191
  xml.tag! tag, amount(money)
193
192
  end
@@ -195,48 +194,48 @@ module ActiveMerchant #:nodoc:
195
194
  def add_reference(xml, reference)
196
195
  xml.tag! "strReferenceCode", reference
197
196
  end
198
-
197
+
199
198
  def add_address(xml, options)
200
199
  if address = options[:billing_address] || options[:address]
201
200
  xml.tag! "strAVSStreetAddress", address[:address1]
202
201
  xml.tag! "strAVSZipCode", address[:zip]
203
202
  end
204
203
  end
205
-
204
+
206
205
  def add_credit_card(xml, credit_card)
207
206
  xml.tag! "strPAN", credit_card.number
208
207
  xml.tag! "strExpDate", expdate(credit_card)
209
208
  xml.tag! "strCardHolder", credit_card.name
210
209
  xml.tag! "strCVCode", credit_card.verification_value if credit_card.verification_value?
211
210
  end
212
-
211
+
213
212
  def split_reference(reference)
214
213
  reference.to_s.split(";")
215
214
  end
216
-
215
+
217
216
  def parse(action, data)
218
217
  response = {}
219
218
  xml = REXML::Document.new(data)
220
-
219
+
221
220
  root = REXML::XPath.first(xml, "//#{ACTIONS[action]}Response/#{ACTIONS[action]}Result")
222
221
 
223
222
  root.elements.each do |element|
224
223
  response[element.name] = element.text
225
224
  end
226
-
225
+
227
226
  status, code, message = response["ApprovalStatus"].split(";")
228
227
  response[:status] = status
229
-
230
- if response[:success] = status == "APPROVED"
228
+
229
+ if response[:success] = status == "APPROVED"
231
230
  response[:message] = status
232
231
  else
233
232
  response[:message] = message
234
233
  response[:failure_code] = code
235
234
  end
236
235
 
237
- response
236
+ response
238
237
  end
239
-
238
+
240
239
  def parse_error(http_response)
241
240
  response = {}
242
241
  response[:http_code] = http_response.code
@@ -246,11 +245,11 @@ module ActiveMerchant #:nodoc:
246
245
  document = REXML::Document.new(http_response.body)
247
246
 
248
247
  node = REXML::XPath.first(document, "//soap:Fault")
249
-
248
+
250
249
  node.elements.each do |element|
251
250
  response[element.name] = element.text
252
251
  end
253
-
252
+
254
253
  response[:message] = response["faultstring"].to_s.gsub("\n", " ")
255
254
  response
256
255
  rescue REXML::ParseException => e
@@ -258,10 +257,10 @@ module ActiveMerchant #:nodoc:
258
257
  response[:message] = "Failed to parse the failed response"
259
258
  response
260
259
  end
261
-
260
+
262
261
  def commit(action, request)
263
262
  begin
264
- data = ssl_post(self.live_url, request,
263
+ data = ssl_post(self.live_url, request,
265
264
  "Content-Type" => 'text/xml; charset=utf-8',
266
265
  "SOAPAction" => "http://merchantwarehouse.com/MerchantWARE/Client/TransactionRetail/#{ACTIONS[action]}"
267
266
  )
@@ -269,15 +268,15 @@ module ActiveMerchant #:nodoc:
269
268
  rescue ActiveMerchant::ResponseError => e
270
269
  response = parse_error(e.response)
271
270
  end
272
-
273
- Response.new(response[:success], response[:message], response,
274
- :test => test?,
271
+
272
+ Response.new(response[:success], response[:message], response,
273
+ :test => test?,
275
274
  :authorization => authorization_from(response),
276
275
  :avs_result => { :code => response["AVSResponse"] },
277
276
  :cvv_result => response["CVResponse"]
278
277
  )
279
278
  end
280
-
279
+
281
280
  def authorization_from(response)
282
281
  if response[:success]
283
282
  [ response["ReferenceID"], response["OrderNumber"] ].join(";")