@@ -13,26 +13,39 @@ import (
1313// - "mock": Mock provider for testing (always available)
1414// - "jumio": Jumio identity verification
1515// - "onfido": Onfido identity verification
16+ // - "stripe": Stripe Identity verification
1617//
1718// ProviderConfig contains provider-specific settings like API keys and endpoints.
1819// Required keys vary by provider.
1920//
20- // WebhookSecret is the HMAC secret used to verify incoming webhook signatures.
21- // This prevents malicious actors from spoofing verification callbacks.
21+ // WebhookSecret is the HMAC secret used to verify incoming webhook signatures
22+ // for the generic webhook handler and as the inner HMAC secret for the Stripe
23+ // adapter. This prevents malicious actors from spoofing verification callbacks.
24+ //
25+ // StripeWebhookSecret is the Stripe endpoint signing secret (whsec_ prefixed)
26+ // used exclusively to validate the Stripe-Signature header on inbound Stripe
27+ // webhooks. Required when provider is "stripe".
2228//
2329// WebhookURL is the publicly accessible URL where providers send verification
2430// callbacks. Required for production deployments.
2531type VerificationConfig struct {
26- // Provider is the verification provider to use ("mock", "jumio", "onfido").
32+ // Provider is the verification provider to use ("mock", "jumio", "onfido", "stripe" ).
2733 Provider string
2834
2935 // ProviderConfig contains provider-specific configuration.
3036 // For jumio/onfido: "api_key", "api_secret", "base_url" (optional).
37+ // For stripe: "api_key", "base_url" (optional), "stripe_account" (optional).
3138 ProviderConfig map [string ]string
3239
33- // WebhookSecret is the HMAC secret for validating webhook signatures.
40+ // WebhookSecret is the HMAC secret for validating webhook signatures on the
41+ // generic handler and as the inner HMAC secret for the Stripe adapter.
3442 WebhookSecret string
3543
44+ // StripeWebhookSecret is the Stripe endpoint signing secret (whsec_ prefixed)
45+ // used to validate inbound Stripe webhook signatures.
46+ // Loaded from STRIPE_WEBHOOK_SECRET. Required when provider is "stripe".
47+ StripeWebhookSecret string
48+
3649 // WebhookURL is the public URL for provider callbacks (e.g., "https://api.example.com/webhooks/verification").
3750 WebhookURL string
3851}
@@ -45,27 +58,32 @@ var (
4558 ErrEmptyWebhookURLForNonMock = errors .New ("webhook URL is required for non-mock providers" )
4659 ErrMissingProviderAPIKey = errors .New ("api_key is required in provider config" )
4760 ErrMissingProviderAPISecret = errors .New ("api_secret is required in provider config" )
61+ ErrMissingStripeWebhookSecret = errors .New ("stripe_webhook_secret is required when provider is stripe (set STRIPE_WEBHOOK_SECRET)" )
4862 ErrMockProviderInProduction = errors .New ("mock provider not allowed in production" )
4963 ErrWebhookHTTPSRequired = errors .New ("webhook URL must use HTTPS in production" )
5064 ErrWebhookSecretTooShort = errors .New ("webhook secret must be at least 32 characters in production" )
5165)
5266
5367// SupportedProviders lists all supported verification provider names.
54- var SupportedProviders = []string {"mock" , "jumio" , "onfido" }
68+ var SupportedProviders = []string {"mock" , "jumio" , "onfido" , "stripe" }
5569
5670// LoadVerificationConfig loads verification configuration from environment variables.
5771//
5872// Required environment variables:
5973// - VERIFICATION_PROVIDER: The provider to use (required)
6074//
6175// Conditional environment variables (required for non-mock providers):
62- // - VERIFICATION_WEBHOOK_SECRET: HMAC secret for webhook validation
76+ // - VERIFICATION_WEBHOOK_SECRET: HMAC secret for generic webhook validation
6377// - VERIFICATION_WEBHOOK_URL: Public webhook callback URL
6478//
6579// Provider-specific environment variables:
6680// - VERIFICATION_API_KEY: Provider API key
67- // - VERIFICATION_API_SECRET: Provider API secret
81+ // - VERIFICATION_API_SECRET: Provider API secret (not required for Stripe)
6882// - VERIFICATION_BASE_URL: Provider base URL (optional, provider default used if not set)
83+ //
84+ // Stripe-specific environment variables:
85+ // - STRIPE_WEBHOOK_SECRET: Stripe endpoint signing secret (whsec_ prefixed).
86+ // Required when VERIFICATION_PROVIDER=stripe.
6987func LoadVerificationConfig () (* VerificationConfig , error ) {
7088 providerConfig := make (map [string ]string )
7189
@@ -81,10 +99,11 @@ func LoadVerificationConfig() (*VerificationConfig, error) {
8199 }
82100
83101 cfg := & VerificationConfig {
84- Provider : strings .TrimSpace (os .Getenv ("VERIFICATION_PROVIDER" )),
85- ProviderConfig : providerConfig ,
86- WebhookSecret : strings .TrimSpace (os .Getenv ("VERIFICATION_WEBHOOK_SECRET" )),
87- WebhookURL : strings .TrimSpace (os .Getenv ("VERIFICATION_WEBHOOK_URL" )),
102+ Provider : strings .TrimSpace (os .Getenv ("VERIFICATION_PROVIDER" )),
103+ ProviderConfig : providerConfig ,
104+ WebhookSecret : strings .TrimSpace (os .Getenv ("VERIFICATION_WEBHOOK_SECRET" )),
105+ StripeWebhookSecret : strings .TrimSpace (os .Getenv ("STRIPE_WEBHOOK_SECRET" )),
106+ WebhookURL : strings .TrimSpace (os .Getenv ("VERIFICATION_WEBHOOK_URL" )),
88107 }
89108
90109 if err := cfg .Validate (); err != nil {
@@ -122,10 +141,16 @@ func (c *VerificationConfig) Validate() error {
122141 if c .ProviderConfig ["api_key" ] == "" {
123142 return ErrMissingProviderAPIKey
124143 }
125- if c .ProviderConfig ["api_secret" ] == "" {
144+ // Stripe only needs api_key; other providers require api_secret as well
145+ if strings .ToLower (c .Provider ) != "stripe" && c .ProviderConfig ["api_secret" ] == "" {
126146 return ErrMissingProviderAPISecret
127147 }
128148
149+ // Stripe requires its own endpoint signing secret (distinct from the generic HMAC secret)
150+ if strings .ToLower (c .Provider ) == "stripe" && c .StripeWebhookSecret == "" {
151+ return ErrMissingStripeWebhookSecret
152+ }
153+
129154 return nil
130155}
131156
0 commit comments