stripe-opal 0.0.2 → 0.0.3

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: 82672d27b554e179c32f4d3bc60f6fdba87bb4b6
4
- data.tar.gz: 8e9ea103b71c753df9b124487f955312c63aad31
3
+ metadata.gz: fc9d8319a52f6039ea7ce3e2678ac1ed5518662a
4
+ data.tar.gz: 5433fbf8ff21c0a433a4b4ad9f9661e4978cdc12
5
5
  SHA512:
6
- metadata.gz: 2726efca7271e287f0b3d758a7f76d3791d1e7223acb4c82e2535ed0877d0b35f450aced200f65b4afa2d871bdd8bb40fd60c2dbdb246a58796da6b036573dcc
7
- data.tar.gz: 464417e13d2cdde948b83aa6284bb555cabb80864894c51126408eddcba45af744a5e7f1b038efc26a651553d13f2acfe4a14f7877a722d20c1815fe26fa75b5
6
+ metadata.gz: 582044474dbdf2103f3124b2ed35c18557bd080b14b9ebf386129b95a33b76aabb6b4eca85eeec78c421c297e2a09d253f8e676db01b526e64eba95b39a13905
7
+ data.tar.gz: 6a0abe54fb30313a3b1b299527e7989e6c6a1a48fd57d38126cd2f32fa5a5b4140d02d6b30524420288e90227336e43d821ee43a55660ca4c53731a3aca96939
@@ -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.3'
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.2
4
+ version: 0.0.3
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
  metadata: {}
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
- require_relative 'lib/stripe-opal'
2
-
3
- Gem::Specification.new do |s|
4
- s.name = 'stripe-opal'
5
- s.version = StripeOpal::VERSION
6
- s.author = 'Rick Carlino'
7
- s.email = 'rick@datamelon.io'
8
- s.homepage = 'https://github.com/DataMelon/stripe-opal'
9
- s.summary = 'Opal access to Stripe.js'
10
- s.description = 'Wrapper around stripe.js to make Opal payments easier'
11
-
12
- s.files = `git ls-files`.split("\n")
13
- s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
14
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
- s.require_paths = ['lib']
16
-
17
- s.add_runtime_dependency 'opal', '>= 0.8.0'
18
- s.add_development_dependency 'opal-rspec', '~> 0.4.0'
19
- s.add_development_dependency 'rake'
20
- end