start_activemerchant 1.50.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +1769 -0
- data/CONTRIBUTORS +540 -0
- data/MIT-LICENSE +20 -0
- data/README.md +226 -0
- data/lib/active_merchant.rb +67 -0
- data/lib/active_merchant/billing.rb +15 -0
- data/lib/active_merchant/billing/apple_pay_payment_token.rb +22 -0
- data/lib/active_merchant/billing/avs_result.rb +98 -0
- data/lib/active_merchant/billing/base.rb +72 -0
- data/lib/active_merchant/billing/check.rb +76 -0
- data/lib/active_merchant/billing/compatibility.rb +120 -0
- data/lib/active_merchant/billing/credit_card.rb +404 -0
- data/lib/active_merchant/billing/credit_card_formatting.rb +24 -0
- data/lib/active_merchant/billing/credit_card_methods.rb +195 -0
- data/lib/active_merchant/billing/cvv_result.rb +38 -0
- data/lib/active_merchant/billing/gateway.rb +291 -0
- data/lib/active_merchant/billing/gateways.rb +14 -0
- data/lib/active_merchant/billing/gateways/allied_wallet.rb +203 -0
- data/lib/active_merchant/billing/gateways/app55.rb +176 -0
- data/lib/active_merchant/billing/gateways/authorize_net.rb +510 -0
- data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +417 -0
- data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +976 -0
- data/lib/active_merchant/billing/gateways/axcessms.rb +181 -0
- data/lib/active_merchant/billing/gateways/balanced.rb +256 -0
- data/lib/active_merchant/billing/gateways/bank_frick.rb +225 -0
- data/lib/active_merchant/billing/gateways/banwire.rb +105 -0
- data/lib/active_merchant/billing/gateways/barclays_epdq.rb +314 -0
- data/lib/active_merchant/billing/gateways/barclays_epdq_extra_plus.rb +15 -0
- data/lib/active_merchant/billing/gateways/be2bill.rb +131 -0
- data/lib/active_merchant/billing/gateways/beanstream.rb +192 -0
- data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +389 -0
- data/lib/active_merchant/billing/gateways/beanstream_interac.rb +58 -0
- data/lib/active_merchant/billing/gateways/blue_pay.rb +506 -0
- data/lib/active_merchant/billing/gateways/bogus.rb +140 -0
- data/lib/active_merchant/billing/gateways/borgun.rb +211 -0
- data/lib/active_merchant/billing/gateways/bpoint.rb +277 -0
- data/lib/active_merchant/billing/gateways/braintree.rb +19 -0
- data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
- data/lib/active_merchant/billing/gateways/braintree_blue.rb +574 -0
- data/lib/active_merchant/billing/gateways/braintree_orange.rb +20 -0
- data/lib/active_merchant/billing/gateways/bridge_pay.rb +189 -0
- data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
- data/lib/active_merchant/billing/gateways/card_stream.rb +238 -0
- data/lib/active_merchant/billing/gateways/cashnet.rb +202 -0
- data/lib/active_merchant/billing/gateways/cc5.rb +201 -0
- data/lib/active_merchant/billing/gateways/cecabank.rb +229 -0
- data/lib/active_merchant/billing/gateways/cenpos.rb +262 -0
- data/lib/active_merchant/billing/gateways/certo_direct.rb +278 -0
- data/lib/active_merchant/billing/gateways/checkout.rb +216 -0
- data/lib/active_merchant/billing/gateways/checkout_v2.rb +200 -0
- data/lib/active_merchant/billing/gateways/commercegate.rb +143 -0
- data/lib/active_merchant/billing/gateways/conekta.rb +210 -0
- data/lib/active_merchant/billing/gateways/cyber_source.rb +720 -0
- data/lib/active_merchant/billing/gateways/data_cash.rb +600 -0
- data/lib/active_merchant/billing/gateways/dibs.rb +206 -0
- data/lib/active_merchant/billing/gateways/efsnet.rb +219 -0
- data/lib/active_merchant/billing/gateways/elavon.rb +348 -0
- data/lib/active_merchant/billing/gateways/epay.rb +274 -0
- data/lib/active_merchant/billing/gateways/evo_ca.rb +308 -0
- data/lib/active_merchant/billing/gateways/eway.rb +214 -0
- data/lib/active_merchant/billing/gateways/eway_managed.rb +291 -0
- data/lib/active_merchant/billing/gateways/eway_rapid.rb +522 -0
- data/lib/active_merchant/billing/gateways/exact.rb +227 -0
- data/lib/active_merchant/billing/gateways/ezic.rb +206 -0
- data/lib/active_merchant/billing/gateways/fat_zebra.rb +213 -0
- data/lib/active_merchant/billing/gateways/federated_canada.rb +160 -0
- data/lib/active_merchant/billing/gateways/finansbank.rb +23 -0
- data/lib/active_merchant/billing/gateways/first_giving.rb +143 -0
- data/lib/active_merchant/billing/gateways/first_pay.rb +160 -0
- data/lib/active_merchant/billing/gateways/firstdata_e4.rb +413 -0
- data/lib/active_merchant/billing/gateways/flo2cash.rb +215 -0
- data/lib/active_merchant/billing/gateways/flo2cash_simple.rb +20 -0
- data/lib/active_merchant/billing/gateways/garanti.rb +261 -0
- data/lib/active_merchant/billing/gateways/global_transport.rb +179 -0
- data/lib/active_merchant/billing/gateways/hdfc.rb +207 -0
- data/lib/active_merchant/billing/gateways/hps.rb +287 -0
- data/lib/active_merchant/billing/gateways/iats_payments.rb +277 -0
- data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +246 -0
- data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
- data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
- data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +66 -0
- data/lib/active_merchant/billing/gateways/inspire.rb +219 -0
- data/lib/active_merchant/billing/gateways/instapay.rb +163 -0
- data/lib/active_merchant/billing/gateways/ipp.rb +175 -0
- data/lib/active_merchant/billing/gateways/iridium.rb +457 -0
- data/lib/active_merchant/billing/gateways/itransact.rb +448 -0
- data/lib/active_merchant/billing/gateways/jetpay.rb +275 -0
- data/lib/active_merchant/billing/gateways/linkpoint.rb +438 -0
- data/lib/active_merchant/billing/gateways/litle.rb +345 -0
- data/lib/active_merchant/billing/gateways/maxipago.rb +197 -0
- data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +170 -0
- data/lib/active_merchant/billing/gateways/merchant_one.rb +114 -0
- data/lib/active_merchant/billing/gateways/merchant_partners.rb +245 -0
- data/lib/active_merchant/billing/gateways/merchant_ware.rb +319 -0
- data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +268 -0
- data/lib/active_merchant/billing/gateways/merchant_warrior.rb +195 -0
- data/lib/active_merchant/billing/gateways/mercury.rb +326 -0
- data/lib/active_merchant/billing/gateways/metrics_global.rb +303 -0
- data/lib/active_merchant/billing/gateways/migs.rb +280 -0
- data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
- data/lib/active_merchant/billing/gateways/modern_payments.rb +37 -0
- data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +219 -0
- data/lib/active_merchant/billing/gateways/monei.rb +307 -0
- data/lib/active_merchant/billing/gateways/moneris.rb +309 -0
- data/lib/active_merchant/billing/gateways/moneris_us.rb +298 -0
- data/lib/active_merchant/billing/gateways/money_movers.rb +152 -0
- data/lib/active_merchant/billing/gateways/nab_transact.rb +290 -0
- data/lib/active_merchant/billing/gateways/net_registry.rb +198 -0
- data/lib/active_merchant/billing/gateways/netaxept.rb +181 -0
- data/lib/active_merchant/billing/gateways/netbilling.rb +224 -0
- data/lib/active_merchant/billing/gateways/netpay.rb +223 -0
- data/lib/active_merchant/billing/gateways/network_merchants.rb +242 -0
- data/lib/active_merchant/billing/gateways/nmi.rb +256 -0
- data/lib/active_merchant/billing/gateways/ogone.rb +435 -0
- data/lib/active_merchant/billing/gateways/omise.rb +319 -0
- data/lib/active_merchant/billing/gateways/openpay.rb +194 -0
- data/lib/active_merchant/billing/gateways/optimal_payment.rb +314 -0
- data/lib/active_merchant/billing/gateways/orbital.rb +834 -0
- data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +47 -0
- data/lib/active_merchant/billing/gateways/pac_net_raven.rb +207 -0
- data/lib/active_merchant/billing/gateways/pago_facil.rb +122 -0
- data/lib/active_merchant/billing/gateways/pay_conex.rb +246 -0
- data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +277 -0
- data/lib/active_merchant/billing/gateways/pay_hub.rb +213 -0
- data/lib/active_merchant/billing/gateways/pay_junction.rb +390 -0
- data/lib/active_merchant/billing/gateways/pay_secure.rb +112 -0
- data/lib/active_merchant/billing/gateways/paybox_direct.rb +188 -0
- data/lib/active_merchant/billing/gateways/payex.rb +412 -0
- data/lib/active_merchant/billing/gateways/payflow.rb +308 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +220 -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 +224 -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 +353 -0
- data/lib/active_merchant/billing/gateways/paymill.rb +282 -0
- data/lib/active_merchant/billing/gateways/paypal.rb +129 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +679 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +65 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +262 -0
- data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
- data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +44 -0
- data/lib/active_merchant/billing/gateways/paypal_express.rb +264 -0
- data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
- data/lib/active_merchant/billing/gateways/payscout.rb +162 -0
- data/lib/active_merchant/billing/gateways/paystation.rb +199 -0
- data/lib/active_merchant/billing/gateways/payu_in.rb +247 -0
- data/lib/active_merchant/billing/gateways/payway.rb +207 -0
- data/lib/active_merchant/billing/gateways/pin.rb +207 -0
- data/lib/active_merchant/billing/gateways/plugnpay.rb +283 -0
- data/lib/active_merchant/billing/gateways/psigate.rb +216 -0
- data/lib/active_merchant/billing/gateways/psl_card.rb +303 -0
- data/lib/active_merchant/billing/gateways/qbms.rb +292 -0
- data/lib/active_merchant/billing/gateways/quantum.rb +276 -0
- data/lib/active_merchant/billing/gateways/quickbooks.rb +280 -0
- data/lib/active_merchant/billing/gateways/quickpay.rb +26 -0
- data/lib/active_merchant/billing/gateways/quickpay/quickpay_common.rb +188 -0
- data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +240 -0
- data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +227 -0
- data/lib/active_merchant/billing/gateways/qvalent.rb +179 -0
- data/lib/active_merchant/billing/gateways/realex.rb +298 -0
- data/lib/active_merchant/billing/gateways/redsys.rb +406 -0
- data/lib/active_merchant/billing/gateways/s5.rb +226 -0
- data/lib/active_merchant/billing/gateways/sage.rb +173 -0
- data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +89 -0
- data/lib/active_merchant/billing/gateways/sage/sage_core.rb +115 -0
- data/lib/active_merchant/billing/gateways/sage/sage_vault.rb +149 -0
- data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
- data/lib/active_merchant/billing/gateways/sage_pay.rb +399 -0
- data/lib/active_merchant/billing/gateways/sallie_mae.rb +143 -0
- data/lib/active_merchant/billing/gateways/secure_net.rb +263 -0
- data/lib/active_merchant/billing/gateways/secure_pay.rb +201 -0
- data/lib/active_merchant/billing/gateways/secure_pay_au.rb +281 -0
- data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +105 -0
- data/lib/active_merchant/billing/gateways/skip_jack.rb +451 -0
- data/lib/active_merchant/billing/gateways/smart_ps.rb +283 -0
- data/lib/active_merchant/billing/gateways/so_easy_pay.rb +194 -0
- data/lib/active_merchant/billing/gateways/spreedly_core.rb +247 -0
- data/lib/active_merchant/billing/gateways/stripe.rb +489 -0
- data/lib/active_merchant/billing/gateways/swipe_checkout.rb +157 -0
- data/lib/active_merchant/billing/gateways/tns.rb +227 -0
- data/lib/active_merchant/billing/gateways/trans_first.rb +126 -0
- data/lib/active_merchant/billing/gateways/transax.rb +23 -0
- data/lib/active_merchant/billing/gateways/transnational.rb +10 -0
- data/lib/active_merchant/billing/gateways/trust_commerce.rb +416 -0
- data/lib/active_merchant/billing/gateways/usa_epay.rb +25 -0
- data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1516 -0
- data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +259 -0
- data/lib/active_merchant/billing/gateways/vanco.rb +280 -0
- data/lib/active_merchant/billing/gateways/verifi.rb +225 -0
- data/lib/active_merchant/billing/gateways/viaklix.rb +183 -0
- data/lib/active_merchant/billing/gateways/webpay.rb +97 -0
- data/lib/active_merchant/billing/gateways/wepay.rb +205 -0
- data/lib/active_merchant/billing/gateways/wirecard.rb +420 -0
- data/lib/active_merchant/billing/gateways/worldpay.rb +331 -0
- data/lib/active_merchant/billing/gateways/worldpay_online_payments.rb +204 -0
- data/lib/active_merchant/billing/gateways/worldpay_us.rb +181 -0
- data/lib/active_merchant/billing/model.rb +30 -0
- data/lib/active_merchant/billing/network_tokenization_credit_card.rb +24 -0
- data/lib/active_merchant/billing/payment_token.rb +21 -0
- data/lib/active_merchant/billing/rails.rb +3 -0
- data/lib/active_merchant/billing/response.rb +92 -0
- data/lib/active_merchant/connection.rb +172 -0
- data/lib/active_merchant/country.rb +332 -0
- data/lib/active_merchant/empty.rb +20 -0
- data/lib/active_merchant/errors.rb +35 -0
- data/lib/active_merchant/network_connection_retries.rb +79 -0
- data/lib/active_merchant/post_data.rb +24 -0
- data/lib/active_merchant/posts_data.rb +84 -0
- data/lib/active_merchant/version.rb +3 -0
- data/lib/activemerchant.rb +1 -0
- data/lib/certs/cacert.pem +3866 -0
- data/lib/support/gateway_support.rb +71 -0
- data/lib/support/outbound_hosts.rb +28 -0
- data/lib/support/ssl_verify.rb +93 -0
- metadata +387 -0
@@ -0,0 +1,223 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
#
|
4
|
+
# NETPAY Gateway
|
5
|
+
#
|
6
|
+
# Support for NETPAY's HTTP Connector payment gateway in Mexico.
|
7
|
+
#
|
8
|
+
# The gateway sends requests as HTTP POST and receives the response details
|
9
|
+
# in the HTTP header, making the process really rather simple.
|
10
|
+
#
|
11
|
+
# Support for calls to the authorize and capture methods have been included
|
12
|
+
# as per the Netpay manuals, however, your millage may vary with these
|
13
|
+
# methods. At the time of writing (January 2013) they were not fully
|
14
|
+
# supported by the production or test gateways. This situation is
|
15
|
+
# expected to change within a few weeks/months.
|
16
|
+
#
|
17
|
+
# Purchases can be cancelled (`#void`) only within 24 hours of the
|
18
|
+
# transaction. After this, a refund should be performed instead.
|
19
|
+
#
|
20
|
+
# In addition to the regular ActiveMerchant transaction options, NETPAY
|
21
|
+
# also supports a `:mode` parameter. This allows testing to be performed
|
22
|
+
# in production and force specific results.
|
23
|
+
#
|
24
|
+
# * 'P' - Production
|
25
|
+
# * 'A' - Approved
|
26
|
+
# * 'D' - Declined
|
27
|
+
# * 'R' - Random (Approved or Declined)
|
28
|
+
# * 'T' - Test
|
29
|
+
#
|
30
|
+
# For example:
|
31
|
+
#
|
32
|
+
# response = @gateway.purchase(1000, card, :mode => 'D')
|
33
|
+
# response.success # false
|
34
|
+
#
|
35
|
+
class NetpayGateway < Gateway
|
36
|
+
self.test_url = 'http://200.57.87.243:8855'
|
37
|
+
self.live_url = 'https://suite.netpay.com.mx/acquirerprd'
|
38
|
+
|
39
|
+
# The countries the gateway supports merchants from as 2 digit ISO country codes
|
40
|
+
self.supported_countries = ['MX']
|
41
|
+
|
42
|
+
self.default_currency = 'MXN'
|
43
|
+
|
44
|
+
# The card types supported by the payment gateway
|
45
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :diners_club]
|
46
|
+
|
47
|
+
# The homepage URL of the gateway
|
48
|
+
self.homepage_url = 'http://www.netpay.com.mx'
|
49
|
+
|
50
|
+
# The name of the gateway
|
51
|
+
self.display_name = 'NETPAY Gateway'
|
52
|
+
|
53
|
+
CURRENCY_CODES = {
|
54
|
+
"MXN" => '484'
|
55
|
+
}
|
56
|
+
|
57
|
+
# The header keys that we will provide in the response params hash
|
58
|
+
RESPONSE_KEYS = ['ResponseMsg', 'ResponseText', 'ResponseCode', 'TimeIn', 'TimeOut', 'AuthCode', 'OrderId', 'CardTypeName', 'MerchantId', 'IssuerAuthDate']
|
59
|
+
|
60
|
+
def initialize(options = {})
|
61
|
+
requires!(options, :store_id, :login, :password)
|
62
|
+
super
|
63
|
+
end
|
64
|
+
|
65
|
+
# Send an authorization request
|
66
|
+
def authorize(money, creditcard, options = {})
|
67
|
+
post = {}
|
68
|
+
add_invoice(post, options)
|
69
|
+
add_creditcard(post, creditcard)
|
70
|
+
add_customer_data(post, options)
|
71
|
+
add_amount(post, money, options)
|
72
|
+
|
73
|
+
commit('PreAuth', post, options)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Capture an authorization
|
77
|
+
def capture(money, authorization, options = {})
|
78
|
+
post = {}
|
79
|
+
add_order_id(post, order_id_from(authorization))
|
80
|
+
add_amount(post, money, options)
|
81
|
+
|
82
|
+
commit('PostAuth', post, options)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Cancel an auth/purchase within first 24 hours
|
86
|
+
def void(authorization, options = {})
|
87
|
+
post = {}
|
88
|
+
order_id, amount, currency = split_authorization(authorization)
|
89
|
+
add_order_id(post, order_id)
|
90
|
+
post['Total'] = (options[:amount] || amount)
|
91
|
+
post['CurrencyCode'] = currency
|
92
|
+
|
93
|
+
commit('Refund', post, options)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Make a purchase.
|
97
|
+
def purchase(money, creditcard, options = {})
|
98
|
+
post = {}
|
99
|
+
add_invoice(post, options)
|
100
|
+
add_creditcard(post, creditcard)
|
101
|
+
add_customer_data(post, options)
|
102
|
+
add_amount(post, money, options)
|
103
|
+
|
104
|
+
commit('Auth', post, options)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Perform a Credit transaction.
|
108
|
+
def refund(money, authorization, options = {})
|
109
|
+
post = {}
|
110
|
+
add_order_id(post, order_id_from(authorization))
|
111
|
+
add_amount(post, money, options)
|
112
|
+
|
113
|
+
#commit('Refund', post, options)
|
114
|
+
commit('Credit', post, options)
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
def add_login_data(post)
|
120
|
+
post['StoreId'] = @options[:store_id]
|
121
|
+
post['UserName'] = @options[:login]
|
122
|
+
post['Password'] = @options[:password]
|
123
|
+
end
|
124
|
+
|
125
|
+
def add_action(post, action, options)
|
126
|
+
post['ResourceName'] = action
|
127
|
+
post['ContentType'] = 'Transaction'
|
128
|
+
post['Mode'] = options[:mode] || 'P'
|
129
|
+
end
|
130
|
+
|
131
|
+
def add_order_id(post, order_id)
|
132
|
+
post['OrderId'] = order_id
|
133
|
+
end
|
134
|
+
|
135
|
+
def add_amount(post, money, options)
|
136
|
+
post['Total'] = amount(money)
|
137
|
+
post['CurrencyCode'] = currency_code(options[:currency] || currency(money))
|
138
|
+
end
|
139
|
+
|
140
|
+
def add_customer_data(post, options)
|
141
|
+
post['IPAddress'] = options[:ip] unless options[:ip].blank?
|
142
|
+
end
|
143
|
+
|
144
|
+
def add_invoice(post, options)
|
145
|
+
post['Comments'] = options[:description] if options[:description]
|
146
|
+
end
|
147
|
+
|
148
|
+
def add_creditcard(post, creditcard)
|
149
|
+
post['CardNumber'] = creditcard.number
|
150
|
+
post['ExpDate'] = expdate(creditcard)
|
151
|
+
post['CustomerName'] = creditcard.name
|
152
|
+
post['CVV2'] = creditcard.verification_value unless creditcard.verification_value.nil?
|
153
|
+
end
|
154
|
+
|
155
|
+
def build_authorization(request_params, response_params)
|
156
|
+
[response_params['OrderId'], request_params['Total'], request_params['CurrencyCode']].join('|')
|
157
|
+
end
|
158
|
+
|
159
|
+
def split_authorization(authorization)
|
160
|
+
order_id, amount, currency = authorization.split("|")
|
161
|
+
[order_id, amount, currency]
|
162
|
+
end
|
163
|
+
|
164
|
+
def order_id_from(authorization)
|
165
|
+
split_authorization(authorization).first
|
166
|
+
end
|
167
|
+
|
168
|
+
def expdate(credit_card)
|
169
|
+
year = sprintf("%.4i", credit_card.year)
|
170
|
+
month = sprintf("%.2i", credit_card.month)
|
171
|
+
|
172
|
+
"#{month}/#{year[-2..-1]}"
|
173
|
+
end
|
174
|
+
|
175
|
+
def url
|
176
|
+
test? ? test_url : live_url
|
177
|
+
end
|
178
|
+
|
179
|
+
def parse(response, request_params)
|
180
|
+
response_params = params_from_response(response)
|
181
|
+
|
182
|
+
success = (response_params['ResponseCode'] == '00')
|
183
|
+
message = response_params['ResponseText'] || response_params['ResponseMsg']
|
184
|
+
options = @options.merge(:test => test?,
|
185
|
+
:authorization => build_authorization(request_params, response_params))
|
186
|
+
|
187
|
+
Response.new(success, message, response_params, options)
|
188
|
+
end
|
189
|
+
|
190
|
+
def commit(action, parameters, options)
|
191
|
+
add_login_data(parameters)
|
192
|
+
add_action(parameters, action, options)
|
193
|
+
|
194
|
+
post = parameters.collect{|key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
|
195
|
+
parse(ssl_post(url, post), parameters)
|
196
|
+
end
|
197
|
+
|
198
|
+
# Override the regular handle response so we can access the headers
|
199
|
+
def handle_response(response)
|
200
|
+
case response.code.to_i
|
201
|
+
when 200...300
|
202
|
+
response
|
203
|
+
else
|
204
|
+
raise ResponseError.new(response)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
# Return a hash containing all the useful, or informative values from netpay
|
209
|
+
def params_from_response(response)
|
210
|
+
params = {}
|
211
|
+
RESPONSE_KEYS.each do |k|
|
212
|
+
params[k] = response[k] unless response[k].to_s.empty?
|
213
|
+
end
|
214
|
+
params
|
215
|
+
end
|
216
|
+
|
217
|
+
def currency_code(currency)
|
218
|
+
return currency if currency =~ /^\d+$/
|
219
|
+
CURRENCY_CODES[currency]
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
@@ -0,0 +1,242 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
class NetworkMerchantsGateway < Gateway
|
4
|
+
self.live_url = self.test_url = 'https://secure.networkmerchants.com/api/transact.php'
|
5
|
+
|
6
|
+
self.supported_countries = ['US']
|
7
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :discover]
|
8
|
+
|
9
|
+
self.homepage_url = 'http://www.nmi.com/'
|
10
|
+
self.display_name = 'Network Merchants (NMI)'
|
11
|
+
|
12
|
+
self.money_format = :dollars
|
13
|
+
self.default_currency = 'USD'
|
14
|
+
|
15
|
+
def initialize(options = {})
|
16
|
+
requires!(options, :login, :password)
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def authorize(money, creditcard_or_vault_id, options = {})
|
21
|
+
post = build_auth_post(money, creditcard_or_vault_id, options)
|
22
|
+
commit('auth', post)
|
23
|
+
end
|
24
|
+
|
25
|
+
def purchase(money, creditcard_or_vault_id, options = {})
|
26
|
+
post = build_purchase_post(money, creditcard_or_vault_id, options)
|
27
|
+
commit('sale', post)
|
28
|
+
end
|
29
|
+
|
30
|
+
def capture(money, authorization, options = {})
|
31
|
+
post = build_capture_post(money, authorization, options)
|
32
|
+
commit('capture', post)
|
33
|
+
end
|
34
|
+
|
35
|
+
def void(authorization, options = {})
|
36
|
+
post = build_void_post(authorization, options)
|
37
|
+
commit('void', post)
|
38
|
+
end
|
39
|
+
|
40
|
+
def refund(money, authorization, options = {})
|
41
|
+
post = build_refund_post(money, authorization, options)
|
42
|
+
commit('refund', post)
|
43
|
+
end
|
44
|
+
|
45
|
+
def store(creditcard, options = {})
|
46
|
+
post = build_store_post(creditcard, options)
|
47
|
+
commit_vault('add_customer', post)
|
48
|
+
end
|
49
|
+
|
50
|
+
def unstore(customer_vault_id, options = {})
|
51
|
+
post = build_unstore_post(customer_vault_id, options)
|
52
|
+
commit_vault('delete_customer', post)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def build_auth_post(money, creditcard_or_vault_id, options)
|
58
|
+
post = {}
|
59
|
+
add_order(post, options)
|
60
|
+
add_address(post, options)
|
61
|
+
add_shipping_address(post, options)
|
62
|
+
add_payment_method(post, creditcard_or_vault_id, options)
|
63
|
+
add_amount(post, money, options)
|
64
|
+
post
|
65
|
+
end
|
66
|
+
|
67
|
+
def build_purchase_post(money, creditcard, options)
|
68
|
+
build_auth_post(money, creditcard, options)
|
69
|
+
end
|
70
|
+
|
71
|
+
def build_capture_post(money, authorization, options)
|
72
|
+
post = {}
|
73
|
+
post[:transactionid] = authorization
|
74
|
+
add_amount(post, money, options)
|
75
|
+
post
|
76
|
+
end
|
77
|
+
|
78
|
+
def build_void_post(authorization, options)
|
79
|
+
post = {}
|
80
|
+
post[:transactionid] = authorization
|
81
|
+
post
|
82
|
+
end
|
83
|
+
|
84
|
+
def build_refund_post(money, authorization, options)
|
85
|
+
post = {}
|
86
|
+
post[:transactionid] = authorization
|
87
|
+
add_amount(post, money, options)
|
88
|
+
post
|
89
|
+
end
|
90
|
+
|
91
|
+
def build_store_post(creditcard_or_check, options)
|
92
|
+
post = {}
|
93
|
+
add_address(post, options)
|
94
|
+
add_shipping_address(post, options)
|
95
|
+
add_payment_method(post, creditcard_or_check, options)
|
96
|
+
post
|
97
|
+
end
|
98
|
+
|
99
|
+
def build_unstore_post(customer_vault_id, options)
|
100
|
+
post = {}
|
101
|
+
post['customer_vault_id'] = customer_vault_id
|
102
|
+
post
|
103
|
+
end
|
104
|
+
|
105
|
+
def add_order(post, options)
|
106
|
+
post[:orderid] = options[:order_id]
|
107
|
+
post[:orderdescription] = options[:description]
|
108
|
+
end
|
109
|
+
|
110
|
+
def add_address(post, options)
|
111
|
+
post[:email] = options[:email]
|
112
|
+
post[:ipaddress] = options[:ip]
|
113
|
+
|
114
|
+
address = options[:billing_address] || options[:address] || {}
|
115
|
+
post[:address1] = address[:address1]
|
116
|
+
post[:address2] = address[:address2]
|
117
|
+
post[:city] = address[:city]
|
118
|
+
post[:state] = address[:state].blank? ? 'n/a' : address[:state]
|
119
|
+
post[:zip] = address[:zip]
|
120
|
+
post[:country] = address[:country]
|
121
|
+
post[:phone] = address[:phone]
|
122
|
+
end
|
123
|
+
|
124
|
+
def add_shipping_address(post, options)
|
125
|
+
shipping_address = options[:shipping_address] || {}
|
126
|
+
post[:shipping_address1] = shipping_address[:address1]
|
127
|
+
post[:shipping_address2] = shipping_address[:address2]
|
128
|
+
post[:shipping_city] = shipping_address[:city]
|
129
|
+
post[:shipping_state] = shipping_address[:state]
|
130
|
+
post[:shipping_zip] = shipping_address[:zip]
|
131
|
+
post[:shipping_country] = shipping_address[:country]
|
132
|
+
end
|
133
|
+
|
134
|
+
def add_swipe_data(post, creditcard, options)
|
135
|
+
# unencrypted tracks
|
136
|
+
if creditcard.respond_to?(:track_data) && creditcard.track_data.present?
|
137
|
+
post[:track_1] = creditcard.track_data
|
138
|
+
else
|
139
|
+
post[:track_1] = options[:track_1]
|
140
|
+
post[:track_2] = options[:track_2]
|
141
|
+
post[:track_3] = options[:track_3]
|
142
|
+
end
|
143
|
+
|
144
|
+
# encrypted tracks
|
145
|
+
post[:magnesafe_track_1] = options[:magnesafe_track_1]
|
146
|
+
post[:magnesafe_track_2] = options[:magnesafe_track_2]
|
147
|
+
post[:magnesafe_track_3] = options[:magnesafe_track_3]
|
148
|
+
post[:magnesafe_magneprint] = options[:magnesafe_magneprint]
|
149
|
+
post[:magnesafe_ksn] = options[:magnesafe_ksn]
|
150
|
+
post[:magnesafe_magneprint_status] = options[:magnesafe_magneprint_status]
|
151
|
+
end
|
152
|
+
|
153
|
+
def add_payment_method(post, payment_source, options)
|
154
|
+
post[:processor_id] = options[:processor_id]
|
155
|
+
post[:customer_vault] = 'add_customer' if options[:store]
|
156
|
+
|
157
|
+
add_swipe_data(post, payment_source, options)
|
158
|
+
|
159
|
+
if payment_source.is_a?(Check)
|
160
|
+
check = payment_source
|
161
|
+
post[:firstname] = check.first_name
|
162
|
+
post[:lastname] = check.last_name
|
163
|
+
post[:checkname] = check.name
|
164
|
+
post[:checkaba] = check.routing_number
|
165
|
+
post[:checkaccount] = check.account_number
|
166
|
+
post[:account_type] = check.account_type
|
167
|
+
post[:account_holder_type] = check.account_holder_type
|
168
|
+
post[:payment] = 'check'
|
169
|
+
elsif payment_source.respond_to?(:number)
|
170
|
+
creditcard = payment_source
|
171
|
+
post[:firstname] = creditcard.first_name
|
172
|
+
post[:lastname] = creditcard.last_name
|
173
|
+
post[:ccnumber] = creditcard.number
|
174
|
+
post[:ccexp] = format(creditcard.month, :two_digits) + format(creditcard.year, :two_digits)
|
175
|
+
post[:cvv] = creditcard.verification_value
|
176
|
+
post[:payment] = 'creditcard'
|
177
|
+
else
|
178
|
+
post[:customer_vault_id] = payment_source
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def add_login(post)
|
183
|
+
post[:username] = @options[:login]
|
184
|
+
post[:password] = @options[:password]
|
185
|
+
end
|
186
|
+
|
187
|
+
def add_amount(post, money, options)
|
188
|
+
post[:currency] = options[:currency] || currency(money)
|
189
|
+
post[:amount] = amount(money)
|
190
|
+
end
|
191
|
+
|
192
|
+
def commit_vault(action, parameters)
|
193
|
+
commit(nil, parameters.merge(:customer_vault => action))
|
194
|
+
end
|
195
|
+
|
196
|
+
def commit(action, parameters)
|
197
|
+
raw = parse(ssl_post(self.live_url, build_request(action, parameters)))
|
198
|
+
|
199
|
+
success = (raw['response'] == ResponseCodes::APPROVED)
|
200
|
+
|
201
|
+
authorization = authorization_from(success, parameters, raw)
|
202
|
+
|
203
|
+
Response.new(success, raw['responsetext'], raw,
|
204
|
+
:test => test?,
|
205
|
+
:authorization => authorization,
|
206
|
+
:avs_result => { :code => raw['avsresponse']},
|
207
|
+
:cvv_result => raw['cvvresponse']
|
208
|
+
)
|
209
|
+
end
|
210
|
+
|
211
|
+
def build_request(action, parameters)
|
212
|
+
parameters[:type] = action if action
|
213
|
+
add_login(parameters)
|
214
|
+
parameters.to_query
|
215
|
+
end
|
216
|
+
|
217
|
+
def authorization_from(success, parameters, response)
|
218
|
+
return nil unless success
|
219
|
+
|
220
|
+
authorization = response['transactionid']
|
221
|
+
if(parameters[:customer_vault] && (authorization.nil? || authorization.empty?))
|
222
|
+
authorization = response['customer_vault_id']
|
223
|
+
end
|
224
|
+
|
225
|
+
authorization
|
226
|
+
end
|
227
|
+
|
228
|
+
class ResponseCodes
|
229
|
+
APPROVED = '1'
|
230
|
+
DENIED = '2'
|
231
|
+
ERROR = '3'
|
232
|
+
end
|
233
|
+
|
234
|
+
def parse(raw_response)
|
235
|
+
rsp = CGI.parse(raw_response)
|
236
|
+
rsp.keys.each { |k| rsp[k] = rsp[k].first } # flatten out the values
|
237
|
+
rsp
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|