Files
commerce/payment/providers/square/webhook.go
zeekay 1943f1c093 Hanzo Commerce
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans,
usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0.

Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
2026-09-23 21:52:16 -07:00

34 lines
1.1 KiB
Go

package square
import (
"context"
"github.com/hanzoai/commerce/payment/processor"
)
// ValidateWebhook verifies the HMAC-SHA256 signature on an incoming
// Square webhook and returns a normalised event. BD's
// /v1/bd/webhooks/square handler must:
//
// 1. Iterate enabled square payment_providers rows (for multi-tenant
// webhook disambiguation — Square's webhook is headerless on tenant).
// 2. Call ValidateWebhook with the raw request body and the
// x-square-hmacsha256-signature header.
// 3. Accept the first row whose WebhookSignatureKey validates, reject
// with 401 if none match.
//
// The normalised event.Type will be one of:
// - payment.created
// - payment.updated (includes status=COMPLETED for settled funds)
// - refund.created / refund.updated
// - dispute.created / dispute.updated
//
// See thirdparty/square/processor.go::mapSquareEventType for the full
// mapping.
func (p *Provider) ValidateWebhook(ctx context.Context, payload []byte, signature string) (*processor.WebhookEvent, error) {
if err := p.checkAvailable(); err != nil {
return nil, err
}
return p.inner.ValidateWebhook(ctx, payload, signature)
}