amazon_flex_pay 0.9.9 → 0.9.10
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/amazon_flex_pay.rb
CHANGED
@@ -1,33 +1,4 @@
|
|
1
1
|
module AmazonFlexPay::API #:nodoc:
|
2
|
-
class ErrorResponse < StandardError
|
3
|
-
# Re-implements the XML parsing because ErrorResponse does not inherit from BaseResponse.
|
4
|
-
def self.from_xml(xml)
|
5
|
-
new(MultiXml.parse(xml)['Response'])
|
6
|
-
end
|
7
|
-
|
8
|
-
def initialize(hash)
|
9
|
-
self.request_id = hash['RequestID']
|
10
|
-
self.errors = hash['Errors']
|
11
|
-
end
|
12
|
-
|
13
|
-
attr_accessor :request
|
14
|
-
attr_accessor :request_id
|
15
|
-
|
16
|
-
attr_reader :errors
|
17
|
-
def errors=(val)
|
18
|
-
@errors = [val['Error']].flatten.map{|e| Error.new(e)}
|
19
|
-
end
|
20
|
-
|
21
|
-
def to_s
|
22
|
-
errors.map{|e| "#{e.code}: #{e.message}"}.join(', ')
|
23
|
-
end
|
24
|
-
|
25
|
-
class Error < AmazonFlexPay::Model #:nodoc:
|
26
|
-
attribute :code
|
27
|
-
attribute :message
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
2
|
class BaseRequest < AmazonFlexPay::Model
|
32
3
|
# This compiles an API request object into a URL, sends it to Amazon, and processes
|
33
4
|
# the response.
|
@@ -39,8 +10,8 @@ module AmazonFlexPay::API #:nodoc:
|
|
39
10
|
response
|
40
11
|
rescue RestClient::BadRequest, RestClient::Unauthorized, RestClient::Forbidden => e
|
41
12
|
er = ErrorResponse.from_xml(e.response.body)
|
42
|
-
|
43
|
-
raise er
|
13
|
+
klass = AmazonFlexPay::API.const_get(er.errors.first.code)
|
14
|
+
raise klass.new(er.errors.first.code, er.errors.first.message, er.request_id, self)
|
44
15
|
end
|
45
16
|
end
|
46
17
|
|
@@ -78,6 +49,25 @@ module AmazonFlexPay::API #:nodoc:
|
|
78
49
|
end
|
79
50
|
end
|
80
51
|
|
52
|
+
class ErrorResponse < AmazonFlexPay::Model
|
53
|
+
attribute :request_id
|
54
|
+
|
55
|
+
def self.from_xml(xml)
|
56
|
+
new(MultiXml.parse(xml)['Response'])
|
57
|
+
end
|
58
|
+
|
59
|
+
attr_reader :errors
|
60
|
+
def errors=(val)
|
61
|
+
@errors = [val['Error']].flatten.map{|e| Error.new(e)}
|
62
|
+
end
|
63
|
+
|
64
|
+
class Error < AmazonFlexPay::Model #:nodoc:
|
65
|
+
attribute :code
|
66
|
+
attribute :message
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
81
71
|
protected
|
82
72
|
|
83
73
|
def action_name #:nodoc:
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module AmazonFlexPay::API
|
2
|
+
class Error < StandardError
|
3
|
+
attr_accessor :request, :request_id, :code, :message
|
4
|
+
|
5
|
+
def initialize(code, message, request_id, request)
|
6
|
+
@request_id, @request, @code, @message = request_id, request, code, message
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
# generated from http://docs.amazonwebservices.com/AmazonFPS/latest/FPSAPIReference/APIErrorCodesTable.html
|
11
|
+
# 2010-08-28
|
12
|
+
%w(
|
13
|
+
AccessFailure
|
14
|
+
AccountClosed
|
15
|
+
AccountLimitsExceeded
|
16
|
+
AmountOutOfRange
|
17
|
+
ConcurrentModification
|
18
|
+
DuplicateRequest
|
19
|
+
InactiveInstrument
|
20
|
+
InsufficientBalance
|
21
|
+
InternalError
|
22
|
+
InvalidAccountState
|
23
|
+
InvalidAccountState_Caller
|
24
|
+
InvalidAccountState_Recipient
|
25
|
+
InvalidAccountState_Sender
|
26
|
+
InvalidParams
|
27
|
+
InvalidSenderRoleForAccountType
|
28
|
+
InvalidTokenId
|
29
|
+
InvalidTokenId_Recipient
|
30
|
+
InvalidTokenId_Sender
|
31
|
+
InvalidTokenType
|
32
|
+
InvalidTransactionId
|
33
|
+
InvalidTransactionState
|
34
|
+
OriginalTransactionFailed
|
35
|
+
RefundAmountExceeded
|
36
|
+
SenderNotOriginalRecipient
|
37
|
+
SettleAmountGreaterThanDebt
|
38
|
+
SettleAmountGreaterThanReserveAmount
|
39
|
+
TokenAccessDenied
|
40
|
+
TokenNotActive
|
41
|
+
TokenNotActive_Recipient
|
42
|
+
TokenNotActive_Sender
|
43
|
+
TransactionDenied
|
44
|
+
TransactionFullyRefundedAlready
|
45
|
+
TransactionTypeNotRefundable
|
46
|
+
UnverifiedAccount_Recipient
|
47
|
+
UnverifiedAccount_Sender
|
48
|
+
UnverifiedBankAccount
|
49
|
+
UnverifiedEmailAddress_Caller
|
50
|
+
UnverifiedEmailAddress_Recipient
|
51
|
+
UnverifiedEmailAddress_Sender
|
52
|
+
).each do |name|
|
53
|
+
const_set(name, Class.new(Error))
|
54
|
+
end
|
55
|
+
end
|
@@ -95,12 +95,12 @@ class AmazonFlexPayTest < AmazonFlexPay::Test
|
|
95
95
|
error = nil
|
96
96
|
begin
|
97
97
|
TestRequest.new(:foo => 'bar').submit
|
98
|
-
rescue AmazonFlexPay::API::
|
98
|
+
rescue AmazonFlexPay::API::InvalidParams => e
|
99
99
|
error = e
|
100
100
|
end
|
101
101
|
assert error.request_id
|
102
|
-
|
103
|
-
assert error.
|
102
|
+
assert_equal 'InvalidParams', error.code
|
103
|
+
assert error.message.match(/has to be a valid/)
|
104
104
|
end
|
105
105
|
|
106
106
|
should "not allow unknown values for enumerated attributes" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amazon_flex_pay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 47
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 10
|
10
|
+
version: 0.9.10
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Lance Ivy
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-04-17 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- lib/amazon_flex_pay/api/base_request.rb
|
93
93
|
- lib/amazon_flex_pay/api/cancel.rb
|
94
94
|
- lib/amazon_flex_pay/api/cancel_token.rb
|
95
|
+
- lib/amazon_flex_pay/api/errors.rb
|
95
96
|
- lib/amazon_flex_pay/api/get_account_activity.rb
|
96
97
|
- lib/amazon_flex_pay/api/get_account_balance.rb
|
97
98
|
- lib/amazon_flex_pay/api/get_recipient_verification_status.rb
|