datatrans 2.2.1 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,6 +14,8 @@ Set your datatrans credentials in your environment.
14
14
  config.environment = :production
15
15
  end
16
16
 
17
+ If you don't want to use signed requests (disabled in datatrans web console), you must set `config.sign_key` to `false`.
18
+
17
19
  Possible values for the environment: `:production`, `:development`
18
20
 
19
21
  Web Authorization
@@ -30,36 +32,36 @@ You need to pass at least `amount`, `currency` and `refno` (order number).
30
32
  :uppCustomerEmail => 'customer@email.com'
31
33
  # feel free to add more upp infos here ...
32
34
  })
33
-
35
+
34
36
  In your View your show the credit card form with a convenient helper:
35
37
 
36
38
  = form_tag Datatrans.web_authorize_url do
37
-
39
+
38
40
  = text_field_tag :paymentmethod, 'ECA'
39
41
  = text_field_tag :cardno
40
42
  = text_field_tag :expm
41
43
  = text_field_tag :expy
42
44
  = text_field_tag :cvv
43
-
45
+
44
46
  = hidden_field_tag :successUrl, <your_application_return_url>
45
47
  = hidden_field_tag :cancelUrl, <your_application_return_url>
46
48
  = hidden_field_tag :errorUrl, <your_application_return_url>
47
-
49
+
48
50
  = datatrans_notification_request_hidden_fields(@transaction)
49
-
51
+
50
52
  = submit_tag "send"
51
-
53
+
52
54
  In this example we use just ECA (Mastercard) as paymentmethod. Feel free to
53
55
  provide an appropriate select field to offer more payment methods. Don't forget
54
56
  to add `successUrl`, `cancelUrl` and `errorUrl`. We recommend to set them all
55
57
  to the same value.
56
-
58
+
57
59
  After you submit the request to Datatrans they redirect back to your application.
58
60
  Now you can process the transaction like this:
59
61
 
60
62
  begin
61
63
  transaction = Datatrans::Web::Transaction.new(params)
62
-
64
+
63
65
  if transaction.authorize
64
66
  # transaction was successful, access the following attributes
65
67
  # transaction.transaction_id
@@ -67,16 +69,16 @@ Now you can process the transaction like this:
67
69
  # transaction.masked_cc
68
70
  # transaction.authorization_code
69
71
  # ...
70
-
72
+
71
73
  else
72
74
  # transaction was not successful, accces the error details
73
75
  # transaction.error_code, transaction.error_message, transaction.error_detail
74
-
75
- end
76
+
77
+ end
76
78
  rescue Datatrans::InvalidSignatureError => exception
77
79
  # the signature was wrong, the request may have been compromised...
78
80
  end
79
-
81
+
80
82
  XML Transactions
81
83
  ================
82
84
 
@@ -94,7 +96,7 @@ Authorize
94
96
  :expm => 12,
95
97
  :expy => 15
96
98
  )
97
-
99
+
98
100
  if transaction.authorize
99
101
  # ok, the transaction is authorized...
100
102
  # access same values as in the web authorization (e.g. transaction.transaction_id)
@@ -114,13 +116,13 @@ To capture an authorized transaction you use the following code:
114
116
  :currency => 'CHF',
115
117
  :transaction_id => 19834324987349723948729834
116
118
  )
117
-
119
+
118
120
  if transaction.capture
119
121
  # ok, the money is yours...
120
122
  else
121
123
  # transaction.error_code, transaction.error_message, transaction.error_detail
122
124
  end
123
-
125
+
124
126
 
125
127
  Void
126
128
  ----
@@ -133,7 +135,7 @@ To make an authorized transaction invalid use void.
133
135
  :currency => 'CHF',
134
136
  :transaction_id => 19834324987349723948729834
135
137
  )
136
-
138
+
137
139
  if transaction.void
138
140
  # ok, the transaction is not longer valid...
139
141
  else
@@ -141,6 +143,14 @@ To make an authorized transaction invalid use void.
141
143
  end
142
144
 
143
145
 
