paypal_adaptive 0.2.8 → 0.2.9

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 CHANGED
@@ -77,7 +77,7 @@ Additionally, you can make calls to Paypal Adaptive's other APIs:
77
77
  Input is just a Hash just like the pay method. Refer to the Paypal manual for more details.
78
78
 
79
79
  ### Certificate validation
80
- You can set the location of the .pem file you wish to use for SSL certificate validation in paypal_adaptive.yml
80
+ You can set the location of the key file you downloaded from PayPal, in paypal_adaptive.yml
81
81
  for each environment, e.g.:
82
82
 
83
83
  development:
@@ -86,12 +86,14 @@ for each environment, e.g.:
86
86
  password: "sandbox_password"
87
87
  signature: "sandbox_signature"
88
88
  application_id: "sandbox_app_id"
89
- ssl_cert_file: "/path/to/your/cacert.pem"
89
+ ssl_cert_file: "/path/to/your/private.key"
90
90
 
91
- If you don't set ssl_cert_file then paypal_adaptive will check for certificates in /etc/ssl/certs if
92
- this location exists, otherwise falling back to the cacert.pem file included with paypal_adaptive.
91
+ The ssl_cert_file should point to your cert_key_pem.txt that is downloaded through the paypal developer interface. It will contain a section that specifies the RSA private key and another section that specifies a certificate. If this is left empty, paypal_adaptive will attempt to use the signature method of validation with PayPal, so your signature config must not be nil.
93
92
 
94
93
  ## Changelog
94
+ 0.2.9
95
+ Fixed cert issues in last release. Exception handling for connection.
96
+
95
97
  0.2.8
96
98
  Cert fixes and ruby 1.9.3 files. Thanks tonyla.
97
99
 
@@ -43,12 +43,7 @@ module PaypalAdaptive
43
43
  }
44
44
  @headers.merge!({"X-PAYPAL-SECURITY-SIGNATURE" => config['signature']}) if config['signature']
45
45
 
46
- if config['ssl_cert_file'] && config['ssl_cert_file'].length > 0
47
- @ssl_cert_file = config['ssl_cert_file']
48
- else
49
- @ssl_cert_file = File.join(File.dirname(__FILE__), "..", "..", "cacert.pem")
50
- end
51
- puts "warning: coulf not find file: #{@ssl_cert_file}" unless File.exists?(@ssl_cert_file.to_s)
46
+ @ssl_cert_file = config['ssl_cert_file'] unless config['ssl_cert_file'].blank?
52
47
  end
53
48
  end
54
49
 
@@ -75,6 +75,10 @@ module PaypalAdaptive
75
75
  PaypalAdaptive::Response.new(post(data, path), @env)
76
76
  end
77
77
 
78
+ def rescue_error_message(e, message = nil)
79
+ {"responseEvelope" => {"ack" => "Failure"}, "error" => [{"message" => (message ||= e)}]}
80
+ end
81
+
78
82
  def post(data, path)
79
83
  #hack fix: JSON.unparse doesn't work in Rails 2.3.5; only {}.to_json does..
80
84
  api_request_data = JSON.unparse(data) rescue data.to_json
@@ -90,9 +94,20 @@ module PaypalAdaptive
90
94
  end
91
95
  http.ca_path = @ssl_cert_path unless @ssl_cert_path.nil?
92
96
 
93
- response_data = http.post(path, api_request_data, @headers).body
97
+ begin
98
+ response_data = http.post(path, api_request_data, @headers)
99
+ return JSON.parse(response_data.body)
100
+ rescue Net::HTTPBadGateway => e
101
+ rescue_error_message(e, "Error reading from remote server.")
102
+ rescue Exception => e
103
+ case e
104
+ when Errno::ECONNRESET
105
+ rescue_error_message(e, "Connection Reset. Request invalid URL.")
106
+ else
107
+ rescue_error_message(e)
108
+ end
109
+ end
94
110
 
95
- JSON.parse(response_data)
96
111
  end
97
112
  end
98
113
 
@@ -1,4 +1,4 @@
1
1
  module PaypalAdaptive
2
- VERSION = "0.2.8"
2
+ VERSION = "0.2.9"
3
3
  end
4
4
 
data/test/test_helper.rb CHANGED
@@ -6,3 +6,4 @@ require "test/unit"
6
6
  require "json"
7
7
  require "jsonschema"
8
8
  require 'paypal_adaptive'
