gimme_gimme 0.2.2 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gimme_gimme (0.2)
4
+ gimme_gimme (0.3.0)
5
5
  activemerchant
6
6
  clearance
7
7
 
data/README.md CHANGED
@@ -3,8 +3,6 @@ gimme_gimme is a Rails engine for managing a User's credit cards. It can
3
3
  authorize and charge cards through its Authorize.net gateway.
4
4
 
5
5
  ## Usage
6
- Important: gimme_gimme assumes that you are using Clearance. If you're not,
7
- things will probably break.
8
6
 
9
7
  gimme_gimme ships with generators:
10
8
 
@@ -18,20 +16,41 @@ application, run:
18
16
 
19
17
  rails generate gimme_gimme:test_support
20
18
 
19
+ This will generate test support for the Authorize.net gateway.
21
20
 
22
- gimme_gimme uses Authorize.net for its CIM (customer information management)
23
- gateway. To set it up, create config/authorize_net.yml with the following
24
- info:
21
+ ## Gateways
22
+ gimme_gimme can use either Authorize.net or Braintree as its payment gateway.
23
+ To set your gateway, create config/gimme_gimme.yml and fill in the info
24
+ appropriate to your gateway as shown below.
25
25
 
26
+ gimme_gimme will use Rails.env to determine which entry in the YAML file to
27
+ use. If you do not have a gateway_mode set for the current Rails.env, it will
28
+ use the :test mode.
29
+
30
+ ### Authorize.net
31
+ Authorize.net must have CIM enabled. For information on CIM, see
32
+ http://www.authorize.net/solutions/merchantsolutions/merchantservices/cim/.
26
33
 
34
+ config/gimme_gimme.yml:
35
+
36
+ gateway: authorize_net
37
+ authorize_net_api_login_id: your_login_id
38
+ authorize_net_transaction_key: your_transaction_key
27
39
  test:
28
- authorize_net_api_login_id: <Fill in login id>
29
- authorize_net_transaction_key: <Fill in transaction key>
30
- gateway_mode: 'test'
31
- <rails_env>:
32
- authorize_net_api_login_id: <Fill in login id>
33
- authorize_net_transaction_key: <Fill in transaction key>
34
- gateway_mode: <Choose a gateway mode>
40
+ gateway_mode: test
41
+ <other_rails_env>:
42
+ gateway_mode: production
35
43
 
36
- gimme_gimme will use Rails.env to determine which entry in the YAML file to
37
- use.
44
+ ### Braintree
45
+ You must have version 2.x.y of the Braintree gem.
46
+
47
+ config/gimme_gimme.yml:
48
+
49
+ gateway: braintree
50
+ braintree_api_merchant_id: your_merchant_id
51
+ braintree_api_public_key: your_public_key
52
+ braintree_api_private_key: your_private_key
53
+ test:
54
+ gateway_mode: test
55
+ <other_rails_env>:
56
+ gateway_mode: production
@@ -7,28 +7,49 @@ Feature: Generators
7
7
  And I append to "Gemfile" with:
8
8
  """
9
9
  gem "clearance"
10
- gem "cucumber-rails"
11
- gem "capybara"
12
- gem "factory_girl_rails"
13
10
  gem "dynamic_form"
14
- gem "database_cleaner"
15
11
  gem "formtastic"
16
- gem "rspec-rails", :require => false
17
- gem "database_cleaner"
18
- gem "formtastic"
19
- gem "rspec-rails", :require => false
12
+
13
+ group :test, :development do
14
+ gem "rspec-rails"
15
+ end
16
+ group :test do
17
+ gem "capybara"
18
+ gem "cucumber-rails"
19
+ gem "factory_girl_rails"
20
+ gem "database_cleaner"
21
+ end
20
22
  """
21
23
  When I bootstrap the application for clearance
22
24
  And I add the "gimme_gimme" gem from this project as a dependency
23
25
  And I successfully run "bundle install"
24
26
  And I successfully run "rails generate gimme_gimme:install"
25
27
  And I successfully run "rails generate gimme_gimme:test_support"
