maedana-activemerchant 1.9.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +571 -0
- data/CONTRIBUTORS +170 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +150 -0
- data/gem-public_cert.pem +20 -0
- data/lib/active_merchant.rb +49 -0
- data/lib/active_merchant/billing.rb +9 -0
- data/lib/active_merchant/billing/avs_result.rb +98 -0
- data/lib/active_merchant/billing/base.rb +57 -0
- data/lib/active_merchant/billing/check.rb +68 -0
- data/lib/active_merchant/billing/credit_card.rb +161 -0
- data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
- data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
- data/lib/active_merchant/billing/cvv_result.rb +38 -0
- data/lib/active_merchant/billing/expiry_date.rb +34 -0
- data/lib/active_merchant/billing/gateway.rb +169 -0
- data/lib/active_merchant/billing/gateways.rb +18 -0
- data/lib/active_merchant/billing/gateways/authorize_net.rb +654 -0
- data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +736 -0
- data/lib/active_merchant/billing/gateways/beanstream.rb +102 -0
- data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +244 -0
- data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
- data/lib/active_merchant/billing/gateways/bogus.rb +102 -0
- data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
- data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
- data/lib/active_merchant/billing/gateways/braintree_blue.rb +210 -0
- data/lib/active_merchant/billing/gateways/braintree_orange.rb +17 -0
- data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
- data/lib/active_merchant/billing/gateways/cyber_source.rb +406 -0
- data/lib/active_merchant/billing/gateways/data_cash.rb +593 -0
- data/lib/active_merchant/billing/gateways/efsnet.rb +229 -0
- data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
- data/lib/active_merchant/billing/gateways/eway.rb +277 -0
- data/lib/active_merchant/billing/gateways/exact.rb +222 -0
- data/lib/active_merchant/billing/gateways/first_pay.rb +172 -0
- data/lib/active_merchant/billing/gateways/garanti.rb +222 -0
- data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
- data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
- data/lib/active_merchant/billing/gateways/iridium.rb +253 -0
- data/lib/active_merchant/billing/gateways/jetpay.rb +270 -0
- data/lib/active_merchant/billing/gateways/linkpoint.rb +449 -0
- data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +154 -0
- data/lib/active_merchant/billing/gateways/merchant_ware.rb +283 -0
- data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
- data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
- data/lib/active_merchant/billing/gateways/moneris.rb +205 -0
- data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
- data/lib/active_merchant/billing/gateways/netaxept.rb +234 -0
- data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
- data/lib/active_merchant/billing/gateways/ogone.rb +279 -0
- data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
- data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
- data/lib/active_merchant/billing/gateways/paybox_direct.rb +203 -0
- data/lib/active_merchant/billing/gateways/payflow.rb +236 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
- data/lib/active_merchant/billing/gateways/payflow_express.rb +138 -0
- data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
- data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
- data/lib/active_merchant/billing/gateways/payment_express.rb +230 -0
- data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +326 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +38 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_payment_details_response.rb +70 -0
- data/lib/active_merchant/billing/gateways/paypal_adaptive_payments.rb +298 -0
- data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
- data/lib/active_merchant/billing/gateways/paypal_express.rb +145 -0
- data/lib/active_merchant/billing/gateways/paypal_express_common.rb +20 -0
- data/lib/active_merchant/billing/gateways/paypal_express_recurring.rb +310 -0
- data/lib/active_merchant/billing/gateways/plugnpay.rb +292 -0
- data/lib/active_merchant/billing/gateways/psigate.rb +214 -0
- data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
- data/lib/active_merchant/billing/gateways/quickpay.rb +213 -0
- data/lib/active_merchant/billing/gateways/realex.rb +200 -0
- data/lib/active_merchant/billing/gateways/sage.rb +146 -0
- data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
- data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
- data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
- data/lib/active_merchant/billing/gateways/sage_pay.rb +315 -0
- data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
- data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
- data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
- data/lib/active_merchant/billing/gateways/secure_pay_au.rb +157 -0
- data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
- data/lib/active_merchant/billing/gateways/skip_jack.rb +453 -0
- data/lib/active_merchant/billing/gateways/smart_ps.rb +265 -0
- data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
- data/lib/active_merchant/billing/gateways/transax.rb +25 -0
- data/lib/active_merchant/billing/gateways/trust_commerce.rb +418 -0
- data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
- data/lib/active_merchant/billing/gateways/verifi.rb +228 -0
- data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
- data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
- data/lib/active_merchant/billing/integrations.rb +17 -0
- data/lib/active_merchant/billing/integrations/action_view_helper.rb +68 -0
- data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
- data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
- data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
- data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
- data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
- data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
- data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
- data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +188 -0
- data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
- data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
- data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
- data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
- data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
- data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
- data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
- data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/helper.rb +96 -0
- data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
- data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
- data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
- data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
- data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
- data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
- data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
- data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/notification.rb +62 -0
- data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
- data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
- data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
- data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/quickpay.rb +17 -0
- data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
- data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
- data/lib/active_merchant/billing/integrations/return.rb +37 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +109 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +204 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +27 -0
- data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
- data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
- data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
- data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
- data/lib/active_merchant/billing/response.rb +32 -0
- data/lib/active_merchant/common.rb +14 -0
- data/lib/active_merchant/common/connection.rb +172 -0
- data/lib/active_merchant/common/country.rb +328 -0
- data/lib/active_merchant/common/error.rb +26 -0
- data/lib/active_merchant/common/post_data.rb +24 -0
- data/lib/active_merchant/common/posts_data.rb +47 -0
- data/lib/active_merchant/common/requires_parameters.rb +16 -0
- data/lib/active_merchant/common/utils.rb +18 -0
- data/lib/active_merchant/common/validateable.rb +76 -0
- data/lib/active_merchant/version.rb +3 -0
- data/lib/certs/cacert.pem +7815 -0
- data/lib/maedana-activemerchant.rb +1 -0
- data/lib/support/gateway_support.rb +58 -0
- data/lib/support/outbound_hosts.rb +25 -0
- metadata +270 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/braintree/braintree_common'
|
2
|
+
|
3
|
+
module ActiveMerchant #:nodoc:
|
4
|
+
module Billing #:nodoc:
|
5
|
+
class BraintreeGateway < Gateway
|
6
|
+
include BraintreeCommon
|
7
|
+
|
8
|
+
def self.new(options={})
|
9
|
+
if options.has_key?(:login)
|
10
|
+
BraintreeOrangeGateway.new(options)
|
11
|
+
else
|
12
|
+
BraintreeBlueGateway.new(options)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module BraintreeCommon
|
2
|
+
def self.included(base)
|
3
|
+
base.supported_countries = ['US']
|
4
|
+
base.supported_cardtypes = [:visa, :master, :american_express, :discover, :jcb]
|
5
|
+
base.homepage_url = 'http://www.braintreepaymentsolutions.com'
|
6
|
+
base.display_name = 'Braintree'
|
7
|
+
base.default_currency = 'USD'
|
8
|
+
end
|
9
|
+
end
|
@@ -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 if Braintree::Configuration.logger
|
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
|
+
|