flexpay 0.1.0 → 0.2.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/lib/flexpay.rb +33 -5
- data/lib/flexpay/cobranding_api/v2009_01_09/pipelines.rb +20 -0
- data/lib/flexpay/fps_api/v2008_09_17.rb +2 -1
- data/lib/flexpay/fps_api/v2008_09_17/cancel_subscription_and_refund.rb +20 -0
- data/lib/flexpay/request.rb +17 -5
- data/lib/flexpay/simple_pay_api/v2009_04_17.rb +9 -0
- data/lib/flexpay/simple_pay_api/v2009_04_17/subscription_button.rb +20 -0
- data/lib/flexpay/util.rb +1 -1
- data/spec/units/cancel_subscription_and_refund_spec.rb +36 -0
- data/spec/units/recipient_token_spec.rb +27 -0
- data/spec/units/subscription_button_spec.rb +20 -0
- data/spec/units/units_helper.rb +2 -1
- metadata +16 -6
data/lib/flexpay.rb
CHANGED
@@ -11,6 +11,7 @@ require 'flexpay/api_module'
|
|
11
11
|
|
12
12
|
require 'flexpay/cobranding_api/v2009_01_09'
|
13
13
|
require 'flexpay/fps_api/v2008_09_17'
|
14
|
+
require 'flexpay/simple_pay_api/v2009_04_17'
|
14
15
|
|
15
16
|
require 'flexpay/util'
|
16
17
|
require 'flexpay/exceptions'
|
@@ -22,28 +23,34 @@ module Flexpay
|
|
22
23
|
API_SANDBOX_ENDPOINT = 'https://fps.sandbox.amazonaws.com/'.freeze
|
23
24
|
PIPELINE_URL = 'https://authorize.payments.amazon.com/cobranded-ui/actions/start'.freeze
|
24
25
|
PIPELINE_SANDBOX_URL = 'https://authorize.payments-sandbox.amazon.com/cobranded-ui/actions/start'.freeze
|
25
|
-
|
26
|
+
SIMPLEPAY_ENDPOINT = 'https://authorize.payments.amazon.com/pba/paypipeline'.freeze
|
27
|
+
SIMPLEPAY_SANDBOX_ENDPOINT = "https://authorize.payments-sandbox.amazon.com/pba/paypipeline".freeze
|
26
28
|
SIGNATURE_VERSION = 2.freeze
|
27
29
|
|
28
30
|
attr_reader :access_key
|
29
31
|
attr_reader :secret_key
|
30
32
|
attr_reader :fps_url
|
31
33
|
attr_reader :pipeline_url
|
34
|
+
attr_reader :simplepay_url
|
32
35
|
attr_reader :cobranding_version
|
33
36
|
attr_reader :fps_version
|
37
|
+
attr_reader :simple_pay_version
|
34
38
|
|
35
39
|
def initialize(params)
|
36
40
|
@access_key = params[:access_key]
|
37
41
|
@secret_key = params[:secret_key]
|
38
42
|
@cobranding_version = params[:cobranding_version] || "2009-01-09"
|
39
43
|
@fps_version = params[:fps_version] || "2008-09-17"
|
44
|
+
@simple_pay_version = params[:simple_pay_version] || "2009-04-17"
|
40
45
|
|
41
46
|
if params[:sandbox].nil? or params[:sandbox] == true
|
42
47
|
@pipeline_url = PIPELINE_SANDBOX_URL
|
43
48
|
@fps_url = API_SANDBOX_ENDPOINT
|
49
|
+
@simplepay_url = SIMPLEPAY_SANDBOX_ENDPOINT
|
44
50
|
else
|
45
51
|
@pipeline_url = PIPELINE_URL
|
46
52
|
@fps_url = API_ENDPOINT
|
53
|
+
@simplepay_url = SIMPLEPAY_ENDPOINT
|
47
54
|
end
|
48
55
|
|
49
56
|
end
|
@@ -53,6 +60,11 @@ module Flexpay
|
|
53
60
|
supply_defaults_for_pipeline_and_return(obj)
|
54
61
|
end
|
55
62
|
|
63
|
+
def get_recipient_token
|
64
|
+
obj = cobranding_constant_lookup(:RecipientToken).new
|
65
|
+
supply_defaults_for_pipeline_and_return(obj)
|
66
|
+
end
|
67
|
+
|
56
68
|
def get_verify_signature
|
57
69
|
obj = fps_constant_lookup(:VerifySignature).new
|
58
70
|
supply_defaults_for_fps_and_return(obj)
|
@@ -63,10 +75,15 @@ module Flexpay
|
|
63
75
|
supply_defaults_for_fps_and_return(obj)
|
64
76
|
end
|
65
77
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
78
|
+
def get_subscription_button
|
79
|
+
obj = simple_pay_constant_lookup(:SubscriptionButton).new
|
80
|
+
supply_defaults_for_simple_pay_and_return(obj)
|
81
|
+
end
|
82
|
+
|
83
|
+
def get_cancel_subscription_and_refund
|
84
|
+
obj = fps_constant_lookup(:CancelSubscriptionAndRefund).new
|
85
|
+
supply_defaults_for_fps_and_return(obj)
|
86
|
+
end
|
70
87
|
|
71
88
|
def access_key
|
72
89
|
raise APINotConfigured if @access_key.nil? || @access_key.empty?
|
@@ -88,6 +105,10 @@ module Flexpay
|
|
88
105
|
Flexpay::FpsAPI.const_get("V#{@fps_version.gsub(/-/,'_')}".to_sym).specific_class(sym)
|
89
106
|
end
|
90
107
|
|
108
|
+
def simple_pay_constant_lookup(sym)
|
109
|
+
Flexpay::SimplePayAPI.const_get("V#{@simple_pay_version.gsub(/-/,'_')}".to_sym).specific_class(sym)
|
110
|
+
end
|
111
|
+
|
91
112
|
def supply_defaults_for_pipeline_and_return(obj)
|
92
113
|
obj.access_key = @access_key
|
93
114
|
obj.secret_key = @secret_key
|
@@ -103,5 +124,12 @@ module Flexpay
|
|
103
124
|
obj
|
104
125
|
end
|
105
126
|
|
127
|
+
def supply_defaults_for_simple_pay_and_return(obj)
|
128
|
+
obj.access_key = @access_key
|
129
|
+
obj.secret_key = @secret_key
|
130
|
+
obj.endpoint = @simplepay_url
|
131
|
+
obj
|
132
|
+
end
|
133
|
+
|
106
134
|
end
|
107
135
|
end
|
@@ -13,6 +13,26 @@ module Flexpay
|
|
13
13
|
self.version = "2009-01-09"
|
14
14
|
end
|
15
15
|
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module Flexpay
|
22
|
+
module CobrandingAPI
|
23
|
+
module V2009_01_09
|
24
|
+
class RecipientToken
|
25
|
+
include Flexpay::CobrandingAPI::V2009_01_09
|
26
|
+
include Flexpay::AmazonFPSRequest
|
27
|
+
|
28
|
+
required_parameters "pipelineName","callerReference", "returnURL", "version", "callerKey",
|
29
|
+
"maxFixedFee", "maxVariableFee", "paymentMethod", "recipientPaysFee"
|
30
|
+
|
31
|
+
def initialize
|
32
|
+
self.pipelineName = "Recipient"
|
33
|
+
self.version = "2009-01-09"
|
34
|
+
end
|
35
|
+
|
16
36
|
end
|
17
37
|
end
|
18
38
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Flexpay
|
2
|
+
module FpsAPI
|
3
|
+
module V2008_09_17
|
4
|
+
class CancelSubscriptionAndRefund
|
5
|
+
include Flexpay::FpsAPI::V2008_09_17
|
6
|
+
include Flexpay::AmazonFPSRequest
|
7
|
+
|
8
|
+
required_parameters "CallerReference", "CancelReason", "RefundAmount", "SubscriptionId", "Action", "AWSAccessKeyId", "Timestamp", "Version"
|
9
|
+
|
10
|
+
response_parameters :RefundTransactionId => "/'CancelSubscriptionAndRefundResponse'/'CancelSubscriptionAndRefundResult'/'RefundTransactionId'"
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
self.Action = "CancelSubscriptionAndRefund"
|
14
|
+
self.Version = "2008-09-17"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/flexpay/request.rb
CHANGED
@@ -51,12 +51,24 @@ module Flexpay
|
|
51
51
|
def go!(signed=true)
|
52
52
|
url = generate_url(signed)
|
53
53
|
|
54
|
-
RestClient.log =
|
55
|
-
|
54
|
+
RestClient.log = Logger.new(STDOUT)
|
55
|
+
result = {}
|
56
|
+
|
57
|
+
begin
|
58
|
+
RestClient.log.info url
|
59
|
+
response = RestClient.get url
|
60
|
+
rescue Exception => e
|
61
|
+
result["Exception"] = e
|
62
|
+
result["Response"] = e.response
|
63
|
+
return result
|
64
|
+
end
|
56
65
|
|
57
|
-
|
66
|
+
if response.respond_to?(:body)
|
67
|
+
doc = Hpricot.XML(response.body)
|
68
|
+
else
|
69
|
+
doc = Hpricot.XML(response)
|
70
|
+
end
|
58
71
|
|
59
|
-
result = {}
|
60
72
|
self.class.get_response_parameters.each do |k,v|
|
61
73
|
result[k] = eval("(doc#{v}).innerHTML")
|
62
74
|
end
|
@@ -91,7 +103,7 @@ module Flexpay
|
|
91
103
|
params = {}
|
92
104
|
self.class.get_required_parameters.each do |p|
|
93
105
|
val = self.send(p)
|
94
|
-
params[p.gsub('_','.')] = val unless val.nil? || val.empty?
|
106
|
+
params[p.gsub('_','.')] = val unless val.nil? || ( val.respond_to?(:empty) ? val.empty? : false )
|
95
107
|
end
|
96
108
|
params
|
97
109
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Flexpay
|
2
|
+
module SimplePayAPI
|
3
|
+
module V2009_04_17
|
4
|
+
|
5
|
+
## This is pseudo-versioned. Amazon intends for a button to be placed on the webpage
|
6
|
+
## but you can just as easily forward the user programatically.
|
7
|
+
|
8
|
+
class SubscriptionButton
|
9
|
+
include Flexpay::SimplePayAPI::V2009_04_17
|
10
|
+
include Flexpay::AmazonFPSRequest
|
11
|
+
|
12
|
+
required_parameters "accessKey", "amount", "description", "recurringFrequency", "returnURL", "immediateReturn"
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/flexpay/util.rb
CHANGED
@@ -19,7 +19,7 @@ module Flexpay
|
|
19
19
|
|
20
20
|
## These are the modified encoding rules proposed by Amazon. Not quite URL encoding
|
21
21
|
def self.modified_URL_encoding(string)
|
22
|
-
URI.escape(string).gsub(/\+/, '%20').gsub(/\*/, '%2A').gsub("%7E","~").gsub(/:/,'%3A').gsub(/\//,'%2F')
|
22
|
+
URI.escape(string).gsub(/\+/, '%20').gsub(/\*/, '%2A').gsub("%7E","~").gsub(/:/,'%3A').gsub(/\//,'%2F').gsub(/,/, '%2C')
|
23
23
|
end
|
24
24
|
|
25
25
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/units_helper'
|
2
|
+
|
3
|
+
describe 'CancelSubscriptionAndRefund' do
|
4
|
+
before(:each) do
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should correctly build a request" do
|
8
|
+
pay = Flexpay::API.new(:access_key => ACCESS_KEY, :secret_key => SECRET_KEY).get_cancel_subscription_and_refund
|
9
|
+
|
10
|
+
body =<<HEREDOC
|
11
|
+
<CancelSubscriptionAndRefundResponse
|
12
|
+
xmlns="http://fps.amazonaws.com/doc/2008-09-17/">
|
13
|
+
<CancelSubscriptionAndRefundResult>
|
14
|
+
<RefundTransactionId>
|
15
|
+
14GKE3B85HCMF1BTSH5C4PD2IHZL95RJ2LM
|
16
|
+
</RefundTransactionId>
|
17
|
+
</CancelSubscriptionAndRefundResult>
|
18
|
+
<ResponseMetadata>
|
19
|
+
<RequestId>bfbc0b1e-3430-4a74-a75e-5292f59107ca:0</RequestId>
|
20
|
+
</ResponseMetadata>
|
21
|
+
</CancelSubscriptionAndRefundResponse>
|
22
|
+
HEREDOC
|
23
|
+
|
24
|
+
RestClient.stub!(:get).and_return(body)
|
25
|
+
|
26
|
+
pay.CallerReference = Time.now.to_i.to_s
|
27
|
+
pay.CancelReason = "UserRequestOnSite"
|
28
|
+
pay.SubscriptionId = "123"
|
29
|
+
pay.Timestamp = Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ")
|
30
|
+
pay.AWSAccessKeyId = ACCESS_KEY
|
31
|
+
|
32
|
+
result = pay.go!
|
33
|
+
result.should have_key(:RefundTransactionId)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/units_helper'
|
2
|
+
|
3
|
+
describe "Recipient token" do
|
4
|
+
before(:each) do
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should respond to all required parameters" do
|
8
|
+
pipeline = Flexpay::API.new(:access_key => ACCESS_KEY, :secret_key => SECRET_KEY).get_recipient_token
|
9
|
+
|
10
|
+
Flexpay::CobrandingAPI::V2009_01_09::RecipientToken::get_required_parameters.each do |p|
|
11
|
+
pipeline.should respond_to(p)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should correctly build a parameter hash" do
|
16
|
+
pipeline = Flexpay::API.new(:access_key => ACCESS_KEY, :secret_key => SECRET_KEY).get_recipient_token
|
17
|
+
|
18
|
+
pipeline.callerReference = Time.now.to_i.to_s
|
19
|
+
pipeline.returnURL = "http://127.0.0.1:3000"
|
20
|
+
pipeline.callerKey = ACCESS_KEY
|
21
|
+
pipeline.recipientPaysFee = true
|
22
|
+
|
23
|
+
url = pipeline.generate_url
|
24
|
+
url.should_not be_empty
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/units_helper'
|
2
|
+
|
3
|
+
describe 'Subscription button' do
|
4
|
+
before(:each) do
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should correctly build a request" do
|
8
|
+
subscription = Flexpay::API.new(:access_key => ACCESS_KEY, :secret_key => SECRET_KEY).get_subscription_button
|
9
|
+
|
10
|
+
subscription.accessKey = ACCESS_KEY
|
11
|
+
subscription.amount = "USD 10"
|
12
|
+
subscription.description = "Unit test"
|
13
|
+
subscription.recurringFrequency = "1 month"
|
14
|
+
subscription.returnURL = "http://localhost:3000"
|
15
|
+
subscription.immediateReturn = 1
|
16
|
+
|
17
|
+
subscription.generate_url.should_not be_empty
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/spec/units/units_helper.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
+
- 2
|
7
8
|
- 1
|
8
|
-
|
9
|
-
version: 0.1.0
|
9
|
+
version: 0.2.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Chris Chandler
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-05-27 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,7 +26,9 @@ dependencies:
|
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
segments:
|
28
28
|
- 0
|
29
|
-
|
29
|
+
- 8
|
30
|
+
- 1
|
31
|
+
version: 0.8.1
|
30
32
|
type: :runtime
|
31
33
|
version_requirements: *id001
|
32
34
|
- !ruby/object:Gem::Dependency
|
@@ -37,8 +39,10 @@ dependencies:
|
|
37
39
|
- - ">="
|
38
40
|
- !ruby/object:Gem::Version
|
39
41
|
segments:
|
40
|
-
-
|
41
|
-
|
42
|
+
- 1
|
43
|
+
- 4
|
44
|
+
- 2
|
45
|
+
version: 1.4.2
|
42
46
|
type: :runtime
|
43
47
|
version_requirements: *id002
|
44
48
|
description:
|
@@ -56,9 +60,12 @@ files:
|
|
56
60
|
- lib/flexpay/cobranding_api/v2009_01_09/pipelines.rb
|
57
61
|
- lib/flexpay/exceptions.rb
|
58
62
|
- lib/flexpay/fps_api/v2008_09_17.rb
|
63
|
+
- lib/flexpay/fps_api/v2008_09_17/cancel_subscription_and_refund.rb
|
59
64
|
- lib/flexpay/fps_api/v2008_09_17/pay.rb
|
60
65
|
- lib/flexpay/fps_api/v2008_09_17/verify_signature.rb
|
61
66
|
- lib/flexpay/request.rb
|
67
|
+
- lib/flexpay/simple_pay_api/v2009_04_17.rb
|
68
|
+
- lib/flexpay/simple_pay_api/v2009_04_17/subscription_button.rb
|
62
69
|
- lib/flexpay/util.rb
|
63
70
|
has_rdoc: true
|
64
71
|
homepage: http://github.com/cchandler/flexpay
|
@@ -92,9 +99,12 @@ specification_version: 3
|
|
92
99
|
summary: An API for using the Amazon Flexible Payment Service (FPS).
|
93
100
|
test_files:
|
94
101
|
- spec/units/api_spec.rb
|
102
|
+
- spec/units/cancel_subscription_and_refund_spec.rb
|
95
103
|
- spec/units/pay_spec.rb
|
104
|
+
- spec/units/recipient_token_spec.rb
|
96
105
|
- spec/units/recurring_pipeline_spec.rb
|
97
106
|
- spec/units/signature_spec.rb
|
107
|
+
- spec/units/subscription_button_spec.rb
|
98
108
|
- spec/units/verify_signature_spec.rb
|
99
109
|
- spec/integrations/integrations_helper.rb
|
100
110
|
- spec/spec_helper.rb
|