defra_ruby_mocks 5.0.0 → 5.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a608d402c9667f9aef72c67f4ae1edf115d0385b4315e37e6c926d1c79d92958
4
- data.tar.gz: 2d8f253849caf74c2486777e82f2c5406bde65725d14078271452df3afdaab98
3
+ metadata.gz: 9a54f9624d84a56d58fb86ff1a7556d5d7c88db8cd4c93106c260e1b14008c38
4
+ data.tar.gz: 020561b363c345fa55dc26a27b9cc5bbe4306a5c5743ef824d095463b8e80e12
5
5
  SHA512:
6
- metadata.gz: b4550088184172df4cf64516baa91a60ae1f6fd496cb2a3d8dbbe9c3375dc1afc73e2dbea191217d059c34773d73de56cc4b5c8c854a1b1cb47869ca8cc8bd22
7
- data.tar.gz: ec7ca0077154ced7847aa76947403b2a994a7b3f2460bc1451755abc4e31f16ed30407ca1c60588f1d04f66c28b9b075c6d64abdcf7021b7ad18775323d85faf
6
+ metadata.gz: 60761ea8c403d69d31ef96d890d37b90013b26e0dc0cd271ef7b5a3efb933225d3fb75178dc3aae3f8715088e1fe2e26344118668bed43cee9f44b901c0071e9
7
+ data.tar.gz: d6c620d9805c12b864727a0f6d7b52356a18925858f8ef11c6e44889764f317d52379146c3fc25adede7e06c8c04e814fd8990b03d57816f4604bf70db7d9490
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module DefraRubyMocks
6
+ module CanUseAwsS3
7
+
8
+ extend ActiveSupport::Concern
9
+
10
+ DEFAULT_LAST_REFUND_REQUEST_TIME = 1.day.ago.freeze
11
+
12
+ included do
13
+
14
+ def s3_bucket_name
15
+ @s3_bucket_name ||= ENV.fetch("AWS_DEFRA_RUBY_MOCKS_BUCKET", nil)
16
+ end
17
+
18
+ def set_response_status(response_status_filename:, status:)
19
+ Rails.logger.info "[DefraRubyMocks] [AwsS3] Setting #{response_status_filename} status to \"#{status}\""
20
+
21
+ AwsBucketService.write(s3_bucket_name, response_status_filename, status)
22
+ end
23
+
24
+ # Check whether a non-default status value has been requested
25
+ def response_status(response_status_filename:, default_status:)
26
+ status = AwsBucketService.read(s3_bucket_name, response_status_filename)
27
+ Rails.logger.warn "[DefraRubyMocks] [AwsS3] read #{response_status_filename}: \"#{status}\""
28
+
29
+ status || default_status
30
+ rescue StandardError => e
31
+ # This is expected behaviour when the status default override file is not present.
32
+ Rails.logger.warn "[DefraRubyMocks] [AwsS3] failed to read #{response_status_filename}: #{e}"
33
+
34
+ default_status
35
+ end
36
+
37
+ # let the refund details service know how long since the refund was requested
38
+ def write_refund_requested_timestamp(timestamp_file_name:)
39
+ Rails.logger.warn "[DefraRubyMocks] [AwsS3] storing timestamp_file_name timestamp"
40
+ AwsBucketService.write(s3_bucket_name, timestamp_file_name, Time.zone.now.to_s)
41
+ end
42
+
43
+ def refund_request_timestamp(timestamp_file_name:)
44
+ timestamp = AwsBucketService.read(s3_bucket_name, timestamp_file_name)
45
+ timestamp ? Time.parse(timestamp) : DEFAULT_LAST_REFUND_REQUEST_TIME
46
+ rescue StandardError
47
+ DEFAULT_LAST_REFUND_REQUEST_TIME
48
+ end
49
+ end
50
+ end
51
+ end
@@ -3,6 +3,8 @@
3
3
  module DefraRubyMocks
4
4
  class GovpayController < ::DefraRubyMocks::ApplicationController
5
5
 
6
+ include CanUseAwsS3
7
+
6
8
  skip_before_action :verify_authenticity_token
