adaptive_pay 0.1.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.
@@ -0,0 +1,166 @@
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
+ end
165
+
166
+ end
@@ -0,0 +1,54 @@
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
+ describe "payment_page_url" do
39
+
40
+ it "should build a payment_page_url for approval" do
41
+ body = "responseEnvelope.ack=Success&preapprovalKey=PA-3TY011106S4428730"
42
+ response = AdaptivePay::Response.new @iface, :preapproval, mock(:response, :body => body, :code => "200")
43
+ response.payment_page_url.should == "https://www.paypal.com/webscr?cmd=_ap-preapproval&preapprovalkey=PA-3TY011106S4428730"
44
+ end
45
+
46
+ it "should build a payment_page_url for payment" do
47
+ body = "responseEnvelope.ack=Success&payKey=AP-3TY011106S4428730"
48
+ response = AdaptivePay::Response.new @iface, :payment, mock(:response, :body => body, :code => "200")
49
+ response.payment_page_url.should == "https://www.paypal.com/webscr?cmd=_ap-payment&paykey=AP-3TY011106S4428730"
50
+ end
51
+
52
+ end
53
+
54
+ 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"
@@ -0,0 +1,3 @@
1
+ class Rails
2
+
3
+ end
@@ -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,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: adaptive_pay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Frederik Fix
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-15 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Wrapper around the Paypal Adaptive Payments API
17
+ email: ich@derfred.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ files:
25
+ - MIT-LICENSE
26
+ - README
27
+ - Rakefile
28
+ - VERSION
29
+ - config/adaptive_pay.yml
30
+ - init.rb
31
+ - install.rb
32
+ - lib/adaptive_pay.rb
33
+ - lib/adaptive_pay/abstract_payment_request.rb
34
+ - lib/adaptive_pay/callback.rb
35
+ - lib/adaptive_pay/cancel_preapproval_request.rb
36
+ - lib/adaptive_pay/interface.rb
37
+ - lib/adaptive_pay/payment_request.rb
38
+ - lib/adaptive_pay/preapproval_request.rb
39
+ - lib/adaptive_pay/recipient.rb
40
+ - lib/adaptive_pay/refund_request.rb
41
+ - lib/adaptive_pay/request.rb
42
+ - lib/adaptive_pay/response.rb
43
+ - lib/adaptive_pay/sender.rb
44
+ - spec/adaptive_pay/abstract_payment_request_spec.rb
45
+ - spec/adaptive_pay/callback_spec.rb
46
+ - spec/adaptive_pay/cancel_preapproval_request_spec.rb
47
+ - spec/adaptive_pay/interface_spec.rb
48
+ - spec/adaptive_pay/payment_request_spec.rb
49
+ - spec/adaptive_pay/preapproval_request_spec.rb
50
+ - spec/adaptive_pay/recipient_spec.rb
51
+ - spec/adaptive_pay/refund_request_spec.rb
52
+ - spec/adaptive_pay/request_spec.rb
53
+ - spec/adaptive_pay/response_spec.rb
54
+ - spec/adaptive_pay/sender_spec.rb
55
+ - spec/fixtures/config/adaptive_pay.yml
56
+ - spec/rails_mocks.rb
57
+ - spec/spec_helper.rb
58
+ - uninstall.rb
59
+ has_rdoc: true
60
+ homepage: http://github.com/derfred/adaptive_pay
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --charset=UTF-8
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ version:
80
+ requirements: []
81
+
82
+ rubyforge_project:
83
+ rubygems_version: 1.3.5
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Wrapper around the Paypal Adaptive Payments API
87
+ test_files:
88
+ - spec/adaptive_pay/abstract_payment_request_spec.rb
89
+ - spec/adaptive_pay/callback_spec.rb
90
+ - spec/adaptive_pay/cancel_preapproval_request_spec.rb
91
+ - spec/adaptive_pay/interface_spec.rb
92
+ - spec/adaptive_pay/payment_request_spec.rb
93
+ - spec/adaptive_pay/preapproval_request_spec.rb
94
+ - spec/adaptive_pay/recipient_spec.rb
95
+ - spec/adaptive_pay/refund_request_spec.rb
96
+ - spec/adaptive_pay/request_spec.rb
97
+ - spec/adaptive_pay/response_spec.rb
98
+ - spec/adaptive_pay/sender_spec.rb
99
+ - spec/rails_mocks.rb
100
+ - spec/spec_helper.rb