jackpot 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. data/.gitignore +16 -0
  2. data/.rspec +1 -0
  3. data/.rvmrc.example +1 -0
  4. data/.travis.yml +12 -0
  5. data/Gemfile +9 -0
  6. data/Gemfile.lock +181 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +134 -0
  9. data/Rakefile +25 -0
  10. data/app/assets/images/jackpot/.gitkeep +0 -0
  11. data/app/assets/javascripts/jackpot/application.js +5 -0
  12. data/app/assets/javascripts/jackpot/bootstrap.js +32 -0
  13. data/app/assets/javascripts/jackpot/customers.js +2 -0
  14. data/app/assets/javascripts/jackpot/login.js +1 -0
  15. data/app/assets/javascripts/jackpot/payments.js +2 -0
  16. data/app/assets/javascripts/jackpot/subscriptions.js +2 -0
  17. data/app/assets/stylesheets/jackpot/application.css +9 -0
  18. data/app/assets/stylesheets/jackpot/customers.css +4 -0
  19. data/app/assets/stylesheets/jackpot/jackpot.css +10 -0
  20. data/app/controllers/jackpot/application_controller.rb +4 -0
  21. data/app/controllers/jackpot/customers_controller.rb +100 -0
  22. data/app/controllers/jackpot/payments_controller.rb +20 -0
  23. data/app/controllers/jackpot/subscriptions_controller.rb +86 -0
  24. data/app/helpers/jackpot/application_helper.rb +27 -0
  25. data/app/helpers/jackpot/customers_helper.rb +7 -0
  26. data/app/helpers/jackpot/subscriptions_helper.rb +4 -0
  27. data/app/models/jackpot/card.rb +29 -0
  28. data/app/models/jackpot/customer.rb +48 -0
  29. data/app/models/jackpot/gateway.rb +28 -0
  30. data/app/models/jackpot/payment.rb +33 -0
  31. data/app/models/jackpot/subscription.rb +13 -0
  32. data/app/models/jackpot/user.rb +25 -0
  33. data/app/views/jackpot/customers/_credit_card_form.html.erb +42 -0
  34. data/app/views/jackpot/customers/_form.html.erb +17 -0
  35. data/app/views/jackpot/customers/edit.html.erb +13 -0
  36. data/app/views/jackpot/customers/index.html.erb +30 -0
  37. data/app/views/jackpot/customers/new.html.erb +8 -0
  38. data/app/views/jackpot/customers/show.html.erb +32 -0
  39. data/app/views/jackpot/payments/create.html.erb +1 -0
  40. data/app/views/jackpot/payments/index.html.erb +25 -0
  41. data/app/views/jackpot/shared/_flash_messages.html.erb +6 -0
  42. data/app/views/jackpot/shared/_navigation.html.erb +5 -0
  43. data/app/views/jackpot/subscriptions/_form.html.erb +13 -0
  44. data/app/views/jackpot/subscriptions/edit.html.erb +6 -0
  45. data/app/views/jackpot/subscriptions/index.html.erb +29 -0
  46. data/app/views/jackpot/subscriptions/new.html.erb +4 -0
  47. data/app/views/jackpot/subscriptions/show.html.erb +23 -0
  48. data/app/views/layouts/devise.html.erb +22 -0
  49. data/app/views/layouts/jackpot/application.html.erb +39 -0
  50. data/config/initializers/jackpot_devise.rb +226 -0
  51. data/config/locales/devise.en.yml +57 -0
  52. data/config/routes.rb +17 -0
  53. data/db/migrate/20111221002616_create_jackpot_payments.rb +11 -0
  54. data/db/migrate/20111230014003_add_customer_information_to_jackpot_payments.rb +5 -0
  55. data/db/migrate/20120102223341_create_jackpot_subscriptions.rb +10 -0
  56. data/db/migrate/20120103211153_create_jackpot_customers.rb +11 -0
  57. data/db/migrate/20120104164830_add_credit_card_number_to_customer.rb +5 -0
  58. data/db/migrate/20120130173242_add_credit_card_information_to_customers.rb +7 -0
  59. data/db/migrate/20120208191815_add_billing_period_to_jackpot_subscriptions.rb +5 -0
  60. data/db/migrate/20120208191934_add_good_until_date_to_jackpot_customers.rb +6 -0
  61. data/db/migrate/20120209203542_add_subscription_and_customer_to_jackpot_payments.rb +8 -0
  62. data/db/migrate/20120209212043_rename_column_token_in_jackpot_payments.rb +5 -0
  63. data/db/migrate/20120210144038_devise_create_jackpot_users.rb +49 -0
  64. data/jackpot.gemspec +33 -0
  65. data/lib/jackpot.rb +23 -0
  66. data/lib/jackpot/configuration.rb +33 -0
  67. data/lib/jackpot/cron.rb +22 -0
  68. data/lib/jackpot/engine.rb +14 -0
  69. data/lib/jackpot/errors.rb +18 -0
  70. data/lib/jackpot/factory.rb +26 -0
  71. data/lib/jackpot/version.rb +3 -0
  72. data/lib/tasks/jackpot_tasks.rake +38 -0
  73. data/script/rails +6 -0
  74. data/spec/controllers/jackpot/customers_controller_spec.rb +170 -0
  75. data/spec/controllers/jackpot/payments_controller_spec.rb +47 -0
  76. data/spec/controllers/jackpot/subscriptions_controller_spec.rb +153 -0
  77. data/spec/dummy/.gitignore +1 -0
  78. data/spec/dummy/Rakefile +7 -0
  79. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  80. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  81. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  82. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  83. data/spec/dummy/app/mailers/.gitkeep +0 -0
  84. data/spec/dummy/app/models/.gitkeep +0 -0
  85. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  86. data/spec/dummy/config.ru +4 -0
  87. data/spec/dummy/config/application.rb +51 -0
  88. data/spec/dummy/config/boot.rb +10 -0
  89. data/spec/dummy/config/database.yml +17 -0
  90. data/spec/dummy/config/environment.rb +5 -0
  91. data/spec/dummy/config/environments/development.rb +32 -0
  92. data/spec/dummy/config/environments/production.rb +60 -0
  93. data/spec/dummy/config/environments/test.rb +41 -0
  94. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  95. data/spec/dummy/config/initializers/inflections.rb +10 -0
  96. data/spec/dummy/config/initializers/jackpot.rb +13 -0
  97. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  98. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  99. data/spec/dummy/config/initializers/session_store.rb +8 -0
  100. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  101. data/spec/dummy/config/locales/en.yml +5 -0
  102. data/spec/dummy/config/routes.rb +3 -0
  103. data/spec/dummy/db/schema.rb +68 -0
  104. data/spec/dummy/lib/assets/.gitkeep +0 -0
  105. data/spec/dummy/public/404.html +26 -0
  106. data/spec/dummy/public/422.html +26 -0
  107. data/spec/dummy/public/500.html +26 -0
  108. data/spec/dummy/public/favicon.ico +0 -0
  109. data/spec/dummy/public/index.html +5 -0
  110. data/spec/dummy/public/payment.html +36 -0
  111. data/spec/dummy/script/rails +6 -0
  112. data/spec/fixtures/vcr/Create_Customers_To_bill_monthly_my_customers_As_a_user_I_want_to_record_their_billing_information_/assigning_credit_card_information_to_customer.yml +34 -0
  113. data/spec/fixtures/vcr/Jackpot_Customer/_update_credit_card_number/when_card_is_valid/.yml +34 -0
  114. data/spec/fixtures/vcr/Jackpot_Customer/_update_credit_card_number/when_card_is_valid/when_persisting/should_NEVER_persist_in_the_database_the_actual_card_number.yml +34 -0
  115. data/spec/fixtures/vcr/Jackpot_Customer/_update_credit_card_number/when_card_is_valid/when_persisting/should_NEVER_persist_in_the_database_the_verification_value.yml +34 -0
  116. data/spec/fixtures/vcr/Jackpot_Customer/_update_credit_card_number/when_card_is_valid/when_persisting/should_persist_in_the_database_the_ONLY_last_four_digits.yml +34 -0
  117. data/spec/fixtures/vcr/Jackpot_Customer/_update_credit_card_number/when_card_is_valid/when_persisting/should_persist_the_card_information.yml +34 -0
  118. data/spec/fixtures/vcr/Jackpot_Customer/_update_credit_card_number/when_card_is_valid/when_persisting/should_store_this_card_at_the_gateway.yml +34 -0
  119. data/spec/fixtures/vcr/Jackpot_Payment/_create/with_valid_token_information/creates_a_new_payment.yml +96 -0
  120. data/spec/fixtures/vcr/Jackpot_Payment/_create/with_valid_token_information/does_not_persist_credit_card_token_information.yml +96 -0
  121. data/spec/fixtures/vcr/Jackpot_Payment/_create/with_valid_token_information/records_the_payment_transaction_id_for_future_reference.yml +96 -0
  122. data/spec/fixtures/vcr/Jackpot_Payment/_create/with_valid_token_information/records_this_payment_information.yml +96 -0
  123. data/spec/fixtures/vcr/Jackpot_Payment/_customer_name/returns_its_customer_email.yml +96 -0
  124. data/spec/fixtures/vcr/jackpot/customer/updatecard.yml +34 -0
  125. data/spec/fixtures/vcr/jackpot/customer_expiration_date.yml +34 -0
  126. data/spec/fixtures/vcr/jackpot/receiving_payments.yml +96 -0
  127. data/spec/helpers/jackpot/customers_helper_spec.rb +16 -0
  128. data/spec/helpers/jackpot/subscriptions_helper_spec.rb +4 -0
  129. data/spec/lib/cron_spec.rb +39 -0
  130. data/spec/lib/factory_spec.rb +40 -0
  131. data/spec/models/jackpot/card_spec.rb +23 -0
  132. data/spec/models/jackpot/customer_spec.rb +140 -0
  133. data/spec/models/jackpot/gateway_spec.rb +22 -0
  134. data/spec/models/jackpot/payment_spec.rb +74 -0
  135. data/spec/models/jackpot/subscription_spec.rb +19 -0
  136. data/spec/requests/jackpot/jackpot_assign_subscription_to_customer_spec.rb +39 -0
  137. data/spec/requests/jackpot/jackpot_create_customer_spec.rb +73 -0
  138. data/spec/requests/jackpot/jackpot_create_subscriptions_spec.rb +27 -0
  139. data/spec/requests/jackpot/jackpot_receive_payments_spec.rb +34 -0
  140. data/spec/spec_helper.rb +41 -0
  141. data/spec/support/active_merchant.rb +1 -0
  142. data/spec/support/capybara.rb +6 -0
  143. data/spec/support/devise.rb +21 -0
  144. data/spec/support/factories/jackpot_customers.rb +36 -0
  145. data/spec/support/factories/jackpot_payments.rb +7 -0
  146. data/spec/support/factories/jackpot_subscriptions.rb +9 -0
  147. data/spec/support/factories/jackpot_users.rb +9 -0
  148. data/spec/support/helpers.rb +16 -0
  149. data/spec/support/routes.rb +3 -0
  150. data/spec/support/vcr.rb +10 -0
  151. data/vendor/assets/images/twitter/bootstrap/glyphicons-halflings-white.png +0 -0
  152. data/vendor/assets/images/twitter/bootstrap/glyphicons-halflings.png +0 -0
  153. data/vendor/assets/javascripts/twitter/bootstrap.js +12 -0
  154. data/vendor/assets/javascripts/twitter/bootstrap/bootstrap-alert.js +91 -0
  155. data/vendor/assets/javascripts/twitter/bootstrap/bootstrap-button.js +98 -0
  156. data/vendor/assets/javascripts/twitter/bootstrap/bootstrap-carousel.js +154 -0
  157. data/vendor/assets/javascripts/twitter/bootstrap/bootstrap-collapse.js +136 -0
  158. data/vendor/assets/javascripts/twitter/bootstrap/bootstrap-dropdown.js +92 -0
  159. data/vendor/assets/javascripts/twitter/bootstrap/bootstrap-modal.js +209 -0
  160. data/vendor/assets/javascripts/twitter/bootstrap/bootstrap-popover.js +95 -0
  161. data/vendor/assets/javascripts/twitter/bootstrap/bootstrap-scrollspy.js +125 -0
  162. data/vendor/assets/javascripts/twitter/bootstrap/bootstrap-tab.js +130 -0
  163. data/vendor/assets/javascripts/twitter/bootstrap/bootstrap-tooltip.js +270 -0
  164. data/vendor/assets/javascripts/twitter/bootstrap/bootstrap-transition.js +51 -0
  165. data/vendor/assets/javascripts/twitter/bootstrap/bootstrap-typeahead.js +271 -0
  166. data/vendor/assets/stylesheets/twitter/bootstrap/bootstrap-responsive.css +567 -0
  167. data/vendor/assets/stylesheets/twitter/bootstrap/bootstrap.css.erb +3366 -0
  168. metadata +351 -0
