dbalatero-fpswax 0.0.2 → 0.0.3

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.
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 0
3
- :patch: 2
3
+ :patch: 3
4
4
  :major: 0
@@ -16,5 +16,7 @@ require 'fpswax/session'
16
16
 
17
17
  require 'fpswax/pay_response'
18
18
 
19
+ require 'fpswax/multi_use_pipeline_request'
20
+
19
21
  module Fpswax
20
22
  end
@@ -0,0 +1,40 @@
1
+ module Fpswax
2
+ class MultiUsePipelineRequest
3
+ include Mixins::HmacSignature
4
+
5
+ CBUI_SANDBOX_URL = 'https://authorize.payments-sandbox.amazon.com/cobranded-ui/actions/start'.freeze
6
+ CBUI_PRODUCTION_URL = 'https://authorize.payments.amazon.com/cobranded-ui/actions/start'.freeze
7
+ CBUI_API_VERSION = '2009-01-09'
8
+
9
+ attr_reader :url
10
+
11
+ def initialize(access_key, secret_key, params, sandbox = true)
12
+ @access_key = access_key
13
+ @sandbox = true
14
+ @params = params
15
+ add_default_params!
16
+ @signature = generate_signature_for(@params, secret_key)
17
+ create_url!
18
+ end
19
+
20
+ private
21
+ def cbui_url
22
+ @sandbox ? CBUI_SANDBOX_URL : CBUI_PRODUCTION_URL
23
+ end
24
+
25
+ def cbui_api_version
26
+ CBUI_API_VERSION
27
+ end
28
+
29
+ def add_default_params!
30
+ @params[:callerKey] = @access_key
31
+ @params[:pipelineName] = 'MultiUse'
32
+ @params[:version] = cbui_api_version
33
+ end
34
+
35
+ def create_url!
36
+ @url = "" << cbui_url << "?awsSignature=#{@signature}&"
37
+ @url << @params.keys.map { |key| "#{key}=#{@params[key]}" }.join('&')
38
+ end
39
+ end
40
+ end
@@ -3,7 +3,6 @@ module Fpswax
3
3
  class ParameterRequired < ArgumentError; end
4
4
 
5
5
  API_VERSION = '2008-09-17'
6
- CBUI_API_VERSION = '2009-01-09'
7
6
 
8
7
  include Mixins::HmacSignature
9
8
 
@@ -30,8 +29,21 @@ module Fpswax
30
29
  API_VERSION
31
30
  end
32
31
 
33
- def cbui_api_version
34
- CBUI_API_VERSION
32
+
33
+ def ipn_request(params)
34
+ IpnRequest.new(params, @secret_key)
35
+ end
36
+
37
+ def get_multi_use_pipeline(params)
38
+ validate_required?(params,
39
+ :callerReference,
40
+ :globalAmountLimit,
41
+ :returnURL)
42
+
43
+ MultiUsePipelineRequest.new(@access_key,
44
+ @secret_key,
45
+ params,
46
+ in_sandbox?)
35
47
  end
36
48
 
37
49
  # operations
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Fpswax::MultiUsePipelineRequest do
4
+ describe "url" do
5
+ before(:each) do
6
+ @request = Fpswax::MultiUsePipelineRequest.new(
7
+ 'my access key',
8
+ 'my secret key',
9
+ :returnURL => 'http://return_url'
10
+ )
11
+ end
12
+
13
+
14
+ it "should add the access key" do
15
+ @request.url.should =~ /callerKey=my access key/
16
+ end
17
+
18
+ it "should calculate an HMAC signature" do
19
+ @request.url.should =~ /awsSignature=\w+/
20
+ end
21
+
22
+ it "should set a version to 2009-01-09" do
23
+ @request.url.should =~ /version=2009-01-09/
24
+ end
25
+
26
+ it "should set pipelineName to MultiUse" do
27
+ @request.url.should =~ /pipelineName=MultiUse/
28
+ end
29
+
30
+ it "should contain any parameters passed in" do
31
+ @request.url.should =~ /&returnURL=http:\/\/return_url/
32
+ end
33
+ end
34
+ end
@@ -38,9 +38,62 @@ describe Fpswax::Session do
38
38
  end
