datatrans 4.0.0 → 5.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.markdown +1 -0
- data/lib/datatrans/config.rb +4 -1
- data/lib/datatrans/version.rb +1 -1
- data/lib/datatrans/web/transaction/authorize.rb +6 -2
- data/lib/datatrans/xml/transaction/request.rb +4 -2
- data/spec/config_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/web/authorize_spec.rb +20 -1
- data/spec/xml/request_spec.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb01c19e9afe3aecaa82ff08e7e9024fefb8c60d3cab86fbd3400e4598879dcd
|
4
|
+
data.tar.gz: 13a9c7a7068610907a8123c11cf50f60014f79b5de6db2b51f763a5509159fb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8d2cc670be21be5336b8856eca9603ef8351be8ebc9e8e19efca2486a2304d7a8701fcabeea629285434dcd4b6c99cf8f53b8382870cbd0a7dbf38db7b6ded2
|
7
|
+
data.tar.gz: a13b4a7a1934bfa437209b9eb53b2c8bba45d3e0c7e24cb699e8544c7d2af67d6497a0a1c885e3d6af034030b3b0b077d5928a4e8e6577a2b606824c1752be22
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,17 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
5
5
|
|
6
6
|
## [Unreleased]
|
7
7
|
|
8
|
+
## 5.0.0 - 2022-09-21
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
|
12
|
+
* [BREAKING CHANGE] Authenticate requests with HTTP Basic Auth (@crackofdusk [#41](https://github.com/simplificator/datatrans/pull/41))
|
13
|
+
|
14
|
+
Datatrans requires [HTTP Basic Auth for XML API calls](https://api-reference.datatrans.ch/xml/#authentication-tls) since 2022-09-14 ([announcement](https://mailchi.mp/datatrans/basic-authsign2_1-email_en))
|
15
|
+
|
16
|
+
## 4.0.1 - 2022-03-18
|
17
|
+
### Fixed
|
18
|
+
* Check for successful transaction depends on `status` and not on `response_message` that can be diferent for different payment methods (@schmijos [#8](https://github.com/simplificator/datatrans/pull/8) and @TatianaPan [#39](https://github.com/simplificator/datatrans/pull/39))
|
8
19
|
## 4.0.0 - 2022-02-25
|
9
20
|
### Changed
|
10
21
|
* [BREAKING CHANGE] Bump minimum required Ruby version to 2.6 and Rails to 5.2 (@andyundso [#34](https://github.com/simplificator/datatrans/pull/34))
|
data/README.markdown
CHANGED
@@ -11,6 +11,7 @@ Build your Datatrans Configuration like so:
|
|
11
11
|
datatrans = Datatrans::Config.new(
|
12
12
|
:merchant_id => '1234567',
|
13
13
|
:sign_key => 'ab739fd5b7c2a1...',
|
14
|
+
:password => 'server to server request password',
|
14
15
|
:environment => :production,
|
15
16
|
:proxy => {
|
16
17
|
:http_proxyaddr => "proxy.com",
|
data/lib/datatrans/config.rb
CHANGED
@@ -11,10 +11,11 @@ module Datatrans
|
|
11
11
|
}
|
12
12
|
DOMAIN = 'datatrans.com'
|
13
13
|
|
14
|
-
attr_reader :environment, :merchant_id, :sign_key, :proxy
|
14
|
+
attr_reader :environment, :merchant_id, :sign_key, :password, :proxy
|
15
15
|
|
16
16
|
# Configure with following options
|
17
17
|
# * :merchant_id (required)
|
18
|
+
# * :password (required)
|
18
19
|
# * :sign_key (defaults to false)
|
19
20
|
# * :environment (defaults to :development, available environments are defined in ENVIRONMENTS)
|
20
21
|
# * :proxy (a hash containing :http_proxyaddr, :http_proxyport, :http_proxyuser, :http_proxypass)
|
@@ -22,6 +23,8 @@ module Datatrans
|
|
22
23
|
@merchant_id = options[:merchant_id]
|
23
24
|
raise ArgumentError.new(":merchant_id is required") unless self.merchant_id
|
24
25
|
self.environment = options[:environment] || DEFAULT_ENVIRONMENT
|
26
|
+
@password = options[:password]
|
27
|
+
raise ArgumentError.new(":password is required") unless self.password
|
25
28
|
@sign_key = options[:sign_key] || DEFAULT_SIGN_KEY
|
26
29
|
@proxy = options[:proxy] || {}
|
27
30
|
end
|
data/lib/datatrans/version.rb
CHANGED
@@ -9,7 +9,7 @@ class Datatrans::Web::Transaction
|
|
9
9
|
|
10
10
|
def successful?
|
11
11
|
raise Datatrans::InvalidSignatureError unless valid_signature?
|
12
|
-
response_code == '01' &&
|
12
|
+
response_code == '01' && status == 'success' && !errors_occurred?
|
13
13
|
end
|
14
14
|
|
15
15
|
def valid_signature?
|
@@ -18,6 +18,10 @@ class Datatrans::Web::Transaction
|
|
18
18
|
sign(self.datatrans.merchant_id, params[:amount], params[:currency], params[:uppTransactionId]) == params[:sign2]
|
19
19
|
end
|
20
20
|
|
21
|
+
def status
|
22
|
+
params[:status] rescue nil
|
23
|
+
end
|
24
|
+
|
21
25
|
def response_code
|
22
26
|
params[:responseCode] rescue nil
|
23
27
|
end
|
@@ -79,4 +83,4 @@ class Datatrans::Web::Transaction
|
|
79
83
|
|
80
84
|
include Datatrans::Common
|
81
85
|
end
|
82
|
-
end
|
86
|
+
end
|
@@ -7,7 +7,9 @@ class Datatrans::XML::Transaction
|
|
7
7
|
attr_accessor :params, :datatrans
|
8
8
|
|
9
9
|
def post(url, options = {})
|
10
|
-
options = options
|
10
|
+
options = options
|
11
|
+
.merge(self.datatrans.proxy)
|
12
|
+
.merge(:basic_auth => { :username => self.datatrans.merchant_id, :password => self.datatrans.password })
|
11
13
|
HTTParty.post(url, **options)
|
12
14
|
end
|
13
15
|
|
@@ -39,4 +41,4 @@ class Datatrans::XML::Transaction
|
|
39
41
|
xml.target!
|
40
42
|
end
|
41
43
|
end
|
42
|
-
end
|
44
|
+
end
|
data/spec/config_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Datatrans::Config do
|
4
4
|
describe "Instance Methods" do
|
5
5
|
before do
|
6
|
-
@datatrans = Datatrans::Config.new(:merchant_id => "xxx")
|
6
|
+
@datatrans = Datatrans::Config.new(:merchant_id => "xxx", :password => "yyy")
|
7
7
|
end
|
8
8
|
|
9
9
|
describe "web_transaction" do
|
data/spec/spec_helper.rb
CHANGED
@@ -15,6 +15,7 @@ RSpec.configure do |config|
|
|
15
15
|
@datatrans = Datatrans::Config.new(
|
16
16
|
:merchant_id => '1100000000',
|
17
17
|
:sign_key => 'd777c17ba2010282c2d2350a68b441ca07a799d294bfaa630b7c8442207c0b69703cc55775b0ca5a4e455b818a9bb10a43669c0c20ce31f4a43f10e0cabb9525',
|
18
|
+
:password => 'basic_auth_password',
|
18
19
|
:environment => :development
|
19
20
|
)
|
20
21
|
end
|
data/spec/web/authorize_spec.rb
CHANGED
@@ -31,6 +31,12 @@ describe Datatrans::Web::Transaction do
|
|
31
31
|
:acqAuthorizationCode => "173520"
|
32
32
|
}
|
33
33
|
|
34
|
+
@successful_swisspost_response = @successful_response.merge({
|
35
|
+
:pmethod => "PFC",
|
36
|
+
:txtEp2TrxID => "7777777000000001",
|
37
|
+
:responseMessage => "YellowPay transaction Ok"
|
38
|
+
})
|
39
|
+
|
34
40
|
@failed_response = {
|
35
41
|
:status => "error",
|
36
42
|
:returnCustomerCountry => "CHE",
|
@@ -78,7 +84,7 @@ describe Datatrans::Web::Transaction do
|
|
78
84
|
end
|
79
85
|
|
80
86
|
it 'should generate valid form field string' do
|
81
|
-
if Gem.loaded_specs['activesupport'].version >= Gem::Version.create('
|
87
|
+
if Gem.loaded_specs['activesupport'].version >= Gem::Version.create('6.0')
|
82
88
|
expected_output = '<input type="hidden" name="merchantId" id="merchantId" value="1100000000" autocomplete="off" /><input type="hidden" name="hiddenMode" id="hiddenMode" value="yes" autocomplete="off" /><input type="hidden" name="reqtype" id="reqtype" value="NOA" autocomplete="off" /><input type="hidden" name="amount" id="amount" value="1000" autocomplete="off" /><input type="hidden" name="currency" id="currency" value="CHF" autocomplete="off" /><input type="hidden" name="useAlias" id="useAlias" value="yes" autocomplete="off" /><input type="hidden" name="sign" id="sign" value="0402fb3fba8c6fcb40df9b7756e7e637" autocomplete="off" /><input type="hidden" name="refno" id="refno" value="ABCDEF" autocomplete="off" /><input type="hidden" name="uppCustomerDetails" id="uppCustomerDetails" autocomplete="off" /><input type="hidden" name="uppCustomerEmail" id="uppCustomerEmail" value="customer@email.com" autocomplete="off" />'
|
83
89
|
else
|
84
90
|
expected_output = '<input type="hidden" name="merchantId" id="merchantId" value="1100000000" /><input type="hidden" name="hiddenMode" id="hiddenMode" value="yes" /><input type="hidden" name="reqtype" id="reqtype" value="NOA" /><input type="hidden" name="amount" id="amount" value="1000" /><input type="hidden" name="currency" id="currency" value="CHF" /><input type="hidden" name="useAlias" id="useAlias" value="yes" /><input type="hidden" name="sign" id="sign" value="0402fb3fba8c6fcb40df9b7756e7e637" /><input type="hidden" name="refno" id="refno" value="ABCDEF" /><input type="hidden" name="uppCustomerDetails" id="uppCustomerDetails" /><input type="hidden" name="uppCustomerEmail" id="uppCustomerEmail" value="customer@email.com" />'
|
@@ -101,6 +107,19 @@ describe Datatrans::Web::Transaction do
|
|
101
107
|
end
|
102
108
|
end
|
103
109
|
|
110
|
+
context "successful response (swiss post)" do
|
111
|
+
before do
|
112
|
+
allow_any_instance_of(Datatrans::Web::Transaction::AuthorizeResponse).to receive(:params).and_return(@successful_swisspost_response)
|
113
|
+
end
|
114
|
+
|
115
|
+
context "process" do
|
116
|
+
it "handles a valid datatrans authorize response" do
|
117
|
+
@transaction = Datatrans::Web::Transaction.new(@datatrans, @valid_params)
|
118
|
+
expect(@transaction.authorize).to be true
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
104
123
|
context "compromised response" do
|
105
124
|
before do
|
106
125
|
fake_response = @successful_response
|
data/spec/xml/request_spec.rb
CHANGED
@@ -7,6 +7,7 @@ describe Datatrans::XML::Transaction::Request do
|
|
7
7
|
@datatrans = Datatrans::Config.new(
|
8
8
|
:merchant_id => '1100000000',
|
9
9
|
:sign_key => 'd777c17ba2010282c2d2350a68b441ca07a799d294bfaa630b7c8442207c0b69703cc55775b0ca5a4e455b818a9bb10a43669c0c20ce31f4a43f10e0cabb9525',
|
10
|
+
:password => 'basic_auth_password',
|
10
11
|
:key => "value",
|
11
12
|
:proxy => {
|
12
13
|
:http_proxyaddr => "proxy.com",
|
@@ -21,6 +22,7 @@ describe Datatrans::XML::Transaction::Request do
|
|
21
22
|
it "forward those options to HTTParty" do
|
22
23
|
request = Datatrans::XML::Transaction::Request.new(@datatrans, {})
|
23
24
|
expect(HTTParty).to receive(:post).with('lirum',
|
25
|
+
:basic_auth => {:password => 'basic_auth_password', :username => '1100000000'},
|
24
26
|
:params => {:foo => :bar},
|
25
27
|
:http_proxpass => 'xxx',
|
26
28
|
:http_proxyuser => 'hans',
|
@@ -33,7 +35,7 @@ describe Datatrans::XML::Transaction::Request do
|
|
33
35
|
describe "not configured" do
|
34
36
|
it "should not add any proxy settings" do
|
35
37
|
request = Datatrans::XML::Transaction::Request.new(@datatrans, {})
|
36
|
-
expect(HTTParty).to receive(:post).with('lirum', :params => {:foo => :bar})
|
38
|
+
expect(HTTParty).to receive(:post).with('lirum', :basic_auth => {:password => 'basic_auth_password', :username => '1100000000'}, :params => {:foo => :bar})
|
37
39
|
request.post('lirum', :params => {:foo => :bar})
|
38
40
|
end
|
39
41
|
end
|
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:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Miesel
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2022-
|
14
|
+
date: 2022-09-21 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: httparty
|