146
+ CHANGELOG
147
+ =========
148
+
149
+ 2.2.2
150
+ -------
151
+ * added ability to skip signing by setting config.sign_key = false
152
+
153
+
144
154
  Todo
145
155
  ====
146
156
 
@@ -163,7 +173,7 @@ Contribute
163
173
  * Commit, do not mess with rakefile, version, or history.
164
174
  (if you want to have your own version, that is fine but bump version in a commit by itself we can ignore when we pull)
165
175
  * Send us a pull request. Bonus points for topic branches.
166
-
176
+
167
177
 
168
178
  Credits
169
179
  =======
@@ -2,6 +2,7 @@ require 'openssl'
2
2
 
3
3
  module Datatrans::Common
4
4
  def sign(*fields)
5
+ return nil unless Datatrans.sign_key
5
6
  key = Datatrans.sign_key.split(/([a-f0-9][a-f0-9])/).reject(&:empty?)
6
7
  key = key.pack("H*" * key.size)
7
8
  OpenSSL::HMAC.hexdigest(OpenSSL::Digest::MD5.new, key, fields.join)
@@ -1,3 +1,3 @@
1
1
  module Datatrans
2
- VERSION = "2.2.1"
2
+ VERSION = "2.2.2"
3
3
  end
@@ -3,28 +3,28 @@ require 'active_support/core_ext/hash'
3
3
  module Datatrans::Web
4
4
  class Transaction
5
5
  include Datatrans::Common
6
-
6
+
7
7
  attr_accessor :request
8
8
  attr_reader :response, :params
9
-
9
+
10
10
  def initialize(params)
11
- raise 'Please define Datatrans.sign_key!' unless Datatrans.sign_key.present?
11
+ raise 'Please define Datatrans.sign_key or set it to false!' unless Datatrans.sign_key == false || Datatrans.sign_key.present?
12
12
 
13
13
  params = params.to_hash
14
14
  params.symbolize_keys!
15
- params.reverse_merge!({ :reqtype => 'NOA', :useAlias => 'Yes', :hiddenMode => 'Yes' })
15
+ params.reverse_merge!(:reqtype => 'NOA', :useAlias => 'yes', :hiddenMode => 'yes')
16
16
  @params = params
17
17
  end
18
-
18
+
19
19
  def signature
20
20
  sign(Datatrans.merchant_id, params[:amount], params[:currency], params[:refno])
21
21
  end
22
-
22
+
23
23
  def authorize
24
24
  @response = AuthorizeResponse.new(params)
25
25
  @response.successful?
26
26
  end
27
-
27
+
28
28
  def method_missing(method, *args, &block)
29
29
  if response.respond_to? method.to_sym
30
30
  response.send(method)
@@ -33,7 +33,7 @@ module Datatrans::Web
33
33
  end
34
34
  end
35
35
  end
36
-
36
+
37
37
  module ViewHelper
38
38
  def datatrans_notification_request_hidden_fields(transaction)
39
39
  fields = [
@@ -46,13 +46,13 @@ module Datatrans::Web
46
46
  hidden_field_tag(:sign, transaction.signature),
47
47
  hidden_field_tag(:refno, transaction.params[:refno]),
48
48
  ]
49
-
49
+
50
50
  [:uppCustomerName, :uppCustomerEmail].each do |field_name|
51
51
  if transaction.params[field_name].present?
52
52
  fields << hidden_field_tag(field_name, transaction.params[field_name])
53
53
  end
54
54
  end
55
-
55
+
56
56
  fields.join.html_safe
57
57
  end
58
58
  end
@@ -5,59 +5,59 @@ require 'spec_helper'
5
5
  describe Datatrans::Web::Transaction do
6
6
  before do
