stripe-opal 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4fa489de910ffeab3aa1017c12b2dfd304e37527
4
- data.tar.gz: ff4047b26e2faf0526b025740d458dc3b51009bf
3
+ metadata.gz: 21377ea49384cbeb9dc069729fabf4acb4a6b931
4
+ data.tar.gz: 4e11f6565b75637e7bf4a5b2c6733433260261ed
5
5
  SHA512:
6
- metadata.gz: 6edc287e605c2e8a74d492a26079f099dc4de8697f39dc3a340405f443ca235473431618dcab875f2ac7c6ad49dd6920839f3e2c0563fa6333f17b6a53de1c13
7
- data.tar.gz: 5827afe5c3be486a302ade449bdf7aa96c953f137d81d496185a55de98bc76b8d5a633f8e5eb68fae758bdab14b572c608945880f11b0be2e415b51700f3b13d
6
+ metadata.gz: 08054a239f22ebd182a36cecab6236852abd6c52d01bfcc9e67a85ee6543f774d2295efa4f516e28846ce25ab935b2f8ad6a76266a6ac0b2c1e5e0ab3bcef356
7
+ data.tar.gz: efa0e43dfa6aedcfe7719825ad4d2d3dac05f2acab88ebd175558cd1f81a9160e11a7e762c3abb68956b5d842d2df76ba1e2cd36f04517c9b2aba7d6be21a235
@@ -0,0 +1,38 @@
1
+ if RUBY_PLATFORM == 'opal'
2
+ require 'native'
3
+
4
+ module StripeOpal
5
+
6
+ class Card
7
+ def self.get_token(query_selector)
8
+ new(query_selector).run.promise
9
+ end
10
+
11
+ attr_reader :query_selector, :promise, :callback
12
+
13
+ def initialize(query_selector)
14
+ @query_selector = query_selector
15
+ @promise = Promise.new
16
+ @callback = lambda { |a, b| resolve_or_reject(a, b) }
17
+ end
18
+
19
+ def run
20
+ `Stripe.card.createToken(document.querySelector(#{query_selector}), #{self.callback});`
21
+ self
22
+ end
23
+
24
+ def resolve_or_reject(status, response)
25
+ status, response = Native(status), Native(response)
26
+ if response[:error]
27
+ promise.reject response, status
28
+ else
29
+ promise.resolve(response, status)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ else
35
+ module StripeOpal
36
+ VERSION = '0.0.5'
37
+ end
38
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe-opal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rick Carlino
@@ -58,16 +58,7 @@ executables: []
58
58
  extensions: []
59
59
  extra_rdoc_files: []
60
60
  files:
61
- - ".gitignore"
62
- - Gemfile
63
- - LICENSE
64
- - README.md
65
- - Rakefile
66
- - config.ru
67
- - spec/index.html.erb
68
- - spec/spec_helper.rb
69
- - spec/stripe_opal_card_spec.rb
70
- - stripe-opal.gemspec
61
+ - lib/stripe-opal.rb
71
62
  homepage: https://github.com/DataMelon/stripe-opal
72
63
  licenses:
73
64
  - MIT