@@ -0,0 +1,57 @@
1
+ # Additional translations at https://github.com/plataformatec/devise/wiki/I18n
2
+
3
+ en:
4
+ errors:
5
+ messages:
6
+ expired: "has expired, please request a new one"
7
+ not_found: "not found"
8
+ already_confirmed: "was already confirmed, please try signing in"
9
+ not_locked: "was not locked"
10
+ not_saved:
11
+ one: "1 error prohibited this %{resource} from being saved:"
12
+ other: "%{count} errors prohibited this %{resource} from being saved:"
13
+
14
+ devise:
15
+ failure:
16
+ already_authenticated: 'You are already signed in.'
17
+ unauthenticated: 'You need to sign in or sign up before continuing.'
18
+ unconfirmed: 'You have to confirm your account before continuing.'
19
+ locked: 'Your account is locked.'
20
+ invalid: 'Invalid email or password.'
21
+ invalid_token: 'Invalid authentication token.'
22
+ timeout: 'Your session expired, please sign in again to continue.'
23
+ inactive: 'Your account was not activated yet.'
24
+ sessions:
25
+ signed_in: 'Signed in successfully.'
26
+ signed_out: 'Signed out successfully.'
27
+ passwords:
28
+ send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
29
+ updated: 'Your password was changed successfully. You are now signed in.'
30
+ updated_not_active: 'Your password was changed successfully.'
31
+ send_paranoid_instructions: "If your e-mail exists on our database, you will receive a password recovery link on your e-mail"
32
+ confirmations:
33
+ send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
34
+ send_paranoid_instructions: 'If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
35
+ confirmed: 'Your account was successfully confirmed. You are now signed in.'
36
+ registrations:
37
+ signed_up: 'Welcome! You have signed up successfully.'
38
+ signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
39
+ signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
40
+ signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
41
+ updated: 'You updated your account successfully.'
42
+ update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
43
+ destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
44
+ unlocks:
45
+ send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
46
+ unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
47
+ send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
48
+ omniauth_callbacks:
49
+ success: 'Successfully authorized from %{kind} account.'
50
+ failure: 'Could not authorize you from %{kind} because "%{reason}".'
51
+ mailer:
52
+ confirmation_instructions:
53
+ subject: 'Confirmation instructions'
54
+ reset_password_instructions:
55
+ subject: 'Reset password instructions'
56
+ unlock_instructions:
57
+ subject: 'Unlock Instructions'
@@ -0,0 +1,17 @@
1
+ Jackpot::Engine.routes.draw do
2
+ resources :customers do
3
+ member do
4
+ put "credit_card"
5
+ end
6
+ end
7
+
8
+ resources :subscriptions
9
+ resources :payments
10
+
11
+
12
+ root :to => "payments#index"
13
+ devise_for :users, {
14
+ :class_name => 'Jackpot::User',
15
+ :module => :devise
16
+ }
17
+ end
@@ -0,0 +1,11 @@
1
+ class CreateJackpotPayments < ActiveRecord::Migration
2
+ def change
3
+ create_table :jackpot_payments do |t|
4
+ t.string :token
5
+ t.integer :amount
6
+ t.text :description
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ class AddCustomerInformationToJackpotPayments < ActiveRecord::Migration
2
+ def change
3
+ add_column :jackpot_payments, :customer_name, :string
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ class CreateJackpotSubscriptions < ActiveRecord::Migration
2
+ def change
3
+ create_table :jackpot_subscriptions do |t|
4
+ t.string :name
5
+ t.integer :price
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ class CreateJackpotCustomers < ActiveRecord::Migration
2
+ def change
3
+ create_table :jackpot_customers do |t|
4
+ t.string :email
5
+ t.text :description
6
+ t.integer :subscription_id
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ class AddCreditCardNumberToCustomer < ActiveRecord::Migration
2
+ def change
3
+ add_column :jackpot_customers, :credit_card_number, :string
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ class AddCreditCardInformationToCustomers < ActiveRecord::Migration
2
+ def change
3
+ add_column :jackpot_customers, :credit_card_expiry_month, :integer
4
+ add_column :jackpot_customers, :credit_card_expiry_year, :integer
5
+ add_column :jackpot_customers, :credit_card_token, :string
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class AddBillingPeriodToJackpotSubscriptions < ActiveRecord::Migration
2
+ def change
3
+ add_column :jackpot_subscriptions, :billing_period, :integer
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class AddGoodUntilDateToJackpotCustomers < ActiveRecord::Migration
2
+ def change
3
+ add_column :jackpot_customers, :good_until, :date
4
+
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ class AddSubscriptionAndCustomerToJackpotPayments < ActiveRecord::Migration
2
+ def change
3
+ change_table :jackpot_payments do |t|
4
+ t.references :subscription
5
+ t.references :customer
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ class RenameColumnTokenInJackpotPayments < ActiveRecord::Migration
2
+ def change
3
+ rename_column :jackpot_payments, :token, :payment_transaction_token
4
+ end
5
+ end
@@ -0,0 +1,49 @@
1
+ class DeviseCreateJackpotUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table(:jackpot_users) do |t|
4
+ ## Database authenticatable
5
+ t.string :email, :null => false, :default => ""
6
+ t.string :encrypted_password, :null => false, :default => ""
7
+
8
+ ## Recoverable
9
+ t.string :reset_password_token
10
+ t.datetime :reset_password_sent_at
11
+
12
+ ## Rememberable
13
+ t.datetime :remember_created_at
14
+
15
+ ## Trackable
16
+ t.integer :sign_in_count, :default => 0
17
+ t.datetime :current_sign_in_at
18
+ t.datetime :last_sign_in_at
19
+ t.string :current_sign_in_ip
20
+ t.string :last_sign_in_ip
21
+
22
+ ## Encryptable
23
+ # t.string :password_salt
24
+
25
+ ## Confirmable
26
+ # t.string :confirmation_token
27
+ # t.datetime :confirmed_at
28
+ # t.datetime :confirmation_sent_at
29
+ # t.string :unconfirmed_email # Only if using reconfirmable
30
+
31
+ ## Lockable
32
+ # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
33
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
34
+ # t.datetime :locked_at
35
+
36
+ ## Token authenticatable
37
+ t.string :authentication_token
38
+
39
+
40
+ t.timestamps
41
+ end
42
+
43
+ add_index :jackpot_users, :email, :unique => true
44
+ add_index :jackpot_users, :reset_password_token, :unique => true
45
+ add_index :jackpot_users, :authentication_token, :unique => true
46
+ # add_index :jackpot_users, :confirmation_token, :unique => true
47
+ # add_index :jackpot_users, :unlock_token, :unique => true
48
+ end
49
+ end
@@ -0,0 +1,33 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require "jackpot/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |s|
8
+ s.name = "jackpot"
9
+
10
+ s.version = Jackpot::VERSION
11
+ s.homepage = "http://github.com/pellegrino/jackpot"
12
+ s.license = "MIT"
13
+ s.summary = "Billing for rack apps"
14
+ s.description = "Billing for rack apps"
15
+ s.email = "vitorp@gmail.com"
16
+ s.authors = ["Vitor Pellegrino"]
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+
20
+ s.add_development_dependency "capybara", "~> 1.1"
21
+ s.add_development_dependency "timecop", "~> 0.3"
22
+ s.add_development_dependency "database_cleaner", "~> 0.7"
23
+ s.add_development_dependency "factory_girl_rails", "~> 1.6.0"
24
+ s.add_development_dependency 'rspec-rails', "~> 2.8"
25
+ s.add_development_dependency 'shoulda-matchers', "~> 1.0.0"
26
+ s.add_development_dependency 'vcr', "~> 2.0.0.rc1"
27
+ s.add_development_dependency 'fakeweb'
28
+
29
+ s.add_dependency "rails", "~> 3.1"
30
+ s.add_dependency "formtastic-bootstrap", "~> 1.1"
31
+ s.add_dependency "activemerchant", "~> 1.20.1"
32
+ s.add_dependency "devise", "~> 2.0"
33
+ end
@@ -0,0 +1,23 @@
1
+ require "jackpot/engine"
2
+ require 'jackpot/errors'
3
+ require 'jackpot/configuration'
4
+ require 'jackpot/factory'
5
+ require 'jackpot/cron'
6
+
7
+ require 'devise'
8
+
9
+ module Jackpot
10
+ extend self
11
+
12
+
13
+ def configure
14
+ yield configuration
15
+ factory = Jackpot::Factory.new(configuration.gateway)
16
+ Jackpot::Payment.gateway = factory.build
17
+ end
18
+
19
+ def configuration
20
+ @configuration ||= Configuration.new
21
+ end
22
+
23
+ end
@@ -0,0 +1,33 @@
1
+ module Jackpot
2
+
3
+ class Configuration
4
+
5
+ attr_accessor :default_options
6
+ attr_accessor :gateway
7
+
8
+ def initialize
9
+ @gateway = HashWithIndifferentAccess.new
10
+ end
11
+
12
+
13
+ def gateway_type(gateway)
14
+ @gateway[:type] = gateway
15
+ end
16
+
17
+
18
+ def gateway_login(login)
19
+ @gateway[:login] = login
20
+ end
21
+
22
+
23
+ def gateway_password(password)
24
+ @gateway[:password] = password
25
+ end
26
+
27
+ def gateway_mode(mode)
28
+ @gateway[:mode] = mode
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,22 @@
1
+ require_relative 'errors'
2
+
3
+ module Jackpot
4
+ class Cron
5
+
6
+ def initialize(customer_storage, logger)
7
+ @customer_storage = customer_storage
8
+ @logger = logger
9
+ end
10
+
11
+ def run
12
+ overdue_customers = @customer_storage.overdue
13
+ overdue_customers.each do |c|
14
+ begin
15
+ c.pay_subscription
16
+ rescue Jackpot::Error => e
17
+ @logger.error "Something was wrong when trying to process #{c} payment. Exception was #{e}"
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ require 'active_merchant'
2
+ require 'devise'
3
+ require 'formtastic-bootstrap'
4
+
5
+ module Jackpot
6
+ class Engine < Rails::Engine
7
+ isolate_namespace Jackpot
8
+ config.generators do |g|
9
+ g.test_framework :rspec, :view_specs => false
10
+ g.fixture_replacement :factory_girl, :dir => "spec/support/factories"
11
+ end
12
+ end
13
+ end
14
+ Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
@@ -0,0 +1,18 @@
1
+ module Jackpot
2
+
3
+ Error = Class.new(StandardError)
4
+
5
+ module Errors
6
+ # Basic Jackpot error class
7
+ #
8
+ # This error is raised when Jackpot::Payment.initialize_credit_card tries to
9
+ # issue a payment to an invalid card
10
+ CardIsInvalid = Class.new(Jackpot::Error)
11
+
12
+ # This error indicates the Gateway was not initialized correctly
13
+ InvalidGateway = Class.new(Jackpot::Error)
14
+ CustomerHasNoCardSaved = Class.new(Jackpot::Error)
15
+ UnauthorizedPayment = Class.new(Jackpot::Error)
16
+ end
17
+
18
+ end
@@ -0,0 +1,26 @@
1
+ require_relative 'errors'
2
+
3
+ module Jackpot
4
+
5
+ class Factory
6
+
7
+ def initialize(gateway_configuration)
8
+ @gateway_configuration = HashWithIndifferentAccess.new gateway_configuration
9
+ end
10
+
11
+ def build
12
+ if @gateway_configuration[:type] == :braintree
13
+ Jackpot::Gateway.new(ActiveMerchant::Billing::BraintreeGateway.new(
14
+ :login => @gateway_configuration['login'],
15
+ :password => @gateway_configuration['password'],
16
+ :mode => @gateway_configuration['mode']))
17
+ elsif @gateway_configuration['type'] == :bogus
18
+ Jackpot::Gateway.new(ActiveMerchant::Billing::BogusGateway.new)
19
+ else
20
+ raise Jackpot::Errors::InvalidGateway.new "There is no #{@gateway_configuration['type']}: available options are :braintree, :bogus"
21
+ end
22
+
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Jackpot
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,38 @@
1
+ # desc "Explaining what the task does"
2
+ # task :jackpot do
3
+ # # Task goes here
4
+ # end
5
+ #
6
+ namespace :jackpot do
7
+ task :environment do
8
+ require './spec/dummy/config/environment'
9
+ end
10
+
11
+ task :routes => :environment do
12
+ all_routes = Jackpot::Engine.routes.routes
13
+
14
+ if ENV['CONTROLLER']
15
+ all_routes = all_routes.select{ |route| route.defaults[:controller] == ENV['CONTROLLER'] }
16
+ end
17
+
18
+ routes = all_routes.collect do |route|
19
+
20
+ reqs = route.requirements.dup
21
+ reqs[:to] = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/
22
+ reqs = reqs.empty? ? "" : reqs.inspect
23
+
24
+ {:name => route.name.to_s, :verb => route.verb.to_s, :path => route.path, :reqs => reqs}
25
+ end
26
+
27
+ # Skip the route if it's internal info route
28
+ routes.reject! { |r| r[:path] =~ %r{/rails/info/properties|^/assets} }
29
+
30
+ name_width = routes.map{ |r| r[:name].length }.max
31
+ verb_width = routes.map{ |r| r[:verb].length }.max
32
+ path_width = routes.map{ |r| r[:path].length }.max
33
+
34
+ routes.each do |r|
35
+ puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}"
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ #!/usr/bin/env ruby
3
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
4
+
5
+ ENGINE_PATH = File.expand_path('../..', __FILE__)
6
+ load File.expand_path('../../spec/dummy/script/rails', __FILE__)