sinatra-paypal 0.3.0 → 0.3.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a60ac8cab5ae922c45d7c630945fff359fefbf6
4
- data.tar.gz: 47dca80829bd0bfa71148c9e4b90fa00144df985
3
+ metadata.gz: ea8ac7963161bd4eff32e3b3a8d36a8d7e62d6fa
4
+ data.tar.gz: 4d449cc884c1f07bc225fa9ba3697b0a3f26957c
5
5
  SHA512:
6
- metadata.gz: f6b8b5d328770f3e9ad58ac726d2ed1b8644081711ddc86d5500d02db545f43220128cdfc04396f2f47f090d072b483dd8c186a4890784cf77ea0109d349727c
7
- data.tar.gz: f7fde5572ccfd005187e8f780b9f84ffa4f324de2d3d22c26edf06c742d75914d2fb04dc1dcb1469ad8cedfc5685d872455951a0884701dc225d2e9e2e90852b
6
+ metadata.gz: 27b818480e7e132d83561c56f5999b75b53007922fee0879c73eeb86fc6f1c9222e60d68e4772538f0a41054eadd72e5aa505bc55124e2c0c4512143442387d5
7
+ data.tar.gz: a11548743fc6152d6789f467e528ae258ccbdbe3dd22a596cbbfe323d57684ddcd9f210973d957b3e085ec46c8302dbbb2e7e3e4ad450193310d7ce4f7c8b257
@@ -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 app._call_paypal_method(:repeated?, paypal_request)
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
- app._call_paypal_method(:validate!, paypal_request)
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
- app._call_paypal_method(:complete, paypal_request)
70
+ _call_paypal_method(:complete, paypal_request)
67
71
  end
68
72
 
69
- app._call_paypal_method(:finish, paypal_request)
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.class.send :define_method, _paypal_method_name(key), &block
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
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module Paypal
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
@@ -35,6 +35,10 @@ payment :repeated? do |p|
35
35
  end
36
36
  end
37
37
 
38
+ payment :complete do |p|
39
+ halt 500, 'rejection requested' if !p.custom_data.nil? && p.custom_data[:reject] == true
40
+ end
41
+
38
42
  get '/payment/form/empty' do
39
43
  return html_payment_form nil
40
44
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-paypal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Reed