data/.gitignore DELETED
@@ -1,8 +0,0 @@
1
- .DS_Store
2
- *.gem
3
- Gemfile.lock
4
- build
5
- gh-pages
6
- /.bundle
7
- .yardoc
8
- /doc
data/Gemfile DELETED
@@ -1,2 +0,0 @@
1
- source 'https://rubygems.org'
2
- gemspec
data/LICENSE DELETED
@@ -1,19 +0,0 @@
1
- Copyright (C) 2015 by Rick Carlino
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to deal
5
- in the Software without restriction, including without limitation the rights
6
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- copies of the Software, and to permit persons to whom the Software is
8
- furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in
11
- all copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
data/README.md DELETED
@@ -1,120 +0,0 @@
1
- # Unofficial Stripe.JS wrapper for Opal
2
-
3
- `stripe-opal` provides credit card payment capabilities to opal by wrapping Stripe.js and providing a nice ruby syntax for dealing with card payments.
4
-
5
- ## Note
6
-
7
- This is an unofficial Gem and I don't work for Stripe. The gem is maintained, but not officially supported or endorsed by Stripe.
8
-
9
- ## Getting Started
10
-
11
- ### Usage
12
-
13
- Add this to `app/main/config/dependencies.rb` for your **Volt Project**:
14
-
15
- ```ruby
16
- javascript_file "https://js.stripe.com/v2/"
17
- ```
18
-
19
- OR, if you are writing a **static app that does not use Volt, but uses Opal**:
20
-
21
- ```html
22
- <script type="text/javascript" src="https://js.stripe.com/v2/"></script>
23
- ```
24
- THEN
25
-
26
- Make this HTML form...
27
-
28
- ```html
29
- <form action="" method="POST" id="payment-form">
30
- <span class="payment-errors"></span>
31
-
32
- <div class="form-row">
33
- <label>
34
- <span>Card Number</span>
35
- <input type="text" size="20" data-stripe="number"/>
36
- </label>
37
- </div>
38
-
39
- <div class="form-row">
40
- <label>
41
- <span>CVC</span>
42
- <input type="text" size="4" data-stripe="cvc"/>
43
- </label>
44
- </div>
45
-
46
- <div class="form-row">
47
- <label>
48
- <span>Expiration (MM/YYYY)</span>
49
- <input type="text" size="2" data-stripe="exp-month"/>
50
- </label>
51
- <span> / </span>
52
- <input type="text" size="4" data-stripe="exp-year"/>
53
- </div>
54
-
55
- <button type="submit">Submit Payment</button>
56
- </form>
57
- ```
58
-
59
- And run payments like this:
60
-
61
- ```ruby
62
-
63
- StripeOpal::Card
64
- .get_token('#payment-form') # Notice the ID on the form above?
65
- .then { |token| "Pass the `token.id` to a Volt::Task or AJAX call" }
66
- .fail { |error| "Tell the user they put bad info in." }
67
-
68
- ```
69
-
70
- If you are developing a [Volt Framework](http://www.voltframework.com) app, it's best to put the code above in a controller method
71
-
72
- ```
73
- def pay_from_controller
74
- StripeOpal::Card
75
- .get_token('#payment-form') # Notice the ID on the form above?
76
- .then { |token| "Pass the `token.id` to a Volt::Task or AJAX call" }
77
- .fail { |error| "Tell the user they put bad info in." }
78
- end
79
- ```
80
-
81
- and add `e-submit="pay_from_controller"` to the `<form>` tag.
82
-
83
- ## Installation
84
-
85
- Install stripe-opal from RubyGems:
86
-
87
- ```
88
- $ gem install stripe-opal
89
- ```
90
-
91
- Or include it in your Gemfile for Bundler:
92
-
93
- ```ruby
94
- gem 'stripe-opal'
95
- ```
96
-
97
- ## License
98
-
99
- (The MIT License)
100
-
101
- Copyright (C) 2015 by Rick Carlino
102
-
103
- Permission is hereby granted, free of charge, to any person obtaining a copy
104
- of this software and associated documentation files (the "Software"), to deal
105
- in the Software without restriction, including without limitation the rights
106
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
107
- copies of the Software, and to permit persons to whom the Software is
108
- furnished to do so, subject to the following conditions:
109
-
110
- The above copyright notice and this permission notice shall be included in
111
- all copies or substantial portions of the Software.
112
-
113
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
114
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
115
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
116
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
117
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
118
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
119
- THE SOFTWARE.
120
-
data/Rakefile DELETED
File without changes
data/config.ru DELETED
@@ -1,13 +0,0 @@
1
- require 'bundler'
2
- Bundler.require
3
-
4
- require 'opal-rspec'
5
- Opal.append_path File.expand_path('../spec', __FILE__)
6
-
7
- run Opal::Server.new { |s|
8
- s.main = 'opal/rspec/sprockets_runner'
9
- s.append_path 'spec'
10
- s.debug = false
11
- s.index_path = 'spec/index.html.erb'
12
- }
13
-
@@ -1,8 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- </head>
5
- <body>
6
- <%= javascript_include_tag @server.main %>
7
- </body>
8
- </html>
@@ -1,9 +0,0 @@
1
- require 'opal-rspec'
2
- require 'stripe-opal'
3
-
4
- module SomeHelpers
5
- end
6
-
7
- RSpec.configure do |config|
8
- config.include SomeHelpers
9
- end
@@ -1,9 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe StripOpal::Card do
4
- let(:four) { 4 }
5
-
6
- describe ".placeholder" do
7
- it 'equals four' { expect(2 + 2).to eq(four) }
8
- end
9
- end
@@ -1,20 +0,0 @@
1
- $:.push File.expand_path('../lib', __FILE__)
2
-
3
- require 'stripe-opal'
4
-
5
- Gem::Specification.new do |s|
6
- s.authors = ['Rick Carlino']
7
- s.description = 'Wrapper around stripe.js to make Opal payments easier'
8
- s.email = 'rick@datamelon.io'
9
- s.files = `git ls-files`.split("\n")
10
- s.homepage = 'https://github.com/DataMelon/stripe-opal'
11
- s.license = 'MIT'
12
- s.name = 'stripe-opal'
13
- s.require_paths = ['lib']
14
- s.summary = 'Opal access to Stripe.js'
15
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
- s.version = StripeOpal::VERSION
17
- s.add_development_dependency 'opal-rspec', '~> 0.4.0'
18
- s.add_development_dependency 'rake'
19
- s.add_runtime_dependency 'opal', '>= 0.8.0'
20
- end