stripe_helper 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MjQ2NTEzYWRjZDVhNTA4MTJiY2Q0MDczMDkwMWZkM2RmMGFjMjhkMg==
5
+ data.tar.gz: !binary |-
6
+ OGVmYzgyMDQ5MjA1ZjViNjMyMTM5ZjY0MTMyY2QzMmZiYjFmYTMxMg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OGJlYjkzYzk2ZTdlOWNhMTQ5MjFlNmIwNjlmZmZjM2YwM2ZhNDE1YzJjNzhj
10
+ YjJmMWM1YTAwZDA2NjU4OWQxZGY5MmFlMjhkNTI3MjgwODc1YTYzNGU2OTNj
11
+ OTBmNTc3NTdlY2QwMGUzYjUyNGQ5MDQxMjMyOGFmMDllMDc1YWU=
12
+ data.tar.gz: !binary |-
13
+ ZTE5M2JmNjBiOTAxYzZiM2MxYzYzOWM3NmI2MmFlM2MxNzU2ZmMyM2NjMTEy
14
+ OTEzNzAwZDVlNzY1MjZmZjczMjRlZDRmNmI5M2NmYjYzY2JmMjE5NDM3YWEw
15
+ NDFjZGMxZjExMDY2ODQ1MTYwNTEwNjM1MTQ3N2ZhZDc0MWJiNGY=
@@ -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.
@@ -0,0 +1,3 @@
1
+ = StripeHelper
2
+
3
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'StripeHelper'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
@@ -0,0 +1,15 @@
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
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= 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,52 @@
1
+ <script type="text/javascript" src="https://js.stripe.com/v2/"></script>
2
+ <script type="text/javascript">
3
+ Stripe.setPublishableKey("<%= @pk %>");
4
+ var stripeResponseHandler = function(status, response) {
5
+ var $form = $('#payment-form');
6
+ if (response.error) {
7
+ $form.find('.payment-errors').text(response.error.message);
8
+ $form.find('button').prop('disabled', false);
9
+ } else {
10
+ var token = response.id;
11
+ $form.append($('<input type="hidden" name="stripeToken" />').val(token));
12
+ $form.get(0).submit();
13
+ }
14
+ };
15
+ jQuery(function($) {
16
+ $('#payment-form').submit(function(e) {
17
+ var $form = $(this);
18
+ $form.find('button').prop('disabled', true);
19
+ Stripe.createToken($form, stripeResponseHandler);
20
+ return false;
21
+ });
22
+ });
23
+ </script>
24
+ <form action="<%= @url %>" method="POST" id="payment-form">
25
+ <%= token_tag nil %>
26
+ <span class="payment-errors"></span>
27
+
28
+ <div class="form-row">
29
+ <label>
30
+ <span>Card Number</span>
31
+ <input type="text" size="20" data-stripe="number"/>
32
+ </label>
33
+ </div>
34
+
35
+ <div class="form-row">
36
+ <label>
37
+ <span>CVC</span>
38
+ <input type="text" size="4" data-stripe="cvc"/>
39
+ </label>
40
+ </div>
41
+
42
+ <div class="form-row">
43
+ <label>
44
+ <span>Expiration (MM/YYYY)</span>
45
+ <input type="text" size="2" data-stripe="exp-month"/>
46
+ </label>
47
+ <span> / </span>
48
+ <input type="text" size="4" data-stripe="exp-year"/>
49
+ </div>
50
+
51
+ <button type="submit">Submit</button>
52
+ </form>
@@ -0,0 +1,12 @@
1
+ <form action=<%= "#{@stem}stripe" %> method="POST">
2
+ <script
3
+ src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button"
4
+ data-key="<%= @pk %>"
5
+ data-amount="<%= @amount %>"
6
+ data-name="<%= @store %>"
7
+ data-description="<%= @desc %>"
8
+ data-image="<%= @image %>">
9
+ </script>
10
+ <%= hidden_field_tag :token, @token %>
11
+ <%= token_tag nil %>
12
+ </form>
@@ -0,0 +1,23 @@
1
+ module StripeHelper
2
+ class StripeCell < ::Cell::Rails
3
+ def show(args)
4
+ @amount = args[:amount]
5
+ @desc = args[:desc]
6
+ @image = args[:image]
7
+ @pk = args[:pk]
8
+ @stem = args[:stem]
9
+ @store = args[:store]
10
+ @token = args[:token]
11
+
12
+ render
13
+ end
14
+
15
+ # capture CC to stripe token
16
+ def capture(args)
17
+ @pk = args[:pk]
18
+ @url = args[:url]
19
+
20
+ render
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,4 @@
1
+ module StripeHelper
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,42 @@
1
+ require 'stripe'
2
+
3
+ module StripeHelper
4
+ class StripeController < ApplicationController
5
+ def handle
6
+ # Determine the amount to charge (or if the token is invalid)
7
+ amount = do_call(:charge_amount, self, params[:token])
8
+
9
+ # If the amount is invalid (ie: token is invalid), then we fail
10
+ if amount == nil || !amount.is_a?(Integer)
11
+ redirect_to do_call(:charge_failure, self, params[:token],
12
+ 'Invalid charge; potential security error.')
13
+ return
14
+ end
15
+
16
+ # Get the credit card details submitted by the form
17
+ token = params[:stripeToken]
18
+
19
+ # Set options for charge
20
+ opts = {
21
+ amount: amount,
22
+ currency: "cad",
23
+ description: params[:desc]
24
+ }
25
+
26
+ ret = StripeHelper.charge_from_token(token, opts)
27
+ if ret
28
+ redirect_to do_call(:charge_success, self, params[:token], token)
29
+ else
30
+ redirect_to do_call(:charge_failure, self, params[:token],
31
+ 'Card declined.')
32
+ end
33
+ end
34
+
35
+ private
36
+ def do_call(key, *args)
37
+ prok = StripeHelper.config.send(key)
38
+ raise "StripeHelper: missing callback for #{key}" if !prok
39
+ prok.call(*args)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,4 @@
1
+ module StripeHelper
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>StripeHelper</title>
5
+ <%= stylesheet_link_tag "stripe_helper/application", :media => "all" %>
6
+ <%= javascript_include_tag "stripe_helper/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,3 @@
1
+ StripeHelper::Engine.routes.draw do
2
+ match '/stripe' => 'stripe#handle', via: :post
3
+ end
@@ -0,0 +1,38 @@
1
+ require "stripe_helper/engine"
2
+ require 'stripe_helper/configuration'
3
+ require 'cells'
4
+ require 'stripe'
5
+
6
+ module StripeHelper
7
+ def self.config
8
+ @@config ||= Configuration.new
9
+ end
10
+
11
+ def self.configure
12
+ yield(self.config)
13
+ end
14
+
15
+ def self.charge_from_token(token, opts = {})
16
+ opts[:card] = token
17
+ # Create the charge on Stripe's servers; this will charge the user's card
18
+ begin
19
+ return ::Stripe::Charge.create(opts)
20
+ rescue ::Stripe::CardError => e
21
+ return nil
22
+ end
23
+ end
24
+
25
+ def self.customer_from_token(token, opts = {})
26
+ opts[:card] = token
27
+ ::Stripe::Customer.create(opts)
28
+ end
29
+
30
+ def self.charge_from_customer(customer_id, opts = {})
31
+ begin
32
+ opts[:customer] = customer_id
33
+ return ::Stripe::Charge.create(opts)
34
+ rescue ::Stripe::CardError => e
35
+ return nil
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,15 @@
1
+ module StripeHelper
2
+ class Configuration
3
+ def settings
4
+ @@settings ||= {}
5
+ end
6
+
7
+ def method_missing(name, *args, &block)
8
+ if name.to_s.ends_with? '='
9
+ settings.send(:[]=, name.to_s.chomp('=').to_sym, *args)
10
+ else
11
+ settings.send(:[], name.to_sym, &block)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module StripeHelper
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace StripeHelper
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module StripeHelper
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :stripe_helper do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stripe_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Colibri Software
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.13
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.13
27
+ - !ruby/object:Gem::Dependency
28
+ name: cells
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: stripe
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: capybara
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: poltergeist
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: puffing-billy
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Provides a Cell to render a 'Pay with Stripe' button and handle the response
140
+ from Stripe.
141
+ email: info@colibri-software.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - MIT-LICENSE
147
+ - README.rdoc
148
+ - Rakefile
149
+ - app/assets/javascripts/stripe_helper/application.js
150
+ - app/assets/stylesheets/stripe_helper/application.css
151
+ - app/cells/stripe_helper/stripe/capture.html.erb
152
+ - app/cells/stripe_helper/stripe/show.html.erb
153
+ - app/cells/stripe_helper/stripe_cell.rb
154
+ - app/controllers/stripe_helper/application_controller.rb
155
+ - app/controllers/stripe_helper/stripe_controller.rb
156
+ - app/helpers/stripe_helper/application_helper.rb
157
+ - app/views/layouts/stripe_helper/application.html.erb
158
+ - config/routes.rb
159
+ - lib/stripe_helper.rb
160
+ - lib/stripe_helper/configuration.rb
161
+ - lib/stripe_helper/engine.rb
162
+ - lib/stripe_helper/version.rb
163
+ - lib/tasks/stripe_helper_tasks.rake
164
+ homepage: http://www.colibri-software.com
165
+ licenses: []
166
+ metadata: {}
167
+ post_install_message:
168
+ rdoc_options: []
169
+ require_paths:
170
+ - lib
171
+ required_ruby_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ! '>='
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ required_rubygems_version: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ! '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ requirements: []
182
+ rubyforge_project:
183
+ rubygems_version: 2.2.2
184
+ signing_key:
185
+ specification_version: 4
186
+ summary: Stripe helper to provide Stripe button & controller logic.
187
+ test_files: []