spree_gateway 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +14 -0
- data/.rspec +1 -0
- data/.travis.yml +22 -0
- data/Gemfile +14 -0
- data/LICENSE +26 -0
- data/README.md +68 -0
- data/Rakefile +14 -0
- data/Versionfile +12 -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 +52 -0
- data/app/models/spree/gateway/authorize_net.rb +18 -0
- data/app/models/spree/gateway/authorize_net_cim.rb +134 -0
- data/app/models/spree/gateway/balanced_gateway.rb +68 -0
- data/app/models/spree/gateway/banwire.rb +16 -0
- data/app/models/spree/gateway/beanstream.rb +195 -0
- data/app/models/spree/gateway/braintree_gateway.rb +143 -0
- data/app/models/spree/gateway/card_save.rb +12 -0
- data/app/models/spree/gateway/data_cash.rb +12 -0
- data/app/models/spree/gateway/eway.rb +22 -0
- data/app/models/spree/gateway/fatzebra.rb +17 -0
- data/app/models/spree/gateway/klarna.rb +0 -0
- data/app/models/spree/gateway/linkpoint.rb +30 -0
- data/app/models/spree/gateway/moneris.rb +13 -0
- data/app/models/spree/gateway/pay_junction.rb +18 -0
- data/app/models/spree/gateway/pay_pal_gateway.rb +14 -0
- data/app/models/spree/gateway/payflow_pro.rb +19 -0
- data/app/models/spree/gateway/paymill.rb +15 -0
- data/app/models/spree/gateway/pin_gateway.rb +18 -0
- data/app/models/spree/gateway/sage_pay.rb +13 -0
- data/app/models/spree/gateway/samurai.rb +65 -0
- data/app/models/spree/gateway/secure_pay_au.rb +10 -0
- data/app/models/spree/gateway/stripe_gateway.rb +94 -0
- data/app/models/spree/gateway/usa_epay.rb +11 -0
- data/app/models/spree/gateway/worldpay.rb +96 -0
- data/app/models/spree/payment_decorator.rb +3 -0
- data/app/models/spree/skrill_transaction.rb +21 -0
- data/app/views/spree/admin/payments/source_forms/_quickcheckout.html.erb +8 -0
- data/app/views/spree/admin/payments/source_views/_quickcheckout.html.erb +39 -0
- data/app/views/spree/checkout/payment/_quickcheckout.html.erb +26 -0
- data/config/locales/bg.yml +11 -0
- data/config/locales/de.yml +11 -0
- data/config/locales/en.yml +11 -0
- data/config/locales/sv.yml +11 -0
- data/config/routes.rb +13 -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/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 +41 -0
- data/script/rails +5 -0
- data/spec/factories/payment_method_factory.rb +4 -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 +284 -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/spec_helper.rb +34 -0
- data/spree_gateway.gemspec +26 -0
- metadata +91 -5
@@ -0,0 +1,22 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::Eway < Gateway
|
3
|
+
preference :login, :string
|
4
|
+
|
5
|
+
attr_accessible :preferred_login
|
6
|
+
|
7
|
+
# Note: EWay supports purchase method only (no authorize method).
|
8
|
+
def auto_capture?
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
def provider_class
|
13
|
+
ActiveMerchant::Billing::EwayGateway
|
14
|
+
end
|
15
|
+
|
16
|
+
def options_with_test_preference
|
17
|
+
options_without_test_preference.merge(:test => self.preferred_test_mode)
|
18
|
+
end
|
19
|
+
|
20
|
+
alias_method_chain :options, :test_preference
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::Fatzebra < Gateway
|
3
|
+
preference :username, :string, default: "TEST"
|
4
|
+
preference :token, :string, default: "TEST"
|
5
|
+
|
6
|
+
attr_accessible :preferred_username, :preferred_token
|
7
|
+
|
8
|
+
def provider_class
|
9
|
+
ActiveMerchant::Billing::FatZebraGateway
|
10
|
+
end
|
11
|
+
|
12
|
+
# Currently no auth/capture, but coming soon...
|
13
|
+
def auto_capture?
|
14
|
+
true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
File without changes
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::Linkpoint < Gateway
|
3
|
+
preference :login, :string
|
4
|
+
preference :pem, :text
|
5
|
+
|
6
|
+
attr_accessible :preferred_login, :preferred_pem
|
7
|
+
|
8
|
+
def provider_class
|
9
|
+
ActiveMerchant::Billing::LinkpointGateway
|
10
|
+
end
|
11
|
+
|
12
|
+
[:authorize, :purchase, :capture, :void, :credit].each do |method|
|
13
|
+
define_method(method) do |*args|
|
14
|
+
options = add_discount_to_subtotal(args.extract_options!)
|
15
|
+
provider.public_send(method, *args << options)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
# Linkpoint ignores the discount, but it will return an error if the
|
22
|
+
# chargetotal is different from the sum of the subtotal, tax and
|
23
|
+
# shipping totals.
|
24
|
+
def add_discount_to_subtotal(options)
|
25
|
+
subtotal = options.fetch(:subtotal)
|
26
|
+
discount = options.fetch(:discount)
|
27
|
+
options.merge(subtotal: subtotal + discount, discount: 0)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::Moneris < Gateway
|
3
|
+
preference :login, :string
|
4
|
+
preference :password, :password
|
5
|
+
|
6
|
+
attr_accessible :preferred_login, :preferred_password
|
7
|
+
|
8
|
+
def provider_class
|
9
|
+
ActiveMerchant::Billing::MonerisGateway
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::PayJunction < Gateway
|
3
|
+
preference :login, :string
|
4
|
+
preference :password, :string
|
5
|
+
|
6
|
+
attr_accessible :preferred_login, :preferred_password
|
7
|
+
|
8
|
+
def provider_class
|
9
|
+
ActiveMerchant::Billing::PayJunctionGateway
|
10
|
+
end
|
11
|
+
|
12
|
+
def options_with_test_preference
|
13
|
+
options_without_test_preference.merge(:test => self.preferred_test_mode)
|
14
|
+
end
|
15
|
+
|
16
|
+
alias_method_chain :options, :test_preference
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,14 @@
|
|
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
|
+
attr_accessible :preferred_login, :preferred_password, :preferred_signature, :preferred_currency_code
|
9
|
+
|
10
|
+
def provider_class
|
11
|
+
ActiveMerchant::Billing::PaypalGateway
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::PayflowPro < Gateway
|
3
|
+
preference :login, :string
|
4
|
+
preference :password, :password
|
5
|
+
|
6
|
+
attr_accessible :preferred_login, :preferred_password
|
7
|
+
|
8
|
+
def provider_class
|
9
|
+
ActiveMerchant::Billing::PayflowGateway
|
10
|
+
end
|
11
|
+
|
12
|
+
def options_with_test_preference
|
13
|
+
options_without_test_preference.merge(:test => self.preferred_test_mode)
|
14
|
+
end
|
15
|
+
|
16
|
+
alias_method_chain :options, :test_preference
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::Paymill < Gateway
|
3
|
+
|
4
|
+
preference :public_key, :string
|
5
|
+
preference :private_key, :string
|
6
|
+
preference :currency, :string, :default => 'GBP'
|
7
|
+
|
8
|
+
attr_accessible :preferred_public_key, :preferred_private_key, :preferred_currency
|
9
|
+
|
10
|
+
|
11
|
+
def provider_class
|
12
|
+
ActiveMerchant::Billing::PaymillGateway
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::PinGateway < Gateway
|
3
|
+
preference :api_key, :string
|
4
|
+
preference :currency, :string, :default => 'AUD'
|
5
|
+
|
6
|
+
attr_accessible :preferred_api_key, :preferred_currency
|
7
|
+
|
8
|
+
|
9
|
+
def provider_class
|
10
|
+
ActiveMerchant::Billing::PinGateway
|
11
|
+
end
|
12
|
+
|
13
|
+
# Pin does not appear to support authorizing transactions yet
|
14
|
+
def auto_capture?
|
15
|
+
true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::SagePay < Gateway
|
3
|
+
preference :login, :string
|
4
|
+
preference :password, :string
|
5
|
+
preference :account, :string
|
6
|
+
|
7
|
+
attr_accessible :preferred_login, :preferred_password, :preferred_account
|
8
|
+
|
9
|
+
def provider_class
|
10
|
+
ActiveMerchant::Billing::SagePayGateway
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::Samurai < Gateway
|
3
|
+
preference :login, :string
|
4
|
+
preference :password, :string
|
5
|
+
preference :processor_token, :string
|
6
|
+
|
7
|
+
attr_accessible :preferred_login, :preferred_password, :preferred_processor_token
|
8
|
+
|
9
|
+
def provider_class
|
10
|
+
ActiveMerchant::Billing::SamuraiGateway
|
11
|
+
end
|
12
|
+
|
13
|
+
def payment_profiles_supported?
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
17
|
+
def purchase(money, creditcard, gateway_options)
|
18
|
+
gateway_options[:billing_reference] = gateway_options[:order_id]
|
19
|
+
gateway_options[:customer_reference] = gateway_options[:customer]
|
20
|
+
gateway_options[:description] = "Spree Order"
|
21
|
+
provider.purchase(money, creditcard.gateway_customer_profile_id, gateway_options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def authorize(money, creditcard, gateway_options)
|
25
|
+
gateway_options[:billing_reference] = gateway_options[:order_id]
|
26
|
+
gateway_options[:customer_reference] = gateway_options[:customer]
|
27
|
+
gateway_options[:description] = "Spree Order"
|
28
|
+
provider.authorize(money, creditcard.gateway_customer_profile_id, gateway_options)
|
29
|
+
end
|
30
|
+
|
31
|
+
def capture(authorization, creditcard, gateway_options)
|
32
|
+
gateway_options[:billing_reference] = gateway_options[:order_id]
|
33
|
+
gateway_options[:customer_reference] = gateway_options[:customer]
|
34
|
+
gateway_options[:description] = "Spree Order"
|
35
|
+
provider.capture(nil, authorization.response_code, {})
|
36
|
+
end
|
37
|
+
|
38
|
+
def credit(money, creditcard, response_code, gateway_options)
|
39
|
+
provider.credit(money, response_code, {})
|
40
|
+
end
|
41
|
+
|
42
|
+
def void(response_code, gateway_options)
|
43
|
+
provider.void(response_code, {})
|
44
|
+
end
|
45
|
+
|
46
|
+
def create_profile(payment)
|
47
|
+
return unless payment.source.gateway_customer_profile_id.nil?
|
48
|
+
|
49
|
+
options = {}
|
50
|
+
options[:email] = payment.order.email
|
51
|
+
options[:address] = {}
|
52
|
+
options[:address][:address1] = payment.order.bill_address.address1
|
53
|
+
options[:address][:address2] = payment.order.bill_address.address2
|
54
|
+
options[:address][:city] = payment.order.bill_address.city
|
55
|
+
options[:address][:state] = payment.order.bill_address.state.abbr
|
56
|
+
options[:address][:zip] = payment.order.bill_address.zipcode
|
57
|
+
response = provider.store(payment.source, options)
|
58
|
+
if response.success?
|
59
|
+
payment.source.update_attributes!(:gateway_customer_profile_id => response.params['payment_method_token'])
|
60
|
+
else
|
61
|
+
payment.send(:gateway_error, response.message)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::StripeGateway < Gateway
|
3
|
+
preference :login, :string
|
4
|
+
|
5
|
+
attr_accessible :preferred_login, :preferred_currency
|
6
|
+
|
7
|
+
def provider_class
|
8
|
+
ActiveMerchant::Billing::StripeGateway
|
9
|
+
end
|
10
|
+
|
11
|
+
def payment_profiles_supported?
|
12
|
+
true
|
13
|
+
end
|
14
|
+
|
15
|
+
def purchase(money, creditcard, gateway_options)
|
16
|
+
provider.purchase(*options_for_purchase_or_auth(money, creditcard, gateway_options))
|
17
|
+
end
|
18
|
+
|
19
|
+
def authorize(money, creditcard, gateway_options)
|
20
|
+
provider.authorize(*options_for_purchase_or_auth(money, creditcard, gateway_options))
|
21
|
+
end
|
22
|
+
|
23
|
+
def capture(payment, creditcard, gateway_options)
|
24
|
+
provider.capture((payment.amount * 100).round, payment.response_code, gateway_options)
|
25
|
+
end
|
26
|
+
|
27
|
+
def credit(money, creditcard, response_code, gateway_options)
|
28
|
+
provider.refund(money, response_code, {})
|
29
|
+
end
|
30
|
+
|
31
|
+
def void(response_code, creditcard, gateway_options)
|
32
|
+
provider.void(response_code, {})
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_profile(payment)
|
36
|
+
return unless payment.source.gateway_customer_profile_id.nil?
|
37
|
+
|
38
|
+
options = {
|
39
|
+
email: payment.order.email,
|
40
|
+
login: preferred_login
|
41
|
+
}.merge! address_for(payment)
|
42
|
+
|
43
|
+
response = provider.store(payment.source, options)
|
44
|
+
if response.success?
|
45
|
+
payment.source.update_attributes!({
|
46
|
+
:gateway_customer_profile_id => response.params['id'],
|
47
|
+
:gateway_payment_profile_id => response.params['default_card']
|
48
|
+
})
|
49
|
+
else
|
50
|
+
payment.send(:gateway_error, response.message)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def options_for_purchase_or_auth(money, creditcard, gateway_options)
|
57
|
+
options = {}
|
58
|
+
options[:description] = "Spree Order ID: #{gateway_options[:order_id]}"
|
59
|
+
options[:currency] = gateway_options[:currency]
|
60
|
+
|
61
|
+
if customer = creditcard.gateway_customer_profile_id
|
62
|
+
options[:customer] = customer
|
63
|
+
end
|
64
|
+
if token_or_card_id = creditcard.gateway_payment_profile_id
|
65
|
+
# The Stripe ActiveMerchant gateway supports passing the token directly as the creditcard parameter
|
66
|
+
# The Stripe ActiveMerchant gateway supports passing the customer_id and credit_card id
|
67
|
+
# https://github.com/Shopify/active_merchant/issues/770
|
68
|
+
creditcard = token_or_card_id
|
69
|
+
end
|
70
|
+
return money, creditcard, options
|
71
|
+
end
|
72
|
+
|
73
|
+
def address_for(payment)
|
74
|
+
{}.tap do |options|
|
75
|
+
if address = payment.order.bill_address
|
76
|
+
options.merge!(address: {
|
77
|
+
address1: address.address1,
|
78
|
+
address2: address.address2,
|
79
|
+
city: address.city,
|
80
|
+
zip: address.zipcode
|
81
|
+
})
|
82
|
+
|
83
|
+
if country = address.country
|
84
|
+
options[:address].merge!(country: country.name)
|
85
|
+
end
|
86
|
+
|
87
|
+
if state = address.state
|
88
|
+
options[:address].merge!(state: state.name)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,96 @@
|
|
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
|
+
attr_accessible :preferred_login, :preferred_password, :preferred_currency,
|
16
|
+
:preferred_installation_id, :preferred_american_express_login,
|
17
|
+
:preferred_discover_login, :preferred_jcb_login, :preferred_maestro_login,
|
18
|
+
:preferred_mastercard_login, :preferred_visa_login
|
19
|
+
|
20
|
+
def provider_class
|
21
|
+
ActiveMerchant::Billing::WorldpayGateway
|
22
|
+
end
|
23
|
+
|
24
|
+
def purchase(money, credit_card, options = {})
|
25
|
+
provider = credit_card_provider(credit_card, options)
|
26
|
+
provider.purchase(money, credit_card, options)
|
27
|
+
end
|
28
|
+
|
29
|
+
def authorize(money, credit_card, options = {})
|
30
|
+
provider = credit_card_provider(credit_card, options)
|
31
|
+
provider.authorize(money, credit_card, options)
|
32
|
+
end
|
33
|
+
|
34
|
+
def capture(money, authorization, options = {})
|
35
|
+
provider = credit_card_provider(auth_credit_card(authorization), options)
|
36
|
+
provider.capture(money, authorization, options)
|
37
|
+
end
|
38
|
+
|
39
|
+
def refund(money, authorization, options = {})
|
40
|
+
provider = credit_card_provider(auth_credit_card(authorization), options)
|
41
|
+
provider.refund(money, authorization, options)
|
42
|
+
end
|
43
|
+
|
44
|
+
def credit(money, authorization, options = {})
|
45
|
+
refund(money, authorization, options)
|
46
|
+
end
|
47
|
+
|
48
|
+
def void(authorization, options = {})
|
49
|
+
provider = credit_card_provider(auth_credit_card(authorization), options)
|
50
|
+
provider.void(authorization, options)
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def options_for_card(credit_card, options)
|
56
|
+
options[:login] = login_for_card(credit_card)
|
57
|
+
options = options().merge( options )
|
58
|
+
end
|
59
|
+
|
60
|
+
def auth_credit_card(authorization)
|
61
|
+
Spree::Payment.find_by_response_code(authorization).source
|
62
|
+
end
|
63
|
+
|
64
|
+
def credit_card_provider(credit_card, options = {})
|
65
|
+
gateway_options = options_for_card(credit_card, options)
|
66
|
+
gateway_options.delete :login if gateway_options.has_key?(:login) and gateway_options[:login].nil?
|
67
|
+
gateway_options[:currency] = self.preferred_currency
|
68
|
+
gateway_options[:inst_id] = self.preferred_installation_id
|
69
|
+
ActiveMerchant::Billing::Base.gateway_mode = gateway_options[:server].to_sym
|
70
|
+
@provider = provider_class.new(gateway_options)
|
71
|
+
end
|
72
|
+
|
73
|
+
def login_for_card(card)
|
74
|
+
case card.brand
|
75
|
+
when 'american_express'
|
76
|
+
choose_login preferred_american_express_login
|
77
|
+
when 'discover'
|
78
|
+
choose_login preferred_discover_login
|
79
|
+
when 'jcb'
|
80
|
+
choose_login preferred_jcb_login
|
81
|
+
when 'maestro'
|
82
|
+
choose_login preferred_maestro_login
|
83
|
+
when 'master'
|
84
|
+
choose_login preferred_mastercard_login
|
85
|
+
when 'visa'
|
86
|
+
choose_login preferred_visa_login
|
87
|
+
else
|
88
|
+
preferred_login
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def choose_login(login)
|
93
|
+
return login ? login : preferred_login
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|