paypal_api 0.3.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/.gitignore +6 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/README.markdown +161 -0
- data/Rakefile +1 -0
- data/init.rb +1 -0
- data/lib/paypal_api/apis/api.rb +149 -0
- data/lib/paypal_api/apis/mass_pay.rb +25 -0
- data/lib/paypal_api/apis/payments_pro.rb +155 -0
- data/lib/paypal_api/support/parameter.rb +195 -0
- data/lib/paypal_api/support/request.rb +125 -0
- data/lib/paypal_api/support/response.rb +77 -0
- data/lib/paypal_api/version.rb +3 -0
- data/lib/paypal_api.rb +21 -0
- data/paypal_api.gemspec +26 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/support/parameter_spec.rb +189 -0
- data/spec/support/request_spec.rb +143 -0
- data/spec/support/response_spec.rb +33 -0
- data/spec/unit/api_spec.rb +133 -0
- data/spec/unit/mass_pay_spec.rb +84 -0
- data/spec/unit/payments_pro_spec.rb +121 -0
- metadata +118 -0
@@ -0,0 +1,133 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Paypal::Api do
|
4
|
+
before do
|
5
|
+
@api = Paypal::Api
|
6
|
+
end
|
7
|
+
|
8
|
+
describe :set_request_signature do
|
9
|
+
it "should be callable from a class body definition" do
|
10
|
+
expect {
|
11
|
+
class Test < @api
|
12
|
+
set_request_signature :test, {}
|
13
|
+
end
|
14
|
+
}.to_not raise_exception
|
15
|
+
end
|
16
|
+
|
17
|
+
context "with field descriptions" do
|
18
|
+
before do
|
19
|
+
class Test < @api
|
20
|
+
set_request_signature :tester, {
|
21
|
+
:test_field => "something",
|
22
|
+
:optional => @api::Optional.new(String),
|
23
|
+
:string => String,
|
24
|
+
:fixnum => Fixnum,
|
25
|
+
:default => @api::Default.new("tamp", Fixnum),
|
26
|
+
:enum => @api::Enum.new("one", "two"),
|
27
|
+
:sequential => @api::Sequential.new({:l_string => String, :l_fixnum => Fixnum, :l_set_category => Optional.new(String)})
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should add getters for all keys" do
|
33
|
+
Test.tester.payload.each do |k,v|
|
34
|
+
Test.tester.respond_to?(k).should be_true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return a dynamic request object" do
|
39
|
+
Test.tester.class.should eq(Paypal::TesterRequest)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should make the class respond to class method" do
|
43
|
+
Test.respond_to?(:tester).should be_true
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should add constant getters and not setters for value types" do
|
47
|
+
Test.tester.respond_to?(:test_field).should be_true
|
48
|
+
Test.tester.send(:test_field).should eq("something")
|
49
|
+
Test.tester.respond_to?(:test_field=).should be_false
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should add setters for all non-constant types" do
|
53
|
+
request = Test.tester
|
54
|
+
request.payload.each do |k,v|
|
55
|
+
if [String, Fixnum, Float].include?(v.class)
|
56
|
+
request.respond_to?(k).should be_false
|
57
|
+
else
|
58
|
+
request.respond_to?(k).should be_true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should raise an InvalidRequest error when missing required fields" do
|
64
|
+
request = Test.tester
|
65
|
+
expect {
|
66
|
+
request.make
|
67
|
+
}.to raise_exception(Paypal::InvalidRequest)
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "setters" do
|
71
|
+
before do
|
72
|
+
@request = Test.tester
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should handle sequential types" do
|
76
|
+
@request.sequential.push({:l_string => "sasdf", :l_fixnum => 23, :l_set_category => "asdfasdf"})
|
77
|
+
|
78
|
+
@request.sequentials_string.should include("sasdf")
|
79
|
+
@request.sequentials_string.should include("23")
|
80
|
+
|
81
|
+
@request.sequential.push({:l_string => "alf", :l_fixnum => 22})
|
82
|
+
@request.sequentials_string.should include("L_FIXNUM1")
|
83
|
+
@request.sequentials_string.should include("L_SETCATEGORY0")
|
84
|
+
@request.sequentials_string.should_not include("L_SETCATEGORY1")
|
85
|
+
|
86
|
+
expect {
|
87
|
+
@request.sequential.push({:l_string => "sass"})
|
88
|
+
}.to raise_exception Paypal::InvalidParameter
|
89
|
+
|
90
|
+
expect {
|
91
|
+
@request.sequential.push({:l_string => "sass", :l_fixnum => "string"})
|
92
|
+
}.to raise_exception Paypal::InvalidParameter
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should handle types like String Fixnum and Float" do
|
96
|
+
@request.string = "a string"
|
97
|
+
@request.string.should eq("a string")
|
98
|
+
|
99
|
+
expect {
|
100
|
+
@request.string = 10
|
101
|
+
}.to raise_exception Paypal::InvalidParameter
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should handle types of Parameters" do
|
105
|
+
@request.payload.each do |k, v|
|
106
|
+
@request.respond_to?("#{k}=").should be_true if v.class < @api::Parameter
|
107
|
+
end
|
108
|
+
|
109
|
+
@request.enum = "one"
|
110
|
+
@request.enum.should eq("one")
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should handle constant types" do
|
114
|
+
@request.test_field.should eq("something")
|
115
|
+
@request.respond_to?(:test_field=).should be_false
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should handle default types" do
|
119
|
+
@request.default.should eq("tamp")
|
120
|
+
@request.default = 10
|
121
|
+
@request.default.should eq(10)
|
122
|
+
|
123
|
+
expect {
|
124
|
+
@request.default = "asdf"
|
125
|
+
}.to raise_exception Paypal::InvalidParameter
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Paypal::MassPay do
|
4
|
+
|
5
|
+
describe :mass_pay do
|
6
|
+
before(:each) do
|
7
|
+
@request = Paypal::MassPay.mass_pay
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be invalid without a payee" do
|
11
|
+
@request.valid?.should be_false
|
12
|
+
@request.error_message.should_not be_nil
|
13
|
+
end
|
14
|
+
|
15
|
+
context "with payees" do
|
16
|
+
|
17
|
+
before(:each) do
|
18
|
+
@request.payee.push({
|
19
|
+
:email => "mark@suster.com",
|
20
|
+
:amt => 10.23
|
21
|
+
})
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should be valid with a payee" do
|
25
|
+
@request.valid?.should be_true
|
26
|
+
@request.error_message.should be_nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should render the keys in the request properly" do
|
30
|
+
@request.request_string.should include("&L_EMAIL0=mark%40suster.com&L_AMT0=10.23&METHOD=MassPay&CURRENCYCODE=USD&RECEIVERTYPE=EmailAddress")
|
31
|
+
expect {
|
32
|
+
URI.parse(@request.request_string)
|
33
|
+
}.to_not raise_exception
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should allow 249 more payees" do
|
37
|
+
249.times do
|
38
|
+
@request.payee.push({
|
39
|
+
:email => "mark@suster.com",
|
40
|
+
:amt => 10.23
|
41
|
+
})
|
42
|
+
end
|
43
|
+
|
44
|
+
@request.valid?.should be_true
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should error out when there are more than 250 payees" do
|
48
|
+
expect {
|
49
|
+
250.times do
|
50
|
+
@request.payee.push({
|
51
|
+
:email => "mark@suster.com",
|
52
|
+
:amt => 10.23
|
53
|
+
})
|
54
|
+
end
|
55
|
+
}.to raise_exception(Paypal::InvalidParameter)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should make a valid request", :slow_paypal => true do
|
59
|
+
response = nil
|
60
|
+
expect {
|
61
|
+
response = @request.make
|
62
|
+
}.to_not raise_exception Paypal::InvalidRequest
|
63
|
+
|
64
|
+
response.raw_response.should_not be_nil
|
65
|
+
response.success?.should be_true
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "with stubbed response" do
|
69
|
+
before(:each) do
|
70
|
+
Paypal::MassPayRequest.any_instance.stub(:make_request).and_return(Paypal::Response.new("TIMESTAMP=2012%2d02%2d26T23%3a19%3a06Z&CORRELATIONID=204a7348d3e11&ACK=Success&VERSION=84%2e0&BUILD=2571254"))
|
71
|
+
end
|
72
|
+
|
73
|
+
before(:each) do
|
74
|
+
@response = @request.make
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should have a correlationid" do
|
78
|
+
@response[:correlation_id].should eq("204a7348d3e11")
|
79
|
+
@response.success?.should be_true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Paypal::PaymentsPro do
|
4
|
+
describe :do_direct_payment do
|
5
|
+
before do
|
6
|
+
@request = Paypal::PaymentsPro.do_direct_payment
|
7
|
+
@request.ip_address = "192.168.0.1"
|
8
|
+
@request.exp_date = "042013"
|
9
|
+
@request.cvv2 = "123"
|
10
|
+
@request.acct = "4683075410516684"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should fail without enough params" do
|
14
|
+
expect {
|
15
|
+
@request.make
|
16
|
+
}.to raise_exception Paypal::InvalidRequest
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with more params" do
|
20
|
+
before do
|
21
|
+
@request.first_name = "mark"
|
22
|
+
@request.last_name = "suster"
|
23
|
+
@request.street = "12 thirteen lane"
|
24
|
+
@request.city = "brooklyn"
|
25
|
+
@request.state = "ny"
|
26
|
+
@request.zip = "11211"
|
27
|
+
@request.amt = 1.00
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should formulate a valid request" do
|
31
|
+
@request.request_string.should_not be_nil
|
32
|
+
|
33
|
+
expect {
|
34
|
+
URI.parse(@request.request_string)
|
35
|
+
}.to_not raise_exception
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should make a valid request", :slow_paypal => true do
|
39
|
+
response = nil
|
40
|
+
expect {
|
41
|
+
response = @request.make
|
42
|
+
}.to_not raise_exception Paypal::InvalidRequest
|
43
|
+
|
44
|
+
response.raw_response.should_not be_nil
|
45
|
+
response.success?.should be_true
|
46
|
+
end
|
47
|
+
|
48
|
+
context "with stubbed response" do
|
49
|
+
before do
|
50
|
+
Paypal::DoDirectPaymentRequest.any_instance.stub(:make_request).and_return(Paypal::Response.new("TIMESTAMP=2012%2d02%2d16T04%3a59%3a39Z&CORRELATIONID=4b356d90312b7&ACK=Success&VERSION=76&BUILD=2571254&AMT=1%2e00&CURRENCYCODE=USD&AVSCODE=X&CVV2MATCH=M&TRANSACTIONID=9WU7637669251764V"))
|
51
|
+
end
|
52
|
+
|
53
|
+
before(:each) do
|
54
|
+
@response = @request.make
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should have a correlationid" do
|
58
|
+
@response[:correlation_id].should_not be_nil
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe :do_reference_transaction do
|
65
|
+
before do
|
66
|
+
@request = Paypal::PaymentsPro.do_reference_transaction
|
67
|
+
# @request.ip_address = "192.168.0.1"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should fail without enough params" do
|
71
|
+
expect {
|
72
|
+
@request.make
|
73
|
+
}.to raise_exception Paypal::InvalidRequest
|
74
|
+
end
|
75
|
+
|
76
|
+
context "with more params" do
|
77
|
+
before do
|
78
|
+
@request.reference_id = "9WU7637669251764V"
|
79
|
+
# @request.first_name = "mark"
|
80
|
+
# @request.last_name = "suster"
|
81
|
+
# @request.street = "12 thirteen lane"
|
82
|
+
# @request.city = "brooklyn"
|
83
|
+
# @request.state = "ny"
|
84
|
+
# @request.zip = "11211"
|
85
|
+
@request.amt = 1.00
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should formulate a valid request" do
|
89
|
+
@request.request_string.should_not be_nil
|
90
|
+
|
91
|
+
expect {
|
92
|
+
URI.parse(@request.request_string)
|
93
|
+
}.to_not raise_exception
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should make a valid request", :slow_paypal => true do
|
97
|
+
response = nil
|
98
|
+
expect {
|
99
|
+
response = @request.make
|
100
|
+
}.to_not raise_exception Paypal::InvalidRequest
|
101
|
+
|
102
|
+
response.raw_response.should_not be_nil
|
103
|
+
response.success?.should be_true
|
104
|
+
end
|
105
|
+
|
106
|
+
context "with stubbed response" do
|
107
|
+
before do
|
108
|
+
Paypal::DoReferenceTransactionRequest.any_instance.stub(:make_request).and_return(Paypal::Response.new("AVSCODE=X&CVV2MATCH=M&TIMESTAMP=2012%2d02%2d16T05%3a32%3a16Z&CORRELATIONID=276e70e08049c&ACK=Success&VERSION=84%2e00&BUILD=2571254&TRANSACTIONID=31R0686475644053G&AMT=1%2e00&CURRENCYCODE=USD"))
|
109
|
+
end
|
110
|
+
|
111
|
+
before(:each) do
|
112
|
+
@response = @request.make
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should have a correlationid" do
|
116
|
+
@response[:correlation_id].should_not be_nil
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paypal_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matt Handler
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-27 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: &70128187644320 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - =
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.2.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70128187644320
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70128187643520 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.6'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70128187643520
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec-mocks
|
38
|
+
requirement: &70128187642680 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '2.6'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70128187642680
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: &70128187642120 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - =
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.8.7
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70128187642120
|
58
|
+
description: alpha - currently covers part of payments pro and all of mass pay
|
59
|
+
email:
|
60
|
+
- matt.handler@gmail.com
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- .gitignore
|
66
|
+
- .rspec
|
67
|
+
- Gemfile
|
68
|
+
- README.markdown
|
69
|
+
- Rakefile
|
70
|
+
- init.rb
|
71
|
+
- lib/paypal_api.rb
|
72
|
+
- lib/paypal_api/apis/api.rb
|
73
|
+
- lib/paypal_api/apis/mass_pay.rb
|
74
|
+
- lib/paypal_api/apis/payments_pro.rb
|
75
|
+
- lib/paypal_api/support/parameter.rb
|
76
|
+
- lib/paypal_api/support/request.rb
|
77
|
+
- lib/paypal_api/support/response.rb
|
78
|
+
- lib/paypal_api/version.rb
|
79
|
+
- paypal_api.gemspec
|
80
|
+
- spec/spec_helper.rb
|
81
|
+
- spec/support/parameter_spec.rb
|
82
|
+
- spec/support/request_spec.rb
|
83
|
+
- spec/support/response_spec.rb
|
84
|
+
- spec/unit/api_spec.rb
|
85
|
+
- spec/unit/mass_pay_spec.rb
|
86
|
+
- spec/unit/payments_pro_spec.rb
|
87
|
+
homepage: https://github.com/matthandlersux/paypal_api
|
88
|
+
licenses: []
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project: paypal_api
|
107
|
+
rubygems_version: 1.8.10
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: an interface to paypals api
|
111
|
+
test_files:
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
- spec/support/parameter_spec.rb
|
114
|
+
- spec/support/request_spec.rb
|
115
|
+
- spec/support/response_spec.rb
|
116
|
+
- spec/unit/api_spec.rb
|
117
|
+
- spec/unit/mass_pay_spec.rb
|
118
|
+
- spec/unit/payments_pro_spec.rb
|