activemerchant-nsp 1.27.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +952 -0
- data/CONTRIBUTORS +347 -0
- data/MIT-LICENSE +20 -0
- data/README.md +204 -0
- data/gem-public_cert.pem +20 -0
- data/lib/active_merchant.rb +63 -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 +56 -0
- data/lib/active_merchant/billing/check.rb +68 -0
- data/lib/active_merchant/billing/credit_card.rb +274 -0
- data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
- data/lib/active_merchant/billing/credit_card_methods.rb +143 -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 +176 -0
- data/lib/active_merchant/billing/gateways.rb +18 -0
- data/lib/active_merchant/billing/gateways/authorize_net.rb +695 -0
- data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +943 -0
- data/lib/active_merchant/billing/gateways/balanced.rb +462 -0
- data/lib/active_merchant/billing/gateways/barclays_epdq.rb +308 -0
- data/lib/active_merchant/billing/gateways/beanstream.rb +167 -0
- data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +389 -0
- data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
- data/lib/active_merchant/billing/gateways/blue_pay.rb +492 -0
- data/lib/active_merchant/billing/gateways/bogus.rb +142 -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 +389 -0
- data/lib/active_merchant/billing/gateways/braintree_orange.rb +19 -0
- data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
- data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
- data/lib/active_merchant/billing/gateways/certo_direct.rb +278 -0
- data/lib/active_merchant/billing/gateways/cyber_source.rb +576 -0
- data/lib/active_merchant/billing/gateways/data_cash.rb +597 -0
- data/lib/active_merchant/billing/gateways/efsnet.rb +235 -0
- data/lib/active_merchant/billing/gateways/elavon.rb +137 -0
- data/lib/active_merchant/billing/gateways/epay.rb +276 -0
- data/lib/active_merchant/billing/gateways/eway.rb +287 -0
- data/lib/active_merchant/billing/gateways/eway_managed.rb +265 -0
- data/lib/active_merchant/billing/gateways/exact.rb +227 -0
- data/lib/active_merchant/billing/gateways/fat_zebra.rb +152 -0
- data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
- data/lib/active_merchant/billing/gateways/first_pay.rb +177 -0
- data/lib/active_merchant/billing/gateways/garanti.rb +262 -0
- data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +252 -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 +55 -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 +257 -0
- data/lib/active_merchant/billing/gateways/itransact.rb +450 -0
- data/lib/active_merchant/billing/gateways/jetpay.rb +276 -0
- data/lib/active_merchant/billing/gateways/linkpoint.rb +451 -0
- data/lib/active_merchant/billing/gateways/litle.rb +290 -0
- data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +157 -0
- data/lib/active_merchant/billing/gateways/merchant_ware.rb +289 -0
- data/lib/active_merchant/billing/gateways/metrics_global.rb +323 -0
- data/lib/active_merchant/billing/gateways/migs.rb +263 -0
- data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
- data/lib/active_merchant/billing/gateways/modern_payments.rb +38 -0
- data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
- data/lib/active_merchant/billing/gateways/moneris.rb +250 -0
- data/lib/active_merchant/billing/gateways/moneris_us.rb +211 -0
- data/lib/active_merchant/billing/gateways/nab_transact.rb +257 -0
- data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
- data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
- data/lib/active_merchant/billing/gateways/netbilling.rb +196 -0
- data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
- data/lib/active_merchant/billing/gateways/ogone.rb +427 -0
- data/lib/active_merchant/billing/gateways/optimal_payment.rb +277 -0
- data/lib/active_merchant/billing/gateways/orbital.rb +351 -0
- data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
- data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +266 -0
- data/lib/active_merchant/billing/gateways/pay_junction.rb +397 -0
- data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
- data/lib/active_merchant/billing/gateways/paybox_direct.rb +201 -0
- data/lib/active_merchant/billing/gateways/payflow.rb +268 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +212 -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 +282 -0
- data/lib/active_merchant/billing/gateways/paypal.rb +106 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +653 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +245 -0
- data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
- data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +43 -0
- data/lib/active_merchant/billing/gateways/paypal_express.rb +178 -0
- data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
- data/lib/active_merchant/billing/gateways/paystation.rb +201 -0
- data/lib/active_merchant/billing/gateways/payway.rb +214 -0
- data/lib/active_merchant/billing/gateways/plugnpay.rb +295 -0
- data/lib/active_merchant/billing/gateways/psigate.rb +219 -0
- data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
- data/lib/active_merchant/billing/gateways/qbms.rb +297 -0
- data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
- data/lib/active_merchant/billing/gateways/quickpay.rb +298 -0
- data/lib/active_merchant/billing/gateways/realex.rb +313 -0
- data/lib/active_merchant/billing/gateways/sage.rb +148 -0
- data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
- data/lib/active_merchant/billing/gateways/sage/sage_core.rb +115 -0
- data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
- data/lib/active_merchant/billing/gateways/sage_pay.rb +322 -0
- data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
- data/lib/active_merchant/billing/gateways/samurai.rb +121 -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 +284 -0
- data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
- data/lib/active_merchant/billing/gateways/skip_jack.rb +458 -0
- data/lib/active_merchant/billing/gateways/smart_ps.rb +273 -0
- data/lib/active_merchant/billing/gateways/stripe.rb +236 -0
- data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
- data/lib/active_merchant/billing/gateways/transax.rb +23 -0
- data/lib/active_merchant/billing/gateways/trust_commerce.rb +423 -0
- data/lib/active_merchant/billing/gateways/usa_epay.rb +25 -0
- data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1497 -0
- data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +206 -0
- data/lib/active_merchant/billing/gateways/verifi.rb +233 -0
- data/lib/active_merchant/billing/gateways/viaklix.rb +194 -0
- data/lib/active_merchant/billing/gateways/vindicia.rb +359 -0
- data/lib/active_merchant/billing/gateways/wirecard.rb +313 -0
- data/lib/active_merchant/billing/gateways/worldpay.rb +271 -0
- data/lib/active_merchant/billing/integrations.rb +17 -0
- data/lib/active_merchant/billing/integrations/action_view_helper.rb +73 -0
- data/lib/active_merchant/billing/integrations/authorize_net_sim.rb +38 -0
- data/lib/active_merchant/billing/integrations/authorize_net_sim/helper.rb +228 -0
- data/lib/active_merchant/billing/integrations/authorize_net_sim/notification.rb +340 -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 +200 -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/directebanking.rb +47 -0
- data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
- data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
- data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
- data/lib/active_merchant/billing/integrations/dotpay.rb +22 -0
- data/lib/active_merchant/billing/integrations/dotpay/helper.rb +77 -0
- data/lib/active_merchant/billing/integrations/dotpay/notification.rb +86 -0
- data/lib/active_merchant/billing/integrations/dotpay/return.rb +11 -0
- data/lib/active_merchant/billing/integrations/dwolla.rb +30 -0
- data/lib/active_merchant/billing/integrations/dwolla/helper.rb +31 -0
- data/lib/active_merchant/billing/integrations/dwolla/notification.rb +55 -0
- data/lib/active_merchant/billing/integrations/dwolla/return.rb +38 -0
- data/lib/active_merchant/billing/integrations/e_payment_plans.rb +48 -0
- data/lib/active_merchant/billing/integrations/e_payment_plans/helper.rb +34 -0
- data/lib/active_merchant/billing/integrations/e_payment_plans/notification.rb +84 -0
- data/lib/active_merchant/billing/integrations/easy_pay.rb +30 -0
- data/lib/active_merchant/billing/integrations/easy_pay/common.rb +40 -0
- data/lib/active_merchant/billing/integrations/easy_pay/helper.rb +40 -0
- data/lib/active_merchant/billing/integrations/easy_pay/notification.rb +51 -0
- data/lib/active_merchant/billing/integrations/epay.rb +21 -0
- data/lib/active_merchant/billing/integrations/epay/helper.rb +55 -0
- data/lib/active_merchant/billing/integrations/epay/notification.rb +110 -0
- data/lib/active_merchant/billing/integrations/first_data.rb +38 -0
- data/lib/active_merchant/billing/integrations/first_data/helper.rb +63 -0
- data/lib/active_merchant/billing/integrations/first_data/notification.rb +56 -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 +117 -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/maksuturva.rb +86 -0
- data/lib/active_merchant/billing/integrations/maksuturva/helper.rb +119 -0
- data/lib/active_merchant/billing/integrations/maksuturva/notification.rb +48 -0
- data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
- data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +59 -0
- data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
- data/lib/active_merchant/billing/integrations/nelnet.rb +40 -0
- data/lib/active_merchant/billing/integrations/nelnet/helper.rb +34 -0
- data/lib/active_merchant/billing/integrations/nelnet/notification.rb +100 -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/paxum.rb +44 -0
- data/lib/active_merchant/billing/integrations/paxum/common.rb +24 -0
- data/lib/active_merchant/billing/integrations/paxum/helper.rb +42 -0
- data/lib/active_merchant/billing/integrations/paxum/notification.rb +33 -0
- data/lib/active_merchant/billing/integrations/payflow_link.rb +21 -0
- data/lib/active_merchant/billing/integrations/payflow_link/helper.rb +100 -0
- data/lib/active_merchant/billing/integrations/payflow_link/notification.rb +78 -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 +155 -0
- data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/paypal_payments_advanced.rb +20 -0
- data/lib/active_merchant/billing/integrations/paypal_payments_advanced/helper.rb +15 -0
- data/lib/active_merchant/billing/integrations/pxpay.rb +31 -0
- data/lib/active_merchant/billing/integrations/pxpay/helper.rb +110 -0
- data/lib/active_merchant/billing/integrations/pxpay/notification.rb +157 -0
- data/lib/active_merchant/billing/integrations/pxpay/return.rb +25 -0
- data/lib/active_merchant/billing/integrations/quickpay.rb +21 -0
- data/lib/active_merchant/billing/integrations/quickpay/helper.rb +71 -0
- data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
- data/lib/active_merchant/billing/integrations/return.rb +42 -0
- data/lib/active_merchant/billing/integrations/robokassa.rb +49 -0
- data/lib/active_merchant/billing/integrations/robokassa/common.rb +19 -0
- data/lib/active_merchant/billing/integrations/robokassa/helper.rb +50 -0
- data/lib/active_merchant/billing/integrations/robokassa/notification.rb +55 -0
- data/lib/active_merchant/billing/integrations/robokassa/return.rb +17 -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 +129 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -0
- data/lib/active_merchant/billing/integrations/two_checkout.rb +44 -0
- data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +91 -0
- data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +139 -0
- data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
- data/lib/active_merchant/billing/integrations/valitor.rb +33 -0
- data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
- data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
- data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +97 -0
- data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
- data/lib/active_merchant/billing/integrations/verkkomaksut.rb +20 -0
- data/lib/active_merchant/billing/integrations/verkkomaksut/helper.rb +87 -0
- data/lib/active_merchant/billing/integrations/verkkomaksut/notification.rb +59 -0
- data/lib/active_merchant/billing/integrations/web_pay.rb +45 -0
- data/lib/active_merchant/billing/integrations/web_pay/common.rb +50 -0
- data/lib/active_merchant/billing/integrations/web_pay/helper.rb +68 -0
- data/lib/active_merchant/billing/integrations/web_pay/notification.rb +51 -0
- data/lib/active_merchant/billing/integrations/world_pay.rb +27 -0
- data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
- data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -0
- data/lib/active_merchant/billing/response.rb +64 -0
- data/lib/active_merchant/version.rb +3 -0
- data/lib/activemerchant.rb +1 -0
- data/lib/support/gateway_support.rb +65 -0
- data/lib/support/outbound_hosts.rb +25 -0
- data/lib/support/ssl_verify.rb +93 -0
- metadata +482 -0
@@ -0,0 +1,142 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
# Bogus Gateway
|
4
|
+
class BogusGateway < Gateway
|
5
|
+
AUTHORIZATION = '53433'
|
6
|
+
|
7
|
+
SUCCESS_MESSAGE = "Bogus Gateway: Forced success"
|
8
|
+
FAILURE_MESSAGE = "Bogus Gateway: Forced failure"
|
9
|
+
ERROR_MESSAGE = "Bogus Gateway: Use CreditCard number 1 for success, 2 for exception and anything else for error"
|
10
|
+
CREDIT_ERROR_MESSAGE = "Bogus Gateway: Use CreditCard number 1 for success, 2 for exception and anything else for error"
|
11
|
+
UNSTORE_ERROR_MESSAGE = "Bogus Gateway: Use trans_id 1 for success, 2 for exception and anything else for error"
|
12
|
+
CAPTURE_ERROR_MESSAGE = "Bogus Gateway: Use authorization number 1 for exception, 2 for error and anything else for success"
|
13
|
+
VOID_ERROR_MESSAGE = "Bogus Gateway: Use authorization number 1 for exception, 2 for error and anything else for success"
|
14
|
+
REFUND_ERROR_MESSAGE = "Bogus Gateway: Use trans_id number 1 for exception, 2 for error and anything else for success"
|
15
|
+
|
16
|
+
self.supported_countries = ['US']
|
17
|
+
self.supported_cardtypes = [:bogus]
|
18
|
+
self.homepage_url = 'http://example.com'
|
19
|
+
self.display_name = 'Bogus'
|
20
|
+
|
21
|
+
def authorize(money, credit_card_or_reference, options = {})
|
22
|
+
money = amount(money)
|
23
|
+
case normalize(credit_card_or_reference)
|
24
|
+
when '1'
|
25
|
+
Response.new(true, SUCCESS_MESSAGE, {:authorized_amount => money}, :test => true, :authorization => AUTHORIZATION )
|
26
|
+
when '2'
|
27
|
+
Response.new(false, FAILURE_MESSAGE, {:authorized_amount => money, :error => FAILURE_MESSAGE }, :test => true)
|
28
|
+
else
|
29
|
+
raise Error, ERROR_MESSAGE
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def purchase(money, credit_card_or_reference, options = {})
|
34
|
+
money = amount(money)
|
35
|
+
case normalize(credit_card_or_reference)
|
36
|
+
when '1', AUTHORIZATION
|
37
|
+
Response.new(true, SUCCESS_MESSAGE, {:paid_amount => money}, :test => true)
|
38
|
+
when '2'
|
39
|
+
Response.new(false, FAILURE_MESSAGE, {:paid_amount => money, :error => FAILURE_MESSAGE },:test => true)
|
40
|
+
else
|
41
|
+
raise Error, ERROR_MESSAGE
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def recurring(money, credit_card_or_reference, options = {})
|
46
|
+
money = amount(money)
|
47
|
+
case normalize(credit_card_or_reference)
|
48
|
+
when '1'
|
49
|
+
Response.new(true, SUCCESS_MESSAGE, {:paid_amount => money}, :test => true)
|
50
|
+
when '2'
|
51
|
+
Response.new(false, FAILURE_MESSAGE, {:paid_amount => money, :error => FAILURE_MESSAGE },:test => true)
|
52
|
+
else
|
53
|
+
raise Error, ERROR_MESSAGE
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def credit(money, credit_card_or_reference, options = {})
|
58
|
+
if credit_card_or_reference.is_a?(String)
|
59
|
+
deprecated CREDIT_DEPRECATION_MESSAGE
|
60
|
+
return refund(money, credit_card_or_reference, options)
|
61
|
+
end
|
62
|
+
|
63
|
+
money = amount(money)
|
64
|
+
case normalize(credit_card_or_reference)
|
65
|
+
when '1'
|
66
|
+
Response.new(true, SUCCESS_MESSAGE, {:paid_amount => money}, :test => true )
|
67
|
+
when '2'
|
68
|
+
Response.new(false, FAILURE_MESSAGE, {:paid_amount => money, :error => FAILURE_MESSAGE }, :test => true)
|
69
|
+
else
|
70
|
+
raise Error, CREDIT_ERROR_MESSAGE
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def refund(money, reference, options = {})
|
75
|
+
money = amount(money)
|
76
|
+
case reference
|
77
|
+
when '1'
|
78
|
+
raise Error, REFUND_ERROR_MESSAGE
|
79
|
+
when '2'
|
80
|
+
Response.new(false, FAILURE_MESSAGE, {:paid_amount => money, :error => FAILURE_MESSAGE }, :test => true)
|
81
|
+
else
|
82
|
+
Response.new(true, SUCCESS_MESSAGE, {:paid_amount => money}, :test => true)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def capture(money, reference, options = {})
|
87
|
+
money = amount(money)
|
88
|
+
case reference
|
89
|
+
when '1'
|
90
|
+
raise Error, CAPTURE_ERROR_MESSAGE
|
91
|
+
when '2'
|
92
|
+
Response.new(false, FAILURE_MESSAGE, {:paid_amount => money, :error => FAILURE_MESSAGE }, :test => true)
|
93
|
+
else
|
94
|
+
Response.new(true, SUCCESS_MESSAGE, {:paid_amount => money}, :test => true)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def void(reference, options = {})
|
99
|
+
case reference
|
100
|
+
when '1'
|
101
|
+
raise Error, VOID_ERROR_MESSAGE
|
102
|
+
when '2'
|
103
|
+
Response.new(false, FAILURE_MESSAGE, {:authorization => reference, :error => FAILURE_MESSAGE }, :test => true)
|
104
|
+
else
|
105
|
+
Response.new(true, SUCCESS_MESSAGE, {:authorization => reference}, :test => true)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def store(credit_card_or_reference, options = {})
|
110
|
+
case normalize(credit_card_or_reference)
|
111
|
+
when '1'
|
112
|
+
Response.new(true, SUCCESS_MESSAGE, {:billingid => '1'}, :test => true, :authorization => AUTHORIZATION)
|
113
|
+
when '2'
|
114
|
+
Response.new(false, FAILURE_MESSAGE, {:billingid => nil, :error => FAILURE_MESSAGE }, :test => true)
|
115
|
+
else
|
116
|
+
raise Error, ERROR_MESSAGE
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def unstore(reference, options = {})
|
121
|
+
case reference
|
122
|
+
when '1'
|
123
|
+
Response.new(true, SUCCESS_MESSAGE, {}, :test => true)
|
124
|
+
when '2'
|
125
|
+
Response.new(false, FAILURE_MESSAGE, {:error => FAILURE_MESSAGE },:test => true)
|
126
|
+
else
|
127
|
+
raise Error, UNSTORE_ERROR_MESSAGE
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
def normalize(credit_card_or_reference)
|
134
|
+
if credit_card_or_reference.respond_to?(:number)
|
135
|
+
credit_card_or_reference.number
|
136
|
+
else
|
137
|
+
credit_card_or_reference.to_s
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,19 @@
|
|
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
|
+
self.abstract_class = true
|
9
|
+
|
10
|
+
def self.new(options={})
|
11
|
+
if options.has_key?(:login)
|
12
|
+
BraintreeOrangeGateway.new(options)
|
13
|
+
else
|
14
|
+
BraintreeBlueGateway.new(options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
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, :diners_club]
|
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,389 @@
|
|
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
|
+
# For more information on the Braintree Gateway please visit their
|
14
|
+
# {Developer Portal}[https://www.braintreepayments.com/developers]
|
15
|
+
#
|
16
|
+
# ==== About this implementation
|
17
|
+
#
|
18
|
+
# This implementation leverages the Braintree-authored ruby gem:
|
19
|
+
# https://github.com/braintree/braintree_ruby
|
20
|
+
#
|
21
|
+
# ==== Debugging Information
|
22
|
+
#
|
23
|
+
# Setting an ActiveMerchant +wiredump_device+ will automatically
|
24
|
+
# configure the Braintree logger (via the Braintree gem's
|
25
|
+
# configuration) when the BraintreeBlueGateway is instantiated.
|
26
|
+
# Additionally, the log level will be set to +DEBUG+. Therefore,
|
27
|
+
# all you have to do is set the +wiredump_device+ and you'll
|
28
|
+
# get your debug output from your HTTP interactions with the
|
29
|
+
# remote gateway. (Don't enable this in production.)
|
30
|
+
#
|
31
|
+
# For example:
|
32
|
+
#
|
33
|
+
# ActiveMerchant::Billing::BraintreeBlueGateway.wiredump_device = Logger.new(STDOUT)
|
34
|
+
# # => #<Logger:0x107d385f8 ...>
|
35
|
+
#
|
36
|
+
# Braintree::Configuration.logger
|
37
|
+
# # => (some other logger, created by default by the gem)
|
38
|
+
#
|
39
|
+
# Braintree::Configuration.logger.level
|
40
|
+
# # => 1 (INFO)
|
41
|
+
#
|
42
|
+
# ActiveMerchant::Billing::BraintreeBlueGateway.new(:merchant_id => 'x', :public_key => 'x', :private_key => 'x')
|
43
|
+
#
|
44
|
+
# Braintree::Configuration.logger
|
45
|
+
# # => #<Logger:0x107d385f8 ...>
|
46
|
+
#
|
47
|
+
# Braintree::Configuration.logger.level
|
48
|
+
# # => 0 (DEBUG)
|
49
|
+
#
|
50
|
+
# Alternatively, you can avoid setting the +wiredump_device+
|
51
|
+
# and set +Braintree::Configuration.logger+ and/or
|
52
|
+
# +Braintree::Configuration.logger.level+ directly.
|
53
|
+
class BraintreeBlueGateway < Gateway
|
54
|
+
include BraintreeCommon
|
55
|
+
|
56
|
+
self.display_name = 'Braintree (Blue Platform)'
|
57
|
+
|
58
|
+
def initialize(options = {})
|
59
|
+
requires!(options, :merchant_id, :public_key, :private_key)
|
60
|
+
@options = options
|
61
|
+
@merchant_account_id = options[:merchant_account_id]
|
62
|
+
Braintree::Configuration.merchant_id = options[:merchant_id]
|
63
|
+
Braintree::Configuration.public_key = options[:public_key]
|
64
|
+
Braintree::Configuration.private_key = options[:private_key]
|
65
|
+
Braintree::Configuration.environment = (options[:environment] || (test? ? :sandbox : :production)).to_sym
|
66
|
+
Braintree::Configuration.custom_user_agent = "ActiveMerchant #{ActiveMerchant::VERSION}"
|
67
|
+
if wiredump_device
|
68
|
+
Braintree::Configuration.logger = wiredump_device
|
69
|
+
Braintree::Configuration.logger.level = Logger::DEBUG
|
70
|
+
end
|
71
|
+
super
|
72
|
+
end
|
73
|
+
|
74
|
+
def authorize(money, credit_card_or_vault_id, options = {})
|
75
|
+
create_transaction(:sale, money, credit_card_or_vault_id, options)
|
76
|
+
end
|
77
|
+
|
78
|
+
def capture(money, authorization, options = {})
|
79
|
+
commit do
|
80
|
+
result = Braintree::Transaction.submit_for_settlement(authorization, amount(money).to_s)
|
81
|
+
Response.new(result.success?, message_from_result(result))
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def purchase(money, credit_card_or_vault_id, options = {})
|
86
|
+
authorize(money, credit_card_or_vault_id, options.merge(:submit_for_settlement => true))
|
87
|
+
end
|
88
|
+
|
89
|
+
def credit(money, credit_card_or_vault_id, options = {})
|
90
|
+
create_transaction(:credit, money, credit_card_or_vault_id, options)
|
91
|
+
end
|
92
|
+
|
93
|
+
def refund(*args)
|
94
|
+
# legacy signature: #refund(transaction_id, options = {})
|
95
|
+
# new signature: #refund(money, transaction_id, options = {})
|
96
|
+
money, transaction_id, options = extract_refund_args(args)
|
97
|
+
money = amount(money).to_s if money
|
98
|
+
|
99
|
+
commit do
|
100
|
+
result = Braintree::Transaction.refund(transaction_id, money)
|
101
|
+
Response.new(result.success?, message_from_result(result),
|
102
|
+
{:braintree_transaction => (transaction_hash(result.transaction) if result.success?)},
|
103
|
+
{:authorization => (result.transaction.id if result.success?)}
|
104
|
+
)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def void(authorization, options = {})
|
109
|
+
commit do
|
110
|
+
result = Braintree::Transaction.void(authorization)
|
111
|
+
Response.new(result.success?, message_from_result(result),
|
112
|
+
{:braintree_transaction => (transaction_hash(result.transaction) if result.success?)},
|
113
|
+
{:authorization => (result.transaction.id if result.success?)}
|
114
|
+
)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def store(creditcard, options = {})
|
119
|
+
commit do
|
120
|
+
parameters = {
|
121
|
+
:first_name => creditcard.first_name,
|
122
|
+
:last_name => creditcard.last_name,
|
123
|
+
:email => options[:email],
|
124
|
+
:credit_card => {
|
125
|
+
:number => creditcard.number,
|
126
|
+
:cvv => creditcard.verification_value,
|
127
|
+
:expiration_month => creditcard.month.to_s.rjust(2, "0"),
|
128
|
+
:expiration_year => creditcard.year.to_s
|
129
|
+
}
|
130
|
+
}
|
131
|
+
result = Braintree::Customer.create(merge_credit_card_options(parameters, options))
|
132
|
+
Response.new(result.success?, message_from_result(result),
|
133
|
+
{
|
134
|
+
:braintree_customer => (customer_hash(result.customer) if result.success?),
|
135
|
+
:customer_vault_id => (result.customer.id if result.success?)
|
136
|
+
}
|
137
|
+
)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def update(vault_id, creditcard, options = {})
|
142
|
+
braintree_credit_card = nil
|
143
|
+
customer_update_result = commit do
|
144
|
+
braintree_credit_card = Braintree::Customer.find(vault_id).credit_cards.detect { |cc| cc.default? }
|
145
|
+
return Response.new(false, 'Braintree::NotFoundError') if braintree_credit_card.nil?
|
146
|
+
|
147
|
+
options.merge!(:update_existing_token => braintree_credit_card.token)
|
148
|
+
credit_card_params = merge_credit_card_options({
|
149
|
+
:credit_card => {
|
150
|
+
:number => creditcard.number,
|
151
|
+
:cvv => creditcard.verification_value,
|
152
|
+
:expiration_month => creditcard.month.to_s.rjust(2, "0"),
|
153
|
+
:expiration_year => creditcard.year.to_s
|
154
|
+
}
|
155
|
+
}, options)[:credit_card]
|
156
|
+
|
157
|
+
result = Braintree::Customer.update(vault_id,
|
158
|
+
:first_name => creditcard.first_name,
|
159
|
+
:last_name => creditcard.last_name,
|
160
|
+
:email => options[:email],
|
161
|
+
:credit_card => credit_card_params
|
162
|
+
)
|
163
|
+
Response.new(result.success?, message_from_result(result),
|
164
|
+
:braintree_customer => (customer_hash(Braintree::Customer.find(vault_id)) if result.success?),
|
165
|
+
:customer_vault_id => (result.customer.id if result.success?)
|
166
|
+
)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def unstore(customer_vault_id)
|
171
|
+
commit do
|
172
|
+
Braintree::Customer.delete(customer_vault_id)
|
173
|
+
Response.new(true, "OK")
|
174
|
+
end
|
175
|
+
end
|
176
|
+
alias_method :delete, :unstore
|
177
|
+
|
178
|
+
private
|
179
|
+
|
180
|
+
def merge_credit_card_options(parameters, options)
|
181
|
+
valid_options = {}
|
182
|
+
options.each do |key, value|
|
183
|
+
valid_options[key] = value if [:update_existing_token, :verify_card, :verification_merchant_account_id].include?(key)
|
184
|
+
end
|
185
|
+
|
186
|
+
parameters[:credit_card] ||= {}
|
187
|
+
parameters[:credit_card].merge!(:options => valid_options)
|
188
|
+
parameters[:credit_card][:billing_address] = map_address(options[:billing_address]) if options[:billing_address]
|
189
|
+
parameters
|
190
|
+
end
|
191
|
+
|
192
|
+
def map_address(address)
|
193
|
+
return {} if address.nil?
|
194
|
+
mapped = {
|
195
|
+
:street_address => address[:address1],
|
196
|
+
:extended_address => address[:address2],
|
197
|
+
:company => address[:company],
|
198
|
+
:locality => address[:city],
|
199
|
+
:region => address[:state],
|
200
|
+
:postal_code => address[:zip],
|
201
|
+
}
|
202
|
+
if(address[:country] || address[:country_code_alpha2])
|
203
|
+
mapped[:country_code_alpha2] = (address[:country] || address[:country_code_alpha2])
|
204
|
+
elsif address[:country_name]
|
205
|
+
mapped[:country_name] = address[:country_name]
|
206
|
+
elsif address[:country_code_alpha3]
|
207
|
+
mapped[:country_code_alpha3] = address[:country_code_alpha3]
|
208
|
+
elsif address[:country_code_numeric]
|
209
|
+
mapped[:country_code_numeric] = address[:country_code_numeric]
|
210
|
+
end
|
211
|
+
mapped
|
212
|
+
end
|
213
|
+
|
214
|
+
def commit(&block)
|
215
|
+
yield
|
216
|
+
rescue Braintree::BraintreeError => ex
|
217
|
+
Response.new(false, ex.class.to_s)
|
218
|
+
end
|
219
|
+
|
220
|
+
def message_from_result(result)
|
221
|
+
if result.success?
|
222
|
+
"OK"
|
223
|
+
elsif result.errors.size == 0 && result.credit_card_verification
|
224
|
+
"Processor declined: #{result.credit_card_verification.processor_response_text} (#{result.credit_card_verification.processor_response_code})"
|
225
|
+
else
|
226
|
+
result.errors.map { |e| "#{e.message} (#{e.code})" }.join(" ")
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
def create_transaction(transaction_type, money, credit_card_or_vault_id, options)
|
231
|
+
transaction_params = create_transaction_parameters(money, credit_card_or_vault_id, options)
|
232
|
+
|
233
|
+
commit do
|
234
|
+
result = Braintree::Transaction.send(transaction_type, transaction_params)
|
235
|
+
response_params, response_options, avs_result, cvv_result = {}, {}, {}, {}
|
236
|
+
if result.success?
|
237
|
+
response_params[:braintree_transaction] = transaction_hash(result.transaction)
|
238
|
+
response_params[:customer_vault_id] = result.transaction.customer_details.id
|
239
|
+
response_options[:authorization] = result.transaction.id
|
240
|
+
end
|
241
|
+
if result.transaction
|
242
|
+
response_options[:avs_result] = {
|
243
|
+
:code => nil, :message => nil,
|
244
|
+
:street_match => result.transaction.avs_street_address_response_code,
|
245
|
+
:postal_match => result.transaction.avs_postal_code_response_code
|
246
|
+
}
|
247
|
+
response_options[:cvv_result] = result.transaction.cvv_response_code
|
248
|
+
if result.transaction.status == "gateway_rejected"
|
249
|
+
message = "Transaction declined - gateway rejected"
|
250
|
+
else
|
251
|
+
message = "#{result.transaction.processor_response_code} #{result.transaction.processor_response_text}"
|
252
|
+
end
|
253
|
+
else
|
254
|
+
message = message_from_result(result)
|
255
|
+
end
|
256
|
+
response = Response.new(result.success?, message, response_params, response_options)
|
257
|
+
response.cvv_result['message'] = ''
|
258
|
+
response
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
def extract_refund_args(args)
|
263
|
+
options = args.extract_options!
|
264
|
+
|
265
|
+
# money, transaction_id, options
|
266
|
+
if args.length == 1 # legacy signature
|
267
|
+
return nil, args[0], options
|
268
|
+
elsif args.length == 2
|
269
|
+
return args[0], args[1], options
|
270
|
+
else
|
271
|
+
raise ArgumentError, "wrong number of arguments (#{args.length} for 2)"
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
def customer_hash(customer)
|
276
|
+
credit_cards = customer.credit_cards.map do |cc|
|
277
|
+
{
|
278
|
+
"bin" => cc.bin,
|
279
|
+
"expiration_date" => cc.expiration_date,
|
280
|
+
"token" => cc.token,
|
281
|
+
"last_4" => cc.last_4,
|
282
|
+
"card_type" => cc.card_type,
|
283
|
+
"masked_number" => cc.masked_number
|
284
|
+
}
|
285
|
+
end
|
286
|
+
|
287
|
+
{
|
288
|
+
"email" => customer.email,
|
289
|
+
"first_name" => customer.first_name,
|
290
|
+
"last_name" => customer.last_name,
|
291
|
+
"credit_cards" => credit_cards,
|
292
|
+
"id" => customer.id
|
293
|
+
}
|
294
|
+
end
|
295
|
+
|
296
|
+
def transaction_hash(transaction)
|
297
|
+
if transaction.vault_customer
|
298
|
+
vault_customer = {
|
299
|
+
}
|
300
|
+
vault_customer["credit_cards"] = transaction.vault_customer.credit_cards.map do |cc|
|
301
|
+
{
|
302
|
+
"bin" => cc.bin
|
303
|
+
}
|
304
|
+
end
|
305
|
+
else
|
306
|
+
vault_customer = nil
|
307
|
+
end
|
308
|
+
|
309
|
+
customer_details = {
|
310
|
+
"id" => transaction.customer_details.id,
|
311
|
+
"email" => transaction.customer_details.email
|
312
|
+
}
|
313
|
+
|
314
|
+
billing_details = {
|
315
|
+
"street_address" => transaction.billing_details.street_address,
|
316
|
+
"extended_address" => transaction.billing_details.extended_address,
|
317
|
+
"company" => transaction.billing_details.company,
|
318
|
+
"locality" => transaction.billing_details.locality,
|
319
|
+
"region" => transaction.billing_details.region,
|
320
|
+
"postal_code" => transaction.billing_details.postal_code,
|
321
|
+
"country_name" => transaction.billing_details.country_name,
|
322
|
+
}
|
323
|
+
|
324
|
+
shipping_details = {
|
325
|
+
"street_address" => transaction.shipping_details.street_address,
|
326
|
+
"extended_address" => transaction.shipping_details.extended_address,
|
327
|
+
"company" => transaction.shipping_details.company,
|
328
|
+
"locality" => transaction.shipping_details.locality,
|
329
|
+
"region" => transaction.shipping_details.region,
|
330
|
+
"postal_code" => transaction.shipping_details.postal_code,
|
331
|
+
"country_name" => transaction.shipping_details.country_name,
|
332
|
+
}
|
333
|
+
credit_card_details = {
|
334
|
+
"masked_number" => transaction.credit_card_details.masked_number,
|
335
|
+
"bin" => transaction.credit_card_details.bin,
|
336
|
+
"last_4" => transaction.credit_card_details.last_4,
|
337
|
+
"card_type" => transaction.credit_card_details.card_type,
|
338
|
+
}
|
339
|
+
|
340
|
+
{
|
341
|
+
"order_id" => transaction.order_id,
|
342
|
+
"status" => transaction.status,
|
343
|
+
"credit_card_details" => credit_card_details,
|
344
|
+
"customer_details" => customer_details,
|
345
|
+
"billing_details" => billing_details,
|
346
|
+
"shipping_details" => shipping_details,
|
347
|
+
"vault_customer" => vault_customer,
|
348
|
+
"merchant_account_id" => transaction.merchant_account_id
|
349
|
+
}
|
350
|
+
end
|
351
|
+
|
352
|
+
def create_transaction_parameters(money, credit_card_or_vault_id, options)
|
353
|
+
parameters = {
|
354
|
+
:amount => amount(money).to_s,
|
355
|
+
:order_id => options[:order_id],
|
356
|
+
:customer => {
|
357
|
+
:id => options[:store] == true ? "" : options[:store],
|
358
|
+
:email => options[:email]
|
359
|
+
},
|
360
|
+
:options => {
|
361
|
+
:store_in_vault => options[:store] ? true : false,
|
362
|
+
:submit_for_settlement => options[:submit_for_settlement]
|
363
|
+
}
|
364
|
+
}
|
365
|
+
if merchant_account_id = (options[:merchant_account_id] || @merchant_account_id)
|
366
|
+
parameters[:merchant_account_id] = merchant_account_id
|
367
|
+
end
|
368
|
+
if credit_card_or_vault_id.is_a?(String) || credit_card_or_vault_id.is_a?(Integer)
|
369
|
+
parameters[:customer_id] = credit_card_or_vault_id
|
370
|
+
else
|
371
|
+
parameters[:customer].merge!(
|
372
|
+
:first_name => credit_card_or_vault_id.first_name,
|
373
|
+
:last_name => credit_card_or_vault_id.last_name
|
374
|
+
)
|
375
|
+
parameters[:credit_card] = {
|
376
|
+
:number => credit_card_or_vault_id.number,
|
377
|
+
:cvv => credit_card_or_vault_id.verification_value,
|
378
|
+
:expiration_month => credit_card_or_vault_id.month.to_s.rjust(2, "0"),
|
379
|
+
:expiration_year => credit_card_or_vault_id.year.to_s
|
380
|
+
}
|
381
|
+
end
|
382
|
+
parameters[:billing] = map_address(options[:billing_address]) if options[:billing_address]
|
383
|
+
parameters[:shipping] = map_address(options[:shipping_address]) if options[:shipping_address]
|
384
|
+
parameters
|
385
|
+
end
|
386
|
+
end
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|