solidus_six_saferpay 0.1.3 → 0.1.8.1
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 +33 -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/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 +2 -2
- 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 +13 -12
- 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 +205 -0
- data/spec/controllers/spree/solidus_six_saferpay/transaction/checkout_controller_spec.rb +228 -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 +378 -0
- data/spec/solidus_six_saferpay/payment_page_gateway_spec.rb +390 -0
- data/spec/solidus_six_saferpay/transaction_gateway_spec.rb +387 -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 +241 -101
@@ -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,5 +1,6 @@
|
|
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 }
|
@@ -13,5 +14,4 @@ Spree::Core::Engine.routes.draw do
|
|
13
14
|
get :fail, controller: :checkout
|
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
|
@@ -87,23 +87,24 @@ module SolidusSixSaferpay
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def refund(amount, transaction_id, options = {})
|
90
|
-
|
91
|
-
|
90
|
+
Rollbar.error("Disabled Refund for: #{transaction_id}")
|
91
|
+
# payment = Spree::Payment.find_by!(response_code: transaction_id)
|
92
|
+
# refund_amount = Spree::Money.new(amount, currency: payment.currency)
|
92
93
|
|
93
|
-
saferpay_amount = SixSaferpay::Amount.new(value: refund_amount.cents, currency_code: payment.currency)
|
94
|
-
saferpay_refund = SixSaferpay::Refund.new(amount: saferpay_amount, order_id: payment.order.number)
|
95
|
-
capture_reference = SixSaferpay::CaptureReference.new(capture_id: payment.transaction_id)
|
94
|
+
# saferpay_amount = SixSaferpay::Amount.new(value: refund_amount.cents, currency_code: payment.currency)
|
95
|
+
# saferpay_refund = SixSaferpay::Refund.new(amount: saferpay_amount, order_id: payment.order.number)
|
96
|
+
# capture_reference = SixSaferpay::CaptureReference.new(capture_id: payment.transaction_id)
|
96
97
|
|
97
|
-
payment_refund = SixSaferpay::SixTransaction::Refund.new(refund: saferpay_refund, capture_reference: capture_reference)
|
98
|
+
# payment_refund = SixSaferpay::SixTransaction::Refund.new(refund: saferpay_refund, capture_reference: capture_reference)
|
98
99
|
|
99
|
-
if refund_response = SixSaferpay::Client.post(payment_refund)
|
100
|
+
# if refund_response = SixSaferpay::Client.post(payment_refund)
|
100
101
|
|
101
|
-
|
102
|
-
|
103
|
-
end
|
102
|
+
# # actually capture the refund
|
103
|
+
# capture(amount, refund_response.transaction.id, options)
|
104
|
+
# end
|
104
105
|
|
105
|
-
rescue SixSaferpay::Error => e
|
106
|
-
handle_error(e, refund_response)
|
106
|
+
# rescue SixSaferpay::Error => e
|
107
|
+
# handle_error(e, refund_response)
|
107
108
|
end
|
108
109
|
|
109
110
|
private
|
@@ -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,205 @@
|
|
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
|
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
|
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) }.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
|
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
|
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
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
context 'when order is in payment state' do
|
127
|
+
let(:order) { create(:order, state: :payment) }
|
128
|
+
|
129
|
+
it 'moves order to next state' do
|
130
|
+
expect(order).to receive(:next!)
|
131
|
+
|
132
|
+
get :success
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context 'when order is already in complete state' do
|
137
|
+
let(:order) { create(:order, state: :complete) }
|
138
|
+
|
139
|
+
it 'does not modify the order state' do
|
140
|
+
expect(order).not_to receive(:next!)
|
141
|
+
|
142
|
+
get :success
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'when the processing fails' do
|
148
|
+
let(:process_success) { false }
|
149
|
+
|
150
|
+
before do
|
151
|
+
allow(Spree::SolidusSixSaferpay::ProcessPaymentPagePayment).to receive(:call).with(payment).and_return(processed_payment)
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'displays an error message' do
|
155
|
+
get :success
|
156
|
+
|
157
|
+
expect(flash[:error]).to eq("payment processing message")
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
context 'when the payment assert fails' do
|
164
|
+
let(:assert_success) { false }
|
165
|
+
|
166
|
+
before do
|
167
|
+
allow(Spree::SolidusSixSaferpay::AssertPaymentPage).to receive(:call).with(payment).and_return(payment_assert)
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'inquires the payment' do
|
171
|
+
expect(Spree::SolidusSixSaferpay::InquirePaymentPagePayment).to receive(:call).with(payment).and_return(payment_inquiry)
|
172
|
+
|
173
|
+
get :success
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'displays an error message' do
|
177
|
+
expect(Spree::SolidusSixSaferpay::InquirePaymentPagePayment).to receive(:call).with(payment).and_return(payment_inquiry)
|
178
|
+
get :success
|
179
|
+
|
180
|
+
expect(flash[:error]).to eq("payment inquiry message")
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe 'GET fail' do
|
187
|
+
let!(:payment) { create(:six_saferpay_payment, order: order) }
|
188
|
+
let(:payment_inquiry) { instance_double("Spree::SolidusSixSaferpay::InquirePaymentPagePayment", user_message: "payment inquiry message") }
|
189
|
+
|
190
|
+
it 'inquires the payment' do
|
191
|
+
expect(Spree::SolidusSixSaferpay::InquirePaymentPagePayment).to receive(:call).with(payment).and_return(payment_inquiry)
|
192
|
+
|
193
|
+
get :fail
|
194
|
+
end
|
195
|
+
|
196
|
+
it 'displays an error message' do
|
197
|
+
expect(Spree::SolidusSixSaferpay::InquirePaymentPagePayment).to receive(:call).with(payment).and_return(payment_inquiry)
|
198
|
+
|
199
|
+
get :fail
|
200
|
+
|
201
|
+
expect(flash[:error]).to eq("payment inquiry message")
|
202
|
+
end
|
203
|
+
|
204
|
+
end
|
205
|
+
end
|