stateless-systems-paypal 2.1.3
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.
- data/MIT-LICENSE +22 -0
- data/README +151 -0
- data/Rakefile +126 -0
- data/init.rb +29 -0
- data/lib/helper.rb +315 -0
- data/lib/notification.rb +271 -0
- data/lib/paypal.rb +31 -0
- data/misc/PayPal - Instant Payment Notification - Technical Overview.pdf +0 -0
- data/misc/paypal.psd +0 -0
- data/test/helper_test.rb +197 -0
- data/test/mocks/http_mock.rb +47 -0
- data/test/mocks/method_mock.rb +33 -0
- data/test/notification_test.rb +99 -0
- data/test/remote/remote_test.rb +16 -0
- data/test/sample.ipn.response.txt +1 -0
- metadata +78 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
module Net
|
2
|
+
remove_const "HTTP"
|
3
|
+
|
4
|
+
class Response
|
5
|
+
def initialize(result)
|
6
|
+
@result = result
|
7
|
+
end
|
8
|
+
|
9
|
+
def body
|
10
|
+
@result
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Request < Struct.new(:host, :port, :query, :post_data)
|
15
|
+
|
16
|
+
cattr_accessor :fail
|
17
|
+
@@fail = false
|
18
|
+
|
19
|
+
def post(query, post)
|
20
|
+
self.query = query
|
21
|
+
self.post_data = post
|
22
|
+
Response.new(self.class.fail ? "INVALID": "VERIFIED")
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
class Net::HTTP
|
28
|
+
|
29
|
+
|
30
|
+
def self.start(host, port)
|
31
|
+
request = Request.new
|
32
|
+
request.host = host
|
33
|
+
request.port = port
|
34
|
+
|
35
|
+
@packages ||= []
|
36
|
+
@packages << request
|
37
|
+
|
38
|
+
yield request
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.packages
|
42
|
+
@packages
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class Module
|
2
|
+
def mock_methods(mock_methods)
|
3
|
+
raise "mock methods needs a block" unless block_given?
|
4
|
+
|
5
|
+
original = self
|
6
|
+
namespace = original.name.split("::")
|
7
|
+
class_name = namespace.last
|
8
|
+
|
9
|
+
mod = namespace[0..-2].inject(Object) { |mod, part| mod.const_get(part) }
|
10
|
+
|
11
|
+
klass = (original.is_a?(Class) ? Class : Module).new(self) do
|
12
|
+
|
13
|
+
instance_eval do
|
14
|
+
mock_methods.each do |method, proc|
|
15
|
+
define_method("mocked_#{method}", &proc)
|
16
|
+
alias_method method, "mocked_#{method}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
begin
|
23
|
+
mod.send(:remove_const, class_name)
|
24
|
+
mod.const_set(class_name, klass)
|
25
|
+
|
26
|
+
yield
|
27
|
+
ensure
|
28
|
+
mod.send(:remove_const, class_name)
|
29
|
+
mod.const_set(class_name, original)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
+
|
3
|
+
require 'openssl'
|
4
|
+
require 'net/http'
|
5
|
+
require File.dirname(__FILE__) + '/mocks/method_mock'
|
6
|
+
require 'test/unit'
|
7
|
+
require 'paypal'
|
8
|
+
|
9
|
+
$paypal_success = Class.new do
|
10
|
+
def body; "VERIFIED"; end
|
11
|
+
end
|
12
|
+
|
13
|
+
$paypal_failure = Class.new do
|
14
|
+
def body; "INVALID"; end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
class NotificationTest < Test::Unit::TestCase
|
19
|
+
|
20
|
+
def setup
|
21
|
+
Paypal::Notification.ipn_url = "http://www.paypal.com/some/address"
|
22
|
+
|
23
|
+
@paypal = Paypal::Notification.new(http_raw_data)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_raw
|
27
|
+
assert_equal http_raw_data, @paypal.raw
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_parse
|
31
|
+
@paypal = Paypal::Notification.new(http_raw_data)
|
32
|
+
assert_equal "500.00", @paypal.params['mc_gross']
|
33
|
+
assert_equal "confirmed", @paypal.params['address_status']
|
34
|
+
assert_equal "EVMXCLDZJV77Q", @paypal.params['payer_id']
|
35
|
+
assert_equal "Completed", @paypal.params['payment_status']
|
36
|
+
assert_equal CGI.unescape("15%3A23%3A54+Apr+15%2C+2005+PDT"), @paypal.params['payment_date']
|
37
|
+
|
38
|
+
assert_equal "myinvoice" , @paypal.params['invoice' ]
|
39
|
+
assert_equal "cusdata" , @paypal.params['custom' ]
|
40
|
+
assert_equal "mypending_reason", @paypal.params['pending_reason']
|
41
|
+
assert_equal "myreason_code" , @paypal.params['reason_code' ]
|
42
|
+
assert_equal "mymemo" , @paypal.params['memo' ]
|
43
|
+
assert_equal "mypayment_type" , @paypal.params['payment_type' ]
|
44
|
+
assert_equal "myexchange_rate" , @paypal.params['exchange_rate' ]
|
45
|
+
|
46
|
+
# ...
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_accessors
|
50
|
+
assert @paypal.complete?
|
51
|
+
assert_equal "Completed", @paypal.status
|
52
|
+
assert_equal "6G996328CK404320L", @paypal.transaction_id
|
53
|
+
assert_equal "web_accept", @paypal.type
|
54
|
+
assert_equal "500.00", @paypal.gross
|
55
|
+
assert_equal "15.05", @paypal.fee
|
56
|
+
assert_equal "CAD", @paypal.currency
|
57
|
+
assert_equal "myinvoice" , @paypal.invoice
|
58
|
+
assert_equal "cusdata" , @paypal.custom
|
59
|
+
assert_equal "mypending_reason" , @paypal.pending_reason
|
60
|
+
assert_equal "myreason_code" , @paypal.reason_code
|
61
|
+
assert_equal "mymemo" , @paypal.memo
|
62
|
+
assert_equal "mypayment_type" , @paypal.payment_type
|
63
|
+
assert_equal "myexchange_rate" , @paypal.exchange_rate
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_compositions
|
67
|
+
assert_equal Money.ca_dollar(50000), @paypal.amount
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_acknowledgement
|
71
|
+
|
72
|
+
|
73
|
+
Net::HTTP.mock_methods( :request => Proc.new { |r, b| $paypal_success.new } ) do
|
74
|
+
assert @paypal.acknowledge
|
75
|
+
end
|
76
|
+
|
77
|
+
Net::HTTP.mock_methods( :request => Proc.new { |r, b| $paypal_failure.new } ) do
|
78
|
+
assert !@paypal.acknowledge
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_send_acknowledgement
|
84
|
+
request, body = nil
|
85
|
+
|
86
|
+
Net::HTTP.mock_methods( :request => Proc.new { |r, b| request = r; body = b; $paypal_success.new } ) do
|
87
|
+
assert @paypal.acknowledge
|
88
|
+
end
|
89
|
+
|
90
|
+
assert_equal '/some/address?cmd=_notify-validate', request.path
|
91
|
+
assert_equal http_raw_data, body
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def http_raw_data
|
97
|
+
"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¬ify_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"
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../../lib')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'paypal'
|
5
|
+
|
6
|
+
class RemoteTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_raw
|
9
|
+
Paypal::Notification.ipn_url = "https://www.sandbox.paypal.com/cgi-bin/webscr"
|
10
|
+
@paypal = Paypal::Notification.new('')
|
11
|
+
|
12
|
+
assert_nothing_raised do
|
13
|
+
assert_equal false, @paypal.acknowledge
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
payment_date=02%3A41%3A30+Oct+16%2C+2008+PDT&txn_type=web_accept&last_name=User&residence_country=US&item_name=Store+purchase&payment_gross=17.00&mc_currency=USD&business=seller_1224144737_biz%40e-electrosystems.com&payment_type=instant&protection_eligibility=Eligible&verify_sign=A-HtX3MCUUWjdDhCPAr-2aBmq018A.3u4sJmLsYXTI2shuvE4k-rW9JJ&payer_status=verified&test_ipn=1&tax=0.00&payer_email=gmedin_1223672304_per%40e-electrosystems.com&txn_id=0HP838810U436742B&quantity=1&receiver_email=seller_1224144737_biz%40e-electrosystems.com&first_name=Test&payer_id=L7HKTESMC5NZ4&receiver_id=3DK5MWJLAGUJ2&item_number=Item+17&payment_status=Completed&payment_fee=0.79&mc_fee=0.79&hipping=0.00&mc_gross=17.00&custom=&charset=windows-1252¬ify_version=2.5
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stateless-systems-paypal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tobias Luetke
|
8
|
+
autorequire: paypal
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-14 00:00:00 +11:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: money
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: Paypal IPN integration library for rails and other web applications
|
26
|
+
email: tobi@leetsoft.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files:
|
34
|
+
- init.rb
|
35
|
+
- README
|
36
|
+
- Rakefile
|
37
|
+
- MIT-LICENSE
|
38
|
+
- lib/notification.rb
|
39
|
+
- lib/helper.rb
|
40
|
+
- lib/paypal.rb
|
41
|
+
- misc/PayPal - Instant Payment Notification - Technical Overview.pdf
|
42
|
+
- misc/paypal.psd
|
43
|
+
- test/sample.ipn.response.txt
|
44
|
+
- test/notification_test.rb
|
45
|
+
- test/mocks/http_mock.rb
|
46
|
+
- test/mocks/method_mock.rb
|
47
|
+
- test/helper_test.rb
|
48
|
+
- test/remote/remote_test.rb
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: http://dist.leetsoft.com/api/paypal
|
51
|
+
licenses: []
|
52
|
+
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
version:
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.3.5
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: Paypal IPN integration library for rails and other web applications
|
77
|
+
test_files: []
|
78
|
+
|