solidus_gateway 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +23 -0
  5. data/Gemfile +9 -0
  6. data/LICENSE.md +26 -0
  7. data/README.md +38 -0
  8. data/Rakefile +21 -0
  9. data/app/models/spree/billing_integration/skrill/quick_checkout.rb +48 -0
  10. data/app/models/spree/gateway/authorize_net.rb +31 -0
  11. data/app/models/spree/gateway/authorize_net_cim.rb +201 -0
  12. data/app/models/spree/gateway/balanced_gateway.rb +65 -0
  13. data/app/models/spree/gateway/banwire.rb +15 -0
  14. data/app/models/spree/gateway/beanstream.rb +193 -0
  15. data/app/models/spree/gateway/braintree_gateway.rb +184 -0
  16. data/app/models/spree/gateway/card_save.rb +10 -0
  17. data/app/models/spree/gateway/data_cash.rb +10 -0
  18. data/app/models/spree/gateway/eway.rb +20 -0
  19. data/app/models/spree/gateway/linkpoint.rb +28 -0
  20. data/app/models/spree/gateway/maxipago.rb +14 -0
  21. data/app/models/spree/gateway/migs.rb +11 -0
  22. data/app/models/spree/gateway/moneris.rb +10 -0
  23. data/app/models/spree/gateway/pay_junction.rb +16 -0
  24. data/app/models/spree/gateway/pay_pal_gateway.rb +12 -0
  25. data/app/models/spree/gateway/payflow_pro.rb +18 -0
  26. data/app/models/spree/gateway/paymill.rb +12 -0
  27. data/app/models/spree/gateway/pin_gateway.rb +60 -0
  28. data/app/models/spree/gateway/sage_pay.rb +11 -0
  29. data/app/models/spree/gateway/secure_pay_au.rb +10 -0
  30. data/app/models/spree/gateway/spreedly_core_gateway.rb +10 -0
  31. data/app/models/spree/gateway/stripe_gateway.rb +126 -0
  32. data/app/models/spree/gateway/usa_epay.rb +9 -0
  33. data/app/models/spree/gateway/worldpay.rb +91 -0
  34. data/app/models/spree/skrill_transaction.rb +19 -0
  35. data/bin/rails +7 -0
  36. data/circle.yml +6 -0
  37. data/config/locales/bg.yml +11 -0
  38. data/config/locales/de.yml +11 -0
  39. data/config/locales/en.yml +30 -0
  40. data/config/locales/sv.yml +11 -0
  41. data/config/routes.rb +12 -0
  42. data/db/migrate/20111118164631_create_skrill_transactions.rb +14 -0
  43. data/db/migrate/20121017004102_update_braintree_payment_method_type.rb +9 -0
  44. data/db/migrate/20130213222555_update_stripe_payment_method_type.rb +9 -0
  45. data/db/migrate/20130415222802_update_balanced_payment_method_type.rb +9 -0
  46. data/db/migrate/20131008221012_update_paypal_payment_method_type.rb +9 -0
  47. data/db/migrate/20131112133401_migrate_stripe_preferences.rb +8 -0
  48. data/lib/active_merchant/billing/skrill.rb +18 -0
  49. data/lib/assets/javascripts/spree/frontend/solidus_gateway.js +1 -0
  50. data/lib/assets/stylesheets/spree/frontend/solidus_gateway.css +3 -0
  51. data/lib/controllers/frontend/spree/checkout_controller_decorator.rb +51 -0
  52. data/lib/controllers/frontend/spree/skrill_status_controller.rb +39 -0
  53. data/lib/generators/solidus_gateway/install/install_generator.rb +28 -0
  54. data/lib/solidus_gateway.rb +4 -0
  55. data/lib/spree_gateway/engine.rb +67 -0
  56. data/lib/views/backend/spree/admin/log_entries/_braintree.html.erb +31 -0
  57. data/lib/views/backend/spree/admin/log_entries/_stripe.html.erb +28 -0
  58. data/lib/views/backend/spree/admin/payments/source_forms/_quickcheckout.html.erb +8 -0
  59. data/lib/views/backend/spree/admin/payments/source_forms/_stripe.html.erb +1 -0
  60. data/lib/views/backend/spree/admin/payments/source_views/_quickcheckout.html.erb +39 -0
  61. data/lib/views/backend/spree/admin/payments/source_views/_stripe.html.erb +1 -0
  62. data/lib/views/frontend/spree/checkout/payment/_quickcheckout.html.erb +26 -0
  63. data/lib/views/frontend/spree/checkout/payment/_stripe.html.erb +80 -0
  64. data/solidus_gateway.gemspec +33 -0
  65. data/spec/factories/skrill_factory.rb +6 -0
  66. data/spec/features/stripe_checkout_spec.rb +78 -0
  67. data/spec/lib/active_merchant/billing_skrill_spec.rb +18 -0
  68. data/spec/models/billing_integration/skrill_quick_checkout_spec.rb +11 -0
  69. data/spec/models/gateway/authorize_net_cim_spec.rb +29 -0
  70. data/spec/models/gateway/authorize_net_spec.rb +23 -0
  71. data/spec/models/gateway/balanced_gateway_spec.rb +17 -0
  72. data/spec/models/gateway/banwire_spec.rb +11 -0
  73. data/spec/models/gateway/beanstream_spec.rb +17 -0
  74. data/spec/models/gateway/braintree_gateway_spec.rb +437 -0
  75. data/spec/models/gateway/card_save_spec.rb +11 -0
  76. data/spec/models/gateway/data_cache_spec.rb +11 -0
  77. data/spec/models/gateway/eway_spec.rb +29 -0
  78. data/spec/models/gateway/linkpoint_spec.rb +62 -0
  79. data/spec/models/gateway/maxipago_spec.rb +17 -0
  80. data/spec/models/gateway/moneris_spec.rb +11 -0
  81. data/spec/models/gateway/pay_junction_spec.rb +23 -0
  82. data/spec/models/gateway/pay_pal_spec.rb +11 -0
  83. data/spec/models/gateway/payflow_pro_spec.rb +23 -0
  84. data/spec/models/gateway/paymill_spec.rb +11 -0
  85. data/spec/models/gateway/pin_gateway_spec.rb +55 -0
  86. data/spec/models/gateway/sage_pay_spec.rb +11 -0
  87. data/spec/models/gateway/secure_pay_au_spec.rb +11 -0
  88. data/spec/models/gateway/stripe_gateway_spec.rb +200 -0
  89. data/spec/models/gateway/usa_epay_spec.rb +49 -0
  90. data/spec/models/gateway/worldpay_spec.rb +11 -0
  91. data/spec/models/skrill_transaction_spec.rb +9 -0
  92. data/spec/spec_helper.rb +50 -0
  93. metadata +317 -0