26
- And a file named "testapp/config/initializers/authorize_net.yml" with:
28
+ And I successfully run "rails generate rspec:install"
29
+ And a file named "config/gimme_gimme.yml" with:
27
30
  """
31
+ gateway: authorize_net
32
+ authorize_net_api_login_id: 'fake login id'
33
+ authorize_net_transaction_key: 'fake transaction key'
28
34
  test:
29
- authorize_net_api_login_id: 'fake login id'
30
- authorize_net_transaction_key: 'fake transaction key'
31
- gateway_mode: 'test'
35
+ gateway_mode: test
36
+ """
37
+ And a file named "spec/app_works_spec.rb" with:
38
+ """
39
+ require 'spec_helper'
40
+
41
+ describe GimmeGimme, ".gateway" do
42
+ it "is the correct class" do
43
+ GimmeGimme.gateway.class.should == ActiveMerchant::Billing::AuthorizeNetCimGateway
44
+ end
45
+ end
46
+ """
47
+ And I append to "Rakefile" with:
48
+ """
49
+ require 'rspec/core/rake_task'
50
+ RSpec::Core::RakeTask.new
51
+
52
+ task :default => [:spec, :cucumber]
32
53
  """
33
54
  And I successfully run "rake db:migrate"
34
55
  When I run "rake"
@@ -36,5 +57,7 @@ Feature: Generators
36
57
  """
37
58
  passed
38
59
  """
39
- Then the output should not contain "failed"
60
+ Then the output should contain "13 scenarios (13 passed)"
61
+ And the output should contain "1 example, 0 failures"
62
+ And the output should not contain "failed"
40
63
  And the output should not contain "Could not find generator"
@@ -24,6 +24,10 @@ DESC
24
24
  directory "controllers", "app/controllers"
25
25
  end
26
26
 
27
+ def create_initializer
28
+ directory "initializers", "config/initializers"
29
+ end
30
+
27
31
  def update_user_model
28
32
  insert_into_file "app/models/user.rb",
29
33
  "\ninclude GimmeGimme::User",
@@ -0,0 +1,27 @@
1
+ if File.exists?(Rails.root.join('config', 'gimme_gimme.yml'))
2
+ config = YAML.load_file(Rails.root.join('config', 'gimme_gimme.yml'))
3
+ gateway = config['gateway']
4
+
5
+ if config.key?(Rails.env) && config[Rails.env].key?('gateway_mode')
6
+ gateway_mode = config[Rails.env]['gateway_mode']
7
+ else
8
+ gateway_mode = :test
9
+ end
10
+
11
+ ActiveMerchant::Billing::Base.gateway_mode = gateway_mode.to_sym
12
+
13
+ if gateway == 'authorize_net'
14
+ AUTHORIZE_NET_API_LOGIN_ID = config['authorize_net_api_login_id']
15
+ AUTHORIZE_NET_TRANSACTION_KEY = config['authorize_net_transaction_key']
16
+
17
+ GimmeGimme.gateway = GimmeGimme::Gateway.authorize_net_gateway
18
+ elsif gateway == 'braintree'
19
+ BRAINTREE_API_MERCHANT_ID = config['braintree_api_merchant_id']
20
+ BRAINTREE_API_PUBLIC_KEY = config['braintree_api_public_key']
21
+ BRAINTREE_API_PRIVATE_KEY = config['braintree_api_private_key']
22
+
23
+ GimmeGimme.gateway = GimmeGimme::Gateway.braintree_gateway
24
+ else
25
+ raise %{The "#{gateway}" gateway is not supported by gimme_gimme, please use "authorize_net" or "braintree"}
26
+ end
27
+ end
@@ -5,5 +5,5 @@ $fake_cim_server = GimmeGimme::FakeCimServer.new
5
5
 
6
6
  Before do
7
7
  $fake_cim_server.reset
8
- ::GimmeGimme::CimGateway.instance.gateway = GimmeGimme::FakeCimGateway.new(:server => $fake_cim_server)
8
+ ::GimmeGimme.gateway = GimmeGimme::FakeCimGateway.new(:server => $fake_cim_server)
9
9
  end
