defra_ruby_mocks 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/defra_ruby_mocks/govpay_controller.rb +33 -3
- data/app/services/defra_ruby_mocks/govpay_create_payment_service.rb +2 -2
- data/config/routes.rb +6 -1
- data/lib/defra_ruby_mocks/version.rb +1 -1
- data/lib/defra_ruby_mocks.rb +0 -6
- metadata +2 -4
- data/app/jobs/defra_ruby_mocks/application_job.rb +0 -6
- data/app/jobs/defra_ruby_mocks/govpay_payment_callback_job.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: daca7a21c8e025f343ee8e118ce47db24bc156f01646d747b3eb69f779f8f47e
|
4
|
+
data.tar.gz: 7d4d39f87f9caae3bf194ff94eb5e952d841deb2f97928177e83b739158166a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b95c89f6d29270099b4d96c5b841de3cbe2f97648a44006bfa13f442e35ea8b191b2c436db0426854efefdc9c001b89686eb3db004ab16acb6854b2036b05f7a
|
7
|
+
data.tar.gz: de085b31d9767d688660ee45b6530cd139d9cb3d4a2a313c5aa170494d415dc88c308f794a7c60b2891a0da6d47c84ce838318455399fc37f6fbcef783f833f0
|
@@ -8,17 +8,31 @@ module DefraRubyMocks
|
|
8
8
|
def create_payment
|
9
9
|
valid_create_params
|
10
10
|
|
11
|
-
|
12
|
-
DefraRubyMocks::GovpayPaymentCallbackJob.perform_later(params[:return_url])
|
11
|
+
store_return_url(params[:return_url])
|
13
12
|
|
14
13
|
render json: GovpayCreatePaymentService.new.run(
|
15
|
-
amount: params[:amount], description: params[:description]
|
14
|
+
amount: params[:amount], description: params[:description]
|
16
15
|
)
|
17
16
|
rescue StandardError => e
|
18
17
|
Rails.logger.error("MOCKS: Govpay payment creation error: #{e.message}")
|
19
18
|
head 500
|
20
19
|
end
|
21
20
|
|
21
|
+
# This mocks the Govpay route which presents the payment details page to the user.
|
22
|
+
# We don't mock the actual payment details and payment confirmation pages - we go
|
23
|
+
# straight to the application callback route.
|
24
|
+
def next_url
|
25
|
+
response_url = retrieve_return_url
|
26
|
+
Rails.logger.warn "Govpay mock calling response URL #{response_url}"
|
27
|
+
redirect_to response_url
|
28
|
+
# RestClient::Request.execute(method: :GET, url: response_url)
|
29
|
+
rescue RestClient::ExceptionWithResponse => e
|
30
|
+
Rails.logger.warn "Govpay mock: RestClient received response: #{e}"
|
31
|
+
rescue StandardError => e
|
32
|
+
Rails.logger.error("Govpay mock: Error sending request to govpay: #{e}")
|
33
|
+
Airbrake.notify(e, message: "Error on govpay request")
|
34
|
+
end
|
35
|
+
|
22
36
|
def payment_details
|
23
37
|
valid_payment_id
|
24
38
|
render json: GovpayGetPaymentService.new.run(payment_id: params[:payment_id])
|
@@ -44,6 +58,22 @@ module DefraRubyMocks
|
|
44
58
|
head 500
|
45
59
|
end
|
46
60
|
|
61
|
+
private
|
62
|
+
|
63
|
+
# We need to persist the return_url between the initial payment creation request and the execution of next_url
|
64
|
+
def return_url_filepath
|
65
|
+
"#{Dir.tmpdir}/last_return_url"
|
66
|
+
end
|
67
|
+
|
68
|
+
def store_return_url(return_url)
|
69
|
+
Rails.logger.warn ":::::: storing return_url #{return_url}"
|
70
|
+
File.write(return_url_filepath, return_url)
|
71
|
+
end
|
72
|
+
|
73
|
+
def retrieve_return_url
|
74
|
+
File.read(return_url_filepath)
|
75
|
+
end
|
76
|
+
|
47
77
|
def valid_create_params
|
48
78
|
params.require(%i[amount description return_url])
|
49
79
|
end
|
@@ -5,12 +5,12 @@ require "securerandom"
|
|
5
5
|
module DefraRubyMocks
|
6
6
|
class GovpayCreatePaymentService < BaseService
|
7
7
|
|
8
|
-
def run(amount:, description
|
8
|
+
def run(amount:, description:)
|
9
9
|
success_response.merge(
|
10
10
|
{
|
11
11
|
_links: {
|
12
12
|
self: { href: "#{base_url}/#{payment_id}", method: "GET" },
|
13
|
-
next_url: { href:
|
13
|
+
next_url: { href: "#{base_url}/secure/next-url-uuid-abc123", method: "GET" }
|
14
14
|
},
|
15
15
|
amount: amount.to_i,
|
16
16
|
description: description,
|
data/config/routes.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
DefraRubyMocks::Engine.routes.draw do
|
3
|
+
DefraRubyMocks::Engine.routes.draw do # rubocop:disable Metrics/BlockLength
|
4
4
|
get "/company/:id",
|
5
5
|
to: "company#show",
|
6
6
|
as: "company",
|
@@ -16,6 +16,11 @@ DefraRubyMocks::Engine.routes.draw do
|
|
16
16
|
as: "govpay_create_payment",
|
17
17
|
constraints: ->(_request) { DefraRubyMocks.configuration.enabled? }
|
18
18
|
|
19
|
+
get "/govpay/v1/payments/secure/:uuid",
|
20
|
+
to: "govpay#next_url",
|
21
|
+
as: "govpay_next_url",
|
22
|
+
constraints: ->(_request) { DefraRubyMocks.configuration.enabled? }
|
23
|
+
|
19
24
|
get "/govpay/v1/payments/:payment_id",
|
20
25
|
to: "govpay#payment_details",
|
21
26
|
as: "govpay_payment_details",
|
data/lib/defra_ruby_mocks.rb
CHANGED
@@ -12,12 +12,6 @@ module DefraRubyMocks
|
|
12
12
|
def configuration
|
13
13
|
@configuration ||= Configuration.new
|
14
14
|
end
|
15
|
-
|
16
|
-
# Added for testing. Without we cannot test both a config object with and
|
17
|
-
# with set values in the same rspec session
|
18
|
-
def reset_configuration
|
19
|
-
@configuration = nil
|
20
|
-
end
|
21
15
|
end
|
22
16
|
|
23
17
|
def self.configure
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: defra_ruby_mocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Defra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -66,8 +66,6 @@ files:
|
|
66
66
|
- app/controllers/defra_ruby_mocks/application_controller.rb
|
67
67
|
- app/controllers/defra_ruby_mocks/company_controller.rb
|
68
68
|
- app/controllers/defra_ruby_mocks/govpay_controller.rb
|
69
|
-
- app/jobs/defra_ruby_mocks/application_job.rb
|
70
|
-
- app/jobs/defra_ruby_mocks/govpay_payment_callback_job.rb
|
71
69
|
- app/services/defra_ruby_mocks/base_service.rb
|
72
70
|
- app/services/defra_ruby_mocks/companies_house_service.rb
|
73
71
|
- app/services/defra_ruby_mocks/govpay_create_payment_service.rb
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module DefraRubyMocks
|
4
|
-
class GovpayPaymentCallbackJob < DefraRubyMocks::ApplicationJob
|
5
|
-
queue_as :default
|
6
|
-
|
7
|
-
def perform(*response_url)
|
8
|
-
Rails.logger.debug "GovpayPaymentCallbackJob calling response URL #{response_url}"
|
9
|
-
RestClient::Request.execute(method: :GET, url: response_url[0])
|
10
|
-
rescue RestClient::ExceptionWithResponse => e
|
11
|
-
Rails.logger.debug "GovpayPaymentCallbackJob: RestClient received response: #{e}"
|
12
|
-
rescue StandardError => e
|
13
|
-
Rails.logger.error("GovpayPaymentCallbackJob: Error sending request to govpay: #{e}")
|
14
|
-
Airbrake.notify(e, message: "Error on govpay request")
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|