9
+ require 'active_support/core_ext/string'
@@ -7,12 +7,6 @@ class ConfigTest < Test::Unit::TestCase
7
7
  assert_equal nil, @config.ssl_cert_path
8
8
  end
9
9
 
10
- def test_default_ssl_cert_file
11
- @config = PaypalAdaptive::Config.new("test", { "ssl_cert_file" => "" })
12
- assert File.exists?(@config.ssl_cert_file)
13
- assert_equal nil, @config.ssl_cert_path
14
- end
15
-
16
10
  def test_erb_tags
17
11
  ENV['paypal.username'] = 'account@email.com'
18
12
  ENV['paypal.password'] = 's3krit'
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ class RequestTest < Test::Unit::TestCase
4
+ def setup
5
+ @schema_filepath = File.join(File.dirname(__FILE__),"..", "..", "lib","pay_request_schema.json")
6
+ @schema = File.open(@schema_filepath, "rb"){|f| JSON.parse(f.read)}
7
+ end
8
+
9
+ def test_post_should_return_hash
10
+ request = PaypalAdaptive::Request.new('test')
11
+ response = request.post({:data => true}, '/AdaptivePayments/Pay')
12
+ assert_instance_of Hash, response
13
+ end
14
+
15
+ def test_post_should_return_hash_when_request_is_invalid
16
+ request = PaypalAdaptive::Request.new('test')
17
+ response = request.post({:data => true}, '/some-random-url')
18
+ assert_instance_of Hash, response
19
+ end
20
+
21
+ def test_post_shoudl_return_error_message_when_request_is_invalid
22
+ request = PaypalAdaptive::Request.new('test')
23
+ response = request.post({:data => true}, '/some-random-url')
24
+ assert_not_nil response["error"][0]["message"]
25
+ end
26
+
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paypal_adaptive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-10 00:00:00.000000000 -08:00
13
- default_executable:
12
+ date: 2012-03-08 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: json
17
- requirement: &2157775420 !ruby/object:Gem::Requirement
16
+ requirement: &70231058458960 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ~>
@@ -22,10 +21,10 @@ dependencies:
22
21
  version: 1.6.0
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *2157775420
24
+ version_requirements: *70231058458960
26
25
  - !ruby/object:Gem::Dependency
27
26
  name: jsonschema
28
- requirement: &2157774920 !ruby/object:Gem::Requirement
27
+ requirement: &70231058458120 !ruby/object:Gem::Requirement
29
28
  none: false
30
29
  requirements:
31
30
  - - ~>
@@ -33,10 +32,10 @@ dependencies:
33
32
  version: 2.0.0
34
33
  type: :runtime
35
34
  prerelease: false
36
- version_requirements: *2157774920
35
+ version_requirements: *70231058458120
37
36
  - !ruby/object:Gem::Dependency
38
37
  name: rake
39
- requirement: &2157774440 !ruby/object:Gem::Requirement
38
+ requirement: &70231058457000 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
42
41
  - - ~>
@@ -44,7 +43,7 @@ dependencies:
44
43
  version: '0.8'
45
44
  type: :runtime
46
45
  prerelease: false
47
- version_requirements: *2157774440
46
+ version_requirements: *70231058457000
48
47
  description: Lightweight wrapper for Paypal's Adaptive Payments API
49
48
  email:
50
49
  - tommy.chheng@gmail.com
@@ -90,7 +89,7 @@ files:
90
89
  - test/unit/payment_details_test.rb
91
90
  - test/unit/payment_options_test.rb
92
91
  - test/unit/preapproval_test.rb
93
- has_rdoc: true
92
+ - test/unit/request_test.rb
94
93
  homepage: http://github.com/tc/paypal_adaptive
95
94
  licenses: []
96
95
  post_install_message:
@@ -111,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
110
  version: '0'
112
111
  requirements: []
113
112
  rubyforge_project: paypal_adaptive
114
- rubygems_version: 1.6.2
113
+ rubygems_version: 1.8.15
115
114
  signing_key:
116
115
  specification_version: 3
117
116
  summary: Lightweight wrapper for Paypal's Adaptive Payments API
@@ -138,3 +137,4 @@ test_files:
138
137
  - test/unit/payment_details_test.rb
139
138
  - test/unit/payment_options_test.rb
140
139
  - test/unit/preapproval_test.rb
140
+ - test/unit/request_test.rb