solidus_six_saferpay 0.1.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) 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/solidus_six_saferpay/saferpay_payment.js +4 -1
  16. data/app/assets/javascripts/spree/backend/solidus_six_saferpay.js +2 -0
  17. data/app/assets/javascripts/spree/frontend/solidus_six_saferpay.js +2 -0
  18. data/app/assets/stylesheets/spree/backend/solidus_six_saferpay.css +4 -0
  19. data/app/assets/stylesheets/spree/frontend/solidus_six_saferpay.css +4 -0
  20. data/app/controllers/spree/solidus_six_saferpay/checkout_controller.rb +133 -17
  21. data/app/controllers/spree/solidus_six_saferpay/transaction/checkout_controller.rb +1 -1
  22. data/app/models/spree/payment_method/saferpay_payment_method.rb +1 -1
  23. data/app/models/spree/payment_method/saferpay_payment_page.rb +2 -2
  24. data/app/models/spree/payment_method/saferpay_transaction.rb +2 -2
  25. data/app/services/spree/solidus_six_saferpay/cancel_authorized_payment.rb +33 -0
  26. data/app/services/spree/solidus_six_saferpay/initialize_payment.rb +0 -1
  27. data/app/services/spree/solidus_six_saferpay/initialize_transaction.rb +0 -1
  28. data/app/services/spree/solidus_six_saferpay/inquire_payment.rb +27 -1
  29. data/app/views/spree/checkout/payment/_saferpay_payment.html.erb +2 -2
  30. data/app/views/spree/solidus_six_saferpay/checkout/{iframe_breakout_redirect.html.erb → iframe_breakout_redirect.erb} +1 -1
  31. data/bin/console +17 -0
  32. data/bin/rails +18 -0
  33. data/bin/rake +7 -0
  34. data/bin/setup +8 -0
  35. data/config/initializers/assets.rb +3 -0
  36. data/config/locales/de.yml +4 -1
  37. data/config/locales/en.yml +4 -1
  38. data/config/locales/fr.yml +4 -1
  39. data/config/routes.rb +8 -8
  40. data/lib/generators/solidus_six_saferpay/install/install_generator.rb +15 -3
  41. data/lib/solidus_six_saferpay.rb +6 -3
  42. data/lib/solidus_six_saferpay/configuration.rb +6 -7
  43. data/lib/solidus_six_saferpay/engine.rb +19 -10
  44. data/lib/solidus_six_saferpay/gateway.rb +11 -11
  45. data/lib/solidus_six_saferpay/payment_page_gateway.rb +8 -9
  46. data/lib/solidus_six_saferpay/transaction_gateway.rb +8 -9
  47. data/lib/solidus_six_saferpay/version.rb +3 -1
  48. data/solidus_six_saferpay.gemspec +42 -0
  49. data/spec/controllers/spree/solidus_six_saferpay/payment_page/checkout_controller_spec.rb +16 -0
  50. data/spec/controllers/spree/solidus_six_saferpay/transaction/checkout_controller_spec.rb +16 -0
  51. data/spec/factories/payment_methods.rb +23 -0
  52. data/spec/factories/payments.rb +11 -0
  53. data/spec/factories/spree/six_saferpay_payments.rb +118 -0
  54. data/spec/models/spree/six_saferpay_payment_spec.rb +203 -0
  55. data/spec/rails_helper.rb +73 -0
  56. data/spec/services/spree/solidus_six_saferpay/assert_payment_page_spec.rb +22 -0
  57. data/spec/services/spree/solidus_six_saferpay/authorize_payment_spec.rb +39 -0
  58. data/spec/services/spree/solidus_six_saferpay/authorize_transaction_spec.rb +24 -0
  59. data/spec/services/spree/solidus_six_saferpay/cancel_authorized_payment_spec.rb +58 -0
  60. data/spec/services/spree/solidus_six_saferpay/initialize_payment_page_spec.rb +81 -0
  61. data/spec/services/spree/solidus_six_saferpay/initialize_payment_spec.rb +40 -0
  62. data/spec/services/spree/solidus_six_saferpay/initialize_transaction_spec.rb +84 -0
  63. data/spec/services/spree/solidus_six_saferpay/inquire_payment_page_payment_spec.rb +20 -0
  64. data/spec/services/spree/solidus_six_saferpay/inquire_payment_spec.rb +39 -0
  65. data/spec/services/spree/solidus_six_saferpay/inquire_transaction_payment_spec.rb +21 -0
  66. data/spec/services/spree/solidus_six_saferpay/payment_validator_spec.rb +100 -0
  67. data/spec/services/spree/solidus_six_saferpay/process_authorized_payment_spec.rb +39 -0
  68. data/spec/services/spree/solidus_six_saferpay/process_payment_page_payment_spec.rb +20 -0
  69. data/spec/services/spree/solidus_six_saferpay/process_transaction_payment_spec.rb +20 -0
  70. data/spec/solidus_six_saferpay/configuration_spec.rb +15 -0
  71. data/spec/solidus_six_saferpay/error_handler_spec.rb +65 -0
  72. data/spec/solidus_six_saferpay/gateway_response_spec.rb +70 -0
  73. data/spec/solidus_six_saferpay/gateway_spec.rb +365 -0
  74. data/spec/solidus_six_saferpay/payment_page_gateway_spec.rb +392 -0
  75. data/spec/solidus_six_saferpay/transaction_gateway_spec.rb +390 -0
  76. data/spec/spec_helper.rb +21 -0
  77. data/spec/support/route_access.rb +6 -0
  78. data/spec/support/shared_examples/authorize_payment.rb +132 -0
  79. data/spec/support/shared_examples/checkout_controller.rb +342 -0
  80. data/spec/support/shared_examples/inquire_payment.rb +118 -0
  81. data/spec/support/shared_examples/process_authorized_payment.rb +202 -0
  82. data/spec/support/uses_payment_page_gateway.rb +29 -0
  83. data/spec/support/uses_transaction_gateway.rb +28 -0
  84. metadata +250 -101
  85. data/app/services/spree/solidus_six_saferpay/inquire_transaction.rb +0 -7