7
7
  @successful_response = {
8
- :status => "success",
9
- :returnCustomerCountry => "CHE",
10
- :sign => "95f3111123e628eab6469c636e0d3f06",
11
- :aliasCC => "70323122544311173",
12
- :maskedCC => "520000xxxxxx0007",
13
- :responseMessage => "Authorized",
14
- :useAlias => "Yes",
15
- :expm => "12",
16
- :responseCode => "01",
17
- :sign2 => "a9571428be4d9d37b88988656984bfbf",
18
- :testOnly => "yes",
19
- :currency => "CHF",
20
- :amount => "1000",
21
- :hiddenMode => "yes",
22
- :expy => "15",
23
- :merchantId => "1100000000",
24
- :authorizationCode => "521029462",
25
- :uppTransactionId => "110808173520119430",
26
- :refno => "1",
27
- :uppMsgType => "web",
28
- :uppCustomerName => "",
29
- :pmethod => "ECA",
30
- :reqtype => "NOA",
31
- :uppCustomerEmail => "customer@email.com",
8
+ :status => "success",
9
+ :returnCustomerCountry => "CHE",
10
+ :sign => "95f3111123e628eab6469c636e0d3f06",
11
+ :aliasCC => "70323122544311173",
12
+ :maskedCC => "520000xxxxxx0007",
13
+ :responseMessage => "Authorized",
14
+ :useAlias => "yes",
15
+ :expm => "12",
16
+ :responseCode => "01",
17
+ :sign2 => "a9571428be4d9d37b88988656984bfbf",
18
+ :testOnly => "yes",
19
+ :currency => "CHF",
20
+ :amount => "1000",
21
+ :hiddenMode => "yes",
22
+ :expy => "15",
23
+ :merchantId => "1100000000",
24
+ :authorizationCode => "521029462",
25
+ :uppTransactionId => "110808173520119430",
26
+ :refno => "1",
27
+ :uppMsgType => "web",
28
+ :uppCustomerName => "",
29
+ :pmethod => "ECA",
30
+ :reqtype => "NOA",
31
+ :uppCustomerEmail => "customer@email.com",
32
32
  :acqAuthorizationCode => "173520"
33
33
  }
34
-
34
+
35
35
  @failed_response = {
36
- :status => "error",
37
- :returnCustomerCountry => "CHE",
38
- :sign => "95f3123246e628eab6469c636e0d3f06",
39
- :aliasCC => "70323122544311173",
40
- :maskedCC => "520000xxxxxx0007",
41
- :errorMessage => "declined",
42
- :useAlias => "Yes",
43
- :expm => "12",
44
- :errorCode => "1403",
45
- :testOnly => "yes",
46
- :currency => "CHF",
47
- :amount => "1000",
48
- :hiddenMode => "yes",
49
- :expy => "14",
50
- :merchantId => "1100000000",
51
- :errorDetail => "Declined",
52
- :uppTransactionId => "110808173951050102",
53
- :refno => "1",
54
- :uppMsgType => "web",
55
- :uppCustomerName => "",
56
- :pmethod => "ECA",
57
- :reqtype => "NOA",
36
+ :status => "error",
37
+ :returnCustomerCountry => "CHE",
38
+ :sign => "95f3123246e628eab6469c636e0d3f06",
39
+ :aliasCC => "70323122544311173",
40
+ :maskedCC => "520000xxxxxx0007",
41
+ :errorMessage => "declined",
42
+ :useAlias => "yes",
43
+ :expm => "12",
44
+ :errorCode => "1403",
45
+ :testOnly => "yes",
46
+ :currency => "CHF",
47
+ :amount => "1000",
48
+ :hiddenMode => "yes",
49
+ :expy => "14",
50
+ :merchantId => "1100000000",
51
+ :errorDetail => "Declined",
52
+ :uppTransactionId => "110808173951050102",
53
+ :refno => "1",
54
+ :uppMsgType => "web",
55
+ :uppCustomerName => "",
56
+ :pmethod => "ECA",
57
+ :reqtype => "NOA",
58
58
  :uppCustomerEmail => "customer@email.com"
59
59
  }
60
-
60
+
61
61
  @valid_params = {
62
62
  :refno => 'ABCDEF',
63
63
  :amount => 1000,
@@ -66,23 +66,23 @@ describe Datatrans::Web::Transaction do
66
66
  # also params from view helper needed
67
67
  }
68
68
  end
69
-
69
+
70
70
  context "rails form helper" do
71
71
  before do
72
72
  @transaction = Datatrans::Web::Transaction.new(@valid_params)
73
73
  @view = ActionView::Base.new