@@ -0,0 +1,14 @@
1
+ module Spree
2
+ class Gateway::Maxipago < Gateway
3
+ preference :login, :string # ID
4
+ preference :password, :string # KEY
5
+
6
+ def provider_class
7
+ ActiveMerchant::Billing::MaxipagoGateway
8
+ end
9
+
10
+ def auto_capture?
11
+ true
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module Spree
2
+ class Gateway::Migs < Gateway
3
+ preference :login, :string
4
+ preference :password, :string
5
+ preference :secure_hash, :string
6
+
7
+ def provider_class
8
+ ActiveMerchant::Billing::MigsGateway
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module Spree
2
+ class Gateway::Moneris < Gateway
3
+ preference :login, :string
4
+ preference :password, :password
5
+
6
+ def provider_class
7
+ ActiveMerchant::Billing::MonerisGateway
8
+ end
9
+ end
10
+ 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,18 @@
1
+ module Spree
2
+ class Gateway::PayflowPro < Gateway
3
+ preference :login, :string
4
+ preference :password, :password
5
+ preference :partner, :string
6
+
7
+ def provider_class
8
+ ActiveMerchant::Billing::PayflowGateway
9
+ end
10
+
11
+ def options_with_test_preference
12
+ options_without_test_preference.merge(:test => self.preferred_test_mode)
13
+ end
14
+
15
+ alias_method_chain :options, :test_preference
16
+
17
+ end
18
+ end
@@ -0,0 +1,12 @@
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
+ def provider_class
9
+ ActiveMerchant::Billing::PaymillGateway
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,60 @@
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
+ def purchase(money, creditcard, options = {})
11
+ super(money, creditcard.try(:gateway_customer_profile_id) || creditcard.try(:gateway_payment_profile_id) || creditcard, options)
12
+ end
13
+
14
+ def create_profile(payment)
15
+ if payment.source.gateway_customer_profile_id.nil?
16
+ response = provider.store(payment.source, options_for_payment(payment))
17
+
18
+ if response.success?
19
+ payment.source.update_attributes!(:gateway_customer_profile_id => response.authorization)
20
+
21
+ cc = response.params['response']['card']
22
+ payment.source.update_attributes!(:gateway_payment_profile_id => cc['token']) if cc
23
+ else
24
+ payment.send(:gateway_error, response.message)
25
+ end
26
+ end
27
+ end
28
+
29
+ # Pin does not appear to support authorizing transactions yet
30
+ def auto_capture?
31
+ true
32
+ end
33
+
34
+ def payment_profiles_supported?
35
+ true
36
+ end
37
+
38
+ private
39
+
40
+ def options_for_payment(p)
41
+ o = Hash.new
42
+ o[:email] = p.order.email
43
+
44
+ if p.order.bill_address
45
+ bill_addr = p.order.bill_address
46
+
47
+ o[:billing_address] = {
48
+ address1: bill_addr.address1,
49
+ city: bill_addr.city,
50
+ state: bill_addr.state ? bill_addr.state.name : bill_addr.state_name,
51
+ country: bill_addr.country.iso3,
52
+ zip: bill_addr.zipcode
53
+ }
54
+ end
55
+
56
+ return o
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,11 @@
1
+ module Spree
2
+ class Gateway::SagePay < Gateway
3
+ preference :login, :string
4
+ preference :password, :string
5
+ preference :account, :string
6
+
7
+ def provider_class
8
+ ActiveMerchant::Billing::SagePayGateway
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module Spree
2
+ class Gateway::SecurePayAU < Gateway
3
+ preference :login, :string
4
+ preference :password, :string
5
+
6
+ def provider_class
7
+ ActiveMerchant::Billing::SecurePayAuGateway
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Spree
2
+ class Gateway::SpreedlyCoreGateway < Gateway
3
+ preference :login, :string
4
+ preference :password, :string
5
+ preference :gateway_token, :string
6
+ def provider_class
7
+ ActiveMerchant::Billing::SpreedlyCoreGateway
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,126 @@
1
+ module Spree
2
+ class Gateway::StripeGateway < Gateway
3
+ preference :secret_key, :string
4
+ preference :publishable_key, :string
5
+
6
+ CARD_TYPE_MAPPING = {
7
+ 'American Express' => 'american_express',
8
+ 'Diners Club' => 'diners_club',
9
+ 'Visa' => 'visa'
10
+ }
11
+
12
+ def method_type
13
+ 'stripe'
14
+ end
15
+
16
+ def provider_class
17
+ ActiveMerchant::Billing::StripeGateway
18
+ end
19
+
20
+ def payment_profiles_supported?
21
+ true
22
+ end
23
+
24
+ def purchase(money, creditcard, gateway_options)
25
+ provider.purchase(*options_for_purchase_or_auth(money, creditcard, gateway_options))
26
+ end
27
+
28
+ def authorize(money, creditcard, gateway_options)
29
+ provider.authorize(*options_for_purchase_or_auth(money, creditcard, gateway_options))
30
+ end
31
+
32
+ def capture(money, response_code, gateway_options)
33
+ provider.capture(money, response_code, gateway_options)
34
+ end
35
+
36
+ def credit(money, creditcard, response_code, gateway_options)
37
+ provider.refund(money, response_code, {})
38
+ end
39
+
40
+ def void(response_code, creditcard, gateway_options)
41
+ provider.void(response_code, {})
42
+ end
43
+
44
+ def cancel(response_code)
45
+ provider.void(response_code, {})
46
+ end
47
+
48
+ def create_profile(payment)
49
+ return unless payment.source.gateway_customer_profile_id.nil?
50
+ options = {
51
+ email: payment.order.email,
52
+ login: preferred_secret_key,
53
+ }.merge! address_for(payment)
54
+
55
+ source = update_source!(payment.source)
56
+ if source.number.blank? && source.gateway_payment_profile_id.present?
57
+ creditcard = source.gateway_payment_profile_id
58
+ else
59
+ creditcard = source
60
+ end
61
+
62
+ response = provider.store(creditcard, options)
63
+ if response.success?
64
+ payment.source.update_attributes!({
65
+ cc_type: payment.source.cc_type, # side-effect of update_source!
66
+ gateway_customer_profile_id: response.params['id'],
67
+ gateway_payment_profile_id: response.params['default_source'] || response.params['default_card']
68
+ })
69
+
70
+ else
71
+ payment.send(:gateway_error, response.message)
72
+ end
73
+ end
74
+
75
+ private
76
+
77
+ # In this gateway, what we call 'secret_key' is the 'login'
78
+ def options
79
+ options = super
80
+ options.merge(:login => preferred_secret_key)
81
+ end
82
+
83
+ def options_for_purchase_or_auth(money, creditcard, gateway_options)
84
+ options = {}
85
+ options[:description] = "Spree Order ID: #{gateway_options[:order_id]}"
86
+ options[:currency] = gateway_options[:currency]
87
+
88
+ if customer = creditcard.gateway_customer_profile_id
89
+ options[:customer] = customer
90
+ end
91
+ if token_or_card_id = creditcard.gateway_payment_profile_id
92
+ # The Stripe ActiveMerchant gateway supports passing the token directly as the creditcard parameter
93
+ # The Stripe ActiveMerchant gateway supports passing the customer_id and credit_card id
94
+ # https://github.com/Shopify/active_merchant/issues/770
95
+ creditcard = token_or_card_id
96
+ end
97
+ return money, creditcard, options
98
+ end
99
+
100
+ def address_for(payment)
101
+ {}.tap do |options|
102
+ if address = payment.order.bill_address
103
+ options.merge!(address: {
104
+ address1: address.address1,
105
+ address2: address.address2,
106
+ city: address.city,
107
+ zip: address.zipcode
108
+ })
109
+
110
+ if country = address.country
111
+ options[:address].merge!(country: country.name)
112
+ end
113
+
114
+ if state = address.state
115
+ options[:address].merge!(state: state.name)
116
+ end
117
+ end
118
+ end
119
+ end
120
+
121
+ def update_source!(source)
122
+ source.cc_type = CARD_TYPE_MAPPING[source.cc_type] if CARD_TYPE_MAPPING.include?(source.cc_type)
123
+ source
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,9 @@
1
+ module Spree
2
+ class Gateway::UsaEpay < Gateway
3
+ preference :login, :string
4
+
5
+ def provider_class
6
+ ActiveMerchant::Billing::UsaEpayGateway
7
+ end
8
+ end
9
+ 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
@@ -0,0 +1,19 @@
1
+ module Spree
2
+ class SkrillTransaction < ActiveRecord::Base
3
+ has_many :payments, :as => :source
4
+
5
+ def actions
6
+ []
7
+ end
8
+
9
+ def self.create_from_postback(params)
10
+ SkrillTransaction.create(:email => params[:pay_from_email],
11
+ :amount => params[:mb_amount],
12
+ :currency => params[:mb_currency],
13
+ :transaction_id => params[:mb_transaction_id],
14
+ :customer_id => params[:customer_id],
15
+ :payment_type => params[:payment_type])
16
+ end
17
+
18
+ end
19
+ end