@@ -1,12 +1,12 @@
1
1
  module GimmeGimme
2
2
  module FakeCimHelpers
3
3
  def with_gateway(new_gateway)
4
- old_gateway = CimGateway.instance.gateway
5
- CimGateway.instance.gateway = new_gateway
4
+ old_gateway = GimmeGimme.gateway
5
+ GimmeGimme.gateway = new_gateway
6
6
  begin
7
7
  yield
8
8
  ensure
9
- CimGateway.instance.gateway = old_gateway
9
+ GimmeGimme.gateway = old_gateway
10
10
  end
11
11
  end
12
12
 
@@ -118,7 +118,7 @@ module GimmeGimme
118
118
 
119
119
  module ClassMethods
120
120
  def gateway
121
- ::GimmeGimme::CimGateway.instance.gateway
121
+ ::GimmeGimme.gateway
122
122
  end
123
123
  end
124
124
  end
@@ -1,4 +1,3 @@
1
- require "gimme_gimme"
2
1
  require "rails/railtie"
3
2
 
4
3
  module GimmeGimme
@@ -0,0 +1,18 @@
1
+ module GimmeGimme
2
+ class Gateway
3
+ def self.authorize_net_gateway
4
+ ActiveMerchant::Billing::AuthorizeNetCimGateway.new(
5
+ :login => AUTHORIZE_NET_API_LOGIN_ID,
6
+ :password => AUTHORIZE_NET_TRANSACTION_KEY
7
+ )
8
+ end
9
+
10
+ def self.braintree_gateway
11
+ ActiveMerchant::Billing::BraintreeBlueGateway.new(
12
+ :merchant_id => BRAINTREE_API_MERCHANT_ID,
13
+ :public_key => BRAINTREE_API_PUBLIC_KEY,
14
+ :private_key => BRAINTREE_API_PRIVATE_KEY
15
+ )
16
+ end
17
+ end
18
+ end
@@ -36,7 +36,7 @@ module GimmeGimme
36
36
 
37
37
  module ClassMethods
38
38
  def gateway
39
- ::GimmeGimme::CimGateway.instance.gateway
39
+ ::GimmeGimme.gateway
40
40
  end
41
41
  end
42
42
  end
@@ -1,3 +1,3 @@
1
1
  module GimmeGimme
2
- VERSION = '0.2.2'
2
+ VERSION = '0.3.1'
3
3
  end
data/lib/gimme_gimme.rb CHANGED
@@ -2,6 +2,17 @@ require 'activemerchant'
2
2
  require 'gimme_gimme/version'
3
3
  require 'gimme_gimme/engine'
4
4
  require 'gimme_gimme/credit_cards_controller'
5
- require 'gimme_gimme/cim_gateway'
5
+ require 'gimme_gimme/gateway'
6
6
  require 'gimme_gimme/credit_card'
7
7
  require 'gimme_gimme/user'
