payone_connect 0.1.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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Patrick Huesler
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/README.rdoc ADDED
@@ -0,0 +1,18 @@
1
+ = payone_connect
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2009 Patrick Huesler. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "payone_connect"
8
+ gem.summary = %Q{Simple http clinet for the psp payone api (http://www.payone.de/)}
9
+ gem.description = %Q{Connects to the payone gateway and passes the parameters}
10
+ gem.email = "patrick.huesler@gmail.com"
11
+ gem.homepage = "http://github.com/phuesler/payone_connect"
12
+ gem.authors = ["Patrick Huesler"]
13
+ gem.add_development_dependency "rspec"
14
+ gem.add_development_dependency "fakeweb"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ if File.exist?('VERSION')
41
+ version = File.read('VERSION')
42
+ else
43
+ version = ""
44
+ end
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "payone_connect #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/core_ext.rb ADDED
@@ -0,0 +1,76 @@
1
+ class Hash
2
+ # Return a new hash with all keys converted to strings.
3
+ def stringify_keys
4
+ inject({}) do |options, (key, value)|
5
+ options[key.to_s] = value
6
+ options
7
+ end
8
+ end
9
+
10
+ # Destructively convert all keys to strings.
11
+ def stringify_keys!
12
+ keys.each do |key|
13
+ self[key.to_s] = delete(key)
14
+ end
15
+ self
16
+ end
17
+ end
18
+
19
+ class Object
20
+ # An object is blank if it's false, empty, or a whitespace string.
21
+ # For example, "", " ", +nil+, [], and {} are blank.
22
+ #
23
+ # This simplifies
24
+ #
25
+ # if !address.nil? && !address.empty?
26
+ #
27
+ # to
28
+ #
29
+ # if !address.blank?
30
+ def blank?
31
+ respond_to?(:empty?) ? empty? : !self
32
+ end
33
+
34
+ # An object is present if it's not blank.
35
+ def present?
36
+ !blank?
37
+ end
38
+ end
39
+
40
+ class NilClass #:nodoc:
41
+ def blank?
42
+ true
43
+ end
44
+ end
45
+
46
+ class FalseClass #:nodoc:
47
+ def blank?
48
+ true
49
+ end
50
+ end
51
+
52
+ class TrueClass #:nodoc:
53
+ def blank?
54
+ false
55
+ end
56
+ end
57
+
58
+ class Array #:nodoc:
59
+ alias_method :blank?, :empty?
60
+ end
61
+
62
+ class Hash #:nodoc:
63
+ alias_method :blank?, :empty?
64
+ end
65
+
66
+ class String #:nodoc:
67
+ def blank?
68
+ self !~ /\S/
69
+ end
70
+ end
71
+
72
+ class Numeric #:nodoc:
73
+ def blank?
74
+ false
75
+ end
76
+ end
@@ -0,0 +1,50 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'uri'
4
+ require 'core_ext'
5
+
6
+ class PayoneConnect
7
+ attr_reader :request_data, :request_header
8
+ def initialize(api_url, data)
9
+ @api_url = URI.parse(api_url)
10
+ @request_data = process_data(data)
11
+ @request_header = {'Content-Type'=> 'application/x-www-form-urlencoded'}
12
+ end
13
+
14
+ def request
15
+ http = Net::HTTP.new(@api_url.host, @api_url.port)
16
+ http.use_ssl = true
17
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
18
+ handle_response(http.post(@api_url.path, @request_data,@request_header))
19
+ end
20
+
21
+ protected
22
+
23
+ def handle_response(http_response)
24
+ return nil if http_response.body.blank?
25
+ response = {}
26
+ http_response.body.split("\n").each do |param|
27
+ key,value = param.split("=")
28
+ response[key.to_sym] = value
29
+ end
30
+ response
31
+ end
32
+
33
+ def process_data(data)
34
+ data.stringify_keys!
35
+ %w(mid portalid key mode).each do |required_field|
36
+ raise "Payone API Setup Data not complete: #{required_field.upcase} was blank" if data[required_field].blank?
37
+ end
38
+ post_data = []
39
+ data.each do |key,value|
40
+ if value.is_a?(Hash)
41
+ value.each do |nested_key, nested_value|
42
+ post_data << "#{key.to_s}[#{nested_key.to_s}]=#{URI.encode(nested_value.to_s)}"
43
+ end
44
+ else
45
+ post_data << "#{key.to_s}=#{URI.encode(value.to_s)}"
46
+ end
47
+ end
48
+ post_data.join("&")
49
+ end
50
+ end
@@ -0,0 +1,57 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{payone_connect}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Patrick Huesler"]
12
+ s.date = %q{2009-10-03}
13
+ s.description = %q{Connects to the payone gateway and passes the parameters}
14
+ s.email = %q{patrick.huesler@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/core_ext.rb",
27
+ "lib/payone_connect.rb",
28
+ "payone_connect.gemspec",
29
+ "spec/payone_connect_spec.rb",
30
+ "spec/spec_helper.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/phuesler/payone_connect}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.5}
36
+ s.summary = %q{Simple http clinet for the psp payone api (http://www.payone.de/)}
37
+ s.test_files = [
38
+ "spec/payone_connect_spec.rb",
39
+ "spec/spec_helper.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ s.add_development_dependency(%q<rspec>, [">= 0"])
48
+ s.add_development_dependency(%q<fakeweb>, [">= 0"])
49
+ else
50
+ s.add_dependency(%q<rspec>, [">= 0"])
51
+ s.add_dependency(%q<fakeweb>, [">= 0"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<rspec>, [">= 0"])
55
+ s.add_dependency(%q<fakeweb>, [">= 0"])
56
+ end
57
+ end
@@ -0,0 +1,80 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe PayoneConnect do
4
+ before(:each) do
5
+ FakeWeb.register_uri(:post, "https://testapi.pay1.de/post-gateway/",:body => "status=APPROVED\ntxid=18059493\nuserid=4923401")
6
+ @request_data = {
7
+ :mode => "test",
8
+ :amount => 100,
9
+ :cardholder => "John Doe",
10
+ :currency => "CHF",
11
+ :mid => "12345",
12
+ :cardexpiredate => "1202",
13
+ :encoding => "UTF-8",
14
+ :key => "827ccb0eea8a706c4c34a16891f84e7b",
15
+ :aid => "54321",
16
+ :cardtype => "V",
17
+ :clearingtype => "cc",
18
+ :cardpan => "4901170005495083",
19
+ :request => "authorization",
20
+ :reference => "00000000000000000001",
21
+ :portalid => "1234567",
22
+ :cardcvc2 => 233
23
+ }
24
+ @finance_gate_connection = PayoneConnect.new("https://testapi.pay1.de/post-gateway/",@request_data)
25
+ @uri = URI.parse("https://testapi.pay1.de/post-gateway/")
26
+ end
27
+
28
+ describe "connection" do
29
+ it "should connect to the payone gateway" do
30
+ https_connection = Net::HTTP.new(@uri.host, @uri.port)
31
+ Net::HTTP.should_receive(:new).with(@uri.host,@uri.port).and_return(https_connection)
32
+ @finance_gate_connection.request
33
+ end
34
+
35
+ it "should set the x form header" do
36
+ @finance_gate_connection.request_header.should == {'Content-Type'=> 'application/x-www-form-urlencoded'}
37
+ end
38
+ end
39
+
40
+ describe "general parameter assignment" do
41
+ %w(portalid mid mode key encoding request).each do |parameter|
42
+ it "should set the #{parameter} parameter" do
43
+ @finance_gate_connection.request_data.should include("#{parameter}=#{@request_data[parameter]}")
44
+ end
45
+ end
46
+ end
47
+
48
+ describe "successfull request" do
49
+ before(:each) do
50
+ FakeWeb.register_uri(:post, "https://testapi.pay1.de/post-gateway/", :body => "status=APPROVED\ntxid=18059493\nuserid=4923401")
51
+ end
52
+ it "should return the status" do
53
+ @finance_gate_connection.request[:status].should == "APPROVED"
54
+ end
55
+
56
+ it "should return payones transaction id" do
57
+ @finance_gate_connection.request[:txid].should == "18059493"
58
+ end
59
+
60
+ it "should return payones user id" do
61
+ @finance_gate_connection.request[:userid].should == "4923401"
62
+ end
63
+ end
64
+
65
+ describe "authorization parameter assignment" do
66
+ %w(aid reference currency amount clearingtype).each do |parameter|
67
+ it "should set the #{parameter} parameter" do
68
+ @finance_gate_connection.request_data.should include("#{parameter}=#{@request_data[parameter]}")
69
+ end
70
+ end
71
+ end
72
+
73
+ describe "credit card payment parameter assignment" do
74
+ %w(cardpan cardtype cardexpiredate cardcvc2 cardholder).each do |parameter|
75
+ it "should set the #{parameter} parameter" do
76
+ @finance_gate_connection.request_data.should include("#{parameter}=#{URI.encode(@request_data[parameter].to_s)}")
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'payone_connect'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+ require 'rubygems'
7
+ require 'fake_web'
8
+
9
+ Spec::Runner.configure do |config|
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: payone_connect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Patrick Huesler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-03 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: fakeweb
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: Connects to the payone gateway and passes the parameters
36
+ email: patrick.huesler@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - lib/core_ext.rb
52
+ - lib/payone_connect.rb
53
+ - payone_connect.gemspec
54
+ - spec/payone_connect_spec.rb
55
+ - spec/spec_helper.rb
56
+ has_rdoc: true
57
+ homepage: http://github.com/phuesler/payone_connect
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options:
62
+ - --charset=UTF-8
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.3.5
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Simple http clinet for the psp payone api (http://www.payone.de/)
84
+ test_files:
85
+ - spec/payone_connect_spec.rb
86
+ - spec/spec_helper.rb