spree_gateway 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +14 -0
- data/.rspec +1 -0
- data/.travis.yml +22 -0
- data/Gemfile +21 -0
- data/LICENSE +26 -0
- data/README.md +68 -0
- data/Rakefile +14 -0
- data/Versionfile +12 -0
- data/app/assets/javascripts/store/gateway/stripe.js.coffee +58 -0
- data/app/assets/javascripts/store/spree_gateway.js +2 -0
- data/app/assets/stylesheets/store/spree_gateway.css +8 -0
- data/app/controllers/spree/checkout_controller_decorator.rb +51 -0
- data/app/controllers/spree/skrill_status_controller.rb +39 -0
- data/app/models/spree/billing_integration/skrill/quick_checkout.rb +48 -0
- data/app/models/spree/gateway/authorize_net.rb +16 -0
- data/app/models/spree/gateway/authorize_net_cim.rb +132 -0
- data/app/models/spree/gateway/balanced_gateway.rb +65 -0
- data/app/models/spree/gateway/banwire.rb +15 -0
- data/app/models/spree/gateway/beanstream.rb +193 -0
- data/app/models/spree/gateway/braintree_gateway.rb +147 -0
- data/app/models/spree/gateway/card_save.rb +10 -0
- data/app/models/spree/gateway/data_cash.rb +10 -0
- data/app/models/spree/gateway/eway.rb +20 -0
- data/app/models/spree/gateway/fatzebra.rb +15 -0
- data/app/models/spree/gateway/linkpoint.rb +28 -0
- data/app/models/spree/gateway/maxipago.rb +14 -0
- data/app/models/spree/gateway/moneris.rb +11 -0
- data/app/models/spree/gateway/pay_junction.rb +16 -0
- data/app/models/spree/gateway/pay_pal_gateway.rb +12 -0
- data/app/models/spree/gateway/payflow_pro.rb +17 -0
- data/app/models/spree/gateway/paymill.rb +12 -0
- data/app/models/spree/gateway/pin_gateway.rb +15 -0
- data/app/models/spree/gateway/sage_pay.rb +11 -0
- data/app/models/spree/gateway/samurai.rb +63 -0
- data/app/models/spree/gateway/secure_pay_au.rb +10 -0
- data/app/models/spree/gateway/stripe_gateway.rb +103 -0
- data/app/models/spree/gateway/usa_epay.rb +9 -0
- data/app/models/spree/gateway/worldpay.rb +91 -0
- data/app/models/spree/skrill_transaction.rb +19 -0
- data/app/views/spree/admin/log_entries/_braintree.html.erb +31 -0
- data/app/views/spree/admin/log_entries/_stripe.html.erb +28 -0
- data/app/views/spree/admin/payments/source_forms/_quickcheckout.html.erb +8 -0
- data/app/views/spree/admin/payments/source_forms/_stripe.html.erb +1 -0
- data/app/views/spree/admin/payments/source_views/_quickcheckout.html.erb +39 -0
- data/app/views/spree/admin/payments/source_views/_stripe.html.erb +1 -0
- data/app/views/spree/checkout/payment/_quickcheckout.html.erb +26 -0
- data/app/views/spree/checkout/payment/_stripe.html.erb +21 -0
- data/config/initializers/savon.rb +3 -0
- data/config/locales/bg.yml +11 -0
- data/config/locales/de.yml +11 -0
- data/config/locales/en.yml +30 -0
- data/config/locales/sv.yml +11 -0
- data/config/routes.rb +20 -0
- data/db/migrate/20111118164631_create_skrill_transactions.rb +14 -0
- data/db/migrate/20121017004102_update_braintree_payment_method_type.rb +9 -0
- data/db/migrate/20130213222555_update_stripe_payment_method_type.rb +9 -0
- data/db/migrate/20130415222802_update_balanced_payment_method_type.rb +9 -0
- data/db/migrate/20131008221012_update_paypal_payment_method_type.rb +9 -0
- data/db/migrate/20131112133401_migrate_stripe_preferences.rb +8 -0
- data/lib/active_merchant/billing/skrill.rb +18 -0
- data/lib/generators/spree_gateway/install/install_generator.rb +28 -0
- data/lib/spree_gateway.rb +3 -0
- data/lib/spree_gateway/engine.rb +42 -0
- data/script/rails +5 -0
- data/spec/factories/payment_method_factory.rb +4 -0
- data/spec/features/stripe_checkout_spec.rb +82 -0
- data/spec/models/gateway/authorize_net_cim_spec.rb +17 -0
- data/spec/models/gateway/authorize_net_spec.rb +17 -0
- data/spec/models/gateway/balanced_gateway_spec.rb +9 -0
- data/spec/models/gateway/banwire_spec.rb +9 -0
- data/spec/models/gateway/braintree_gateway_spec.rb +289 -0
- data/spec/models/gateway/eway_spec.rb +17 -0
- data/spec/models/gateway/fatzebra_spec.rb +47 -0
- data/spec/models/gateway/linkpoint_spec.rb +60 -0
- data/spec/models/gateway/pay_junction_spec.rb +17 -0
- data/spec/models/gateway/payflow_pro_spec.rb +17 -0
- data/spec/models/gateway/pin_gateway_spec.rb +57 -0
- data/spec/models/gateway/stripe_gateway_spec.rb +122 -0
- data/spec/models/gateway/usa_epay_spec.rb +38 -0
- data/spec/models/savon_spec.rb +9 -0
- data/spec/spec_helper.rb +56 -0
- data/spree_gateway.gemspec +28 -0
- metadata +104 -5
@@ -0,0 +1,20 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::Eway < Gateway
|
3
|
+
preference :login, :string
|
4
|
+
|
5
|
+
# Note: EWay supports purchase method only (no authorize method).
|
6
|
+
def auto_capture?
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
10
|
+
def provider_class
|
11
|
+
ActiveMerchant::Billing::EwayGateway
|
12
|
+
end
|
13
|
+
|
14
|
+
def options_with_test_preference
|
15
|
+
options_without_test_preference.merge(:test => self.preferred_test_mode)
|
16
|
+
end
|
17
|
+
|
18
|
+
alias_method_chain :options, :test_preference
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::Fatzebra < Gateway
|
3
|
+
preference :username, :string, default: "TEST"
|
4
|
+
preference :token, :string, default: "TEST"
|
5
|
+
|
6
|
+
def provider_class
|
7
|
+
ActiveMerchant::Billing::FatZebraGateway
|
8
|
+
end
|
9
|
+
|
10
|
+
# Currently no auth/capture, but coming soon...
|
11
|
+
def auto_capture?
|
12
|
+
true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::Linkpoint < Gateway
|
3
|
+
preference :login, :string
|
4
|
+
preference :pem, :text
|
5
|
+
|
6
|
+
def provider_class
|
7
|
+
ActiveMerchant::Billing::LinkpointGateway
|
8
|
+
end
|
9
|
+
|
10
|
+
[:authorize, :purchase, :capture, :void, :credit].each do |method|
|
11
|
+
define_method(method) do |*args|
|
12
|
+
options = add_discount_to_subtotal(args.extract_options!)
|
13
|
+
provider.public_send(method, *args << options)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
# Linkpoint ignores the discount, but it will return an error if the
|
20
|
+
# chargetotal is different from the sum of the subtotal, tax and
|
21
|
+
# shipping totals.
|
22
|
+
def add_discount_to_subtotal(options)
|
23
|
+
subtotal = options.fetch(:subtotal)
|
24
|
+
discount = options.fetch(:discount)
|
25
|
+
options.merge(subtotal: subtotal + discount, discount: 0)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::PayJunction < Gateway
|
3
|
+
preference :login, :string
|
4
|
+
preference :password, :string
|
5
|
+
|
6
|
+
def provider_class
|
7
|
+
ActiveMerchant::Billing::PayJunctionGateway
|
8
|
+
end
|
9
|
+
|
10
|
+
def options_with_test_preference
|
11
|
+
options_without_test_preference.merge(:test => self.preferred_test_mode)
|
12
|
+
end
|
13
|
+
|
14
|
+
alias_method_chain :options, :test_preference
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::PayPalGateway < Gateway
|
3
|
+
preference :login, :string
|
4
|
+
preference :password, :string
|
5
|
+
preference :signature, :string
|
6
|
+
preference :currency_code, :string
|
7
|
+
|
8
|
+
def provider_class
|
9
|
+
ActiveMerchant::Billing::PaypalGateway
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::PayflowPro < Gateway
|
3
|
+
preference :login, :string
|
4
|
+
preference :password, :password
|
5
|
+
|
6
|
+
def provider_class
|
7
|
+
ActiveMerchant::Billing::PayflowGateway
|
8
|
+
end
|
9
|
+
|
10
|
+
def options_with_test_preference
|
11
|
+
options_without_test_preference.merge(:test => self.preferred_test_mode)
|
12
|
+
end
|
13
|
+
|
14
|
+
alias_method_chain :options, :test_preference
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::PinGateway < Gateway
|
3
|
+
preference :api_key, :string
|
4
|
+
preference :currency, :string, :default => 'AUD'
|
5
|
+
|
6
|
+
def provider_class
|
7
|
+
ActiveMerchant::Billing::PinGateway
|
8
|
+
end
|
9
|
+
|
10
|
+
# Pin does not appear to support authorizing transactions yet
|
11
|
+
def auto_capture?
|
12
|
+
true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::Samurai < Gateway
|
3
|
+
preference :login, :string
|
4
|
+
preference :password, :string
|
5
|
+
preference :processor_token, :string
|
6
|
+
|
7
|
+
def provider_class
|
8
|
+
ActiveMerchant::Billing::SamuraiGateway
|
9
|
+
end
|
10
|
+
|
11
|
+
def payment_profiles_supported?
|
12
|
+
true
|
13
|
+
end
|
14
|
+
|
15
|
+
def purchase(money, creditcard, gateway_options)
|
16
|
+
gateway_options[:billing_reference] = gateway_options[:order_id]
|
17
|
+
gateway_options[:customer_reference] = gateway_options[:customer]
|
18
|
+
gateway_options[:description] = "Spree Order"
|
19
|
+
provider.purchase(money, creditcard.gateway_customer_profile_id, gateway_options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def authorize(money, creditcard, gateway_options)
|
23
|
+
gateway_options[:billing_reference] = gateway_options[:order_id]
|
24
|
+
gateway_options[:customer_reference] = gateway_options[:customer]
|
25
|
+
gateway_options[:description] = "Spree Order"
|
26
|
+
provider.authorize(money, creditcard.gateway_customer_profile_id, gateway_options)
|
27
|
+
end
|
28
|
+
|
29
|
+
def capture(authorization, creditcard, gateway_options)
|
30
|
+
gateway_options[:billing_reference] = gateway_options[:order_id]
|
31
|
+
gateway_options[:customer_reference] = gateway_options[:customer]
|
32
|
+
gateway_options[:description] = "Spree Order"
|
33
|
+
provider.capture(nil, authorization.response_code, {})
|
34
|
+
end
|
35
|
+
|
36
|
+
def credit(money, creditcard, response_code, gateway_options)
|
37
|
+
provider.credit(money, response_code, {})
|
38
|
+
end
|
39
|
+
|
40
|
+
def void(response_code, gateway_options)
|
41
|
+
provider.void(response_code, {})
|
42
|
+
end
|
43
|
+
|
44
|
+
def create_profile(payment)
|
45
|
+
return unless payment.source.gateway_customer_profile_id.nil?
|
46
|
+
|
47
|
+
options = {}
|
48
|
+
options[:email] = payment.order.email
|
49
|
+
options[:address] = {}
|
50
|
+
options[:address][:address1] = payment.order.bill_address.address1
|
51
|
+
options[:address][:address2] = payment.order.bill_address.address2
|
52
|
+
options[:address][:city] = payment.order.bill_address.city
|
53
|
+
options[:address][:state] = payment.order.bill_address.state.abbr
|
54
|
+
options[:address][:zip] = payment.order.bill_address.zipcode
|
55
|
+
response = provider.store(payment.source, options)
|
56
|
+
if response.success?
|
57
|
+
payment.source.update_attributes!(:gateway_customer_profile_id => response.params['payment_method_token'])
|
58
|
+
else
|
59
|
+
payment.send(:gateway_error, response.message)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::StripeGateway < Gateway
|
3
|
+
preference :secret_key, :string
|
4
|
+
preference :publishable_key, :string
|
5
|
+
|
6
|
+
def method_type
|
7
|
+
'stripe'
|
8
|
+
end
|
9
|
+
|
10
|
+
def provider_class
|
11
|
+
ActiveMerchant::Billing::StripeGateway
|
12
|
+
end
|
13
|
+
|
14
|
+
def payment_profiles_supported?
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
def purchase(money, creditcard, gateway_options)
|
19
|
+
provider.purchase(*options_for_purchase_or_auth(money, creditcard, gateway_options))
|
20
|
+
end
|
21
|
+
|
22
|
+
def authorize(money, creditcard, gateway_options)
|
23
|
+
provider.authorize(*options_for_purchase_or_auth(money, creditcard, gateway_options))
|
24
|
+
end
|
25
|
+
|
26
|
+
def capture(payment, creditcard, gateway_options)
|
27
|
+
provider.capture((payment.amount * 100).round, payment.response_code, gateway_options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def credit(money, creditcard, response_code, gateway_options)
|
31
|
+
provider.refund(money, response_code, {})
|
32
|
+
end
|
33
|
+
|
34
|
+
def void(response_code, creditcard, gateway_options)
|
35
|
+
provider.void(response_code, {})
|
36
|
+
end
|
37
|
+
|
38
|
+
def create_profile(payment)
|
39
|
+
return unless payment.source.gateway_customer_profile_id.nil?
|
40
|
+
options = {
|
41
|
+
email: payment.order.email,
|
42
|
+
login: preferred_secret_key,
|
43
|
+
}.merge! address_for(payment)
|
44
|
+
|
45
|
+
response = provider.store(payment.source, options)
|
46
|
+
if response.success?
|
47
|
+
payment.source.update_attributes!({
|
48
|
+
:gateway_customer_profile_id => response.params['id'],
|
49
|
+
:gateway_payment_profile_id => response.params['default_card']
|
50
|
+
})
|
51
|
+
else
|
52
|
+
payment.send(:gateway_error, response.message)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
# In this gateway, what we call 'secret_key' is the 'login'
|
59
|
+
def options
|
60
|
+
options = super
|
61
|
+
options.merge(:login => preferred_secret_key)
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
def options_for_purchase_or_auth(money, creditcard, gateway_options)
|
66
|
+
options = {}
|
67
|
+
options[:description] = "Spree Order ID: #{gateway_options[:order_id]}"
|
68
|
+
options[:currency] = gateway_options[:currency]
|
69
|
+
|
70
|
+
if customer = creditcard.gateway_customer_profile_id
|
71
|
+
options[:customer] = customer
|
72
|
+
end
|
73
|
+
if token_or_card_id = creditcard.gateway_payment_profile_id
|
74
|
+
# The Stripe ActiveMerchant gateway supports passing the token directly as the creditcard parameter
|
75
|
+
# The Stripe ActiveMerchant gateway supports passing the customer_id and credit_card id
|
76
|
+
# https://github.com/Shopify/active_merchant/issues/770
|
77
|
+
creditcard = token_or_card_id
|
78
|
+
end
|
79
|
+
return money, creditcard, options
|
80
|
+
end
|
81
|
+
|
82
|
+
def address_for(payment)
|
83
|
+
{}.tap do |options|
|
84
|
+
if address = payment.order.bill_address
|
85
|
+
options.merge!(address: {
|
86
|
+
address1: address.address1,
|
87
|
+
address2: address.address2,
|
88
|
+
city: address.city,
|
89
|
+
zip: address.zipcode
|
90
|
+
})
|
91
|
+
|
92
|
+
if country = address.country
|
93
|
+
options[:address].merge!(country: country.name)
|
94
|
+
end
|
95
|
+
|
96
|
+
if state = address.state
|
97
|
+
options[:address].merge!(state: state.name)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::Worldpay < Gateway
|
3
|
+
preference :login, :string
|
4
|
+
preference :password, :string
|
5
|
+
preference :currency, :string, :default => 'GBP'
|
6
|
+
preference :installation_id, :string
|
7
|
+
|
8
|
+
preference :american_express_login, :string
|
9
|
+
preference :discover_login, :string
|
10
|
+
preference :jcb_login, :string
|
11
|
+
preference :mastercard_login, :string
|
12
|
+
preference :maestro_login, :string
|
13
|
+
preference :visa_login, :string
|
14
|
+
|
15
|
+
def provider_class
|
16
|
+
ActiveMerchant::Billing::WorldpayGateway
|
17
|
+
end
|
18
|
+
|
19
|
+
def purchase(money, credit_card, options = {})
|
20
|
+
provider = credit_card_provider(credit_card, options)
|
21
|
+
provider.purchase(money, credit_card, options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def authorize(money, credit_card, options = {})
|
25
|
+
provider = credit_card_provider(credit_card, options)
|
26
|
+
provider.authorize(money, credit_card, options)
|
27
|
+
end
|
28
|
+
|
29
|
+
def capture(money, authorization, options = {})
|
30
|
+
provider = credit_card_provider(auth_credit_card(authorization), options)
|
31
|
+
provider.capture(money, authorization, options)
|
32
|
+
end
|
33
|
+
|
34
|
+
def refund(money, authorization, options = {})
|
35
|
+
provider = credit_card_provider(auth_credit_card(authorization), options)
|
36
|
+
provider.refund(money, authorization, options)
|
37
|
+
end
|
38
|
+
|
39
|
+
def credit(money, authorization, options = {})
|
40
|
+
refund(money, authorization, options)
|
41
|
+
end
|
42
|
+
|
43
|
+
def void(authorization, options = {})
|
44
|
+
provider = credit_card_provider(auth_credit_card(authorization), options)
|
45
|
+
provider.void(authorization, options)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def options_for_card(credit_card, options)
|
51
|
+
options[:login] = login_for_card(credit_card)
|
52
|
+
options = options().merge( options )
|
53
|
+
end
|
54
|
+
|
55
|
+
def auth_credit_card(authorization)
|
56
|
+
Spree::Payment.find_by_response_code(authorization).source
|
57
|
+
end
|
58
|
+
|
59
|
+
def credit_card_provider(credit_card, options = {})
|
60
|
+
gateway_options = options_for_card(credit_card, options)
|
61
|
+
gateway_options.delete :login if gateway_options.has_key?(:login) and gateway_options[:login].nil?
|
62
|
+
gateway_options[:currency] = self.preferred_currency
|
63
|
+
gateway_options[:inst_id] = self.preferred_installation_id
|
64
|
+
ActiveMerchant::Billing::Base.gateway_mode = gateway_options[:server].to_sym
|
65
|
+
@provider = provider_class.new(gateway_options)
|
66
|
+
end
|
67
|
+
|
68
|
+
def login_for_card(card)
|
69
|
+
case card.brand
|
70
|
+
when 'american_express'
|
71
|
+
choose_login preferred_american_express_login
|
72
|
+
when 'discover'
|
73
|
+
choose_login preferred_discover_login
|
74
|
+
when 'jcb'
|
75
|
+
choose_login preferred_jcb_login
|
76
|
+
when 'maestro'
|
77
|
+
choose_login preferred_maestro_login
|
78
|
+
when 'master'
|
79
|
+
choose_login preferred_mastercard_login
|
80
|
+
when 'visa'
|
81
|
+
choose_login preferred_visa_login
|
82
|
+
else
|
83
|
+
preferred_login
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def choose_login(login)
|
88
|
+
return login ? login : preferred_login
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|