solidus_six_saferpay 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +35 -0
  3. data/.gem_release.yml +5 -0
  4. data/.github/stale.yml +17 -0
  5. data/.gitignore +18 -0
  6. data/.rspec +2 -0
  7. data/.rubocop.yml +2 -0
  8. data/.travis.yml +12 -0
  9. data/Gemfile +33 -0
  10. data/LICENSE +26 -0
  11. data/README.md +36 -20
  12. data/Rakefile +4 -54
  13. data/app/assets/config/solidus_six_saferpay_manifest.js +1 -0
  14. data/app/assets/images/solidus_six_saferpay/.keep +0 -0
  15. data/app/assets/javascripts/spree/backend/solidus_six_saferpay.js +2 -0
  16. data/app/assets/javascripts/spree/frontend/solidus_six_saferpay.js +2 -0
  17. data/app/assets/stylesheets/solidus_six_saferpay/loading_animation.scss +0 -27
  18. data/app/assets/stylesheets/solidus_six_saferpay/payments.scss +4 -1
  19. data/app/assets/stylesheets/spree/backend/solidus_six_saferpay.css +4 -0
  20. data/app/assets/stylesheets/spree/frontend/solidus_six_saferpay.css +4 -0
  21. data/app/controllers/spree/solidus_six_saferpay/checkout_controller.rb +56 -10
  22. data/app/services/spree/solidus_six_saferpay/inquire_payment.rb +1 -0
  23. data/app/views/spree/checkout/payment/_saferpay_payment.html.erb +1 -1
  24. data/app/views/spree/six_saferpay_payments/_six_saferpay_payment.html.erb +2 -2
  25. data/bin/console +17 -0
  26. data/bin/rails +18 -0
  27. data/bin/rake +7 -0
  28. data/bin/setup +8 -0
  29. data/config/initializers/assets.rb +3 -0
  30. data/config/locales/de.yml +1 -1
  31. data/config/locales/en.yml +1 -1
  32. data/config/locales/fr.yml +1 -1
  33. data/config/routes.rb +6 -6
  34. data/lib/generators/solidus_six_saferpay/install/install_generator.rb +15 -3
  35. data/lib/solidus_six_saferpay.rb +6 -3
  36. data/lib/solidus_six_saferpay/configuration.rb +4 -7
  37. data/lib/solidus_six_saferpay/engine.rb +19 -10
  38. data/lib/solidus_six_saferpay/gateway.rb +5 -4
  39. data/lib/solidus_six_saferpay/payment_page_gateway.rb +8 -9
  40. data/lib/solidus_six_saferpay/transaction_gateway.rb +8 -9
  41. data/lib/solidus_six_saferpay/version.rb +3 -1
  42. data/solidus_six_saferpay.gemspec +42 -0
  43. data/spec/controllers/spree/solidus_six_saferpay/checkout_controller_spec.rb +41 -0
  44. data/spec/controllers/spree/solidus_six_saferpay/payment_page/checkout_controller_spec.rb +206 -0
  45. data/spec/controllers/spree/solidus_six_saferpay/transaction/checkout_controller_spec.rb +229 -0
  46. data/spec/factories/payment_methods.rb +23 -0
  47. data/spec/factories/payments.rb +11 -0
  48. data/spec/factories/spree/six_saferpay_payments.rb +118 -0
  49. data/spec/models/spree/six_saferpay_payment_spec.rb +203 -0
  50. data/spec/rails_helper.rb +73 -0
  51. data/spec/services/spree/solidus_six_saferpay/assert_payment_page_spec.rb +148 -0
  52. data/spec/services/spree/solidus_six_saferpay/authorize_payment_spec.rb +39 -0
  53. data/spec/services/spree/solidus_six_saferpay/authorize_transaction_spec.rb +148 -0
  54. data/spec/services/spree/solidus_six_saferpay/initialize_payment_page_spec.rb +83 -0
  55. data/spec/services/spree/solidus_six_saferpay/initialize_payment_spec.rb +40 -0
  56. data/spec/services/spree/solidus_six_saferpay/initialize_transaction_spec.rb +85 -0
  57. data/spec/services/spree/solidus_six_saferpay/inquire_payment_page_payment_spec.rb +116 -0
  58. data/spec/services/spree/solidus_six_saferpay/inquire_payment_spec.rb +39 -0
  59. data/spec/services/spree/solidus_six_saferpay/inquire_transaction_payment_spec.rb +117 -0
  60. data/spec/services/spree/solidus_six_saferpay/payment_validator_spec.rb +100 -0
  61. data/spec/services/spree/solidus_six_saferpay/process_authorized_payment_spec.rb +39 -0
  62. data/spec/services/spree/solidus_six_saferpay/process_payment_page_payment_spec.rb +225 -0
  63. data/spec/services/spree/solidus_six_saferpay/process_transaction_payment_spec.rb +219 -0
  64. data/spec/solidus_six_saferpay/configuration_spec.rb +15 -0
  65. data/spec/solidus_six_saferpay/error_handler_spec.rb +65 -0
  66. data/spec/solidus_six_saferpay/gateway_response_spec.rb +70 -0
  67. data/spec/solidus_six_saferpay/gateway_spec.rb +365 -0
  68. data/spec/solidus_six_saferpay/payment_page_gateway_spec.rb +392 -0
  69. data/spec/solidus_six_saferpay/transaction_gateway_spec.rb +390 -0
  70. data/spec/spec_helper.rb +21 -0
  71. data/spec/support/route_access.rb +6 -0
  72. data/spec/support/uses_payment_page_gateway.rb +29 -0
  73. data/spec/support/uses_transaction_gateway.rb +28 -0
  74. metadata +240 -99
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e86c32327a8f67739e8ba8e7c730d3b6de5e1896dc353440cafb9356f093a57a
4
- data.tar.gz: a0365e0a210eeb52b898c8e1fd878038b1633cce081c11921cf1f4417662c512
3
+ metadata.gz: 5e228b5766fec776fecd596f1f9316553ed3bc9d48c4ada1adfebb470da63c7c
4
+ data.tar.gz: 1367d382455ade917798c68ced6fd717e71dafd2caeb2cefccde0d58517903e7
5
5
  SHA512:
