anedot_webhooks 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 25399debdd7e8129a0321fe79bd06df0e54d537f0abe1dfd914042a88d2a84e4
4
+ data.tar.gz: 2a202294d03eefd9227d0e646cf785f39ee98bb751a8b24cf43ab0dff2a4796c
5
+ SHA512:
6
+ metadata.gz: '094ee4eb8337c6f41827c03f6f1141ce50104bf051ec541a1e392984459d64f611c4676f68dba30465218acd3c25be50f327fe77eae89c0371f9a93f975923c1'
7
+ data.tar.gz: 77beba81b0f55a14202aeb79db89aa585bfc6861236c007691fd3fba234247ec412dee4b7ff31b14349aeab4b4b06c806227152e621b4e73e41619ef013d64b1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jason Rogers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,109 @@
1
+ # AnedotWebhooks
2
+
3
+ A mountable Rails engine for receiving [Anedot](https://anedot.com) webhook callbacks.
4
+ Verifies request authenticity via HMAC-SHA256 and publishes events via
5
+ `ActiveSupport::Notifications`.
6
+
7
+ ## Installation
8
+
9
+ Add to your Gemfile:
10
+
11
+ ```ruby
12
+ gem "anedot_webhooks"
13
+ ```
14
+
15
+ ## Configuration
16
+
17
+ Mount the engine and configure your webhook secret:
18
+
19
+ ```ruby
20
+ # config/routes.rb
21
+ mount AnedotWebhooks::Engine, at: "/anedot_webhooks"
22
+ ```
23
+
24
+ ```ruby
25
+ # config/initializers/anedot_webhooks.rb
26
+ AnedotWebhooks.configure do |config|
27
+ config.webhook_secret = ENV["ANEDOT_WEBHOOK_SECRET"]
28
+ end
29
+ ```
30
+
31
+ Set the Anedot webhook URL to `https://yourapp.com/anedot_webhooks/events`.
32
+
33
+ ## Subscribing to events
34
+
35
+ ### Catch-all
36
+
37
+ ```ruby
38
+ ActiveSupport::Notifications.subscribe("anedot_webhooks.event") do |*, payload|
39
+ event = payload[:event] # AnedotWebhooks::Event
40
+ Rails.logger.info "Received #{event.name}: #{event.payload["id"]}"
41
+ end
42
+ ```
43
+
44
+ ### Specific event type
45
+
46
+ ```ruby
47
+ ActiveSupport::Notifications.subscribe("anedot_webhooks.donation_completed") do |*, payload|
48
+ event = payload[:event]
49
+ Donation.record!(event.payload)
50
+ end
51
+ ```
52
+
53
+ ### Available event types
54
+
55
+ | Event | Description |
56
+ |-------|-------------|
57
+ | `submission_created` | New submission created |
58
+ | `submission_pledged` | Pledge submission created |
59
+ | `donation_completed` | Successful donation processed |
60
+ | `donation_ach_returned` | ACH/check return |
61
+ | `donation_chargeback` | Chargeback initiated |
62
+ | `donation_chargeback_reversed` | Chargeback reversed |
63
+ | `donation_partially_refunded` | Partial refund |
64
+ | `donation_refunded` | Full refund |
65
+ | `donation_voided` | Donation voided |
66
+ | `donation_settled` | Settlement completed |
67
+ | `commitment_created` | New recurring commitment |
68
+ | `commitment_updated` | Commitment modified |
69
+ | `commitment_failed_to_process` | Recurring charge failed |
70
+
71
+ ## Async handling with ActiveJob
72
+
73
+ Subclass `AnedotWebhooks::WebhookJob` and override `process`:
74
+
75
+ ```ruby
76
+ class HandleDonation < AnedotWebhooks::WebhookJob
77
+ def process(event)
78
+ Donation.create!(event.payload)
79
+ end
80
+ end
81
+ ```
82
+
83
+ Then enqueue from a subscriber:
84
+
85
+ ```ruby
86
+ ActiveSupport::Notifications.subscribe("anedot_webhooks.donation_completed") do |*, payload|
87
+ event = payload[:event]
88
+ HandleDonation.perform_later(event.name, event.payload)
89
+ end
90
+ ```
91
+
92
+ ## Security
93
+
94
+ All requests are verified via HMAC-SHA256 using your webhook secret. Requests with
95
+ an invalid or missing `X-Request-Signature` header are rejected with `401 Unauthorized`
96
+ before any processing occurs.
97
+
98
+ **Important:** Configure a request body size limit at the web server layer (e.g.,
99
+ `client_max_body_size 1m` in nginx) to limit exposure to unauthenticated large-payload
100
+ requests. The gem does not enforce a body size limit.
101
+
102
+ ## Development
103
+
104
+ ```bash
105
+ bundle exec rspec # tests
106
+ bin/rubocop # lint
107
+ bin/rubocop -a # lint with autocorrect
108
+ bin/brakeman # security scan
109
+ ```
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AnedotWebhooks
4
+ class ApplicationController < ActionController::API
5
+ before_action :verify_signature!
6
+ before_action :parse_payload
7
+
8
+ private
9
+
10
+ def parse_payload
11
+ @payload = JSON.parse(@raw_body)
12
+ head :unprocessable_content unless @payload.is_a?(Hash)
13
+ rescue JSON::ParserError
14
+ head :unprocessable_content
15
+ end
16
+
17
+ def verify_signature!
18
+ secret = AnedotWebhooks.configuration.webhook_secret
19
+ return head :internal_server_error if secret.nil? || secret.empty?
20
+ @raw_body = request.body.read
21
+ expected = OpenSSL::HMAC.hexdigest("SHA256", secret, @raw_body)
22
+ actual = request.headers["X-Request-Signature"].to_s
23
+ head :unauthorized unless ActiveSupport::SecurityUtils.secure_compare(expected, actual)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AnedotWebhooks
4
+ class WebhooksController < ApplicationController
5
+ def receive
6
+ event = Event.new(name: @payload["event"], payload: @payload["payload"])
7
+ ActiveSupport::Notifications.instrument(event.notification_name, event: event)
8
+ ActiveSupport::Notifications.instrument("anedot_webhooks.event", event: event)
9
+ head :ok
10
+ end
11
+ end
12
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ AnedotWebhooks::Engine.routes.draw do
4
+ post "events", to: "webhooks#receive"
5
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AnedotWebhooks
4
+ class Configuration
5
+ attr_accessor :webhook_secret
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AnedotWebhooks
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace AnedotWebhooks
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AnedotWebhooks
4
+ Event = Data.define(:name, :payload) do
5
+ def notification_name
6
+ "anedot_webhooks.#{name}"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AnedotWebhooks
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AnedotWebhooks
4
+ class WebhookJob < ActiveJob::Base
5
+ def perform(event_name, payload)
6
+ process(Event.new(name: event_name, payload: payload))
7
+ end
8
+
9
+ def process(event)
10
+ raise NotImplementedError, "#{self.class}#process must be implemented"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "anedot_webhooks/configuration"
4
+ require "anedot_webhooks/event"
5
+ require "anedot_webhooks/version"
6
+ require "anedot_webhooks/webhook_job"
7
+ require "anedot_webhooks/engine"
8
+
9
+ module AnedotWebhooks
10
+ class << self
11
+ def configure
12
+ yield configuration
13
+ end
14
+
15
+ def configuration
16
+ @configuration ||= Configuration.new
17
+ end
18
+
19
+ def reset_configuration!
20
+ @configuration = nil
21
+ end
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: anedot_webhooks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason Rogers
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: actionpack
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '8.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '8.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: activejob
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '8.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '8.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: activesupport
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '8.0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '8.0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: railties
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '8.0'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '8.0'
68
+ description: A mountable Rails engine that receives Anedot webhook callbacks, verifies
69
+ their authenticity via HMAC-SHA256, and publishes events via ActiveSupport::Notifications.
70
+ email:
71
+ - jason@wordsanddeeds.org
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - LICENSE.txt
77
+ - README.md
78
+ - app/controllers/anedot_webhooks/application_controller.rb
79
+ - app/controllers/anedot_webhooks/webhooks_controller.rb
80
+ - config/routes.rb
81
+ - lib/anedot_webhooks.rb
82
+ - lib/anedot_webhooks/configuration.rb
83
+ - lib/anedot_webhooks/engine.rb
84
+ - lib/anedot_webhooks/event.rb
85
+ - lib/anedot_webhooks/version.rb
86
+ - lib/anedot_webhooks/webhook_job.rb
87
+ homepage: https://github.com/jacaetevha/anedot-webhooks
88
+ licenses:
89
+ - MIT
90
+ metadata:
91
+ homepage_uri: https://github.com/jacaetevha/anedot-webhooks
92
+ changelog_uri: https://github.com/jacaetevha/anedot-webhooks/blob/main/CHANGELOG.md
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '3.2'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubygems_version: 3.6.9
108
+ specification_version: 4
109
+ summary: Mountable Rails engine for receiving Anedot webhook callbacks
110
+ test_files: []