74
74
  end
75
-
75
+
76
76
  it "should generate valid form field string" do
77
- @view.datatrans_notification_request_hidden_fields(@transaction).should == "<input id=\"merchantId\" name=\"merchantId\" type=\"hidden\" value=\"1100000000\" /><input id=\"hiddenMode\" name=\"hiddenMode\" type=\"hidden\" value=\"Yes\" /><input id=\"reqtype\" name=\"reqtype\" type=\"hidden\" value=\"NOA\" /><input id=\"amount\" name=\"amount\" type=\"hidden\" value=\"1000\" /><input id=\"currency\" name=\"currency\" type=\"hidden\" value=\"CHF\" /><input id=\"useAlias\" name=\"useAlias\" type=\"hidden\" value=\"Yes\" /><input id=\"sign\" name=\"sign\" type=\"hidden\" value=\"0402fb3fba8c6fcb40df9b7756e7e637\" /><input id=\"refno\" name=\"refno\" type=\"hidden\" value=\"ABCDEF\" /><input id=\"uppCustomerEmail\" name=\"uppCustomerEmail\" type=\"hidden\" value=\"customer@email.com\" />"
77
+ @view.datatrans_notification_request_hidden_fields(@transaction).should == "<input id=\"merchantId\" name=\"merchantId\" type=\"hidden\" value=\"1100000000\" /><input id=\"hiddenMode\" name=\"hiddenMode\" type=\"hidden\" value=\"yes\" /><input id=\"reqtype\" name=\"reqtype\" type=\"hidden\" value=\"NOA\" /><input id=\"amount\" name=\"amount\" type=\"hidden\" value=\"1000\" /><input id=\"currency\" name=\"currency\" type=\"hidden\" value=\"CHF\" /><input id=\"useAlias\" name=\"useAlias\" type=\"hidden\" value=\"yes\" /><input id=\"sign\" name=\"sign\" type=\"hidden\" value=\"0402fb3fba8c6fcb40df9b7756e7e637\" /><input id=\"refno\" name=\"refno\" type=\"hidden\" value=\"ABCDEF\" /><input id=\"uppCustomerEmail\" name=\"uppCustomerEmail\" type=\"hidden\" value=\"customer@email.com\" />"
78
78
  end
79
79
  end
80
-
80
+
81
81
  context "successful response" do
82
82
  before do
83
83
  Datatrans::Web::Transaction::AuthorizeResponse.any_instance.stub(:params).and_return(@successful_response)
84
84
  end
85
-
85
+
86
86
  context "process" do
87
87
  it "handles a valid datatrans authorize response" do
88
88
  @transaction = Datatrans::Web::Transaction.new(@valid_params)
@@ -90,7 +90,7 @@ describe Datatrans::Web::Transaction do
90
90
  end
91
91
  end
92
92
  end
93
-
93
+
94
94
  context "compromised response" do
95
95
  before do
96
96
  fake_response = @successful_response
@@ -98,25 +98,25 @@ describe Datatrans::Web::Transaction do
98
98
  Datatrans::Web::Transaction::AuthorizeResponse.any_instance.stub(:params).and_return(fake_response)
99
99
  @transaction = Datatrans::Web::Transaction.new(@valid_params)
100
100
  end
101
-
101
+
102
102
  it "raises an exception if sign2 is invalid" do
103
103
  expect {
104
104
  @transaction.authorize
105
105
  }.to raise_error(Datatrans::InvalidSignatureError)
106
106
  end
107
107
  end
108
-
108
+
109
109
  context "failed response" do
110
110
  before do
111
111
  Datatrans::Web::Transaction::AuthorizeResponse.any_instance.stub(:params).and_return(@failed_response)
112
112
  @transaction = Datatrans::Web::Transaction.new(@valid_params)
113
113
  end
114
-
114
+
115
115
  context "process" do
116
116
  it "handles a failed datatrans authorize response" do
117
117
  @transaction.authorize.should be_false
118
118
  end
119
-
119
+
120
120
  it "returns error details" do
121
121
  @transaction.authorize