7
9
 
8
10
  def create_payment
@@ -14,7 +16,7 @@ module DefraRubyMocks
14
16
  amount: params[:amount], description: params[:description]
15
17
  )
16
18
  rescue StandardError => e
17
- Rails.logger.error("MOCKS: Govpay payment creation error: #{e.message}")
19
+ Rails.logger.error("[DefraRubyMocks] [create_payment] error: #{e}")
18
20
  head 500
19
21
  end
20
22
 
@@ -23,12 +25,12 @@ module DefraRubyMocks
23
25
  # straight to the application callback route.
24
26
  def next_url
25
27
  response_url = retrieve_return_url
26
- Rails.logger.warn "Govpay mock calling response URL #{response_url}"
28
+ Rails.logger.warn "[DefraRubyMocks] [Govpay] calling response URL #{response_url}"
27
29
  redirect_to response_url, allow_other_host: true
28
30
  rescue RestClient::ExceptionWithResponse => e
29
- Rails.logger.warn "Govpay mock: RestClient received response: #{e}"
31
+ Rails.logger.warn "[DefraRubyMocks] [Govpay] RestClient received response: #{e}"
30
32
  rescue StandardError => e
31
- Rails.logger.error("Govpay mock: Error sending request to govpay: #{e}")
33
+ Rails.logger.error("[DefraRubyMocks] [Govpay] Error sending request to govpay: #{e}")
32
34
  Airbrake.notify(e, message: "Error on govpay request")
33
35
  end
34
36
 
@@ -36,7 +38,7 @@ module DefraRubyMocks
36
38
  valid_payment_id
37
39
  render json: GovpayGetPaymentService.new.run(payment_id: params[:payment_id])
38
40
  rescue StandardError => e
39
- Rails.logger.error("MOCKS: Govpay payment details error: #{e.message}")
41
+ Rails.logger.error("[DefraRubyMocks] [payment_details] error: #{e}")
40
42
  head 422
41
43
  end
42
44
 
@@ -46,36 +48,32 @@ module DefraRubyMocks
46
48
  amount: params[:amount],
47
49
  refund_amount_available: params[:refund_amount_available])
48
50
  rescue StandardError => e
49
- Rails.logger.error("MOCKS: Govpay refund error: #{e.message}")
51
+ Rails.logger.error("[DefraRubyMocks] [create_refund] error: #{e}")
50
52
  head 500
51
53
  end
52
54
 
53
55
  def refund_details
54
56
  render json: GovpayRefundDetailsService.new.run(payment_id: params[:payment_id], refund_id: params[:refund_id])
55
57
  rescue StandardError => e
56
- Rails.logger.error("MOCKS: Govpay refund error: #{e.message}")
58
+ Rails.logger.error("[DefraRubyMocks] [refund_details] error: #{e}")
57
59
  head 500
58
60
  end
59
61
 
60
62
  private
61
63
 
62
- def s3_bucket_name
63
- @s3_bucket_name = ENV.fetch("AWS_DEFRA_RUBY_MOCKS_BUCKET", nil)
64
- end
65
-
66
64
  def return_url_file_name
67
- @return_url_file_name = "return_url_file"
65
+ @return_url_file_name ||= "return_url_file"
68
66
  end
69
67
 
70
68
  # We need to persist the return_url between the initial payment creation request and the execution of next_url.
71
69
  # We can't use tmp for multi-server environments so we load the temp file to AWS S3.
72
70
  def store_return_url(return_url)
73
- Rails.logger.warn ":::::: storing return_url #{return_url}"
71
+ Rails.logger.warn "[DefraRubyMocks] [store_return_url] #{return_url}"
74
72
  AwsBucketService.write(s3_bucket_name, return_url_file_name, return_url)
75
73
  end
76
74
 
77
75
  def retrieve_return_url
78
- AwsBucketService.read(s3_bucket_name, return_url_file_name)
76
+ @retrieve_return_url ||= AwsBucketService.read(s3_bucket_name, return_url_file_name)
79
77
  end
80
78
 