@@ -0,0 +1,73 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ require 'spec_helper'
3
+ ENV['RAILS_ENV'] ||= 'test'
4
+ require File.expand_path('../dummy/config/environment', __FILE__)
5
+ # Prevent database truncation if the environment is production
6
+ abort("The Rails environment is running in production mode!") if Rails.env.production?
7
+ require 'rspec/rails'
8
+ require 'rails-controller-testing'
9
+ Rails::Controller::Testing.install
10
+ # Add additional requires below this line. Rails is not loaded until this point!
11
+
12
+ # require 'active_support/core_ext/string/deep_symbolize_keys'
13
+
14
+ require 'shoulda/matchers'
15
+
16
+ # Requires supporting ruby files with custom matchers and macros, etc, in
17
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
18
+ # run as spec files by default. This means that files in spec/support that end
19
+ # in _spec.rb will both be required and run as specs, causing the specs to be
20
+ # run twice. It is recommended that you do not name files matching this glob to
21
+ # end with _spec.rb. You can configure this pattern with the --pattern
22
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
23
+ #
24
+ # The following line is provided for convenience purposes. It has the downside
25
+ # of increasing the boot-up time by auto-requiring all files in the support
26
+ # directory. Alternatively, in the individual `*_spec.rb` files, manually
27
+ # require only the support files necessary.
28
+ #
29
+ Dir[SolidusSixSaferpay::Engine.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }
30
+
31
+
32
+ # Set route host
33
+ Spree::Core::Engine.routes.default_url_options = {
34
+ host: 'shop.localhost:3000'
35
+ }
36
+
37
+ RSpec.configure do |config|
38
+ Shoulda::Matchers.configure do |c|
39
+ c.integrate do |with|
40
+ with.test_framework :rspec
41
+ with.library :rails
42
+ end
43
+
44
+ # include url_helpers in specs
45
+ include Spree::Core::Engine.routes.url_helpers
46
+ end
47
+
48
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
49
+ # examples within a transaction, remove the following line or assign false
50
+ # instead of true.
51
+ config.use_transactional_fixtures = true
52
+
53
+ # RSpec Rails can automatically mix in different behaviours to your tests
54
+ # based on their file location, for example enabling you to call `get` and
55
+ # `post` in specs under `spec/controllers`.
56
+ #
57
+ # You can disable this behaviour by removing the line below, and instead
58
+ # explicitly tag your specs with their type, e.g.:
59
+ #
60
+ # RSpec.describe UsersController, :type => :controller do
61
+ # # ...
62
+ # end
63
+ #
64
+ # The different available types are documented in the features, such as in
65
+ # https://relishapp.com/rspec/rspec-rails/docs
66
+ config.infer_spec_type_from_file_location!
67
+
68
+ # Filter lines from Rails gems in backtraces.
69
+ config.filter_rails_from_backtrace!
70
+ # arbitrary gems may also be filtered via:
71
+ # config.filter_gems_from_backtrace("gem name")
72
+ end
73
+
@@ -0,0 +1,22 @@
1
+ require 'rails_helper'
2
+
3
+ module Spree
4
+ module SolidusSixSaferpay
5
+ RSpec.describe AssertPaymentPage do
6
+
7
+ let(:payment) { create(:six_saferpay_payment) }
8
+
9
+ subject { described_class.new(payment) }
10
+
11
+
12
+ describe '#gateway' do
13
+ it_behaves_like "it uses the payment page gateway"
14
+ end
15
+
16
+ describe '#call' do
17
+ let(:api_response_class) { SixSaferpay::SixPaymentPage::AssertResponse }
18
+ it_behaves_like "authorize_payment"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,39 @@
1
+ require 'rails_helper'
2
+
3
+ module Spree
4
+ module SolidusSixSaferpay
5
+ RSpec.describe AuthorizePayment do
6
+
7
+ let(:payment) { create(:six_saferpay_payment) }
8
+
9
+ let(:service) { described_class.new(payment) }
10
+
11
+ describe '.call' do
12
+ it 'calls an initialized service with given order and payment method' do
13
+ expect(described_class).to receive(:new).with(payment).and_return(service)
14
+ expect(service).to receive(:call)
15
+
16
+ described_class.call(payment)
17
+ end
18
+ end
19
+
20
+ describe '#call' do
21
+ it 'fails because gateway raises an error' do
22
+ expect { service.call }.to raise_error(NotImplementedError)
23
+ end
24
+ end
25
+
26
+ describe '#gateway' do
27
+ it 'raises an error because the gateway must be defined in subclasses' do
28
+ expect { service.gateway }.to raise_error(NotImplementedError)
29
+ end
30
+ end
31
+
32
+ describe '#success?' do
33
+ it 'is initially false' do
34
+ expect(service).not_to be_success
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,24 @@
1
+ require 'rails_helper'
2
+
3
+ module Spree
4
+ module SolidusSixSaferpay
5
+ RSpec.describe AuthorizeTransaction do
6
+
7
+ let(:payment) { create(:six_saferpay_payment) }
8
+
9
+ subject { described_class.new(payment) }
10
+
11
+
12
+ describe '#gateway' do
13
+ it_behaves_like "it uses the transaction gateway"
14
+ end
15
+
16
+ describe '#call' do
17
+ let(:api_response_class) { SixSaferpay::SixTransaction::AuthorizeResponse }
18
+ it_behaves_like "authorize_payment"
19
+ end
20
+
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,58 @@
1
+ require 'rails_helper'
2
+
3
+ module Spree
4
+ module SolidusSixSaferpay
5
+ RSpec.describe CancelAuthorizedPayment do
6
+
7
+
8
+ let(:service) { described_class.new(payment) }
9
+
10
+ describe '.call' do
11
+ let(:payment) { create(:six_saferpay_payment) }
12
+
13
+ it 'calls an initialized service with given order and payment method' do
14
+ expect(described_class).to receive(:new).with(payment).and_return(service)
15
+ expect(service).to receive(:call)
16
+
17
+ described_class.call(payment)
18
+ end
19
+ end
20
+
21
+ describe '#call' do
22
+ let(:gateway) { instance_double(::SolidusSixSaferpay::Gateway) }
23
+
24
+ before do
25
+ allow(service).to receive(:gateway).and_return(gateway)
26
+ end
27
+
28
+ context 'when the payment has not been authorized yet' do
29
+ let(:payment) { create(:six_saferpay_payment) }
30
+
31
+ it 'does not cancel the payment' do
32
+ expect(gateway).not_to receive(:void)
33
+
34
+ service.call
35
+ end
36
+
37
+ it 'is treated as an error' do
38
+ expect(::SolidusSixSaferpay::ErrorHandler).to receive(:handle).with(instance_of(::SolidusSixSaferpay::InvalidSaferpayPayment))
39
+
40
+ service.call
41
+ end
42
+ end
43
+
44
+ context 'when the payment has been authorized already' do
45
+ let(:payment) { create(:six_saferpay_payment, :authorized) }
46
+
47
+ it 'voids the payment' do
48
+ expect(gateway).to receive(:void).with(payment.transaction_id)
49
+
50
+ service.call
51
+ end
52
+
53
+ end
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,81 @@
1
+ require 'rails_helper'
2
+
3
+ module Spree
4
+ module SolidusSixSaferpay
5
+ RSpec.describe InitializePaymentPage do
6
+
7
+ let(:order) { create(:order) }
8
+ let(:payment_method) { create(:saferpay_payment_method) }
9
+
10
+ subject { described_class.new(order, payment_method) }
11
+
12
+ describe '#gateway' do
13
+ it_behaves_like "it uses the payment page gateway"
14
+ end
15
+
16
+ describe '#call' do
17
+ let(:token) { '234uhfh78234hlasdfh8234e1234' }
18
+ let(:expiration) { '2015-01-30T12:45:22.258+01:00' }
19
+ let(:redirect_url) { '/saferpay/redirect/url' }
20
+
21
+ # https://saferpay.github.io/jsonapi/#Payment_v1_PaymentPage_Initialize
22
+ let(:api_response) do
23
+ SixSaferpay::SixPaymentPage::InitializeResponse.new(
24
+ response_header: SixSaferpay::ResponseHeader.new(request_id: 'test', spec_version: 'test'),
25
+ token: token,
26
+ expiration: expiration,
27
+ redirect_url: redirect_url
28
+ )
29
+ end
30
+
31
+ let(:gateway_response) do
32
+ ::SolidusSixSaferpay::GatewayResponse.new(
33
+ gateway_success,
34
+ "initialize success: #{gateway_success}",
35
+ api_response
36
+ )
37
+ end
38
+
39
+ before do
40
+ allow(subject).to receive(:gateway).
41
+ and_return(double('gateway', initialize_payment: gateway_response))
42
+ end
43
+
44
+ context 'when not successful' do
45
+ let(:gateway_success) { false }
46
+
47
+ it 'indicates failure' do
48
+ subject.call
49
+
50
+ expect(subject).not_to be_success
51
+ end
52
+
53
+ it 'does not create a saferpay payment' do
54
+ expect { subject.call }.not_to change { Spree::SixSaferpayPayment.count }
55
+ end
56
+ end
57
+
58
+ context 'when successful' do
59
+ let(:gateway_success) { true }
60
+
61
+ it 'creates a new saferpay payment' do
62
+ expect { subject.call }.to change { Spree::SixSaferpayPayment.count }.from(0).to(1)
63
+ end
64
+
65
+ it 'sets the redirect_url' do
66
+ subject.call
67
+
68
+ expect(subject.redirect_url).to eq(redirect_url)
69
+ end
70
+
71
+ it 'indicates success' do
72
+ subject.call
73
+
74
+ expect(subject).to be_success
75
+ end
76
+ end
77
+ end
78
+
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,40 @@
1
+ require 'rails_helper'
2
+
3
+ module Spree
4
+ module SolidusSixSaferpay
5
+ RSpec.describe InitializePayment do
6
+
7
+ let(:order) { create(:order) }
8
+ let(:payment_method) { create(:saferpay_payment_method) }
9
+
10
+ let(:service) { described_class.new(order, payment_method) }
11
+
12
+ describe '.call' do
13
+ it 'calls an initialized service with given order and payment method' do
14
+ expect(described_class).to receive(:new).with(order, payment_method).and_return(service)
15
+ expect(service).to receive(:call)
16
+
17
+ described_class.call(order, payment_method)
18
+ end
19
+ end
20
+
21
+ describe '#call' do
22
+ it 'fails because gateway raises an error' do
23
+ expect { service.call }.to raise_error(NotImplementedError)
24
+ end
25
+ end
26
+
27
+ describe '#gateway' do
28
+ it 'raises an error because the gateway must be defined in subclasses' do
29
+ expect { service.gateway }.to raise_error(NotImplementedError)
30
+ end
31
+ end
32
+
33
+ describe '#success?' do
34
+ it 'is initially false' do
35
+ expect(service.success).to be false
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,84 @@
1
+ require 'rails_helper'
2
+
3
+ module Spree
4
+ module SolidusSixSaferpay
5
+ RSpec.describe InitializeTransaction do
6
+
7
+ let(:order) { create(:order) }
8
+ let(:payment_method) { create(:saferpay_payment_method) }
9
+
10
+ subject { described_class.new(order, payment_method) }
11
+
12
+
13
+ describe '#gateway' do
14
+ it_behaves_like "it uses the transaction gateway"
15
+ end
16
+
17
+ describe '#call' do
18
+ let(:token) { '234uhfh78234hlasdfh8234e1234' }
19
+ let(:expiration) { '2015-01-30T12:45:22.258+01:00' }
20
+ let(:redirect_url) { '/saferpay/redirect/url' }
21
+
22
+ # https://saferpay.github.io/jsonapi/#Payment_v1_Transaction_Initialize
23
+ let(:api_response) do
24
+ SixSaferpay::SixTransaction::InitializeResponse.new(
25
+ response_header: SixSaferpay::ResponseHeader.new(request_id: 'test', spec_version: 'test'),
26
+ token: token,
27
+ expiration: expiration,
28
+ liability_shift: nil, # this is empty because we don't submit PaymentMeans on initialize already
29
+ redirect_required: true,
30
+ redirect: SixSaferpay::Redirect.new(redirect_url: redirect_url, payment_means_required: true) # since we don't provide PaymentMeans on initialize, we must always redirect
31
+ )
32
+ end
33
+
34
+ let(:gateway_response) do
35
+ ::SolidusSixSaferpay::GatewayResponse.new(
36
+ gateway_success,
37
+ "initialize success: #{gateway_success}",
38
+ api_response
39
+ )
40
+ end
41
+
42
+ before do
43
+ allow(subject).to receive(:gateway).
44
+ and_return(double('gateway', initialize_payment: gateway_response))
45
+ end
46
+
47
+ context 'when not successful' do
48
+ let(:gateway_success) { false }
49
+
50
+ it 'indicates failure' do
51
+ subject.call
52
+
53
+ expect(subject).not_to be_success
54
+ end
55
+
56
+ it 'does not create a saferpay payment' do
57
+ expect { subject.call }.not_to change { Spree::SixSaferpayPayment.count }
58
+ end
59
+ end
60
+
61
+ context 'when successful' do
62
+ let(:gateway_success) { true }
63
+
64
+ it 'creates a new saferpay payment' do
65
+ expect { subject.call }.to change { Spree::SixSaferpayPayment.count }.from(0).to(1)
66
+ end
67
+
68
+ it 'sets the redirect_url' do
69
+ subject.call
70
+
71
+ expect(subject.redirect_url).to eq(redirect_url)
72
+ end
73
+
74
+ it 'indicates success' do
75
+ subject.call
76
+
77
+ expect(subject).to be_success
78
+ end
79
+ end
80
+ end
81
+
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,20 @@
1
+ require 'rails_helper'
2
+
3
+ module Spree
4
+ module SolidusSixSaferpay
5
+ RSpec.describe InquirePaymentPagePayment do
6
+
7
+ let(:payment) { create(:six_saferpay_payment) }
8
+ subject { described_class.new(payment) }
9
+
10
+ describe '#gateway' do
11
+ it_behaves_like "it uses the payment page gateway"
12
+ end
13
+
14
+ describe '#call' do
15
+ let(:api_response_class) { SixSaferpay::SixPaymentPage::AssertResponse }
16
+ it_behaves_like "inquire_payment"
17
+ end
18
+ end
19
+ end
20
+ end