paymill_on_rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +34 -0
  5. data/app/assets/javascripts/paymill_on_rails/application.js +13 -0
  6. data/app/assets/javascripts/paymill_on_rails/plans.js +2 -0
  7. data/app/assets/javascripts/paymill_on_rails/subscriptions.js +2 -0
  8. data/app/assets/stylesheets/paymill_on_rails/application.css +13 -0
  9. data/app/assets/stylesheets/paymill_on_rails/plans.css +4 -0
  10. data/app/assets/stylesheets/paymill_on_rails/subscriptions.css +4 -0
  11. data/app/assets/stylesheets/scaffold.css +56 -0
  12. data/app/controllers/paymill_on_rails/application_controller.rb +4 -0
  13. data/app/controllers/paymill_on_rails/plans_controller.rb +63 -0
  14. data/app/controllers/paymill_on_rails/subscriptions_controller.rb +70 -0
  15. data/app/helpers/paymill_on_rails/application_helper.rb +4 -0
  16. data/app/helpers/paymill_on_rails/plans_helper.rb +4 -0
  17. data/app/helpers/paymill_on_rails/subscriptions_helper.rb +4 -0
  18. data/app/models/paymill_on_rails/plan.rb +9 -0
  19. data/app/models/paymill_on_rails/subscription.rb +25 -0
  20. data/app/views/layouts/paymill_on_rails/application.html.erb +115 -0
  21. data/app/views/paymill_on_rails/plans/_form.html.erb +29 -0
  22. data/app/views/paymill_on_rails/plans/edit.html.erb +6 -0
  23. data/app/views/paymill_on_rails/plans/index.html.erb +41 -0
  24. data/app/views/paymill_on_rails/plans/new.html.erb +5 -0
  25. data/app/views/paymill_on_rails/plans/show.html.erb +28 -0
  26. data/app/views/paymill_on_rails/subscriptions/_form.html.erb +17 -0
  27. data/app/views/paymill_on_rails/subscriptions/edit.html.erb +6 -0
  28. data/app/views/paymill_on_rails/subscriptions/index.html.erb +25 -0
  29. data/app/views/paymill_on_rails/subscriptions/new.html.erb +52 -0
  30. data/app/views/paymill_on_rails/subscriptions/show.html.erb +6 -0
  31. data/config/initializers/paymill.rb +5 -0
  32. data/config/routes.rb +7 -0
  33. data/db/migrate/20131111122533_create_paymill_on_rails_plans.rb +12 -0
  34. data/db/migrate/20131111132308_create_paymill_on_rails_subscriptions.rb +13 -0
  35. data/lib/paymill_on_rails.rb +4 -0
  36. data/lib/paymill_on_rails/engine.rb +7 -0
  37. data/lib/paymill_on_rails/version.rb +3 -0
  38. data/lib/tasks/paymill_on_rails.rake +20 -0
  39. data/test/controllers/paymill_on_rails/plans_controller_test.rb +51 -0
  40. data/test/controllers/paymill_on_rails/subscriptions_controller_test.rb +51 -0
  41. data/test/dummy/README.rdoc +28 -0
  42. data/test/dummy/Rakefile +6 -0
  43. data/test/dummy/app/assets/javascripts/application.js +13 -0
  44. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  45. data/test/dummy/app/controllers/application_controller.rb +5 -0
  46. data/test/dummy/app/helpers/application_helper.rb +2 -0
  47. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  48. data/test/dummy/bin/bundle +3 -0
  49. data/test/dummy/bin/rails +4 -0
  50. data/test/dummy/bin/rake +4 -0
  51. data/test/dummy/config.ru +4 -0
  52. data/test/dummy/config/application.rb +23 -0
  53. data/test/dummy/config/boot.rb +5 -0
  54. data/test/dummy/config/database.yml +25 -0
  55. data/test/dummy/config/environment.rb +5 -0
  56. data/test/dummy/config/environments/development.rb +29 -0
  57. data/test/dummy/config/environments/production.rb +80 -0
  58. data/test/dummy/config/environments/test.rb +36 -0
  59. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  60. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  61. data/test/dummy/config/initializers/inflections.rb +16 -0
  62. data/test/dummy/config/initializers/mime_types.rb +5 -0
  63. data/test/dummy/config/initializers/secret_token.rb +12 -0
  64. data/test/dummy/config/initializers/session_store.rb +3 -0
  65. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  66. data/test/dummy/config/locales/en.yml +23 -0
  67. data/test/dummy/config/routes.rb +4 -0
  68. data/test/dummy/db/migrate/20131111135531_create_paymill_on_rails_plans.paymill_on_rails.rb +9 -0
  69. data/test/dummy/db/migrate/20131111135532_create_paymill_on_rails_subscriptions.paymill_on_rails.rb +9 -0
  70. data/test/dummy/public/404.html +58 -0
  71. data/test/dummy/public/422.html +58 -0
  72. data/test/dummy/public/500.html +57 -0
  73. data/test/dummy/public/favicon.ico +0 -0
  74. data/test/fixtures/paymill_on_rails/plans.yml +11 -0
  75. data/test/fixtures/paymill_on_rails/subscriptions.yml +11 -0
  76. data/test/helpers/paymill_on_rails/plans_helper_test.rb +6 -0
  77. data/test/helpers/paymill_on_rails/subscriptions_helper_test.rb +6 -0
  78. data/test/integration/navigation_test.rb +10 -0
  79. data/test/models/paymill_on_rails/plan_test.rb +9 -0
  80. data/test/models/paymill_on_rails/subscription_test.rb +9 -0
  81. data/test/paymill_on_rails_test.rb +7 -0
  82. data/test/test_helper.rb +15 -0
  83. metadata +211 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: 5ac18899865becc43f7cabd938227ee4a65e7bea
