datatrans 1.0.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/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in datatrans.gemspec
4
+ gemspec
data/README.markdown ADDED
@@ -0,0 +1,40 @@
1
+ Datatrans
2
+ =========
3
+
4
+ Ruby adapter for the Datatrans payment gateway (http://www.datatrans.ch).
5
+
6
+ Usage
7
+ =====
8
+
9
+ Configuration
10
+ -------------
11
+
12
+ Datatrans.configure do |config|
13
+ config.merchant_id = '1234567'
14
+ config.sign_key = '...'
15
+ config.environment = :production
16
+ end
17
+
18
+ Possible values for the environment: `:production`, `:development`
19
+
20
+ Controller
21
+ ----------
22
+
23
+ TODO
24
+
25
+ View
26
+ ----
27
+
28
+ TODO
29
+
30
+ Credits
31
+ =======
32
+
33
+ Datatrans is maintained by Simplificator GmbH (http://simplificator.com).
34
+
35
+ The initial development was sponsered by Evita AG and Limmex AG.
36
+
37
+ License
38
+ =======
39
+
40
+ Datatrans is released under the MIT license.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/datatrans.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "datatrans/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "datatrans"
7
+ s.version = Datatrans::VERSION
8
+ s.authors = ["Tobias Miesel", "Thomas Maurer"]
9
+ s.email = ["tobias.miesel@simplificator.com", "thomas.maurer@simplificator.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Datatrans Integration for Ruby on Rails}
12
+ s.description = %q{Datatrans Integration for Ruby on Rails}
13
+
14
+ s.rubyforge_project = "datatrans"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency 'httparty'
22
+ s.add_dependency 'activesupport', '>= 3.0.0'
23
+ end
data/lib/datatrans.rb ADDED
@@ -0,0 +1,47 @@
1
+ module Datatrans
2
+ BASE_URL = 'https://payment.datatrans.biz'
3
+ WEB_AUTHORIZE_URL = "#{BASE_URL}/upp/jsp/upStart.jsp"
4
+ XML_AUTHORIZE_URL = "#{BASE_URL}/upp/jsp/XML_authorize.jsp"
5
+ XML_SETTLEMENT_URL = "#{BASE_URL}/upp/jsp/XML_processor.jsp"
6
+
7
+ TEST_BASE_URL = 'https://pilot.datatrans.biz'
8
+ TEST_WEB_AUTHORIZE_URL = "#{TEST_BASE_URL}/upp/jsp/upStart.jsp"
9
+ TEST_XML_AUTHORIZE_URL = "#{TEST_BASE_URL}/upp/jsp/XML_authorize.jsp"
10
+ TEST_XML_SETTLEMENT_URL = "#{TEST_BASE_URL}/upp/jsp/XML_processor.jsp"
11
+
12
+ mattr_accessor :merchant_id
13
+ mattr_accessor :sign_key
14
+
15
+ mattr_reader :base_url
16
+ mattr_reader :web_authorize_url
17
+ mattr_reader :xml_authorize_url
18
+ mattr_reader :xml_settlement_url
19
+
20
+ def self.configure
21
+ self.environment = :development # default
22
+ yield self
23
+ end
24
+
25
+ def self.environment=(environment)
26
+ case environment
27
+ when :development
28
+ @@base_url = TEST_BASE_URL
29
+ @@web_authorize_url = TEST_WEB_AUTHORIZE_URL
30
+ @@xml_authorize_url = TEST_XML_AUTHORIZE_URL
31
+ @@xml_settlement_url = TEST_XML_SETTLEMENT_URL
32
+ when :production
33
+ @@base_url = BASE_URL
34
+ @@web_authorize_url = WEB_AUTHORIZE_URL
35
+ @@xml_authorize_url = XML_AUTHORIZE_URL
36
+ @@xml_settlement_url = XML_SETTLEMENT_URL
37
+ else
38
+ raise "Unknown environment '#{environment}'. Available: :development, :production."
39
+ end
40
+ end
41
+ end
42
+
43
+ require 'datatrans/version'
44
+ require 'datatrans/notification'
45
+ require 'datatrans/transaction'
46
+
47
+ ActionView::Base.send :include, Datatrans::Notification::ViewHelper if defined? ActionView
@@ -0,0 +1,81 @@
1
+ module Datatrans::Notification
2
+ class InvalidSignatureError < StandardError; end
3
+
4
+ class Base
5
+ attr_reader :params
6
+
7
+ def initialize(params)
8
+ raise 'Please define Datatrans.sign_key!' unless Datatrans.sign_key.present?
9
+
10
+ params = params.to_hash
11
+ params.symbolize_keys!
12
+ params.reverse_merge!({ :reqtype => 'NOA', :useAlias => 'Yes', :hiddenMode => 'Yes' })
13
+ @params = params
14
+ end
15
+
16
+ def reference_number
17
+ params[:refno]
18
+ end
19
+
20
+ protected
21
+
22
+ def sign(*fields)
23
+ key = Datatrans.sign_key.split(/([a-f0-9][a-f0-9])/).reject(&:empty?)
24
+ key = key.pack("H*" * key.size)
25
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest::MD5.new, key, fields.join)
26
+ end
27
+ end
28
+
29
+ class Request < Base
30
+ def signature
31
+ sign(Datatrans.merchant_id, params[:amount], params[:currency], params[:refno])
32
+ end
33
+ end
34
+
35
+ class Response < Base
36
+ def valid_signature?
37
+ sign(Datatrans.merchant_id, params[:amount], params[:currency], params[:uppTransactionId]) == params[:sign2]
38
+ end
39
+
40
+ def transaction_id
41
+ params[:uppTransactionId]
42
+ end
43
+
44
+ def creditcard_alias
45
+ params[:aliasCC]
46
+ end
47
+
48
+ def payment_method
49
+ params[:pmethod]
50
+ end
51
+
52
+ def success?
53
+ params[:status] == 'success'
54
+ end
55
+
56
+ def cancel?
57
+ params[:status] == 'cancel'
58
+ end
59
+
60
+ def error?
61
+ params[:status] == 'error'
62
+ end
63
+ end
64
+
65
+ module ViewHelper
66
+ def datatrans_notification_request_hidden_fields(request)
67
+ [
68
+ hidden_field_tag(:merchantId, Datatrans.merchant_id),
69
+ hidden_field_tag(:hiddenMode, request.params[:hiddenMode]),
70
+ hidden_field_tag(:reqtype, request.params[:reqtype]),
71
+ hidden_field_tag(:amount, request.params[:amount]),
72
+ hidden_field_tag(:currency, request.params[:currency]),
73
+ hidden_field_tag(:useAlias, request.params[:useAlias]),
74
+ hidden_field_tag(:sign, request.signature),
75
+ hidden_field_tag(:refno, request.params[:refno]),
76
+ hidden_field_tag(:uppCustomerName, request.params[:uppCustomerName]),
77
+ hidden_field_tag(:uppCustomerEmail, request.params[:uppCustomerEmail])
78
+ ].join.html_safe
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,79 @@
1
+ require 'httparty'
2
+
3
+ class Datatrans::Transaction
4
+ include HTTParty
5
+
6
+ attr_reader :params
7
+
8
+ def initialize(params)
9
+ @params = params.symbolize_keys
10
+ end
11
+
12
+ def authorize
13
+ @response = self.class.post(Datatrans.xml_authorize_url,
14
+ :headers => { 'Content-Type' => 'text/xml' },
15
+ :body => build_authorize_request.to_s).parsed_response
16
+ end
17
+
18
+ def capture
19
+ @response = self.class.post(Datatrans.xml_settlement_url,
20
+ :headers => { 'Content-Type' => 'text/xml' },
21
+ :body => build_capture_request.to_s).parsed_response
22
+ end
23
+
24
+ def void
25
+ @response = self.class.post(Datatrans.xml_settlement_url,
26
+ :headers => { 'Content-Type' => 'text/xml' },
27
+ :body => build_void_request.to_s).parsed_response
28
+ end
29
+
30
+ def success?
31
+ @response['paymentService']['body']['transaction']['response'].present? rescue false
32
+ end
33
+
34
+ def error?
35
+ @response['paymentService']['body']['transaction']['error'].present? rescue false
36
+ end
37
+
38
+ private
39
+
40
+ def build_xml_request(service)
41
+ xml = Builder::XmlMarkup.new
42
+ xml.instruct!
43
+ xml.tag! "#{service}Service", :version => 1 do
44
+ xml.body :merchantId => Datatrans.merchant_id do |body|
45
+ xml.transaction :refno => params[:refno] do
46
+ xml.request do
47
+ yield body
48
+ end
49
+ end
50
+ end
51
+ end
52
+ xml.target!
53
+ end
54
+
55
+ def build_authorize_request
56
+ build_xml_request(:authorization) do |xml|
57
+ xml.amount params[:amount]
58
+ xml.currency params[:currency]
59
+ xml.aliasCC params[:aliasCC]
60
+ end
61
+ end
62
+
63
+ def build_capture_request
64
+ build_xml_request(:payment) do |xml|
65
+ xml.amount params[:amount]
66
+ xml.currency params[:currency]
67
+ xml.uppTransactionId params[:transaction_id]
68
+ end
69
+ end
70
+
71
+ def build_void_request
72
+ build_xml_request(:payment) do |xml|
73
+ xml.amount params[:amount]
74
+ xml.currency params[:currency]
75
+ xml.uppTransactionId params[:transaction_id]
76
+ xml.reqtype 'DOA'
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,3 @@
1
+ module Datatrans
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: datatrans
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.0
6
+ platform: ruby
7
+ authors:
8
+ - Tobias Miesel
9
+ - Thomas Maurer
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2011-07-07 00:00:00 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: httparty
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 3.0.0
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ description: Datatrans Integration for Ruby on Rails
39
+ email:
40
+ - tobias.miesel@simplificator.com
41
+ - thomas.maurer@simplificator.com
42
+ executables: []
43
+
44
+ extensions: []
45
+
46
+ extra_rdoc_files: []
47
+
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - README.markdown
52
+ - Rakefile
53
+ - datatrans.gemspec
54
+ - lib/datatrans.rb
55
+ - lib/datatrans/notification.rb
56
+ - lib/datatrans/transaction.rb
57
+ - lib/datatrans/version.rb
58
+ homepage: ""
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options: []
63
+
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ requirements: []
79
+
80
+ rubyforge_project: datatrans
81
+ rubygems_version: 1.7.2
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Datatrans Integration for Ruby on Rails
85
+ test_files: []
86
+