8
+
9
+ module GimmeGimme
10
+ @@gateway = nil
11
+ def self.gateway
12
+ @@gateway ||= Gateway.authorize_net_gateway
13
+ end
14
+
15
+ def self.gateway=(new_gateway)
16
+ @@gateway = new_gateway
17
+ end
18
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe GimmeGimme::Gateway, '.braintree_gateway' do
4
+ before do
5
+ BRAINTREE_API_MERCHANT_ID = '123'
6
+ BRAINTREE_API_PUBLIC_KEY = '123'
7
+ BRAINTREE_API_PRIVATE_KEY = '123'
8
+ end
9
+
10
+ after do
11
+ [:BRAINTREE_API_MERCHANT_ID, :BRAINTREE_API_PUBLIC_KEY, :BRAINTREE_API_PRIVATE_KEY].each do |constant|
12
+ Object.send(:remove_const, constant)
13
+ end
14
+ end
15
+
16
+ it "returns a new BraintreeBlueGateway" do
17
+ GimmeGimme::Gateway.braintree_gateway.class.should == ActiveMerchant::Billing::BraintreeBlueGateway
18
+ end
19
+ end
20
+
21
+ describe GimmeGimme::Gateway, '.authorize_net_gateway' do
22
+ before do
23
+ AUTHORIZE_NET_API_LOGIN_ID = '123'
24
+ AUTHORIZE_NET_TRANSACTION_KEY = '123'
25
+ end
26
+
27
+ after do
28
+ [:AUTHORIZE_NET_API_LOGIN_ID, :AUTHORIZE_NET_TRANSACTION_KEY].each do |constant|
29
+ Object.send(:remove_const, constant)
30
+ end
31
+ end
32
+
33
+ it "returns a new AuthorizeNetCimGateway" do
34
+ GimmeGimme::Gateway.authorize_net_gateway.class.should == ActiveMerchant::Billing::AuthorizeNetCimGateway
35
+ end
36
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe GimmeGimme, '.gateway' do
4
+ after do
5
+ server = GimmeGimme::FakeCimServer.new
6
+ GimmeGimme.gateway = GimmeGimme::FakeCimGateway.new(:server => server)
7
+ end
8
+
9
+ it "can set the gateway" do
10
+ GimmeGimme.gateway = :foo
11
+ GimmeGimme.gateway.should == :foo
12
+ end
13
+ end
@@ -187,7 +187,7 @@ end
187
187
 
188
188
  describe CreditCard, 'gateway' do
189
189
  it "delegates to the CimGateway instance" do
190
- CreditCard.gateway.should == GimmeGimme::CimGateway.instance.gateway
190
+ CreditCard.gateway.should == GimmeGimme.gateway
191
191
  end
192
192
  end
193
193
 
data/spec/spec_helper.rb CHANGED
@@ -27,4 +27,4 @@ RSpec.configure do |config|
27
27
  end
28
28
 
29
29
  server = GimmeGimme::FakeCimServer.new
30
- GimmeGimme::CimGateway.instance.gateway = GimmeGimme::FakeCimGateway.new(:server => server)
30
+ GimmeGimme.gateway = GimmeGimme::FakeCimGateway.new(:server => server)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gimme_gimme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,12 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-08-10 00:00:00.000000000 -04:00
14
- default_executable:
13
+ date: 2011-08-10 00:00:00.000000000Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: activemerchant
18
- requirement: &2156081700 !ruby/object:Gem::Requirement
17
+ requirement: &2160264860 !ruby/object:Gem::Requirement
19
18
  none: false
20
19
  requirements:
21
20
  - - ! '>='
@@ -23,10 +22,10 @@ dependencies:
23
22
  version: '0'
24
23
  type: :runtime
25
24
  prerelease: false
26
- version_requirements: *2156081700
25
+ version_requirements: *2160264860
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: clearance
29
- requirement: &2156081060 !ruby/object:Gem::Requirement
28
+ requirement: &2160264260 !ruby/object:Gem::Requirement
30
29
  none: false
31
30
  requirements:
32
31
  - - ! '>='
@@ -34,10 +33,10 @@ dependencies:
34
33
  version: '0'
35
34
  type: :runtime
36
35
  prerelease: false
37
- version_requirements: *2156081060
36
+ version_requirements: *2160264260
38
37
  - !ruby/object:Gem::Dependency
39
38
  name: cucumber
40
- requirement: &2156070000 !ruby/object:Gem::Requirement
39
+ requirement: &2160263620 !ruby/object:Gem::Requirement
41
40
  none: false
42
41
  requirements:
43
42
  - - ! '>='
@@ -45,10 +44,10 @@ dependencies:
45
44
  version: '0'
46
45
  type: :development
47
46
  prerelease: false
48
- version_requirements: *2156070000
47
+ version_requirements: *2160263620
49
48
  - !ruby/object:Gem::Dependency
50
49
  name: aruba
51
- requirement: &2156069160 !ruby/object:Gem::Requirement
50
+ requirement: &2160263080 !ruby/object:Gem::Requirement
52
51
  none: false
53
52
  requirements:
54
53
  - - ! '>='
@@ -56,10 +55,10 @@ dependencies:
56
55
  version: '0'
