defra_ruby_mocks 2.3.2 → 2.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/defra_ruby_mocks/govpay_controller.rb +5 -3
  3. data/app/jobs/defra_ruby_mocks/application_job.rb +6 -0
  4. data/app/jobs/defra_ruby_mocks/govpay_payment_callback_job.rb +17 -0
  5. data/app/services/defra_ruby_mocks/govpay_create_payment_service.rb +41 -13
  6. data/app/services/defra_ruby_mocks/govpay_get_payment_service.rb +74 -16
  7. data/lib/defra_ruby_mocks/version.rb +1 -1
  8. data/spec/dummy/log/test.log +1488 -0
  9. data/spec/examples.txt +119 -110
  10. data/spec/fixtures/files/govpay/create_payment_created_response.json +24 -0
  11. data/spec/fixtures/files/govpay/create_payment_error_response.json +5 -0
  12. data/spec/fixtures/files/govpay/get_payment_response_cancelled.json +61 -0
  13. data/spec/fixtures/files/govpay/get_payment_response_created.json +73 -0
  14. data/spec/fixtures/files/govpay/get_payment_response_error.json +5 -0
  15. data/spec/fixtures/files/govpay/get_payment_response_failure.json +9 -0
  16. data/spec/fixtures/files/govpay/get_payment_response_not_found.json +4 -0
  17. data/spec/fixtures/files/govpay/get_payment_response_submitted.json +75 -0
  18. data/spec/fixtures/files/govpay/get_payment_response_success.json +62 -0
  19. data/spec/fixtures/{payment_request_invalid.xml → files/worldpay/payment_request_invalid.xml} +0 -0
  20. data/spec/fixtures/{payment_request_valid.xml → files/worldpay/payment_request_valid.xml} +0 -0
  21. data/spec/fixtures/{refund_request_invalid.xml → files/worldpay/refund_request_invalid.xml} +0 -0
  22. data/spec/fixtures/{refund_request_valid.xml → files/worldpay/refund_request_valid.xml} +0 -0
  23. data/spec/fixtures/{unrecognised_request.xml → files/worldpay/unrecognised_request.xml} +0 -0
  24. data/spec/requests/govpay_spec.rb +20 -0
  25. data/spec/requests/worldpay_spec.rb +3 -3
  26. data/spec/services/govpay_create_payment_service_spec.rb +44 -0
  27. data/spec/services/govpay_get_payment_service_spec.rb +30 -0
  28. data/spec/services/worldpay_payment_service_spec.rb +2 -2
  29. data/spec/services/worldpay_refund_service_spec.rb +2 -2
  30. data/spec/services/worldpay_request_handler_service_spec.rb +3 -3
  31. metadata +36 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72e4545b335d8982579d4e72ec7319ad6d2a18dff08f931576dbace757736e30
4
- data.tar.gz: 4b8a88a381bd24fd027214c2b86016d4b532d74dce07284050e2a48f3dfe726d
3
+ metadata.gz: 9215253284f8928c0b731ac83de618da7e328ee04a75453290956132bb72d65d
4
+ data.tar.gz: 56087ad7a0263a7d6cb70d2a6d02df385c33262735a544921fbd0f25a7a607f8
5
5
  SHA512:
6
- metadata.gz: 5043858781580f1d769aecbe6c0e185311421811c4dad12154e50b83e58f69efde797a854d190384219b8a2d8fb2b73da66ddabecc2064a52c51140022e01b85
7
- data.tar.gz: 45699483045aba318c7421ff48dbea130aaba08f3b92204fc9b2c16e1a63e89838c1429aaae4f72c32e8a32a7bf4757463b721469c4125d7e50e6413cf56f023
6
+ metadata.gz: c2fa8dee0d93abf131a79cad79b6a94c58fa6e9541051c9d39fbba645b294b35ce7246a4ebc69a4854765ac002b6e77acb98fa6cad785b0a82bb4ad4b0c4f7f4
7
+ data.tar.gz: c01f83850554a60d11341677892d92e9c13613481aa48d5967ed3fdbdd6de5f45620ceb7623294d58656e23b3a4e4decfc9ffa1431ae656757db5bc559c9197e
@@ -3,16 +3,19 @@
3
3
  module DefraRubyMocks
