datatrans 5.0.0 → 5.2.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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +37 -4
  3. data/.github/workflows/release.yml +1 -1
  4. data/.gitignore +1 -1
  5. data/.ruby-version +1 -1
  6. data/Appraisals +16 -8
  7. data/CHANGELOG.md +22 -0
  8. data/Gemfile +1 -0
  9. data/Gemfile.lock +151 -0
  10. data/README.markdown +183 -3
  11. data/Rakefile +2 -2
  12. data/datatrans.gemspec +20 -22
  13. data/gemfiles/rails_5_2.gemfile +2 -2
  14. data/gemfiles/rails_6_0.gemfile +2 -2
  15. data/gemfiles/rails_6_1.gemfile +2 -2
  16. data/gemfiles/rails_7_0.gemfile +2 -2
  17. data/gemfiles/rails_7_1.gemfile +12 -0
  18. data/lib/datatrans/common.rb +5 -5
  19. data/lib/datatrans/config.rb +41 -12
  20. data/lib/datatrans/json/transaction/authorize.rb +10 -0
  21. data/lib/datatrans/json/transaction/init.rb +61 -0
  22. data/lib/datatrans/json/transaction/merchant_authorize.rb +45 -0
  23. data/lib/datatrans/json/transaction/response.rb +26 -0
  24. data/lib/datatrans/json/transaction/settle.rb +41 -0
  25. data/lib/datatrans/json/transaction/status.rb +50 -0
  26. data/lib/datatrans/json/transaction.rb +54 -0
  27. data/lib/datatrans/version.rb +1 -1
  28. data/lib/datatrans/web/transaction/authorize.rb +46 -17
  29. data/lib/datatrans/web/transaction.rb +10 -4
  30. data/lib/datatrans/web/view_helper.rb +3 -1
  31. data/lib/datatrans/xml/transaction/authorize.rb +39 -19
  32. data/lib/datatrans/xml/transaction/capture.rb +29 -15
  33. data/lib/datatrans/xml/transaction/request.rb +10 -9
  34. data/lib/datatrans/xml/transaction/response.rb +4 -2
  35. data/lib/datatrans/xml/transaction/status.rb +41 -25
  36. data/lib/datatrans/xml/transaction/void.rb +30 -16
  37. data/lib/datatrans/xml/transaction.rb +18 -14
  38. data/lib/datatrans.rb +9 -8
  39. data/renovate.json +14 -0
  40. data/spec/common_spec.rb +6 -6
  41. data/spec/config_spec.rb +8 -2
  42. data/spec/json/authorize_spec.rb +100 -0
  43. data/spec/json/init_spec.rb +100 -0
  44. data/spec/json/merchant_authorize_spec.rb +97 -0
  45. data/spec/json/settle_spec.rb +55 -0
  46. data/spec/json/status_spec.rb +75 -0
  47. data/spec/json/transaction_spec.rb +10 -0
  48. data/spec/spec_helper.rb +11 -11
  49. data/spec/web/init_spec.rb +157 -0
  50. data/spec/xml/capture_spec.rb +5 -5
  51. data/spec/xml/{authorize_spec.rb → init_spec.rb} +7 -7
  52. data/spec/xml/request_spec.rb +21 -22
  53. data/spec/xml/status_spec.rb +4 -4
  54. data/spec/xml/void_spec.rb +5 -5
  55. metadata +20 -4
  56. data/spec/web/authorize_spec.rb +0 -157
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb01c19e9afe3aecaa82ff08e7e9024fefb8c60d3cab86fbd3400e4598879dcd
4
- data.tar.gz: 13a9c7a7068610907a8123c11cf50f60014f79b5de6db2b51f763a5509159fb3
3
+ metadata.gz: c2f34eb8d332a694f26cb82bb7f9f6d953914b4f314d6eb6cf73896b5398a228
4
+ data.tar.gz: d62d36a4d876a1b594706ef77e845fa10d80d22bfe712e01acb1d4e7d7e1b394
5
5
  SHA512:
