jonathantron-paypal 3.0.0pre → 3.0.0pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/paypal/notification.rb +29 -29
- data/lib/paypal/version.rb +1 -1
- metadata +3 -3
data/lib/paypal/notification.rb
CHANGED
@@ -3,8 +3,8 @@ require 'net/http'
|
|
3
3
|
|
4
4
|
module Paypal
|
5
5
|
class NoDataError < StandardError; end
|
6
|
-
|
7
|
-
# Parser and handler for incoming Instant payment notifications from paypal.
|
6
|
+
|
7
|
+
# Parser and handler for incoming Instant payment notifications from paypal.
|
8
8
|
# The Example shows a typical handler in a rails application. Note that this
|
9
9
|
# is an example, please read the Paypal API documentation for all the details
|
10
10
|
# on creating a safe payment controller.
|
@@ -42,33 +42,33 @@ module Paypal
|
|
42
42
|
# end
|
43
43
|
#
|
44
44
|
# Example (Rails)
|
45
|
-
#
|
45
|
+
#
|
46
46
|
# class BackendController < ApplicationController
|
47
|
-
#
|
47
|
+
#
|
48
48
|
# def paypal_ipn
|
49
49
|
# notify = Paypal::Notification.new(request.raw_post)
|
50
|
-
#
|
50
|
+
#
|
51
51
|
# order = Order.find(notify.item_id)
|
52
|
-
#
|
53
|
-
# if notify.acknowledge
|
52
|
+
#
|
53
|
+
# if notify.acknowledge
|
54
54
|
# begin
|
55
|
-
#
|
55
|
+
#
|
56
56
|
# if notify.complete? and order.total == notify.amount and notify.business == 'sales@myshop.com'
|
57
|
-
# order.status = 'success'
|
58
|
-
#
|
57
|
+
# order.status = 'success'
|
58
|
+
#
|
59
59
|
# shop.ship(order)
|
60
60
|
# else
|
61
61
|
# logger.error("Failed to verify Paypal's notification, please investigate")
|
62
62
|
# end
|
63
|
-
#
|
63
|
+
#
|
64
64
|
# rescue => e
|
65
|
-
# order.status = 'failed'
|
65
|
+
# order.status = 'failed'
|
66
66
|
# raise
|
67
67
|
# ensure
|
68
68
|
# order.save
|
69
69
|
# end
|
70
70
|
# end
|
71
|
-
#
|
71
|
+
#
|
72
72
|
# render :nothing
|
73
73
|
# end
|
74
74
|
# end
|
@@ -76,9 +76,9 @@ module Paypal
|
|
76
76
|
attr_accessor :params
|
77
77
|
attr_accessor :raw
|
78
78
|
|
79
|
-
# Creates a new paypal object. Pass the raw html you got from paypal in.
|
79
|
+
# Creates a new paypal object. Pass the raw html you got from paypal in.
|
80
80
|
# In a rails application this looks something like this
|
81
|
-
#
|
81
|
+
#
|
82
82
|
# def paypal_ipn
|
83
83
|
# paypal = Paypal::Notification.new(request.raw_post)
|
84
84
|
# ...
|
@@ -133,56 +133,56 @@ module Paypal
|
|
133
133
|
status == :Voided
|
134
134
|
end
|
135
135
|
|
136
|
-
# Acknowledge the transaction to paypal. This method has to be called after a new
|
137
|
-
# ipn arrives. Paypal will verify that all the information we received are correct and will return a
|
138
|
-
# ok or a fail.
|
139
|
-
#
|
136
|
+
# Acknowledge the transaction to paypal. This method has to be called after a new
|
137
|
+
# ipn arrives. Paypal will verify that all the information we received are correct and will return a
|
138
|
+
# ok or a fail.
|
139
|
+
#
|
140
140
|
# Example:
|
141
|
-
#
|
141
|
+
#
|
142
142
|
# def paypal_ipn
|
143
143
|
# notify = PaypalNotification.new(request.raw_post)
|
144
144
|
#
|
145
|
-
# if notify.acknowledge
|
145
|
+
# if notify.acknowledge
|
146
146
|
# ... process order ... if notify.complete?
|
147
147
|
# else
|
148
148
|
# ... log possible hacking attempt ...
|
149
149
|
# end
|
150
150
|
def acknowledge
|
151
151
|
payload = raw
|
152
|
-
|
152
|
+
|
153
153
|
uri = URI.parse(Paypal::Config.ipn_url)
|
154
154
|
request = Net::HTTP::Post.new(Paypal::Config.ipn_validation_path)
|
155
155
|
request['Content-Length'] = "#{payload.size}"
|
156
156
|
request['User-Agent'] = "paypal ruby -- http://github.com/JonathanTron/paypal"
|
157
|
-
|
157
|
+
|
158
158
|
http = Net::HTTP.new(uri.host, uri.port)
|
159
159
|
|
160
160
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless @ssl_strict
|
161
161
|
http.use_ssl = true
|
162
162
|
|
163
163
|
request = http.request(request, payload)
|
164
|
-
|
164
|
+
|
165
165
|
raise StandardError.new("Faulty paypal result: #{request.body}") unless ["VERIFIED", "INVALID"].include?(request.body)
|
166
|
-
|
166
|
+
|
167
167
|
request.body == "VERIFIED"
|
168
168
|
end
|
169
|
-
|
169
|
+
|
170
170
|
def method_missing(method, *args)
|
171
171
|
params[method.to_s] || super
|
172
172
|
end
|
173
|
-
|
173
|
+
|
174
174
|
private
|
175
175
|
|
176
176
|
def status
|
177
177
|
@status ||= (params['payment_status'] ? params['payment_status'].to_sym : nil)
|
178
178
|
end
|
179
|
-
|
179
|
+
|
180
180
|
# Take the posted data and move the relevant data into a hash
|
181
181
|
def parse(post)
|
182
182
|
@raw = post
|
183
183
|
self.params = Rack::Utils.parse_query(post)
|
184
184
|
# Rack allows duplicate keys in queries, we need to use only the last value here
|
185
|
-
self.params.each{|k,v| self.params[k] = v.last if v.
|
185
|
+
self.params.each{|k,v| self.params[k] = v.last if v.is_a?(Array)}
|
186
186
|
end
|
187
187
|
end
|
188
188
|
end
|
data/lib/paypal/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 3
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 3.0.
|
8
|
+
- 0pre1
|
9
|
+
version: 3.0.0pre1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jonathan Tron
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-04-
|
19
|
+
date: 2010-04-11 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|