ljoseppi-paypal 3.0.0pre6

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,148 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Paypal::Notification do
4
+ before do
5
+ Paypal::Config.mode = :sandbox
6
+ end
7
+
8
+ def valid_http_raw_data
9
+ "mc_gross=500.00&address_status=confirmed&payer_id=EVMXCLDZJV77Q&tax=0.00&address_street=164+Waverley+Street&payment_date=15%3A23%3A54+Apr+15%2C+2005+PDT&payment_status=Completed&address_zip=K2P0V6&first_name=Tobias&mc_fee=15.05&address_country_code=CA&address_name=Tobias+Luetke&notify_version=1.7&custom=cusdata&payer_status=unverified&business=tobi%40leetsoft.com&address_country=Canada&address_city=Ottawa&quantity=1&payer_email=tobi%40snowdevil.ca&verify_sign=AEt48rmhLYtkZ9VzOGAtwL7rTGxUAoLNsuf7UewmX7UGvcyC3wfUmzJP&txn_id=6G996328CK404320L&payment_type=instant&last_name=Luetke&address_state=Ontario&receiver_email=tobi%40leetsoft.com&payment_fee=&receiver_id=UQ8PDYXJZQD9Y&txn_type=web_accept&item_name=Store+Purchase&mc_currency=CAD&item_number=&test_ipn=1&payment_gross=&shipping=0.00&invoice=myinvoice&pending_reason=mypending_reason&reason_code=myreason_code&memo=mymemo&payment_type=mypayment_type&exchange_rate=myexchange_rate"
10
+ end
11
+
12
+ def self.valid_parsed_raw_data
13
+ {"payment_gross"=>"", "receiver_id"=>"UQ8PDYXJZQD9Y", "payer_email"=>"tobi@snowdevil.ca", "address_city"=>"Ottawa", "address_country"=>"Canada", "business"=>"tobi@leetsoft.com", "address_name"=>"Tobias Luetke", "payment_status"=>"Completed", "tax"=>"0.00", "reason_code"=>"myreason_code", "receiver_email"=>"tobi@leetsoft.com", "invoice"=>"myinvoice", "verify_sign"=>"AEt48rmhLYtkZ9VzOGAtwL7rTGxUAoLNsuf7UewmX7UGvcyC3wfUmzJP", "address_street"=>"164 Waverley Street", "memo"=>"mymemo", "mc_currency"=>"CAD", "txn_type"=>"web_accept", "quantity"=>"1", "address_zip"=>"K2P0V6", "pending_reason"=>"mypending_reason", "item_name"=>"Store Purchase", "txn_id"=>"6G996328CK404320L", "address_country_code"=>"CA", "payment_fee"=>"", "address_state"=>"Ontario", "payer_status"=>"unverified", "notify_version"=>"1.7", "shipping"=>"0.00", "mc_fee"=>"15.05", "payment_date"=>"15:23:54 Apr 15, 2005 PDT", "address_status"=>"confirmed", "test_ipn"=>"1", "payment_type"=>"mypayment_type", "first_name"=>"Tobias", "last_name"=>"Luetke", "payer_id"=>"EVMXCLDZJV77Q", "mc_gross"=>"500.00", "exchange_rate"=>"myexchange_rate", "item_number"=>"", "custom"=>"cusdata"}
14
+ end
15
+
16
+ describe "without data" do
17
+ it "should raise Paypal::NoDataError" do
18
+ lambda {
19
+ Paypal::Notification.new(nil)
20
+ }.should raise_error(Paypal::NoDataError)
21
+ end
22
+ end
23
+
24
+ describe "with valid raw data" do
25
+ before do
26
+ @notification = Paypal::Notification.new(valid_http_raw_data)
27
+ end
28
+
29
+ it "should store raw data" do
30
+ @notification.raw.should eql(valid_http_raw_data)
31
+ end
32
+
33
+ describe "#params" do
34
+ it "should not be empty" do
35
+ @notification.params.should_not be_empty
36
+ end
37
+
38
+ valid_parsed_raw_data.each do |key, value|
39
+ it "should have #{key}=#{value}" do
40
+ @notification.params[key].should eql(value)
41
+ end
42
+ end
43
+
44
+ it "should have unescaped values" do
45
+ @notification.params["payment_date"].should eql("15:23:54 Apr 15, 2005 PDT")
46
+ end
47
+
48
+ it "should include only the last value for duplicate key" do
49
+ @notification.params["payment_type"].should eql("mypayment_type")
50
+ end
51
+ end
52
+
53
+ it "should define method to access each query params" do
54
+ self.class.valid_parsed_raw_data.each do |key, _|
55
+ lambda {
56
+ @notification.send(key.to_sym)
57
+ }.should_not raise_error
58
+ end
59
+ end
60
+
61
+ ["Canceled_Reversal",
62
+ "Completed",
63
+ "Denied",
64
+ "Expired",
65
+ "Failed",
66
+ "Pending",
67
+ "Processed",
68
+ "Refunded",
69
+ "Reversed",
70
+ "Voided"].each do |status|
71
+ describe "when transaction payment_status = '#{status}'" do
72
+ it "should be #{status.downcase}" do
73
+ old_status, @notification.params["payment_status"] = @notification.params["payment_status"], status
74
+
75
+ @notification.send(:"#{status.downcase}?").should be_true
76
+
77
+ @notification.params["payment_status"] = old_status
78
+ end
79
+ end
80
+ end
81
+
82
+ describe "#acknowledge" do
83
+ before do
84
+ @paypal_validation_url = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_notify-validate"
85
+ end
86
+
87
+ it "should send a post request to Paypal at #{@paypal_validation_url}" do
88
+ FakeWeb.register_uri(:post, @paypal_validation_url, :body => 'VERIFIED')
89
+
90
+ lambda { @notification.acknowledge }.should_not raise_error(FakeWeb::NetConnectNotAllowedError)
91
+
92
+ FakeWeb.clean_registry
93
+ end
94
+
95
+ describe "when Paypal response is VERIFIED" do
96
+ before do
97
+ FakeWeb.register_uri(:post, @paypal_validation_url, :body => 'VERIFIED')
98
+ end
99
+
100
+ it "should return true" do
101
+ @notification.acknowledge.should be(true)
102
+ end
103
+
104
+ after do
105
+ FakeWeb.clean_registry
106
+ end
107
+ end
108
+
109
+ describe "when Paypal response is INVALID" do
110
+ before do
111
+ FakeWeb.register_uri(:post, @paypal_validation_url, :body => 'INVALID')
112
+ end
113
+
114
+ it "should return false" do
115
+ @notification.acknowledge.should be(false)
116
+ end
117
+
118
+ after do
119
+ FakeWeb.clean_registry
120
+ end
121
+ end
122
+
123
+ describe "when Paypal response is not a recognize value" do
124
+ before do
125
+ FakeWeb.register_uri(:post, @paypal_validation_url, :body => 'BAD_VALUE')
126
+ end
127
+
128
+ it "should raise StandardError" do
129
+ lambda {
130
+ @notification.acknowledge
131
+ }.should raise_error(StandardError)
132
+ end
133
+
134
+ it "should include body response in StandardError" do
135
+ begin
136
+ @notification.acknowledge
137
+ rescue StandardError => e
138
+ e.message.should =~ /BAD_VALUE/
139
+ end
140
+ end
141
+
142
+ after do
143
+ FakeWeb.clean_registry
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,35 @@
1
+ require "rubygems"
2
+ require "bundler"
3
+ Bundler.setup
4
+
5
+ require "paypal"
6
+ require "fakeweb"
7
+ require "nokogiri"
8
+ require "rspec"
9
+
10
+ # Do not allow connection to non registered URLs, so we can catch if specifics were called
11
+ FakeWeb.allow_net_connect = false
12
+
13
+ RSpec::Matchers.define :have_css do |css|
14
+ match do |text|
15
+ html = Nokogiri::HTML(text)
16
+ !html.css(css).empty?
17
+ end
18
+
19
+ failure_message_for_should do |text|
20
+ "expected to find css expression #{css} in:\n#{text}"
21
+ end
22
+
23
+ failure_message_for_should_not do |text|
24
+ "expected not to find css expression #{css} in:\n#{text}"
25
+ end
26
+
27
+ description do
28
+ "have css in #{expected}"
29
+ end
30
+ end
31
+
32
+ RSpec.configure do |c|
33
+ c.mock_framework = :rspec
34
+ c.color_enabled = true
35
+ end
metadata ADDED
@@ -0,0 +1,201 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ljoseppi-paypal
3
+ version: !ruby/object:Gem::Version
4
+ hash: -223651643
5
+ prerelease: 5
6
+ segments:
7
+ - 3
8
+ - 0
9
+ - 0
10
+ - pre
11
+ - 6
12
+ version: 3.0.0pre6
13
+ platform: ruby
14
+ authors:
15
+ - Lairton Borges
16
+ - Jonathan TRON
17
+ - Joseph HALTER
18
+ - Tobias LUETKE
19
+ autorequire:
20
+ bindir: bin
21
+ cert_chain: []
22
+
23
+ date: 2012-03-06 00:00:00 Z
24
+ dependencies:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rack
27
+ prerelease: false
28
+ requirement: &id001 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ hash: 23
34
+ segments:
35
+ - 1
36
+ - 0
37
+ - 0
38
+ version: 1.0.0
39
+ type: :runtime
40
+ version_requirements: *id001
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ prerelease: false
44
+ requirement: &id002 !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ hash: 23
50
+ segments:
51
+ - 2
52
+ - 6
53
+ - 0
54
+ version: 2.6.0
55
+ type: :development
56
+ version_requirements: *id002
57
+ - !ruby/object:Gem::Dependency
58
+ name: rcov
59
+ prerelease: false
60
+ requirement: &id003 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ hash: 43
66
+ segments:
67
+ - 0
68
+ - 9
69
+ - 8
70
+ version: 0.9.8
71
+ type: :development
72
+ version_requirements: *id003
73
+ - !ruby/object:Gem::Dependency
74
+ name: nokogiri
75
+ prerelease: false
76
+ requirement: &id004 !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ type: :development
86
+ version_requirements: *id004
87
+ - !ruby/object:Gem::Dependency
88
+ name: bluecloth
89
+ prerelease: false
90
+ requirement: &id005 !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ type: :development
100
+ version_requirements: *id005
101
+ - !ruby/object:Gem::Dependency
102
+ name: yard
103
+ prerelease: false
104
+ requirement: &id006 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ type: :development
114
+ version_requirements: *id006
115
+ - !ruby/object:Gem::Dependency
116
+ name: fakeweb
117
+ prerelease: false
118
+ requirement: &id007 !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ hash: 3
124
+ segments:
125
+ - 0
126
+ version: "0"
127
+ type: :development
128
+ version_requirements: *id007
129
+ description: Paypal Express Integration
130
+ email: ljoseppi@gmail.com
131
+ executables: []
132
+
133
+ extensions: []
134
+
135
+ extra_rdoc_files:
136
+ - LICENSE
137
+ - README.md
138
+ files:
139
+ - .document
140
+ - .gitignore
141
+ - CHANGELOG.md
142
+ - Gemfile
143
+ - Gemfile.lock
144
+ - LICENSE
145
+ - README.md
146
+ - Rakefile
147
+ - lib/paypal.rb
148
+ - lib/paypal/certs/paypal_sandbox.pem
149
+ - lib/paypal/config.rb
150
+ - lib/paypal/helpers/common.rb
151
+ - lib/paypal/helpers/rails.rb
152
+ - lib/paypal/notification.rb
153
+ - lib/paypal/rails.rb
154
+ - lib/paypal/version.rb
155
+ - misc/PayPal - Instant Payment Notification - Technical Overview.pdf
156
+ - misc/multiruby.sh
157
+ - misc/paypal.psd
158
+ - paypal.gemspec
159
+ - spec/config_spec.rb
160
+ - spec/fixtures/business_cert.pem
161
+ - spec/fixtures/business_key.pem
162
+ - spec/helpers/common_spec.rb
163
+ - spec/notification_spec.rb
164
+ - spec/spec_helper.rb
165
+ homepage: https://github.com/ljoseppi/paypal
166
+ licenses: []
167
+
168
+ post_install_message:
169
+ rdoc_options:
170
+ - --charset=UTF-8
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ none: false
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ hash: 3
179
+ segments:
180
+ - 0
181
+ version: "0"
182
+ required_rubygems_version: !ruby/object:Gem::Requirement
183
+ none: false
184
+ requirements:
185
+ - - ">"
186
+ - !ruby/object:Gem::Version
187
+ hash: 25
188
+ segments:
189
+ - 1
190
+ - 3
191
+ - 1
192
+ version: 1.3.1
193
+ requirements: []
194
+
195
+ rubyforge_project:
196
+ rubygems_version: 1.8.10
197
+ signing_key:
198
+ specification_version: 3
199
+ summary: Integrate Paypal Express
200
+ test_files: []
201
+