paypal-express 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/paypal/express/response.rb +6 -18
- data/spec/paypal/exception/api_error_spec.rb +50 -58
- data/spec/paypal/exception/http_error_spec.rb +4 -6
- data/spec/paypal/express/request_spec.rb +10 -10
- data/spec/paypal/express/response_spec.rb +33 -37
- data/spec/paypal/ipn_spec.rb +7 -15
- data/spec/paypal/nvp/request_spec.rb +5 -5
- metadata +5 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
@@ -1,43 +1,31 @@
|
|
1
1
|
module Paypal
|
2
2
|
module Express
|
3
3
|
class Response < NVP::Response
|
4
|
-
attr_accessor :
|
4
|
+
attr_accessor :pay_on_paypal
|
5
5
|
|
6
6
|
def initialize(response, options = {})
|
7
7
|
super response
|
8
|
-
@on_mobile = options[:on_mobile]
|
9
8
|
@pay_on_paypal = options[:pay_on_paypal]
|
10
9
|
end
|
11
10
|
|
12
11
|
def redirect_uri
|
13
12
|
endpoint = URI.parse Paypal.endpoint
|
14
|
-
endpoint.query = query(:
|
13
|
+
endpoint.query = query(:with_cmd).to_query
|
15
14
|
endpoint.to_s
|
16
15
|
end
|
17
16
|
|
18
17
|
def popup_uri
|
19
18
|
endpoint = URI.parse Paypal.popup_endpoint
|
20
|
-
endpoint.query = query
|
19
|
+
endpoint.query = query.to_query
|
21
20
|
endpoint.to_s
|
22
21
|
end
|
23
22
|
|
24
23
|
private
|
25
24
|
|
26
|
-
def query(
|
25
|
+
def query(with_cmd = false)
|
27
26
|
_query_ = {:token => self.token}
|
28
|
-
|
29
|
-
|
30
|
-
if self.on_mobile
|
31
|
-
_query_.merge!(:cmd => '_express-checkout-mobile')
|
32
|
-
else
|
33
|
-
_query_.merge!(:cmd => '_express-checkout')
|
34
|
-
end
|
35
|
-
when :popup
|
36
|
-
# No popup specific params for now
|
37
|
-
end
|
38
|
-
if self.pay_on_paypal
|
39
|
-
_query_.merge!(:useraction => 'commit')
|
40
|
-
end
|
27
|
+
_query_.merge!(:cmd => '_express-checkout') if with_cmd
|
28
|
+
_query_.merge!(:useraction => 'commit') if pay_on_paypal
|
41
29
|
_query_
|
42
30
|
end
|
43
31
|
end
|
@@ -1,73 +1,65 @@
|
|
1
1
|
require 'spec_helper.rb'
|
2
2
|
|
3
3
|
describe Paypal::Exception::APIError do
|
4
|
-
|
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
|
4
|
+
let(:error) { Paypal::Exception::APIError.new(params) }
|
23
5
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
6
|
+
context 'when Hash is given' do
|
7
|
+
let :params do
|
8
|
+
{
|
9
|
+
:VERSION=>"66.0",
|
10
|
+
:TIMESTAMP=>"2011-03-03T06:33:51Z",
|
11
|
+
:CORRELATIONID=>"758ebdc546b9c",
|
12
|
+
:L_SEVERITYCODE0=>"Error",
|
13
|
+
:L_ERRORCODE0=>"10411",
|
14
|
+
:L_LONGMESSAGE0=>"This Express Checkout session has expired. Token value is no longer valid.",
|
15
|
+
:BUILD=>"1741654",
|
16
|
+
:ACK=>"Failure",
|
17
|
+
:L_SHORTMESSAGE0=>"This Express Checkout session has expired."
|
18
|
+
}
|
19
|
+
end
|
36
20
|
|
37
|
-
|
38
|
-
|
21
|
+
describe '#subject' do
|
22
|
+
subject { error.response }
|
23
|
+
its(:raw) { should == params }
|
24
|
+
Paypal::Exception::APIError::Response.attribute_mapping.each do |key, attribute|
|
25
|
+
its(attribute) { should == params[key] }
|
39
26
|
end
|
40
27
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
28
|
+
describe '#details' do
|
29
|
+
subject { error.response.details.first }
|
30
|
+
Paypal::Exception::APIError::Response::Detail.attribute_mapping.each do |key, attribute|
|
31
|
+
its(attribute) { should == params[:"L_#{key}0"] }
|
57
32
|
end
|
58
33
|
end
|
59
34
|
end
|
35
|
+
end
|
60
36
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
37
|
+
context 'when unknown params given' do
|
38
|
+
let :params do
|
39
|
+
{
|
40
|
+
:UNKNOWN => 'Unknown',
|
41
|
+
:L_UNKNOWN0 => 'Unknown Detail'
|
42
|
+
}
|
43
|
+
end
|
65
44
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
45
|
+
it 'should warn' do
|
46
|
+
Paypal.logger.should_receive(:warn).with(
|
47
|
+
"Ignored Parameter (Paypal::Exception::APIError::Response): UNKNOWN=Unknown"
|
48
|
+
)
|
49
|
+
Paypal.logger.should_receive(:warn).with(
|
50
|
+
"Ignored Parameter (Paypal::Exception::APIError::Response::Detail): UNKNOWN=Unknown Detail"
|
51
|
+
)
|
52
|
+
error
|
53
|
+
end
|
54
|
+
describe '#response' do
|
55
|
+
subject { error.response }
|
56
|
+
its(:raw) { should == params }
|
70
57
|
end
|
71
58
|
end
|
72
|
-
|
59
|
+
|
60
|
+
context 'otherwise' do
|
61
|
+
subject { error }
|
62
|
+
let(:params) { 'Failure' }
|
63
|
+
its(:response) { should == params }
|
64
|
+
end
|
73
65
|
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
require 'spec_helper.rb'
|
2
2
|
|
3
3
|
describe Paypal::Exception::HttpError do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
error.body.should == 'You are bad man!'
|
9
|
-
end
|
4
|
+
subject { Paypal::Exception::HttpError.new(400, 'BadRequest', 'You are bad man!') }
|
5
|
+
its(:code) { should == 400 }
|
6
|
+
its(:message) { should == 'BadRequest' }
|
7
|
+
its(:body) { should == 'You are bad man!' }
|
10
8
|
end
|
@@ -58,7 +58,7 @@ describe Paypal::Express::Request do
|
|
58
58
|
insufficient_attributes = attributes.reject do |key, value|
|
59
59
|
key == missing_key
|
60
60
|
end
|
61
|
-
|
61
|
+
expect do
|
62
62
|
Paypal::Express::Request.new insufficient_attributes
|
63
63
|
end.should raise_error AttrRequired::AttrMissing
|
64
64
|
end
|
@@ -67,7 +67,7 @@ describe Paypal::Express::Request do
|
|
67
67
|
|
68
68
|
context 'when all required parameters are given' do
|
69
69
|
it 'should succeed' do
|
70
|
-
|
70
|
+
expect do
|
71
71
|
Paypal::Express::Request.new attributes
|
72
72
|
end.should_not raise_error AttrRequired::AttrMissing
|
73
73
|
end
|
@@ -82,7 +82,7 @@ describe Paypal::Express::Request do
|
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'should support no_shipping option' do
|
85
|
-
|
85
|
+
expect do
|
86
86
|
instance.setup instant_payment_request, :no_shipping => true
|
87
87
|
end.should request_to 'https://api-3t.paypal.com/nvp', :post
|
88
88
|
instance._method_.should == :SetExpressCheckout
|
@@ -98,7 +98,7 @@ describe Paypal::Express::Request do
|
|
98
98
|
|
99
99
|
context 'when instance payment request given' do
|
100
100
|
it 'should call SetExpressCheckout' do
|
101
|
-
|
101
|
+
expect do
|
102
102
|
instance.setup instant_payment_request
|
103
103
|
end.should request_to 'https://api-3t.paypal.com/nvp', :post
|
104
104
|
instance._method_.should == :SetExpressCheckout
|
@@ -113,7 +113,7 @@ describe Paypal::Express::Request do
|
|
113
113
|
|
114
114
|
context 'when recurring payment request given' do
|
115
115
|
it 'should call SetExpressCheckout' do
|
116
|
-
|
116
|
+
expect do
|
117
117
|
instance.setup recurring_payment_request
|
118
118
|
end.should request_to 'https://api-3t.paypal.com/nvp', :post
|
119
119
|
instance._method_.should == :SetExpressCheckout
|
@@ -136,7 +136,7 @@ describe Paypal::Express::Request do
|
|
136
136
|
end
|
137
137
|
|
138
138
|
it 'should call GetExpressCheckoutDetails' do
|
139
|
-
|
139
|
+
expect do
|
140
140
|
instance.details 'token'
|
141
141
|
end.should request_to 'https://api-3t.paypal.com/nvp', :post
|
142
142
|
instance._method_.should == :GetExpressCheckoutDetails
|
@@ -154,7 +154,7 @@ describe Paypal::Express::Request do
|
|
154
154
|
end
|
155
155
|
|
156
156
|
it 'should call DoExpressCheckoutPayment' do
|
157
|
-
|
157
|
+
expect do
|
158
158
|
instance.checkout! 'token', 'payer_id', instant_payment_request
|
159
159
|
end.should request_to 'https://api-3t.paypal.com/nvp', :post
|
160
160
|
instance._method_.should == :DoExpressCheckoutPayment
|
@@ -175,7 +175,7 @@ describe Paypal::Express::Request do
|
|
175
175
|
end
|
176
176
|
|
177
177
|
it 'should call CreateRecurringPaymentsProfile' do
|
178
|
-
|
178
|
+
expect do
|
179
179
|
instance.subscribe! 'token', recurring_profile
|
180
180
|
end.should request_to 'https://api-3t.paypal.com/nvp', :post
|
181
181
|
instance._method_.should == :CreateRecurringPaymentsProfile
|
@@ -205,7 +205,7 @@ describe Paypal::Express::Request do
|
|
205
205
|
end
|
206
206
|
|
207
207
|
it 'should call GetRecurringPaymentsProfileDetails' do
|
208
|
-
|
208
|
+
expect do
|
209
209
|
instance.subscription 'profile_id'
|
210
210
|
end.should request_to 'https://api-3t.paypal.com/nvp', :post
|
211
211
|
instance._method_.should == :GetRecurringPaymentsProfileDetails
|
@@ -223,7 +223,7 @@ describe Paypal::Express::Request do
|
|
223
223
|
end
|
224
224
|
|
225
225
|
it 'should call ManageRecurringPaymentsProfileStatus' do
|
226
|
-
|
226
|
+
expect do
|
227
227
|
instance.renew! 'profile_id', :Cancel
|
228
228
|
end.should request_to 'https://api-3t.paypal.com/nvp', :post
|
229
229
|
instance._method_.should == :ManageRecurringPaymentsProfileStatus
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'spec_helper.rb'
|
2
2
|
|
3
3
|
describe Paypal::Express::Response do
|
4
|
+
before { fake_response 'SetExpressCheckout/success' }
|
5
|
+
|
4
6
|
let :request do
|
5
7
|
Paypal::Express::Request.new(
|
6
8
|
:username => 'nov',
|
@@ -10,63 +12,57 @@ describe Paypal::Express::Response do
|
|
10
12
|
:cancel_url => 'http://example.com/cancel'
|
11
13
|
)
|
12
14
|
end
|
13
|
-
|
14
15
|
let :payment_request do
|
15
16
|
Paypal::Payment::Request.new(
|
16
17
|
:billing_type => :RecurringPayments,
|
17
18
|
:billing_agreement_description => 'Recurring Payment Request'
|
18
19
|
)
|
19
20
|
end
|
21
|
+
let(:response) { request.setup payment_request }
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
+
describe '#redirect_uri' do
|
24
|
+
subject { response.redirect_uri }
|
25
|
+
it { should include 'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=' }
|
23
26
|
end
|
24
27
|
|
25
|
-
describe '#
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
describe '#popup_uri' do
|
29
|
+
subject { response.popup_uri }
|
30
|
+
it { should include 'https://www.paypal.com/incontext?token=' }
|
31
|
+
end
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
response.on_mobile.should be_true
|
33
|
-
response.send(:query, :redirect)[:cmd].should == '_express-checkout-mobile'
|
34
|
-
end
|
33
|
+
context 'when pay_on_paypal option is given' do
|
34
|
+
let(:response) { request.setup payment_request, :pay_on_paypal => true }
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
response.send(:query, :popup)[:useraction].should == 'commit'
|
40
|
-
response.send(:query, :redirect)[:useraction].should == 'commit'
|
41
|
-
end
|
42
|
-
end
|
36
|
+
subject { response }
|
37
|
+
its(:pay_on_paypal) { should be_true }
|
38
|
+
its(:query) { should include(:useraction => 'commit') }
|
43
39
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
instance.redirect_uri.should == 'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-5YJ90598G69065317'
|
40
|
+
describe '#redirect_uri' do
|
41
|
+
subject { response.redirect_uri }
|
42
|
+
it { should include 'useraction=commit' }
|
48
43
|
end
|
49
44
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
instance.redirect_uri.should == 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-5YJ90598G69065317'
|
54
|
-
end
|
45
|
+
describe '#popup_uri' do
|
46
|
+
subject { response.popup_uri }
|
47
|
+
it { should include 'useraction=commit' }
|
55
48
|
end
|
56
49
|
end
|
57
50
|
|
58
|
-
|
59
|
-
|
51
|
+
context 'when sandbox mode' do
|
52
|
+
before do
|
53
|
+
Paypal.sandbox!
|
60
54
|
fake_response 'SetExpressCheckout/success'
|
61
|
-
instance.popup_uri.should == 'https://www.paypal.com/incontext?token=EC-5YJ90598G69065317'
|
62
55
|
end
|
56
|
+
after { Paypal.sandbox = false }
|
63
57
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
instance.popup_uri.should == 'https://www.sandbox.paypal.com/incontext?token=EC-5YJ90598G69065317'
|
68
|
-
end
|
58
|
+
describe '#redirect_uri' do
|
59
|
+
subject { response.redirect_uri }
|
60
|
+
it { should include 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=' }
|
69
61
|
end
|
70
|
-
end
|
71
62
|
|
63
|
+
describe '#popup_uri' do
|
64
|
+
subject { response.popup_uri }
|
65
|
+
it { should include 'https://www.sandbox.paypal.com/incontext?token=' }
|
66
|
+
end
|
67
|
+
end
|
72
68
|
end
|
data/spec/paypal/ipn_spec.rb
CHANGED
@@ -3,24 +3,16 @@ require 'spec_helper'
|
|
3
3
|
describe Paypal::IPN do
|
4
4
|
describe '.verify!' do
|
5
5
|
context 'when valid' do
|
6
|
-
before
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
it 'should return true' do
|
11
|
-
Paypal::IPN.verify!("raw-post-body").should be_true
|
12
|
-
end
|
6
|
+
before { fake_response 'IPN/valid', :IPN }
|
7
|
+
subject { Paypal::IPN.verify!('raw-post-body') }
|
8
|
+
it { should be_true }
|
13
9
|
end
|
14
10
|
|
15
11
|
context 'when invalid' do
|
16
|
-
before
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
it 'should raise Paypal::Exception::APIError' do
|
21
|
-
lambda do
|
22
|
-
Paypal::IPN.verify!("raw-post-body")
|
23
|
-
end.should raise_error(Paypal::Exception::APIError)
|
12
|
+
before { fake_response 'IPN/invalid', :IPN }
|
13
|
+
subject {}
|
14
|
+
it do
|
15
|
+
expect { Paypal::IPN.verify!('raw-post-body') }.should raise_error(Paypal::Exception::APIError)
|
24
16
|
end
|
25
17
|
end
|
26
18
|
end
|
@@ -20,7 +20,7 @@ describe Paypal::NVP::Request do
|
|
20
20
|
insufficient_attributes = attributes.reject do |key, value|
|
21
21
|
key == missing_key
|
22
22
|
end
|
23
|
-
|
23
|
+
expect do
|
24
24
|
Paypal::NVP::Request.new insufficient_attributes
|
25
25
|
end.should raise_error AttrRequired::AttrMissing
|
26
26
|
end
|
@@ -29,7 +29,7 @@ describe Paypal::NVP::Request do
|
|
29
29
|
|
30
30
|
context 'when all required parameters are given' do
|
31
31
|
it 'should succeed' do
|
32
|
-
|
32
|
+
expect do
|
33
33
|
Paypal::NVP::Request.new attributes
|
34
34
|
end.should_not raise_error AttrRequired::AttrMissing
|
35
35
|
end
|
@@ -51,7 +51,7 @@ describe Paypal::NVP::Request do
|
|
51
51
|
|
52
52
|
describe '#request' do
|
53
53
|
it 'should POST to NPV endpoint' do
|
54
|
-
|
54
|
+
expect do
|
55
55
|
instance.request :RPCMethod
|
56
56
|
end.should request_to Paypal::NVP::Request::ENDPOINT[:production], :post
|
57
57
|
end
|
@@ -62,7 +62,7 @@ describe Paypal::NVP::Request do
|
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'should raise Paypal::Exception::APIError' do
|
65
|
-
|
65
|
+
expect do
|
66
66
|
instance.request :SetExpressCheckout
|
67
67
|
end.should raise_error(Paypal::Exception::APIError)
|
68
68
|
end
|
@@ -79,7 +79,7 @@ describe Paypal::NVP::Request do
|
|
79
79
|
end
|
80
80
|
|
81
81
|
it 'should raise Paypal::Exception::APIError' do
|
82
|
-
|
82
|
+
expect do
|
83
83
|
instance.request :SetExpressCheckout
|
84
84
|
end.should raise_error(Paypal::Exception::HttpError)
|
85
85
|
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: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
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-03-
|
18
|
+
date: 2011-03-04 00:00:00 +09:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -247,7 +247,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
247
247
|
requirements: []
|
248
248
|
|
249
249
|
rubyforge_project:
|
250
|
-
rubygems_version: 1.5.
|
250
|
+
rubygems_version: 1.5.3
|
251
251
|
signing_key:
|
252
252
|
specification_version: 3
|
253
253
|
summary: PayPal Express Checkout API Client Supporting Both Instant and Recurring Payment
|