Overview
The SnapPay Go SDK provides a comprehensive, idiomatic interface for integrating payment processing, subscription management, and real-time event streaming into your Go applications. Built with modern Go patterns including context support, channel-based concurrency, and explicit error handling, it offers seamless integration with SnapPay’s platform. Requirements: Go 1.21+Key Features
- Idiomatic Go design with context.Context support for cancellation and timeouts
- Channel-based concurrency for optimal performance and real-time event handling
- Explicit error handling following Go conventions
- Full type safety with struct definitions and interface contracts
- Goroutine-safe client for concurrent usage across your application
- Real-time event streaming via Server-Sent Events (SSE) using channels
- Context-aware operations with deadline propagation and cancellation
- Environment-based configuration with sensible defaults
Installation
go.mod:
Configuration & Initialization
The SDK client is configured via a constructor function that accepts an optional configuration struct. All operations support context.Context for proper timeout and cancellation handling.API Key Authentication
Authentication is handled via an API key that must start withpk_test_ (for testing) or pk_live_ (for production). Configure your API key in one of these ways:
Environment Variable (Recommended):
Core Methods
All methods accept acontext.Context as the first parameter and return a result struct pointer and an error, following standard Go patterns. The client is safe for concurrent use across multiple goroutines.
Customer Management
GetCustomer
Retrieves or creates a customer record (upsert logic).CustomerId(string): Customer identifierEmail(*string): Customer email address (optional)Name(*string): Customer full name (optional)
(*Customer, error)
Checkout Sessions
CreateCheckoutSession
Creates a payment checkout session URL for customer purchases.CustomerID(string): SnapPay customer IDProductID(string): Product ID from your snappay dashboardPriceID(*string): Price ID from your snappay dashboard (optional)SuccessURL(string): URL to redirect after successful paymentCancelURL(*string): URL to redirect on cancellation (optional)
(*CheckoutSession, error)
Access Control
CheckAccess
Checks if a customer has access to a specific feature based on their subscription and usage limits.CustomerID(string): SnapPay customer IDFeatureID(string): Feature identifier
(*AccessCheck, error)
Usage Tracking
TrackUsage
Reports usage for a metered feature. This action is idempotent to prevent duplicate tracking.CustomerID(string): SnapPay customer IDFeatureID(string): Feature identifier for usage trackingUsage(int64): Usage amount to trackIdempotencyKey(*string): Prevents duplicate tracking (optional)
(*TrackUsageResponse, error)
GetUsage
Retrieves current usage details for a customer’s feature.CustomerID(string): SnapPay customer IDFeatureID(string): Feature identifier
(*[]GetUsageResponse, error)
Real-time Event Handling
Say goodbye to webhook hell! snappay eliminates the complexity of managing payment webhooks by processing all provider webhooks (Stripe, PayPal, etc.) internally and delivering clean, structured events directly to your application via Server-Sent Events (SSE) using Go channels.🚫 What You DON’T Need:
- No webhook endpoints to create and maintain
- No webhook signature verification
- No webhook retry logic or failure handling
- No webhook security concerns
- No debugging webhook delivery issues
✅ What You GET:
- Real-time events delivered instantly via Go channels
- Guaranteed delivery with automatic reconnection
- Clean, structured data - no raw webhook payloads
- Channel-based concurrency perfect for Go’s goroutine model
- Context-aware with proper cancellation support