defra_ruby_mocks 2.2.0 → 2.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -1
- data/app/controllers/defra_ruby_mocks/govpay_controller.rb +38 -0
- data/app/controllers/defra_ruby_mocks/worldpay_controller.rb +1 -0
- data/app/services/defra_ruby_mocks/govpay_create_payment_service.rb +34 -0
- data/app/services/defra_ruby_mocks/govpay_get_payment_service.rb +32 -0
- data/app/services/defra_ruby_mocks/worldpay_resource_service.rb +2 -2
- data/app/services/defra_ruby_mocks/worldpay_response_service.rb +2 -0
- data/config/routes.rb +13 -4
- data/lib/defra_ruby_mocks/configuration.rb +1 -2
- data/lib/defra_ruby_mocks/version.rb +1 -1
- data/spec/dummy/log/test.log +1088 -2101
- data/spec/examples.txt +116 -109
- data/spec/requests/govpay_spec.rb +107 -0
- data/spec/requests/worldpay_spec.rb +3 -3
- data/spec/services/worldpay_resource_service_spec.rb +8 -0
- data/spec/services/worldpay_response_service_spec.rb +9 -2
- metadata +11 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72e4545b335d8982579d4e72ec7319ad6d2a18dff08f931576dbace757736e30
|
4
|
+
data.tar.gz: 4b8a88a381bd24fd027214c2b86016d4b532d74dce07284050e2a48f3dfe726d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5043858781580f1d769aecbe6c0e185311421811c4dad12154e50b83e58f69efde797a854d190384219b8a2d8fb2b73da66ddabecc2064a52c51140022e01b85
|
7
|
+
data.tar.gz: 45699483045aba318c7421ff48dbea130aaba08f3b92204fc9b2c16e1a63e89838c1429aaae4f72c32e8a32a7bf4757463b721469c4125d7e50e6413cf56f023
|
data/README.md
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
![Build Status](https://github.com/DEFRA/defra-ruby-mocks/workflows/CI/badge.svg?branch=main)
|
4
4
|
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=DEFRA_defra-ruby-mocks&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=DEFRA_defra-ruby-mocks)
|
5
5
|
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=DEFRA_defra-ruby-mocks&metric=coverage)](https://sonarcloud.io/dashboard?id=DEFRA_defra-ruby-mocks)
|
6
|
-
[![security](https://hakiri.io/github/DEFRA/defra-ruby-mocks/main.svg)](https://hakiri.io/github/DEFRA/defra-ruby-mocks/main)
|
7
6
|
[![Licence](https://img.shields.io/badge/Licence-OGLv3-blue.svg)](http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3)
|
8
7
|
|
9
8
|
A Rails Engine used by the [Ruby services team](https://github.com/DEFRA/ruby-services-team) in their digital services.
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DefraRubyMocks
|
4
|
+
class GovpayController < ::DefraRubyMocks::ApplicationController
|
5
|
+
|
6
|
+
protect_from_forgery with: :exception, except: [:create_payemnt]
|
7
|
+
|
8
|
+
def create_payment
|
9
|
+
valid_create_params
|
10
|
+
render json: GovpayCreatePaymentService.new.run(
|
11
|
+
amount: params[:amount], description: params[:description], return_url: params[:return_url]
|
12
|
+
)
|
13
|
+
rescue StandardError => e
|
14
|
+
Rails.logger.error("MOCKS: Govpay payment creation error: #{e.message}")
|
15
|
+
Rails.logger.error e.backtrace
|
16
|
+
head 500
|
17
|
+
end
|
18
|
+
|
19
|
+
def payment_details
|
20
|
+
valid_payment_id
|
21
|
+
render json: GovpayGetPaymentService.new.run(payment_id: params[:payment_id])
|
22
|
+
rescue StandardError => e
|
23
|
+
Rails.logger.error("MOCKS: Govpay payment details error: #{e.message}")
|
24
|
+
Rails.logger.error e.backtrace
|
25
|
+
head 422
|
26
|
+
end
|
27
|
+
|
28
|
+
def valid_create_params
|
29
|
+
params.require(%i[amount description return_url])
|
30
|
+
end
|
31
|
+
|
32
|
+
def valid_payment_id
|
33
|
+
return true if params[:payment_id].length > 20 && params[:payment_id].match(/\A[a-zA-Z0-9]*\z/)
|
34
|
+
|
35
|
+
raise ArgumentError, "Invalid Govpay payment ID #{params[:payment_id]}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "securerandom"
|
4
|
+
|
5
|
+
module DefraRubyMocks
|
6
|
+
class GovpayCreatePaymentService < BaseService
|
7
|
+
|
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
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def base_url
|
27
|
+
File.join(DefraRubyMocks.configuration.govpay_domain, "/payments")
|
28
|
+
end
|
29
|
+
|
30
|
+
def payment_id
|
31
|
+
@payment_id ||= SecureRandom.alphanumeric(26)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "securerandom"
|
4
|
+
|
5
|
+
module DefraRubyMocks
|
6
|
+
class GovpayGetPaymentService < BaseService
|
7
|
+
|
8
|
+
def run(payment_id:, amount: Random.rand(100..1_000), created_at: Time.current)
|
9
|
+
{
|
10
|
+
created_date: created_at,
|
11
|
+
amount: amount,
|
12
|
+
state: {
|
13
|
+
status: "success",
|
14
|
+
finished: true
|
15
|
+
},
|
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
|
24
|
+
},
|
25
|
+
total_amount: amount,
|
26
|
+
payment_provider: "worldpay",
|
27
|
+
provider_id: "10987654321"
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -46,9 +46,9 @@ module DefraRubyMocks
|
|
46
46
|
|
47
47
|
def company_name
|
48
48
|
if resource.class.to_s == "WasteCarriersEngine::OrderCopyCardsRegistration"
|
49
|
-
locate_original_registration(resource.reg_identifier).company_name
|
49
|
+
locate_original_registration(resource.reg_identifier).company_name&.downcase
|
50
50
|
else
|
51
|
-
resource.company_name
|
51
|
+
resource.company_name&.downcase
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -65,6 +65,8 @@ module DefraRubyMocks
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def payment_status
|
68
|
+
return :AUTHORISED unless @resource.company_name
|
69
|
+
|
68
70
|
return :REFUSED if @resource.company_name.include?("reject")
|
69
71
|
return :STUCK if @resource.company_name.include?("stuck")
|
70
72
|
return :SENT_FOR_AUTHORISATION if @resource.company_name.include?("pending")
|
data/config/routes.rb
CHANGED
@@ -11,14 +11,23 @@ DefraRubyMocks::Engine.routes.draw do
|
|
11
11
|
as: "company_officers",
|
12
12
|
constraints: ->(_request) { DefraRubyMocks.configuration.enabled? }
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
post "/worldpay/payments-service",
|
15
|
+
to: "worldpay#payments_service",
|
16
|
+
as: "worldpay_payments_service",
|
17
|
+
constraints: ->(_request) { DefraRubyMocks.configuration.enabled? }
|
18
18
|
|
19
19
|
get "/worldpay/dispatcher",
|
20
20
|
to: "worldpay#dispatcher",
|
21
21
|
as: "worldpay_dispatcher",
|
22
22
|
constraints: ->(_request) { DefraRubyMocks.configuration.enabled? }
|
23
23
|
|
24
|
+
post "/govpay/v1/payments",
|
25
|
+
to: "govpay#create_payment",
|
26
|
+
as: "govpay_create_payment",
|
27
|
+
constraints: ->(_request) { DefraRubyMocks.configuration.enabled? }
|
28
|
+
|
29
|
+
get "/govpay/v1/payments/:payment_id",
|
30
|
+
to: "govpay#payment_details",
|
31
|
+
as: "govpay_payment_details",
|
32
|
+
constraints: ->(_request) { DefraRubyMocks.configuration.enabled? }
|
24
33
|
end
|
@@ -5,8 +5,7 @@ module DefraRubyMocks
|
|
5
5
|
|
6
6
|
DEFAULT_DELAY = 1000
|
7
7
|
|
8
|
-
attr_accessor :worldpay_admin_code, :worldpay_mac_secret
|
9
|
-
attr_accessor :worldpay_merchant_code, :worldpay_domain
|
8
|
+
attr_accessor :worldpay_admin_code, :worldpay_mac_secret, :worldpay_merchant_code, :worldpay_domain, :govpay_domain
|
10
9
|
attr_reader :delay
|
11
10
|
|
12
11
|
def initialize
|