defra_ruby_govpay 0.2.7 → 1.0.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/CHANGELOG.md +65 -10
- data/Gemfile.lock +1 -1
- data/README.md +4 -4
- data/lib/defra_ruby_govpay/services/{govpay_webhook_base_service.rb → webhook_base_service.rb} +5 -5
- data/lib/defra_ruby_govpay/services/webhook_body_validator_service.rb +16 -0
- data/lib/defra_ruby_govpay/services/{govpay_webhook_payment_service.rb → webhook_payment_service.rb} +1 -1
- data/lib/defra_ruby_govpay/services/{govpay_webhook_refund_service.rb → webhook_refund_service.rb} +1 -1
- data/lib/defra_ruby_govpay/services/{govpay_webhook_sanitizer_service.rb → webhook_sanitizer_service.rb} +1 -1
- data/lib/defra_ruby_govpay/services/{govpay_webhook_signature_service.rb → webhook_signature_service.rb} +2 -2
- data/lib/defra_ruby_govpay/version.rb +1 -1
- data/lib/defra_ruby_govpay.rb +6 -5
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64bcc877234037364951bacc95c04b7b1b271cdc3c00dc5fba2580d400a80119
|
4
|
+
data.tar.gz: 3337a1593262fb4fb8d4fca99ff7f08f3754dbc8062eb20af9e6dff618e9f6bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f65a4b685d433c6fc3a294e3e191f55a269c88618da2e54a3b206c9b29c90428dcb9d7bcf3fe80d7674051ed4fea5081e6ad5026730d59cf92e5a2a486720b3
|
7
|
+
data.tar.gz: 5876f1a42828f461d1e59dac18a8ea477981fbdec3830d2abb7244e83fc8fbbfe89a9acabceae56501e16386590258d416927b456d1f6d8b1149cc8010f60c58
|
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,60 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## [
|
3
|
+
## [v1.0.0](https://github.com/DEFRA/defra-ruby-govpay/tree/v1.0.0) (2025-04-30)
|
4
4
|
|
5
|
-
[Full Changelog](https://github.com/DEFRA/defra-ruby-govpay/compare/v0.2.
|
5
|
+
[Full Changelog](https://github.com/DEFRA/defra-ruby-govpay/compare/v0.2.8...v1.0.0)
|
6
|
+
|
7
|
+
**Merged pull requests:**
|
8
|
+
|
9
|
+
- \[RUBY-3757\] Refactor webhook handling services in Govpay gem [\#34](https://github.com/DEFRA/defra-ruby-govpay/pull/34) ([jjromeo](https://github.com/jjromeo))
|
10
|
+
|
11
|
+
## [v0.2.8](https://github.com/DEFRA/defra-ruby-govpay/tree/v0.2.8) (2025-04-29)
|
12
|
+
|
13
|
+
[Full Changelog](https://github.com/DEFRA/defra-ruby-govpay/compare/v0.2.7...v0.2.8)
|
14
|
+
|
15
|
+
**Implemented enhancements:**
|
16
|
+
|
17
|
+
- 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))
|
18
|
+
|
19
|
+
**Merged pull requests:**
|
20
|
+
|
21
|
+
- Bump version to 0.2.8 and update changelog [\#33](https://github.com/DEFRA/defra-ruby-govpay/pull/33) ([jjromeo](https://github.com/jjromeo))
|
22
|
+
|
23
|
+
## [v0.2.7](https://github.com/DEFRA/defra-ruby-govpay/tree/v0.2.7) (2025-04-28)
|
24
|
+
|
25
|
+
[Full Changelog](https://github.com/DEFRA/defra-ruby-govpay/compare/v0.2.6...v0.2.7)
|
26
|
+
|
27
|
+
**Implemented enhancements:**
|
28
|
+
|
29
|
+
- \[RUBY-3757\] Add signature service to defra ruby govpay [\#30](https://github.com/DEFRA/defra-ruby-govpay/pull/30) ([jjromeo](https://github.com/jjromeo))
|
30
|
+
|
31
|
+
**Merged pull requests:**
|
32
|
+
|
33
|
+
- Bump version to 0.2.7 [\#31](https://github.com/DEFRA/defra-ruby-govpay/pull/31) ([jjromeo](https://github.com/jjromeo))
|
34
|
+
|
35
|
+
## [v0.2.6](https://github.com/DEFRA/defra-ruby-govpay/tree/v0.2.6) (2025-04-23)
|
36
|
+
|
37
|
+
[Full Changelog](https://github.com/DEFRA/defra-ruby-govpay/compare/v0.2.5...v0.2.6)
|
38
|
+
|
39
|
+
**Implemented enhancements:**
|
40
|
+
|
41
|
+
- 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))
|
42
|
+
|
43
|
+
**Merged pull requests:**
|
44
|
+
|
45
|
+
- 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))
|
46
|
+
|
47
|
+
## [v0.2.5](https://github.com/DEFRA/defra-ruby-govpay/tree/v0.2.5) (2023-11-16)
|
48
|
+
|
49
|
+
[Full Changelog](https://github.com/DEFRA/defra-ruby-govpay/compare/v0.2.4...v0.2.5)
|
6
50
|
|
7
51
|
**Fixed bugs:**
|
8
52
|
|
9
|
-
- fix host\_is\_back\_office [\#11](https://github.com/DEFRA/defra-ruby-govpay/pull/11) ([PaulDoyle-
|
53
|
+
- fix host\_is\_back\_office [\#11](https://github.com/DEFRA/defra-ruby-govpay/pull/11) ([PaulDoyle-EA](https://github.com/PaulDoyle-EA))
|
54
|
+
|
55
|
+
**Merged pull requests:**
|
56
|
+
|
57
|
+
- Version 0.2.5 [\#12](https://github.com/DEFRA/defra-ruby-govpay/pull/12) ([PaulDoyle-EA](https://github.com/PaulDoyle-EA))
|
10
58
|
|
11
59
|
## [v0.2.4](https://github.com/DEFRA/defra-ruby-govpay/tree/v0.2.4) (2023-11-10)
|
12
60
|
|
@@ -14,11 +62,11 @@
|
|
14
62
|
|
15
63
|
**Fixed bugs:**
|
16
64
|
|
17
|
-
- fix DefraRubyGovpay config [\#9](https://github.com/DEFRA/defra-ruby-govpay/pull/9) ([PaulDoyle-
|
65
|
+
- fix DefraRubyGovpay config [\#9](https://github.com/DEFRA/defra-ruby-govpay/pull/9) ([PaulDoyle-EA](https://github.com/PaulDoyle-EA))
|
18
66
|
|
19
67
|
**Merged pull requests:**
|
20
68
|
|
21
|
-
- Version 0.2.4 [\#10](https://github.com/DEFRA/defra-ruby-govpay/pull/10) ([PaulDoyle-
|
69
|
+
- Version 0.2.4 [\#10](https://github.com/DEFRA/defra-ruby-govpay/pull/10) ([PaulDoyle-EA](https://github.com/PaulDoyle-EA))
|
22
70
|
- 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
71
|
|
24
72
|
## [v0.2.3](https://github.com/DEFRA/defra-ruby-govpay/tree/v0.2.3) (2023-11-07)
|
@@ -27,7 +75,7 @@
|
|
27
75
|
|
28
76
|
**Implemented enhancements:**
|
29
77
|
|
30
|
-
- Chore/ruby 2769 enhance govpay logging [\#8](https://github.com/DEFRA/defra-ruby-govpay/pull/8) ([PaulDoyle-
|
78
|
+
- Chore/ruby 2769 enhance govpay logging [\#8](https://github.com/DEFRA/defra-ruby-govpay/pull/8) ([PaulDoyle-EA](https://github.com/PaulDoyle-EA))
|
31
79
|
|
32
80
|
## [v0.2.2](https://github.com/DEFRA/defra-ruby-govpay/tree/v0.2.2) (2023-11-06)
|
33
81
|
|
@@ -35,8 +83,8 @@
|
|
35
83
|
|
36
84
|
**Implemented enhancements:**
|
37
85
|
|
38
|
-
- gem version 0.2.2 [\#7](https://github.com/DEFRA/defra-ruby-govpay/pull/7) ([PaulDoyle-
|
39
|
-
- Chore/ruby 2769 enhance govpay logging [\#5](https://github.com/DEFRA/defra-ruby-govpay/pull/5) ([PaulDoyle-
|
86
|
+
- gem version 0.2.2 [\#7](https://github.com/DEFRA/defra-ruby-govpay/pull/7) ([PaulDoyle-EA](https://github.com/PaulDoyle-EA))
|
87
|
+
- Chore/ruby 2769 enhance govpay logging [\#5](https://github.com/DEFRA/defra-ruby-govpay/pull/5) ([PaulDoyle-EA](https://github.com/PaulDoyle-EA))
|
40
88
|
|
41
89
|
## [v0.2.1](https://github.com/DEFRA/defra-ruby-govpay/tree/v0.2.1) (2023-10-03)
|
42
90
|
|
@@ -53,11 +101,18 @@
|
|
53
101
|
**Merged pull requests:**
|
54
102
|
|
55
103
|
- 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
104
|
|
58
105
|
## [v0.1.1](https://github.com/DEFRA/defra-ruby-govpay/tree/v0.1.1) (2023-09-18)
|
59
106
|
|
60
|
-
[Full Changelog](https://github.com/DEFRA/defra-ruby-govpay/compare/
|
107
|
+
[Full Changelog](https://github.com/DEFRA/defra-ruby-govpay/compare/v0.1.0...v0.1.1)
|
108
|
+
|
109
|
+
## [v0.1.0](https://github.com/DEFRA/defra-ruby-govpay/tree/v0.1.0) (2023-09-18)
|
110
|
+
|
111
|
+
[Full Changelog](https://github.com/DEFRA/defra-ruby-govpay/compare/1bd9ccaffdb51137f980d553336b5dddf2f4901d...v0.1.0)
|
112
|
+
|
113
|
+
**Merged pull requests:**
|
114
|
+
|
115
|
+
- gem version 0.1.0 [\#1](https://github.com/DEFRA/defra-ruby-govpay/pull/1) ([jjromeo](https://github.com/jjromeo))
|
61
116
|
|
62
117
|
|
63
118
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -88,11 +88,11 @@ The webhook services extract and return data from the webhook payload:
|
|
88
88
|
|
89
89
|
```ruby
|
90
90
|
# For payment webhooks
|
91
|
-
result = DefraRubyGovpay::
|
91
|
+
result = DefraRubyGovpay::WebhookPaymentService.run(webhook_body)
|
92
92
|
# => { id: "hu20sqlact5260q2nanm0q8u93", status: "success" }
|
93
93
|
|
94
94
|
# For refund webhooks
|
95
|
-
result = DefraRubyGovpay::
|
95
|
+
result = DefraRubyGovpay::WebhookRefundService.run(webhook_body)
|
96
96
|
# => { id: "789", payment_id: "original-payment-123", status: "success" }
|
97
97
|
```
|
98
98
|
|
@@ -123,8 +123,8 @@ The gem can handle both payment and refund webhooks:
|
|
123
123
|
|
124
124
|
The appropriate service class will be used based on the webhook type:
|
125
125
|
|
126
|
-
- `
|
127
|
-
- `
|
126
|
+
- `WebhookPaymentService` for payment webhooks
|
127
|
+
- `WebhookRefundService` for refund webhooks
|
128
128
|
|
129
129
|
## Testing
|
130
130
|
|
data/lib/defra_ruby_govpay/services/{govpay_webhook_base_service.rb → webhook_base_service.rb}
RENAMED
@@ -3,8 +3,8 @@
|
|
3
3
|
require "active_support/core_ext/object/blank"
|
4
4
|
|
5
5
|
module DefraRubyGovpay
|
6
|
-
class
|
7
|
-
class
|
6
|
+
class WebhookBaseService
|
7
|
+
class InvalidStatusTransition < StandardError; end
|
8
8
|
|
9
9
|
attr_accessor :webhook_body, :previous_status
|
10
10
|
|
@@ -44,9 +44,9 @@ module DefraRubyGovpay
|
|
44
44
|
def validate_status_transition
|
45
45
|
return if self.class::VALID_STATUS_TRANSITIONS[previous_status]&.include?(webhook_payment_or_refund_status)
|
46
46
|
|
47
|
-
raise
|
48
|
-
|
49
|
-
|
47
|
+
raise InvalidStatusTransition, "Invalid #{payment_or_refund_str} status transition " \
|
48
|
+
"from #{previous_status} to #{webhook_payment_or_refund_status}" \
|
49
|
+
"#{log_webhook_context}"
|
50
50
|
end
|
51
51
|
|
52
52
|
def extract_data_from_webhook
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DefraRubyGovpay
|
4
|
+
class WebhookBodyValidatorService
|
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 = WebhookSignatureService.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
|
data/lib/defra_ruby_govpay/services/{govpay_webhook_payment_service.rb → webhook_payment_service.rb}
RENAMED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module DefraRubyGovpay
|
4
|
-
class
|
4
|
+
class WebhookPaymentService < WebhookBaseService
|
5
5
|
|
6
6
|
VALID_STATUS_TRANSITIONS = {
|
7
7
|
"created" => %w[started submitted success failed cancelled error],
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module DefraRubyGovpay
|
4
|
-
class
|
4
|
+
class WebhookSignatureService
|
5
5
|
class DigestFailure < StandardError; end
|
6
6
|
|
7
7
|
def self.run(body:)
|
@@ -11,7 +11,7 @@ module DefraRubyGovpay
|
|
11
11
|
def run(body:)
|
12
12
|
generate_signatures(body.to_s)
|
13
13
|
rescue StandardError => e
|
14
|
-
DefraRubyGovpay.logger.error "
|
14
|
+
DefraRubyGovpay.logger.error "Payment webhook signature generation failed: #{e}"
|
15
15
|
raise DigestFailure, e
|
16
16
|
end
|
17
17
|
|
data/lib/defra_ruby_govpay.rb
CHANGED
@@ -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/services/
|
13
|
-
require_relative "defra_ruby_govpay/services/
|
14
|
-
require_relative "defra_ruby_govpay/services/
|
15
|
-
require_relative "defra_ruby_govpay/services/
|
16
|
-
require_relative "defra_ruby_govpay/services/
|
12
|
+
require_relative "defra_ruby_govpay/services/webhook_base_service"
|
13
|
+
require_relative "defra_ruby_govpay/services/webhook_payment_service"
|
14
|
+
require_relative "defra_ruby_govpay/services/webhook_refund_service"
|
15
|
+
require_relative "defra_ruby_govpay/services/webhook_sanitizer_service"
|
16
|
+
require_relative "defra_ruby_govpay/services/webhook_signature_service"
|
17
|
+
require_relative "defra_ruby_govpay/services/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.
|
4
|
+
version: 1.0.0
|
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-
|
11
|
+
date: 2025-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -53,11 +53,12 @@ files:
|
|
53
53
|
- lib/defra_ruby_govpay/object.rb
|
54
54
|
- lib/defra_ruby_govpay/payment.rb
|
55
55
|
- lib/defra_ruby_govpay/refund.rb
|
56
|
-
- lib/defra_ruby_govpay/services/
|
57
|
-
- lib/defra_ruby_govpay/services/
|
58
|
-
- lib/defra_ruby_govpay/services/
|
59
|
-
- lib/defra_ruby_govpay/services/
|
60
|
-
- lib/defra_ruby_govpay/services/
|
56
|
+
- lib/defra_ruby_govpay/services/webhook_base_service.rb
|
57
|
+
- lib/defra_ruby_govpay/services/webhook_body_validator_service.rb
|
58
|
+
- lib/defra_ruby_govpay/services/webhook_payment_service.rb
|
59
|
+
- lib/defra_ruby_govpay/services/webhook_refund_service.rb
|
60
|
+
- lib/defra_ruby_govpay/services/webhook_sanitizer_service.rb
|
61
|
+
- lib/defra_ruby_govpay/services/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
|