6
- metadata.gz: b8d2cc670be21be5336b8856eca9603ef8351be8ebc9e8e19efca2486a2304d7a8701fcabeea629285434dcd4b6c99cf8f53b8382870cbd0a7dbf38db7b6ded2
7
- data.tar.gz: a13b4a7a1934bfa437209b9eb53b2c8bba45d3e0c7e24cb699e8544c7d2af67d6497a0a1c885e3d6af034030b3b0b077d5928a4e8e6577a2b606824c1752be22
6
+ metadata.gz: c6d5a9d7d70dec2c18bcc7b18060003f6e769497479851c8646c5b04df703a504ab5dac6f0a8b7144891ae0c65c2f3894e762429da3f9586cb06d0a08398d181
7
+ data.tar.gz: abdef0e7fc212ae0ac3015f271bf98bb9f22ce163d43bbb88e68e1b056b4deeca1f903374d50a64c9078cdfdc33da9c532a4822349f5a99a69aa8deae867ef52
@@ -1,17 +1,34 @@
1
1
  ---
2
2
  name: CI
3
- on: [push, pull_request]
3
+ on: [ push, pull_request ]
4
4
  jobs:
5
+ standard:
6
+ runs-on: ubuntu-latest
7
+ steps:
8
+ - uses: actions/checkout@v4
9
+
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 2.6 # keep it on the lowest supported Ruby version
14
+ bundler-cache: true
15
+
16
+ - name: Run Standard
17
+ run: bundle exec standardrb
18
+
5
19
  tests:
6
20
  runs-on: ubuntu-latest
7
21
  strategy:
8
22
  fail-fast: false
9
23
  matrix:
10
- ruby: [ '2.6', '2.7', '3.0', '3.1' ]
11
- rails: [ '5-2', '6-0', '6-1', '7-0' ]
24
+ ruby: [ '2.6', '2.7', '3.0', '3.1', '3.2', '3.3' ]
25
+ rails: [ '5-2', '6-0', '6-1', '7-0', '7-1' ]
26
+ # excludes are sorted by Ruby version, then Rails version
12
27
  exclude:
13
28
  - ruby: 2.6 # Rails 7 requires 2.7 minimum
14
29
  rails: 7-0
30
+ - ruby: 2.6 # Rails 7.1 requires 2.7 minimum
31
+ rails: 7-1
15
32
  - ruby: 3.0 # Ruby 3 support for 5.2 hasn't been added
16
33
  rails: 5-2
17
34
  - ruby: 3.1 # Ruby 3.1 only works on the latest Rails 7 version
@@ -20,9 +37,25 @@ jobs:
20
37
  rails: 6-0
21
38
  - ruby: 3.1
22
39
  rails: 6-1
40
+ - ruby: 3.2 # Ruby 3.2 only works on the latest Rails 7 version
41
+ rails: 5-2
42
+ - ruby: 3.2
43
+ rails: 6-0
44
+ - ruby: 3.2
45
+ rails: 6-1
46
+ - ruby: 3.3 # Ruby 3.3 only works on the latest Rails 7 version
47
+ rails: 5-2
48
+ - ruby: 3.3
49
+ rails: 6-0
50
+ - ruby: 3.3
51
+ rails: 6-1
23
52
 
24
53
  steps:
25
- - uses: actions/checkout@v2
54
+ - uses: actions/checkout@v4
55
+
56
+ # we otherwise run into issues with different versions of actionpack / activesupport with Appraisal
57
+ - name: Remove Gemfile.lock
58
+ run: rm Gemfile.lock
26
59
 
27
60
  - name: Set up Ruby
28
61
  uses: ruby/setup-ruby@v1
@@ -8,7 +8,7 @@ jobs:
8
8
  runs-on: ubuntu-latest
9
9
  if: github.ref == 'refs/heads/master'
10
10
  steps:
11
- - uses: actions/checkout@v2
11
+ - uses: actions/checkout@v4
12
12
  - uses: ruby/setup-ruby@v1
13
13
  with:
14
14
  ruby-version: 2.7
data/.gitignore CHANGED
@@ -1,5 +1,5 @@
1
1
  *.gem
2
2
  .bundle
