defra_ruby_govpay 0.2.6 → 0.2.8

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: 0c82aff9dd09e95432ad62c5aedb6b4a2d8d4e9e42d9f17bac37ac7cbebbc90f
4
- data.tar.gz: e859b6ca00740c0112aa80c117b3584dc2ae64f3be8aceb5fdc8cc055a2bdf59
3
+ metadata.gz: 98b1ac9bdd7fbc9c353f4f93f324ed988b2d17d3d744b4cc0c95e690b14cd343
4
+ data.tar.gz: 402ac1f3644735c4d69806e90c97959873377248b96602a3ff306ca83b3e83c2
5
5
  SHA512:
6
- metadata.gz: 62772d1e4dd940a2faa216a9c53d9e1c3fbbe1a36e04bfc7faa9af5969550c2a9ad1c5b3e8ca75d47052b3689a76618cd653d78d357f3d8c4c2409f17fbc3e3d
7
- data.tar.gz: 1134a7ff08a8445cca67f50330f022a75e4e51fa08b13c0ef4e1c499659f9c88acf93397c1a1e5b963db4e953c8fd16f65456819a2c50257dc1ce260d5d30ad9
6
+ metadata.gz: 64d5e81ca4208af458dfe56469f6d4f05845b8450c0bd11a0a89a7c73b4ac515d4184bec4c3cc08aa00e1a972d279631f430c90bc0f95d7314bccd90acb7fd45
7
+ data.tar.gz: 4531af74e4161427717899628554a3418bf83ffe331b6f8c625de018d76ab366899923c8af27d9316ff5874a8437efe56201832981d719f91a3c40a83f0f38d7
data/CHANGELOG.md CHANGED
@@ -1,12 +1,48 @@
1
1
  # Changelog
2
2
 
3
- ## [Unreleased](https://github.com/DEFRA/defra-ruby-govpay/tree/HEAD)
3
+ ## [v0.2.8](https://github.com/DEFRA/defra-ruby-govpay/tree/v0.2.8) (2025-04-29)
4
4
 