4
4
  class GovpayController < ::DefraRubyMocks::ApplicationController
5
5
 
6
- protect_from_forgery with: :exception, except: [:create_payemnt]
6
+ skip_before_action :verify_authenticity_token
7
7
 
8
8
  def create_payment
9
9
  valid_create_params
10
+
11
+ # Enqueue the payment callback to run after the controller responds
12
+ DefraRubyMocks::GovpayPaymentCallbackJob.perform_later(params[:return_url])
13
+
10
14
  render json: GovpayCreatePaymentService.new.run(
11
15
  amount: params[:amount], description: params[:description], return_url: params[:return_url]
12
16
  )
13
17
  rescue StandardError => e
14
18
  Rails.logger.error("MOCKS: Govpay payment creation error: #{e.message}")
15
- Rails.logger.error e.backtrace
16
19
  head 500
17
20
  end
18
21
 
@@ -21,7 +24,6 @@ module DefraRubyMocks
21
24
  render json: GovpayGetPaymentService.new.run(payment_id: params[:payment_id])
22
25
  rescue StandardError => e
23
26
  Rails.logger.error("MOCKS: Govpay payment details error: #{e.message}")
24
- Rails.logger.error e.backtrace
25
27
  head 422
26
28
  end
27
29
 
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DefraRubyMocks
4
+ class ApplicationJob < ActiveJob::Base
5
+ end
6
+ end
@@ -0,0 +1,17 @@
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)
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
@@ -6,19 +6,17 @@ module DefraRubyMocks
6
6
  class GovpayCreatePaymentService < BaseService
7
7
 
8
8
  def run(amount:, description:, return_url:)
9
- {
10
- created_date: Time.current,
11
- state: { status: "created", finished: false },
12
- _links: {
13
- self: { href: "#{base_url}/#{payment_id}", method: "GET" },
14
- next_url: { href: return_url, method: "GET" }
15
- },
16
- amount: amount.to_i,
17
- reference: "12345",
18
- description: description,
19
- payment_id: payment_id,
20
- payment_provider: "sandbox"
21
- }
9
+ success_response.merge(
10
+ {
11
+ _links: {
12
+ self: { href: "#{base_url}/#{payment_id}", method: "GET" },
13
+ next_url: { href: return_url, method: "GET" }
14
+ },
15
+ amount: amount.to_i,
16
+ description: description,
17
+ payment_id: payment_id
18
+ }
19
+ )
22
20
  end
23
21
 
24
22
  private
@@ -30,5 +28,35 @@ module DefraRubyMocks
30
28
  def payment_id
31
29
  @payment_id ||= SecureRandom.alphanumeric(26)
32
30
  end
31
+
32
+ # rubocop:disable Metrics/MethodLength
33
+ def success_response
34
+ {
35
+ "created_date": "2020-03-03T16:17:19.554Z",
36
+ "state": {
37
+ "status": "created",
38
+ "finished": false
39
+ },
40
+ "_links": {
41
+ "self": {
42
+ "href": "https://publicapi.payments.service.gov.uk/v1/payments/hu20sqlact5260q2nanm0q8u93",
43
+ "method": "GET"
44
+ },
45
+ "next_url": {
46
+ "href": "https://www.payments.service.gov.uk/secure/bb0a272c-8eaf-468d-b3xf-ae5e000d2231",
47
+ "method": "GET"
48
+ }
49
+ },
50
+ "amount": 14_500,
51
+ "reference": "12345",
52
+ "description": "Pay your council tax",
53
+ "return_url": "https://your.service.gov.uk/completed",
54
+ "payment_id": "hu20sqlact5260q2nanm0q8u93",
55
+ "payment_provider": "worldpay",
56
+ "provider_id": "10987654321"
57
+ }
58
+ end
59
+ # rubocop:enable Metrics/MethodLength
60
+
33
61
  end
