foxycart_helpers 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/.env +1 -0
- data/.env.example +1 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +66 -0
- data/Rakefile +6 -0
- data/bin/console +7 -0
- data/bin/setup +7 -0
- data/foxycart_helpers.gemspec +30 -0
- data/lib/foxycart_helpers.rb +7 -0
- data/lib/foxycart_helpers/configuration.rb +33 -0
- data/lib/foxycart_helpers/datafeed.rb +25 -0
- data/lib/foxycart_helpers/listeners.rb +12 -0
- data/lib/foxycart_helpers/middleware.rb +44 -0
- data/lib/foxycart_helpers/railtie.rb +11 -0
- data/lib/foxycart_helpers/version.rb +3 -0
- metadata +161 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5f5fd26d3b714a0c8da11768cce2851729179ca9
|
4
|
+
data.tar.gz: a91e981343f2cb65ccc354c69fb92a0eb2978899
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4293fbedae46cbfe935cc72f0f27a7f53fa347b40f6e232c0635c092a39780e670a877a118cf9195d59d60f2e1dcc293f037254282be879ae9beeb2180b462ff
|
7
|
+
data.tar.gz: 502e6cd100890745946a4356794d3fb78d700de7699897df63e110d5ec4c6d179c81f44f0e610f8f677348c2dd6b4a0ea7cb198bfc29170aeca649df6c826bea
|
data/.env.example
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
FOXYCART_API_KEY=
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Robert Coleman
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Foxycart Helpers
|
2
|
+
|
3
|
+
Several helpers for working with FoxyCart:
|
4
|
+
|
5
|
+
* Webhook endpoint for Datafeeds - https://wiki.foxycart.com/v/2.0/transaction_xml_datafeed
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'foxycart_helpers'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
`$ bundle`
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
`$ gem install foxycart_helpers`
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
### Transactional Datafeed Webhook
|
26
|
+
|
27
|
+
This helper creates a Rack endpoint to receive a POSTed XML data feed, it:
|
28
|
+
|
29
|
+
* Automatically URL decodes the POST.
|
30
|
+
* Decrypts with your API key `ENV['FOXYCART_API_KEY']`
|
31
|
+
* Parses the XML and presents it as a hash.
|
32
|
+
|
33
|
+
__Rack/Sinatra:__
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
# config.ru
|
37
|
+
require 'foxycart_helpers/middleware'
|
38
|
+
use Foxycart::Middleware
|
39
|
+
```
|
40
|
+
|
41
|
+
__Rails:__ This middleware is registered automatically.
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
FoxycartHelpers.subscribe do |payload|
|
45
|
+
puts payload
|
46
|
+
# Do something with payload
|
47
|
+
# You probably want to fire a background task
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
In Rails this could live at `config/initalizers/foxycart.rb`
|
52
|
+
|
53
|
+
## Development
|
54
|
+
|
55
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
56
|
+
|
57
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rjocoleman/foxycart_helpers.
|
62
|
+
|
63
|
+
|
64
|
+
## License
|
65
|
+
|
66
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'foxycart_helpers/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'foxycart_helpers'
|
8
|
+
spec.version = FoxycartHelpers::VERSION
|
9
|
+
spec.authors = ['Robert Coleman']
|
10
|
+
spec.email = ['github@robert.net.nz']
|
11
|
+
|
12
|
+
spec.summary = %q{Helpers for using FoxyCart in Ruby}
|
13
|
+
spec.description = %q{Helpers for using FoxyCart in Ruby}
|
14
|
+
spec.homepage = 'https://github.com/rjocoleman/foxycart_helpers'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_dependency 'ruby-rc4'
|
23
|
+
spec.add_dependency 'nokogiri'
|
24
|
+
spec.add_dependency 'nori'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rspec'
|
29
|
+
spec.add_dependency 'pry'
|
30
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module FoxycartHelpers
|
2
|
+
|
3
|
+
class << self
|
4
|
+
attr_accessor :configuration
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.configuration
|
8
|
+
@configuration ||= Configuration.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.configure
|
12
|
+
yield(configuration)
|
13
|
+
end
|
14
|
+
|
15
|
+
class Configuration
|
16
|
+
attr_accessor *[
|
17
|
+
:logger,
|
18
|
+
:api_key,
|
19
|
+
:mount_point,
|
20
|
+
:raise_exceptions,
|
21
|
+
]
|
22
|
+
|
23
|
+
alias_method :raise_exceptions?, :raise_exceptions
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@mount_point = '/foxycart_processor'
|
27
|
+
@logger = Logger.new STDOUT
|
28
|
+
@api_key = ENV.fetch 'FOXYCART_API_KEY'
|
29
|
+
@raise_exceptions = true unless ENV['RACK_ENV'] == 'production'
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'foxycart_helpers/configuration'
|
2
|
+
|
3
|
+
require 'rc4'
|
4
|
+
require 'nori'
|
5
|
+
|
6
|
+
module FoxycartHelpers
|
7
|
+
class Datafeed
|
8
|
+
|
9
|
+
def self.from_params(params)
|
10
|
+
decoded = URI.unescape params
|
11
|
+
|
12
|
+
trimmed = decoded.gsub(/FoxyData=/, '')
|
13
|
+
encrypted = URI.unescape trimmed
|
14
|
+
|
15
|
+
rc4 = RC4.new FoxycartHelpers.configuration.api_key
|
16
|
+
decrypted = rc4.decrypt encrypted
|
17
|
+
|
18
|
+
parser = Nori.new
|
19
|
+
payload = parser.parse decrypted
|
20
|
+
|
21
|
+
payload['foxydata']
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'foxycart_helpers/configuration'
|
2
|
+
require 'foxycart_helpers/listeners'
|
3
|
+
require 'foxycart_helpers/datafeed'
|
4
|
+
|
5
|
+
module FoxycartHelpers
|
6
|
+
class Middleware
|
7
|
+
|
8
|
+
def initialize(app=nil)
|
9
|
+
@app = app
|
10
|
+
end
|
11
|
+
|
12
|
+
def config
|
13
|
+
Foxycart.configuration
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
req = Rack::Request.new(env)
|
18
|
+
return @app.call(env) unless req.path_info == config.mount_point
|
19
|
+
return response 405 unless req.post?
|
20
|
+
|
21
|
+
parse_and_respond req.body.read
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def parse_and_respond(params)
|
27
|
+
datafeed = Datafeed.from_params params
|
28
|
+
FoxycartHelpers.propagate datafeed
|
29
|
+
response 200, 'foxy'
|
30
|
+
rescue => e
|
31
|
+
raise e if config.raise_exceptions?
|
32
|
+
response 500
|
33
|
+
end
|
34
|
+
|
35
|
+
def response(status, body='', headers={})
|
36
|
+
[
|
37
|
+
status,
|
38
|
+
{'Content-Type' => 'text/plain'}.merge(headers),
|
39
|
+
[body],
|
40
|
+
]
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: foxycart_helpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert Coleman
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruby-rc4
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
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: nori
|
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: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
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: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Helpers for using FoxyCart in Ruby
|
112
|
+
email:
|
113
|
+
- github@robert.net.nz
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".env"
|
119
|
+
- ".env.example"
|
120
|
+
- ".gitignore"
|
121
|
+
- ".rspec"
|
122
|
+
- ".travis.yml"
|
123
|
+
- Gemfile
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/console
|
128
|
+
- bin/setup
|
129
|
+
- foxycart_helpers.gemspec
|
130
|
+
- lib/foxycart_helpers.rb
|
131
|
+
- lib/foxycart_helpers/configuration.rb
|
132
|
+
- lib/foxycart_helpers/datafeed.rb
|
133
|
+
- lib/foxycart_helpers/listeners.rb
|
134
|
+
- lib/foxycart_helpers/middleware.rb
|
135
|
+
- lib/foxycart_helpers/railtie.rb
|
136
|
+
- lib/foxycart_helpers/version.rb
|
137
|
+
homepage: https://github.com/rjocoleman/foxycart_helpers
|
138
|
+
licenses:
|
139
|
+
- MIT
|
140
|
+
metadata: {}
|
141
|
+
post_install_message:
|
142
|
+
rdoc_options: []
|
143
|
+
require_paths:
|
144
|
+
- lib
|
145
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
requirements: []
|
156
|
+
rubyforge_project:
|
157
|
+
rubygems_version: 2.4.5.1
|
158
|
+
signing_key:
|
159
|
+
specification_version: 4
|
160
|
+
summary: Helpers for using FoxyCart in Ruby
|
161
|
+
test_files: []
|