Add invoice creation, quoting, and webhook signature verification

Finishes the two gaps that mattered most for real use: Invoices#create
(POST invoices) + Invoices#quote (POST invoices/{id}/quote, returning
the new Quote model with the actual payable bolt11 — an invoice alone
has nothing payable until quoted) and Webhook.valid_signature?
(HMAC-SHA256 over the raw body via X-Webhook-Signature, per Strike's own
documented reference implementation, timing-safe compare). Also finishes
Invoices#find (was a stub with a leftover binding.pry) and adds
WebhookEvent to parse the {id, eventType, data: {entityId, changes}}
payload shape — deliberately doesn't expose changed values, since
Strike's webhooks never carry them; a real value only ever comes from
re-fetching the resource.

Client gains #post/#patch (only #get existed before), needed for both
of the above.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0199wudpuAtkhouHKSEGxzpa
This commit is contained in:
bterkuileandClaude Sonnet 5 committed 2026-09-15 09:34:45 -05:00
1 parent 9b0351576a
commit 90ab7c74b1
11 files changed
+308 -4

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
# frozen_string_literal: true
module StrikeMe
module API
# Parses the WebhookEvent payload every Strike webhook POST carries —
# {id, eventType, webhookVersion, data: {entityId, changes}, created,
# deliverySuccess}. Deliberately does NOT carry the changed values
# themselves — Strike's own docs are explicit that the event never
# contains the actual data changes, only that something changed on
# `entity_id`. A real value only comes from calling the matching
# fetch endpoint (e.g. Invoices#find for an invoice.* event) —
# trusting anything else here would mean trusting an unauthenticated
# claim about money having moved.
class WebhookEvent < BaseModel
attribute :id
attribute :eventType
attribute :webhookVersion
attribute :data
attribute :created, :datetime
attribute :deliverySuccess, :boolean
alias_attribute :event_type, :eventType
alias_attribute :webhook_version, :webhookVersion
alias_attribute :delivery_success, :deliverySuccess
def entity_id
data['entityId'] || data[:entityId]
end
def changes
data['changes'] || data[:changes] || []
end
def invoice_event?
event_type.to_s.start_with?('invoice.')
end
end
end
end