4
+ data.tar.gz: 8c24e97a61540247395e5b221a9752891f898312
5
+ !binary "U0hBNTEy":
6
+ metadata.gz: 97237602c288e648c030cb8dad3d541aaec40c2a630f8c91d4c8de03665dc9492651e2e3b5562ce6dc3dff5b597f0208ea42367493c79eba713aad872053e0fd
7
+ data.tar.gz: d5bbd9be2f001bb21974849d9b93ef4ae233d25c0d4022fecd533d758f8678989ec624f67e47bf84f036a777280c9b7a8ed487f90ea9d2e114a5ba8a500c5de8
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = PaymillOnRails
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'PaymillOnRails'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -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,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -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,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,4 @@
1
+ module PaymillOnRails
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,63 @@
1
+ require_dependency "paymill_on_rails/application_controller"
2
+
3
+ module PaymillOnRails
4
+ class PlansController < ApplicationController
5
+ #before_action :set_plan, only: [:show, :edit, :update, :destroy]
6
+
7
+ # GET /plans
8
+ def index
9
+ @plans = Plan.order("price")
10
+ end
11
+
12
+ # # GET /plans/1
13
+ # def show
14
+ # end
15
+ #
16
+ # # GET /plans/new
17
+ # def new
18
+ # @plan = Plan.new
19
+ # end
20
+ #
21
+ # # GET /plans/1/edit
22
+ # def edit
23
+ # end
24
+ #
25
+ # # POST /plans
26
+ # def create
27
+ # @plan = Plan.new(plan_params)
28
+ #
29
+ # if @plan.save
30
+ # redirect_to @plan, notice: 'Plan was successfully created.'
31
+ # else
32
+ # render action: 'new'
33
+ # end
34
+ # end
35
+ #
36
+ # # PATCH/PUT /plans/1
37
+ # def update
38
+ # if @plan.update(plan_params)
39
+ # redirect_to @plan, notice: 'Plan was successfully updated.'
40
+ # else
41
+ # render action: 'edit'
42
+ # end
43
+ # end
44
+ #
45
+ # # DELETE /plans/1
46
+ # def destroy
47
+ # @plan.destroy
48
+ # redirect_to plans_url, notice: 'Plan was successfully destroyed.'
49
+ # end
50
+ #
51
+ # private
52
+ # # Use callbacks to share common setup or constraints between actions.
53
+ # def set_plan
54
+ # @plan = Plan.find(params[:id])
55
+ # end
56
+ #
57
+ # # Only allow a trusted parameter "white list" through.
58
+ # def plan_params
59
+ # params[:plan]
60
+ # end
61
+
62
+ end
63
+ end
@@ -0,0 +1,70 @@
1
+ require_dependency "paymill_on_rails/application_controller"
2
+
3
+ module PaymillOnRails
4
+ class SubscriptionsController < ApplicationController
5
+ before_action :set_subscription, only: [:show, :edit, :update, :destroy]
6
+
7
+ # GET /subscriptions
8
+ #def index
9
+ # @subscriptions = Subscription.all
10
+ #end
11
+
12
+ # GET /subscriptions/1
13
+ def show
14
+ @subscription = Subscription.find(params[:id])
15
+ end
16
+
17
+ # GET /subscriptions/new
18
+ def new
19
+ plan = Plan.find(params[:plan_id])
20
+ @subscription = plan.subscriptions.build
21
+ end
22
+
23
+ # GET /subscriptions/1/edit
24
+ #def edit
25
+ #end
26
+
27
+ # POST /subscriptions
28
+ def create
29
+ @subscription = Subscription.new( subscription_params )
30
+ if @subscription.save_with_payment
31
+ redirect_to @subscription, :notice => "Thank you for subscribing!"
32
+ else
33
+ render :new
34
+ end
35
+ end
36
+
37
+ # PATCH/PUT /subscriptions/1
38
+ #def update
39
+ # if @subscription.update(subscription_params)
40
+ # redirect_to @subscription, notice: 'Subscription was successfully updated.'
41
+ # else
42
+ # render action: 'edit'
43
+ # end
44
+ #end
45
+
46
+ # DELETE /subscriptions/1
47
+ #def destroy
48
+ # @subscription.destroy
49
+ # redirect_to subscriptions_url, notice: 'Subscription was successfully destroyed.'
50
+ #end
51
+
52
+ private
53
+
54
+ # orig
55
+ #def subscription_params
56
+ # params[:subscription]
57
+ #end
58
+
59
+ # Only allow a trusted parameter "white list" through.
60
+ def subscription_params
61
+ # specialize this private method with per-user checking of permissible attributes with params.require :
62
+ params.require(:subscription).permit(:name, :email, :paymill_id, :plan_id, :paymill_card_token)
63
+ end
64
+
65
+ # Use callbacks to share common setup or constraints between actions.
66
+ def set_subscription
67
+ @subscription = Subscription.find(params[:id])
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,4 @@
1
+ module PaymillOnRails
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module PaymillOnRails
2
+ module PlansHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module PaymillOnRails
2
+ module SubscriptionsHelper
3
+ end
4
+ end
@@ -0,0 +1,9 @@
1
+ module PaymillOnRails
2
+ class Plan < ActiveRecord::Base
3
+ include ActiveModel::ForbiddenAttributesProtection
4
+
5
+ has_many :subscriptions
6
+ end
7
+ end
8
+
9
+
@@ -0,0 +1,25 @@
1
+ module PaymillOnRails
2
+ class Subscription < ActiveRecord::Base
3
+ include ActiveModel::ForbiddenAttributesProtection
4
+ attr_accessor :paymill_card_token
5
+
6
+ belongs_to :plan
7
+ validates_presence_of :plan_id
8
+ validates_presence_of :email
9
+
10
+ def save_with_payment
11
+ if valid?
12
+ client = Paymill::Client.create email: email, description: name
13
+ payment = Paymill::Payment.create token: paymill_card_token, client: client.id
14
+ subscription = Paymill::Subscription.create offer: plan.paymill_id, client: client.id, payment: payment.id
15
+
16
+ self.paymill_id = subscription.id
17
+ save!
18
+ end
19
+ rescue Paymill::PaymillError => e
20
+ logger.error "Paymill error while creating customer: #{e.message}"
21
+ errors.add :base, "There was a problem with your credit card. Please try again."
22
+ false
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,115 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title><%= content_for?(:title) ? yield(:title) : "PaymillOnRails" %></title>
8
+
9
+ <!-- %= stylesheet_link_tag "paymill_on_rails/application", media: "all", "data-turbolinks-track" => true % -->
10
+ <%= stylesheet_link_tag "scaffold" %>
11
+
12
+ <!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
13
+ <!--[if lt IE 9]>
14
+ <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.1/html5shiv.js" type="text/javascript"></script>
15
+ <![endif]-->
16
+
17
+ <!-- For third-generation iPad with high-resolution Retina display: -->
18
+ <!-- Size should be 144 x 144 pixels -->
19
+ <%= favicon_link_tag 'images/apple-touch-icon-144x144-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '144x144' %>
20
+
21
+ <!-- For iPhone with high-resolution Retina display: -->
22
+ <!-- Size should be 114 x 114 pixels -->
23
+ <%= favicon_link_tag 'images/apple-touch-icon-114x114-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '114x114' %>
24
+
25
+ <!-- For first- and second-generation iPad: -->
26
+ <!-- Size should be 72 x 72 pixels -->
27
+ <%= favicon_link_tag 'images/apple-touch-icon-72x72-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '72x72' %>
28
+
29
+ <!-- For non-Retina iPhone, iPod Touch, and Android 2.1+ devices: -->
30
+ <!-- Size should be 57 x 57 pixels -->
31
+ <%= favicon_link_tag 'images/apple-touch-icon-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png' %>
32
+
33
+ <!-- For all other devices -->
34
+ <!-- Size should be 32 x 32 pixels -->
35
+ <%= favicon_link_tag 'favicon.ico', :rel => 'shortcut icon' %>
36
+
37
+ <style type="text/css">
38
+ body {
39
+ padding-top: 20px;
40
+ padding-bottom: 40px;
41
+ }
42
+
43
+ /* Custom container */
44
+ .container-narrow {
45
+ margin: 0 auto;
46
+ max-width: 700px;
47
+ }
48
+ .container-narrow > hr {
49
+ margin: 30px 0;
50
+ }
51
+
52
+ /* Main marketing message and sign up button */
53
+ .jumbotron {
54
+ margin: 60px 0;
55
+ text-align: center;
56
+ }
57
+ .jumbotron h1 {
58
+ font-size: 72px;
59
+ line-height: 1;
60
+ }
61
+ .jumbotron .btn {
62
+ font-size: 21px;
63
+ padding: 14px 24px;
64
+ }
65
+
66
+ /* Supporting marketing content */
67
+ .marketing {
68
+ margin: 60px 0;
69
+ }
70
+ .marketing p + h4 {
71
+ margin-top: 28px;
72
+ }
73
+ </style>
74
+
75
+
76
+ </head>
77
+ <body>
78
+ <div class="container">
79
+
80
+ <div class="masthead">
81
+ <ul class="nav nav-pills pull-right">
82
+ <li class="active"><a href="http://paymill-on-rails.herokuapp.com/">Home</a></li>
83
+ <li><a href="https://github.com/lgs/paymill-on-rails">Source Code</a></li>
84
+ <li><a href="https://github.com/lgs">Contact</a></li>
85
+ </ul>
86
+ <h3 class="muted">Paymill on Rails 4.0.0</h3>
87
+ </div>
88
+
89
+ <hr>
90
+ <div class="subscriptions">
91
+ <% flash.each do |name, msg| %>
92
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
93
+ <% end %>
94
+ <%= yield %>
95
+ </div>
96
+
97
+ <hr>
98
+ <div class="footer">
99
+ <p>&copy; 2013 <a href="https://github.com/lgs">Luca G. Soave</a></p>
100
+ </div>
101
+
102
+ </div> <!-- /container -->
103
+
104
+ <!-- Javascripts
105
+ ================================================== -->
106
+ <!-- Placed at the end of the document so the pages load faster -->
107
+
108
+ <%= javascript_include_tag "https://bridge.paymill.com/", "paymill_on_rails/application", "data-turbolinks-track" => true %>
109
+ <%= csrf_meta_tags %>
110
+ <script type="text/javascript">
111
+ var PAYMILL_PUBLIC_KEY = '<%=PAYMILL_PUBLIC_KEY%>';
112
+ </script>
113
+ </body>
114
+ </html>
115
+