projectdx_activemerchant 1.7.1.20100817.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. data/CHANGELOG +530 -0
  2. data/CONTRIBUTORS +142 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +136 -0
  5. data/gem-public_cert.pem +20 -0
  6. data/lib/active_merchant/billing/avs_result.rb +98 -0
  7. data/lib/active_merchant/billing/base.rb +57 -0
  8. data/lib/active_merchant/billing/check.rb +68 -0
  9. data/lib/active_merchant/billing/credit_card.rb +159 -0
  10. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  11. data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
  12. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  13. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  14. data/lib/active_merchant/billing/gateway.rb +163 -0
  15. data/lib/active_merchant/billing/gateways/authorize_net.rb +654 -0
  16. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +736 -0
  17. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +244 -0
  18. data/lib/active_merchant/billing/gateways/beanstream.rb +102 -0
  19. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  20. data/lib/active_merchant/billing/gateways/bogus.rb +102 -0
  21. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  22. data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
  23. data/lib/active_merchant/billing/gateways/braintree_blue.rb +210 -0
  24. data/lib/active_merchant/billing/gateways/braintree_orange.rb +17 -0
  25. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  26. data/lib/active_merchant/billing/gateways/convenience_pay.rb +191 -0
  27. data/lib/active_merchant/billing/gateways/cyber_source.rb +406 -0
  28. data/lib/active_merchant/billing/gateways/data_cash.rb +593 -0
  29. data/lib/active_merchant/billing/gateways/efsnet.rb +229 -0
  30. data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
  31. data/lib/active_merchant/billing/gateways/eway.rb +277 -0
  32. data/lib/active_merchant/billing/gateways/exact.rb +222 -0
  33. data/lib/active_merchant/billing/gateways/first_pay.rb +172 -0
  34. data/lib/active_merchant/billing/gateways/garanti.rb +222 -0
  35. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  36. data/lib/active_merchant/billing/gateways/jetpay.rb +270 -0
  37. data/lib/active_merchant/billing/gateways/linkpoint.rb +449 -0
  38. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +154 -0
  39. data/lib/active_merchant/billing/gateways/merchant_ware.rb +283 -0
  40. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  41. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  42. data/lib/active_merchant/billing/gateways/moneris.rb +205 -0
  43. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  44. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  45. data/lib/active_merchant/billing/gateways/ogone.rb +279 -0
  46. data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
  47. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  48. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -0
  49. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  50. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  51. data/lib/active_merchant/billing/gateways/payflow.rb +236 -0
  52. data/lib/active_merchant/billing/gateways/payflow_express.rb +138 -0
  53. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  54. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  55. data/lib/active_merchant/billing/gateways/payment_express.rb +230 -0
  56. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +326 -0
  57. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +38 -0
  58. data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
  59. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  60. data/lib/active_merchant/billing/gateways/paypal_express.rb +135 -0
  61. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +20 -0
  62. data/lib/active_merchant/billing/gateways/plugnpay.rb +292 -0
  63. data/lib/active_merchant/billing/gateways/psigate.rb +214 -0
  64. data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
  65. data/lib/active_merchant/billing/gateways/quickpay.rb +213 -0
  66. data/lib/active_merchant/billing/gateways/realex.rb +200 -0
  67. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  68. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
  69. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  70. data/lib/active_merchant/billing/gateways/sage.rb +146 -0
  71. data/lib/active_merchant/billing/gateways/sage_pay.rb +309 -0
  72. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  73. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  74. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +157 -0
  75. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  76. data/lib/active_merchant/billing/gateways/skip_jack.rb +453 -0
  77. data/lib/active_merchant/billing/gateways/smart_ps.rb +265 -0
  78. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  79. data/lib/active_merchant/billing/gateways/transax.rb +25 -0
  80. data/lib/active_merchant/billing/gateways/trust_commerce.rb +418 -0
  81. data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
  82. data/lib/active_merchant/billing/gateways/verifi.rb +228 -0
  83. data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
  84. data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
  85. data/lib/active_merchant/billing/gateways.rb +18 -0
  86. data/lib/active_merchant/billing/integrations/action_view_helper.rb +79 -0
  87. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  88. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  89. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  90. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  91. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
  92. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
  93. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  94. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  95. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  96. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  97. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
  98. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  99. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  100. data/lib/active_merchant/billing/integrations/helper.rb +93 -0
  101. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  102. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  103. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  104. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  105. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  106. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  107. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  108. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  109. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  110. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  111. data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
  112. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  113. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  114. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
  115. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  116. data/lib/active_merchant/billing/integrations/quickpay.rb +17 -0
  117. data/lib/active_merchant/billing/integrations/return.rb +35 -0
  118. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
  119. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
  120. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  121. data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
  122. data/lib/active_merchant/billing/integrations.rb +29 -0
  123. data/lib/active_merchant/billing/response.rb +32 -0
  124. data/lib/active_merchant/billing.rb +9 -0
  125. data/lib/active_merchant/common/connection.rb +172 -0
  126. data/lib/active_merchant/common/country.rb +319 -0
  127. data/lib/active_merchant/common/error.rb +26 -0
  128. data/lib/active_merchant/common/post_data.rb +24 -0
  129. data/lib/active_merchant/common/posts_data.rb +47 -0
  130. data/lib/active_merchant/common/requires_parameters.rb +16 -0
  131. data/lib/active_merchant/common/utils.rb +18 -0
  132. data/lib/active_merchant/common/validateable.rb +76 -0
  133. data/lib/active_merchant/common.rb +14 -0
  134. data/lib/active_merchant/version.rb +3 -0
  135. data/lib/active_merchant.rb +47 -0
  136. data/lib/activemerchant.rb +1 -0
  137. data/lib/certs/cacert.pem +7815 -0
  138. data/lib/support/gateway_support.rb +58 -0
  139. data/lib/support/outbound_hosts.rb +25 -0
  140. metadata +254 -0
