spree_gateway 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +14 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +22 -0
  5. data/Gemfile +14 -0
  6. data/LICENSE +26 -0
  7. data/README.md +68 -0
  8. data/Rakefile +14 -0
  9. data/Versionfile +12 -0
  10. data/app/controllers/spree/checkout_controller_decorator.rb +51 -0
  11. data/app/controllers/spree/skrill_status_controller.rb +39 -0
  12. data/app/models/spree/billing_integration/skrill/quick_checkout.rb +52 -0
  13. data/app/models/spree/gateway/authorize_net.rb +18 -0
  14. data/app/models/spree/gateway/authorize_net_cim.rb +134 -0
  15. data/app/models/spree/gateway/balanced_gateway.rb +68 -0
  16. data/app/models/spree/gateway/banwire.rb +16 -0
  17. data/app/models/spree/gateway/beanstream.rb +195 -0
  18. data/app/models/spree/gateway/braintree_gateway.rb +143 -0
  19. data/app/models/spree/gateway/card_save.rb +12 -0
  20. data/app/models/spree/gateway/data_cash.rb +12 -0
  21. data/app/models/spree/gateway/eway.rb +22 -0
  22. data/app/models/spree/gateway/fatzebra.rb +17 -0
  23. data/app/models/spree/gateway/klarna.rb +0 -0
  24. data/app/models/spree/gateway/linkpoint.rb +30 -0
  25. data/app/models/spree/gateway/moneris.rb +13 -0
  26. data/app/models/spree/gateway/pay_junction.rb +18 -0
  27. data/app/models/spree/gateway/pay_pal_gateway.rb +14 -0
  28. data/app/models/spree/gateway/payflow_pro.rb +19 -0
  29. data/app/models/spree/gateway/paymill.rb +15 -0
  30. data/app/models/spree/gateway/pin_gateway.rb +18 -0
  31. data/app/models/spree/gateway/sage_pay.rb +13 -0
  32. data/app/models/spree/gateway/samurai.rb +65 -0
  33. data/app/models/spree/gateway/secure_pay_au.rb +10 -0
  34. data/app/models/spree/gateway/stripe_gateway.rb +94 -0
  35. data/app/models/spree/gateway/usa_epay.rb +11 -0
  36. data/app/models/spree/gateway/worldpay.rb +96 -0
  37. data/app/models/spree/payment_decorator.rb +3 -0
  38. data/app/models/spree/skrill_transaction.rb +21 -0
  39. data/app/views/spree/admin/payments/source_forms/_quickcheckout.html.erb +8 -0
  40. data/app/views/spree/admin/payments/source_views/_quickcheckout.html.erb +39 -0
  41. data/app/views/spree/checkout/payment/_quickcheckout.html.erb +26 -0
  42. data/config/locales/bg.yml +11 -0
  43. data/config/locales/de.yml +11 -0
  44. data/config/locales/en.yml +11 -0
  45. data/config/locales/sv.yml +11 -0
  46. data/config/routes.rb +13 -0
  47. data/db/migrate/20111118164631_create_skrill_transactions.rb +14 -0
  48. data/db/migrate/20121017004102_update_braintree_payment_method_type.rb +9 -0
  49. data/db/migrate/20130213222555_update_stripe_payment_method_type.rb +9 -0
  50. data/db/migrate/20130415222802_update_balanced_payment_method_type.rb +9 -0
  51. data/db/migrate/20131008221012_update_paypal_payment_method_type.rb +9 -0
  52. data/lib/active_merchant/billing/skrill.rb +18 -0
  53. data/lib/generators/spree_gateway/install/install_generator.rb +28 -0
  54. data/lib/spree_gateway.rb +3 -0
  55. data/lib/spree_gateway/engine.rb +41 -0
  56. data/script/rails +5 -0
  57. data/spec/factories/payment_method_factory.rb +4 -0
  58. data/spec/models/gateway/authorize_net_cim_spec.rb +17 -0
  59. data/spec/models/gateway/authorize_net_spec.rb +17 -0
  60. data/spec/models/gateway/balanced_gateway_spec.rb +9 -0
  61. data/spec/models/gateway/banwire_spec.rb +9 -0
  62. data/spec/models/gateway/braintree_gateway_spec.rb +284 -0
  63. data/spec/models/gateway/eway_spec.rb +17 -0
  64. data/spec/models/gateway/fatzebra_spec.rb +47 -0
  65. data/spec/models/gateway/linkpoint_spec.rb +60 -0
  66. data/spec/models/gateway/pay_junction_spec.rb +17 -0
  67. data/spec/models/gateway/payflow_pro_spec.rb +17 -0
  68. data/spec/models/gateway/pin_gateway_spec.rb +57 -0
  69. data/spec/models/gateway/stripe_gateway_spec.rb +122 -0
  70. data/spec/models/gateway/usa_epay_spec.rb +38 -0
  71. data/spec/spec_helper.rb +34 -0
  72. data/spree_gateway.gemspec +26 -0
  73. metadata +91 -5
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Gateway::Eway do
4
+ let (:gateway) { Spree::Gateway::Eway.create!(:name => "Eway") }
5
+
6
+ describe "options" do
7
+ it "should include :test => true in when :test_mode is true" do
8
+ gateway.preferred_test_mode = true
9
+ gateway.options[:test].should == true
10
+ end
11
+
12
+ it "should not include :test when test_mode is false" do
13
+ gateway.preferred_test_mode = false
14
+ gateway.options[:test].should == false
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Gateway::Fatzebra do
4
+
5
+ before(:each) do
6
+ Spree::Gateway.update_all :active => false
7
+ @gateway = Spree::Gateway::Fatzebra.create!(:name => "Fat Zebra Gateway", :environment => "sandbox", :active => true)
8
+
9
+ @gateway.set_preference(:username, "TEST")
10
+ @gateway.set_preference(:token, "TEST")
11
+ @gateway.save!
12
+
13
+ @country = FactoryGirl.create(:country, :name => "Australia", :iso_name => "Australia", :iso3 => "AUS", :iso => "AU", :numcode => 61)
14
+ @state = FactoryGirl.create(:state, :name => "Victoria", :abbr => "VIC", :country => @country)
15
+ @address = FactoryGirl.create(:address,
16
+ :firstname => 'Ronald C',
17
+ :lastname => 'Robot',
18
+ :address1 => '1234 My Street',
19
+ :address2 => 'Apt 1',
20
+ :city => 'Melbourne',
21
+ :zipcode => '3000',
22
+ :phone => '88888888',
23
+ :state => @state,
24
+ :country => @country
25
+ )
26
+ @order = FactoryGirl.create(:order_with_totals, :bill_address => @address, :ship_address => @address, :last_ip_address => "127.0.0.1")
27
+ @order.update!
28
+ @credit_card = FactoryGirl.create(:credit_card,
29
+ :verification_value => '123',
30
+ :number => '5123456789012346',
31
+ :month => 5,
32
+ :year => Time.now.year + 1,
33
+ :first_name => 'Ronald C',
34
+ :last_name => 'Robot'
35
+ )
36
+ @payment = FactoryGirl.create(:payment,
37
+ :source => @credit_card,
38
+ :order => @order,
39
+ :payment_method => @gateway, :amount => 10.00)
40
+ @payment.payment_method.environment = "test"
41
+ end
42
+
43
+ it "can purchase" do
44
+ @payment.purchase!
45
+ @payment.state.should == 'completed'
46
+ end
47
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Gateway::Linkpoint do
4
+ let(:gateway) { Spree::Gateway::Linkpoint.create!(:name => "Linkpoint") }
5
+ let(:provider) { double('provider') }
6
+ let(:money) { double('money') }
7
+ let(:credit_card) { double('credit_card') }
8
+ let(:identification) { double('identification') }
9
+ let(:options) { { subtotal: 3, discount: -1 } }
10
+
11
+ before do
12
+ gateway.provider_class.stub(new: provider)
13
+ end
14
+
15
+ it "should be Linkpoint gateway" do
16
+ gateway.provider_class.should == ::ActiveMerchant::Billing::LinkpointGateway
17
+ end
18
+
19
+ describe "#authorize" do
20
+ it "adds the discount to the subtotal" do
21
+ provider.should_receive(:authorize)
22
+ .with(money, credit_card, subtotal: 2, discount: 0)
23
+ gateway.authorize(money, credit_card, options)
24
+ end
25
+ end
26
+
27
+ describe "#purchase" do
28
+ it "adds the discount to the subtotal" do
29
+ provider.should_receive(:purchase)
30
+ .with(money, credit_card, subtotal: 2, discount: 0)
31
+ gateway.purchase(money, credit_card, options)
32
+ end
33
+ end
34
+
35
+ describe "#capture" do
36
+ let(:authorization) { double('authorization') }
37
+
38
+ it "adds the discount to the subtotal" do
39
+ provider.should_receive(:capture)
40
+ .with(money, authorization, subtotal: 2, discount: 0)
41
+ gateway.capture(money, authorization, options)
42
+ end
43
+ end
44
+
45
+ describe "#void" do
46
+ it "adds the discount to the subtotal" do
47
+ provider.should_receive(:void)
48
+ .with(identification, subtotal: 2, discount: 0)
49
+ gateway.void(identification, options)
50
+ end
51
+ end
52
+
53
+ describe "#credit" do
54
+ it "adds the discount to the subtotal" do
55
+ provider.should_receive(:credit)
56
+ .with(money, identification, subtotal: 2, discount: 0)
57
+ gateway.credit(money, identification, options)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Gateway::PayJunction do
4
+ let (:gateway) { Spree::Gateway::PayJunction.create!(:name => "PayJunction") }
5
+
6
+ describe "options" do
7
+ it "should include :test => true in when :test_mode is true" do
8
+ gateway.preferred_test_mode = true
9
+ gateway.options[:test].should == true
10
+ end
11
+
12
+ it "should not include :test when test_mode is false" do
13
+ gateway.preferred_test_mode = false
14
+ gateway.options[:test].should == false
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Gateway::PayflowPro do
4
+ let (:gateway) { Spree::Gateway::PayflowPro.create!(:name => "PayflowPro") }
5
+
6
+ describe "options" do
7
+ it "should include :test => true when :test_mode is true" do
8
+ gateway.preferred_test_mode = true
9
+ gateway.options[:test].should == true
10
+ end
11
+
12
+ it "should not include :test when test_mode is false" do
13
+ gateway.preferred_test_mode = false
14
+ gateway.options[:test].should == false
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Gateway::PinGateway do
4
+
5
+ before(:each) do
6
+ Spree::Gateway.update_all :active => false
7
+ @gateway = Spree::Gateway::PinGateway.create!(:name => "Pin Gateway", :environment => "sandbox", :active => true)
8
+
9
+ @gateway.set_preference(:api_key, "W_VzkRCZSILiKWUS-dndUg" )
10
+ @gateway.save!
11
+
12
+ @country = FactoryGirl.create(:country, :name => "Australia", :iso_name => "Australia", :iso3 => "AUS", :iso => "AU", :numcode => 61)
13
+ @state = FactoryGirl.create(:state, :name => "Victoria", :abbr => "VIC", :country => @country)
14
+ @address = FactoryGirl.create(:address,
15
+ :firstname => 'Ronald C',
16
+ :lastname => 'Robot',
17
+ :address1 => '1234 My Street',
18
+ :address2 => 'Apt 1',
19
+ :city => 'Melbourne',
20
+ :zipcode => '3000',
21
+ :phone => '88888888',
22
+ :state => @state,
23
+ :country => @country
24
+ )
25
+ @order = FactoryGirl.create(:order_with_totals, :bill_address => @address, :ship_address => @address)
26
+ @order.update!
27
+ @credit_card = FactoryGirl.create(:credit_card,
28
+ :verification_value => '123',
29
+ :number => '5520000000000000',
30
+ :month => 5,
31
+ :year => Time.now.year + 1,
32
+ :first_name => 'Ronald C',
33
+ :last_name => 'Robot',
34
+ :cc_type => 'master'
35
+ )
36
+ @payment = FactoryGirl.create(:payment,
37
+ :source => @credit_card,
38
+ :order => @order,
39
+ :payment_method => @gateway, :amount => 10.00)
40
+ @payment.payment_method.environment = "test"
41
+ end
42
+
43
+ it "can purchase" do
44
+ @payment.purchase!
45
+ @payment.state.should == 'completed'
46
+ end
47
+
48
+ # Regression test for #106
49
+ it "uses auto capturing" do
50
+ expect(@gateway.auto_capture?).to be_true
51
+ end
52
+
53
+ it "always uses purchase" do
54
+ @payment.should_receive(:purchase!)
55
+ @payment.process!
56
+ end
57
+ end
@@ -0,0 +1,122 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Gateway::StripeGateway do
4
+ let(:login) { 'nothing' }
5
+ let(:email) { 'customer@example.com' }
6
+
7
+ let(:payment) {
8
+ double('Spree::Payment',
9
+ source: double('Source', gateway_customer_profile_id: nil).as_null_object,
10
+ order: double('Spree::Order',
11
+ email: email,
12
+ bill_address: bill_address
13
+ )
14
+ )
15
+ }
16
+
17
+ let(:provider) do
18
+ double('provider').tap do |p|
19
+ p.stub(:purchase)
20
+ p.stub(:authorize)
21
+ p.stub(:capture)
22
+ end
23
+ end
24
+
25
+ before do
26
+ subject.set_preference :login, login
27
+ subject.stub(:options_for_purchase_or_auth).and_return(['money','cc','opts'])
28
+ subject.stub(:provider).and_return provider
29
+ end
30
+
31
+ describe '#create_profile' do
32
+ context 'with an order that has a bill address' do
33
+ let(:bill_address) {
34
+ double('Spree::Address',
35
+ address1: '123 Happy Road',
36
+ address2: 'Apt 303',
37
+ city: 'Suzarac',
38
+ zipcode: '95671',
39
+ state: double('Spree::State', name: 'Oregon'),
40
+ country: double('Spree::Country', name: 'United States')
41
+ )
42
+ }
43
+
44
+ it 'stores the bill address with the provider' do
45
+ subject.provider.should_receive(:store).with(payment.source, {
46
+ email: email,
47
+ login: login,
48
+
49
+ address: {
50
+ address1: '123 Happy Road',
51
+ address2: 'Apt 303',
52
+ city: 'Suzarac',
53
+ zip: '95671',
54
+ state: 'Oregon',
55
+ country: 'United States'
56
+ }
57
+ }).and_return double.as_null_object
58
+
59
+ subject.create_profile payment
60
+ end
61
+ end
62
+
63
+ context 'with an order that does not have a bill address' do
64
+ let(:bill_address) { nil }
65
+
66
+ it 'does not store a bill address with the provider' do
67
+ subject.provider.should_receive(:store).with(payment.source, {
68
+ email: email,
69
+ login: login,
70
+ }).and_return double.as_null_object
71
+
72
+ subject.create_profile payment
73
+ end
74
+ end
75
+ end
76
+
77
+ context 'purchasing' do
78
+
79
+ after(:each) do
80
+ subject.purchase(19.99, 'credit card', {})
81
+ end
82
+
83
+ it 'should send the payment to the provider' do
84
+ provider.should_receive(:purchase).with('money','cc','opts')
85
+ end
86
+
87
+ end
88
+
89
+ context 'authorizing' do
90
+
91
+ after(:each) do
92
+ subject.authorize(19.99, 'credit card', {})
93
+ end
94
+
95
+ it 'should send the authorization to the provider' do
96
+ provider.should_receive(:authorize).with('money','cc','opts')
97
+ end
98
+
99
+ end
100
+
101
+ context 'capturing' do
102
+
103
+ let(:payment) do
104
+ double('payment').tap do |p|
105
+ p.stub(:amount).and_return(12.34)
106
+ p.stub(:response_code).and_return('response_code')
107
+ end
108
+ end
109
+
110
+ after(:each) do
111
+ subject.capture(payment, 'credit card', {})
112
+ end
113
+
114
+ it 'should convert the amount to cents' do
115
+ provider.should_receive(:capture).with(1234,anything,anything)
116
+ end
117
+
118
+ it 'should use the response code as the authorization' do
119
+ provider.should_receive(:capture).with(anything,'response_code',anything)
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Gateway::UsaEpay do
4
+
5
+ before(:each) do
6
+ Spree::Gateway.update_all :active => false
7
+ @gateway = Spree::Gateway::UsaEpay.create!(:name => "USA EPay Gateway", :environment => "sandbox", :active => true)
8
+
9
+ @gateway.set_preference(:login, "0r19zQBdp5nS8i3t4hFxz0di13yf56q1" )
10
+ @gateway.save!
11
+
12
+ @country = create(:country, :name => "United States", :iso_name => "UNITED STATES", :iso3 => "USA", :iso => "US", :numcode => 840)
13
+ @state = create(:state, :name => "Maryland", :abbr => "MD", :country => @country)
14
+ @address = create(:address,
15
+ :firstname => 'John',
16
+ :lastname => 'Doe',
17
+ :address1 => '1234 My Street',
18
+ :address2 => 'Apt 1',
19
+ :city => 'Washington DC',
20
+ :zipcode => '20123',
21
+ :phone => '(555)555-5555',
22
+ :state => @state,
23
+ :country => @country
24
+ )
25
+ @order = create(:order_with_totals, :bill_address => @address, :ship_address => @address)
26
+ @order.update!
27
+ @credit_card = create(:credit_card, :verification_value => '123', :number => '4111111111111111', :month => 9, :year => Time.now.year + 1, :first_name => 'John', :last_name => 'Doe')
28
+ @payment = create(:payment, :source => @credit_card, :order => @order, :payment_method => @gateway, :amount => 10.00)
29
+ @payment.payment_method.environment = "test"
30
+ end
31
+
32
+ describe "purchasing" do
33
+ it "can purchase a payment" do
34
+ pending "Broken due to USA EPay missing a source key."
35
+ @payment.purchase!.should be_true
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,34 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+
6
+ require 'rspec/rails'
7
+
8
+ # Requires supporting ruby files with custom matchers and macros, etc,
9
+ # in spec/support/ and its subdirectories.
10
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
11
+
12
+ # Requires factories defined in spree_core
13
+ require 'spree/testing_support/factories'
14
+
15
+ RSpec.configure do |config|
16
+ # == Mock Framework
17
+ #
18
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
19
+ #
20
+ # config.mock_with :mocha
21
+ # config.mock_with :flexmock
22
+ # config.mock_with :rr
23
+ config.mock_with :rspec
24
+
25
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
26
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
27
+
28
+ config.include FactoryGirl::Syntax::Methods
29
+
30
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
31
+ # examples within a transaction, remove the following line or assign false
32
+ # instead of true.
33
+ config.use_transactional_fixtures = true
34
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ Gem::Specification.new do |s|
3
+ s.platform = Gem::Platform::RUBY
4
+ s.name = 'spree_gateway'
5
+ s.version = '2.0.1'
6
+ s.summary = 'Additional Payment Gateways for Spree Commerce'
7
+ s.description = s.summary
8
+ s.required_ruby_version = '>= 1.9.3'
9
+
10
+ s.author = 'Spree Commerce'
11
+ s.email = 'gems@spreecommerce.com'
12
+ s.homepage = 'http://www.spreecommerce.com'
13
+ s.license = %q{BSD-3}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- spec/*`.split("\n")
17
+ s.require_path = 'lib'
18
+ s.requirements << 'none'
19
+
20
+ s.add_dependency 'spree_core', '~> 2.0.0'
21
+ s.add_dependency 'savon', '~> 1.2'
22
+
23
+ s.add_development_dependency 'factory_girl_rails', '~> 4.2.0'
24
+ s.add_development_dependency 'rspec-rails', '~> 2.13'
25
+ s.add_development_dependency 'sqlite3'
26
+ end