Payment Provider Architecture
The payment system in Openfront uses an adapter pattern that abstracts payment provider implementation details. Each payment provider implements a standard set of functions:createPaymentFunction- Initialize a payment intentcapturePaymentFunction- Capture an authorized paymentrefundPaymentFunction- Process refundsgetPaymentStatusFunction- Check payment statusgeneratePaymentLinkFunction- Generate provider-specific payment linkshandleWebhookFunction- Process webhook events
Payment Providers
Stripe Integration
Openfront includes full Stripe integration with support for automatic payment methods, payment intents, and webhook processing.Configuration
Add your Stripe credentials to your environment variables:Implementation
The Stripe adapter (features/integrations/payment/stripe.ts) implements all required payment functions:
Capturing Payments
Processing Refunds
Webhook Handling
Stripe webhooks are verified using signature validation:PayPal Integration
PayPal integration supports both sandbox and production environments with OAuth2 authentication.Configuration
Currency Handling
PayPal has special handling for no-division currencies (JPY, KRW, etc.):Creating PayPal Orders
Manual Payment
The manual payment provider allows processing payments outside the automated flow, useful for bank transfers, checks, or other offline payment methods.Payment Flow
mutation {
createPaymentSessions(cartId: "cart_id") {
id
paymentSessions {
id
providerId
status
}
}
}
mutation {
setPaymentSession(cartId: "cart_id", providerId: "pp_stripe_***") {
id
selectedPaymentSession {
providerId
data
}
}
}
Multi-Currency Support
Openfront handles multiple currencies automatically:- Amounts are stored in the smallest currency unit (cents)
- Currency conversion happens at the region level
- No-division currencies (JPY, KRW) are handled appropriately
- Each payment provider receives properly formatted amounts
Payment Sessions
Payment sessions track payment state for each provider:Creating Custom Payment Adapters
To add a new payment provider:- Create a new file in
features/integrations/payment/ - Implement all required functions:
- Register the adapter in
features/integrations/payment/index.ts:
- Create the provider in the admin dashboard under Payment Providers
Security Best Practices
- Never expose secret keys in client-side code
- Always validate webhook signatures
- Use environment variables for credentials
- Implement proper error handling
- Log payment events for audit trails
- Use HTTPS for all payment communications
Testing Payments
Use provider test credentials for development: Stripe Test Cards:- Success:
4242 4242 4242 4242 - Decline:
4000 0000 0000 0002 - Authentication Required:
4000 0025 0000 3155
- Use sandbox credentials from PayPal Developer Dashboard
- Test with sandbox buyer accounts