@@ -0,0 +1,210 @@
1
+ require File.dirname(__FILE__) + '/braintree/braintree_common'
2
+
3
+ begin
4
+ require "braintree"
5
+ rescue LoadError
6
+ raise "Could not load the braintree gem. Use `gem install braintree` to install it."
7
+ end
8
+
9
+ raise "Need braintree gem 2.x.y. Run `gem install braintree --version '~>2.0'` to get the correct version." unless Braintree::Version::Major == 2
10
+
11
+ module ActiveMerchant #:nodoc:
12
+ module Billing #:nodoc:
13
+ class BraintreeBlueGateway < Gateway
14
+ include BraintreeCommon
15
+
16
+ self.display_name = 'Braintree (Blue Platform)'
17
+
18
+ def initialize(options = {})
19
+ requires!(options, :merchant_id, :public_key, :private_key)
20
+ @options = options
21
+ Braintree::Configuration.merchant_id = options[:merchant_id]
22
+ Braintree::Configuration.public_key = options[:public_key]
23
+ Braintree::Configuration.private_key = options[:private_key]
24
+ Braintree::Configuration.environment = test? ? :sandbox : :production
25
+ Braintree::Configuration.logger.level = Logger::ERROR#DEBUG
26
+ Braintree::Configuration.custom_user_agent = "ActiveMerchant #{ActiveMerchant::VERSION}"
27
+ super
28
+ end
29
+
30
+ def authorize(money, credit_card_or_vault_id, options = {})
31
+ create_transaction(:sale, money, credit_card_or_vault_id, options)
32
+ end
33
+
34
+ def capture(money, authorization, options = {})
35
+ commit do
36
+ result = Braintree::Transaction.submit_for_settlement(authorization, amount(money).to_s)
37
+ Response.new(result.success?, message_from_result(result))
38
+ end
39
+ end
40
+
41
+ def purchase(money, credit_card_or_vault_id, options = {})
42
+ authorize(money, credit_card_or_vault_id, options.merge(:submit_for_settlement => true))
43
+ end
44
+
45
+ def credit(money, credit_card_or_vault_id, options = {})
46
+ create_transaction(:credit, money, credit_card_or_vault_id, options)
47
+ end
48
+
49
+ def refund(transaction_id, options = {})
50
+ commit do
51
+ result = Braintree::Transaction.find(transaction_id).refund
52
+ Response.new(result.success?, message_from_result(result))
53
+ end
54
+ end
55
+
56
+ def void(authorization, options = {})
57
+ commit do
58
+ result = Braintree::Transaction.void(authorization)
59
+ Response.new(result.success?, message_from_result(result),
60
+ :braintree_transaction => (result.transaction if result.success?)
61
+ )
62
+ end
63
+ end
64
+
65
+ def store(creditcard, options = {})
66
+ commit do
67
+ result = Braintree::Customer.create(
68
+ :first_name => creditcard.first_name,
69
+ :last_name => creditcard.last_name,
70
+ :email => options[:email],
71
+ :credit_card => {
72
+ :number => creditcard.number,
73
+ :cvv => creditcard.verification_value,
74
+ :expiration_month => creditcard.month.to_s.rjust(2, "0"),
75
+ :expiration_year => creditcard.year.to_s
76
+ }
77
+ )
78
+ Response.new(result.success?, message_from_result(result),
79
+ {
80
+ :braintree_customer => (result.customer if result.success?),
81
+ :customer_vault_id => (result.customer.id if result.success?)
82
+ }
83
+ )
84
+ end
85
+ end
86
+
87
+ def update(vault_id, creditcard, options = {})
88
+ braintree_credit_card = nil
89
+ customer_update_result = commit do
90
+ braintree_credit_card = Braintree::Customer.find(vault_id).credit_cards.detect { |cc| cc.default? }
91
+ return Response.new(false, 'Braintree::NotFoundError') if braintree_credit_card.nil?
92
+ result = Braintree::Customer.update(vault_id,
93
+ :first_name => creditcard.first_name,
94
+ :last_name => creditcard.last_name,
95
+ :email => options[:email]
96
+ )
97
+ Response.new(result.success?, message_from_result(result),
98
+ :braintree_customer => (Braintree::Customer.find(vault_id) if result.success?)
99
+ )
100
+ end
101
+ return customer_update_result unless customer_update_result.success?
102
+ credit_card_update_result = commit do
103
+ result = Braintree::CreditCard.update(braintree_credit_card.token,
104
+ :number => creditcard.number,
105
+ :expiration_month => creditcard.month.to_s.rjust(2, "0"),
106
+ :expiration_year => creditcard.year.to_s
107
+ )
108
+ Response.new(result.success?, message_from_result(result),
109
+ :braintree_customer => (Braintree::Customer.find(vault_id) if result.success?)
110
+ )
111
+ end
112
+ end
113
+
114
+ def unstore(customer_vault_id)
115
+ commit do
116
+ Braintree::Customer.delete(customer_vault_id)
117
+ Response.new(true, "OK")
118
+ end
119
+ end
120
+ alias_method :delete, :unstore
121
+
122
+ private
123
+
124
+ def map_address(address)
125
+ return {} if address.nil?
126
+ {
127
+ :street_address => address[:address1],
128
+ :extended_address => address[:address2],
129
+ :company => address[:company],
130
+ :locality => address[:city],
131
+ :region => address[:state],
132
+ :postal_code => address[:zip],
133
+ :country_name => address[:country]
134
+ }
135
+ end
136
+
137
+ def commit(&block)
138
+ yield
139
+ rescue Braintree::BraintreeError => ex
140
+ Response.new(false, ex.class.to_s)
141
+ end
142
+
143
+ def message_from_result(result)
144
+ if result.success?
145
+ "OK"
146
+ else
147
+ result.errors.map { |e| "#{e.message} (#{e.code})" }.join(" ")
148
+ end
149
+ end
150
+
151
+ def create_transaction(transaction_type, money, credit_card_or_vault_id, options)
152
+ parameters = {
153
+ :amount => amount(money).to_s,
154
+ :order_id => options[:order_id],
155
+ :customer => {
156
+ :id => options[:store] == true ? "" : options[:store],
157
+ :email => options[:email]
158
+ },
159
+ :options => {
160
+ :store_in_vault => options[:store] ? true : false,
161
+ :submit_for_settlement => options[:submit_for_settlement]
162
+ }
163
+ }
164
+ if credit_card_or_vault_id.is_a?(String) || credit_card_or_vault_id.is_a?(Integer)
165
+ parameters[:customer_id] = credit_card_or_vault_id
166
+ else
167
+ parameters[:customer].merge!(
168
+ :first_name => credit_card_or_vault_id.first_name,
169
+ :last_name => credit_card_or_vault_id.last_name
170
+ )
171
+ parameters[:credit_card] = {
172
+ :number => credit_card_or_vault_id.number,
173
+ :cvv => credit_card_or_vault_id.verification_value,
174
+ :expiration_month => credit_card_or_vault_id.month.to_s.rjust(2, "0"),
175
+ :expiration_year => credit_card_or_vault_id.year.to_s
176
+ }
177
+ end
178
+ parameters[:billing] = map_address(options[:billing_address]) if options[:billing_address]
179
+ parameters[:shipping] = map_address(options[:shipping_address]) if options[:shipping_address]
180
+ commit do
181
+ result = Braintree::Transaction.send(transaction_type, parameters)
182
+ response_params, response_options, avs_result, cvv_result = {}, {}, {}, {}
183
+ if result.success?
184
+ response_params[:braintree_transaction] = result.transaction
185
+ response_params[:customer_vault_id] = result.transaction.customer_details.id
186
+ response_options[:authorization] = result.transaction.id
187
+ end
188
+ if result.transaction
189
+ avs_result = {
190
+ 'code' => '', 'message' => '',
191
+ 'street_match' => result.transaction.avs_street_address_response_code == 'M',
192
+ 'postal_match' => result.transaction.avs_postal_code_response_code == 'M'
193
+ }
194
+ cvv_result = {
195
+ 'code' => result.transaction.cvv_response_code, 'message' => ''
196
+ }
197
+ message = result.transaction.processor_response_code + " " + result.transaction.processor_response_text
198
+ else
199
+ message = message_from_result(result)
200
+ end
201
+ response = Response.new(result.success?, message, response_params, response_options)
202
+ response.instance_variable_set("@avs_result", avs_result)
203
+ response.instance_variable_set("@cvv_result", cvv_result)
204
+ response
205
+ end
206
+ end
207
+ end
208
+ end
209
+ end
210
+
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/smart_ps.rb'
2
+ require File.dirname(__FILE__) + '/braintree/braintree_common'
3
+
4
+ module ActiveMerchant #:nodoc:
5
+ module Billing #:nodoc:
6
+ class BraintreeOrangeGateway < SmartPs
7
+ include BraintreeCommon
8
+
9
+ self.display_name = 'Braintree (Orange Platform)'
10
+
11
+ def api_url
12
+ 'https://secure.braintreepaymentgateway.com/api/transact.php'
13
+ end
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,230 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ #
4
+ # CardStream supports the following credit cards, which are auto-detected by
5
+ # the gateway based on the card number used:
6
+ # * AM American Express
7
+ # * Diners Club
8
+ # * Electron
9
+ # * JCB
10
+ # * UK Maestro
11
+ # * Maestro International
12
+ # * Mastercard
13
+ # * Solo
14
+ # * Style
15
+ # * Switch
16
+ # * Visa Credit
17
+ # * Visa Debit
18
+ # * Visa Purchasing
19
+ #
20
+ class CardStreamGateway < Gateway
21
+ URL = 'https://gateway.cardstream.com/process.ashx'
22
+
23
+ self.money_format = :cents
24
+ self.default_currency = 'GBP'
25
+ self.supported_countries = ['GB']
26
+ self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :discover, :jcb, :maestro, :solo, :switch]
27
+ self.homepage_url = 'http://www.cardstream.com/'
28
+ self.display_name = 'CardStream'
29
+
30
+ APPROVED = '00'
31
+
32
+ CURRENCY_CODES = {
33
+ "AUD"=> '036',
34
+ "CAD"=> '124',
35
+ "CZK"=> '203',
36
+ "DKK"=> '208',
37
+ "HKD"=> '344',
38
+ "ICK"=> '352',
39
+ "JPY"=> '392',
40
+ "NOK"=> '578',
41
+ "SGD"=> '702',
42
+ "SEK"=> '752',
43
+ "CHF"=> '756',
44
+ "GBP"=> '826',
45
+ "USD"=> '840',
46
+ "EUR"=> '978'
47
+ }
48
+
49
+ TRANSACTIONS = {
50
+ :purchase => 'ESALE_KEYED',
51
+ :refund => 'EREFUND_KEYED',
52
+ :authorization => 'ESALE_KEYED'
53
+ }
54
+
55
+ CVV_CODE = {
56
+ '0' => 'U',
57
+ '1' => 'P',
58
+ '2' => 'M',
59
+ '4' => 'N'
60
+ }
61
+
62
+ # 0 - No additional information available.
63
+ # 1 - Postcode not checked.
64
+ # 2 - Postcode matched.
65
+ # 4 - Postcode not matched.
66
+ # 8 - Postcode partially matched.
67
+ AVS_POSTAL_MATCH = {
68
+ "0" => nil,
69
+ "1" => nil,
70
+ "2" => "Y",
71
+ "4" => "N",
72
+ "8" => "N"
73
+ }
74
+
75
+ # 0 - No additional information available.
76
+ # 1 - Address numeric not checked.
77
+ # 2 - Address numeric matched.
78
+ # 4 - Address numeric not matched.
79
+ # 8 - Address numeric partially matched.
80
+ AVS_STREET_MATCH = {
81
+ "0" => nil,
82
+ "1" => nil,
83
+ "2" => "Y",
84
+ "4" => "N",
85
+ "8" => "N"
86
+ }
87
+
88
+ def initialize(options = {})
89
+ requires!(options, :login, :password)
90
+ @options = options
91
+ super
92
+ end
93
+
94
+ def purchase(money, credit_card, options = {})
95
+ requires!(options, :order_id)
96
+
97
+ post = {}
98
+
99
+ add_amount(post, money, options)
100
+ add_invoice(post, money, credit_card, options)
101
+ add_credit_card(post, credit_card)
102
+ add_address(post, options)
103
+ add_customer_data(post, options)
104
+
105
+ commit(:purchase, post)
106
+ end
107
+
108
+ private
109
+
110
+ def add_amount(post, money, options)
111
+ add_pair(post, :Amount, amount(money), :required => true)
112
+ add_pair(post, :CurrencyCode, currency_code(options[:currency] || currency(money)), :required => true)
113
+ end
114
+
115
+ def add_customer_data(post, options)
116
+ add_pair(post, :BillingEmail, options[:email])
117
+ add_pair(post, :BillingPhoneNumber, options[:phone])
118
+ end
119
+
120
+ def add_address(post, options)
121
+ address = options[:billing_address] || options[:address]
122
+
123
+ return if address.nil?
124
+
125
+ add_pair(post, :BillingStreet, address[:address1])
126
+ add_pair(post, :BillingHouseNumber, address[:address2])
127
+ add_pair(post, :BillingCity, address[:city])
128
+ add_pair(post, :BillingState, address[:state])
129
+ add_pair(post, :BillingPostCode, address[:zip])
130
+ end
131
+
132
+ def add_invoice(post, money, credit_card, options)
133
+ add_pair(post, :TransactionUnique, options[:order_id], :required => true)
134
+ add_pair(post, :OrderDesc, options[:description] || options[:order_id], :required => true)
135
+
136
+ if [ 'american_express', 'diners_club' ].include?(card_brand(credit_card).to_s)
137
+ add_pair(post, :AEIT1Quantity, 1)
138
+ add_pair(post, :AEIT1Description, (options[:description] || options[:order_id]).slice(0, 15))
139
+ add_pair(post, :AEIT1GrossValue, amount(money))
140
+ end
141
+ end
142
+
143
+ def add_credit_card(post, credit_card)
144
+ add_pair(post, :CardName, credit_card.name, :required => true)
145
+ add_pair(post, :CardNumber, credit_card.number, :required => true)
146
+
147
+ add_pair(post, :ExpiryDateMM, format(credit_card.month, :two_digits), :required => true)
148
+ add_pair(post, :ExpiryDateYY, format(credit_card.year, :two_digits), :required => true)
149
+
150
+ if requires_start_date_or_issue_number?(credit_card)
151
+ add_pair(post, :StartDateMM, format(credit_card.start_month, :two_digits))
152
+ add_pair(post, :StartDateYY, format(credit_card.start_year, :two_digits))
153
+
154
+ add_pair(post, :IssueNumber, credit_card.issue_number)
155
+ end
156
+
157
+ add_pair(post, :CV2, credit_card.verification_value)
158
+ end
159
+
160
+ def commit(action, parameters)
161
+ response = parse( ssl_post(URL, post_data(action, parameters)) )
162
+
163
+ Response.new(response[:response_code] == APPROVED, message_from(response), response,
164
+ :test => test?,
165
+ :authorization => response[:cross_reference],
166
+ :cvv_result => CVV_CODE[ response[:avscv2_response_code].to_s[0, 1] ],
167
+ :avs_result => {
168
+ :street_match => AVS_STREET_MATCH[ response[:avscv2_response_code].to_s[2, 1] ],
169
+ :postal_match => AVS_POSTAL_MATCH[ response[:avscv2_response_code].to_s[1, 1] ]
170
+ }
171
+ )
172
+ end
173
+
174
+ def message_from(results)
175
+ results[:response_code] == APPROVED ? "APPROVED" : results[:message]
176
+ end
177
+
178
+ def post_data(action, parameters = {})
179
+ parameters.update(
180
+ :MerchantPassword => @options[:password],
181
+ :MerchantID => @options[:login],
182
+ :MessageType => TRANSACTIONS[action],
183
+ :CallBack => "disable",
184
+ :DuplicateDelay => "0",
185
+ :EchoCardType => "YES",
186
+ :EchoAmount => "YES",
187
+ :EchoAVSCV2ResponseCode => "YES",
188
+ :ReturnAVSCV2Message => "YES",
189
+ :CountryCode => '826' # 826 for UK based merchant
190
+ )
191
+
192
+ add_pair(parameters, :Dispatch, action == :authorization ? "LATER" : "NOW")
193
+
194
+ parameters.collect { |key, value| "VP#{key}=#{CGI.escape(value.to_s)}" }.join("&")
195
+ end
196
+
197
+ # VPCrossReference
198
+ # The value in VPCrossReference on a success transaction will contain
199
+ # a unique reference that you may use to run future transactions.
200
+ # Please note that cross reference transactions must come a static IP
201
+ # addressed that has been pre-registered with Cardstream. To
202
+ # register an IP address please send it to support@cardstream.com
203
+ # with your Cardstream issued merchant ID and it will be added to
204
+ # your account.
205
+ def parse(body)
206
+ result = {}
207
+ pairs = body.split("&")
208
+ pairs.each do |pair|
209
+ a = pair.split("=")
210
+ result[a[0].gsub(/^VP/,'').underscore.to_sym] = a[1]
211
+ end
212
+
213
+ result
214
+ end
215
+
216
+ def test?
217
+ @options[:test] || Base.gateway_mode == :test
218
+ end
219
+
220
+ def currency_code(currency)
221
+ CURRENCY_CODES[currency]
222
+ end
223
+
224
+ def add_pair(post, key, value, options = {})
225
+ post[key] = value if !value.blank? || options[:required]
226
+ end
227
+ end
228
+ end
229
+ end
230
+
@@ -0,0 +1,191 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ # See the remote test file for example usage.
4
+ #
5
+ # * All transactions use dollar values.
6
+ class ConveniencePayGateway < Gateway
7
+ TEST_URL = 'https://mo.paybill.com/WebServices/v3.6/PaybillService36.asmx'
8
+ LIVE_URL = 'https://www.paybill.com/WebServices/v3.6/PaybillService36.asmx'
9
+
10
+ # visa, master, american_express, discover
11
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
12
+ self.supported_countries = ['US']
13
+ self.default_currency = 'USD'
14
+ self.homepage_url = 'http://www.paybill.com'
15
+ self.display_name = 'HP Convenience Pay Services'
16
+
17
+ # These are the options that can be used when creating a new Convenience Pay Gateway object.
18
+ #
19
+ # :login => your username
20
+ #
21
+ # :password => your password
22
+ #
23
+ # :test => true sets the gateway to test mode
24
+
25
+ def initialize(options = {})
26
+ requires!(options, :login, :password, :client_id, :transaction_type)
27
+ @options = options
28
+ super
29
+ end
30
+
31
+ # Should run against the test servers or not?
32
+ def test?
33
+ @options[:test] || Base.gateway_mode == :test
34
+ end
35
+
36
+ def purchase(money, creditcard, options = {})
37
+ requires!(options, :order_id)
38
+ setup_address_hash(options)
39
+ commit('AuthorizeCreditCard', build_purchase_request(money, creditcard, options), options)
40
+ end
41
+
42
+ def void(identification, options = {})
43
+ commit('VoidPayment', build_void_request(identification, options), options)
44
+ end
45
+
46
+ private
47
+ # Create all address hash key value pairs so that we still function if we were only provided with one or two of them
48
+ def setup_address_hash(options)
49
+ options[:billing_address] = options[:billing_address] || options[:address] || {}
50
+ options[:shipping_address] = options[:shipping_address] || {}
51
+ end
52
+
53
+ def build_purchase_request(money, creditcard, options)
54
+ xml = Builder::XmlMarkup.new :indent => 2
55
+ add_address(xml, creditcard, options[:billing_address], options)
56
+ add_purchase_data(xml, money, options)
57
+ add_creditcard(xml, creditcard)
58
+ xml.target!
59
+ end
60
+
61
+ def build_void_request(transaction_id, options)
62
+ xml = Builder::XmlMarkup.new :indent => 2
63
+ add_void_data(xml, transaction_id, options)
64
+ xml.target!
65
+ end
66
+
67
+ def add_merchant_data(xml, options)
68
+ xml.tag! 'ClientId', @options[:client_id]
69
+ xml.tag! 'TransactionType', @options[:transaction_type]
70
+ end
71
+
72
+ def add_void_data(xml, transaction_id, options)
73
+ xml.tag! 'ClientAccountNumber', options[:order_id]
74
+ xml.tag! 'TransactionId', transaction_id
75
+ end
76
+
77
+ def add_purchase_data(xml, money = 0, options={})
78
+ xml.tag! 'PaymentAmount', amount(money)
79
+ xml.tag! 'ClientAccountNumber', options[:order_id]
80
+ xml.tag! 'ClientUserId', nil
81
+ xml.tag! 'AdditionalData', nil
82
+ end
83
+
84
+ def add_address(xml, creditcard, address, options)
85
+ xml.tag! 'CustomerFirstName', creditcard.first_name
86
+ xml.tag! 'CustomerLastName', creditcard.last_name
87
+ xml.tag! 'NotifyCustomerEmail', nil
88
+ xml.tag! 'ZipCode', address[:zip]
89
+ end
90
+
91
+ def add_creditcard(xml, creditcard)
92
+ xml.tag! 'PaymentAccountNumber', creditcard.number
93
+ xml.tag! 'ExpirationDate', "#{format(creditcard.month, :two_digits)}#{format(creditcard.year, :four_digits)}"
94
+ xml.tag! 'VerificationCode', creditcard.verification_value
95
+ end
96
+
97
+ # Where we actually build the full SOAP request using builder
98
+ def build_request(transaction_type, body, options)
99
+ xml = Builder::XmlMarkup.new :indent => 2
100
+ xml.instruct!
101
+ xml.tag! 'soap:Envelope', {'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema', 'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/'} do
102
+ xml.tag! 'soap:Header' do
103
+ xml.tag! 'PaybillCredentials', {'xmlns' => 'http://www.paybill.com/'} do
104
+ xml.tag! 'Username', @options[:login]
105
+ xml.tag! 'Password', @options[:password]
106
+ end
107
+ end
108
+ xml.tag! 'soap:Body' do
109
+ xml.tag! transaction_type, {'xmlns' => 'http://www.paybill.com/'} do
110
+ xml.tag! 'request' do
111
+ add_merchant_data(xml, options)
112
+ xml << body
113
+ end
114
+ end
115
+ end
116
+ end
117
+ xml.target!
118
+ end
119
+
120
+ # Contact HP Convenience Pay Services, make the SOAP request, and parse the reply into a Response object
121
+ def commit(transaction_type, request, options)
122
+ response = parse(ssl_post(test? ? TEST_URL : LIVE_URL, build_request(transaction_type, request, options), { "Content-Type" => "text/xml" }))
123
+
124
+ success = response[:decision] == "true"
125
+ message = response[:message]
126
+ authorization = response[:transaction_id]
127
+
128
+ Response.new(success, message, response,
129
+ :test => test?,
130
+ :authorization => authorization
131
+ )
132
+ end
133
+
134
+ # Parse the SOAP response
135
+ # Technique inspired by the Paypal Gateway
136
+ def parse(xml)
137
+ reply = {}
138
+ xml = REXML::Document.new(xml)
139
+ if root = REXML::XPath.first(xml, "//AuthorizeCreditCardResult")
140
+ root.elements.to_a.each do |node|
141
+ case node.name
142
+ when 'ResponseText'
143
+ reply[:message] = node.text
144
+ when 'Authorized'
145
+ reply[:decision] = node.text
146
+ when 'ConfirmationNumber'
147
+ reply[:confirmation_number] = node.text
148
+ when 'TransactionId'
149
+ reply[:transaction_id] = node.text
150
+ else
151
+ parse_element(reply, node)
152
+ end
153
+ end
154
+ elsif root = REXML::XPath.first(xml, "//VoidPaymentResult")
155
+ root.elements.to_a.each do |node|
156
+ case node.name
157
+ when 'VoidResponseText'
158
+ reply[:message] = node.text
159
+ when 'IsVoided'
160
+ reply[:decision] = node.text
161
+ when 'VoidConfirmationNumber'
162
+ reply[:confirmation_number] = node.text
163
+ when 'VoidDateTime'
164
+ reply[:void_date_time] = node.text
165
+ else
166
+ parse_element(reply, node)
167
+ end
168
+ end
169
+ elsif root = REXML::XPath.first(xml, "//soap:Fault")
170
+ parse_element(reply, root)
171
+ reply[:message] = "#{reply[:faultcode]}: #{reply[:faultstring]}"
172
+ end
173
+ return reply
174
+ end
175
+
176
+ def parse_element(reply, node)
177
+ if node.has_elements?
178
+ node.elements.each{|e| parse_element(reply, e) }
179
+ else
180
+ if node.parent.name =~ /item/
181
+ parent = node.parent.name + (node.parent.attributes["id"] ? "_" + node.parent.attributes["id"] : '')
182
+ reply[(parent + '_' + node.name).to_sym] = node.text
183
+ else
184
+ reply[node.name.to_sym] = node.text
185
+ end
186
+ end
187
+ return reply
188
+ end
189
+ end
190
+ end
191
+ end