elucid-adaptive_pay 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/MIT-LICENSE +20 -0
- data/README +186 -0
- data/Rakefile +39 -0
- data/VERSION +1 -0
- data/config/adaptive_pay.yml +19 -0
- data/elucid-adaptive_pay.gemspec +90 -0
- data/init.rb +1 -0
- data/install.rb +4 -0
- data/lib/adaptive_pay.rb +12 -0
- data/lib/adaptive_pay/abstract_payment_request.rb +44 -0
- data/lib/adaptive_pay/callback.rb +17 -0
- data/lib/adaptive_pay/cancel_preapproval_request.rb +16 -0
- data/lib/adaptive_pay/interface.rb +93 -0
- data/lib/adaptive_pay/parser.rb +43 -0
- data/lib/adaptive_pay/payment_request.rb +48 -0
- data/lib/adaptive_pay/preapproval_request.rb +24 -0
- data/lib/adaptive_pay/recipient.rb +17 -0
- data/lib/adaptive_pay/refund_request.rb +46 -0
- data/lib/adaptive_pay/request.rb +124 -0
- data/lib/adaptive_pay/response.rb +76 -0
- data/lib/adaptive_pay/sender.rb +13 -0
- data/spec/adaptive_pay/abstract_payment_request_spec.rb +41 -0
- data/spec/adaptive_pay/callback_spec.rb +17 -0
- data/spec/adaptive_pay/cancel_preapproval_request_spec.rb +22 -0
- data/spec/adaptive_pay/interface_spec.rb +184 -0
- data/spec/adaptive_pay/parser_spec.rb +47 -0
- data/spec/adaptive_pay/payment_request_spec.rb +53 -0
- data/spec/adaptive_pay/preapproval_request_spec.rb +9 -0
- data/spec/adaptive_pay/recipient_spec.rb +20 -0
- data/spec/adaptive_pay/refund_request_spec.rb +51 -0
- data/spec/adaptive_pay/request_spec.rb +178 -0
- data/spec/adaptive_pay/response_spec.rb +87 -0
- data/spec/adaptive_pay/sender_spec.rb +20 -0
- data/spec/fixtures/config/adaptive_pay.yml +16 -0
- data/spec/rails_mocks.rb +3 -0
- data/spec/spec_helper.rb +13 -0
- data/uninstall.rb +1 -0
- metadata +106 -0
@@ -0,0 +1,178 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'fakeweb'
|
3
|
+
|
4
|
+
describe AdaptivePay::Request do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
FakeWeb.allow_net_connect = false
|
8
|
+
end
|
9
|
+
|
10
|
+
after :each do
|
11
|
+
FakeWeb.allow_net_connect = true
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "self.attribute" do
|
15
|
+
|
16
|
+
it "should generate setter method" do
|
17
|
+
class MyKlass1 < AdaptivePay::Request
|
18
|
+
attribute "myAttrib"
|
19
|
+
end
|
20
|
+
|
21
|
+
obj = MyKlass1.new
|
22
|
+
obj.should respond_to(:my_attrib=)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should generate getter method" do
|
26
|
+
class MyKlass2 < AdaptivePay::Request
|
27
|
+
attribute "myAttrib"
|
28
|
+
end
|
29
|
+
|
30
|
+
obj = MyKlass2.new
|
31
|
+
obj.should respond_to(:my_attrib)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should allow setting and retrieving attribute" do
|
35
|
+
class MyKlass3 < AdaptivePay::Request
|
36
|
+
attribute "myAttrib"
|
37
|
+
end
|
38
|
+
|
39
|
+
obj = MyKlass3.new
|
40
|
+
obj.my_attrib = "test"
|
41
|
+
obj.my_attrib.should == "test"
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
it "should add attribute to list" do
|
46
|
+
class MyKlass4 < AdaptivePay::Request
|
47
|
+
attribute "myAttrib"
|
48
|
+
end
|
49
|
+
MyKlass4.attribute_names.should include("myAttrib")
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should build inheritable attributes" do
|
53
|
+
class ParentKlass < AdaptivePay::Request
|
54
|
+
attribute "myInheritableAttrib"
|
55
|
+
end
|
56
|
+
class ChildKlass < ParentKlass
|
57
|
+
attribute "myAttrib"
|
58
|
+
end
|
59
|
+
|
60
|
+
ChildKlass.attribute_names.should include("myInheritableAttrib")
|
61
|
+
obj = ChildKlass.new
|
62
|
+
obj.should respond_to(:my_inheritable_attrib=)
|
63
|
+
obj.should respond_to(:my_inheritable_attrib)
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
it "should map nested attributes to the toplevel" do
|
68
|
+
class MyKlass5 < AdaptivePay::Request
|
69
|
+
attribute "myGroup.myAttrib"
|
70
|
+
end
|
71
|
+
|
72
|
+
MyKlass5.attribute_names.should include("myGroup.myAttrib")
|
73
|
+
obj = MyKlass5.new
|
74
|
+
obj.should respond_to(:my_attrib=)
|
75
|
+
obj.should respond_to(:my_attrib)
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "initialize" do
|
81
|
+
|
82
|
+
it "should pass self to block if given" do
|
83
|
+
called = false
|
84
|
+
AdaptivePay::Request.new do |p|
|
85
|
+
called = true
|
86
|
+
p.should be_a(AdaptivePay::Request)
|
87
|
+
end
|
88
|
+
called.should be_true
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should set default attributes if present" do
|
92
|
+
class MyKlass6 < AdaptivePay::Request
|
93
|
+
attribute "myAttrib", :default => "value"
|
94
|
+
end
|
95
|
+
|
96
|
+
obj = MyKlass6.new
|
97
|
+
obj.my_attrib.should == "value"
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "perform" do
|
103
|
+
|
104
|
+
def mock_interface(options={})
|
105
|
+
mock(:interface, {:base_url => "https://somewhere.at.paypal.cc", :base_page_url => "https://deep.down_on.paypal.cc", :username => "username", :password => "password", :signature => "signature", :application_id => "application_id"}.merge(options))
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should send request to base_url + request specific endpoint" do
|
109
|
+
class MyKlass8 < AdaptivePay::Request
|
110
|
+
def self.endpoint
|
111
|
+
"my_endpoint"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
request = MyKlass8.new
|
116
|
+
FakeWeb.register_uri(:post, "https://somewhere.at.paypal.cc/my_endpoint", :body => "")
|
117
|
+
request.perform mock_interface
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should build Response from http response" do
|
121
|
+
class MyKlass9 < AdaptivePay::Request
|
122
|
+
def self.endpoint
|
123
|
+
"my_endpoint"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
request = MyKlass8.new
|
128
|
+
FakeWeb.register_uri(:post, "https://somewhere.at.paypal.cc/my_endpoint", :body => "{ actionType: 'PAY' }")
|
129
|
+
AdaptivePay::Response.should_receive(:new).with { |interface, type, resp| resp.body.should == "{ actionType: 'PAY' }" }
|
130
|
+
request.perform mock_interface
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "serialize" do
|
136
|
+
|
137
|
+
it "should build query string for attributes" do
|
138
|
+
class MyKlass10 < AdaptivePay::Request
|
139
|
+
attribute "nesting.testing"
|
140
|
+
attribute "topLevel"
|
141
|
+
end
|
142
|
+
|
143
|
+
obj = MyKlass10.new
|
144
|
+
obj.testing = "1234"
|
145
|
+
obj.top_level = true
|
146
|
+
decompose(obj.serialize).should == {
|
147
|
+
"nesting.testing" => "1234",
|
148
|
+
"topLevel" => "true"
|
149
|
+
}
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should format date attributes" do
|
153
|
+
class MyKlass11 < AdaptivePay::Request
|
154
|
+
attribute "date", :format => :date
|
155
|
+
end
|
156
|
+
|
157
|
+
obj = MyKlass11.new
|
158
|
+
obj.date = Date.new(2009, 12, 12)
|
159
|
+
decompose(obj.serialize).should == {
|
160
|
+
"date" => "2009-12-12"
|
161
|
+
}
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should escape attributes containing '&'" do
|
165
|
+
class MyClass12 < AdaptivePay::Request
|
166
|
+
attribute "foo"
|
167
|
+
end
|
168
|
+
|
169
|
+
obj = MyClass12.new
|
170
|
+
obj.foo = "b&r"
|
171
|
+
decompose(obj.serialize).should == {
|
172
|
+
"foo" => "b%26r"
|
173
|
+
}
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe AdaptivePay::Response do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@iface = mock(:iface, :base_page_url => "https://www.paypal.com")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should parse a successful response" do
|
10
|
+
body = "responseEnvelope.timestamp=2009-07-13T12%3A34%3A29.316-07%3A00&responseEnvelope.ack=Success&responseEnvelope.correlationId=d615a365bed61&responseEnvelope.build=DEV&payKey=AP-3TY011106S4428730&paymentExecStatus=CREATED"
|
11
|
+
response = AdaptivePay::Response.new @iface, :other, mock(:response, :body => body, :code => "200")
|
12
|
+
response.should be_success
|
13
|
+
response.read_attribute("responseEnvelope.timestamp").should == "2009-07-13T12:34:29.316-07:00"
|
14
|
+
response.read_attribute("responseEnvelope.ack").should == "Success"
|
15
|
+
response.read_attribute("responseEnvelope.correlationId").should == "d615a365bed61"
|
16
|
+
response.read_attribute("responseEnvelope.build").should == "DEV"
|
17
|
+
response.pay_key.should == "AP-3TY011106S4428730"
|
18
|
+
response.payment_exec_status.should == "CREATED"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should interpret a completed response as successful" do
|
22
|
+
body = "responseEnvelope.ack=Success"
|
23
|
+
response = AdaptivePay::Response.new @iface, :other, mock(:response, :body => body, :code => "200")
|
24
|
+
response.should be_success
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should interpret a http error as a non succesful response" do
|
28
|
+
response = AdaptivePay::Response.new @iface, :other, mock(:response, :body => "", :code => "500")
|
29
|
+
response.should_not be_success
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should interpret a paypal error as a non succesful response" do
|
33
|
+
body = "responseEnvelope.ack=Failure"
|
34
|
+
response = AdaptivePay::Response.new @iface, :other, mock(:response, :body => body, :code => "200")
|
35
|
+
response.should_not be_success
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should provide access to raw response" do
|
39
|
+
body = "responseEnvelope.ack=Success"
|
40
|
+
response = AdaptivePay::Response.new @iface, :other, mock(:response, :body => body, :code => "200")
|
41
|
+
response.should respond_to(:raw)
|
42
|
+
response.raw.should == body
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return nil for #read_attribute on missing attribute" do
|
46
|
+
body = "responseEnvelope.ack=Success"
|
47
|
+
response = AdaptivePay::Response.new @iface, :other, mock(:response, :body => body, :code => "200")
|
48
|
+
response.read_attribute("foo").should be_nil
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should return nil for #read_attribute on missing nested attribute" do
|
52
|
+
body = "responseEnvelope.ack=Success"
|
53
|
+
response = AdaptivePay::Response.new @iface, :other, mock(:response, :body => body, :code => "200")
|
54
|
+
response.read_attribute("foo.bar").should be_nil
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return nil for #errors on successful response" do
|
58
|
+
body = "responseEnvelope.ack=Success"
|
59
|
+
response = AdaptivePay::Response.new @iface, :other, mock(:response, :body => body, :code => "200")
|
60
|
+
response.should respond_to(:errors)
|
61
|
+
response.errors.should be_nil
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should provide access to response errors on failed resonse" do
|
65
|
+
body = "responseEnvelope.ack=Failure&error(0).errorId=569042&error(0).domain=PLATFORM&error(0).severity=Error"
|
66
|
+
response = AdaptivePay::Response.new @iface, :other, mock(:response, :body => body, :code => "200")
|
67
|
+
response.should respond_to(:errors)
|
68
|
+
response.errors.should == [{"errorId" => "569042", "severity" => "Error", "domain" => "PLATFORM"}]
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "payment_page_url" do
|
72
|
+
|
73
|
+
it "should build a payment_page_url for approval" do
|
74
|
+
body = "responseEnvelope.ack=Success&preapprovalKey=PA-3TY011106S4428730"
|
75
|
+
response = AdaptivePay::Response.new @iface, :preapproval, mock(:response, :body => body, :code => "200")
|
76
|
+
response.payment_page_url.should == "https://www.paypal.com/webscr?cmd=_ap-preapproval&preapprovalkey=PA-3TY011106S4428730"
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should build a payment_page_url for payment" do
|
80
|
+
body = "responseEnvelope.ack=Success&payKey=AP-3TY011106S4428730"
|
81
|
+
response = AdaptivePay::Response.new @iface, :payment, mock(:response, :body => body, :code => "200")
|
82
|
+
response.payment_page_url.should == "https://www.paypal.com/webscr?cmd=_ap-payment&paykey=AP-3TY011106S4428730"
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe AdaptivePay::Sender do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@sender = AdaptivePay::Sender.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "attributes" do
|
10
|
+
|
11
|
+
%w{email client_ip}.each do |attribute|
|
12
|
+
it "should have #{attribute} attribute" do
|
13
|
+
@sender.send("#{attribute}=", "test")
|
14
|
+
@sender.send(attribute).should == "test"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
development:
|
2
|
+
environment: "sandbox"
|
3
|
+
username: "my_username"
|
4
|
+
password: "my_password"
|
5
|
+
signature: "my_signature"
|
6
|
+
application_id: "my_application_id"
|
7
|
+
|
8
|
+
test:
|
9
|
+
retain_requests_for_test: true
|
10
|
+
|
11
|
+
production:
|
12
|
+
environment: "production"
|
13
|
+
username: "my_production_username"
|
14
|
+
password: "my_production_password"
|
15
|
+
signature: "my_production_signature"
|
16
|
+
application_id: "my_production_application_id"
|
data/spec/rails_mocks.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "active_support"
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + "/../lib/adaptive_pay")
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + "/rails_mocks")
|
5
|
+
|
6
|
+
def decompose(qstr)
|
7
|
+
result = {}
|
8
|
+
qstr.split("&").each do |f|
|
9
|
+
k, v = f.split("=")
|
10
|
+
result[k] = v
|
11
|
+
end
|
12
|
+
result
|
13
|
+
end
|
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: elucid-adaptive_pay
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Frederik Fix
|
8
|
+
- Justin Giancola
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2010-08-05 00:00:00 -04:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Wrapper around the Paypal Adaptive Payments API
|
18
|
+
email: elucid@gmail.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- README
|
25
|
+
files:
|
26
|
+
- .gitignore
|
27
|
+
- MIT-LICENSE
|
28
|
+
- README
|
29
|
+
- Rakefile
|
30
|
+
- VERSION
|
31
|
+
- config/adaptive_pay.yml
|
32
|
+
- elucid-adaptive_pay.gemspec
|
33
|
+
- init.rb
|
34
|
+
- install.rb
|
35
|
+
- lib/adaptive_pay.rb
|
36
|
+
- lib/adaptive_pay/abstract_payment_request.rb
|
37
|
+
- lib/adaptive_pay/callback.rb
|
38
|
+
- lib/adaptive_pay/cancel_preapproval_request.rb
|
39
|
+
- lib/adaptive_pay/interface.rb
|
40
|
+
- lib/adaptive_pay/parser.rb
|
41
|
+
- lib/adaptive_pay/payment_request.rb
|
42
|
+
- lib/adaptive_pay/preapproval_request.rb
|
43
|
+
- lib/adaptive_pay/recipient.rb
|
44
|
+
- lib/adaptive_pay/refund_request.rb
|
45
|
+
- lib/adaptive_pay/request.rb
|
46
|
+
- lib/adaptive_pay/response.rb
|
47
|
+
- lib/adaptive_pay/sender.rb
|
48
|
+
- spec/adaptive_pay/abstract_payment_request_spec.rb
|
49
|
+
- spec/adaptive_pay/callback_spec.rb
|
50
|
+
- spec/adaptive_pay/cancel_preapproval_request_spec.rb
|
51
|
+
- spec/adaptive_pay/interface_spec.rb
|
52
|
+
- spec/adaptive_pay/parser_spec.rb
|
53
|
+
- spec/adaptive_pay/payment_request_spec.rb
|
54
|
+
- spec/adaptive_pay/preapproval_request_spec.rb
|
55
|
+
- spec/adaptive_pay/recipient_spec.rb
|
56
|
+
- spec/adaptive_pay/refund_request_spec.rb
|
57
|
+
- spec/adaptive_pay/request_spec.rb
|
58
|
+
- spec/adaptive_pay/response_spec.rb
|
59
|
+
- spec/adaptive_pay/sender_spec.rb
|
60
|
+
- spec/fixtures/config/adaptive_pay.yml
|
61
|
+
- spec/rails_mocks.rb
|
62
|
+
- spec/spec_helper.rb
|
63
|
+
- uninstall.rb
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: http://github.com/elucid/adaptive_pay
|
66
|
+
licenses: []
|
67
|
+
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options:
|
70
|
+
- --charset=UTF-8
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
version:
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.3.5
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Wrapper around the Paypal Adaptive Payments API
|
92
|
+
test_files:
|
93
|
+
- spec/adaptive_pay/abstract_payment_request_spec.rb
|
94
|
+
- spec/adaptive_pay/callback_spec.rb
|
95
|
+
- spec/adaptive_pay/cancel_preapproval_request_spec.rb
|
96
|
+
- spec/adaptive_pay/interface_spec.rb
|
97
|
+
- spec/adaptive_pay/parser_spec.rb
|
98
|
+
- spec/adaptive_pay/payment_request_spec.rb
|
99
|
+
- spec/adaptive_pay/preapproval_request_spec.rb
|
100
|
+
- spec/adaptive_pay/recipient_spec.rb
|
101
|
+
- spec/adaptive_pay/refund_request_spec.rb
|
102
|
+
- spec/adaptive_pay/request_spec.rb
|
103
|
+
- spec/adaptive_pay/response_spec.rb
|
104
|
+
- spec/adaptive_pay/sender_spec.rb
|
105
|
+
- spec/rails_mocks.rb
|
106
|
+
- spec/spec_helper.rb
|