81
79
  def valid_create_params
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DefraRubyMocks
4
+ class GovpayTestHelpersController < ::DefraRubyMocks::ApplicationController
5
+
6
+ skip_before_action :verify_authenticity_token
7
+
8
+ include CanUseAwsS3
9
+
10
+ # These are helpers for the automated acceptance tests.
11
+
12
+ # The mock will use the value passed in to populate the status field on all future payments.
13
+ def set_test_payment_response_status
14
+ set_response_status(response_status_filename: "test_payment_response_status", status: params[:status])
15
+
16
+ head 200
17
+ end
18
+
19
+ # The mock will use the value passed in to populate the status field on all future refunds.
20
+ def set_test_refund_response_status
21
+ set_response_status(response_status_filename: "test_refund_response_status", status: params[:status])
22
+
23
+ head 200
24
+ end
25
+
26
+ # This schedules a job to send a mock payment webhook.
27
+ def send_payment_webhook
28
+ Rails.logger.warn "[DefraRubyMocks] [send_payment_webhook] " \
29
+ "params: #{params[:govpay_id]}, status #{params[:payment_status]}"
30
+
31
+ %w[govpay_id payment_status callback_url signing_secret].each do |p|
32
+ raise StandardError, "Missing parameter: '#{p}'" unless params[p].present?
33
+ end
34
+
35
+ SendPaymentWebhookJob.perform_later(
36
+ govpay_id: params[:govpay_id],
37
+ status: params[:payment_status],
38
+ callback_url: params[:callback_url],
39
+ signing_secret: params[:signing_secret]
40
+ )
41
+
42
+ head 200
43
+ end
44
+
45
+ # This schedules a job to send a mock refund webhook.
46
+ def send_refund_webhook
47
+ Rails.logger.warn "[DefraRubyMocks] [send_refund webhook] " \
48
+ "params: #{params[:govpay_id]}, status #{params[:refund_status]}"
49
+
50
+ %w[govpay_id refund_status callback_url signing_secret].each do |p|
51
+ raise StandardError, "Missing parameter: '#{p}'" unless params[p].present?
52
+ end
53
+
54
+ SendRefundWebhookJob.perform_later(
55
+ govpay_id: params[:govpay_id],
56
+ status: params[:refund_status],
57
+ callback_url: params[:callback_url],
58
+ signing_secret: params[:signing_secret]
59
+ )
60
+
61
+ head 200
62
+ end
63
+
64
+ private
65
+
66
+ def s3_bucket_name
67
+ @s3_bucket_name = ENV.fetch("AWS_DEFRA_RUBY_MOCKS_BUCKET", nil)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationJob < ActiveJob::Base
4
+ queue_as :default
5
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ class BaseSendWebhookJob < ApplicationJob
4
+ def perform(govpay_id:, status:, callback_url:, signing_secret:)
5
+ body = webhook_body(govpay_id:, status:)
6
+ Rails.logger.warn "[DefraRubyMocks] [BaseSendWebhookJob] sending #{webhook_type} webhook " \
7
+ "for #{govpay_id}, status \"#{status}\" to #{callback_url}"
8
+ RestClient::Request.execute(
9
+ method: :get,
10
+ url: callback_url,
11
+ body: body,
12
+ headers: { "Pay-Signature": webhook_signature(body, signing_secret) }
13
+ )
14
+ rescue StandardError => e
15
+ Rails.logger.error "[DefraRubyMocks] [BaseSendWebhookJob] error sending " \
16
+ "#{webhook_type} webhook to #{callback_url}: #{e}"
17
+ end
18
+
19
+ private
20
+
21
+ def webhook_type
22
+ raise NotImplementedError
23
+ end
24
+
25
+ def webhook_body(govpay_id:, status:)
26
+ raise NotImplementedError
27
+ end
28
+
29
+ def webhook_signature(webhook_body, signing_secret)
30
+ OpenSSL::HMAC.hexdigest("sha256", signing_secret.encode("utf-8"), webhook_body.to_json.encode("utf-8"))
31
+ end
32
+
33
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SendPaymentWebhookJob < BaseSendWebhookJob
4
+
5
+ private
6
+
7
+ def webhook_type
8
+ "payment"
9
+ end
10
+
11
+ def webhook_body(govpay_id:, status:)
12
+ webhook_body ||= JSON.parse(File.read("lib/fixtures/files/govpay/webhook_payment_update_body.json"))
13
+
14
+ webhook_body["resource"]["payment_id"] = govpay_id
15
+ webhook_body["resource"]["state"]["status"] = status
16
+
17
+ webhook_body
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SendRefundWebhookJob < BaseSendWebhookJob
4
+
5
+ private
6
+
7
+ def webhook_type
8
+ "refund"
9
+ end
10
+
11
+ def webhook_body(govpay_id:, status:)
12
+ webhook_body ||= JSON.parse(File.read("lib/fixtures/files/govpay/webhook_refund_update_body.json"))
13
+
14
+ webhook_body["payment_id"] = govpay_id
15
+ webhook_body["status"] = status
16
+
17
+ webhook_body
18
+ end
19
+ end
@@ -16,10 +16,15 @@ module DefraRubyMocks
16
16
  new.read(bucket_name, file_name)