57
56
  type: :development
58
57
  prerelease: false
59
- version_requirements: *2156069160
58
+ version_requirements: *2160263080
60
59
  - !ruby/object:Gem::Dependency
61
60
  name: rake
62
- requirement: &2156067240 !ruby/object:Gem::Requirement
61
+ requirement: &2160262520 !ruby/object:Gem::Requirement
63
62
  none: false
64
63
  requirements:
65
64
  - - ! '>='
@@ -67,10 +66,10 @@ dependencies:
67
66
  version: '0'
68
67
  type: :development
69
68
  prerelease: false
70
- version_requirements: *2156067240
69
+ version_requirements: *2160262520
71
70
  - !ruby/object:Gem::Dependency
72
71
  name: rspec-rails
73
- requirement: &2156066140 !ruby/object:Gem::Requirement
72
+ requirement: &2160261860 !ruby/object:Gem::Requirement
74
73
  none: false
75
74
  requirements:
76
75
  - - ! '>='
@@ -78,10 +77,10 @@ dependencies:
78
77
  version: 2.3.1
79
78
  type: :development
80
79
  prerelease: false
81
- version_requirements: *2156066140
80
+ version_requirements: *2160261860
82
81
  - !ruby/object:Gem::Dependency
83
82
  name: rails
84
- requirement: &2156065360 !ruby/object:Gem::Requirement
83
+ requirement: &2160261180 !ruby/object:Gem::Requirement
85
84
  none: false
86
85
  requirements:
87
86
  - - ! '>='
@@ -89,10 +88,10 @@ dependencies:
89
88
  version: 3.0.3
90
89
  type: :development
91
90
  prerelease: false
92
- version_requirements: *2156065360
91
+ version_requirements: *2160261180
93
92
  - !ruby/object:Gem::Dependency
94
93
  name: thin
95
- requirement: &2156064680 !ruby/object:Gem::Requirement
94
+ requirement: &2160260620 !ruby/object:Gem::Requirement
96
95
  none: false
97
96
  requirements:
98
97
  - - ! '>='
@@ -100,10 +99,10 @@ dependencies:
100
99
  version: '0'
101
100
  type: :development
102
101
  prerelease: false
103
- version_requirements: *2156064680
102
+ version_requirements: *2160260620
104
103
  - !ruby/object:Gem::Dependency
105
104
  name: nokogiri
106
- requirement: &2156064000 !ruby/object:Gem::Requirement
105
+ requirement: &2160259980 !ruby/object:Gem::Requirement
107
106
  none: false
108
107
  requirements:
109
108
  - - ! '>='
@@ -111,10 +110,10 @@ dependencies:
111
110
  version: '0'
112
111
  type: :development
113
112
  prerelease: false
114
- version_requirements: *2156064000
113
+ version_requirements: *2160259980
115
114
  - !ruby/object:Gem::Dependency
116
115
  name: shoulda
117
- requirement: &2156063360 !ruby/object:Gem::Requirement
116
+ requirement: &2160259380 !ruby/object:Gem::Requirement
118
117
  none: false
119
118
  requirements:
120
119
  - - ! '>='
@@ -122,10 +121,10 @@ dependencies:
122
121
  version: '0'
123
122
  type: :development
124
123
  prerelease: false
125
- version_requirements: *2156063360
124
+ version_requirements: *2160259380
126
125
  - !ruby/object:Gem::Dependency
127
126
  name: bourne
128
- requirement: &2156062580 !ruby/object:Gem::Requirement
127
+ requirement: &2160258780 !ruby/object:Gem::Requirement
129
128
  none: false
130
129
  requirements:
131
130
  - - ! '>='
@@ -133,10 +132,10 @@ dependencies:
133
132
  version: '0'
134
133
  type: :development
135
134
  prerelease: false
136
- version_requirements: *2156062580
135
+ version_requirements: *2160258780
137
136
  - !ruby/object:Gem::Dependency
138
137
  name: sqlite3-ruby