39
39
  end
40
40
 
41
- describe "cbui_api_version" do
42
- session = Fpswax::Session.new('a', 'b', false)
43
- session.cbui_api_version.should == '2009-01-09'
41
+ describe "ipn_request" do
42
+ it "should return an IpnRequest object with the params and secret key passed through" do
43
+ params = { 'test' => 'it' }
44
+ session = Fpswax::Session.new('a', 'b', false)
45
+
46
+ request = session.ipn_request(params)
47
+ request.should be_a_kind_of(Fpswax::IpnRequest)
48
+ end
49
+ end
50
+
51
+ describe "get_multi_use_pipeline" do
52
+ before(:each) do
53
+ @session = Fpswax::Session.new('a', 'b', true)
54
+ @valid_params = {
55
+ :callerReference => 'a',
56
+ :globalAmountLimit => 5.00,
57
+ :returnURL => 'http://localhost:3000/return_url'
58
+ }
59
+ end
60
+
61
+ it "should return a MultiUsePipelineRequest" do
62
+ response = @session.get_multi_use_pipeline(@valid_params)
63
+ response.should be_an_instance_of(Fpswax::MultiUsePipelineRequest)
64
+ end
65
+
66
+ describe "should validate parameters" do
67
+ it "and raise an error if no valid params are passed" do
68
+ @valid_params.keys.each do |key|
69
+ bad_params = @valid_params.dup
70
+ bad_params.delete(key)
71
+ lambda {
72
+ @session.get_multi_use_pipeline(bad_params)
73
+ }.should raise_error(Fpswax::Session::ParameterRequired)
74
+ end
75
+ end
76
+
77
+ it "and not raise an error if valid params are passed" do
78
+ lambda {
79
+ @session.get_multi_use_pipeline(@valid_params)
80
+ }.should_not raise_error(Fpswax::Session::ParameterRequired)
81
+ end
82
+ end
83
+ end
84
+
85
+ describe "fps_url" do
86
+ it "should point at the production API if we are in production" do
87
+ session = Fpswax::Session.new('a', 'b', false)
88
+ session.should_not be_in_sandbox
89
+ session.fps_url.should == 'https://fps.amazonaws.com'
90
+ end
91
+
92
+ it "should point at the sandbox API if we aren't in production" do
93
+ session = Fpswax::Session.new('a', 'b', true)
94
+ session.should be_in_sandbox
95
+ session.fps_url.should == 'https://fps.sandbox.amazonaws.com'
96
+ end
44
97
  end
45
98
 
46
99
  describe "pay" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbalatero-fpswax
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
  - David Balatero
@@ -40,6 +40,7 @@ files:
40
40
  - lib/fpswax/error.rb
41
41
  - lib/fpswax/ipn_request.rb
42
42
  - lib/fpswax/mixins/hmac_signature.rb
43
+ - lib/fpswax/multi_use_pipeline_request.rb
43
44
  - lib/fpswax/pay_response.rb
44
45
  - lib/fpswax/response.rb
45
46
  - lib/fpswax/session.rb
@@ -54,6 +55,7 @@ files:
54
55
  - spec/fpswax/error_spec.rb
55
56
  - spec/fpswax/ipn_request_spec.rb
56
57
  - spec/fpswax/mixins/hmac_signature_spec.rb
58
+ - spec/fpswax/multi_use_pipeline_request_spec.rb
57
59
  - spec/fpswax/pay_response_spec.rb
58
60
  - spec/fpswax/response_spec.rb
59
61
  - spec/fpswax/session_spec.rb
@@ -88,6 +90,7 @@ test_files:
88
90
  - spec/fpswax/error_spec.rb
89
91
  - spec/fpswax/ipn_request_spec.rb
90
92
  - spec/fpswax/mixins/hmac_signature_spec.rb
93
+ - spec/fpswax/multi_use_pipeline_request_spec.rb
91
94
  - spec/fpswax/pay_response_spec.rb
92
95
  - spec/fpswax/response_spec.rb
93
96
  - spec/fpswax/session_spec.rb