n8_activemerchant 1.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +574 -0
- data/CONTRIBUTORS +175 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +151 -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/epay.rb +263 -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_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/paysimple/paysimple.rb +333 -0
- data/lib/active_merchant/billing/gateways/paysimple/usaepay.wsdl +1596 -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/usa_epay_soap.rb +154 -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 +162 -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 +61 -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/activemerchant.rb +1 -0
- data/lib/certs/cacert.pem +7815 -0
- data/lib/support/gateway_support.rb +58 -0
- data/lib/support/outbound_hosts.rb +25 -0
- metadata +270 -0
@@ -0,0 +1,164 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
class InstapayGateway < Gateway
|
4
|
+
GATEWAY_URL = 'https://trans.instapaygateway.com/cgi-bin/process.cgi'
|
5
|
+
|
6
|
+
# The countries the gateway supports merchants from as 2 digit ISO country codes
|
7
|
+
self.supported_countries = ['US']
|
8
|
+
self.money_format = :dollars
|
9
|
+
self.default_currency = 'USD'
|
10
|
+
# The card types supported by the payment gateway
|
11
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :discover]
|
12
|
+
|
13
|
+
# The homepage URL of the gateway
|
14
|
+
self.homepage_url = 'http://www.instapayllc.com'
|
15
|
+
|
16
|
+
# The name of the gateway
|
17
|
+
self.display_name = 'InstaPay'
|
18
|
+
|
19
|
+
SUCCESS = "Accepted"
|
20
|
+
SUCCESS_MESSAGE = "The transaction has been approved"
|
21
|
+
|
22
|
+
def initialize(options = {})
|
23
|
+
requires!(options, :login)
|
24
|
+
@options = options
|
25
|
+
super
|
26
|
+
end
|
27
|
+
|
28
|
+
def authorize(money, creditcard, options = {})
|
29
|
+
post = {}
|
30
|
+
post[:authonly] = 1
|
31
|
+
add_amount(post, money)
|
32
|
+
add_invoice(post, options)
|
33
|
+
add_creditcard(post, creditcard)
|
34
|
+
add_address(post, options)
|
35
|
+
add_customer_data(post, options)
|
36
|
+
|
37
|
+
commit('ns_quicksale_cc', post)
|
38
|
+
end
|
39
|
+
|
40
|
+
def purchase(money, creditcard, options = {})
|
41
|
+
post = {}
|
42
|
+
add_amount(post, money)
|
43
|
+
add_invoice(post, options)
|
44
|
+
add_creditcard(post, creditcard)
|
45
|
+
add_address(post, options)
|
46
|
+
add_customer_data(post, options)
|
47
|
+
|
48
|
+
commit('ns_quicksale_cc', post)
|
49
|
+
end
|
50
|
+
|
51
|
+
def capture(money, authorization, options = {})
|
52
|
+
post = {}
|
53
|
+
add_amount(post, money)
|
54
|
+
add_reference(post, authorization)
|
55
|
+
commit('ns_quicksale_cc', post)
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def add_amount(post, money)
|
61
|
+
post[:amount] = amount(money)
|
62
|
+
end
|
63
|
+
|
64
|
+
def add_reference(post, reference)
|
65
|
+
post[:postonly] = reference
|
66
|
+
end
|
67
|
+
|
68
|
+
def add_customer_data(post, options)
|
69
|
+
post[:ci_email] = options[:email]
|
70
|
+
post["ci_IP Address"] = options[:ip]
|
71
|
+
end
|
72
|
+
|
73
|
+
def add_address(post, options)
|
74
|
+
if address = options[:billing_address] || options[:address]
|
75
|
+
post[:ci_billaddr1] = address[:address1]
|
76
|
+
post[:ci_billaddr2] = address[:address2]
|
77
|
+
post[:ci_billcity] = address[:city]
|
78
|
+
post[:ci_billstate] = address[:state]
|
79
|
+
post[:ci_billzip] = address[:zip]
|
80
|
+
post[:ci_billcountry] = address[:country]
|
81
|
+
post[:ci_phone] = address[:phone]
|
82
|
+
end
|
83
|
+
|
84
|
+
if address = options[:shipping_address]
|
85
|
+
post[:ci_shipaddr1] = address[:address1]
|
86
|
+
post[:ci_shipaddr2] = address[:address2]
|
87
|
+
post[:ci_shipcity] = address[:city]
|
88
|
+
post[:ci_shipstate] = address[:state]
|
89
|
+
post[:ci_shipzip] = address[:zip]
|
90
|
+
post[:ci_shipcountry] = address[:country]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def add_invoice(post, options)
|
95
|
+
post[:merchantordernumber] = options[:order_id]
|
96
|
+
post[:ci_memo] = options[:description]
|
97
|
+
post[:pocustomerrefid] = options[:invoice]
|
98
|
+
end
|
99
|
+
|
100
|
+
def add_creditcard(post, creditcard)
|
101
|
+
post[:ccnum] = creditcard.number
|
102
|
+
post[:expmon] = format(creditcard.month, :two_digits)
|
103
|
+
post[:cvv2] = creditcard.verification_value if creditcard.verification_value?
|
104
|
+
post[:expyear] = creditcard.year
|
105
|
+
post[:ccname] = creditcard.name
|
106
|
+
end
|
107
|
+
|
108
|
+
def parse(body)
|
109
|
+
results = {}
|
110
|
+
fields = body.split("\r\n")
|
111
|
+
|
112
|
+
response = fields[1].split('=')
|
113
|
+
response_data = response[1].split(':')
|
114
|
+
|
115
|
+
if response[0] == SUCCESS
|
116
|
+
results[:success] = true
|
117
|
+
results[:message] = SUCCESS_MESSAGE
|
118
|
+
results[:transaction_type] = response_data[0]
|
119
|
+
results[:authorization_code] = response_data[1]
|
120
|
+
results[:reference_number] = response_data[2]
|
121
|
+
results[:batch_number] = response_data[3]
|
122
|
+
results[:transaction_id] = response_data[4]
|
123
|
+
results[:avs_result] = response_data[5]
|
124
|
+
results[:authorize_net] = response_data[6]
|
125
|
+
results[:cvv_result] = response_data[7]
|
126
|
+
else
|
127
|
+
results[:success] = false
|
128
|
+
results[:result] = response_data[0]
|
129
|
+
results[:response_code] = response_data[1]
|
130
|
+
results[:message] = response_data[2]
|
131
|
+
end
|
132
|
+
|
133
|
+
fields[1..-1].each do |pair|
|
134
|
+
key, value = pair.split('=')
|
135
|
+
results[key] = value
|
136
|
+
end
|
137
|
+
results
|
138
|
+
end
|
139
|
+
|
140
|
+
def commit(action, parameters)
|
141
|
+
data = ssl_post GATEWAY_URL , post_data(action, parameters)
|
142
|
+
response = parse(data)
|
143
|
+
|
144
|
+
Response.new(response[:success] , response[:message], response,
|
145
|
+
:authorization => response[:transaction_id],
|
146
|
+
:avs_result => { :code => response[:avs_result] },
|
147
|
+
:cvv_result => response[:cvv_result]
|
148
|
+
)
|
149
|
+
end
|
150
|
+
|
151
|
+
def post_data(action, parameters = {})
|
152
|
+
post = {}
|
153
|
+
post[:acctid] = @options[:login]
|
154
|
+
if(@options[:password])
|
155
|
+
post[:merchantpin] = @options[:password]
|
156
|
+
end
|
157
|
+
post[:action] = action
|
158
|
+
request = post.merge(parameters).collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
|
159
|
+
request
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
@@ -0,0 +1,253 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
# For more information on the Iridium Gateway please download the
|
4
|
+
# documentation from their Merchant Management System.
|
5
|
+
#
|
6
|
+
# The login and password are not the username and password you use to
|
7
|
+
# login to the Iridium Merchant Management System. Instead, you will
|
8
|
+
# use the API username and password you were issued separately.
|
9
|
+
class IridiumGateway < Gateway
|
10
|
+
TEST_URL = 'https://gw1.iridiumcorp.net/'
|
11
|
+
LIVE_URL = 'https://gw1.iridiumcorp.net/'
|
12
|
+
|
13
|
+
# The countries the gateway supports merchants from as 2 digit ISO country codes
|
14
|
+
self.supported_countries = ['GB', 'ES']
|
15
|
+
self.default_currency = 'EUR'
|
16
|
+
self.money_format = :cents
|
17
|
+
|
18
|
+
# The card types supported by the payment gateway
|
19
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :discover]
|
20
|
+
|
21
|
+
# The homepage URL of the gateway
|
22
|
+
self.homepage_url = 'http://www.iridiumcorp.co.uk/'
|
23
|
+
|
24
|
+
# The name of the gateway
|
25
|
+
self.display_name = 'Iridium'
|
26
|
+
|
27
|
+
CURRENCY_CODES = {
|
28
|
+
"AUD" => '036',
|
29
|
+
"CAD" => '124',
|
30
|
+
"EUR" => '978',
|
31
|
+
"GBP" => '826',
|
32
|
+
"MXN" => '484',
|
33
|
+
"NZD" => '554',
|
34
|
+
"USD" => '840',
|
35
|
+
}
|
36
|
+
|
37
|
+
def initialize(options = {})
|
38
|
+
requires!(options, :login, :password)
|
39
|
+
@options = options
|
40
|
+
super
|
41
|
+
end
|
42
|
+
|
43
|
+
def authorize(money, creditcard, options = {})
|
44
|
+
commit(build_purchase_request('PREAUTH', money, creditcard, options), options)
|
45
|
+
end
|
46
|
+
|
47
|
+
def purchase(money, payment_source, options = {})
|
48
|
+
setup_address_hash(options)
|
49
|
+
|
50
|
+
if payment_source.is_a?(CreditCard)
|
51
|
+
commit(build_purchase_request('SALE', money, payment_source, options), options)
|
52
|
+
else
|
53
|
+
commit(build_reference_request('SALE', money, payment_source, options), options)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def capture(money, authorization, options = {})
|
58
|
+
commit(build_reference_request('COLLECTION', money, authorization, options), options)
|
59
|
+
end
|
60
|
+
|
61
|
+
def credit(money, authorization, options={})
|
62
|
+
commit(build_reference_request('REFUND', money, authorization, options), options)
|
63
|
+
end
|
64
|
+
|
65
|
+
def void(authorization, options={})
|
66
|
+
commit(build_reference_request('VOID', nil, authorization, options), options)
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def build_purchase_request(type, money, creditcard, options)
|
72
|
+
options.merge!(:action => 'CardDetailsTransaction')
|
73
|
+
build_request(options) do |xml|
|
74
|
+
add_purchase_data(xml, type, money, options)
|
75
|
+
add_creditcard(xml, creditcard)
|
76
|
+
add_customerdetails(xml, creditcard, options[:billing_address], options)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def build_reference_request(type, money, authorization, options)
|
81
|
+
options.merge!(:action => 'CrossReferenceTransaction')
|
82
|
+
order_id, cross_reference, auth_id = authorization.split(";")
|
83
|
+
build_request(options) do |xml|
|
84
|
+
if money
|
85
|
+
details = {'CurrencyCode' => currency_code(options[:currency] || default_currency), 'Amount' => amount(money)}
|
86
|
+
else
|
87
|
+
details = {'CurrencyCode' => currency_code(default_currency), 'Amount' => '0'}
|
88
|
+
end
|
89
|
+
xml.tag! 'TransactionDetails', details do
|
90
|
+
xml.tag! 'MessageDetails', {'TransactionType' => type, 'CrossReference' => cross_reference}
|
91
|
+
xml.tag! 'OrderID', (options[:order_id] || order_id)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def build_request(options)
|
97
|
+
requires!(options, :action)
|
98
|
+
xml = Builder::XmlMarkup.new :indent => 2
|
99
|
+
xml.instruct!(:xml, :version => '1.0', :encoding => 'utf-8')
|
100
|
+
xml.tag! 'soap:Envelope', { 'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/',
|
101
|
+
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
|
102
|
+
'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema'} do
|
103
|
+
xml.tag! 'soap:Body' do
|
104
|
+
xml.tag! options[:action], {'xmlns' => "https://www.thepaymentgateway.net/"} do
|
105
|
+
xml.tag! 'PaymentMessage' do
|
106
|
+
add_merchant_data(xml, options)
|
107
|
+
yield(xml)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
xml.target!
|
113
|
+
end
|
114
|
+
|
115
|
+
def setup_address_hash(options)
|
116
|
+
options[:billing_address] = options[:billing_address] || options[:address] || {}
|
117
|
+
options[:shipping_address] = options[:shipping_address] || {}
|
118
|
+
end
|
119
|
+
|
120
|
+
def add_purchase_data(xml, type, money, options)
|
121
|
+
requires!(options, :order_id)
|
122
|
+
xml.tag! 'TransactionDetails', {'Amount' => amount(money), 'CurrencyCode' => currency_code(options[:currency] || currency(money))} do
|
123
|
+
xml.tag! 'MessageDetails', {'TransactionType' => type}
|
124
|
+
xml.tag! 'OrderID', options[:order_id]
|
125
|
+
xml.tag! 'TransactionControl' do
|
126
|
+
xml.tag! 'ThreeDSecureOverridePolicy', 'FALSE'
|
127
|
+
xml.tag! 'EchoAVSCheckResult', 'TRUE'
|
128
|
+
xml.tag! 'EchoCV2CheckResult', 'TRUE'
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def add_customerdetails(xml, creditcard, address, options, shipTo = false)
|
134
|
+
xml.tag! 'CustomerDetails' do
|
135
|
+
if address
|
136
|
+
unless address[:country].blank?
|
137
|
+
country_code = Country.find(address[:country]).code(:numeric)
|
138
|
+
end
|
139
|
+
xml.tag! 'BillingAddress' do
|
140
|
+
xml.tag! 'Address1', address[:address1]
|
141
|
+
xml.tag! 'Address2', address[:address2]
|
142
|
+
xml.tag! 'City', address[:city]
|
143
|
+
xml.tag! 'State', address[:state]
|
144
|
+
xml.tag! 'PostCode', address[:zip]
|
145
|
+
xml.tag! 'CountryCode', country_code if country_code
|
146
|
+
end
|
147
|
+
xml.tag! 'PhoneNumber', address[:phone]
|
148
|
+
end
|
149
|
+
|
150
|
+
xml.tag! 'EmailAddress', options[:email]
|
151
|
+
xml.tag! 'CustomerIPAddress', options[:ip] || "127.0.0.1"
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def add_creditcard(xml, creditcard)
|
156
|
+
xml.tag! 'CardDetails' do
|
157
|
+
xml.tag! 'CardName', creditcard.name
|
158
|
+
xml.tag! 'CV2', creditcard.verification_value if creditcard.verification_value
|
159
|
+
xml.tag! 'CardNumber', creditcard.number
|
160
|
+
xml.tag! 'ExpiryDate', { 'Month' => creditcard.month.to_s.rjust(2, "0"), 'Year' => creditcard.year.to_s[/\d\d$/] }
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def add_merchant_data(xml, options)
|
165
|
+
xml.tag! 'MerchantAuthentication', {"MerchantID" => @options[:login], "Password" => @options[:password]}
|
166
|
+
end
|
167
|
+
|
168
|
+
def commit(request, options)
|
169
|
+
requires!(options, :action)
|
170
|
+
response = parse(ssl_post(test? ? TEST_URL : LIVE_URL, request,
|
171
|
+
{"SOAPAction" => "https://www.thepaymentgateway.net/#{options[:action]}",
|
172
|
+
"Content-Type" => "text/xml; charset=utf-8" }))
|
173
|
+
|
174
|
+
success = response[:transaction_result][:status_code] == "0"
|
175
|
+
message = response[:transaction_result][:message]
|
176
|
+
authorization = success ? [ options[:order_id], response[:transaction_output_data][:cross_reference], response[:transaction_output_data][:auth_code] ].compact.join(";") : nil
|
177
|
+
|
178
|
+
Response.new(success, message, response,
|
179
|
+
:test => test?,
|
180
|
+
:authorization => authorization)
|
181
|
+
end
|
182
|
+
|
183
|
+
def parse(xml)
|
184
|
+
reply = {}
|
185
|
+
xml = REXML::Document.new(xml)
|
186
|
+
if (root = REXML::XPath.first(xml, "//CardDetailsTransactionResponse")) or
|
187
|
+
(root = REXML::XPath.first(xml, "//CrossReferenceTransactionResponse"))
|
188
|
+
root.elements.to_a.each do |node|
|
189
|
+
case node.name
|
190
|
+
when 'Message'
|
191
|
+
reply[:message] = reply(node.text)
|
192
|
+
else
|
193
|
+
parse_element(reply, node)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
elsif root = REXML::XPath.first(xml, "//soap:Fault")
|
197
|
+
parse_element(reply, root)
|
198
|
+
reply[:message] = "#{reply[:faultcode]}: #{reply[:faultstring]}"
|
199
|
+
end
|
200
|
+
reply
|
201
|
+
end
|
202
|
+
|
203
|
+
def parse_element(reply, node)
|
204
|
+
case node.name
|
205
|
+
when "CrossReferenceTransactionResult"
|
206
|
+
reply[:transaction_result] = {}
|
207
|
+
node.attributes.each do |a,b|
|
208
|
+
reply[:transaction_result][a.underscore.to_sym] = b
|
209
|
+
end
|
210
|
+
node.elements.each{|e| parse_element(reply[:transaction_result], e) } if node.has_elements?
|
211
|
+
|
212
|
+
when "CardDetailsTransactionResult"
|
213
|
+
reply[:transaction_result] = {}
|
214
|
+
node.attributes.each do |a,b|
|
215
|
+
reply[:transaction_result][a.underscore.to_sym] = b
|
216
|
+
end
|
217
|
+
node.elements.each{|e| parse_element(reply[:transaction_result], e) } if node.has_elements?
|
218
|
+
|
219
|
+
when "TransactionOutputData"
|
220
|
+
reply[:transaction_output_data] = {}
|
221
|
+
node.attributes.each{|a,b| reply[:transaction_output_data][a.underscore.to_sym] = b }
|
222
|
+
node.elements.each{|e| parse_element(reply[:transaction_output_data], e) } if node.has_elements?
|
223
|
+
when "CustomVariables"
|
224
|
+
reply[:custom_variables] = {}
|
225
|
+
node.attributes.each{|a,b| reply[:custom_variables][a.underscore.to_sym] = b }
|
226
|
+
node.elements.each{|e| parse_element(reply[:custom_variables], e) } if node.has_elements?
|
227
|
+
when "GatewayEntryPoints"
|
228
|
+
reply[:gateway_entry_points] = {}
|
229
|
+
node.attributes.each{|a,b| reply[:gateway_entry_points][a.underscore.to_sym] = b }
|
230
|
+
node.elements.each{|e| parse_element(reply[:gateway_entry_points], e) } if node.has_elements?
|
231
|
+
else
|
232
|
+
k = node.name.underscore.to_sym
|
233
|
+
if node.has_elements?
|
234
|
+
reply[k] = {}
|
235
|
+
node.elements.each{|e| parse_element(reply[k], e) }
|
236
|
+
else
|
237
|
+
if node.has_attributes?
|
238
|
+
reply[k] = {}
|
239
|
+
node.attributes.each{|a,b| reply[k][a.underscore.to_sym] = b }
|
240
|
+
else
|
241
|
+
reply[k] = node.text
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
reply
|
246
|
+
end
|
247
|
+
|
248
|
+
def currency_code(currency)
|
249
|
+
CURRENCY_CODES[currency]
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
@@ -0,0 +1,270 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
class JetpayGateway < Gateway
|
4
|
+
TEST_URL = 'https://test1.jetpay.com/jetpay'
|
5
|
+
LIVE_URL = 'https://gateway17.jetpay.com/jetpay'
|
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]
|
12
|
+
|
13
|
+
# The homepage URL of the gateway
|
14
|
+
self.homepage_url = 'http://www.jetpay.com/'
|
15
|
+
|
16
|
+
# The name of the gateway
|
17
|
+
self.display_name = 'JetPay'
|
18
|
+
|
19
|
+
# all transactions are in cents
|
20
|
+
self.money_format = :cents
|
21
|
+
|
22
|
+
ACTION_CODE_MESSAGES = {
|
23
|
+
"001" => "Refer to card issuer.",
|
24
|
+
"002" => "Refer to card issuer, special condition.",
|
25
|
+
"003" => "Pick up card.",
|
26
|
+
"200" => "Deny - Pick up card.",
|
27
|
+
"005" => "Do not honor.",
|
28
|
+
"100" => "Deny.",
|
29
|
+
"006" => "Error.",
|
30
|
+
"181" => "Format error.",
|
31
|
+
"007" => "Pickup card, special condition.",
|
32
|
+
"104" => "Deny - New card issued.",
|
33
|
+
"110" => "Invalid amount.",
|
34
|
+
"014" => "Invalid account number (no such number).",
|
35
|
+
"111" => "Invalid account.",
|
36
|
+
"015" => "No such issuer.",
|
37
|
+
"103" => "Deny - Invalid manual Entry 4DBC.",
|
38
|
+
"182" => "Please wait.",
|
39
|
+
"109" => "Invalid merchant.",
|
40
|
+
"041" => "Pick up card (lost card).",
|
41
|
+
"043" => "Pick up card (stolen card).",
|
42
|
+
"051" => "Insufficient funds.",
|
43
|
+
"052" => "No checking account.",
|
44
|
+
"105" => "Deny - Account Cancelled.",
|
45
|
+
"054" => "Expired Card.",
|
46
|
+
"101" => "Expired Card.",
|
47
|
+
"183" => "Invalid currency code.",
|
48
|
+
"057" => "Transaction not permitted to cardholder.",
|
49
|
+
"115" => "Service not permitted.",
|
50
|
+
"062" => "Restricted card.",
|
51
|
+
"189" => "Deny - Cancelled or Closed Merchant/SE.",
|
52
|
+
"188" => "Deny - Expiration date required.",
|
53
|
+
"125" => "Invalid effective date.",
|
54
|
+
"122" => "Invalid card (CID) security code.",
|
55
|
+
"400" => "Reversal accepted.",
|
56
|
+
"992" => "DECLINE/TIMEOUT.",
|
57
|
+
"107" => "Please Call Issuer.",
|
58
|
+
"025" => "Transaction Not Found.",
|
59
|
+
"981" => "AVS Error.",
|
60
|
+
"913" => "Invalid Card Type.",
|
61
|
+
"996" => "Terminal ID Not Found."
|
62
|
+
}
|
63
|
+
|
64
|
+
def initialize(options = {})
|
65
|
+
requires!(options, :login)
|
66
|
+
@options = options
|
67
|
+
super
|
68
|
+
end
|
69
|
+
|
70
|
+
def purchase(money, credit_card, options = {})
|
71
|
+
commit(money, build_sale_request(money, credit_card, options))
|
72
|
+
end
|
73
|
+
|
74
|
+
def authorize(money, credit_card, options = {})
|
75
|
+
commit(money, build_authonly_request(money, credit_card, options))
|
76
|
+
end
|
77
|
+
|
78
|
+
def capture(money, reference, options = {})
|
79
|
+
commit(money, build_capture_request('CAPT', reference.split(";").first))
|
80
|
+
end
|
81
|
+
|
82
|
+
def void(reference, options = {})
|
83
|
+
transaction_id, approval, amount = reference.split(";")
|
84
|
+
commit(amount.to_i, build_void_request(amount.to_i, transaction_id, approval))
|
85
|
+
end
|
86
|
+
|
87
|
+
def credit(money, transaction_id_or_card, options = {})
|
88
|
+
|
89
|
+
if transaction_id_or_card.is_a?(String)
|
90
|
+
transaction_id = transaction_id_or_card.split(";").first
|
91
|
+
credit_card = options[:credit_card]
|
92
|
+
else
|
93
|
+
transaction_id = nil
|
94
|
+
credit_card = transaction_id_or_card
|
95
|
+
end
|
96
|
+
|
97
|
+
commit(money, build_credit_request('CREDIT', money, transaction_id, credit_card))
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
def build_xml_request(transaction_type, transaction_id = nil, &block)
|
103
|
+
xml = Builder::XmlMarkup.new
|
104
|
+
xml.tag! 'JetPay' do
|
105
|
+
# The basic values needed for any request
|
106
|
+
xml.tag! 'TerminalID', @options[:login]
|
107
|
+
xml.tag! 'TransactionType', transaction_type
|
108
|
+
xml.tag! 'TransactionID', transaction_id.nil? ? generate_unique_id.slice(0, 18) : transaction_id
|
109
|
+
|
110
|
+
if block_given?
|
111
|
+
yield xml
|
112
|
+
else
|
113
|
+
xml.target!
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def build_sale_request(money, credit_card, options)
|
119
|
+
build_xml_request('SALE') do |xml|
|
120
|
+
add_credit_card(xml, credit_card)
|
121
|
+
add_addresses(xml, options)
|
122
|
+
add_customer_data(xml, options)
|
123
|
+
add_invoice_data(xml, options)
|
124
|
+
xml.tag! 'TotalAmount', amount(money)
|
125
|
+
|
126
|
+
xml.target!
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def build_authonly_request(money, credit_card, options)
|
131
|
+
build_xml_request('AUTHONLY') do |xml|
|
132
|
+
add_credit_card(xml, credit_card)
|
133
|
+
add_addresses(xml, options)
|
134
|
+
add_customer_data(xml, options)
|
135
|
+
add_invoice_data(xml, options)
|
136
|
+
xml.tag! 'TotalAmount', amount(money)
|
137
|
+
|
138
|
+
xml.target!
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def build_capture_request(transaction_type, transaction_id)
|
143
|
+
build_xml_request(transaction_type, transaction_id)
|
144
|
+
end
|
145
|
+
|
146
|
+
def build_void_request(money, transaction_id, approval)
|
147
|
+
build_xml_request('VOID', transaction_id) do |xml|
|
148
|
+
xml.tag! 'Approval', approval
|
149
|
+
xml.tag! 'TotalAmount', amount(money)
|
150
|
+
|
151
|
+
xml.target!
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
# `transaction_id` may be nil for unlinked credit transactions.
|
156
|
+
def build_credit_request(transaction_type, money, transaction_id, card)
|
157
|
+
build_xml_request(transaction_type, transaction_id) do |xml|
|
158
|
+
add_credit_card(xml, card) if card
|
159
|
+
xml.tag! 'TotalAmount', amount(money)
|
160
|
+
|
161
|
+
xml.target!
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def commit(money, request)
|
166
|
+
response = parse(ssl_post(test? ? TEST_URL : LIVE_URL, request))
|
167
|
+
|
168
|
+
success = success?(response)
|
169
|
+
Response.new(success,
|
170
|
+
success ? 'APPROVED' : message_from(response),
|
171
|
+
response,
|
172
|
+
:test => test?,
|
173
|
+
:authorization => authorization_from(response, money),
|
174
|
+
:avs_result => { :code => response[:avs] },
|
175
|
+
:cvv_result => response[:cvv2]
|
176
|
+
)
|
177
|
+
end
|
178
|
+
|
179
|
+
def parse(body)
|
180
|
+
xml = REXML::Document.new(body)
|
181
|
+
|
182
|
+
response = {}
|
183
|
+
xml.root.elements.to_a.each do |node|
|
184
|
+
parse_element(response, node)
|
185
|
+
end
|
186
|
+
response
|
187
|
+
end
|
188
|
+
|
189
|
+
def parse_element(response, node)
|
190
|
+
if node.has_elements?
|
191
|
+
node.elements.each{|element| parse_element(response, element) }
|
192
|
+
else
|
193
|
+
response[node.name.underscore.to_sym] = node.text
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
def format_exp(value)
|
198
|
+
format(value, :two_digits)
|
199
|
+
end
|
200
|
+
|
201
|
+
def success?(response)
|
202
|
+
response[:action_code] == "000"
|
203
|
+
end
|
204
|
+
|
205
|
+
def message_from(response)
|
206
|
+
ACTION_CODE_MESSAGES[response[:action_code]]
|
207
|
+
end
|
208
|
+
|
209
|
+
def authorization_from(response, money)
|
210
|
+
original_amount = amount(money) if money
|
211
|
+
[ response[:transaction_id], response[:approval], original_amount ].join(";")
|
212
|
+
end
|
213
|
+
|
214
|
+
def add_credit_card(xml, credit_card)
|
215
|
+
xml.tag! 'CardNum', credit_card.number
|
216
|
+
xml.tag! 'CardExpMonth', format_exp(credit_card.month)
|
217
|
+
xml.tag! 'CardExpYear', format_exp(credit_card.year)
|
218
|
+
|
219
|
+
if credit_card.first_name || credit_card.last_name
|
220
|
+
xml.tag! 'CardName', [credit_card.first_name,credit_card.last_name].compact.join(' ')
|
221
|
+
end
|
222
|
+
|
223
|
+
unless credit_card.verification_value.nil? || (credit_card.verification_value.length == 0)
|
224
|
+
xml.tag! 'CVV2', credit_card.verification_value
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def add_addresses(xml, options)
|
229
|
+
if billing_address = options[:billing_address] || options[:address]
|
230
|
+
xml.tag! 'BillingAddress', [billing_address[:address1], billing_address[:address2]].compact.join(" ")
|
231
|
+
xml.tag! 'BillingCity', billing_address[:city]
|
232
|
+
xml.tag! 'BillingStateProv', billing_address[:state]
|
233
|
+
xml.tag! 'BillingPostalCode', billing_address[:zip]
|
234
|
+
xml.tag! 'BillingCountry', lookup_country_code(billing_address[:country])
|
235
|
+
xml.tag! 'BillingPhone', billing_address[:phone]
|
236
|
+
end
|
237
|
+
|
238
|
+
if shipping_address = options[:shipping_address]
|
239
|
+
xml.tag! 'ShippingInfo' do
|
240
|
+
xml.tag! 'ShippingName', shipping_address[:name]
|
241
|
+
|
242
|
+
xml.tag! 'ShippingAddr' do
|
243
|
+
xml.tag! 'Address', [shipping_address[:address1], shipping_address[:address2]].compact.join(" ")
|
244
|
+
xml.tag! 'City', shipping_address[:city]
|
245
|
+
xml.tag! 'StateProv', shipping_address[:state]
|
246
|
+
xml.tag! 'PostalCode', shipping_address[:zip]
|
247
|
+
xml.tag! 'Country', lookup_country_code(shipping_address[:country])
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
def add_customer_data(xml, options)
|
254
|
+
xml.tag! 'Email', options[:email] if options[:email]
|
255
|
+
xml.tag! 'UserIPAddress', options[:ip] if options[:ip]
|
256
|
+
end
|
257
|
+
|
258
|
+
def add_invoice_data(xml, options)
|
259
|
+
xml.tag! 'OrderNumber', options[:order_id] if options[:order_id]
|
260
|
+
xml.tag! 'TaxAmount', amount(options[:tax]) if options[:tax]
|
261
|
+
end
|
262
|
+
|
263
|
+
def lookup_country_code(code)
|
264
|
+
country = Country.find(code) rescue nil
|
265
|
+
country && country.code(:alpha3)
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|