Overview
The SnapPay Java SDK provides a comprehensive, enterprise-grade interface for integrating payment processing, subscription management, and real-time event streaming into your Java applications. Built with modern Java patterns including CompletableFuture for asynchronous operations, reactive streams for event handling, and comprehensive type safety, it offers seamless integration with SnapPay’s complete platform. Requirements: Java 11+ / Maven or GradleKey Features
- Modern async design with CompletableFuture and reactive patterns for optimal performance
- Enterprise-grade reliability with connection pooling and automatic retry mechanisms
- Real-time event streaming via Server-Sent Events (SSE) with reactive programming support
- Full type safety with immutable POJOs and builder patterns
- Thread-safe client for concurrent usage across your application
- Comprehensive error handling with typed exceptions and detailed error contexts
- Framework integrations for Spring Boot, Quarkus, and Micronaut
- Environment-based configuration with flexible setup options
Installation
Maven
Gradle
Gradle (Kotlin DSL)
Configuration & Initialization
The SDK client is configured via a primary constructor that accepts a configuration object. All operations return CompletableFuture for asynchronous execution and proper resource management.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:
SnapPay Client
Customer Management
getCustomer
Retrieves or creates a customer record.id(String): Customer identifieremail(String, optional): Customer email addressname(String, optional): Customer full name
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 dashboardsuccessUrl(String): URL to redirect after successful paymentcancelUrl(String, optional): URL to redirect on cancellationprovider(Provider): Payment provider (defaults to STRIPE)
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
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(Double): Usage amount to trackidempotencyKey(String, optional): Prevents duplicate tracking
getUsage
Retrieves current usage details for a customer’s feature.customerId(String): SnapPay customer IDfeatureId(String): Feature identifier
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 reactive patterns.🚫 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 reactive streams
- Guaranteed delivery with automatic reconnection
- Clean, structured data - no raw webhook payloads
- Reactive programming perfect for Java’s async ecosystem
- Type-safe event objects with comprehensive error handling
Event Structure
Supported Events
See the list of supported events: Server-sent Event TypesReactive Event Streaming
Simply subscribe to events as they arrive - SnapPay handles all the webhook complexity behind the scenes:- ✅ Zero webhook infrastructure - no endpoints, no servers, no security concerns
- ✅ Instant event processing - no webhook delivery delays or failures
- ✅ Reactive programming - perfect for Java’s async ecosystem
- ✅ Type-safe event handling - compile-time safety with comprehensive error handling