sinatra-paypal 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sinatra/paypal.rb +9 -9
- data/lib/sinatra/paypal/version.rb +1 -1
- data/test/app.rb +4 -0
- data/test/paypal_test.rb +9 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea8ac7963161bd4eff32e3b3a8d36a8d7e62d6fa
|
4
|
+
data.tar.gz: 4d449cc884c1f07bc225fa9ba3697b0a3f26957c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27b818480e7e132d83561c56f5999b75b53007922fee0879c73eeb86fc6f1c9222e60d68e4772538f0a41054eadd72e5aa505bc55124e2c0c4512143442387d5
|
7
|
+
data.tar.gz: a11548743fc6152d6789f467e528ae258ccbdbe3dd22a596cbbfe323d57684ddcd9f210973d957b3e085ec46c8302dbbb2e7e3e4ad450193310d7ce4f7c8b257
|
data/lib/sinatra/paypal.rb
CHANGED
@@ -29,6 +29,10 @@ module PayPal
|
|
29
29
|
:item => item
|
30
30
|
}
|
31
31
|
end
|
32
|
+
|
33
|
+
def _call_paypal_method(key, paypal_request)
|
34
|
+
self.send self.class._paypal_method_name(key), paypal_request
|
35
|
+
end
|
32
36
|
end
|
33
37
|
|
34
38
|
def self.registered(app)
|
@@ -52,21 +56,21 @@ module PayPal
|
|
52
56
|
end
|
53
57
|
|
54
58
|
# check transaction log to make sure this not a replay attack
|
55
|
-
if
|
59
|
+
if _call_paypal_method(:repeated?, paypal_request)
|
56
60
|
# we also want to return 200, because if it is paypal sending this, it will send
|
57
61
|
# it again and again until it gets a 200 back
|
58
62
|
halt 200, 'already processed'
|
59
63
|
end
|
60
64
|
|
61
|
-
|
65
|
+
_call_paypal_method(:validate!, paypal_request)
|
62
66
|
|
63
67
|
# check that the payment is complete. we still return 200 if not, but
|
64
68
|
# we don't need to do anymore processing (except for marking it as accountable, if it is)
|
65
69
|
if paypal_request.complete?
|
66
|
-
|
70
|
+
_call_paypal_method(:complete, paypal_request)
|
67
71
|
end
|
68
72
|
|
69
|
-
|
73
|
+
_call_paypal_method(:finish, paypal_request)
|
70
74
|
|
71
75
|
return 200
|
72
76
|
end
|
@@ -93,17 +97,13 @@ module PayPal
|
|
93
97
|
end
|
94
98
|
|
95
99
|
def _paypal_register_callback(key, &block)
|
96
|
-
self.
|
100
|
+
self.send :define_method, _paypal_method_name(key), &block
|
97
101
|
end
|
98
102
|
|
99
103
|
def _paypal_valid_blocks
|
100
104
|
[:complete, :finish, :validate!, :repeated?]
|
101
105
|
end
|
102
106
|
|
103
|
-
def _call_paypal_method(key, paypal_request)
|
104
|
-
self.send _paypal_method_name(key), paypal_request
|
105
|
-
end
|
106
|
-
|
107
107
|
def _paypal_method_name(key)
|
108
108
|
"payment_event_#{key}".to_sym
|
109
109
|
end
|
data/test/app.rb
CHANGED
data/test/paypal_test.rb
CHANGED
@@ -110,6 +110,15 @@ class RedditStreamTest < Test::Unit::TestCase
|
|
110
110
|
assert last_response.ok?, page_error("Payment not accepted")
|
111
111
|
end
|
112
112
|
|
113
|
+
def test_payment_rejected_by_halt
|
114
|
+
data = standard_payment_data
|
115
|
+
data[:custom] = {:username => data[:custom], :reject => true}.to_json
|
116
|
+
|
117
|
+
post '/payment/validate', data
|
118
|
+
assert !last_response.ok?, page_error("Payment should have been rejected")
|
119
|
+
assert last_response.body.include?('requested'), page_error("Incorrect error message")
|
120
|
+
end
|
121
|
+
|
113
122
|
def test_payment_accepted
|
114
123
|
data = standard_payment_data
|
115
124
|
post '/payment/validate', data
|