3
3
  pkg/*
4
- *.lock
4
+ gemfiles/*.lock
5
5
  coverage
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.9
1
+ 2.6.10
data/Appraisals CHANGED
@@ -1,31 +1,39 @@
1
1
  appraise "rails-5-2" do
2
- gem "activesupport", "~> 5.2"
2
+ gem "activesupport", "~> 5.2.0"
3
3
 
4
4
  group :development, :test do
5
- gem "actionpack", "~> 5.2"
5
+ gem "actionpack", "~> 5.2.0"
6
6
  end
7
7
  end
8
8
 
9
9
  appraise "rails-6-0" do
10
- gem "activesupport", "~> 6.0"
10
+ gem "activesupport", "~> 6.0.0"
11
11
 
12
12
  group :development, :test do
13
- gem "actionpack", "~> 6.0"
13
+ gem "actionpack", "~> 6.0.0"
14
14
  end
15
15
  end
16
16
 
17
17
  appraise "rails-6-1" do
18
- gem "activesupport", "~> 6.1"
18
+ gem "activesupport", "~> 6.1.0"
19
19
 
20
20
  group :development, :test do
21
- gem "actionpack", "~> 6.1"
21
+ gem "actionpack", "~> 6.1.0"
22
22
  end
23
23
  end
24
24
 
25
25
  appraise "rails-7-0" do
26
- gem "activesupport", "~> 7.0"
26
+ gem "activesupport", "~> 7.0.0"
27
27
 
28
28
  group :development, :test do
29
- gem "actionpack", "~> 7.0"
29
+ gem "actionpack", "~> 7.0.0"
30
+ end
31
+ end
32
+
33
+ appraise "rails-7-1" do
34
+ gem "activesupport", "~> 7.1.0"
35
+
36
+ group :development, :test do
37
+ gem "actionpack", "~> 7.1.0"
30
38
  end
31
39
  end
data/CHANGELOG.md CHANGED
@@ -5,6 +5,28 @@ This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## 5.2.0 - 2024-01-31
9
+
10
+ ### Added
11
+
12
+ * Support for Ruby 3.3 and Rails 7.1 (@andyundso [#47](https://github.com/simplificator/datatrans/pull/47))
13
+ * Support for Merchant Initiated Payments (@visini [#48](https://github.com/simplificator/datatrans/pull/48), [#52](https://github.com/simplificator/datatrans/pull/52), [#53](https://github.com/simplificator/datatrans/pull/53), [#56](https://github.com/simplificator/datatrans/pull/56))
14
+
15
+ ### Changed
16
+
17
+ * Reformatted code with standardrb (@andyundso [#57](https://github.com/simplificator/datatrans/pull/57))
18
+ * Marked XML APIs and Web APIs as deprecated (@andyundso [#60](https://github.com/simplificator/datatrans/pull/60))
19
+ * Renamed `Datatrans::JSON::Transaction::Authorize` to `Datatrans::JSON::Transaction::Init`. `::Authorize` will still work until the next major release (@andyundso [#60](https://github.com/simplificator/datatrans/pull/60))
20
+
21
+ ## 5.1.0 - 2023-07-06
22
+
23
+ ### Added
24
+
25
+ * Test against Ruby 3.2 (@andyundso [#43](https://github.com/simplificator/datatrans/pull/43))
26
+ * Add support for Datatrans JSON API (@TatianaPan [#45](https://github.com/simplificator/datatrans/pull/45)). Check Readme for details on how to use it.
27
+
28
+ XML API is [deprecated](https://mailchi.mp/datatrans/basic-authdynamic-sign_reminder) by Datatrans and will not be supported by them after June 3rd, 2024. Consider to moving to a [new JSON API](https://api-reference.datatrans.ch/).
29
+
8
30
  ## 5.0.0 - 2022-09-21
9
31
 
10
32
  ### Changed
data/Gemfile CHANGED
@@ -3,3 +3,4 @@ source "http://rubygems.org"
3
3
  # Specify your gem's dependencies in datatrans.gemspec
4
4
  gemspec
5
5
  gem "simplecov", group: :test, require: nil
6
+ gem "standard", group: :development, require: false
data/Gemfile.lock ADDED
@@ -0,0 +1,151 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ datatrans (5.2.0)
5
+ activesupport (>= 5.2)
6
+ builder
7
+ httparty
8
+ i18n
9
+ multi_xml (>= 0.5.1)
10
+
11
+ GEM
12
+ remote: http://rubygems.org/
13
+ specs:
14
+ actionpack (6.1.5)
15
+ actionview (= 6.1.5)
16
+ activesupport (= 6.1.5)
17
+ rack (~> 2.0, >= 2.0.9)
18
+ rack-test (>= 0.6.3)
19
+ rails-dom-testing (~> 2.0)
20
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
21
+ actionview (6.1.5)
22
+ activesupport (= 6.1.5)
23
+ builder (~> 3.1)
24
+ erubi (~> 1.4)
25
+ rails-dom-testing (~> 2.0)
26
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
27
+ activesupport (6.1.5)
28
+ concurrent-ruby (~> 1.0, >= 1.0.2)
29
+ i18n (>= 1.6, < 2)
30
+ minitest (>= 5.1)
31
+ tzinfo (~> 2.0)
32
+ zeitwerk (~> 2.3)
33
+ appraisal (2.4.1)
34
+ bundler
35
+ rake
36
+ thor (>= 0.14.0)
37
+ ast (2.4.2)
38
+ builder (3.2.4)
39
+ concurrent-ruby (1.1.10)
40
+ crass (1.0.6)
41
+ diff-lcs (1.5.0)
42
+ docile (1.4.0)
43
+ erubi (1.10.0)
44
+ httparty (0.21.0)
45
+ mini_mime (>= 1.0.0)
46
+ multi_xml (>= 0.5.2)
47
+ i18n (1.10.0)
48
+ concurrent-ruby (~> 1.0)
49
+ json (2.7.1)
50
+ language_server-protocol (3.17.0.3)
51
+ lint_roller (1.1.0)
52
+ loofah (2.16.0)
53
+ crass (~> 1.0.2)
54
+ nokogiri (>= 1.5.9)
55
+ mini_mime (1.1.5)
56
+ mini_portile2 (2.8.5)
57
+ minitest (5.15.0)
58
+ multi_xml (0.6.0)
59
+ nokogiri (1.13.4)
60
+ mini_portile2 (~> 2.8.0)
61
+ racc (~> 1.4)
62
+ nokogiri (1.13.4-x86_64-darwin)
63
+ racc (~> 1.4)
64
+ nokogiri (1.13.4-x86_64-linux)
65
+ racc (~> 1.4)
66
+ parallel (1.24.0)
67
+ parser (3.3.0.5)
68
+ ast (~> 2.4.1)
69
+ racc
70
+ racc (1.7.3)
71
+ rack (2.2.3)
72
+ rack-test (1.1.0)
73
+ rack (>= 1.0, < 3)
74
+ rails-dom-testing (2.0.3)
75
+ activesupport (>= 4.2.0)
76
+ nokogiri (>= 1.6)
77
+ rails-html-sanitizer (1.4.2)
78
+ loofah (~> 2.3)
79
+ rainbow (3.1.1)
80
+ rake (13.0.6)
81
+ regexp_parser (2.9.0)
82
+ rexml (3.2.6)
83
+ rspec (3.11.0)
84
+ rspec-core (~> 3.11.0)
85
+ rspec-expectations (~> 3.11.0)
86
+ rspec-mocks (~> 3.11.0)
87
+ rspec-core (3.11.0)
88
+ rspec-support (~> 3.11.0)
89
+ rspec-expectations (3.11.0)
90
+ diff-lcs (>= 1.2.0, < 2.0)
91
+ rspec-support (~> 3.11.0)
92
+ rspec-mocks (3.11.1)
93
+ diff-lcs (>= 1.2.0, < 2.0)
94
+ rspec-support (~> 3.11.0)
95
+ rspec-support (3.11.0)
96
+ rubocop (1.50.2)
97
+ json (~> 2.3)
98
+ parallel (~> 1.10)
99
+ parser (>= 3.2.0.0)
100
+ rainbow (>= 2.2.2, < 4.0)
101
+ regexp_parser (>= 1.8, < 3.0)
102
+ rexml (>= 3.2.5, < 4.0)
103
+ rubocop-ast (>= 1.28.0, < 2.0)
104
+ ruby-progressbar (~> 1.7)
105
+ unicode-display_width (>= 2.4.0, < 3.0)
106
+ rubocop-ast (1.30.0)
107
+ parser (>= 3.2.1.0)
108
+ rubocop-performance (1.16.0)
109
+ rubocop (>= 1.7.0, < 2.0)
110
+ rubocop-ast (>= 0.4.0)
111
+ ruby-progressbar (1.13.0)
112
+ simplecov (0.22.0)
113
+ docile (~> 1.1)
114
+ simplecov-html (~> 0.11)
115
+ simplecov_json_formatter (~> 0.1)
116
+ simplecov-html (0.12.3)
117
+ simplecov_json_formatter (0.1.4)
118
+ standard (1.28.5)
119
+ language_server-protocol (~> 3.17.0.2)
120
+ lint_roller (~> 1.0)
121
+ rubocop (~> 1.50.2)
122
+ standard-custom (~> 1.0.0)
123
+ standard-performance (~> 1.0.1)
124
+ standard-custom (1.0.2)
125
+ lint_roller (~> 1.0)
126
+ rubocop (~> 1.50)
127
+ standard-performance (1.0.1)
128
+ lint_roller (~> 1.0)
129
+ rubocop-performance (~> 1.16.0)
130
+ thor (1.2.1)
131
+ tzinfo (2.0.4)
132
+ concurrent-ruby (~> 1.0)
133
+ unicode-display_width (2.5.0)
134
+ zeitwerk (2.5.4)
135
+
136
+ PLATFORMS
137
+ ruby
138
+ x86_64-darwin-21
139
+ x86_64-linux
140
+
141
+ DEPENDENCIES
142
+ actionpack (>= 5.2)
143
+ appraisal
144
+ datatrans!
145
+ rake
146
+ rspec
147
+ simplecov
148
+ standard
149
+
150
+ BUNDLED WITH
151
+ 2.3.3
data/README.markdown CHANGED
@@ -8,6 +8,7 @@ Configuration
8
8
 
9
9
  Build your Datatrans Configuration like so:
10
10
 
11
+ ```ruby
11
12
  datatrans = Datatrans::Config.new(
12
13
  :merchant_id => '1234567',
13
14
  :sign_key => 'ab739fd5b7c2a1...',
@@ -20,7 +21,7 @@ Build your Datatrans Configuration like so:
20
21
  :http_proxpass => "xxx",
21
22
  }
22
23
  )
23
-
24
+ ```
24
25
 
25
26
  If you don't want to use signed requests (disabled in datatrans web console), you can set `config.sign_key` to `false`.
26
27
  The configuration is then used as parameter to all the constructors and helpers, see examples below.
@@ -30,9 +31,14 @@ Possible values for the environment: `:production`, `:development`
30
31
  Web Authorization
31
32
  =================
32
33
 
34
+ > [!IMPORTANT]
35
+ >
36
+ > Datatrans no longer supports the Payment Page API. The support in this gem will be removed in the next major release. Please use the [JSON API](#json-transactions) instead.
37
+
33
38
  If you want to process a credit card the first time a web authorization is
34
39
  necessary. Add the following code to a controller action that shows the form.
35
40
  You need to pass at least `amount`, `currency` and `refno` (order number).
41
+ ```ruby
36
42
  @transaction = datatrans.web_transaction(
37
43
  :amount => 1000, # in cents!
38
44
  :currency => 'CHF',
@@ -40,9 +46,11 @@ You need to pass at least `amount`, `currency` and `refno` (order number).
40
46
  :uppCustomerEmail => 'customer@email.com',
41
47
  # feel free to add more upp infos here ...
42
48
  )
49
+ ```
43
50
 
44
51
  In your View your show the credit card form with a convenient helper:
45
52
 
53
+ ```ruby
46
54
  = form_tag Datatrans.web_authorize_url do
47
55
 
48
56
  = text_field_tag :paymentmethod, 'ECA'
@@ -58,6 +66,7 @@ In your View your show the credit card form with a convenient helper:
58
66
  = datatrans_notification_request_hidden_fields(datatrans, @transaction)
59
67
 
60
68
  = submit_tag "send"
69
+ ```
61
70
 
62
71
  In this example we use just ECA (Mastercard) as paymentmethod. Feel free to
63
72
  provide an appropriate select field to offer more payment methods. Don't forget
@@ -66,7 +75,7 @@ to the same value.
66
75
 
67
76
  After you submit the request to Datatrans they redirect back to your application.
68
77
  Now you can process the transaction like this:
69
-
78
+ ```ruby
70
79
  begin
71
80
  transaction = datatrans.web_transaction(params)
72
81
 
@@ -86,16 +95,183 @@ Now you can process the transaction like this:
86
95
  rescue Datatrans::InvalidSignatureError => exception
87
96
  # the signature was wrong, the request may have been compromised...
88
97
  end
98
+ ```
99
+
100
+ JSON Transactions
101
+ =================
102
+
103
+ More information about Datatrans JSON API can be found [here](https://api-reference.datatrans.ch/). Our gem uses endpoints from `/v1/transactions` section.
104
+
105
+ We implemented support for [Redirect mode](https://docs.datatrans.ch/docs/redirect-lightbox) (since Lightbox mode may not work correctly on mobile, whereas Redirect works well on all devices).
106
+
107
+ Saving Payment Information
108
+ --------------------------
109
+
110
+ According to the [docs](https://docs.datatrans.ch/docs/customer-initiated-payments#saving-payment-information), there are three possible flows:
111
+
112
+ - **Customer Initiated Payments**: _Your customer pays and nothing is registered._
113
+ - This is the most basic setup and does _not_ save any payment information: First, call `transaction.init`, and then redirect the user to the `transaction_path` (see the sections `Initialize` and `Start a transaction` below).
114
+ - **Customer Initiated Payment** and creating an `alias` for subsequent **Merchant Initiated Payments**: _Your customer pays and the card or payment method information is registered. You receive an alias which you save for later merchant initiated payments or one-click checkouts._
115
+ - In order to save payment information after your customer has finalized their payment, without them having to re-enter their payment information and go through the 3D-Secure flow, pass `option: {"createAlias": true}`. More information can be found [here](https://docs.datatrans.ch/docs/redirect-lightbox#saving-payment-information).
116
+ - **Merchant Initiated Payments**: _Your customer registers their card or payment method information without any payment. Their account is not charged. This is what we call a dedicated registration._
117
+ - This setup allows you to save a customers payment information without any charge in the beginning. This is useful in the context of setting up a subscription model (e.g., usage-based billing at the end of a billing period). See the section `Merchant Initiated Payments` below.
118
+
119
+ Initialize
120
+ ---------
121
+
122
+ Initialize a JSON transaction:
123
+
124
+ ```ruby
125
+ transaction = datatrans.json_transaction(
126
+ refno: 'ABCDEF',
127
+ amount: 1000, # in cents!
128
+ currency: "CHF",
129
+ payment_methods: ["ECA", "VIS"],
130
+ success_url: <your_application_return_url>,
131
+ cancel_url: <your_application_return_url>,
132
+ error_url: <your_application_return_url>
133
+ )
134
+
135
+ # call to initialize endpoint to initialize a transaction
136
+ # returns true or false depending if response was successful or not
137
+ init = transaction.init
138
+
139
+ # successful authorization call returns in response a transaction id
140
+ if init
141
+ transaction_id = transaction.response.params["transactionId"]
142
+ end
143
+ ```
144
+
145
+ Start a transaction
146
+ -------------------
147
+
148
+ Once you have a transaction id, you can start a transaction. Users of your application will be redirected to the datatrans payment pages: `https://pay.sandbox.datatrans.com/v1/start/{{transactionId}}`.
149
+
150
+ ```ruby
151
+ path = datatrans.json_transaction(transaction_id: transaction_id).transaction_path
152
+
153
+ redirect_to path
154
+ # or if you redirect after AJAX request:
155
+ render js: "window.location='#{path}'"
156
+ ```
157
+
158
+ You do not have to [settle a transaction](https://api-reference.datatrans.ch/#tag/v1transactions/operation/settle) by yourself: we set `"autoSettle": true` by default when authorizing a transaction, which means the transaction will be settled automatically. This can be overridden by setting `auto_settle: false` when authorizing a transaction.
159
+
160
+ Transaction status
161
+ ------------------
162
+
163
+ You can check the trasaction [status](https://api-reference.datatrans.ch/#tag/v1transactions/operation/status), see its history and retrieve the card information.
164
+
165
+ ```ruby
166
+ transaction = datatrans.json_transaction(transaction_id: transaction_id)
167
+
168
+ # status method returns true or false depending if response was successfull
169
+ if transaction.status
170
+ data = transaction.response.params
171
+ # this will return following hash (may vary dependong on your payment method):
172
+ {
173
+ "transactionId"=>"230223022302230223",
174
+ "merchantId"=>"1100000000",
175
+ "type"=>"payment",
176
+ "status"=>"settled",
177
+ "currency"=>"CHF",
178
+ "refno"=>"123456abc",
179
+ "paymentMethod"=>"VIS",
180
+ "detail"=>
181
+ {"authorize"=>{"amount"=>1000, "acquirerAuthorizationCode"=>"100000"}, "settle"=>{"amount"=>1000}},
182
+ "language"=>"en",
183
+ "card"=>
184
+ {"masked"=>"400000xxxxxx0018",
185
+ "expiryMonth"=>"06",
186
+ "expiryYear"=>"25",
187
+ "info"=>
188
+ {"brand"=>"VISA",
189
+ "type"=>"debit",
190
+ "usage"=>"consumer",
191
+ "country"=>"SE",
192
+ "issuer"=>"SVENSKA HANDELSBANKEN AB"},
193
+ "3D"=>{"authenticationResponse"=>"Y"}},
194
+ "history"=>
195
+ [{"action"=>"init",
196
+ "amount"=>1000,
197
+ "source"=>"api",
198
+ "date"=>"2023-06-06T08:37:23Z",
199
+ "success"=>true,
200
+ "ip"=>"8.8.8.8"},
201
+ {"action"=>"authorize",
202
+ "autoSettle"=>true,
203
+ "amount"=>1000,
204
+ "source"=>"redirect",
205
+ "date"=>"2023-06-06T08:37:42Z",
206
+ "success"=>true,
207
+ "ip"=>"8.8.8.8"}]
208
+ }
209
+ else
210
+ transaction.response.error_code
211
+ transaction.response.error_message
212
+ end
213
+ ```
214
+
215
+ Merchant Initiated Payments
216
+ ---------
217
+
218
+ It's possible to authorize transactions without user interaction, via [merchant initiated payments](https://docs.datatrans.ch/docs/merchant-initiated-payments).
219
+
220
+ To perform a so-called "dedicated registration" (so we can later charge the card via its `alias`), you should follow the same steps as described above, but not provide an amount:
221
+
222
+ ```ruby
223
+ transaction = datatrans.json_transaction(
224
+ refno: 'ABCDEF',
225
+ amount: 0, # omit amount for dedicated registrations
226
+ currency: "CHF",
227
+ payment_methods: ["ECA", "VIS"],
228
+ success_url: <your_application_return_url>,
229
+ cancel_url: <your_application_return_url>,
230
+ error_url: <your_application_return_url>
231
+ )
232
+
233
+ init = transaction.init
234
+
235
+ # successful authorization call returns in response a transaction id
236
+ if init
237
+ transaction_id = transaction.response.params["transactionId"]
238
+ end
239
+ ```
240
+
241
+ Then, at a later point in time, and without needing any user interaction, you can create a payment via `merchant_authorize`:
242
+
243
+ ```ruby
244
+ dedicated_registration = datatrans.json_transaction(transaction_id: transaction_id)
245
+ dedicated_registration.status # this will contain the card information
246
+
247
+ card_alias = dedicated_registration.response.params["card"]["alias"]
248
+ card_expiry_month = dedicated_registration.response.params["card"]["expiryMonth"]
249
+ card_expiry_year = dedicated_registration.response.params["card"]["expiryYear"]
250
+
251
+ transaction = datatrans.json_transaction(
252
+ refno: "ABCDEF",
253
+ amount: 1000,
254
+ currency: "CHF",
255
+ card: {alias: card_alias, expiryMonth: card_expiry_month, expiryYear: card_expiry_year}
256
+ )
257
+
258
+ transaction.merchant_authorize # this will charge the card without user interaction
259
+ ```
89
260
 
90
261
  XML Transactions
91
262
  ================
92
263
 
264
+ > [!IMPORTANT]
265
+ >
266
+ > Datatrans will stop supporting the XML API on June 3rd, 2024. The support in this gem will be removed in the next major release. Please use the [JSON API](#json-transactions) instead.
267
+
93
268
  If you have already a credit card alias or an authorized transaction you can
94
269
  use the convenient XML methods to process payments.
95
270
 
96
271
  Authorize
97
272
  ---------
98
273
 
274
+ ```ruby
99
275
  transaction = datatrans.xml_transaction(
100
276
  :refno => 'ABCDEF',
101
277
  :amount => 1000, # in cents!
@@ -111,6 +287,7 @@ Authorize
111
287
  else
112
288
  # transaction.error_code, transaction.error_message, transaction.error_detail
113
289
  end
290
+ ```
114
291
 
115
292
 
116
293
  Capture
@@ -118,6 +295,7 @@ Capture
118
295
 
119
296
  To capture an authorized transaction you use the following code:
120
297
 
298
+ ```ruby
121
299
  transaction = datatrans.xml_transaction(
122
300
  :refno => 'ABCDEF',
123
301
  :amount => 1000, # in cents!
@@ -130,13 +308,14 @@ To capture an authorized transaction you use the following code:
130
308
  else
131
309
  # transaction.error_code, transaction.error_message, transaction.error_detail
132
310
  end
133
-
311
+ ```
134
312
 
135
313
  Void
136
314
  ----
137
315
 
138
316
  To make an authorized transaction invalid use void.
139
317
 
318
+ ```ruby
140
319
  transaction = datatrans.xml_transaction(
141
320
  :refno => 'ABCDEF',
142
321
  :amount => 1000, # in cents!
@@ -149,6 +328,7 @@ To make an authorized transaction invalid use void.
149
328
  else
150
329
  # transaction.error_code, transaction.error_message, transaction.error_detail
151
330
  end
331
+ ```
152
332
 
153
333
  Todo
154
334
  ====
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
- require 'bundler/gem_tasks'
1
+ require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
4
  RSpec::Core::RakeTask.new("spec")
5
- task :default => :spec
5
+ task default: :spec
data/datatrans.gemspec CHANGED
@@ -1,34 +1,32 @@
1
- # -*- encoding: utf-8 -*-
2
1
  $:.push File.expand_path("../lib", __FILE__)
3
2
  require "datatrans/version"
4
3
 
5
4
  Gem::Specification.new do |s|
6
- s.name = "datatrans"
7
- s.version = Datatrans::VERSION
8
- s.authors = ["Tobias Miesel", "Thomas Maurer", "Corin Langosch", "Pascal Betz"]
9
- s.email = ["info@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}
5
+ s.name = "datatrans"
6
+ s.version = Datatrans::VERSION
7
+ s.authors = ["Tobias Miesel", "Thomas Maurer", "Corin Langosch", "Pascal Betz"]
8
+ s.email = ["info@simplificator.com"]
9
+ s.homepage = ""
10
+ s.summary = "Datatrans Integration for Ruby on Rails"
11
+ s.description = "Datatrans Integration for Ruby on Rails"
13
12
 
14
13
  s.rubyforge_project = "datatrans"
15
14
 
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) }
15
+ s.files = `git ls-files`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
19
17
  s.require_paths = ["lib"]
20
18
 
21
- s.required_ruby_version = '>= 2.6'
19
+ s.required_ruby_version = ">= 2.6"
22
20
 
23
- s.add_dependency 'httparty'
24
- s.add_dependency 'activesupport', '>= 5.2'
25
- s.add_dependency 'i18n'
26
- s.add_dependency 'builder'
27
- s.add_dependency 'multi_xml', '>= 0.5.1'
21
+ s.add_dependency "httparty"
22
+ s.add_dependency "activesupport", ">= 5.2"
23
+ s.add_dependency "i18n"
24
+ s.add_dependency "builder"
25
+ s.add_dependency "multi_xml", ">= 0.5.1"
28
26
 
29
- s.add_development_dependency 'actionpack', '>= 5.2'
30
- s.add_development_dependency 'appraisal'
31
- s.add_development_dependency 'rake'
32
- s.add_development_dependency 'rspec'
33
- s.license = 'MIT'
27
+ s.add_development_dependency "actionpack", ">= 5.2"
28
+ s.add_development_dependency "appraisal"
29
+ s.add_development_dependency "rake"
30
+ s.add_development_dependency "rspec"
31
+ s.license = "MIT"
34
32
  end