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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0cd93431049ffc3deba79d3c594ae93aff9e6fd91dc158ad0a68ae1e766a83e
4
- data.tar.gz: c67ba41b81de8adfbe9962cb85c80e881a57b69490972dae577f93e269935659
3
+ metadata.gz: eb01c19e9afe3aecaa82ff08e7e9024fefb8c60d3cab86fbd3400e4598879dcd
4
+ data.tar.gz: 13a9c7a7068610907a8123c11cf50f60014f79b5de6db2b51f763a5509159fb3
5
5
  SHA512:
6
- metadata.gz: 2bf90e36d3ef096f0904cc03309931408d1e26c23761645de6e46ce1588c350850d4466127c7443408eddf2a3475b48a2fd4db69fa761779a2a15d0e5d37031c
7
- data.tar.gz: eb8aa923a6599f0cbf10b4ed1fc2fc76e3068fbbd589768635f4d89e55063072c2c691f8a91504c04fb4eec761d798b92ad4522000094b932d775c5c195be6aa
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",
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Datatrans
2
- VERSION = "4.0.0"
2
+ VERSION = "5.0.0"
3
3
  end
@@ -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' && response_message == 'Authorized' && !errors_occurred?
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.merge(self.datatrans.proxy)
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
@@ -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('7.0')
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
@@ -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.0.0
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-02-24 00:00:00.000000000 Z
14
+ date: 2022-09-21 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: httparty