defra_ruby_govpay 0.2.8 → 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 +12 -0
- 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/{govpay_webhook_body_validator_service.rb → webhook_body_validator_service.rb} +2 -2
- 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 -6
- metadata +8 -8
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,5 +1,13 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [v1.0.0](https://github.com/DEFRA/defra-ruby-govpay/tree/v1.0.0) (2025-04-30)
|
4
|
+
|
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
|
+
|
3
11
|
## [v0.2.8](https://github.com/DEFRA/defra-ruby-govpay/tree/v0.2.8) (2025-04-29)
|
4
12
|
|
5
13
|
[Full Changelog](https://github.com/DEFRA/defra-ruby-govpay/compare/v0.2.7...v0.2.8)
|
@@ -8,6 +16,10 @@
|
|
8
16
|
|
9
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))
|
10
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
|
+
|
11
23
|
## [v0.2.7](https://github.com/DEFRA/defra-ruby-govpay/tree/v0.2.7) (2025-04-28)
|
12
24
|
|
13
25
|
[Full Changelog](https://github.com/DEFRA/defra-ruby-govpay/compare/v0.2.6...v0.2.7)
|
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
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module DefraRubyGovpay
|
4
|
-
class
|
4
|
+
class WebhookBodyValidatorService
|
5
5
|
class ValidationFailure < StandardError; end
|
6
6
|
|
7
7
|
def self.run(body:, signature:)
|
8
8
|
raise ValidationFailure, "Missing expected signature" if signature.blank?
|
9
9
|
|
10
|
-
body_signatures =
|
10
|
+
body_signatures = WebhookSignatureService.run(body:)
|
11
11
|
return true if body_signatures[:front_office] == signature || body_signatures[:back_office] == signature
|
12
12
|
|
13
13
|
raise ValidationFailure, "digest/signature header mismatch"
|
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,12 +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/
|
17
|
-
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"
|
18
18
|
|
19
19
|
# The DefraRubyGovpay module facilitates integration with Govpay services.
|
20
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,12 +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/
|
61
|
-
- 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
|
62
62
|
- lib/defra_ruby_govpay/version.rb
|
63
63
|
- sig/defra_ruby_govpay.rbs
|
64
64
|
homepage: https://github.com/DEFRA/defra-ruby-govpay
|