122
122
  @transaction.error_code.length.should > 0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datatrans
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,12 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-08-26 00:00:00.000000000Z
13
+ date: 2011-10-11 00:00:00.000000000 +02:00
14
+ default_executable:
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: httparty
17
- requirement: &2152354120 !ruby/object:Gem::Requirement
18
+ requirement: &70124632684580 !ruby/object:Gem::Requirement
18
19
  none: false
19
20
  requirements:
20
21
  - - ! '>='
@@ -22,10 +23,10 @@ dependencies:
22
23
  version: '0'
23
24
  type: :runtime
24
25
  prerelease: false
25
- version_requirements: *2152354120
26
+ version_requirements: *70124632684580
26
27
  - !ruby/object:Gem::Dependency
27
28
  name: activesupport
28
- requirement: &2152353620 !ruby/object:Gem::Requirement
29
+ requirement: &70124632684020 !ruby/object:Gem::Requirement
29
30
  none: false
30
31
  requirements:
31
32
  - - ! '>='
@@ -33,10 +34,10 @@ dependencies:
33
34
  version: 3.0.0
34
35
  type: :runtime
35
36
  prerelease: false
36
- version_requirements: *2152353620
37
+ version_requirements: *70124632684020
37
38
  - !ruby/object:Gem::Dependency
38
39
  name: i18n
39
- requirement: &2152353200 !ruby/object:Gem::Requirement
40
+ requirement: &70124632683320 !ruby/object:Gem::Requirement
40
41
  none: false
41
42
  requirements:
42
43
  - - ! '>='
@@ -44,10 +45,10 @@ dependencies:
44
45
  version: '0'
45
46
  type: :runtime
46
47
  prerelease: false
47
- version_requirements: *2152353200
48
+ version_requirements: *70124632683320
48
49
  - !ruby/object:Gem::Dependency
49
50
  name: builder
50
- requirement: &2152352740 !ruby/object:Gem::Requirement
51
+ requirement: &70124632682440 !ruby/object:Gem::Requirement
51
52
  none: false
52
53
  requirements:
53
54
  - - ! '>='
@@ -55,10 +56,10 @@ dependencies:
55
56
  version: '0'
56
57
  type: :runtime
57
58
  prerelease: false
58
- version_requirements: *2152352740
59
+ version_requirements: *70124632682440
59
60
  - !ruby/object:Gem::Dependency
60
61
  name: rspec
61
- requirement: &2152352320 !ruby/object:Gem::Requirement
62
+ requirement: &70124632681860 !ruby/object:Gem::Requirement
62
63
  none: false
63
64
  requirements:
64
65
  - - ! '>='
@@ -66,10 +67,10 @@ dependencies:
66
67
  version: '0'
67
68
  type: :development
68
69
  prerelease: false
69
- version_requirements: *2152352320
70
+ version_requirements: *70124632681860
70
71
  - !ruby/object:Gem::Dependency
71
72
  name: actionpack
72
- requirement: &2152351820 !ruby/object:Gem::Requirement
73
+ requirement: &70124632681360 !ruby/object:Gem::Requirement
73
74
  none: false
74
75
  requirements:
75
76
  - - ! '>='
@@ -77,7 +78,7 @@ dependencies:
77
78
  version: 3.0.0
78
79
  type: :development
79
80
  prerelease: false
80
- version_requirements: *2152351820
81
+ version_requirements: *70124632681360
81
82
  description: Datatrans Integration for Ruby on Rails
82
83
  email:
83
84
  - tobias.miesel@simplificator.com
@@ -109,6 +110,7 @@ files:
109
110
  - spec/xml/authorize_spec.rb
110
111
  - spec/xml/capture_spec.rb
111
112
  - spec/xml/void_spec.rb
113
+ has_rdoc: true
112
114
  homepage: ''
113
115
  licenses: []
114
116
  post_install_message:
@@ -129,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
131
  version: '0'
130
132
  requirements: []
131
133
  rubyforge_project: datatrans
132
- rubygems_version: 1.7.2
134
+ rubygems_version: 1.6.2
133
135
  signing_key:
134
136
  specification_version: 3
135
137
  summary: Datatrans Integration for Ruby on Rails