atmos-braintree_transparent_redirect_slice 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/LICENSE +20 -0
  2. data/README +41 -0
  3. data/Rakefile +65 -0
  4. data/TODO +15 -0
  5. data/app/controllers/application.rb +5 -0
  6. data/app/controllers/credit_cards.rb +54 -0
  7. data/app/controllers/main.rb +7 -0
  8. data/app/controllers/payments.rb +17 -0
  9. data/app/helpers/application_helper.rb +63 -0
  10. data/app/helpers/credit_cards_helper.rb +15 -0
  11. data/app/models/braintree/gateway_request.rb +55 -0
  12. data/app/models/braintree/gateway_response.rb +101 -0
  13. data/app/models/braintree/query.rb +46 -0
  14. data/app/models/braintree/transaction_info.rb +20 -0
  15. data/app/models/credit_card.rb +18 -0
  16. data/app/models/credit_card_info.rb +31 -0
  17. data/app/models/credit_card_invoice.rb +15 -0
  18. data/app/views/braintree_transparent_redirect_slice/credit_cards/_form.html.haml +27 -0
  19. data/app/views/braintree_transparent_redirect_slice/credit_cards/_gateway_request.html.haml +6 -0
  20. data/app/views/braintree_transparent_redirect_slice/credit_cards/destroy.html.haml +8 -0
  21. data/app/views/braintree_transparent_redirect_slice/credit_cards/edit.html.haml +8 -0
  22. data/app/views/braintree_transparent_redirect_slice/credit_cards/index.html.haml +26 -0
  23. data/app/views/braintree_transparent_redirect_slice/credit_cards/new.html.haml +9 -0
  24. data/app/views/braintree_transparent_redirect_slice/credit_cards/show.html.haml +33 -0
  25. data/app/views/braintree_transparent_redirect_slice/payments/index.html.haml +2 -0
  26. data/app/views/braintree_transparent_redirect_slice/payments/new.html.haml +21 -0
  27. data/app/views/layout/braintree_transparent_redirect_slice.html.haml +26 -0
  28. data/app/views/main/index.html.haml +1 -0
  29. data/lib/braintree_transparent_redirect_slice.rb +103 -0
  30. data/lib/braintree_transparent_redirect_slice/merbtasks.rb +103 -0
  31. data/lib/braintree_transparent_redirect_slice/slicetasks.rb +20 -0
  32. data/lib/braintree_transparent_redirect_slice/spectasks.rb +53 -0
  33. data/lib/braintree_transparent_redirect_slice/version.rb +3 -0
  34. data/public/javascripts/master.js +6 -0
  35. data/public/stylesheets/master.css +153 -0
  36. data/spec/fixtures/user.rb +24 -0
  37. data/spec/models/credit_card_info_spec.rb +30 -0
  38. data/spec/requests/credit_cards/adding_a_card_spec.rb +110 -0
  39. data/spec/requests/credit_cards/deleting_a_card_spec.rb +19 -0
  40. data/spec/requests/credit_cards/updating_a_card_spec.rb +56 -0
  41. data/spec/requests/main_spec.rb +14 -0
  42. data/spec/requests/payments/issuing_a_transaction_spec.rb +49 -0
  43. data/spec/spec_helper.rb +127 -0
  44. data/spec/spec_helpers/braintree/api_helper.rb +14 -0
  45. data/spec/spec_helpers/edit_form_helper.rb +34 -0
  46. data/stubs/app/controllers/application.rb +2 -0
  47. data/stubs/app/controllers/main.rb +2 -0
  48. metadata +212 -0
