saaz 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +33 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +21 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +11 -0
  7. data/Rakefile +32 -0
  8. data/Readme.md +11 -0
  9. data/app/assets/images/saaz/.keep +0 -0
  10. data/app/assets/javascripts/saaz.js.coffee +1 -0
  11. data/app/assets/javascripts/saaz/application.js.coffee +13 -0
  12. data/app/assets/javascripts/saaz/forms.js.coffee.erb +57 -0
  13. data/app/assets/stylesheets/saaz.css.scss +1 -0
  14. data/app/assets/stylesheets/saaz/_vars.css.scss +0 -0
  15. data/app/assets/stylesheets/saaz/application.css.scss +13 -0
  16. data/app/assets/stylesheets/saaz/customers.css.scss +24 -0
  17. data/app/assets/stylesheets/saaz/devmode.css.scss +5 -0
  18. data/app/controllers/saaz/application_controller.rb +2 -0
  19. data/app/controllers/saaz/customers_controller.rb +74 -0
  20. data/app/helpers/saaz/application_helper.rb +4 -0
  21. data/app/helpers/saaz/customers_helper.rb +4 -0
  22. data/app/models/saaz/customer.rb +47 -0
  23. data/app/models/saaz/subscription.rb +42 -0
  24. data/app/views/layouts/saaz/application.html.erb +14 -0
  25. data/app/views/saaz/customers/_form.html.erb +28 -0
  26. data/app/views/saaz/customers/edit.html.erb +11 -0
  27. data/app/views/saaz/customers/new.html.erb +8 -0
  28. data/config/routes.rb +2 -0
  29. data/db/migrate/20140709194435_add_customers.rb +9 -0
  30. data/db/migrate/20140709194448_add_subscriptions.rb +10 -0
  31. data/lib/saaz.rb +19 -0
  32. data/lib/saaz/configuration.rb +30 -0
  33. data/lib/saaz/engine.rb +5 -0
  34. data/lib/saaz/stripe_object.rb +66 -0
  35. data/lib/saaz/version.rb +3 -0
  36. data/lib/tasks/saaz_tasks.rake +4 -0
  37. data/saaz.gemspec +25 -0
  38. data/spec/dummy/README.rdoc +28 -0
  39. data/spec/dummy/Rakefile +6 -0
  40. data/spec/dummy/app/assets/images/.keep +0 -0
  41. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  42. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  43. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  44. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  45. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  46. data/spec/dummy/app/mailers/.keep +0 -0
  47. data/spec/dummy/app/models/.keep +0 -0
  48. data/spec/dummy/app/models/concerns/.keep +0 -0
  49. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  50. data/spec/dummy/bin/bundle +3 -0
  51. data/spec/dummy/bin/rails +4 -0
  52. data/spec/dummy/bin/rake +4 -0
  53. data/spec/dummy/config.ru +4 -0
  54. data/spec/dummy/config/application.rb +23 -0
  55. data/spec/dummy/config/boot.rb +5 -0
  56. data/spec/dummy/config/database.yml +25 -0
  57. data/spec/dummy/config/environment.rb +5 -0
  58. data/spec/dummy/config/environments/development.rb +29 -0
  59. data/spec/dummy/config/environments/production.rb +80 -0
  60. data/spec/dummy/config/environments/test.rb +36 -0
  61. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  62. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  63. data/spec/dummy/config/initializers/inflections.rb +16 -0
  64. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  65. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  66. data/spec/dummy/config/initializers/session_store.rb +3 -0
  67. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  68. data/spec/dummy/config/locales/en.yml +23 -0
  69. data/spec/dummy/config/routes.rb +4 -0
  70. data/spec/dummy/lib/assets/.keep +0 -0
  71. data/spec/dummy/log/.keep +0 -0
  72. data/spec/dummy/public/404.html +58 -0
  73. data/spec/dummy/public/422.html +58 -0
  74. data/spec/dummy/public/500.html +57 -0
  75. data/spec/dummy/public/favicon.ico +0 -0
  76. data/spec/integration/navigation_test.rb +10 -0
  77. data/spec/saaz_test.rb +7 -0
  78. data/spec/test_helper.rb +15 -0
  79. data/test/controllers/saaz/saaz/customers_controller_test.rb +9 -0
  80. data/test/helpers/saaz/saaz/customers_helper_test.rb +6 -0
  81. metadata +250 -0
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Saaz</title>
5
+ <%= stylesheet_link_tag "saaz/application", media: "all" %>
6
+ <%= javascript_include_tag "saaz/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,28 @@
1
+ <span class="payment-errors"></span>
2
+
3
+ <div class="form-row">
4
+ <label for="saaz_customer_card_number">
5
+ Card Number
6
+ </label>
7
+ <input type="text" size="20" data-stripe="number" id="saaz_customer_card_number" class="SaazCustomerCard"/>
8
+ </div>
9
+
10
+ <div class="form-row">
11
+ <label for="saaz_customer_exp_month">
12
+ Expiration
13
+ </label>
14
+ <div class="SaazExpirationRow">
15
+ <input type="text" size="2" data-stripe="exp-month" class="SaazExpirationRow__month" placeholder="MM" id="saaz_customer_exp_month" />
16
+ <span class="SaazExpirationRow__separator"> / </span>
17
+ <input type="text" size="4" data-stripe="exp-year" class="SaazExpirationRow__year" placeholder="YYYY" />
18
+ </div>
19
+ </div>
20
+
21
+ <div class="form-row">
22
+ <label for="saaz_customer_cvc">
23
+ <span>CVC</span>
24
+ </label>
25
+ <input type="text" size="4" data-stripe="cvc" id="saaz_customer_cvc" class="SaazCustomerCVC" />
26
+ </div>
27
+
28
+ <button type="submit" class="btn">Submit Payment</button>
@@ -0,0 +1,11 @@
1
+ <div class="SaazFloatingBox">
2
+ <h3>Payment Information</h3>
3
+ <div class="SaazVerticalForm">
4
+ <%= form_tag main_app.url_for(action: 'update'), class: 'jsSaazCustomerForm', method: :patch do %>
5
+ <p>
6
+ Current Card: <%= @resource.default_card_string %>
7
+ </p>
8
+ <%= render partial: 'form' %>
9
+ <% end %>
10
+ </div>
11
+ </div>
@@ -0,0 +1,8 @@
1
+ <div class="SaazFloatingBox">
2
+ <h3>Payment Information</h3>
3
+ <div class="SaazVerticalForm">
4
+ <%= form_tag main_app.url_for(action: 'create'), class: 'jsSaazCustomerForm' do %>
5
+ <%= render partial: 'form' %>
6
+ <% end %>
7
+ </div>
8
+ </div>
@@ -0,0 +1,2 @@
1
+ Saaz::Engine.routes.draw do
2
+ end
@@ -0,0 +1,9 @@
1
+ class AddCustomers < ActiveRecord::Migration
2
+ def change
3
+ create_table "saaz_customers", force: true do |t|
4
+ t.string "stripe_id"
5
+ t.datetime "created_at"
6
+ t.datetime "updated_at"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ class AddSubscriptions < ActiveRecord::Migration
2
+ def change
3
+ create_table "saaz_subscriptions", force: true do |t|
4
+ t.string "stripe_id"
5
+ t.integer "customer_id"
6
+ t.datetime "created_at"
7
+ t.datetime "updated_at"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ require 'stripe'
2
+ require 'saaz/engine'
3
+ require 'saaz/version'
4
+ require 'saaz/stripe_object'
5
+ require 'saaz/configuration'
6
+
7
+ module Saaz
8
+ mattr_accessor :_config
9
+
10
+ def self.configure(&block)
11
+ block.call config
12
+
13
+ config.find_or_create_plans
14
+ end
15
+
16
+ def self.config
17
+ self._config ||= Configuration.new
18
+ end
19
+ end
@@ -0,0 +1,30 @@
1
+ class Saaz::Configuration
2
+ attr_accessor :plans, :publishable_key, :customer_resource_class
3
+
4
+ def api_key=(v)
5
+ Stripe.api_key = v
6
+ end
7
+
8
+ def api_key
9
+ Stripe.api_key
10
+ end
11
+
12
+ def plans
13
+ @plans || {}
14
+ end
15
+
16
+ def customer_resource_class
17
+ @customer_resource_class || Saaz::Customer
18
+ end
19
+
20
+ def find_or_create_plans
21
+ plans.each do |key, plan_params|
22
+ begin
23
+ Stripe::Plan.retrieve(key.to_s)
24
+ rescue Stripe::InvalidRequestError # Plan does not exist
25
+ plan_params[:id] ||= key.to_s
26
+ Stripe::Plan.create plan_params
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ module Saaz
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Saaz
4
+ end
5
+ end
@@ -0,0 +1,66 @@
1
+ module Saaz::StripeObject
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ validate :update_stripe, if: :stripe_dirty
6
+ attr_writer :stripe_dirty
7
+ end
8
+
9
+ def stripe_dirty
10
+ @stripe_dirty || false
11
+ end
12
+
13
+ def update_stripe
14
+ begin
15
+ to_stripe.save
16
+ self.stripe_dirty = false
17
+ rescue Stripe::StripeError => e
18
+ self.errors[:base] << e.message
19
+ end
20
+ end
21
+
22
+ def delegate_to_stripe(name, &block)
23
+ (class << self; self; end).class_eval do
24
+ define_method name, &block
25
+ end
26
+ end
27
+
28
+ def delegate_getter(attribute)
29
+ return if self.respond_to?(attribute)
30
+ delegate_to_stripe(attribute) do
31
+ to_stripe.send(attribute)
32
+ end
33
+ end
34
+
35
+ def delegate_setter(attribute)
36
+ setter_name = (attribute.to_s + '=').to_sym
37
+ return if self.respond_to?(setter_name)
38
+
39
+ delegate_to_stripe(setter_name) do |v|
40
+ self.stripe_dirty = true
41
+ to_stripe.send(setter_name, v)
42
+ end
43
+ end
44
+
45
+ def delegate_all_to_stripe(stripe_obj)
46
+ stripe_obj.keys.each do |attribute|
47
+ delegate_getter(attribute)
48
+ delegate_setter(attribute)
49
+ end
50
+ end
51
+
52
+ def method_missing(method_name, *args, &block)
53
+ begin
54
+ # Try the rails magic first
55
+ super
56
+ rescue NoMethodError => e
57
+ # See if the wrapped stripe object defines this
58
+ to_stripe
59
+ if methods.include? method_name
60
+ send(method_name, *args, &block)
61
+ else
62
+ fail e
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,3 @@
1
+ module Saaz
2
+ VERSION = '0.0.0'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :saaz do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/saaz/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ['Robert Prehn']
6
+ gem.email = ['robert@revelry.co']
7
+ gem.description = %q{Handling Stripe subscriptions and charges within Rails applications}
8
+ gem.summary = %q{Handling Stripe subscriptions and charges within Rails applications}
9
+ gem.homepage = 'http://github.com/revelrylabs/saaz'
10
+ gem.license = 'MIT'
11
+
12
+ gem.files = `git ls-files`.split($\)
13
+ gem.executables = []
14
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
+ gem.name = 'saaz'
16
+ gem.require_paths = ['lib']
17
+ gem.version = Saaz::VERSION
18
+
19
+ gem.add_dependency('rails', '>= 4.0')
20
+ gem.add_dependency('activesupport', '>= 4.0')
21
+ gem.add_dependency('stripe', '>= 1')
22
+ gem.add_development_dependency('rake')
23
+ gem.add_development_dependency('rspec')
24
+ gem.add_development_dependency('rspec-rails')
25
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Dummy::Application.load_tasks
File without changes
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
6
+ <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
@@ -0,0 +1,23 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require(*Rails.groups)
6
+ require "saaz"
7
+
8
+ module Dummy
9
+ class Application < Rails::Application
10
+ # Settings in config/environments/* take precedence over those specified here.
11
+ # Application configuration should go into files in config/initializers
12
+ # -- all .rb files in that directory are automatically loaded.
13
+
14
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
15
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
16
+ # config.time_zone = 'Central Time (US & Canada)'
17
+
18
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
19
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
20
+ # config.i18n.default_locale = :de
21
+ end
22
+ end
23
+
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ development:
7
+ adapter: sqlite3
8
+ database: db/development.sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ # Warning: The database defined as "test" will be erased and
13
+ # re-generated from your development database when you run "rake".
14
+ # Do not set this db to the same as development or production.
15
+ test:
16
+ adapter: sqlite3
17
+ database: db/test.sqlite3
18
+ pool: 5
19
+ timeout: 5000
20
+
21
+ production:
22
+ adapter: sqlite3
23
+ database: db/production.sqlite3
24
+ pool: 5
25
+ timeout: 5000
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the Rails application.
5
+ Dummy::Application.initialize!