6
- metadata.gz: 6487e39cbb59d59427219ef90dc0f86ff13ae06ecf8b4396a9ae390440b0dd6e45eeb9b65a486a7015d2003a0ac3ba94a99aa1995401d788969e19d653df262e
7
- data.tar.gz: 28261518e153591d9867f69de92d68e24e7e211c6e259881f21d38a26dd55f60e2faa777d98a12c1c4423094852c390423b66df2d6b3e3da2a654ef8021cbee6
6
+ metadata.gz: 181ec3d7959392e3b7c0a100be584091507e74cdab7fb76efe19eaa406ae36ec4bc0777b8927c54d3e41518b52808f0d26e3202a35d703aaf63eced9d3c38199
7
+ data.tar.gz: 71c01086a0e866e1a0aa48e71304c057ff662cc268db3e961ef9761eb3182f7282c28ccdd2acfd1f7f827cc3939eb64d41921cfbb3f5f590066b2e572da3c5b6
@@ -0,0 +1,35 @@
1
+ version: 2.1
2
+
3
+ orbs:
4
+ # Always take the latest version of the orb, this allows us to
5
+ # run specs against Solidus supported versions only without the need
6
+ # to change this configuration every time a Solidus version is released
7
+ # or goes EOL.
8
+ solidusio_extensions: solidusio/extensions@volatile
9
+
10
+ jobs:
11
+ run-specs-with-postgres:
12
+ executor: solidusio_extensions/postgres
13
+ steps:
14
+ - solidusio_extensions/run-tests
15
+ run-specs-with-mysql:
16
+ executor: solidusio_extensions/mysql
17
+ steps:
18
+ - solidusio_extensions/run-tests
19
+
20
+ workflows:
21
+ "Run specs on supported Solidus versions":
22
+ jobs:
23
+ - run-specs-with-postgres
24
+ - run-specs-with-mysql
25
+ "Weekly run specs against master":
26
+ triggers:
27
+ - schedule:
28
+ cron: "0 0 * * 4" # every Thursday
29
+ filters:
30
+ branches:
31
+ only:
32
+ - master
33
+ jobs:
34
+ - run-specs-with-postgres
35
+ - run-specs-with-mysql
@@ -0,0 +1,5 @@
1
+ bump:
2
+ recurse: false
3
+ file: 'lib/solidus_six_saferpay/version.rb'
4
+ message: Bump SolidusSixSaferpay to %{version}
5
+ tag: true
@@ -0,0 +1,17 @@
1
+ # Number of days of inactivity before an issue becomes stale
2
+ daysUntilStale: 60
3
+ # Number of days of inactivity before a stale issue is closed
4
+ daysUntilClose: 7
5
+ # Issues with these labels will never be considered stale
6
+ exemptLabels:
7
+ - pinned
8
+ - security
9
+ # Label to use when marking an issue as stale
10
+ staleLabel: wontfix
11
+ # Comment to post when marking an issue as stale. Set to `false` to disable
12
+ markComment: >
13
+ This issue has been automatically marked as stale because it has not had
14
+ recent activity. It will be closed if no further activity occurs. Thank you
15
+ for your contributions.
16
+ # Comment to post when closing a stale issue. Set to `false` to disable
17
+ closeComment: false
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ \#*
3
+ *~
4
+ .#*
5
+ .DS_Store
6
+ .idea
7
+ .project
8
+ .sass-cache
9
+ coverage
10
+ Gemfile.lock
11
+ tmp
12
+ nbproject
13
+ pkg
14
+ *.swp
15
+ spec/dummy
16
+ spec/examples.txt
17
+
18
+ sandbox
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,2 @@
1
+ require:
2
+ - solidus_dev_support/rubocop
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.5.1
4
+ before_install:
5
+ - gem install bundler -v 2.0.1
6
+ script:
7
+ - bin/rake extension:test_app
8
+ - bin/rake extension:specs
9
+ notifications:
10
+ slack:
11
+ secure: Vpuu/JENlZAiH67DU5bFmyKlKNmhiAZ0wSd6mjFyzcFAXaEbFIt9xkMigoEwLfQh/ZMUvKQcv3oQ6s9j5FkYImRZ0gfs1me7z/H8NTXMF5eOu7aS/gRHMGq8x2nvDBqNhSVtffqLfF3aydjZPJvGz8cvAQtqw4b+qOSIuxs2BOpcMMgEZEXW7Py6AthY2p1jxByyiqGB7NcvKsQedVtgdrnK4j+jcwK6Q9/DTOMivhWLEWAvn6VJ5zMomM5FdOFfH86uhHASGYB72ufpmKUwmFASSNHBM3CNQhZ0O/LS+a1dOlaW1BhU5q6KS/q6vgEYHyjdqcD7HhKFdlaVm6W/N1lbX+MFFcFT++l6CN8Aa3xmYpy/zWO5wwBRZw0zhYT/7P4BRoCll1D7RetnGcIV6KJyC0ydn2u/pi1kKBOgzuwbgQ+pH/lPH9+HuZzlhynRBdz2v45ctXf6AFQZmfJvFEBNwb38Q08zzGcCru0+Lu4uhFFLEwi2oMCWtpUsk0PfUJf/cUfp0hluh8wZsQWe+VQOS1NjmL8/yxjijFGzmS8WmMTb+fw7bRXFir0ecdntbP9aAhJxBN4PaMfYEFzBjCbc1e2gmwXk0VBV/0IH9hxxzIorUSmGydrWLDWiap0yDC2bm+gndodxKawT4+O45qB9jI5aYXG6JlHzrTn8QU4=
12
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5
+
6
+ branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
7
+ gem 'solidus', github: 'solidusio/solidus', branch: branch
8
+
9
+ # Needed to help Bundler figure out how to resolve dependencies,
10
+ # otherwise it takes forever to resolve them.
11
+ # See https://github.com/bundler/bundler/issues/6677
12
+ gem 'rails', '>0.a'
13
+
14
+ # Provides basic authentication functionality for testing parts of your engine
15
+ gem 'solidus_auth_devise'
16
+
17
+ case ENV['DB']
18
+ when 'mysql'
19
+ gem 'mysql2'
20
+ when 'postgresql'
21
+ gem 'pg'
22
+ else
23
+ gem 'sqlite3'
24
+ end
25
+
26
+ gemspec
27
+
28
+ # Use a local Gemfile to include development dependencies that might not be
29
+ # relevant for the project or for other contributors, e.g. pry-byebug.
30
+ #
31
+ # We use `send` instead of calling `eval_gemfile` to work around an issue with
32
+ # how Dependabot parses projects: https://github.com/dependabot/dependabot-core/issues/1658.
33
+ send(:eval_gemfile, 'Gemfile-local') if File.exist? 'Gemfile-local'
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2020 [name of plugin creator]
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Solidus nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md CHANGED
@@ -1,33 +1,26 @@
1
1
  # SolidusSixSaferpay
