paypal-express 0.1.0 → 0.2.0
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/VERSION +1 -1
- data/lib/paypal.rb +3 -1
- data/lib/paypal/exception.rb +4 -0
- data/lib/paypal/exception/api_error.rb +75 -0
- data/lib/paypal/exception/http_error.rb +12 -0
- data/lib/paypal/ipn.rb +1 -1
- data/lib/paypal/nvp/request.rb +2 -2
- data/spec/paypal/exception/api_error_spec.rb +73 -0
- data/spec/paypal/exception/http_error_spec.rb +10 -0
- data/spec/paypal/ipn_spec.rb +2 -2
- data/spec/paypal/nvp/request_spec.rb +4 -4
- metadata +11 -7
- data/lib/paypal/exceptions.rb +0 -21
- data/spec/paypal/exception_spec.rb +0 -17
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/paypal.rb
CHANGED
@@ -57,7 +57,9 @@ module Paypal
|
|
57
57
|
end
|
58
58
|
|
59
59
|
require 'paypal/util'
|
60
|
-
require 'paypal/
|
60
|
+
require 'paypal/exception'
|
61
|
+
require 'paypal/exception/http_error'
|
62
|
+
require 'paypal/exception/api_error'
|
61
63
|
require 'paypal/base'
|
62
64
|
require 'paypal/ipn'
|
63
65
|
require 'paypal/nvp/request'
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Paypal
|
2
|
+
class Exception
|
3
|
+
class APIError < Exception
|
4
|
+
attr_accessor :response
|
5
|
+
def initialize(response = {})
|
6
|
+
@response = if response.is_a?(Hash)
|
7
|
+
Response.new response
|
8
|
+
else
|
9
|
+
response
|
10
|
+
end
|
11
|
+
super 'PayPal API Error'
|
12
|
+
end
|
13
|
+
|
14
|
+
class Response
|
15
|
+
cattr_reader :attribute_mapping
|
16
|
+
@@attribute_mapping = {
|
17
|
+
:ACK => :ack,
|
18
|
+
:BUILD => :build,
|
19
|
+
:CORRELATIONID => :colleration_id,
|
20
|
+
:TIMESTAMP => :timestamp,
|
21
|
+
:VERSION => :version
|
22
|
+
}
|
23
|
+
attr_accessor *@@attribute_mapping.values
|
24
|
+
attr_accessor :raw, :details
|
25
|
+
|
26
|
+
class Detail
|
27
|
+
cattr_reader :attribute_mapping
|
28
|
+
@@attribute_mapping = {
|
29
|
+
:ERRORCODE => :error_code,
|
30
|
+
:SEVERITYCODE => :severity_code,
|
31
|
+
:LONGMESSAGE => :long_message,
|
32
|
+
:SHORTMESSAGE => :short_message
|
33
|
+
}
|
34
|
+
attr_accessor *@@attribute_mapping.values
|
35
|
+
|
36
|
+
def initialize(attributes = {})
|
37
|
+
@raw = attributes
|
38
|
+
attrs = attributes.dup
|
39
|
+
@@attribute_mapping.each do |key, value|
|
40
|
+
self.send "#{value}=", attrs.delete(key)
|
41
|
+
end
|
42
|
+
|
43
|
+
# warn ignored params
|
44
|
+
attrs.each do |key, value|
|
45
|
+
Paypal.log "Ignored Parameter (#{self.class}): #{key}=#{value}", :warn
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def initialize(attributes = {})
|
51
|
+
attrs = attributes.dup
|
52
|
+
@raw = attributes
|
53
|
+
@@attribute_mapping.each do |key, value|
|
54
|
+
self.send "#{value}=", attrs.delete(key)
|
55
|
+
end
|
56
|
+
details = []
|
57
|
+
attrs.keys.each do |attribute|
|
58
|
+
key, index = attribute.to_s.scan(/^L_(\S+)(\d+)$/).first
|
59
|
+
next if [key, index].any?(&:blank?)
|
60
|
+
details[index.to_i] ||= {}
|
61
|
+
details[index.to_i][key.to_sym] = attrs.delete(attribute)
|
62
|
+
end
|
63
|
+
@details = details.collect do |_attrs_|
|
64
|
+
Detail.new _attrs_
|
65
|
+
end
|
66
|
+
|
67
|
+
# warn ignored params
|
68
|
+
attrs.each do |key, value|
|
69
|
+
Paypal.log "Ignored Parameter (#{self.class}): #{key}=#{value}", :warn
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/paypal/ipn.rb
CHANGED
data/lib/paypal/nvp/request.rb
CHANGED
@@ -52,10 +52,10 @@ module Paypal
|
|
52
52
|
when 'Success', 'SuccessWithWarning'
|
53
53
|
response
|
54
54
|
else
|
55
|
-
raise APIError.new(response)
|
55
|
+
raise Exception::APIError.new(response)
|
56
56
|
end
|
57
57
|
rescue RestClient::Exception => e
|
58
|
-
raise HttpError.new(e.http_code, e.message, e.http_body)
|
58
|
+
raise Exception::HttpError.new(e.http_code, e.message, e.http_body)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Paypal::Exception::APIError do
|
4
|
+
describe '.new' do
|
5
|
+
let :error do
|
6
|
+
Paypal::Exception::APIError.new response
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'when Hash is given' do
|
10
|
+
let :response do
|
11
|
+
{
|
12
|
+
:VERSION=>"66.0",
|
13
|
+
:TIMESTAMP=>"2011-03-03T06:33:51Z",
|
14
|
+
:CORRELATIONID=>"758ebdc546b9c",
|
15
|
+
:L_SEVERITYCODE0=>"Error",
|
16
|
+
:L_ERRORCODE0=>"10411",
|
17
|
+
:L_LONGMESSAGE0=>"This Express Checkout session has expired. Token value is no longer valid.",
|
18
|
+
:BUILD=>"1741654",
|
19
|
+
:ACK=>"Failure",
|
20
|
+
:L_SHORTMESSAGE0=>"This Express Checkout session has expired."
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should have Paypal::Exception::APIError::Response as response' do
|
25
|
+
Paypal::Exception::APIError::Response.attribute_mapping.each do |key, value|
|
26
|
+
error.response.send(value).should == response[key]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should have Paypal::Exception::APIError::Response::Detail as response.detail' do
|
31
|
+
detail = error.response.details.first
|
32
|
+
Paypal::Exception::APIError::Response::Detail.attribute_mapping.each do |key, value|
|
33
|
+
detail.send(value).should == response[:"L_#{key}0"]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should have raw response as response.raw' do
|
38
|
+
error.response.raw.should == response
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when unknown params given' do
|
42
|
+
let :response do
|
43
|
+
{
|
44
|
+
:UNKNOWN => 'Unknown',
|
45
|
+
:L_UNKNOWN0 => 'Unknown Detail'
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should warn it and keep it only in response.raw' do
|
50
|
+
Paypal.logger.should_receive(:warn).with(
|
51
|
+
"Ignored Parameter (Paypal::Exception::APIError::Response): UNKNOWN=Unknown"
|
52
|
+
)
|
53
|
+
Paypal.logger.should_receive(:warn).with(
|
54
|
+
"Ignored Parameter (Paypal::Exception::APIError::Response::Detail): UNKNOWN=Unknown Detail"
|
55
|
+
)
|
56
|
+
error
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'otherwise' do
|
62
|
+
let :response do
|
63
|
+
'Failure'
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should store response in raw format' do
|
67
|
+
error = Paypal::Exception::APIError.new response
|
68
|
+
error.response.should == response
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Paypal::Exception::HttpError do
|
4
|
+
it 'should have code, message and body' do
|
5
|
+
error = Paypal::Exception::HttpError.new(400, 'BadRequest', 'You are bad man!')
|
6
|
+
error.code.should == 400
|
7
|
+
error.message.should == 'BadRequest'
|
8
|
+
error.body.should == 'You are bad man!'
|
9
|
+
end
|
10
|
+
end
|
data/spec/paypal/ipn_spec.rb
CHANGED
@@ -17,10 +17,10 @@ describe Paypal::IPN do
|
|
17
17
|
fake_response 'IPN/invalid', :IPN
|
18
18
|
end
|
19
19
|
|
20
|
-
it 'should raise Paypal::APIError' do
|
20
|
+
it 'should raise Paypal::Exception::APIError' do
|
21
21
|
lambda do
|
22
22
|
Paypal::IPN.verify!("raw-post-body")
|
23
|
-
end.should raise_error(Paypal::APIError)
|
23
|
+
end.should raise_error(Paypal::Exception::APIError)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -61,10 +61,10 @@ describe Paypal::NVP::Request do
|
|
61
61
|
fake_response 'SetExpressCheckout/failure'
|
62
62
|
end
|
63
63
|
|
64
|
-
it 'should raise Paypal::APIError' do
|
64
|
+
it 'should raise Paypal::Exception::APIError' do
|
65
65
|
lambda do
|
66
66
|
instance.request :SetExpressCheckout
|
67
|
-
end.should raise_error(Paypal::APIError)
|
67
|
+
end.should raise_error(Paypal::Exception::APIError)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -78,10 +78,10 @@ describe Paypal::NVP::Request do
|
|
78
78
|
)
|
79
79
|
end
|
80
80
|
|
81
|
-
it 'should raise Paypal::APIError' do
|
81
|
+
it 'should raise Paypal::Exception::APIError' do
|
82
82
|
lambda do
|
83
83
|
instance.request :SetExpressCheckout
|
84
|
-
end.should raise_error(Paypal::HttpError)
|
84
|
+
end.should raise_error(Paypal::Exception::HttpError)
|
85
85
|
end
|
86
86
|
end
|
87
87
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paypal-express
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- nov matake
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-03-03 00:00:00 +09:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -159,7 +159,9 @@ files:
|
|
159
159
|
- lib/cert
|
160
160
|
- lib/paypal.rb
|
161
161
|
- lib/paypal/base.rb
|
162
|
-
- lib/paypal/
|
162
|
+
- lib/paypal/exception.rb
|
163
|
+
- lib/paypal/exception/api_error.rb
|
164
|
+
- lib/paypal/exception/http_error.rb
|
163
165
|
- lib/paypal/express.rb
|
164
166
|
- lib/paypal/express/request.rb
|
165
167
|
- lib/paypal/express/response.rb
|
@@ -195,7 +197,8 @@ files:
|
|
195
197
|
- spec/fake_response/SetExpressCheckout/failure.txt
|
196
198
|
- spec/fake_response/SetExpressCheckout/success.txt
|
197
199
|
- spec/helpers/fake_response_helper.rb
|
198
|
-
- spec/paypal/
|
200
|
+
- spec/paypal/exception/api_error_spec.rb
|
201
|
+
- spec/paypal/exception/http_error_spec.rb
|
199
202
|
- spec/paypal/express/request_spec.rb
|
200
203
|
- spec/paypal/express/response_spec.rb
|
201
204
|
- spec/paypal/ipn_spec.rb
|
@@ -264,7 +267,8 @@ test_files:
|
|
264
267
|
- spec/fake_response/SetExpressCheckout/failure.txt
|
265
268
|
- spec/fake_response/SetExpressCheckout/success.txt
|
266
269
|
- spec/helpers/fake_response_helper.rb
|
267
|
-
- spec/paypal/
|
270
|
+
- spec/paypal/exception/api_error_spec.rb
|
271
|
+
- spec/paypal/exception/http_error_spec.rb
|
268
272
|
- spec/paypal/express/request_spec.rb
|
269
273
|
- spec/paypal/express/response_spec.rb
|
270
274
|
- spec/paypal/ipn_spec.rb
|
data/lib/paypal/exceptions.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
module Paypal
|
2
|
-
|
3
|
-
class Exception < StandardError; end
|
4
|
-
|
5
|
-
class HttpError < Exception
|
6
|
-
attr_accessor :code, :message, :body
|
7
|
-
def initialize(code, message, body = '')
|
8
|
-
@code = code
|
9
|
-
@message = message
|
10
|
-
@body = body
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class APIError < Exception
|
15
|
-
attr_accessor :response
|
16
|
-
def initialize(response = {})
|
17
|
-
@response = response
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'spec_helper.rb'
|
2
|
-
|
3
|
-
describe Paypal::HttpError do
|
4
|
-
it 'should have code, message and body' do
|
5
|
-
error = Paypal::HttpError.new(400, 'BadRequest', 'You are bad man!')
|
6
|
-
error.code.should == 400
|
7
|
-
error.message.should == 'BadRequest'
|
8
|
-
error.body.should == 'You are bad man!'
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe Paypal::APIError do
|
13
|
-
it 'should have raw response' do
|
14
|
-
error = Paypal::APIError.new({:error => 'ERROR!!'})
|
15
|
-
error.response.should == {:error => 'ERROR!!'}
|
16
|
-
end
|
17
|
-
end
|