34
62
  end
@@ -6,27 +6,85 @@ module DefraRubyMocks
6
6
  class GovpayGetPaymentService < BaseService
7
7
 
8
8
  def run(payment_id:, amount: Random.rand(100..1_000), created_at: Time.current)
9
+ # This currently supports only success results:
10
+ response_success.merge(
11
+ {
12
+ created_date: created_at,
13
+ amount: amount,
14
+ payment_id: payment_id,
15
+ total_amount: amount
16
+ }
17
+ )
18
+ end
19
+
20
+ private
21
+
22
+ # rubocop:disable Metrics/MethodLength
23
+ def response_success
9
24
  {
10
- created_date: created_at,
11
- amount: amount,
12
- state: {
13
- status: "success",
14
- finished: true
25
+ "amount": 10_501,
26
+ "description": "Waste carrier registration upper tier",
27
+ "reference": "12345",
28
+ "language": "en",
29
+ "metadata": {
30
+ "ledger_code": "AB100",
31
+ "an_internal_reference_number": 200
32
+ },
33
+ "email": "sherlock.holmes@example.com",
34
+ "state": {
35
+ "status": "success",
36
+ "finished": true
37
+ },
38
+ "payment_id": "cnnffa1e6s3u9a6n24u2cp527d",
39
+ "payment_provider": "sandbox",
40
+ "created_date": "2022-05-18T11:52:13.669Z",
41
+ "refund_summary": {
42
+ "status": "available",
43
+ "amount_available": 10_501,
44
+ "amount_submitted": 0
45
+ },
46
+ "settlement_summary": {
47
+ "capture_submit_time": "2022-05-18T11:52:39.172Z",
48
+ "captured_date": "2022-05-18"
15
49
  },
16
- description: "Your waste carriers registration fee",
17
- reference: "12345",
18
- language: "en",
19
- payment_id: payment_id,
20
- refund_summary: {
21
- status: "available",
22
- amount_available: amount - 100,
23
- amount_submitted: 0
50
+ "card_details": {
51
+ "last_digits_card_number": "5100",
52
+ "first_digits_card_number": "510510",
53
+ "cardholder_name": "Sherlock Holmes",
54
+ "expiry_date": "01/24",
55
+ "billing_address": {
56
+ "line1": "221 Baker Street",
57
+ "line2": "Flat b",
58
+ "postcode": "NW1 6XE",
59
+ "city": "London",
60
+ "country": "GB"
61
+ },
62
+ "card_brand": "Mastercard",
63
+ "card_type": "debit"
24
64
  },
25
- total_amount: amount,
26
- payment_provider: "worldpay",
27
- provider_id: "10987654321"
65
+ "delayed_capture": false,
66
+ "moto": false,
67
+ "provider_id": "9bb0c2c1-d0c5-4a63-8945-f4240e06f8ae",
68
+ "return_url": "https://some-wcr-env.defra.gov.uk/completed",
69
+ "authorisation_mode": "web",
70
+ "card_brand": "Mastercard",
71
+ "_links": {
72
+ "self": {
73
+ "href": "https://publicapi.payments.service.gov.uk/v1/payments/cnnffa1e6s3u9a6n24u2cp527d",
74
+ "method": "GET"
75
+ },
76
+ "events": {
77
+ "href": "https://publicapi.payments.service.gov.uk/v1/payments/cnnffa1e6s3u9a6n24u2cp527d/events",
78
+ "method": "GET"
79
+ },
80
+ "refunds": {
81
+ "href": "https://publicapi.payments.service.gov.uk/v1/payments/cnnffa1e6s3u9a6n24u2cp527d/refunds",
82
+ "method": "GET"
83
+ }
84
+ }
28
85
  }
29
86
  end
87
+ # rubocop:enable Metrics/MethodLength
30
88
 
31
89
  end
32
90
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DefraRubyMocks
4
- VERSION = "2.3.2"
4
+ VERSION = "2.3.3"
5
5
  end