datatrans 1.0.0 → 2.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/.rvmrc +1 -0
- data/README.markdown +153 -9
- data/datatrans.gemspec +5 -0
- data/lib/datatrans.rb +9 -3
- data/lib/datatrans/common.rb +9 -0
- data/lib/datatrans/version.rb +1 -1
- data/lib/datatrans/web/transaction.rb +55 -0
- data/lib/datatrans/web/transaction/authorize.rb +68 -0
- data/lib/datatrans/xml/transaction.rb +47 -0
- data/lib/datatrans/xml/transaction/authorize.rb +83 -0
- data/lib/datatrans/xml/transaction/capture.rb +68 -0
- data/lib/datatrans/xml/transaction/request.rb +39 -0
- data/lib/datatrans/xml/transaction/response.rb +13 -0
- data/lib/datatrans/xml/transaction/void.rb +69 -0
- data/spec/common_spec.rb +20 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/web/authorize_spec.rb +128 -0
- data/spec/xml/authorizate_spec.rb +114 -0
- data/spec/xml/capture_spec.rb +103 -0
- data/spec/xml/void_spec.rb +103 -0
- metadata +105 -47
- data/lib/datatrans/notification.rb +0 -81
- data/lib/datatrans/transaction.rb +0 -79
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Datatrans::XML::Transaction::CaptureRequest do
|
4
|
+
before do
|
5
|
+
@successful_response = {
|
6
|
+
"paymentService" => {
|
7
|
+
"body" => {
|
8
|
+
"transaction" => {
|
9
|
+
"request" => {
|
10
|
+
"amount" => "1000",
|
11
|
+
"currency" => "CHF",
|
12
|
+
"uppTransactionId" => "110808142256858007",
|
13
|
+
"reqtype" => "COA",
|
14
|
+
"transtype" => "05"
|
15
|
+
},
|
16
|
+
"response" => {
|
17
|
+
"responseCode" => "01",
|
18
|
+
"responseMessage" => "settlement succeeded"
|
19
|
+
},
|
20
|
+
"refno" => "ABCDEF",
|
21
|
+
"trxStatus" => "response"
|
22
|
+
},
|
23
|
+
"merchantId" => "1100001872",
|
24
|
+
"status" => "accepted"
|
25
|
+
},
|
26
|
+
"version" => "1"
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
@failed_response = {
|
31
|
+
"paymentService" => {
|
32
|
+
"body" => {
|
33
|
+
"transaction" => {
|
34
|
+
"request" => {
|
35
|
+
"amount" => "1000",
|
36
|
+
"currency" => "CHF",
|
37
|
+
"uppTransactionId" => "110808143302868124",
|
38
|
+
"reqtype" => "DOA",
|
39
|
+
"transtype" => "05"
|
40
|
+
},
|
41
|
+
"error" => {
|
42
|
+
"errorCode" => "1010",
|
43
|
+
"errorMessage" => "cannot be settled",
|
44
|
+
"errorDetail" => "trx has another as authorized status: 92"
|
45
|
+
},
|
46
|
+
"refno" => "ABCDEF",
|
47
|
+
"trxStatus" => "response"
|
48
|
+
},
|
49
|
+
"merchantId" => "1100001872",
|
50
|
+
"status" => "accepted"
|
51
|
+
},
|
52
|
+
"version" => "1"
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
@valid_params = {
|
57
|
+
:refno => 'ABCDEF',
|
58
|
+
:amount => 1000,
|
59
|
+
:currency => 'CHF',
|
60
|
+
:transaction_id => '110808142256858007'
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
context "successful response" do
|
65
|
+
before do
|
66
|
+
Datatrans::XML::Transaction::CaptureRequest.any_instance.stub(:process).and_return(@successful_response)
|
67
|
+
end
|
68
|
+
|
69
|
+
context "build_capture_request" do
|
70
|
+
it "generates a valid datatrans capture xml" do
|
71
|
+
@request = Datatrans::XML::Transaction::CaptureRequest.new(@valid_params)
|
72
|
+
@request.send(:build_capture_request).should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?><paymentService version=\"1\"><body merchantId=\"1100000000\"><transaction refno=\"ABCDEF\"><request><amount>1000</amount><currency>CHF</currency><uppTransactionId>110808142256858007</uppTransactionId></request></transaction></body></paymentService>"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "process" do
|
77
|
+
it "handles a valid datatrans capture response" do
|
78
|
+
@transaction = Datatrans::XML::Transaction.new(@valid_params)
|
79
|
+
@transaction.capture.should be_true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "failed response" do
|
85
|
+
before do
|
86
|
+
Datatrans::XML::Transaction::CaptureRequest.any_instance.stub(:process).and_return(@failed_response)
|
87
|
+
@transaction = Datatrans::XML::Transaction.new(@valid_params)
|
88
|
+
end
|
89
|
+
|
90
|
+
context "process" do
|
91
|
+
it "handles a failed datatrans capture response" do
|
92
|
+
@transaction.capture.should be_false
|
93
|
+
end
|
94
|
+
|
95
|
+
it "returns error details" do
|
96
|
+
@transaction.capture
|
97
|
+
@transaction.error_code.length.should > 0
|
98
|
+
@transaction.error_message.length.should > 0
|
99
|
+
@transaction.error_detail.length.should > 0
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Datatrans::XML::Transaction::VoidRequest do
|
4
|
+
before do
|
5
|
+
@successful_response = {
|
6
|
+
"paymentService" => {
|
7
|
+
"body" => {
|
8
|
+
"transaction" => {
|
9
|
+
"request" => {
|
10
|
+
"amount" => "1000",
|
11
|
+
"currency" => "CHF",
|
12
|
+
"uppTransactionId" => "110808143302868124",
|
13
|
+
"reqtype" => "DOA",
|
14
|
+
"transtype" => "05"
|
15
|
+
},
|
16
|
+
"response" => {
|
17
|
+
"responseCode" => "01",
|
18
|
+
"responseMessage" => "cancellation succeeded"
|
19
|
+
},
|
20
|
+
"refno" => "ABCDEF",
|
21
|
+
"trxStatus" => "response"
|
22
|
+
},
|
23
|
+
"merchantId" => "1100001872",
|
24
|
+
"status" => "accepted"
|
25
|
+
},
|
26
|
+
"version" => "1"
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
@failed_response = {
|
31
|
+
"paymentService" => {
|
32
|
+
"body" => {
|
33
|
+
"transaction" => {
|
34
|
+
"request" => {
|
35
|
+
"amount" => "1000",
|
36
|
+
"currency" => "CHF",
|
37
|
+
"uppTransactionId" => "110808143302868124",
|
38
|
+
"reqtype" => "DOA",
|
39
|
+
"transtype" => "05"
|
40
|
+
},
|
41
|
+
"error" => {
|
42
|
+
"errorCode" => "1010",
|
43
|
+
"errorMessage" => "cannot be canceled",
|
44
|
+
"errorDetail" => "trx has not corresponding status: 82"
|
45
|
+
},
|
46
|
+
"refno" => "ABCDEF",
|
47
|
+
"trxStatus" => "response"
|
48
|
+
},
|
49
|
+
"merchantId" => "1100001872",
|
50
|
+
"status" => "accepted"
|
51
|
+
},
|
52
|
+
"version" => "1"
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
@valid_params = {
|
57
|
+
:refno => 'ABCDEF',
|
58
|
+
:amount => 1000,
|
59
|
+
:currency => 'CHF',
|
60
|
+
:transaction_id => '110808143302868124'
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
context "successful response" do
|
65
|
+
before do
|
66
|
+
Datatrans::XML::Transaction::VoidRequest.any_instance.stub(:process).and_return(@successful_response)
|
67
|
+
end
|
68
|
+
|
69
|
+
context "build_void_request" do
|
70
|
+
it "generates a valid datatrans void xml" do
|
71
|
+
@request = Datatrans::XML::Transaction::VoidRequest.new(@valid_params)
|
72
|
+
@request.send(:build_void_request).should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?><paymentService version=\"1\"><body merchantId=\"1100000000\"><transaction refno=\"ABCDEF\"><request><amount>1000</amount><currency>CHF</currency><uppTransactionId>110808143302868124</uppTransactionId><reqtype>DOA</reqtype></request></transaction></body></paymentService>"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "process" do
|
77
|
+
it "handles a valid datatrans void response" do
|
78
|
+
@transaction = Datatrans::XML::Transaction.new(@valid_params)
|
79
|
+
@transaction.void.should be_true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "failed response" do
|
85
|
+
before do
|
86
|
+
Datatrans::XML::Transaction::VoidRequest.any_instance.stub(:process).and_return(@failed_response)
|
87
|
+
@transaction = Datatrans::XML::Transaction.new(@valid_params)
|
88
|
+
end
|
89
|
+
|
90
|
+
context "process" do
|
91
|
+
it "handles a failed datatrans void response" do
|
92
|
+
@transaction.void.should be_false
|
93
|
+
end
|
94
|
+
|
95
|
+
it "returns error details" do
|
96
|
+
@transaction.void
|
97
|
+
@transaction.error_code.length.should > 0
|
98
|
+
@transaction.error_message.length.should > 0
|
99
|
+
@transaction.error_detail.length.should > 0
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
metadata
CHANGED
@@ -1,86 +1,144 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: datatrans
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
4
5
|
prerelease:
|
5
|
-
version: 1.0.0
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Tobias Miesel
|
9
9
|
- Thomas Maurer
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
|
14
|
-
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
13
|
+
date: 2011-08-09 00:00:00.000000000 +02:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
17
|
name: httparty
|
18
|
-
|
19
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
requirement: &70246968936500 !ruby/object:Gem::Requirement
|
20
19
|
none: false
|
21
|
-
requirements:
|
22
|
-
- -
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version:
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '0'
|
25
24
|
type: :runtime
|
26
|
-
version_requirements: *id001
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: activesupport
|
29
25
|
prerelease: false
|
30
|
-
|
26
|
+
version_requirements: *70246968936500
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: &70246968936000 !ruby/object:Gem::Requirement
|
31
30
|
none: false
|
32
|
-
requirements:
|
33
|
-
- -
|
34
|
-
- !ruby/object:Gem::Version
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
35
34
|
version: 3.0.0
|
36
35
|
type: :runtime
|
37
|
-
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *70246968936000
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: i18n
|
40
|
+
requirement: &70246968935580 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
type: :runtime
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *70246968935580
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: builder
|
51
|
+
requirement: &70246968935120 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
type: :runtime
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *70246968935120
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: rspec
|
62
|
+
requirement: &70246968934700 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: *70246968934700
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: actionpack
|
73
|
+
requirement: &70246968934200 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 3.0.0
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: *70246968934200
|
38
82
|
description: Datatrans Integration for Ruby on Rails
|
39
|
-
email:
|
83
|
+
email:
|
40
84
|
- tobias.miesel@simplificator.com
|
41
85
|
- thomas.maurer@simplificator.com
|
42
86
|
executables: []
|
43
|
-
|
44
87
|
extensions: []
|
45
|
-
|
46
88
|
extra_rdoc_files: []
|
47
|
-
|
48
|
-
files:
|
89
|
+
files:
|
49
90
|
- .gitignore
|
91
|
+
- .rvmrc
|
50
92
|
- Gemfile
|
51
93
|
- README.markdown
|
52
94
|
- Rakefile
|
53
95
|
- datatrans.gemspec
|
54
96
|
- lib/datatrans.rb
|
55
|
-
- lib/datatrans/
|
56
|
-
- lib/datatrans/transaction.rb
|
97
|
+
- lib/datatrans/common.rb
|
57
98
|
- lib/datatrans/version.rb
|
58
|
-
|
99
|
+
- lib/datatrans/web/transaction.rb
|
100
|
+
- lib/datatrans/web/transaction/authorize.rb
|
101
|
+
- lib/datatrans/xml/transaction.rb
|
102
|
+
- lib/datatrans/xml/transaction/authorize.rb
|
103
|
+
- lib/datatrans/xml/transaction/capture.rb
|
104
|
+
- lib/datatrans/xml/transaction/request.rb
|
105
|
+
- lib/datatrans/xml/transaction/response.rb
|
106
|
+
- lib/datatrans/xml/transaction/void.rb
|
107
|
+
- spec/common_spec.rb
|
108
|
+
- spec/spec_helper.rb
|
109
|
+
- spec/web/authorize_spec.rb
|
110
|
+
- spec/xml/authorizate_spec.rb
|
111
|
+
- spec/xml/capture_spec.rb
|
112
|
+
- spec/xml/void_spec.rb
|
113
|
+
has_rdoc: true
|
114
|
+
homepage: ''
|
59
115
|
licenses: []
|
60
|
-
|
61
116
|
post_install_message:
|
62
117
|
rdoc_options: []
|
63
|
-
|
64
|
-
require_paths:
|
118
|
+
require_paths:
|
65
119
|
- lib
|
66
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
121
|
none: false
|
68
|
-
requirements:
|
69
|
-
- -
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
version:
|
72
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
127
|
none: false
|
74
|
-
requirements:
|
75
|
-
- -
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version:
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
78
132
|
requirements: []
|
79
|
-
|
80
133
|
rubyforge_project: datatrans
|
81
|
-
rubygems_version: 1.
|
134
|
+
rubygems_version: 1.6.2
|
82
135
|
signing_key:
|
83
136
|
specification_version: 3
|
84
137
|
summary: Datatrans Integration for Ruby on Rails
|
85
|
-
test_files:
|
86
|
-
|
138
|
+
test_files:
|
139
|
+
- spec/common_spec.rb
|
140
|
+
- spec/spec_helper.rb
|
141
|
+
- spec/web/authorize_spec.rb
|
142
|
+
- spec/xml/authorizate_spec.rb
|
143
|
+
- spec/xml/capture_spec.rb
|
144
|
+
- spec/xml/void_spec.rb
|
@@ -1,81 +0,0 @@
|
|
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
|