5
- [Full Changelog](https://github.com/DEFRA/defra-ruby-govpay/compare/v0.2.4...HEAD)
5
+ [Full Changelog](https://github.com/DEFRA/defra-ruby-govpay/compare/v0.2.7...v0.2.8)
6
+
7
+ **Implemented enhancements:**
8
+
9
+ - RUBY 3757 wcr tech move govpay webhook handling to the govpay gem [\#32](https://github.com/DEFRA/defra-ruby-govpay/pull/32) ([jjromeo](https://github.com/jjromeo))
10
+
11
+ ## [v0.2.7](https://github.com/DEFRA/defra-ruby-govpay/tree/v0.2.7) (2025-04-28)
12
+
13
+ [Full Changelog](https://github.com/DEFRA/defra-ruby-govpay/compare/v0.2.6...v0.2.7)
14
+
15
+ **Implemented enhancements:**
16
+
17
+ - \[RUBY-3757\] Add signature service to defra ruby govpay [\#30](https://github.com/DEFRA/defra-ruby-govpay/pull/30) ([jjromeo](https://github.com/jjromeo))
18
+
19
+ **Merged pull requests:**
20
+
21
+ - Bump version to 0.2.7 [\#31](https://github.com/DEFRA/defra-ruby-govpay/pull/31) ([jjromeo](https://github.com/jjromeo))
22
+
23
+ ## [v0.2.6](https://github.com/DEFRA/defra-ruby-govpay/tree/v0.2.6) (2025-04-23)
24
+
25
+ [Full Changelog](https://github.com/DEFRA/defra-ruby-govpay/compare/v0.2.5...v0.2.6)
26
+
27
+ **Implemented enhancements:**
28
+
29
+ - RUBY 3757 wcr tech move govpay webhook handling to the govpay gem [\#28](https://github.com/DEFRA/defra-ruby-govpay/pull/28) ([jjromeo](https://github.com/jjromeo))
30
+
31
+ **Merged pull requests:**
32
+
33
+ - Bump version to 0.2.6 for release \(on main\) [\#29](https://github.com/DEFRA/defra-ruby-govpay/pull/29) ([jjromeo](https://github.com/jjromeo))
34
+
35
+ ## [v0.2.5](https://github.com/DEFRA/defra-ruby-govpay/tree/v0.2.5) (2023-11-16)
36
+
37
+ [Full Changelog](https://github.com/DEFRA/defra-ruby-govpay/compare/v0.2.4...v0.2.5)
6
38
 
7
39
  **Fixed bugs:**
8
40
 
9
- - fix host\_is\_back\_office [\#11](https://github.com/DEFRA/defra-ruby-govpay/pull/11) ([PaulDoyle-DEFRA](https://github.com/PaulDoyle-DEFRA))
41
+ - fix host\_is\_back\_office [\#11](https://github.com/DEFRA/defra-ruby-govpay/pull/11) ([PaulDoyle-EA](https://github.com/PaulDoyle-EA))
42
+
43
+ **Merged pull requests:**
44
+
45
+ - Version 0.2.5 [\#12](https://github.com/DEFRA/defra-ruby-govpay/pull/12) ([PaulDoyle-EA](https://github.com/PaulDoyle-EA))
10
46
 
11
47
  ## [v0.2.4](https://github.com/DEFRA/defra-ruby-govpay/tree/v0.2.4) (2023-11-10)
12
48
 
@@ -14,11 +50,11 @@
14
50
 
15
51
  **Fixed bugs:**
16
52
 
17
- - fix DefraRubyGovpay config [\#9](https://github.com/DEFRA/defra-ruby-govpay/pull/9) ([PaulDoyle-DEFRA](https://github.com/PaulDoyle-DEFRA))
53
+ - fix DefraRubyGovpay config [\#9](https://github.com/DEFRA/defra-ruby-govpay/pull/9) ([PaulDoyle-EA](https://github.com/PaulDoyle-EA))
18
54
 
19
55
  **Merged pull requests:**
20
56
 
21
- - Version 0.2.4 [\#10](https://github.com/DEFRA/defra-ruby-govpay/pull/10) ([PaulDoyle-DEFRA](https://github.com/PaulDoyle-DEFRA))
57
+ - Version 0.2.4 [\#10](https://github.com/DEFRA/defra-ruby-govpay/pull/10) ([PaulDoyle-EA](https://github.com/PaulDoyle-EA))
22
58
  - Bump rake from 13.0.6 to 13.1.0 [\#6](https://github.com/DEFRA/defra-ruby-govpay/pull/6) ([dependabot[bot]](https://github.com/apps/dependabot))
23
59
 
24
60
  ## [v0.2.3](https://github.com/DEFRA/defra-ruby-govpay/tree/v0.2.3) (2023-11-07)
@@ -27,7 +63,7 @@
27
63
 
28
64
  **Implemented enhancements:**
29
65
 
30
- - Chore/ruby 2769 enhance govpay logging [\#8](https://github.com/DEFRA/defra-ruby-govpay/pull/8) ([PaulDoyle-DEFRA](https://github.com/PaulDoyle-DEFRA))
66
+ - Chore/ruby 2769 enhance govpay logging [\#8](https://github.com/DEFRA/defra-ruby-govpay/pull/8) ([PaulDoyle-EA](https://github.com/PaulDoyle-EA))
31
67
 
32
68
  ## [v0.2.2](https://github.com/DEFRA/defra-ruby-govpay/tree/v0.2.2) (2023-11-06)
33
69
 
@@ -35,8 +71,8 @@
35
71
 
36
72
  **Implemented enhancements:**
37
73
 
38
- - gem version 0.2.2 [\#7](https://github.com/DEFRA/defra-ruby-govpay/pull/7) ([PaulDoyle-DEFRA](https://github.com/PaulDoyle-DEFRA))
39
- - Chore/ruby 2769 enhance govpay logging [\#5](https://github.com/DEFRA/defra-ruby-govpay/pull/5) ([PaulDoyle-DEFRA](https://github.com/PaulDoyle-DEFRA))
74
+ - gem version 0.2.2 [\#7](https://github.com/DEFRA/defra-ruby-govpay/pull/7) ([PaulDoyle-EA](https://github.com/PaulDoyle-EA))
75
+ - Chore/ruby 2769 enhance govpay logging [\#5](https://github.com/DEFRA/defra-ruby-govpay/pull/5) ([PaulDoyle-EA](https://github.com/PaulDoyle-EA))
40
76
 
41
77
  ## [v0.2.1](https://github.com/DEFRA/defra-ruby-govpay/tree/v0.2.1) (2023-10-03)
42
78
 
@@ -53,11 +89,18 @@
53
89
  **Merged pull requests:**
54
90
 
55
91
  - release/v0.1.2 [\#4](https://github.com/DEFRA/defra-ruby-govpay/pull/4) ([jjromeo](https://github.com/jjromeo))
56
- - gem version 0.1.0 [\#1](https://github.com/DEFRA/defra-ruby-govpay/pull/1) ([jjromeo](https://github.com/jjromeo))
57
92
 
58
93
  ## [v0.1.1](https://github.com/DEFRA/defra-ruby-govpay/tree/v0.1.1) (2023-09-18)
59
94
 
60
- [Full Changelog](https://github.com/DEFRA/defra-ruby-govpay/compare/1bd9ccaffdb51137f980d553336b5dddf2f4901d...v0.1.1)
95
+ [Full Changelog](https://github.com/DEFRA/defra-ruby-govpay/compare/v0.1.0...v0.1.1)
96
+
97
+ ## [v0.1.0](https://github.com/DEFRA/defra-ruby-govpay/tree/v0.1.0) (2023-09-18)
98
+
99
+ [Full Changelog](https://github.com/DEFRA/defra-ruby-govpay/compare/1bd9ccaffdb51137f980d553336b5dddf2f4901d...v0.1.0)
100
+
101
+ **Merged pull requests:**
102
+
103
+ - gem version 0.1.0 [\#1](https://github.com/DEFRA/defra-ruby-govpay/pull/1) ([jjromeo](https://github.com/jjromeo))
61
104
 
62
105
 
63
106
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- defra_ruby_govpay (0.2.5)
4
+ defra_ruby_govpay (0.2.8)
5
5
  rest-client (~> 2.1)
6
6
 
7
7
  GEM
@@ -5,6 +5,7 @@ module DefraRubyGovpay
5
5
  # for the DefraRubyGovpay module. You can set different options like
6
6
  # API tokens, host preferences, and other necessary configurations here.
7
7
  class Configuration
8
- attr_accessor :govpay_url, :govpay_front_office_api_token, :govpay_back_office_api_token, :logger
8
+ attr_accessor :govpay_url, :govpay_front_office_api_token, :govpay_back_office_api_token, :logger,
9
+ :front_office_webhook_signing_secret, :back_office_webhook_signing_secret
9
10
  end
10
11
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DefraRubyGovpay
4
+ class GovpayWebhookBodyValidatorService
5
+ class ValidationFailure < StandardError; end
6
+
7
+ def self.run(body:, signature:)
8
+ raise ValidationFailure, "Missing expected signature" if signature.blank?
9
+
10
+ body_signatures = GovpayWebhookSignatureService.run(body:)
11
+ return true if body_signatures[:front_office] == signature || body_signatures[:back_office] == signature
12
+
13
+ raise ValidationFailure, "digest/signature header mismatch"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DefraRubyGovpay
4
+ class GovpayWebhookSignatureService
5
+ class DigestFailure < StandardError; end
6
+
7
+ def self.run(body:)
8
+ new.run(body: body)
9
+ end
10
+
11
+ def run(body:)
12
+ generate_signatures(body.to_s)
13
+ rescue StandardError => e
14
+ DefraRubyGovpay.logger.error "Govpay payment webhook signature generation failed: #{e}"
15
+ raise DigestFailure, e
16
+ end
17
+
18
+ private
19
+
20
+ def generate_signatures(body)
21
+ {
22
+ front_office: hmac_digest(body, front_office_secret),
23
+ back_office: hmac_digest(body, back_office_secret)
24
+ }
25
+ end
26
+
27
+ def front_office_secret
28
+ DefraRubyGovpay.configuration.front_office_webhook_signing_secret
29
+ end
30
+
31
+ def back_office_secret
32
+ DefraRubyGovpay.configuration.back_office_webhook_signing_secret
33
+ end
34
+
35
+ def hmac_digest(body, secret)
36
+ digest = OpenSSL::Digest.new("sha256")
37
+ OpenSSL::HMAC.hexdigest(digest, secret, body)
38
+ end
39
+ end
40
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DefraRubyGovpay
4
- VERSION = "0.2.6"
4
+ VERSION = "0.2.8"
5
5
  end
@@ -9,11 +9,12 @@ require_relative "defra_ruby_govpay/payment"
9
9
  require_relative "defra_ruby_govpay/refund"
10
10
  require_relative "defra_ruby_govpay/error"
11
11
  require_relative "defra_ruby_govpay/api"
12
- require_relative "defra_ruby_govpay/callback_validator"
13
12
  require_relative "defra_ruby_govpay/services/govpay_webhook_base_service"
14
13
  require_relative "defra_ruby_govpay/services/govpay_webhook_payment_service"
15
14
  require_relative "defra_ruby_govpay/services/govpay_webhook_refund_service"
16
15
  require_relative "defra_ruby_govpay/services/govpay_webhook_sanitizer_service"
16
+ require_relative "defra_ruby_govpay/services/govpay_webhook_signature_service"
17
+ require_relative "defra_ruby_govpay/services/govpay_webhook_body_validator_service"
17
18
 
18
19
  # The DefraRubyGovpay module facilitates integration with Govpay services.
19
20
  # It provides a convenient and configurable way to interact with Govpay APIs in Defra's ruby applications.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: defra_ruby_govpay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jerome Pratt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-23 00:00:00.000000000 Z
11
+ date: 2025-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -48,16 +48,17 @@ files:
48
48
  - defra_ruby_govpay.gemspec
49
49
  - lib/defra_ruby_govpay.rb
50
50
  - lib/defra_ruby_govpay/api.rb
51
- - lib/defra_ruby_govpay/callback_validator.rb
52
51
  - lib/defra_ruby_govpay/configuration.rb
53
52
  - lib/defra_ruby_govpay/error.rb
54
53
  - lib/defra_ruby_govpay/object.rb
55
54
  - lib/defra_ruby_govpay/payment.rb
56
55
  - lib/defra_ruby_govpay/refund.rb
57
56
  - lib/defra_ruby_govpay/services/govpay_webhook_base_service.rb
57
+ - lib/defra_ruby_govpay/services/govpay_webhook_body_validator_service.rb
58
58
  - lib/defra_ruby_govpay/services/govpay_webhook_payment_service.rb
59
59
  - lib/defra_ruby_govpay/services/govpay_webhook_refund_service.rb
60
60
  - lib/defra_ruby_govpay/services/govpay_webhook_sanitizer_service.rb
61
+ - lib/defra_ruby_govpay/services/govpay_webhook_signature_service.rb
61
62
  - lib/defra_ruby_govpay/version.rb
62
63
  - sig/defra_ruby_govpay.rbs
63
64
  homepage: https://github.com/DEFRA/defra-ruby-govpay
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "openssl"
4
-
5
- module DefraRubyGovpay
6
- class CallbackValidator
7
- def self.call(request_body, signing_secret, pay_signature_header)
8
- new(request_body, signing_secret, pay_signature_header).call
9
- end
10
-
11
- attr_reader :request_body, :signing_secret, :pay_signature_header
12
-
13
- def initialize(request_body, signing_secret, pay_signature_header)
14
- @request_body = request_body
15
- @signing_secret = signing_secret
16
- @pay_signature_header = pay_signature_header
17
- end
18
-
19
- def call
20
- hmac = OpenSSL::HMAC.hexdigest("sha256", signing_secret.encode("utf-8"), request_body.encode("utf-8"))
21
-
22
- hmac == pay_signature_header
23
- end
24
- end
25
- end