payson_api 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -2
- data/MIT-LICENSE +20 -0
- data/lib/payson_api/client.rb +17 -8
- data/lib/payson_api/version.rb +1 -1
- data/payson_api.gemspec +3 -1
- data/test/integration/request_test.rb +40 -0
- metadata +26 -16
data/Gemfile
CHANGED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Christopher Svensson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/payson_api/client.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'net/https'
|
2
2
|
|
3
3
|
module PaysonAPI
|
4
4
|
class Client
|
@@ -8,12 +8,6 @@ module PaysonAPI
|
|
8
8
|
Response.new(response.body)
|
9
9
|
end
|
10
10
|
|
11
|
-
def self.payment_details(token)
|
12
|
-
action = '/%s/%s/' % [PAYSON_API_VERSION, PAYSON_API_PAYMENT_DETAILS_ACTION]
|
13
|
-
response = post(PAYSON_API_ENDPOINT + action, { :token => token })
|
14
|
-
Response.new(response.body)
|
15
|
-
end
|
16
|
-
|
17
11
|
private
|
18
12
|
|
19
13
|
def self.post(url, data)
|
@@ -22,7 +16,22 @@ module PaysonAPI
|
|
22
16
|
'PAYSON-SECURITY-PASSWORD' => PaysonAPI.config.api_password,
|
23
17
|
'Content-Type' => 'application/x-www-form-urlencoded'
|
24
18
|
}
|
25
|
-
|
19
|
+
uri = URI.parse(url)
|
20
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
21
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
22
|
+
http.use_ssl = uri.scheme == 'https'
|
23
|
+
req = Net::HTTP::Post.new(uri.path)
|
24
|
+
req.body = hash_to_params(data)
|
25
|
+
headers.each do |name, value|
|
26
|
+
req[name] = value
|
27
|
+
end
|
28
|
+
http.request(req)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.hash_to_params(hash)
|
32
|
+
out = ""
|
33
|
+
hash.each { |k, v| out << "#{k}=#{v}&" }
|
34
|
+
out.chop
|
26
35
|
end
|
27
36
|
end
|
28
37
|
end
|
data/lib/payson_api/version.rb
CHANGED
data/payson_api.gemspec
CHANGED
@@ -11,11 +11,13 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.homepage = "https://github.com/stoffus/payson_api"
|
12
12
|
s.summary = %q{Client for Payson API}
|
13
13
|
s.description = %q{Client that enables access to the Payson payment gateway API.}
|
14
|
+
s.license = 'MIT'
|
14
15
|
|
15
16
|
s.files = `git ls-files`.split("\n")
|
16
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
19
|
s.require_paths = ["lib"]
|
19
20
|
|
20
|
-
s.
|
21
|
+
s.add_development_dependency 'rake'
|
22
|
+
s.add_development_dependency 'guard-test'
|
21
23
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'test_helper'
|
5
|
+
require 'payson_api'
|
6
|
+
|
7
|
+
class PayDataTest < Test::Unit::TestCase
|
8
|
+
include TestHelper
|
9
|
+
ORDER = YAML.load_file('test/fixtures/order.yml')
|
10
|
+
|
11
|
+
def test_request_and_fail_gracefully
|
12
|
+
sender = PaysonAPI::Sender.new(
|
13
|
+
ORDER[:sender][:email],
|
14
|
+
ORDER[:sender][:first_name],
|
15
|
+
ORDER[:sender][:last_name]
|
16
|
+
)
|
17
|
+
|
18
|
+
receivers = []
|
19
|
+
ORDER[:receivers].each do |receiver|
|
20
|
+
receivers << PaysonAPI::Receiver.new(
|
21
|
+
receiver[:email],
|
22
|
+
receiver[:amount]
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
pay_data = PaysonAPI::PayData.new(
|
27
|
+
ORDER[:return_url],
|
28
|
+
ORDER[:cancel_url],
|
29
|
+
ORDER[:ipn_url],
|
30
|
+
ORDER[:memo],
|
31
|
+
sender,
|
32
|
+
receivers
|
33
|
+
)
|
34
|
+
|
35
|
+
response = PaysonAPI::Client.pay(pay_data)
|
36
|
+
|
37
|
+
# This should fail due to bad credentials
|
38
|
+
assert_equal 'FAILURE', response.envelope['ack']
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: payson_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
4
|
+
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
8
|
+
- 6
|
9
|
+
version: 0.0.6
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Christopher Svensson
|
@@ -15,22 +14,33 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2012-07-25 00:00:00
|
17
|
+
date: 2012-07-25 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
21
|
+
name: rake
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
-
none: false
|
25
24
|
requirements:
|
26
25
|
- - ">="
|
27
26
|
- !ruby/object:Gem::Version
|
28
|
-
hash: 3
|
29
27
|
segments:
|
30
28
|
- 0
|
31
29
|
version: "0"
|
32
|
-
type: :
|
30
|
+
type: :development
|
33
31
|
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: guard-test
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :development
|
43
|
+
version_requirements: *id002
|
34
44
|
description: Client that enables access to the Payson payment gateway API.
|
35
45
|
email:
|
36
46
|
- stoffus@stoffus.com
|
@@ -45,6 +55,7 @@ files:
|
|
45
55
|
- .travis.yml
|
46
56
|
- Gemfile
|
47
57
|
- Guardfile
|
58
|
+
- MIT-LICENSE
|
48
59
|
- README.rdoc
|
49
60
|
- Rakefile
|
50
61
|
- lib/payson_api.rb
|
@@ -63,37 +74,35 @@ files:
|
|
63
74
|
- test/fixtures/order.yml
|
64
75
|
- test/integration/config_test.rb
|
65
76
|
- test/integration/pay_data_test.rb
|
77
|
+
- test/integration/request_test.rb
|
66
78
|
- test/test_helper.rb
|
79
|
+
has_rdoc: true
|
67
80
|
homepage: https://github.com/stoffus/payson_api
|
68
|
-
licenses:
|
69
|
-
|
81
|
+
licenses:
|
82
|
+
- MIT
|
70
83
|
post_install_message:
|
71
84
|
rdoc_options: []
|
72
85
|
|
73
86
|
require_paths:
|
74
87
|
- lib
|
75
88
|
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
-
none: false
|
77
89
|
requirements:
|
78
90
|
- - ">="
|
79
91
|
- !ruby/object:Gem::Version
|
80
|
-
hash: 3
|
81
92
|
segments:
|
82
93
|
- 0
|
83
94
|
version: "0"
|
84
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
-
none: false
|
86
96
|
requirements:
|
87
97
|
- - ">="
|
88
98
|
- !ruby/object:Gem::Version
|
89
|
-
hash: 3
|
90
99
|
segments:
|
91
100
|
- 0
|
92
101
|
version: "0"
|
93
102
|
requirements: []
|
94
103
|
|
95
104
|
rubyforge_project:
|
96
|
-
rubygems_version: 1.
|
105
|
+
rubygems_version: 1.3.6
|
97
106
|
signing_key:
|
98
107
|
specification_version: 3
|
99
108
|
summary: Client for Payson API
|
@@ -102,4 +111,5 @@ test_files:
|
|
102
111
|
- test/fixtures/order.yml
|
103
112
|
- test/integration/config_test.rb
|
104
113
|
- test/integration/pay_data_test.rb
|
114
|
+
- test/integration/request_test.rb
|
105
115
|
- test/test_helper.rb
|