dbalatero-fpswax 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README.rdoc +9 -0
- data/Rakefile +48 -0
- data/VERSION.yml +4 -0
- data/lib/fpswax/error.rb +9 -0
- data/lib/fpswax/ipn_request.rb +24 -0
- data/lib/fpswax/mixins/hmac_signature.rb +16 -0
- data/lib/fpswax/response.rb +23 -0
- data/lib/fpswax/session.rb +50 -0
- data/lib/fpswax.rb +14 -0
- data/spec/fixtures/raw/errors.xml +2 -0
- data/spec/fixtures/raw/request_id.xml +9 -0
- data/spec/fpswax/error_spec.rb +25 -0
- data/spec/fpswax/ipn_request_spec.rb +42 -0
- data/spec/fpswax/response_spec.rb +35 -0
- data/spec/fpswax/session_spec.rb +76 -0
- data/spec/spec_helper.rb +17 -0
- metadata +74 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 David Balatero <david@bitwax.cd>
|
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.
|
data/README.rdoc
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
= fpswax
|
2
|
+
|
3
|
+
This allows for integration with Amazon FPS in the common-case.
|
4
|
+
This is not a full implementation yet. Remit has *an* implementation,
|
5
|
+
but it is highly out of date, and a bit too clever for my taste.
|
6
|
+
|
7
|
+
== Copyright
|
8
|
+
|
9
|
+
Copyright (c) 2009 David Balatero. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "fpswax"
|
8
|
+
gem.summary = %Q{A library for interfacing with Amazon FPS, without any "cleverness".}
|
9
|
+
gem.email = "david@bitwax.cd"
|
10
|
+
gem.homepage = "http://github.com/dbalatero/fpswax"
|
11
|
+
gem.authors = ["David Balatero"]
|
12
|
+
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
end
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'spec/rake/spectask'
|
20
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
21
|
+
spec.libs << 'lib' << 'spec'
|
22
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
23
|
+
end
|
24
|
+
|
25
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
26
|
+
spec.libs << 'lib' << 'spec'
|
27
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
28
|
+
spec.rcov = true
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
task :default => :spec
|
33
|
+
|
34
|
+
require 'rake/rdoctask'
|
35
|
+
Rake::RDocTask.new do |rdoc|
|
36
|
+
if File.exist?('VERSION.yml')
|
37
|
+
config = YAML.load(File.read('VERSION.yml'))
|
38
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
39
|
+
else
|
40
|
+
version = ""
|
41
|
+
end
|
42
|
+
|
43
|
+
rdoc.rdoc_dir = 'rdoc'
|
44
|
+
rdoc.title = "fpswax #{version}"
|
45
|
+
rdoc.rdoc_files.include('README*')
|
46
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
47
|
+
end
|
48
|
+
|
data/VERSION.yml
ADDED
data/lib/fpswax/error.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Fpswax
|
2
|
+
class IpnRequest
|
3
|
+
include Mixins::HmacSignature
|
4
|
+
|
5
|
+
def initialize(params, secret_key)
|
6
|
+
@signature = params.delete('signature')
|
7
|
+
strip_keys_from!(params, 'action', 'controller')
|
8
|
+
@params = params
|
9
|
+
@secret_key = secret_key
|
10
|
+
end
|
11
|
+
|
12
|
+
def valid?
|
13
|
+
return false if !@signature
|
14
|
+
generate_signature_for(@params, @secret_key) == @signature
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def strip_keys_from!(hash, *keys)
|
19
|
+
keys.each do |key|
|
20
|
+
hash.delete(key)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'openssl/digest'
|
3
|
+
|
4
|
+
module Fpswax
|
5
|
+
module Mixins
|
6
|
+
module HmacSignature
|
7
|
+
private
|
8
|
+
def generate_signature_for(params, secret_key)
|
9
|
+
query = params.sort_by { |k,v| k.downcase }
|
10
|
+
digest = OpenSSL::Digest::Digest.new('sha1')
|
11
|
+
hmac = OpenSSL::HMAC.digest(digest, secret_key, query.to_s)
|
12
|
+
encoded = Base64.encode64(hmac).chomp
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Fpswax
|
2
|
+
class Response
|
3
|
+
attr_reader :request_id, :errors
|
4
|
+
def initialize(xml)
|
5
|
+
# parse any errors
|
6
|
+
@errors = xml.css('Response Errors Error').map do |error|
|
7
|
+
code = error.css('Code')[0].content
|
8
|
+
message = error.css('Message')[0].content
|
9
|
+
Fpswax::Error.new(code, message)
|
10
|
+
end
|
11
|
+
|
12
|
+
if @errors.empty?
|
13
|
+
@request_id = xml.css('RequestId')[0].content
|
14
|
+
else
|
15
|
+
@request_id = xml.css('RequestID')[0].content
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def valid?
|
20
|
+
@errors.empty?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Fpswax
|
2
|
+
class Session
|
3
|
+
class ParameterRequired < ArgumentError; end
|
4
|
+
|
5
|
+
API_VERSION = '2008-09-17'
|
6
|
+
CBUI_API_VERSION = '2009-01-09'
|
7
|
+
|
8
|
+
include Mixins::HmacSignature
|
9
|
+
|
10
|
+
def initialize(access_key, secret_key, sandbox = true)
|
11
|
+
@access_key = access_key
|
12
|
+
@secret_key = secret_key
|
13
|
+
@sandbox = sandbox
|
14
|
+
end
|
15
|
+
|
16
|
+
def in_sandbox?
|
17
|
+
@sandbox
|
18
|
+
end
|
19
|
+
|
20
|
+
def api_version
|
21
|
+
API_VERSION
|
22
|
+
end
|
23
|
+
|
24
|
+
def cbui_api_version
|
25
|
+
CBUI_API_VERSION
|
26
|
+
end
|
27
|
+
|
28
|
+
# operations
|
29
|
+
# See: http://docs.amazonwebservices.com/AmazonFPS/2008-09-17/FPSAdvancedGuide/Pay.html
|
30
|
+
def pay(params)
|
31
|
+
validate_required?(params,
|
32
|
+
:CallerReference,
|
33
|
+
:SenderTokenId,
|
34
|
+
:TransactionAmount)
|
35
|
+
|
36
|
+
#get_response('Pay', PayResponse, params)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def validate_required?(hash, *args)
|
41
|
+
args.each do |arg|
|
42
|
+
raise(ParameterRequired, "This method requires #{arg} to be passed in!") if !hash[arg]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def make_request(params)
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/fpswax.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
|
2
|
+
|
3
|
+
require 'openssl'
|
4
|
+
require 'nokogiri'
|
5
|
+
|
6
|
+
require 'fpswax/mixins/hmac_signature'
|
7
|
+
|
8
|
+
require 'fpswax/error'
|
9
|
+
require 'fpswax/ipn_request'
|
10
|
+
require 'fpswax/response'
|
11
|
+
require 'fpswax/session'
|
12
|
+
|
13
|
+
module Fpswax
|
14
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<PayResponse xmlns="http://fps.amazonaws.com/doc/2008-09-17/">
|
2
|
+
<PayResult>
|
3
|
+
<TransactionId>13N8UPFET32I4I7FCF9T4ZKFETETINTK56Q</TransactionId>
|
4
|
+
<TransactionStatus>Pending</TransactionStatus>
|
5
|
+
</PayResult>
|
6
|
+
<ResponseMetadata>
|
7
|
+
<RequestId>b415f09d-5924-4315-b31a-21c977c85c39:0</RequestId>
|
8
|
+
</ResponseMetadata>
|
9
|
+
</PayResponse>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Fpswax::Error do
|
4
|
+
describe "initialize" do
|
5
|
+
it "should require a code and a message" do
|
6
|
+
lambda {
|
7
|
+
Fpswax::Error.new('code', 'message')
|
8
|
+
}.should_not raise_error(ArgumentError)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "code" do
|
13
|
+
it "should be whatever is passed into the constructor" do
|
14
|
+
error = Fpswax::Error.new('mycode', 'msg')
|
15
|
+
error.code.should == 'mycode'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "message" do
|
20
|
+
it "should be whatever is passed into the constructor" do
|
21
|
+
error = Fpswax::Error.new('mycode', 'msg')
|
22
|
+
error.message.should == 'msg'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Fpswax::IpnRequest do
|
4
|
+
before(:each) do
|
5
|
+
@test_key = 'mykey'
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "initialize" do
|
9
|
+
it "should require a params hash and secret key" do
|
10
|
+
lambda {
|
11
|
+
Fpswax::IpnRequest.new({}, @test_key)
|
12
|
+
}.should_not raise_error
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "valid?" do
|
17
|
+
it "should be false if no signature is provided" do
|
18
|
+
req = Fpswax::IpnRequest.new({}, @test_key)
|
19
|
+
req.should_not be_valid
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should be false if the signature doesn't match up" do
|
23
|
+
req = Fpswax::IpnRequest.new({'signature' => 'bad', 'param1' => 'ok'}, @test_key)
|
24
|
+
req.should_not be_valid
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should be true if the signature does match up" do
|
28
|
+
good_params = {
|
29
|
+
"tokenID" => "N1CHGCG13NNB4JMVJN1Q1JXIKBQDO4DQ595NRSCTILAU47P7GA7JVQMMJNXRUJFM",
|
30
|
+
"callerReference" => "44441234567fdsa44",
|
31
|
+
"action" => "amazon_return",
|
32
|
+
"signature" => "uoOmSftU4gnUMK6Q1ylyGnr5hEw=",
|
33
|
+
"controller" => "checkout",
|
34
|
+
"expiry" => "10/2014",
|
35
|
+
"status" => "SC"
|
36
|
+
}
|
37
|
+
|
38
|
+
req = Fpswax::IpnRequest.new(good_params, @test_key)
|
39
|
+
req.should be_valid
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Fpswax::Response do
|
4
|
+
describe "request_id" do
|
5
|
+
it "should successfully be parsed from a response" do
|
6
|
+
xml = fixture_raw_xml('raw/request_id.xml')
|
7
|
+
response = Fpswax::Response.new(xml)
|
8
|
+
response.request_id.should == 'b415f09d-5924-4315-b31a-21c977c85c39:0'
|
9
|
+
response.should be_valid
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "errors" do
|
14
|
+
it "should return any errors that were present in the XML response" do
|
15
|
+
xml = fixture_raw_xml('raw/errors.xml')
|
16
|
+
response = Fpswax::Response.new(xml)
|
17
|
+
|
18
|
+
response.errors.should have_at_least(1).thing
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "valid" do
|
23
|
+
it "should be true if there are no errors" do
|
24
|
+
xml = fixture_raw_xml('raw/request_id.xml')
|
25
|
+
response = Fpswax::Response.new(xml)
|
26
|
+
response.should be_valid
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should be false if there are errors" do
|
30
|
+
xml = fixture_raw_xml("raw/errors.xml")
|
31
|
+
response = Fpswax::Response.new(xml)
|
32
|
+
response.should_not be_valid
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Fpswax::Session do
|
4
|
+
describe "initialize" do
|
5
|
+
it "should take an access key, private key" do
|
6
|
+
lambda {
|
7
|
+
Fpswax::Session.new('a', 'b')
|
8
|
+
}.should_not raise_error
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should also be allowed to operate in sandbox mode" do
|
12
|
+
lambda {
|
13
|
+
Fpswax::Session.new('a', 'b', true)
|
14
|
+
}.should_not raise_error
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "in_sandbox?" do
|
19
|
+
it "should by default be in sandbox mode" do
|
20
|
+
session = Fpswax::Session.new('a', 'b')
|
21
|
+
session.should be_in_sandbox
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should not be in sandbox if sandbox is passed in as false" do
|
25
|
+
session = Fpswax::Session.new('a', 'b', false)
|
26
|
+
session.should_not be_in_sandbox
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "api_version" do
|
31
|
+
it "should be 2008-09-17" do
|
32
|
+
session = Fpswax::Session.new('a', 'b', false)
|
33
|
+
session.api_version.should == '2008-09-17'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "cbui_api_version" do
|
38
|
+
session = Fpswax::Session.new('a', 'b', false)
|
39
|
+
session.cbui_api_version.should == '2009-01-09'
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "pay" do
|
43
|
+
before(:each) do
|
44
|
+
@session = Fpswax::Session.new('a', 'b', true)
|
45
|
+
@valid_params = {
|
46
|
+
:CallerReference => 'a',
|
47
|
+
:SenderTokenId => 'b',
|
48
|
+
:TransactionAmount => 'c'
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should return a PayResponse" do
|
53
|
+
pending
|
54
|
+
response = @session.pay(@valid_params)
|
55
|
+
response.should be_an_instance_of(PayResponse)
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "should validate parameters" do
|
59
|
+
it "and raise an error if no valid params are passed" do
|
60
|
+
@valid_params.keys.each do |key|
|
61
|
+
bad_params = @valid_params.dup
|
62
|
+
bad_params.delete(key)
|
63
|
+
lambda {
|
64
|
+
@session.pay(bad_params)
|
65
|
+
}.should raise_error(Fpswax::Session::ParameterRequired)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it "and not raise an error if valid params are passed" do
|
70
|
+
lambda {
|
71
|
+
@session.pay(@valid_params)
|
72
|
+
}.should_not raise_error(Fpswax::Session::ParameterRequired)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec'
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
|
+
require 'fpswax'
|
6
|
+
|
7
|
+
Spec::Runner.configure do |config|
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
def fixture_path(path)
|
12
|
+
File.join(File.dirname(__FILE__), "fixtures", path)
|
13
|
+
end
|
14
|
+
|
15
|
+
def fixture_raw_xml(path)
|
16
|
+
Nokogiri::XML(File.read(fixture_path(path)))
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dbalatero-fpswax
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Balatero
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-23 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: david@bitwax.cd
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- LICENSE
|
27
|
+
- README.rdoc
|
28
|
+
- Rakefile
|
29
|
+
- VERSION.yml
|
30
|
+
- lib/fpswax.rb
|
31
|
+
- lib/fpswax/error.rb
|
32
|
+
- lib/fpswax/ipn_request.rb
|
33
|
+
- lib/fpswax/mixins/hmac_signature.rb
|
34
|
+
- lib/fpswax/response.rb
|
35
|
+
- lib/fpswax/session.rb
|
36
|
+
- spec/fixtures/raw/errors.xml
|
37
|
+
- spec/fixtures/raw/request_id.xml
|
38
|
+
- spec/fpswax/error_spec.rb
|
39
|
+
- spec/fpswax/ipn_request_spec.rb
|
40
|
+
- spec/fpswax/response_spec.rb
|
41
|
+
- spec/fpswax/session_spec.rb
|
42
|
+
- spec/spec_helper.rb
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://github.com/dbalatero/fpswax
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options:
|
47
|
+
- --charset=UTF-8
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.2.0
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: A library for interfacing with Amazon FPS, without any "cleverness".
|
69
|
+
test_files:
|
70
|
+
- spec/fpswax/error_spec.rb
|
71
|
+
- spec/fpswax/ipn_request_spec.rb
|
72
|
+
- spec/fpswax/response_spec.rb
|
73
|
+
- spec/fpswax/session_spec.rb
|
74
|
+
- spec/spec_helper.rb
|