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.
- checksums.yaml +4 -4
- data/.circleci/config.yml +35 -0
- data/.gem_release.yml +5 -0
- data/.github/stale.yml +17 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +12 -0
- data/Gemfile +33 -0
- data/LICENSE +26 -0
- data/README.md +36 -20
- data/Rakefile +4 -54
- data/app/assets/config/solidus_six_saferpay_manifest.js +1 -0
- data/app/assets/images/solidus_six_saferpay/.keep +0 -0
- data/app/assets/javascripts/spree/backend/solidus_six_saferpay.js +2 -0
- data/app/assets/javascripts/spree/frontend/solidus_six_saferpay.js +2 -0
- data/app/assets/stylesheets/solidus_six_saferpay/loading_animation.scss +0 -27
- data/app/assets/stylesheets/solidus_six_saferpay/payments.scss +4 -1
- data/app/assets/stylesheets/spree/backend/solidus_six_saferpay.css +4 -0
- data/app/assets/stylesheets/spree/frontend/solidus_six_saferpay.css +4 -0
- data/app/controllers/spree/solidus_six_saferpay/checkout_controller.rb +56 -10
- data/app/services/spree/solidus_six_saferpay/inquire_payment.rb +1 -0
- data/app/views/spree/checkout/payment/_saferpay_payment.html.erb +1 -1
- data/app/views/spree/six_saferpay_payments/_six_saferpay_payment.html.erb +2 -2
- data/bin/console +17 -0
- data/bin/rails +18 -0
- data/bin/rake +7 -0
- data/bin/setup +8 -0
- data/config/initializers/assets.rb +3 -0
- data/config/locales/de.yml +1 -1
- data/config/locales/en.yml +1 -1
- data/config/locales/fr.yml +1 -1
- data/config/routes.rb +6 -6
- data/lib/generators/solidus_six_saferpay/install/install_generator.rb +15 -3
- data/lib/solidus_six_saferpay.rb +6 -3
- data/lib/solidus_six_saferpay/configuration.rb +4 -7
- data/lib/solidus_six_saferpay/engine.rb +19 -10
- data/lib/solidus_six_saferpay/gateway.rb +5 -4
- data/lib/solidus_six_saferpay/payment_page_gateway.rb +8 -9
- data/lib/solidus_six_saferpay/transaction_gateway.rb +8 -9
- data/lib/solidus_six_saferpay/version.rb +3 -1
- data/solidus_six_saferpay.gemspec +42 -0
- data/spec/controllers/spree/solidus_six_saferpay/checkout_controller_spec.rb +41 -0
- data/spec/controllers/spree/solidus_six_saferpay/payment_page/checkout_controller_spec.rb +206 -0
- data/spec/controllers/spree/solidus_six_saferpay/transaction/checkout_controller_spec.rb +229 -0
- data/spec/factories/payment_methods.rb +23 -0
- data/spec/factories/payments.rb +11 -0
- data/spec/factories/spree/six_saferpay_payments.rb +118 -0
- data/spec/models/spree/six_saferpay_payment_spec.rb +203 -0
- data/spec/rails_helper.rb +73 -0
- data/spec/services/spree/solidus_six_saferpay/assert_payment_page_spec.rb +148 -0
- data/spec/services/spree/solidus_six_saferpay/authorize_payment_spec.rb +39 -0
- data/spec/services/spree/solidus_six_saferpay/authorize_transaction_spec.rb +148 -0
- data/spec/services/spree/solidus_six_saferpay/initialize_payment_page_spec.rb +83 -0
- data/spec/services/spree/solidus_six_saferpay/initialize_payment_spec.rb +40 -0
- data/spec/services/spree/solidus_six_saferpay/initialize_transaction_spec.rb +85 -0
- data/spec/services/spree/solidus_six_saferpay/inquire_payment_page_payment_spec.rb +116 -0
- data/spec/services/spree/solidus_six_saferpay/inquire_payment_spec.rb +39 -0
- data/spec/services/spree/solidus_six_saferpay/inquire_transaction_payment_spec.rb +117 -0
- data/spec/services/spree/solidus_six_saferpay/payment_validator_spec.rb +100 -0
- data/spec/services/spree/solidus_six_saferpay/process_authorized_payment_spec.rb +39 -0
- data/spec/services/spree/solidus_six_saferpay/process_payment_page_payment_spec.rb +225 -0
- data/spec/services/spree/solidus_six_saferpay/process_transaction_payment_spec.rb +219 -0
- data/spec/solidus_six_saferpay/configuration_spec.rb +15 -0
- data/spec/solidus_six_saferpay/error_handler_spec.rb +65 -0
- data/spec/solidus_six_saferpay/gateway_response_spec.rb +70 -0
- data/spec/solidus_six_saferpay/gateway_spec.rb +365 -0
- data/spec/solidus_six_saferpay/payment_page_gateway_spec.rb +392 -0
- data/spec/solidus_six_saferpay/transaction_gateway_spec.rb +390 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/support/route_access.rb +6 -0
- data/spec/support/uses_payment_page_gateway.rb +29 -0
- data/spec/support/uses_transaction_gateway.rb +28 -0
- metadata +240 -99
@@ -21,6 +21,7 @@ module Spree
|
|
21
21
|
if inquiry.success?
|
22
22
|
saferpay_payment.update_attributes(response_hash: inquiry.api_response.to_h)
|
23
23
|
else
|
24
|
+
saferpay_payment.update_attributes(response_hash: saferpay_payment.response_hash.merge(error: "#{inquiry.error_name}"))
|
24
25
|
general_error = I18n.t(:general_error, scope: [:solidus_six_saferpay, :errors])
|
25
26
|
specific_error = I18n.t(inquiry.error_name, scope: [:six_saferpay, :error_names])
|
26
27
|
@user_message = "#{general_error}: #{specific_error}"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<% payment_container_id = "saferpay-payment-container-#{payment_method.id}" %>
|
2
2
|
<% if payment_method.preferred_as_iframe %>
|
3
|
-
<iframe class="
|
3
|
+
<iframe class="saferpay-iframe" width='100%' height='550px' id="<%= payment_container_id %>" src="" frameborder="0">
|
4
4
|
</iframe>
|
5
5
|
<script charset="utf-8">
|
6
6
|
SaferpayPayment.registerIframePaymentMethod({id: "<%= payment_method.id %>", initUrl: "<%= payment_method.init_path %>", containerId: "#<%= payment_container_id %>"})
|
@@ -2,8 +2,8 @@
|
|
2
2
|
<% container_class = "saferpay-payment #{payment.state}" %>
|
3
3
|
<div class="<%= container_class %>">
|
4
4
|
<div class="credit-card">
|
5
|
-
<
|
6
|
-
<
|
5
|
+
<div class="cc-image-container"><%= image_tag "solidus_six_saferpay/credit_cards/icons/#{saferpay_payment.icon_name}.png", class: "cc-img" %></div>
|
6
|
+
<div class="cc-number"><%= saferpay_payment.display_text %></div>
|
7
7
|
</div>
|
8
8
|
<div>
|
9
9
|
<div class="amount">
|
data/bin/console
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require "bundler/setup"
|
6
|
+
require "solidus_six_saferpay"
|
7
|
+
|
8
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
9
|
+
# with your gem easier. You can also use a different console, if you like.
|
10
|
+
$LOAD_PATH.unshift(*Dir["#{__dir__}/../app/*"])
|
11
|
+
|
12
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
13
|
+
# require "pry"
|
14
|
+
# Pry.start
|
15
|
+
|
16
|
+
require "irb"
|
17
|
+
IRB.start(__FILE__)
|
data/bin/rails
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
app_root = 'sandbox'
|
6
|
+
|
7
|
+
unless File.exist? "#{app_root}/bin/rails"
|
8
|
+
warn 'Creating the sandbox app...'
|
9
|
+
Dir.chdir "#{__dir__}/.." do
|
10
|
+
system "#{__dir__}/sandbox" or begin # rubocop:disable Style/AndOr
|
11
|
+
warn 'Automatic creation of the sandbox app failed'
|
12
|
+
exit 1
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Dir.chdir app_root
|
18
|
+
exec 'bin/rails', *ARGV
|
data/bin/rake
ADDED
data/bin/setup
ADDED
data/config/locales/de.yml
CHANGED
@@ -6,7 +6,7 @@ de:
|
|
6
6
|
init:
|
7
7
|
checkout_not_initialized: Zahlung konnte nicht gestartet werden.
|
8
8
|
success:
|
9
|
-
|
9
|
+
saferpay_payment_not_found: Six Saferpay Zahlung kann nicht gefunden werden.
|
10
10
|
fail:
|
11
11
|
payment_failed: Die Zahlung konnte nicht abgeschlossen werden.
|
12
12
|
payment_page:
|
data/config/locales/en.yml
CHANGED
@@ -6,7 +6,7 @@ en:
|
|
6
6
|
init:
|
7
7
|
checkout_not_initialized: Payment could not be initialized.
|
8
8
|
success:
|
9
|
-
|
9
|
+
saferpay_payment_not_found: Six Saferpay payment can not be found.
|
10
10
|
fail:
|
11
11
|
payment_failed: The payment could not be completed.
|
12
12
|
payment_page:
|
data/config/locales/fr.yml
CHANGED
@@ -6,7 +6,7 @@ fr:
|
|
6
6
|
init:
|
7
7
|
checkout_not_initialized: Le paiement n'a pas pu être initialisé.
|
8
8
|
success:
|
9
|
-
|
9
|
+
saferpay_payment_not_found: Paiement Six Saferpay est introuvable.
|
10
10
|
fail:
|
11
11
|
payment_failed: Le paiement n'a pas pu être complété.
|
12
12
|
payment_page:
|
data/config/routes.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
Spree::Core::Engine.routes.draw do
|
3
4
|
namespace :solidus_six_saferpay do
|
4
5
|
namespace :payment_page do
|
5
6
|
get :init, controller: :checkout, defaults: { format: :json }
|
6
|
-
get :success,
|
7
|
-
get :fail,
|
7
|
+
get 'success/:order_number', to: 'checkout#success', as: :success
|
8
|
+
get 'fail/:order_number', to: 'checkout#fail', as: :fail
|
8
9
|
end
|
9
10
|
|
10
11
|
namespace :transaction do
|
11
12
|
get :init, controller: :checkout, defaults: { format: :json }
|
12
|
-
get :success,
|
13
|
-
get :fail,
|
13
|
+
get 'success/:order_number', to: 'checkout#success', as: :success
|
14
|
+
get 'fail/:order_number', to: 'checkout#fail', as: :fail
|
14
15
|
end
|
15
16
|
end
|
16
|
-
|
17
17
|
end
|
@@ -1,18 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SolidusSixSaferpay
|
2
4
|
module Generators
|
3
5
|
class InstallGenerator < Rails::Generators::Base
|
4
6
|
class_option :auto_run_migrations, type: :boolean, default: false
|
5
7
|
|
8
|
+
def add_javascripts
|
9
|
+
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_six_saferpay\n"
|
10
|
+
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_six_saferpay\n"
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_stylesheets
|
14
|
+
inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_six_saferpay\n", before: %r{\*/}, verbose: true
|
15
|
+
inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_six_saferpay\n", before: %r{\*/}, verbose: true
|
16
|
+
end
|
17
|
+
|
6
18
|
def add_migrations
|
7
|
-
run '
|
19
|
+
run 'bin/rails railties:install:migrations FROM=solidus_six_saferpay'
|
8
20
|
end
|
9
21
|
|
10
22
|
def run_migrations
|
11
23
|
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
|
12
24
|
if run_migrations
|
13
|
-
run '
|
25
|
+
run 'bin/rails db:migrate'
|
14
26
|
else
|
15
|
-
puts 'Skipping
|
27
|
+
puts 'Skipping bin/rails db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output
|
16
28
|
end
|
17
29
|
end
|
18
30
|
end
|
data/lib/solidus_six_saferpay.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
-
|
2
|
-
require "solidus_support"
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
require
|
3
|
+
require 'solidus_core'
|
4
|
+
require 'solidus_support'
|
5
5
|
require 'six_saferpay'
|
6
|
+
|
7
|
+
require 'solidus_six_saferpay/version'
|
8
|
+
require 'solidus_six_saferpay/engine'
|
@@ -1,12 +1,9 @@
|
|
1
1
|
module SolidusSixSaferpay
|
2
|
-
|
3
2
|
class Configuration
|
4
|
-
|
5
|
-
|
6
|
-
end
|
3
|
+
include ActiveSupport::Configurable
|
4
|
+
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
6
|
+
config_accessor(:payment_processing_success_handler)
|
7
|
+
config_accessor(:error_handlers) { [] }
|
11
8
|
end
|
12
9
|
end
|
@@ -1,6 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spree/core'
|
1
4
|
module SolidusSixSaferpay
|
2
|
-
|
3
|
-
|
5
|
+
|
6
|
+
def self.config
|
7
|
+
@config ||= Configuration.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configure
|
11
|
+
yield config
|
12
|
+
end
|
13
|
+
|
14
|
+
class Engine < Rails::Engine
|
15
|
+
include SolidusSupport::EngineExtensions::Decorators
|
16
|
+
|
17
|
+
isolate_namespace ::Spree
|
18
|
+
|
19
|
+
engine_name 'solidus_six_saferpay'
|
4
20
|
|
5
21
|
config.autoload_paths += Dir["#{config.root}/lib/**/"]
|
6
22
|
config.eager_load_paths += Dir["#{config.root}/lib/**/"]
|
@@ -10,16 +26,9 @@ module SolidusSixSaferpay
|
|
10
26
|
app.config.spree.payment_methods << Spree::PaymentMethod::SaferpayTransaction
|
11
27
|
end
|
12
28
|
|
13
|
-
|
14
|
-
app.config.assets.precompile += %w( solidus_six_saferpay/application.css )
|
15
|
-
app.config.assets.precompile += %w( solidus_six_saferpay/saferpay_payment.js )
|
16
|
-
app.config.assets.precompile += %w( solidus_six_saferpay/credit_cards/**/*.png )
|
17
|
-
end
|
18
|
-
|
29
|
+
# use rspec for tests
|
19
30
|
config.generators do |g|
|
20
31
|
g.test_framework :rspec
|
21
|
-
g.fixture_replacement :factory_bot
|
22
|
-
g.factory_bot dir: 'spec/factories'
|
23
32
|
end
|
24
33
|
end
|
25
34
|
end
|
@@ -5,9 +5,6 @@ module SolidusSixSaferpay
|
|
5
5
|
|
6
6
|
def initialize(options = {})
|
7
7
|
SixSaferpay.configure do |config|
|
8
|
-
config.success_url = options.fetch(:success_url)
|
9
|
-
config.fail_url = options.fetch(:fail_url)
|
10
|
-
|
11
8
|
# Allow config via ENV for static values
|
12
9
|
config.customer_id = options.fetch(:customer_id) { ENV.fetch('SIX_SAFERPAY_CUSTOMER_ID') }
|
13
10
|
config.terminal_id = options.fetch(:terminal_id) { ENV.fetch('SIX_SAFERPAY_TERMINAL_ID') }
|
@@ -156,7 +153,7 @@ module SolidusSixSaferpay
|
|
156
153
|
)
|
157
154
|
payer = SixSaferpay::Payer.new(language_code: I18n.locale, billing_address: billing_address, delivery_address: delivery_address)
|
158
155
|
|
159
|
-
params = { payment: payment, payer: payer }
|
156
|
+
params = { payment: payment, payer: payer, return_urls: return_urls(order) }
|
160
157
|
|
161
158
|
six_payment_methods = payment_method.enabled_payment_methods
|
162
159
|
params.merge!(payment_methods: six_payment_methods) unless six_payment_methods.blank?
|
@@ -164,6 +161,10 @@ module SolidusSixSaferpay
|
|
164
161
|
params
|
165
162
|
end
|
166
163
|
|
164
|
+
def return_urls(order)
|
165
|
+
raise NotImplementedError, "Must be implemented in PaymentPageGateway or TransactionGateway"
|
166
|
+
end
|
167
|
+
|
167
168
|
def response(success, message, api_response, options = {})
|
168
169
|
GatewayResponse.new(success, message, api_response, options)
|
169
170
|
end
|
@@ -1,15 +1,6 @@
|
|
1
1
|
module SolidusSixSaferpay
|
2
2
|
class PaymentPageGateway < Gateway
|
3
3
|
|
4
|
-
def initialize(options = {})
|
5
|
-
super(
|
6
|
-
options.merge(
|
7
|
-
success_url: url_helpers.solidus_six_saferpay_payment_page_success_url,
|
8
|
-
fail_url: url_helpers.solidus_six_saferpay_payment_page_fail_url
|
9
|
-
)
|
10
|
-
)
|
11
|
-
end
|
12
|
-
|
13
4
|
def inquire(saferpay_payment, options = {})
|
14
5
|
inquire_response = perform_assert_request(saferpay_payment, options)
|
15
6
|
|
@@ -47,6 +38,14 @@ module SolidusSixSaferpay
|
|
47
38
|
SixSaferpay::SixPaymentPage::Initialize.new(interface_initialize_params(order, payment_method))
|
48
39
|
end
|
49
40
|
|
41
|
+
def return_urls(order)
|
42
|
+
SixSaferpay::ReturnUrls.new(
|
43
|
+
success: url_helpers.solidus_six_saferpay_payment_page_success_url(order.number),
|
44
|
+
fd_fail: url_helpers.solidus_six_saferpay_payment_page_fail_url(order.number),
|
45
|
+
fd_abort: url_helpers.solidus_six_saferpay_payment_page_fail_url(order.number)
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
50
49
|
def perform_assert_request(saferpay_payment, options = {})
|
51
50
|
payment_page_assert = SixSaferpay::SixPaymentPage::Assert.new(token: saferpay_payment.token)
|
52
51
|
SixSaferpay::Client.post(payment_page_assert)
|
@@ -1,15 +1,6 @@
|
|
1
1
|
module SolidusSixSaferpay
|
2
2
|
class TransactionGateway < Gateway
|
3
3
|
|
4
|
-
def initialize(options = {})
|
5
|
-
super(
|
6
|
-
options.merge(
|
7
|
-
success_url: url_helpers.solidus_six_saferpay_transaction_success_url,
|
8
|
-
fail_url: url_helpers.solidus_six_saferpay_transaction_fail_url
|
9
|
-
)
|
10
|
-
)
|
11
|
-
end
|
12
|
-
|
13
4
|
def inquire(saferpay_payment, options = {})
|
14
5
|
transaction_inquire = SixSaferpay::SixTransaction::Inquire.new(transaction_reference: saferpay_payment.transaction_id)
|
15
6
|
inquire_response = SixSaferpay::Client.post(transaction_inquire)
|
@@ -43,5 +34,13 @@ module SolidusSixSaferpay
|
|
43
34
|
def interface_initialize_object(order, payment_method)
|
44
35
|
SixSaferpay::SixTransaction::Initialize.new(interface_initialize_params(order, payment_method))
|
45
36
|
end
|
37
|
+
|
38
|
+
def return_urls(order)
|
39
|
+
SixSaferpay::ReturnUrls.new(
|
40
|
+
success: url_helpers.solidus_six_saferpay_transaction_success_url(order.number),
|
41
|
+
fd_fail: url_helpers.solidus_six_saferpay_transaction_fail_url(order.number),
|
42
|
+
fd_abort: url_helpers.solidus_six_saferpay_transaction_fail_url(order.number)
|
43
|
+
)
|
44
|
+
end
|
46
45
|
end
|
47
46
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/solidus_six_saferpay/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'solidus_six_saferpay'
|
7
|
+
spec.version = SolidusSixSaferpay::VERSION
|
8
|
+
spec.authors = ['Simon Kiener']
|
9
|
+
spec.email = ['jugglinghobo@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Saferpay Payment Page and Transaction payment methods for Solidus'
|
12
|
+
spec.description = 'Adds Saferpay Payment Page and Transaction payment methods to your Solidus application'
|
13
|
+
spec.homepage = 'https://github.com/fadendaten/solidus_six_saferpay'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = 'https://github.com/fadendaten/solidus_six_saferpay'
|
18
|
+
|
19
|
+
spec.required_ruby_version = Gem::Requirement.new('~> 2.4')
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") }
|
24
|
+
|
25
|
+
spec.files = files.grep_v(%r{^(test|spec|features)/})
|
26
|
+
spec.test_files = files.grep(%r{^(test|spec|features)/})
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 3']
|
32
|
+
spec.add_dependency 'solidus_support', '~> 0.4.0'
|
33
|
+
spec.add_dependency "six_saferpay", "~> 2.2"
|
34
|
+
spec.add_dependency "rails-i18n", "~> 5.1"
|
35
|
+
|
36
|
+
spec.add_development_dependency 'solidus_dev_support'
|
37
|
+
|
38
|
+
spec.add_development_dependency "shoulda-matchers", "~> 4.1"
|
39
|
+
spec.add_development_dependency "rails-controller-testing", "~> 1.0", ">= 1.0.4"
|
40
|
+
spec.add_development_dependency "pry", "~> 0.12"
|
41
|
+
spec.add_development_dependency "pry-rails", "~> 0.3"
|
42
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe Spree::SolidusSixSaferpay::CheckoutController, type: :controller do
|
4
|
+
routes { Spree::Core::Engine.routes }
|
5
|
+
|
6
|
+
let(:user) { create(:user) }
|
7
|
+
let(:order) { create(:order) }
|
8
|
+
let(:payment_method) { create(:saferpay_payment_method_transaction) }
|
9
|
+
let(:payment) { create(:six_saferpay_payment) }
|
10
|
+
|
11
|
+
let(:subject) { described_class.new }
|
12
|
+
|
13
|
+
before do
|
14
|
+
allow(controller).to receive_messages try_spree_current_user: user
|
15
|
+
allow(controller).to receive_messages current_order: order
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#initialize_payment' do
|
19
|
+
it 'is not implemented in this superclass' do
|
20
|
+
expect { subject.send(:initialize_payment, order, payment_method) }.to raise_error(NotImplementedError)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#authorize_payment' do
|
25
|
+
it 'is not implemented in this superclass' do
|
26
|
+
expect { subject.send(:authorize_payment, payment) }.to raise_error(NotImplementedError)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#process_authorization' do
|
31
|
+
it 'is not implemented in this superclass' do
|
32
|
+
expect { subject.send(:process_authorization, payment) }.to raise_error(NotImplementedError)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#inquire_payment' do
|
37
|
+
it 'is not implemented in this superclass' do
|
38
|
+
expect { subject.send(:inquire_payment, payment) }.to raise_error(NotImplementedError)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,206 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe Spree::SolidusSixSaferpay::PaymentPage::CheckoutController, type: :controller do
|
4
|
+
routes { Spree::Core::Engine.routes }
|
5
|
+
|
6
|
+
let(:user) { create(:user) }
|
7
|
+
let(:order) { create(:order) }
|
8
|
+
let(:payment_method) { create(:saferpay_payment_method_payment_page) }
|
9
|
+
|
10
|
+
let(:subject) { described_class.new }
|
11
|
+
|
12
|
+
before do
|
13
|
+
allow(controller).to receive_messages try_spree_current_user: user
|
14
|
+
allow(controller).to receive_messages current_order: order
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'GET init' do
|
18
|
+
let(:success) { false }
|
19
|
+
let(:redirect_url) { '/saferpay/redirect/url' }
|
20
|
+
let(:initialized_payment) { instance_double("Spree::SolidusSixSaferpay::InitializePaymentPage", success?: success, redirect_url: redirect_url) }
|
21
|
+
|
22
|
+
it 'tries to the saferpay payment' do
|
23
|
+
expect(Spree::SolidusSixSaferpay::InitializePaymentPage).to receive(:call).with(order, payment_method).and_return(initialized_payment)
|
24
|
+
|
25
|
+
get :init, params: { payment_method_id: payment_method.id }
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
context 'when payment initialize succeeds' do
|
30
|
+
let(:success) { true }
|
31
|
+
|
32
|
+
before do
|
33
|
+
allow(Spree::SolidusSixSaferpay::InitializePaymentPage).to receive(:call).with(order, payment_method).and_return(initialized_payment)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'returns the redirect_url' do
|
37
|
+
get :init, params: { payment_method_id: payment_method.id }
|
38
|
+
|
39
|
+
body = JSON.parse(response.body)
|
40
|
+
expect(body["redirect_url"]).to eq(redirect_url)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when payment initialize fails' do
|
45
|
+
let(:success) { false }
|
46
|
+
|
47
|
+
before do
|
48
|
+
allow(Spree::SolidusSixSaferpay::InitializePaymentPage).to receive(:call).with(order, payment_method).and_return(initialized_payment)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'returns an error' do
|
52
|
+
get :init, params: { payment_method_id: payment_method.id }
|
53
|
+
|
54
|
+
expect(response.body).to match(/errors/)
|
55
|
+
expect(response.status).to eq(422)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'GET success' do
|
62
|
+
context 'when the order is not found' do
|
63
|
+
let(:order) { nil }
|
64
|
+
|
65
|
+
it 'redirects to the cart page via iframe breakout' do
|
66
|
+
get :success, params: { order_number: "not_found" }
|
67
|
+
expect(assigns(:redirect_path)).to eq(routes.cart_path)
|
68
|
+
expect(response).to render_template :iframe_breakout_redirect
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'when the order is already completed' do
|
73
|
+
let(:order) { create(:order_ready_to_ship) }
|
74
|
+
|
75
|
+
it 'redirects to the cart page via iframe breakout' do
|
76
|
+
get :success, params: { order_number: order.number }
|
77
|
+
expect(assigns(:redirect_path)).to eq(routes.cart_path)
|
78
|
+
expect(response).to render_template :iframe_breakout_redirect
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'when payment could not be created' do
|
83
|
+
let!(:payment) { nil }
|
84
|
+
|
85
|
+
it 'raises an error because no payment exists' do
|
86
|
+
expect{ get(:success, params: { order_number: order.number }) }.to raise_error(Spree::Core::GatewayError)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'when payment create was successful' do
|
91
|
+
let!(:payment) { create(:six_saferpay_payment, order: order) }
|
92
|
+
let(:assert_success) { false }
|
93
|
+
let(:payment_assert) { instance_double("Spree::SolidusSixSaferpay::AssertPaymentPage", success?: assert_success) }
|
94
|
+
let(:payment_inquiry) { instance_double("Spree::SolidusSixSaferpay::InquirePaymentPagePayment", user_message: "payment inquiry message") }
|
95
|
+
|
96
|
+
it 'asserts the payment' do
|
97
|
+
expect(Spree::SolidusSixSaferpay::AssertPaymentPage).to receive(:call).with(payment).and_return(payment_assert)
|
98
|
+
expect(Spree::SolidusSixSaferpay::InquirePaymentPagePayment).to receive(:call).with(payment).and_return(payment_inquiry)
|
99
|
+
|
100
|
+
get :success, params: { order_number: order.number }
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'when the payment assert is successful' do
|
104
|
+
let(:assert_success) { true }
|
105
|
+
let(:process_success) { false }
|
106
|
+
let(:processed_payment) { instance_double("Spree::SolidusSixSaferpay::ProcessPaymentPagePayment", success?: process_success, user_message: "payment processing message") }
|
107
|
+
|
108
|
+
before do
|
109
|
+
allow(Spree::SolidusSixSaferpay::AssertPaymentPage).to receive(:call).with(payment).and_return(payment_assert)
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'processes the asserted payment' do
|
113
|
+
expect(Spree::SolidusSixSaferpay::ProcessPaymentPagePayment).to receive(:call).with(payment).and_return(processed_payment)
|
114
|
+
|
115
|
+
get :success, params: { order_number: order.number }
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'when the processing is successful' do
|
119
|
+
let(:process_success) { true }
|
120
|
+
|
121
|
+
before do
|
122
|
+
allow(Spree::SolidusSixSaferpay::ProcessPaymentPagePayment).to receive(:call).with(payment).and_return(processed_payment)
|
123
|
+
allow(Spree::Order).to receive(:find_by).with(number: order.number).and_return(order)
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
context 'when order is in payment state' do
|
128
|
+
let(:order) { create(:order, state: :payment) }
|
129
|
+
|
130
|
+
it 'moves order to next state' do
|
131
|
+
expect(order).to receive(:next!)
|
132
|
+
|
133
|
+
get :success, params: { order_number: order.number }
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'when order is already in complete state' do
|
138
|
+
let(:order) { create(:order, state: :complete) }
|
139
|
+
|
140
|
+
it 'does not modify the order state' do
|
141
|
+
expect(order).not_to receive(:next!)
|
142
|
+
|
143
|
+
get :success, params: { order_number: order.number }
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'when the processing fails' do
|
149
|
+
let(:process_success) { false }
|
150
|
+
|
151
|
+
before do
|
152
|
+
allow(Spree::SolidusSixSaferpay::ProcessPaymentPagePayment).to receive(:call).with(payment).and_return(processed_payment)
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'displays an error message' do
|
156
|
+
get :success, params: { order_number: order.number }
|
157
|
+
|
158
|
+
expect(flash[:error]).to eq("payment processing message")
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
context 'when the payment assert fails' do
|
165
|
+
let(:assert_success) { false }
|
166
|
+
|
167
|
+
before do
|
168
|
+
allow(Spree::SolidusSixSaferpay::AssertPaymentPage).to receive(:call).with(payment).and_return(payment_assert)
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'inquires the payment' do
|
172
|
+
expect(Spree::SolidusSixSaferpay::InquirePaymentPagePayment).to receive(:call).with(payment).and_return(payment_inquiry)
|
173
|
+
|
174
|
+
get :success, params: { order_number: order.number }
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'displays an error message' do
|
178
|
+
expect(Spree::SolidusSixSaferpay::InquirePaymentPagePayment).to receive(:call).with(payment).and_return(payment_inquiry)
|
179
|
+
get :success, params: { order_number: order.number }
|
180
|
+
|
181
|
+
expect(flash[:error]).to eq("payment inquiry message")
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
describe 'GET fail' do
|
188
|
+
let!(:payment) { create(:six_saferpay_payment, order: order) }
|
189
|
+
let(:payment_inquiry) { instance_double("Spree::SolidusSixSaferpay::InquirePaymentPagePayment", user_message: "payment inquiry message") }
|
190
|
+
|
191
|
+
it 'inquires the payment' do
|
192
|
+
expect(Spree::SolidusSixSaferpay::InquirePaymentPagePayment).to receive(:call).with(payment).and_return(payment_inquiry)
|
193
|
+
|
194
|
+
get :fail, params: { order_number: order.number }
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'displays an error message' do
|
198
|
+
expect(Spree::SolidusSixSaferpay::InquirePaymentPagePayment).to receive(:call).with(payment).and_return(payment_inquiry)
|
199
|
+
|
200
|
+
get :fail, params: { order_number: order.number }
|
201
|
+
|
202
|
+
expect(flash[:error]).to eq("payment inquiry message")
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
206
|
+
end
|