volt-braintree 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +80 -0
- data/Rakefile +1 -0
- data/app/braintree/config/dependencies.rb +1 -0
- data/app/braintree/config/initializers/boot.rb +10 -0
- data/app/braintree/config/routes.rb +1 -0
- data/app/braintree/controllers/main_controller.rb +35 -0
- data/app/braintree/tasks/client_token_task.rb +26 -0
- data/app/braintree/views/main/index.html +1 -0
- data/lib/volt/braintree.rb +18 -0
- data/lib/volt/braintree/version.rb +5 -0
- data/spec/app/braintree/tasks/foobar_task_spec.rb +5 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/volt/braintree_spec.rb +11 -0
- data/volt-braintree.gemspec +26 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b4f66caa01039c25cac5b5eb0d4c6ebaa5ae09c7
|
4
|
+
data.tar.gz: 48cfe6118061b6352ff72ba1e2134472e87f81d6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ce8a142992f77801f0e999067cfe069eec867ae00762301aa7fec1784f8e91ae569003962c7c042401e182b07947b585499e98d1c677db15996ac5e43bb17b33
|
7
|
+
data.tar.gz: c4c2d2ee4a97d6125e4a4a27b1d33cf41d3d563ccb147c51256edfa7fd7638b27cc4a868e3bae11ca5f079570ee67f1ad2137e5ae70b2b98083b22130c9047b0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Cristiano Betta
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Volt::Braintree
|
2
|
+
|
3
|
+
A wrapper around the [Braintree gem](https://github.com/braintree/braintree_ruby) that provides you with a way to load the [Braintree v.zero Drop-in](https://github.com/braintree/braintree_ruby) with 1 line of code.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'volt-braintree'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install volt-braintree
|
18
|
+
|
19
|
+
And then add the dependency to your `dependecies.rb`
|
20
|
+
|
21
|
+
$ component 'braintree'
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
### Configuration
|
26
|
+
|
27
|
+
Add the following initializer (e.g. `app/main/initializers/server/braintree.rb`):
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
Braintree::Configuration.environment = :sandbox
|
31
|
+
Braintree::Configuration.merchant_id = 'your_merchant_id'
|
32
|
+
Braintree::Configuration.public_key = 'your_public_key'
|
33
|
+
Braintree::Configuration.private_key = 'your_private_key'
|
34
|
+
```
|
35
|
+
|
36
|
+
### Integration
|
37
|
+
|
38
|
+
To add the Braintree form to your site simply add the component to your page:
|
39
|
+
|
40
|
+
```html
|
41
|
+
<form e-submit='process_payment'>
|
42
|
+
<:braintree>
|
43
|
+
</form>
|
44
|
+
```
|
45
|
+
|
46
|
+
You can specify additional options to generate the [ClientToken](https://developers.braintreepayments.com/javascript+ruby/reference/request/client-token/generate) by passing in arguments prefixed with the `server__` name. For example to pass the `client_id` option when generating the **ClientToken** you specify the following:
|
47
|
+
|
48
|
+
```html
|
49
|
+
<:braintree server__customer_id='123'>
|
50
|
+
```
|
51
|
+
|
52
|
+
You can also pass in options to the loading of the [Javascript library](https://developers.braintreepayments.com/javascript+ruby/guides/drop-in) by prefixing it with `client__` as follows:
|
53
|
+
|
54
|
+
```html
|
55
|
+
<:braintree client__form='alternative_form_name'>
|
56
|
+
````
|
57
|
+
|
58
|
+
### Processing payment
|
59
|
+
|
60
|
+
To process the payment you should add an `e-submit` listener to the surrounding form. This form will be called twice, once before the card has been tokenised and once after. If you need the payment nonce generated by Braintree simply check for it's existence.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
...
|
64
|
+
def process_payment
|
65
|
+
if page._payment_method_nonce
|
66
|
+
# so something with page._payment_method_nonce
|
67
|
+
else
|
68
|
+
return false #stop the form from submitting
|
69
|
+
end
|
70
|
+
end
|
71
|
+
...
|
72
|
+
```
|
73
|
+
|
74
|
+
## Contributing
|
75
|
+
|
76
|
+
1. Fork it ( http://github.com/cbetta/volt-braintree/fork )
|
77
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
78
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
79
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
80
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1 @@
|
|
1
|
+
javascript_file 'https://js.braintreegateway.com/v2/braintree.js'
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Place any code you want to run when the component is included on the client
|
2
|
+
# or server.
|
3
|
+
|
4
|
+
# To include code only on the client use:
|
5
|
+
# if RUBY_PLATFORM == 'opal'
|
6
|
+
#
|
7
|
+
# To include code only on the server, use:
|
8
|
+
# unless RUBY_PLATFORM == 'opal'
|
9
|
+
# ^^ this will not send compile in code in the conditional to the client.
|
10
|
+
# ^^ this include code required in the conditional.require 'braintree'
|
@@ -0,0 +1 @@
|
|
1
|
+
# Component routes
|
@@ -0,0 +1,35 @@
|
|
1
|
+
if RUBY_PLATFORM == 'opal'
|
2
|
+
require 'native'
|
3
|
+
end
|
4
|
+
|
5
|
+
module Braintree
|
6
|
+
|
7
|
+
class MainController < Volt::ModelController
|
8
|
+
def index
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def index_ready
|
14
|
+
options = parse(attrs.locals)
|
15
|
+
ClientTokenTask.generate(attrs.locals).then do |client_token|
|
16
|
+
handler = proc do |event, nonce|
|
17
|
+
page._payment_method_nonce = nonce
|
18
|
+
`$('#volt-braintree-form').parents('form').submit()`
|
19
|
+
end
|
20
|
+
%x{
|
21
|
+
options["paymentMethodNonceReceived"] = handler;
|
22
|
+
braintree.setup(client_token, "dropin", options);
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def parse options
|
28
|
+
result = { container: "volt-braintree-form" }
|
29
|
+
options.keys.each do |key|
|
30
|
+
result[key.split("__").last.to_sym] = options[key] if key.start_with?("client__")
|
31
|
+
end
|
32
|
+
result.to_n
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class ClientTokenTask < Volt::Task
|
2
|
+
def generate *options
|
3
|
+
Braintree::ClientToken.generate(parse(*options))
|
4
|
+
end
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def parse options={}
|
9
|
+
result = {}
|
10
|
+
options.keys.each do |key|
|
11
|
+
result[key.split("__").last.to_sym] = options[key] if key.start_with?("server__")
|
12
|
+
end
|
13
|
+
result
|
14
|
+
end
|
15
|
+
|
16
|
+
def symbolize_keys! hash={}
|
17
|
+
transform_keys!(hash){ |key| key.to_sym rescue key }
|
18
|
+
end
|
19
|
+
|
20
|
+
def transform_keys!(hash)
|
21
|
+
hash.keys.each do |key|
|
22
|
+
hash[yield(key)] = hash.delete(key)
|
23
|
+
end
|
24
|
+
hash
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<div id="volt-braintree-form"></div>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# If you need to require in code in the gem's app folder, keep in mind that
|
2
|
+
# the app is not on the load path when the gem is required. Use
|
3
|
+
# app/{gemname}/config/initializers/boot.rb to require in client or server
|
4
|
+
# code.
|
5
|
+
#
|
6
|
+
# Also, in volt apps, you typically use the lib folder in the
|
7
|
+
# app/{componentname} folder instead of this lib folder. This lib folder is
|
8
|
+
# for setting up gem code when Bundler.require is called. (or the gem is
|
9
|
+
# required.)
|
10
|
+
#
|
11
|
+
# If you need to configure volt in some way, you can add a Volt.configure block
|
12
|
+
# in this file.
|
13
|
+
require 'braintree'
|
14
|
+
|
15
|
+
module Volt
|
16
|
+
module Braintree
|
17
|
+
end
|
18
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Volt sets up rspec and capybara for testing.
|
2
|
+
require 'volt/spec/setup'
|
3
|
+
Volt.spec_setup
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.run_all_when_everything_filtered = true
|
7
|
+
config.filter_run :focus
|
8
|
+
|
9
|
+
# Run specs in random order to surface order dependencies. If you find an
|
10
|
+
# order dependency and want to debug it, you can fix the order by providing
|
11
|
+
# the seed, which is printed after each run.
|
12
|
+
# --seed 1234
|
13
|
+
config.order = 'random'
|
14
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'volt/braintree/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "volt-braintree"
|
8
|
+
spec.version = Volt::Braintree::VERSION
|
9
|
+
spec.authors = ["Cristiano Betta"]
|
10
|
+
spec.email = ["cbetta@gmail.com"]
|
11
|
+
spec.summary = "A Volt component for the Braintree v.zero integration"
|
12
|
+
spec.description = "A wrapper around the Braintree gem that provides you with a way to load the Braintree v.zero dropin with 1 line of code."
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "volt", "~> 0.9.0"
|
22
|
+
spec.add_development_dependency 'rspec', '~> 3.2.0'
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
|
25
|
+
spec.add_dependency "braintree"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: volt-braintree
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cristiano Betta
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: volt
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.9.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.2.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
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: braintree
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: A wrapper around the Braintree gem that provides you with a way to load
|
70
|
+
the Braintree v.zero dropin with 1 line of code.
|
71
|
+
email:
|
72
|
+
- cbetta@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- CODE_OF_CONDUCT.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- app/braintree/config/dependencies.rb
|
85
|
+
- app/braintree/config/initializers/boot.rb
|
86
|
+
- app/braintree/config/routes.rb
|
87
|
+
- app/braintree/controllers/main_controller.rb
|
88
|
+
- app/braintree/tasks/client_token_task.rb
|
89
|
+
- app/braintree/views/main/index.html
|
90
|
+
- lib/volt/braintree.rb
|
91
|
+
- lib/volt/braintree/version.rb
|
92
|
+
- spec/app/braintree/tasks/foobar_task_spec.rb
|
93
|
+
- spec/spec_helper.rb
|
94
|
+
- spec/volt/braintree_spec.rb
|
95
|
+
- volt-braintree.gemspec
|
96
|
+
homepage: ''
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.4.5
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: A Volt component for the Braintree v.zero integration
|
120
|
+
test_files:
|
121
|
+
- spec/app/braintree/tasks/foobar_task_spec.rb
|
122
|
+
- spec/spec_helper.rb
|
123
|
+
- spec/volt/braintree_spec.rb
|
124
|
+
has_rdoc:
|