139
- requirement: &2156059000 !ruby/object:Gem::Requirement
138
+ requirement: &2160258300 !ruby/object:Gem::Requirement
140
139
  none: false
141
140
  requirements:
142
141
  - - ! '>='
@@ -144,10 +143,10 @@ dependencies:
144
143
  version: '0'
145
144
  type: :development
146
145
  prerelease: false
147
- version_requirements: *2156059000
146
+ version_requirements: *2160258300
148
147
  - !ruby/object:Gem::Dependency
149
148
  name: factory_girl
150
- requirement: &2156058400 !ruby/object:Gem::Requirement
149
+ requirement: &2160257800 !ruby/object:Gem::Requirement
151
150
  none: false
152
151
  requirements:
153
152
  - - ! '>='
@@ -155,7 +154,7 @@ dependencies:
155
154
  version: '0'
156
155
  type: :development
157
156
  prerelease: false
158
- version_requirements: *2156058400
157
+ version_requirements: *2160257800
159
158
  description: A rails engine for integrating with authorize.net CIM
160
159
  email: support@thoughtbot.com
161
160
  executables: []
@@ -170,6 +169,7 @@ files:
170
169
  - lib/generators/gimme_gimme/install/install_generator.rb
171
170
  - lib/generators/gimme_gimme/install/templates/controllers/credit_cards_controller.rb
172
171
  - lib/generators/gimme_gimme/install/templates/create_gimme_gimme_tables.rb
172
+ - lib/generators/gimme_gimme/install/templates/initializers/gimme_gimme.rb
173
173
  - lib/generators/gimme_gimme/install/templates/models/credit_card.rb
174
174
  - lib/generators/gimme_gimme/test_support/templates/factories/factories.rb
175
175
  - lib/generators/gimme_gimme/test_support/templates/support/fake_cim.rb
@@ -177,10 +177,10 @@ files:
177
177
  - lib/generators/gimme_gimme/test_support/templates/testing/fake_cim_server.rb
178
178
  - lib/generators/gimme_gimme/test_support/templates/testing/fake_cim_spec_helpers.rb
179
179
  - lib/generators/gimme_gimme/test_support/test_support_generator.rb
180
- - lib/gimme_gimme/cim_gateway.rb
181
180
  - lib/gimme_gimme/credit_card.rb
182
181
  - lib/gimme_gimme/credit_cards_controller.rb
183
182
  - lib/gimme_gimme/engine.rb
183
+ - lib/gimme_gimme/gateway.rb
184
184
  - lib/gimme_gimme/user.rb
185
185
  - lib/gimme_gimme/version.rb
186
186
  - lib/gimme_gimme.rb
@@ -190,11 +190,12 @@ files:
190
190
  - features/support/file_helpers.rb
191
191
  - spec/environment.rb
192
192
  - spec/factories/clearance.rb
193
+ - spec/gimme_gimme/gateway_spec.rb
194
+ - spec/gimme_gimme_spec.rb
193
195
  - spec/models/credit_card_spec.rb
194
196
  - spec/models/user_spec.rb
195
197
  - spec/spec_helper.rb
196
198
  - spec/testapp/config/routes.rb
197
- has_rdoc: false
198
199
  homepage: http://github.com/thoughtbot/gimme_gimme
199
200
  licenses: []
200
201
  post_install_message:
@@ -215,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
216
  version: '0'
216
217
  requirements: []
217
218
  rubyforge_project:
218
- rubygems_version: 1.6.2
219
+ rubygems_version: 1.8.7
219
220
  signing_key:
220
221
  specification_version: 3
221
222
  summary: authorize.net CIM rails engine
@@ -1,16 +0,0 @@
1
- require 'singleton'
2
-
3
- module GimmeGimme
4
- class CimGateway
5
- include Singleton
6
-
7
- attr_accessor :gateway
8
-
9
- def initialize
10
- @gateway = ActiveMerchant::Billing::AuthorizeNetCimGateway.new(
11
- :login => AUTHORIZE_NET_API_LOGIN_ID,
12
- :password => AUTHORIZE_NET_TRANSACTION_KEY
13
- )
14
- end
15
- end
16
- end