@@ -0,0 +1,14 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
2
+
3
+ describe "" do
4
+ before(:all) do
5
+ mount_slice
6
+ end
7
+ describe "visiting /billing", :given => 'an authenticated user' do
8
+ it "should display the user's billing information" do
9
+ response = request("/billing")
10
+ response.status.should be_successful
11
+ response.should have_selector("a[href='/billing/credit_cards/new']")
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,49 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper.rb')
2
+
3
+ describe "" do
4
+ before(:each) do
5
+ mount_slice
6
+ end
7
+ describe "visiting /billing/credit_cards/1/payments/new", :given => 'a user with a credit card in the vault' do
8
+ it "should display a form telling you that you'll be charged 10.00" do
9
+ response = request("/billing/credit_cards/1/payments/new")
10
+ response.should be_successful
11
+ end
12
+ end
13
+
14
+ describe "submitting the form at /billing/credit_cards/1/payments/new", :given => 'a user with a credit card in the vault' do
15
+ before(:each) do
16
+ @token = User.first.credit_cards.first.token
17
+ end
18
+ describe "given a successful transaction" do
19
+ it "should redirect to the credit card's page and display the transaction" do
20
+ query_params = { 'customer_vault_id' => @token, 'type' => 'sale', 'amount' => '10.00',
21
+ 'redirect' => 'http://example.org/credit_cards/1/new_response' }
22
+
23
+ api_response = Braintree::Spec::ApiRequest.new('10.00', @token, query_params)
24
+
25
+ response = request("/billing/credit_cards/1/payments/new_response", :params => api_response.params)
26
+ response.should redirect_to("/billing/credit_cards/1")
27
+
28
+ response = request(response.headers['Location'])
29
+ response.should be_successful
30
+ response.should have_selector("div#braintree-message:contains('Successfully charged your Credit Card.')")
31
+ end
32
+ end
33
+ describe "given a failed transaction" do
34
+ it "send you back to the form telling you the payment was declined" do
35
+ query_params = { 'customer_vault_id' => @token, 'type' => 'sale', 'amount' => '0.99',
36
+ 'redirect' => 'http://example.org/credit_cards/1/new_response' }
37
+
38
+ api_response = Braintree::Spec::ApiRequest.new('0.99', @token, query_params)
39
+
40
+ response = request("/billing/credit_cards/1/payments/new_response", :params => api_response.params)
41
+ response.should redirect_to("/billing/credit_cards/1/payments/new")
42
+
43
+ response = request(response.headers['Location'])
44
+ response.should be_successful
45
+ response.should have_selector("div#braintree-message:contains('DECLINE')")
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,127 @@
1
+ root = File.expand_path(File.dirname(__FILE__)+'/../')
2
+ ENV['GEM_HOME'] = File.join(root, 'gems')
3
+ ENV['GEM_PATH'] = File.join(root, 'gems')
4
+
5
+ require 'rubygems'
6
+ require 'merb-core'
7
+ require 'merb-slices'
8
+ require 'merb-auth-core'
9
+ require 'merb-auth-more'
10
+ require 'spec'
11
+ require 'pp'
12
+ require 'ruby-debug'
13
+ require 'dm-core'
14
+ require 'dm-validations'
15
+ require root + '/lib/braintree_transparent_redirect_slice/version'
16
+
17
+ # Add braintree_transparent_redirect_slice.rb to the search path
18
+ Merb::Plugins.config[:merb_slices][:auto_register] = true
19
+ Merb::Plugins.config[:merb_slices][:search_path] = File.join(File.dirname(__FILE__), '..', 'lib', 'braintree_transparent_redirect_slice.rb')
20
+
21
+ # Require braintree_transparent_redirect_slice.rb explicitly so any dependencies are loaded
22
+ require Merb::Plugins.config[:merb_slices][:search_path]
23
+
24
+ require File.expand_path(File.dirname(__FILE__)+'/fixtures/user')
25
+ require File.expand_path(File.dirname(__FILE__)+'/spec_helpers/edit_form_helper')
26
+ require File.expand_path(File.dirname(__FILE__)+'/spec_helpers/braintree/api_helper')
27
+
28
+ # Using Merb.root below makes sure that the correct root is set for
29
+ # - testing standalone, without being installed as a gem and no host application
30
+ # - testing from within the host application; its root will be used
31
+ Merb.start_environment(
32
+ :testing => true,
33
+ :adapter => 'runner',
34
+ :environment => ENV['MERB_ENV'] || 'test',
35
+ :session_store => 'memory'
36
+ )
37
+ DataMapper.setup(:default, 'sqlite3::memory:')
38
+ DataMapper.auto_migrate!
39
+
40
+ module Merb
41
+ module Test
42
+ module SliceHelper
43
+ # The absolute path to the current slice
44
+ def current_slice_root
45
+ @current_slice_root ||= File.expand_path(File.join(File.dirname(__FILE__), '..'))
46
+ end
47
+
48
+ # Whether the specs are being run from a host application or standalone
49
+ def standalone?
50
+ Merb.root == ::BraintreeTransparentRedirectSlice.root
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ Spec::Runner.configure do |config|
57
+ config.include(Merb::Test::ViewHelper)
58
+ config.include(Merb::Test::RouteHelper)
59
+ config.include(Merb::Test::ControllerHelper)
60
+ config.include(Merb::Test::SliceHelper)
61
+ config.before(:all) do
62
+ DataMapper.auto_migrate! if Merb.orm == :datamapper
63
+ user = User.create(:login => 'quentin', :email => 'quentin@example.com',
64
+ :password => 'lolerskates', :password_confirmation => 'lolerskates')
65
+ end
66
+
67
+ config.before(:each) do # transactional tests
68
+ repository(:default) do
69
+ while repository.adapter.current_transaction do
70
+ repository.adapter.current_transaction.rollback
71
+ repository.adapter.pop_transaction
72
+ end
73
+
74
+ transaction = DataMapper::Transaction.new(repository)
75
+ transaction.begin
76
+ repository.adapter.push_transaction(transaction)
77
+ end
78
+ end
79
+ config.after(:each) do
80
+ dismount_slice
81
+ end
82
+
83
+ def quentin_form_info
84
+ { 'firstname' => 'Quentin', 'lastname' => 'Blake',
85
+ 'email' => 'quentin@example.org', 'address1' => '187 Drive By Blvd',
86
+ 'city' => 'Compton', 'state' => 'CA', 'country' => 'US', 'zip' => '90220',
87
+ 'cvv' => '999', 'ccexp' => '1010', 'ccnumber' => '4111111111111111',
88
+ 'customer_vault' => 'add_customer', 'customer_vault_id' => '',
89
+ 'redirect' => 'http://example.org/billing/credit_cards/new_response'
90
+ }
91
+ end
92
+ end
93
+
94
+ # You can add your own helpers here
95
+ #
96
+ Merb::Test.add_helpers do
97
+ def mount_slice
98
+ Merb::Router.prepare do
99
+ slice(:merb_auth_slice_password, :name_prefix => nil, :path_prefix => "")
100
+ add_slice(:braintree_transparent_redirect_slice, :name_prefix => nil, :path_prefix => "billing")
101
+ #add_slice(BraintreeTransparentRedirectSlice)
102
+ end if standalone?
103
+ end
104
+
105
+ def dismount_slice
106
+ Merb::Router.reset! if standalone?
107
+ end
108
+ end
109
+
110
+ given "an authenticated user" do
111
+ response = request url(:perform_login), :method => "PUT",
112
+ :params => { :login => 'quentin', :password => 'lolerskates' }
113
+ response.should redirect_to '/'
114
+ end
115
+
116
+ given "a user with a credit card in the vault" do
117
+ response = request url(:perform_login), :method => "PUT",
118
+ :params => { :login => 'quentin', :password => 'lolerskates' }
119
+ response.should redirect_to '/'
120
+ response = request("/billing/credit_cards/new")
121
+
122
+ api_response = Braintree::Spec::ApiRequest.new('10.00', nil,
123
+ quentin_form_info.merge({'type'=>'sale', 'payment'=>'creditcard'}))
124
+
125
+ response = request("/billing/credit_cards/new_response", :params => api_response.params)
126
+ response.should redirect_to('/billing/credit_cards')
127
+ end
@@ -0,0 +1,14 @@
1
+ module Braintree
2
+ module Spec
3
+ class ApiRequest
4
+ def initialize(amount, customer_vault_id, params)
5
+ @response = Braintree::GatewayRequest.new(:amount => amount, :customer_vault_id => customer_vault_id).post(params)
6
+ end
7
+
8
+ def params
9
+ params = @response.query_values
10
+ params.reject { |k,v| v == true }
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,34 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
2
+
3
+ module BrainTreeEditFormHelper
4
+ class BrainTreeEditFormHelperForQuentin
5
+ include Merb::Test::Matchers
6
+ include Merb::Test::ViewHelper
7
+ def matches?(target)
8
+ target.should have_selector("form[action='https://secure.braintreepaymentgateway.com/api/transact.php'][method='post']")
9
+ target.should have_selector("form input#firstname[value='Quentin']")
10
+ target.should have_selector("form input#lastname[value='Blake']")
11
+ target.should have_selector("form input#email[value='quentin@example.org']")
12
+ target.should have_selector("form input#address1[value='187 Drive By Blvd']")
13
+ target.should have_selector("form input#city[value='Compton']")
14
+ target.should have_selector("form input#state[value='CA']")
15
+ target.should have_selector("form input#zip[value='90220']")
16
+ target.should have_selector("form input#country[value='US']")
17
+ target.should have_selector("form input#ccexp[value='1010']")
18
+ target.should have_selector("form input#customer_vault_id[value='#{User.first.credit_cards.first.token}']")
19
+
20
+ target.should have_selector("form input#orderid[value=''][type='hidden']")
21
+ target.should have_selector("form input#hash[type='hidden']")
22
+ target.should have_selector("form input#time[type='hidden']")
23
+ target.should have_selector("form input#customer_vault[type='hidden'][value='update_customer']")
24
+ target.should have_selector("form input#redirect[type='hidden'][value='http://example.org/billing/credit_cards/1/edit_response']")
25
+ end
26
+
27
+ def failure_message
28
+ "FAIL! :'("
29
+ end
30
+ end
31
+ def display_a_credit_card_edit_form_for_quentin
32
+ BrainTreeEditFormHelperForQuentin.new
33
+ end
34
+ end
@@ -0,0 +1,2 @@
1
+ class BraintreeTransparentRedirectSlice::Application < Merb::Controller
2
+ end
@@ -0,0 +1,2 @@
1
+ class BraintreeTransparentRedirectSlice::Main < BraintreeTransparentRedirectSlice::Application
2
+ end
metadata ADDED
@@ -0,0 +1,212 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: atmos-braintree_transparent_redirect_slice
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Corey Donohoe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-21 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: merb-slices
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.7.1
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: libxml-ruby
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - "="
30
+ - !ruby/object:Gem::Version
31
+ version: 0.9.7
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: dm-core
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.8
41
+ version:
42
+ - !ruby/object:Gem::Dependency
43
+ name: dm-validations
44
+ version_requirement:
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.9.8
50
+ version:
51
+ - !ruby/object:Gem::Dependency
52
+ name: merb-auth-core
53
+ version_requirement:
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ - !ruby/object:Gem::Dependency
61
+ name: merb-auth-more
62
+ version_requirement:
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ - !ruby/object:Gem::Dependency
70
+ name: merb-haml
71
+ version_requirement:
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
78
+ - !ruby/object:Gem::Dependency
79
+ name: merb-helpers
80
+ version_requirement:
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ version:
87
+ - !ruby/object:Gem::Dependency
88
+ name: merb-assets
89
+ version_requirement:
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ version:
96
+ - !ruby/object:Gem::Dependency
97
+ name: merb-action-args
98
+ version_requirement:
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: "0"
104
+ version:
105
+ description: Merb Slice that allows you to process stuff with braintree, without storing credit cards and shit
106
+ email: atmos@atmos.org
107
+ executables: []
108
+
109
+ extensions: []
110
+
111
+ extra_rdoc_files:
112
+ - README
113
+ - LICENSE
114
+ - TODO
115
+ files:
116
+ - LICENSE
117
+ - README
118
+ - Rakefile
119
+ - TODO
120
+ - lib/braintree_transparent_redirect_slice
121
+ - lib/braintree_transparent_redirect_slice/merbtasks.rb
122
+ - lib/braintree_transparent_redirect_slice/slicetasks.rb
123
+ - lib/braintree_transparent_redirect_slice/spectasks.rb
124
+ - lib/braintree_transparent_redirect_slice/version.rb
125
+ - lib/braintree_transparent_redirect_slice.rb
126
+ - spec/fixtures
127
+ - spec/fixtures/user.rb
128
+ - spec/models
129
+ - spec/models/credit_card_info_spec.rb
130
+ - spec/requests
131
+ - spec/requests/credit_cards
132
+ - spec/requests/credit_cards/adding_a_card_spec.rb
133
+ - spec/requests/credit_cards/deleting_a_card_spec.rb
134
+ - spec/requests/credit_cards/updating_a_card_spec.rb
135
+ - spec/requests/main_spec.rb
136
+ - spec/requests/payments
137
+ - spec/requests/payments/issuing_a_transaction_spec.rb
138
+ - spec/spec_helper.rb
139
+ - spec/spec_helpers
140
+ - spec/spec_helpers/braintree
141
+ - spec/spec_helpers/braintree/api_helper.rb
142
+ - spec/spec_helpers/edit_form_helper.rb
143
+ - app/controllers
144
+ - app/controllers/application.rb
145
+ - app/controllers/credit_cards.rb
146
+ - app/controllers/main.rb
147
+ - app/controllers/payments.rb
148
+ - app/helpers
149
+ - app/helpers/application_helper.rb
150
+ - app/helpers/credit_cards_helper.rb
151
+ - app/models
152
+ - app/models/braintree
153
+ - app/models/braintree/gateway_request.rb
154
+ - app/models/braintree/gateway_response.rb
155
+ - app/models/braintree/query.rb
156
+ - app/models/braintree/transaction_info.rb
157
+ - app/models/credit_card.rb
158
+ - app/models/credit_card_info.rb
159
+ - app/models/credit_card_invoice.rb
160
+ - app/views
161
+ - app/views/braintree_transparent_redirect_slice
162
+ - app/views/braintree_transparent_redirect_slice/credit_cards
163
+ - app/views/braintree_transparent_redirect_slice/credit_cards/_form.html.haml
164
+ - app/views/braintree_transparent_redirect_slice/credit_cards/_gateway_request.html.haml
165
+ - app/views/braintree_transparent_redirect_slice/credit_cards/destroy.html.haml
166
+ - app/views/braintree_transparent_redirect_slice/credit_cards/edit.html.haml
167
+ - app/views/braintree_transparent_redirect_slice/credit_cards/index.html.haml
168
+ - app/views/braintree_transparent_redirect_slice/credit_cards/new.html.haml
169
+ - app/views/braintree_transparent_redirect_slice/credit_cards/show.html.haml
170
+ - app/views/braintree_transparent_redirect_slice/payments
171
+ - app/views/braintree_transparent_redirect_slice/payments/index.html.haml
172
+ - app/views/braintree_transparent_redirect_slice/payments/new.html.haml
173
+ - app/views/layout
174
+ - app/views/layout/braintree_transparent_redirect_slice.html.haml
175
+ - app/views/main
176
+ - app/views/main/index.html.haml
177
+ - public/javascripts
178
+ - public/javascripts/master.js
179
+ - public/stylesheets
180
+ - public/stylesheets/master.css
181
+ - stubs/app
182
+ - stubs/app/controllers
183
+ - stubs/app/controllers/application.rb
184
+ - stubs/app/controllers/main.rb
185
+ has_rdoc: true
186
+ homepage: http://github.com/atmos/braintree_transparent_redirect_slice/
187
+ post_install_message:
188
+ rdoc_options: []
189
+
190
+ require_paths:
191
+ - lib
192
+ required_ruby_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: "0"
197
+ version:
198
+ required_rubygems_version: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - ">="
201
+ - !ruby/object:Gem::Version
202
+ version: "0"
203
+ version:
204
+ requirements: []
205
+
206
+ rubyforge_project: merb
207
+ rubygems_version: 1.2.0
208
+ signing_key:
209
+ specification_version: 2
210
+ summary: Merb Slice that allows you to process stuff with braintree, without storing credit cards and shit
211
+ test_files: []
212
+