2
+
2
3
  The `solidus_six_saferpay` engine adds checkout options for the Saferpay Payment Page ([Integration Guide](https://saferpay.github.io/sndbx/Integration_PP.html), [JSON API documentation](http://saferpay.github.io/jsonapi/#ChapterPaymentPage)) and the Saferpay Transaction ([Integration Guide](https://saferpay.github.io/sndbx/Integration_trx.html), [JSON API documentation](https://saferpay.github.io/sndbx/Integration_trx.html)).
3
4
 
5
+ ### Disclaimer
6
+ This gem is built to be a general-purpose integration of the Six Saferpay payment interface. However due to lack of resources and because we are (as far as we know) the only users of this gem, we are only testing our use cases (PaymentPage). Therefore we can not guarantee that this will work in any other solidus shop. If you consider using this gem, please test everything thoroughly.
7
+
4
8
  ## Status
5
9
  Travis CI status: [![Build Status](https://travis-ci.org/fadendaten/solidus_six_saferpay.svg?branch=master)](https://travis-ci.org/fadendaten/solidus_six_saferpay)
6
10
 
7
-
8
11
  ## Installation
9
- Add this line to your application's Gemfile:
12
+
13
+ Add solidus_six_saferpay to your Gemfile:
10
14
 
11
15
  ```ruby
12
16
  gem 'solidus_six_saferpay'
13
17
  ```
14
18
 
15
- And then execute:
16
-
17
- ```bash
18
- $ bundle
19
- ```
20
-
21
- Or install it yourself as:
19
+ Bundle your dependencies and run the installation generator:
22
20
 
23
- ```bash
24
- $ gem install solidus_six_saferpay
25
- ```
26
-
27
- After installing the gem, copy the migrations to your host application and migrate:
28
-
29
- ```bash
30
- $ bundle exec rails g solidus_six_saferpay:install
21
+ ```shell
22
+ bundle
23
+ bundle exec rails g solidus_six_saferpay:install
31
24
  ```
32
25
 
33
26
  Add the following javascript to your `application.js` manifest file below the `//= require spree` line:
@@ -60,7 +53,6 @@ Spree::Core::Engine.routes.default_url_options { 'http://localhost:3000' }
60
53
  Spree::Core::Engine.routes.default_url_options { 'https://url-to-your-solidus-shop.tld' }
61
54
  ```
62
55
 
63
-
64
56
  ## Configuration and Usage
65
57
  After adding the `solidus_six_saferpay` gem to your Solidus Rails app, you can create new payment methods `Saferpay Payment Page` and `Saferpay Transaction` in the admin backend under "Settings" > "Payment". When adding a new Saferpay payment method, you can configure the payment method with the information you have received from SIX when creating a new test account.
66
58
 
@@ -212,9 +204,33 @@ When the user confirms the purchase in the checkout process, the saferpay paymen
212
204
  #### Checkout: Payment Cancel
213
205
  When a user cancels a payment, the `CheckoutController` receives a `fail` request and handles this request in the `#fail` action. The result is that the user is shown an error message stating that the payment was aborted.
214
206
 
207
+
208
+ ## Testing
209
+
210
+ First bundle your dependencies, then run `rake`. `rake` will default to building the dummy app if it does not exist, then it will run specs, and [Rubocop](https://github.com/bbatsov/rubocop) static code analysis. The dummy app can be regenerated by using `rake test_app`.
211
+
212
+ ```shell
213
+ bundle
214
+ bin/rake
215
+ ```
216
+
217
+ When testing your application's integration with this extension you may use its factories.
218
+ Simply add this require statement to your spec_helper:
219
+
220
+ ```ruby
221
+ require 'solidus_six_saferpay/factories'
222
+ ```
223
+
215
224
  ## Contributing
216
225
  This gem is available for everyone to use, however chances are that its implementation is still tailored towards our custom solidus-based shop.
217
226
  If you see improvements to be made, feel free to fork the gem and submit pull requests. All incoming pull requests will be discussed, but it's possible that we will reject pull requests that break functionality for our use case.
218
227
 
219
- ## License
220
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
228
+ ## Releasing
229
+
230
+ Your new extension version can be released using `gem-release` like this:
231
+
232
+ ```shell
233
+ bundle exec gem bump -v VERSION --tag --push --remote upstream && gem release
234
+ ```
235
+
236
+ Copyright (c) 2020 fadendaten GmbH, released under the New BSD License
data/Rakefile CHANGED
@@ -1,56 +1,6 @@
1
- # begin
2
- # require 'bundler/setup'
3
- # rescue LoadError
4
- # puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
- # end
1
+ # frozen_string_literal: true
6
2
 
7
- # require 'rdoc/task'
3
+ require 'solidus_dev_support/rake_tasks'
4
+ SolidusDevSupport::RakeTasks.install
8
5
 
9
- # RDoc::Task.new(:rdoc) do |rdoc|
10
- # rdoc.rdoc_dir = 'rdoc'
11
- # rdoc.title = 'SolidusSixSaferpay'
12
- # rdoc.options << '--line-numbers'
13
- # rdoc.rdoc_files.include('README.md')
14
- # rdoc.rdoc_files.include('lib/**/*.rb')
15
- # end
16
-
17
- # APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
18
- # load 'rails/tasks/engine.rake'
19
-
20
- # load 'rails/tasks/statistics.rake'
21
-
22
- # require 'bundler/gem_tasks'
23
-
24
- # require 'rspec/core/rake_task'
25
- # RSpec::Core::RakeTask.new(:spec)
26
-
27
- # task default: :spec
28
-
29
- require 'bundler'
30
-
31
- Bundler::GemHelper.install_tasks
32
-
33
- begin
34
- require 'spree/testing_support/extension_rake'
35
- require 'rspec/core/rake_task'
36
-
37
- RSpec::Core::RakeTask.new(:spec)
38
-
39
- # task default: %i(first_run spec)
40
- task default: %i(first_run spec)
41
- rescue LoadError
42
- # no rspec available
43
- end
44
-
45
- task :first_run do
46
- if Dir['spec/dummy'].empty?
47
- Rake::Task[:test_app].invoke
48
- Dir.chdir('../../')
49
- end
50
- end
51
-
52
- desc 'Generates a dummy app for testing'
53
- task :test_app do
54
- ENV['LIB_NAME'] = 'solidus_six_saferpay'
55
- Rake::Task['extension:test_app'].invoke
56
- end
6
+ task default: 'extension:specs'
@@ -1,2 +1,3 @@
1
+ //= link_tree ../images
1
2
  //= link_directory ../javascripts/solidus_six_saferpay .js
2
3
  //= link_directory ../stylesheets/solidus_six_saferpay .css
@@ -0,0 +1,2 @@
1
+ // Placeholder manifest file.
2
+ // the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/backend/all.js'
@@ -0,0 +1,2 @@
1
+ // Placeholder manifest file.
2
+ // the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/frontend/all.js'
@@ -1,30 +1,3 @@
1
1
  .saferpay-iframe {
2
2
  width: 100%;
3
3
  }
4
-
5
- .loading-animation {
6
- text-align: center;
7
- background-color: #222222;
8
-
9
- -webkit-animation: sk-scaleout 0.5s infinite ease-in-out;
10
- animation: sk-scaleout 0.5s infinite ease-in-out;
11
- }
12
-
13
- @-webkit-keyframes sk-scaleout {
14
- 0% { -webkit-transform: scale(0) }
15
- 100% {
16
- -webkit-transform: scale(0.2);
17
- opacity: 0;
18
- }
19
- }
20
-
21
- @keyframes sk-scaleout {
22
- 0% {
23
- -webkit-transform: scale(0);
24
- transform: scale(0);
25
- } 100% {
26
- -webkit-transform: scale(0.2);
27
- transform: scale(0.2);
28
- opacity: 0;
29
- }
30
- }
@@ -4,5 +4,8 @@
4
4
  text-decoration: line-through;
5
5
  }
6
6
  }
7
- }
8
7
 
8
+ .cc-img {
9
+ max-height: 25px;
10
+ }
11
+ }
@@ -0,0 +1,4 @@
1
+ /*
2
+ Placeholder manifest file.
3
+ the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/backend/all.css'
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Placeholder manifest file.
3
+ the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/frontend/all.css'
4
+ */
@@ -2,9 +2,11 @@ module Spree
2
2
  module SolidusSixSaferpay
3
3
  class CheckoutController < StoreController
4
4
 
5
- before_action :load_order
6
-
7
5
  def init
6
+ @order = current_order
7
+ redirect_to(spree.cart_path) && return unless @order
8
+
9
+
8
10
  payment_method = Spree::PaymentMethod.find(params[:payment_method_id])
9
11
  initialized_payment = initialize_payment(@order, payment_method)
10
12
 
@@ -17,10 +19,28 @@ module Spree
17
19
  end
18
20
 
19
21
  def success
22
+ order_number = params[:order_number]
23
+ @order = Spree::Order.find_by(number: order_number)
24
+
25
+ if @order.nil?
26
+ @redirect_path = spree.cart_path
27
+ render :iframe_breakout_redirect, layout: false
28
+ return
29
+ end
30
+
31
+ # ensure that completed orders don't try to reprocess the
32
+ # authorization. This could happen if a user presses the back button
33
+ # after completing an order.
34
+ if @order.completed?
35
+ @redirect_path = spree.cart_path
36
+ render :iframe_breakout_redirect, layout: false
37
+ return
38
+ end
39
+
20
40
  saferpay_payment = Spree::SixSaferpayPayment.where(order_id: @order.id).order(:created_at).last
21
41
 
22
42
  if saferpay_payment.nil?
23
- raise Spree::Core::GatewayError, t('.payment_source_not_created')
43
+ raise Spree::Core::GatewayError, t('.saferpay_payment_not_found')
24
44
  end
25
45
 
26
46
  # NOTE: PaymentPage payments are authorized directly. Instead, we
@@ -38,7 +58,7 @@ module Spree
38
58
 
39
59
  processed_authorization = process_authorization(saferpay_payment)
40
60
  if processed_authorization.success?
41
- @order.next! if @order.payment?
61
+ handle_payment_processing_success
42
62
  else
43
63
  flash[:error] = processed_authorization.user_message
44
64
  end
@@ -48,17 +68,32 @@ module Spree
48
68
  flash[:error] = payment_inquiry.user_message
49
69
  end
50
70
 
51
- @redirect_path = order_checkout_path(@order.state)
71
+ @redirect_path ||= order_checkout_path(@order.state)
52
72
  render :iframe_breakout_redirect, layout: false
53
73
  end
54
74
 
55
75
  def fail
76
+ order_number = params[:order_number]
77
+ @order = Spree::Order.find_by(number: order_number)
78
+
79
+ if @order.nil?
80
+ @redirect_path = spree.cart_path
81
+ render :iframe_breakout_redirect, layout: false
82
+ return
83
+ end
84
+
56
85
  saferpay_payment = Spree::SixSaferpayPayment.where(order_id: @order.id).order(:created_at).last
57
86
 
58
- payment_inquiry = inquire_payment(saferpay_payment)
87
+
88
+ if saferpay_payment
89
+ payment_inquiry = inquire_payment(saferpay_payment)
90
+ flash[:error] = payment_inquiry.user_message
91
+ else
92
+ user_message = I18n.t(:general_error, scope: [:solidus_six_saferpay, :errors])
93
+ flash[:error] = user_message
94
+ end
59
95
 
60
96
  @redirect_path = order_checkout_path(:payment)
61
- flash[:error] = payment_inquiry.user_message
62
97
  render :iframe_breakout_redirect, layout: false
63
98
  end
64
99
 
@@ -80,9 +115,20 @@ module Spree
80
115
  raise NotImplementedError, "Must be implemented in PaymentPageCheckoutController or TransactionCheckoutController"
81
116
  end
82
117
 
83
- def load_order
84
- @order = current_order
85
- redirect_to(spree.cart_path) && return unless @order
118
+ # Allows overriding of success behaviour in host application by setting
119
+ # SolidusSixSaferpay.config.payment_processing_success_handler
120
+ #
121
+ # By default, it will ensure that the order state is no longer "payment"
122
+ #
123
+ # Example
124
+ # config.payment_processing_success_handler = Proc.new { |order| puts "Order #{order} has been successfully paid!" }
125
+ #
126
+ def handle_payment_processing_success
127
+ if success_handler = ::SolidusSixSaferpay.config.payment_processing_success_handler.presence
128
+ success_handler.call(self, @order)
129
+ else
130
+ @order.next! if @order.payment?
131
+ end
86
132
  end
87
133
 
88
134
  def order_checkout_path(state)