17
17
  end
18
18
 
19
+ def self.remove(bucket_name, file_name)
20
+ Rails.logger.debug "[DefraRubyMocks] [AwsBucketService] removing #{file_name} on S3"
21
+ new.remove(bucket_name, file_name)
22
+ end
23
+
19
24
  def write(bucket_name, file_name, content)
20
25
  @bucket_name = bucket_name
21
26
  @file_name = file_name
22
- Rails.logger.debug ":::::: mocks writing to S3"
27
+ Rails.logger.debug "[DefraRubyMocks] [AwsBucketService] writing #{file_name} to S3"
23
28
 
24
29
  write_temp_file(content)
25
30
 
@@ -31,31 +36,41 @@ module DefraRubyMocks
31
36
  def read(bucket_name, file_name)
32
37
  @bucket_name = bucket_name
33
38
  @file_name = file_name
34
- Rails.logger.debug ":::::: mocks reading from S3"
39
+ Rails.logger.debug "[DefraRubyMocks] [AwsBucketService] reading #{file_name} from S3"
40
+
41
+ s3.get_object(bucket: bucket_name, key: file_name).body.read
42
+ end
43
+
44
+ def remove(bucket_name, file_name)
45
+ @bucket_name = bucket_name
46
+ Rails.logger.debug "[DefraRubyMocks] [AwsBucketService] removing #{file_name} from S3"
35
47
 
