paypal_adaptive 0.1.0 → 0.2.0
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/README.markdown +26 -2
- data/Rakefile +11 -10
- data/VERSION +1 -1
- data/cacert.pem +3987 -0
- data/config/paypal_adaptive.yml +4 -1
- data/lib/config.rb +22 -9
- data/lib/ipn_notification.rb +6 -1
- data/lib/paypal_adaptive.rb +1 -1
- data/lib/request.rb +6 -1
- data/lib/response.rb +1 -1
- data/paypal_adaptive.gemspec +41 -40
- data/test/data/dummy_cacert.pem +1 -0
- data/test/data/valid_preapproval.json +2 -2
- data/test/{helper.rb → test_helper.rb} +2 -1
- data/test/unit/config_test.rb +15 -0
- data/test/{pay_request_schema_test.rb → unit/pay_request_schema_test.rb} +6 -6
- data/test/{pay_request_test.rb → unit/pay_request_test.rb} +11 -9
- data/test/{payment_details_test.rb → unit/payment_details_test.rb} +3 -4
- data/test/{preapproval_test.rb → unit/preapproval_test.rb} +6 -6
- metadata +57 -68
- data/.gitignore +0 -22
data/config/paypal_adaptive.yml
CHANGED
@@ -4,6 +4,7 @@ development:
|
|
4
4
|
password: "signupforuseratsandboxpaypal"
|
5
5
|
signature: "signupforuseratsandboxpaypal"
|
6
6
|
application_id: "APP-TEST"
|
7
|
+
ssl_cert_file:
|
7
8
|
|
8
9
|
test:
|
9
10
|
environment: "sandbox"
|
@@ -11,10 +12,12 @@ test:
|
|
11
12
|
password: "signupforuseratsandboxpaypal"
|
12
13
|
signature: "signupforuseratsandboxpaypal"
|
13
14
|
application_id: "APP-TEST"
|
15
|
+
ssl_cert_file:
|
14
16
|
|
15
17
|
production:
|
16
18
|
environment: "production"
|
17
19
|
username: "my_production_username"
|
18
20
|
password: "my_production_password"
|
19
21
|
signature: "my_production_signature"
|
20
|
-
application_id: "my_production_app_id"
|
22
|
+
application_id: "my_production_app_id"
|
23
|
+
ssl_cert_file:
|
data/lib/config.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
1
3
|
module PaypalAdaptive
|
2
4
|
class Config
|
3
5
|
PAYPAL_BASE_URL_MAPPING = {
|
@@ -12,27 +14,30 @@ module PaypalAdaptive
|
|
12
14
|
:beta_sandbox => "https://svcs.beta-sandbox.paypal.com"
|
13
15
|
} unless defined? API_BASE_URL_MAPPING
|
14
16
|
|
15
|
-
attr_accessor :config_filepath, :paypal_base_url, :api_base_url, :headers
|
17
|
+
attr_accessor :config_filepath, :paypal_base_url, :api_base_url, :headers, :ssl_cert_path, :ssl_cert_file
|
16
18
|
|
17
|
-
def initialize(env=nil)
|
19
|
+
def initialize(env=nil, config_override=nil)
|
18
20
|
if env
|
19
21
|
#non-rails env
|
20
|
-
@config_filepath = "
|
21
|
-
load(env)
|
22
|
+
@config_filepath = File.join(File.dirname(__FILE__), "..", "config", "paypal_adaptive.yml")
|
23
|
+
load(env, config_override)
|
22
24
|
else
|
23
|
-
@config_filepath = File.join(Rails.root, "config
|
24
|
-
load(Rails.env)
|
25
|
+
@config_filepath = File.join(Rails.root, "config", "paypal_adaptive.yml")
|
26
|
+
load(Rails.env, config_override)
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
|
-
def load(rails_env)
|
29
|
-
config= YAML.load_file(@config_filepath)[rails_env]
|
30
|
+
def load(rails_env, config_override)
|
31
|
+
config = YAML.load_file(@config_filepath)[rails_env]
|
32
|
+
config.merge!(config_override) unless config_override.nil?
|
30
33
|
|
31
34
|
if config["retain_requests_for_test"] == true
|
32
35
|
@retain_requests_for_test = true
|
33
36
|
else
|
34
37
|
pp_env = config['environment'].to_sym
|
35
38
|
|
39
|
+
@ssl_cert_path = nil
|
40
|
+
@ssl_cert_file = nil
|
36
41
|
@paypal_base_url = PAYPAL_BASE_URL_MAPPING[pp_env]
|
37
42
|
@api_base_url = API_BASE_URL_MAPPING[pp_env]
|
38
43
|
@headers = {
|
@@ -43,6 +48,14 @@ module PaypalAdaptive
|
|
43
48
|
"X-PAYPAL-REQUEST-DATA-FORMAT" => "JSON",
|
44
49
|
"X-PAYPAL-RESPONSE-DATA-FORMAT" => "JSON"
|
45
50
|
}
|
51
|
+
|
52
|
+
if config['ssl_cert_file'] && config['ssl_cert_file'].length > 0
|
53
|
+
@ssl_cert_file = config['ssl_cert_file']
|
54
|
+
elsif File.exists?("/etc/ssl/certs")
|
55
|
+
@ssl_cert_path = "/etc/ssl/certs"
|
56
|
+
else
|
57
|
+
@ssl_cert_file = "../cacert.pem"
|
58
|
+
end
|
46
59
|
end
|
47
60
|
end
|
48
61
|
|
@@ -51,4 +64,4 @@ module PaypalAdaptive
|
|
51
64
|
end
|
52
65
|
|
53
66
|
end
|
54
|
-
end
|
67
|
+
end
|
data/lib/ipn_notification.rb
CHANGED
@@ -10,13 +10,18 @@ module PaypalAdaptive
|
|
10
10
|
@env = env
|
11
11
|
@@config ||= PaypalAdaptive::Config.new(@env)
|
12
12
|
@@paypal_base_url ||= @@config.paypal_base_url
|
13
|
+
@@ssl_cert_path ||= @@config.ssl_cert_path
|
14
|
+
@@ssl_cert_file ||= @@config.ssl_cert_file
|
13
15
|
end
|
14
16
|
|
15
17
|
def send_back(data)
|
16
18
|
data = "cmd=_notify-validate&#{data}"
|
17
19
|
url = URI.parse @@paypal_base_url
|
18
20
|
http = Net::HTTP.new(url.host, 443)
|
19
|
-
http.use_ssl =
|
21
|
+
http.use_ssl = true
|
22
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
23
|
+
http.ca_path = @@ssl_cert_path unless @@ssl_cert_path.nil?
|
24
|
+
http.ca_file = @@ssl_cert_file unless @@ssl_cert_file.nil?
|
20
25
|
|
21
26
|
path = "#{@@paypal_base_url}/cgi-bin/webscr"
|
22
27
|
resp, response_data = http.post(path, data)
|
data/lib/paypal_adaptive.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), "config"))
|
2
2
|
require File.expand_path(File.join(File.dirname(__FILE__), "request"))
|
3
3
|
require File.expand_path(File.join(File.dirname(__FILE__), "response"))
|
4
|
-
require File.expand_path(File.join(File.dirname(__FILE__), "ipn_notification"))
|
4
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "ipn_notification"))
|
data/lib/request.rb
CHANGED
@@ -14,6 +14,8 @@ module PaypalAdaptive
|
|
14
14
|
@@config ||= PaypalAdaptive::Config.new(@env)
|
15
15
|
@@api_base_url ||= @@config.api_base_url
|
16
16
|
@@headers ||= @@config.headers
|
17
|
+
@@ssl_cert_path ||= @@config.ssl_cert_path
|
18
|
+
@@ssl_cert_file ||= @@config.ssl_cert_file
|
17
19
|
end
|
18
20
|
|
19
21
|
def validate
|
@@ -74,7 +76,10 @@ module PaypalAdaptive
|
|
74
76
|
api_request_data = JSON.unparse(data) rescue data.to_json
|
75
77
|
url = URI.parse @@api_base_url
|
76
78
|
http = Net::HTTP.new(url.host, 443)
|
77
|
-
http.use_ssl =
|
79
|
+
http.use_ssl = true
|
80
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
81
|
+
http.ca_path = @@ssl_cert_path unless @@ssl_cert_path.nil?
|
82
|
+
http.ca_file = @@ssl_cert_file unless @@ssl_cert_file.nil?
|
78
83
|
|
79
84
|
resp, response_data = http.post(path, api_request_data, @@headers)
|
80
85
|
|
data/lib/response.rb
CHANGED
data/paypal_adaptive.gemspec
CHANGED
@@ -1,68 +1,69 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{paypal_adaptive}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Tommy Chheng"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-04-25}
|
13
13
|
s.description = %q{Lightweight wrapper for Paypal's Adaptive Payments API.}
|
14
14
|
s.email = %q{tommy.chheng@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
|
17
|
+
"README.markdown"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
|
-
"
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
20
|
+
"LICENSE",
|
21
|
+
"README.markdown",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"cacert.pem",
|
25
|
+
"config/paypal_adaptive.yml",
|
26
|
+
"lib/config.rb",
|
27
|
+
"lib/ipn_notification.rb",
|
28
|
+
"lib/pay_request_schema.json",
|
29
|
+
"lib/paypal_adaptive.rb",
|
30
|
+
"lib/request.rb",
|
31
|
+
"lib/response.rb",
|
32
|
+
"paypal_adaptive.gemspec",
|
33
|
+
"templates/paypal_ipn.rb",
|
34
|
+
"test/data/dummy_cacert.pem",
|
35
|
+
"test/data/invalid_chain_pay_request.json",
|
36
|
+
"test/data/invalid_parallel_pay_request.json",
|
37
|
+
"test/data/invalid_preapproval.json",
|
38
|
+
"test/data/invalid_simple_pay_request_1.json",
|
39
|
+
"test/data/valid_chain_pay_request.json",
|
40
|
+
"test/data/valid_parallel_pay_request.json",
|
41
|
+
"test/data/valid_preapproval.json",
|
42
|
+
"test/data/valid_simple_pay_request_1.json",
|
43
|
+
"test/test_helper.rb",
|
44
|
+
"test/unit/config_test.rb",
|
45
|
+
"test/unit/pay_request_schema_test.rb",
|
46
|
+
"test/unit/pay_request_test.rb",
|
47
|
+
"test/unit/payment_details_test.rb",
|
48
|
+
"test/unit/preapproval_test.rb"
|
47
49
|
]
|
48
50
|
s.homepage = %q{http://github.com/tc/paypal_adaptive}
|
49
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
50
51
|
s.require_paths = ["lib"]
|
51
|
-
s.rubygems_version = %q{1.
|
52
|
+
s.rubygems_version = %q{1.6.2}
|
52
53
|
s.summary = %q{initial import}
|
53
54
|
s.test_files = [
|
54
|
-
"test/
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
"test/test_helper.rb",
|
56
|
+
"test/unit/config_test.rb",
|
57
|
+
"test/unit/pay_request_schema_test.rb",
|
58
|
+
"test/unit/pay_request_test.rb",
|
59
|
+
"test/unit/payment_details_test.rb",
|
60
|
+
"test/unit/preapproval_test.rb"
|
59
61
|
]
|
60
62
|
|
61
63
|
if s.respond_to? :specification_version then
|
62
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
63
64
|
s.specification_version = 3
|
64
65
|
|
65
|
-
if Gem::Version.new(Gem::
|
66
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
66
67
|
s.add_development_dependency(%q<json>, [">= 0"])
|
67
68
|
s.add_development_dependency(%q<jsonschema>, [">= 0"])
|
68
69
|
else
|
@@ -0,0 +1 @@
|
|
1
|
+
# Dummy file for testing.
|
@@ -5,7 +5,7 @@
|
|
5
5
|
"cancelUrl":"http://127.0.0.1:3000/payments/canceled_payment_request",
|
6
6
|
"maxTotalAmountOfAllPayments": "1500.00",
|
7
7
|
"maxNumberOfPayments":"30",
|
8
|
-
"startingDate":"
|
9
|
-
"endingDate":"
|
8
|
+
"startingDate":"2020-07-13T07:00:00.000Z",
|
9
|
+
"endingDate":"2020-12-13T07:00:00.000Z"
|
10
10
|
}
|
11
11
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ConfigTest < Test::Unit::TestCase
|
4
|
+
def test_ssl_cert_logic
|
5
|
+
@config = PaypalAdaptive::Config.new("test", { "ssl_cert_file" => "" })
|
6
|
+
|
7
|
+
assert_equal File.join("..","cacert.pem"), @config.ssl_cert_file
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_ssl_cert_file
|
11
|
+
@config = PaypalAdaptive::Config.new("test", { "ssl_cert_file" => "data/dummy_cacert.pem" })
|
12
|
+
assert_equal File.join("data", "dummy_cacert.pem"), @config.ssl_cert_file
|
13
|
+
assert_equal nil, @config.ssl_cert_path
|
14
|
+
end
|
15
|
+
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'json'
|
3
3
|
require 'jsonschema'
|
4
4
|
|
5
5
|
class PayRequestSchemaTest < Test::Unit::TestCase
|
6
6
|
def setup
|
7
|
-
@schema_filepath = "
|
7
|
+
@schema_filepath = File.join(File.dirname(__FILE__),"..", "..", "lib","pay_request_schema.json")
|
8
8
|
@schema = File.open(@schema_filepath, "rb"){|f| JSON.parse(f.read)}
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
data_filepath =
|
11
|
+
def test_valid_simple_pay
|
12
|
+
data_filepath = File.join(File.dirname(__FILE__),"..", "data","valid_simple_pay_request_1.json")
|
13
13
|
data = read_json_file(data_filepath)
|
14
14
|
|
15
15
|
#receiverList not validating correctly, is it due to the schema or jsonschema parsing?
|
@@ -19,7 +19,7 @@ class PayRequestSchemaTest < Test::Unit::TestCase
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def test_invalid_simple_pay
|
22
|
-
data_filepath =
|
22
|
+
data_filepath = File.join(File.dirname(__FILE__),"..", "data","invalid_simple_pay_request_1.json")
|
23
23
|
data = read_json_file(data_filepath)
|
24
24
|
|
25
25
|
assert_raise JSON::Schema::ValueError do
|
@@ -46,4 +46,4 @@ class PayRequestSchemaTest < Test::Unit::TestCase
|
|
46
46
|
def read_json_file(filepath)
|
47
47
|
File.open(filepath, "rb"){|f| JSON.parse(f.read)}
|
48
48
|
end
|
49
|
-
end
|
49
|
+
end
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require '../lib/request'
|
1
|
+
require 'test_helper'
|
3
2
|
|
4
3
|
class PayRequestTest < Test::Unit::TestCase
|
5
4
|
def setup
|
@@ -10,7 +9,7 @@ class PayRequestTest < Test::Unit::TestCase
|
|
10
9
|
puts "-------"
|
11
10
|
puts "simple"
|
12
11
|
|
13
|
-
data_filepath = "
|
12
|
+
data_filepath = File.join(File.dirname(__FILE__),"..", "data","valid_simple_pay_request_1.json")
|
14
13
|
|
15
14
|
data = read_json_file(data_filepath)
|
16
15
|
pp_response = @pay_request.pay(data)
|
@@ -20,7 +19,7 @@ class PayRequestTest < Test::Unit::TestCase
|
|
20
19
|
end
|
21
20
|
|
22
21
|
def test_invalid_simple_pay
|
23
|
-
data_filepath = "
|
22
|
+
data_filepath = File.join(File.dirname(__FILE__),"..", "data","invalid_simple_pay_request_1.json")
|
24
23
|
|
25
24
|
data = read_json_file(data_filepath)
|
26
25
|
pp_response = @pay_request.pay(data)
|
@@ -31,7 +30,7 @@ class PayRequestTest < Test::Unit::TestCase
|
|
31
30
|
def test_valid_chain_pay
|
32
31
|
puts "-------"
|
33
32
|
puts "chain"
|
34
|
-
data_filepath = "
|
33
|
+
data_filepath = File.join(File.dirname(__FILE__),"..", "data","valid_chain_pay_request.json")
|
35
34
|
|
36
35
|
data = read_json_file(data_filepath)
|
37
36
|
pp_response = @pay_request.pay(data)
|
@@ -45,7 +44,7 @@ class PayRequestTest < Test::Unit::TestCase
|
|
45
44
|
end
|
46
45
|
|
47
46
|
def test_invalid_chain_pay
|
48
|
-
data_filepath = "
|
47
|
+
data_filepath = File.join(File.dirname(__FILE__),"..", "data","invalid_chain_pay_request.json")
|
49
48
|
|
50
49
|
data = read_json_file(data_filepath)
|
51
50
|
pp_response = @pay_request.pay(data)
|
@@ -57,7 +56,7 @@ class PayRequestTest < Test::Unit::TestCase
|
|
57
56
|
puts "-------"
|
58
57
|
puts "parallel"
|
59
58
|
|
60
|
-
data_filepath = "
|
59
|
+
data_filepath = File.join(File.dirname(__FILE__),"..", "data","valid_parallel_pay_request.json")
|
61
60
|
|
62
61
|
data = read_json_file(data_filepath)
|
63
62
|
pp_response = @pay_request.pay(data)
|
@@ -66,7 +65,7 @@ class PayRequestTest < Test::Unit::TestCase
|
|
66
65
|
end
|
67
66
|
|
68
67
|
def test_invalid_parallel_pay
|
69
|
-
data_filepath = "
|
68
|
+
data_filepath = File.join(File.dirname(__FILE__),"..", "data","invalid_parallel_pay_request.json")
|
70
69
|
|
71
70
|
data = read_json_file(data_filepath)
|
72
71
|
pp_response = @pay_request.pay(data)
|
@@ -74,6 +73,9 @@ class PayRequestTest < Test::Unit::TestCase
|
|
74
73
|
assert pp_response.success? == false
|
75
74
|
end
|
76
75
|
|
76
|
+
def test_set_payment_options
|
77
|
+
#TODO
|
78
|
+
end
|
77
79
|
|
78
80
|
def test_preapproval
|
79
81
|
#TODO
|
@@ -99,4 +101,4 @@ class PayRequestTest < Test::Unit::TestCase
|
|
99
101
|
File.open(filepath, "rb"){|f| JSON.parse(f.read)}
|
100
102
|
end
|
101
103
|
|
102
|
-
end
|
104
|
+
end
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require '../lib/request'
|
1
|
+
require 'test_helper'
|
3
2
|
|
4
3
|
class PaymentDetailsTest < Test::Unit::TestCase
|
5
4
|
def setup
|
@@ -10,7 +9,7 @@ class PaymentDetailsTest < Test::Unit::TestCase
|
|
10
9
|
def test_payment_details
|
11
10
|
puts "-------"
|
12
11
|
puts "payment details"
|
13
|
-
data_filepath = "
|
12
|
+
data_filepath = File.join(File.dirname(__FILE__),"..", "data","valid_chain_pay_request.json")
|
14
13
|
|
15
14
|
data = read_json_file(data_filepath)
|
16
15
|
pp_response = @pay_request.pay(data)
|
@@ -32,4 +31,4 @@ class PaymentDetailsTest < Test::Unit::TestCase
|
|
32
31
|
File.open(filepath, "rb"){|f| JSON.parse(f.read)}
|
33
32
|
end
|
34
33
|
|
35
|
-
end
|
34
|
+
end
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require '../lib/request'
|
1
|
+
require 'test_helper'
|
3
2
|
|
4
3
|
class PreapprovalTest < Test::Unit::TestCase
|
5
4
|
def setup
|
@@ -9,9 +8,10 @@ class PreapprovalTest < Test::Unit::TestCase
|
|
9
8
|
def test_preapproval
|
10
9
|
puts "-------"
|
11
10
|
puts "valid test"
|
12
|
-
data_filepath = "
|
11
|
+
data_filepath = File.join(File.dirname(__FILE__),"..", "data","valid_preapproval.json")
|
13
12
|
|
14
13
|
data = read_json_file(data_filepath)
|
14
|
+
p data
|
15
15
|
|
16
16
|
pp_response = @preapproval_request.preapproval(data)
|
17
17
|
puts "preapproval code is #{pp_response['preapprovalKey']}"
|
@@ -25,7 +25,7 @@ class PreapprovalTest < Test::Unit::TestCase
|
|
25
25
|
def test_invalid_preapproval
|
26
26
|
puts "-------"
|
27
27
|
puts "invalid"
|
28
|
-
data_filepath = "
|
28
|
+
data_filepath = File.join(File.dirname(__FILE__),"..", "data","invalid_preapproval.json")
|
29
29
|
|
30
30
|
data = read_json_file(data_filepath)
|
31
31
|
pp_response = @preapproval_request.preapproval(data)
|
@@ -37,7 +37,7 @@ class PreapprovalTest < Test::Unit::TestCase
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def read_json_file(filepath)
|
40
|
-
File.open(filepath,
|
40
|
+
File.open(filepath, "rb"){|f| JSON.parse(f.read)}
|
41
41
|
end
|
42
42
|
|
43
|
-
end
|
43
|
+
end
|