36
- s3 = Aws::S3::Client.new(
48
+ bucket.delete(file_name)
49
+ end
50
+
51
+ private
52
+
53
+ def s3
54
+ @s3 ||= Aws::S3::Client.new(
37
55
  region: ENV.fetch("AWS_REGION", nil),
38
56
  credentials: Aws::Credentials.new(
39
57
  ENV.fetch("AWS_DEFRA_RUBY_MOCKS_ACCESS_KEY_ID", nil),
40
58
  ENV.fetch("AWS_DEFRA_RUBY_MOCKS_SECRET_ACCESS_KEY", nil)
41
59
  )
42
60
  )
43
- s3.get_object(bucket: bucket_name, key: file_name).body.read
44
61
  end
45
62
 
46
- private
47
-
48
63
  def temp_filepath
49
64
  "#{Dir.tmpdir}/#{file_name}"
50
65
  end
51
66
 
52
67
  def write_temp_file(content)
53
- Rails.logger.debug ":::::: mocks creating temp file for #{content}"
68
+ Rails.logger.debug "[DefraRubyMocks] [AwsBucketService] creating temp file for \"#{content}\""
54
69
  File.write(temp_filepath, content)
55
70
  end
56
71
 
57
72
  def load_temp_file_to_s3
58
- Rails.logger.debug ":::::: mocks loading temp file to S3 bucket #{bucket_name}"
73
+ Rails.logger.debug "[DefraRubyMocks] [AwsBucketService] loading temp file to S3 bucket #{bucket_name}"
59
74
 
60
75
  result = nil
61
76
 
@@ -5,6 +5,8 @@ require "securerandom"
5
5
  module DefraRubyMocks
6
6
  class GovpayCreatePaymentService < BaseService
7
7
 
8
+ include CanUseAwsS3
9
+
8
10
  def run(amount:, description:)
9
11
  success_response.merge(
10
12
  {
@@ -21,6 +23,10 @@ module DefraRubyMocks
21
23
 
22
24
  private
23
25
 
26
+ def test_payment_response_status
27
+ response_status(response_status_filename: "test_payment_response_status", default_status: "created")
28
+ end
29
+
24
30
  def base_url
25
31
  File.join(DefraRubyMocks.configuration.govpay_domain, "/payments")
26
32
  end
@@ -34,7 +40,7 @@ module DefraRubyMocks
34
40
  {
35
41
  created_date: "2020-03-03T16:17:19.554Z",
36
42
  state: {
37
- status: "created",
43
+ status: test_payment_response_status,
38
44
  finished: false
39
45
  },
40
46
  _links: {
@@ -5,6 +5,8 @@ require "securerandom"
5
5
  module DefraRubyMocks
6
6
  class GovpayGetPaymentService < BaseService
7
7
 
8
+ include CanUseAwsS3
9
+
8
10
  def run(payment_id:, amount: Random.rand(100..1_000), created_at: Time.current)
9
11
  # This currently supports only success results:
10
12
  response_success.merge(
@@ -19,6 +21,10 @@ module DefraRubyMocks
19
21
 
20
22
  private
21
23
 
24
+ def test_payment_response_status
25
+ response_status(response_status_filename: "test_payment_response_status", default_status: "success")
26
+ end
27
+
22
28
  # rubocop:disable Metrics/MethodLength
23
29
  def response_success
24
30
  {
@@ -32,7 +38,7 @@ module DefraRubyMocks
32
38
  },
33
39
  email: "sherlock.holmes@example.com",
34
40
  state: {
35
- status: "success",
41
+ status: test_payment_response_status,
36
42
  finished: true
37
43
  },
38
44
  payment_id: "cnnffa1e6s3u9a6n24u2cp527d",
@@ -3,7 +3,7 @@
3
3
  module DefraRubyMocks
4
4
  class GovpayRefundDetailsService < BaseService
5
5
 
6
- DEFAULT_LAST_REFUND_REQUEST_TIME = 1.day.ago.freeze
6
+ include CanUseAwsS3
7
7
 
8
8
  def run(payment_id:, refund_id:) # rubocop:disable Lint/UnusedMethodArgument
9
9
  {
@@ -19,40 +19,28 @@ module DefraRubyMocks
19
19
 
20
20
  private
21
21
 
22
- # "submitted" for up to GOVPAY_REFUND_SUBMITTED_SUCCESS_LAG seconds after the last refund request, then "success"
22
+ # Check if a non-default status value has been requested
23
+ def test_refund_response_status
24
+ response_status(response_status_filename: "test_refund_response_status", default_status: "submitted")
25
+ end
26
+
27
+ # "submitted" (or other, if default override is in place) for up to GOVPAY_REFUND_SUBMITTED_SUCCESS_LAG
28
+ # seconds after the last refund request, then "success"
23
29
  def status
24
- last_refund_time = refund_request_timestamp
30
+ last_refund_time = refund_request_timestamp(timestamp_file_name:)
25
31
  submitted_success_lag = ENV.fetch("GOVPAY_REFUND_SUBMITTED_SUCCESS_LAG", 0).to_i
26
32
  cutoff_time = (last_refund_time + submitted_success_lag.seconds).to_time
27
33
  return "success" if submitted_success_lag.zero?
28
34
 
29
- Time.zone.now < cutoff_time ? "submitted" : "success"
35
+ Time.zone.now < cutoff_time ? test_refund_response_status : "success"
30
36
  rescue Errno::ENOENT
31
- write_timestamp_file
37
+ write_refund_requested_timestamp(timestamp_file_name:)
32
38
 
33
39
  "success"
34
40
  end
35
41
 
36
- def write_timestamp_file
37
- timestamp = Time.zone.now
38
- Rails.logger.warn ":::::: writing timestamp file: #{timestamp}"
39
- AwsBucketService.write(s3_bucket_name, timestamp_file_name, timestamp)
40
- end
41
-
42
- def s3_bucket_name
43
- @s3_bucket_name = ENV.fetch("AWS_DEFRA_RUBY_MOCKS_BUCKET", nil)
44
- end
45
-
46
42
  def timestamp_file_name
47
43
  @govpay_request_refund_service_last_run_time = "govpay_request_refund_service_last_run_time"
48
44
  end
49
-
50
- def refund_request_timestamp
51
- timestamp = AwsBucketService.read(s3_bucket_name, timestamp_file_name)
52
- timestamp ? Time.parse(timestamp) : DEFAULT_LAST_REFUND_REQUEST_TIME
53
- rescue StandardError
54
- DEFAULT_LAST_REFUND_REQUEST_TIME
55
- end
56
-
57
45
  end
58
46
  end
@@ -3,28 +3,23 @@
3
3
  module DefraRubyMocks
4
4
  class GovpayRequestRefundService < BaseService
5
5
 
6
+ include CanUseAwsS3
7
+
6
8
  def run(payment_id:, amount:, refund_amount_available:) # rubocop:disable Lint/UnusedMethodArgument
7
- write_timestamp
9
+ write_refund_requested_timestamp(timestamp_file_name:)
8
10
 
9
- # This currently supports only "submitted" status:
10
11
  {
11
12
  amount: amount,
12
13
  created_date: "2019-09-19T16:53:03.213Z",
13
14
  refund_id: SecureRandom.hex(22),
14
- status: "submitted"
15
+ status: test_refund_response_status
15
16
  }
16
17
  end
17
18
 
18
19
  private
19
20
 
20
- # let the refund details service know how long since the refund was requested
21
- def write_timestamp
22
- Rails.logger.warn ":::::: storing refund request timestamp"
23
- AwsBucketService.write(s3_bucket_name, timestamp_file_name, Time.zone.now.to_s)
24
- end
25
-
26
- def s3_bucket_name
27
- @s3_bucket_name = ENV.fetch("AWS_DEFRA_RUBY_MOCKS_BUCKET", nil)
21
+ def test_refund_response_status
22
+ response_status(response_status_filename: "test_refund_response_status", default_status: "submitted")
28
23
  end
29
24
 
30
25
  def timestamp_file_name
data/config/routes.rb CHANGED
@@ -35,4 +35,25 @@ DefraRubyMocks::Engine.routes.draw do # rubocop:disable Metrics/BlockLength
35
35
  to: "govpay#refund_details",
36
36
  as: "govpay_refund_details",
37
37
  constraints: ->(_request) { DefraRubyMocks.configuration.enabled? }
38
+
39
+ # test helpers, not mocks:
40
+ get "/govpay/v1/payments/set_test_payment_response_status/:status",
41
+ to: "govpay_test_helpers#set_test_payment_response_status",
42
+ as: "govpay_set_test_payment_response_status",
43
+ constraints: ->(_request) { DefraRubyMocks.configuration.enabled? }
44
+
45
+ get "/govpay/v1/payments/set_test_refund_response_status/:status",
46
+ to: "govpay_test_helpers#set_test_refund_response_status",
47
+ as: "govpay_set_test_refund_response_status",
48
+ constraints: ->(_request) { DefraRubyMocks.configuration.enabled? }
49
+
50
+ post "/govpay/v1/payments/:govpay_id/send_payment_webhook",
51
+ to: "govpay_test_helpers#send_payment_webhook",
52
+ as: "send_payment_webhook",
53
+ constraints: ->(_request) { DefraRubyMocks.configuration.enabled? }
54
+
55
+ post "/govpay/v1/payments/:govpay_id/send_refund_webhook",
56
+ to: "govpay_test_helpers#send_refund_webhook",
57
+ as: "send_refund_webhook",
58
+ constraints: ->(_request) { DefraRubyMocks.configuration.enabled? }
38
59
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DefraRubyMocks
4
- VERSION = "5.0.0"
4
+ VERSION = "5.1.1"
5
5
  end
@@ -0,0 +1,48 @@
1
+ {
2
+ "webhook_message_id": "123abc",
3
+ "api_version": 1,
4
+ "created_date": "2019-07-11T10:36:26.988Z",
5
+ "resource_id": "hu20sqlact5260q2nanm0q8u93",
6
+ "resource_type": "payment",
7
+ "event_type": "card_payment_captured",
8
+ "resource": {
9
+ "amount": 5000,
10
+ "description": "Pay your council tax",
11
+ "reference": "12345",
12
+ "language": "en",
13
+ "email": "sherlock.holmes@example.com",
14
+ "state": {
15
+ "status": "success",
16
+ "finished": false
17
+ },
18
+ "payment_id": "hu20sqlact5260q2nanm0q8u93",
19
+ "payment_provider": "stripe",
20
+ "created_date": "2021-10-19T10:05:45.454Z",
21
+ "refund_summary": {
22
+ "status": "pending",
23
+ "amount_available": 5000,
24
+ "amount_submitted": 0
25
+ },
26
+ "settlement_summary": {},
27
+ "card_details": {
28
+ "last_digits_card_number": "1234",
29
+ "first_digits_card_number": "123456",
30
+ "cardholder_name": "Sherlock Holmes",
31
+ "expiry_date": "04/24",
32
+ "billing_address": {
33
+ "line1": "221 Baker Street",
34
+ "line2": "Flat b",
35
+ "postcode": "NW1 6XE",
36
+ "city": "London",
37
+ "country": "GB"
38
+ },
39
+ "card_brand": "Visa",
40
+ "card_type": "debit"
41
+ },
42
+ "delayed_capture": false,
43
+ "moto": false,
44
+ "provider_id": "10987654321",
45
+ "return_url": "https://your.service.gov.uk/completed"
46
+ }
47
+ }
48
+
@@ -0,0 +1,8 @@
1
+ {
2
+ "refund_id": "345",
3
+ "created_date": "2022-01-26T16:52:41.178Z",
4
+ "amount": 2000,
5
+ "status": "success",
6
+ "settlement_summary": {},
7
+ "payment_id": "789"
8
+ }
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: 5.0.0
4
+ version: 5.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Defra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-26 00:00:00.000000000 Z
11
+ date: 2025-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rest-client
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
69
83
  description: A Rails engine which can be used to mock external services when loaded
70
84
  into an application
71
85
  email:
@@ -77,9 +91,15 @@ files:
77
91
  - LICENSE
78
92
  - README.md
79
93
  - Rakefile
94
+ - app/controllers/concerns/defra_ruby_mocks/can_use_aws_s3.rb
80
95
  - app/controllers/defra_ruby_mocks/application_controller.rb
81
96
  - app/controllers/defra_ruby_mocks/company_controller.rb
82
97
  - app/controllers/defra_ruby_mocks/govpay_controller.rb
98
+ - app/controllers/defra_ruby_mocks/govpay_test_helpers_controller.rb
99
+ - app/jobs/application_job.rb
100
+ - app/jobs/base_send_webhook_job.rb
101
+ - app/jobs/send_payment_webhook_job.rb
102
+ - app/jobs/send_refund_webhook_job.rb
83
103
  - app/services/defra_ruby_mocks/aws_bucket_service.rb
84
104
  - app/services/defra_ruby_mocks/base_service.rb
85
105
  - app/services/defra_ruby_mocks/companies_house_service.rb
@@ -97,6 +117,8 @@ files:
97
117
  - lib/defra_ruby_mocks/invalid_config_error.rb
98
118
  - lib/defra_ruby_mocks/missing_resource_error.rb
99
119
  - lib/defra_ruby_mocks/version.rb
120
+ - lib/fixtures/files/govpay/webhook_payment_update_body.json
121
+ - lib/fixtures/files/govpay/webhook_refund_update_body.json
100
122
  - lib/tasks/changelog.rake
101
123
  - lib/tasks/defra_ruby_mocks_tasks.rake
102
124
  homepage: https://github.com/DEFRA/defra-ruby-mocks