This guide will help you set up Stripe payment integration for wallet recharge functionality in the CircularSync application.
- Stripe Account: Create a Stripe account at https://stripe.com
- Node.js and npm: For frontend dependencies
- PostgreSQL: For database setup
- Ballerina: For backend services
The Stripe dependency has been added to Ballerina.toml:
[[dependency]]
org = "ballerinax"
name = "stripe"
version = "3.0.0"Update your Config.toml file with your Stripe credentials:
# Stripe Payment Configuration
stripeSecretKey = "sk_test_your-stripe-secret-key-here"
stripeWebhookSecret = "whsec_your-webhook-secret-here"Important:
- Use test keys for development (starting with
sk_test_) - Never commit real API keys to version control
- Use environment variables in production
Run the payment schema SQL script to create required tables:
psql -U your_username -d your_database -f backend/scripts/payment_schema.sqlThis creates:
payment_intentstable for tracking Stripe paymentspayment_methodstable for storing user payment methodsstripe_customerstable for Stripe customer mapping- Necessary indexes and triggers
The payment service runs on port 8098. Make sure this port is available:
cd backend
bal runInstall the required Stripe packages:
cd frontend
npm install @stripe/stripe-js @stripe/react-stripe-jsUpdate your .env file:
# Add your Stripe publishable key
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_your-stripe-publishable-key-here
# Add payment API URL
NEXT_PUBLIC_PAYMENT_API_URL=http://localhost:8098npm run dev- Log in to your Stripe Dashboard
- Go to Developers > API keys
- Copy your Publishable key and Secret key
- For webhooks, go to Developers > Webhooks
Create a webhook endpoint for production:
- Go to Developers > Webhooks
- Click Add endpoint
- URL:
https://yourdomain.com/api/payment/webhook - Select events:
payment_intent.succeededpayment_intent.payment_failedcustomer.created
Use these test card numbers during development:
- Visa: 4242424242424242
- Visa (debit): 4000056655665556
- Mastercard: 5555555555554444
- Declined card: 4000000000000002
Use any future expiry date, any 3-digit CVC, and any postal code.
- Payment Intent Creation: Create secure payment intents for wallet recharge
- Payment Confirmation: Verify and process successful payments
- Customer Management: Create and manage Stripe customers
- Webhook Processing: Handle Stripe webhook events
- Database Integration: Automatic wallet balance updates
- Transaction Logging: Complete audit trail of payments
- Stripe Elements: Secure card input with Stripe Elements
- Payment Flow: Multi-step payment process with validation
- Real-time Validation: Amount and payment method validation
- Error Handling: Comprehensive error messages and recovery
- Loading States: User feedback during payment processing
- Responsive Design: Works on desktop and mobile devices
POST /api/payment/create-intent- Create payment intentPOST /api/payment/confirm-payment- Confirm paymentGET /api/payment/intent/{id}- Get payment intent statusPOST /api/payment/customer- Create Stripe customerPOST /api/payment/webhook- Handle Stripe webhooks
POST /api/payment/create-intent- Proxy to backendPOST /api/payment/confirm-payment- Proxy to backendGET /api/payment/intent/[id]- Proxy to backendPOST /api/payment/customer- Proxy to backend
- API Keys: Never expose secret keys in frontend code
- HTTPS: Always use HTTPS in production
- Webhook Verification: Verify webhook signatures
- Amount Validation: Validate amounts on both frontend and backend
- Authentication: All endpoints require user authentication
- Input Sanitization: Validate and sanitize all inputs
- Navigate to wallet dashboard
- Click "Deposit Funds"
- Select "Credit/Debit Card" payment method
- Enter amount and click "Continue to Payment"
- Use test card: 4242424242424242
- Complete payment and verify wallet balance update
- Invalid card numbers
- Expired cards
- Insufficient funds
- Network errors
- "Module not found" errors: Run
npm installto install dependencies - Stripe key errors: Verify your publishable key is correct
- Payment failures: Check Stripe Dashboard for detailed error logs
- Database errors: Ensure payment schema is properly applied
- CORS issues: Verify service configurations and ports
Check these locations for debug information:
- Ballerina console output
- Browser developer console
- Stripe Dashboard > Logs
- Backend log files
Set these environment variables in production:
# Backend
STRIPE_SECRET_KEY=sk_live_your-live-secret-key
STRIPE_WEBHOOK_SECRET=whsec_your-live-webhook-secret
# Frontend
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_live_your-live-publishable-key
NEXT_PUBLIC_PAYMENT_API_URL=https://yourdomain.com/api/paymentUpdate webhook URL to your production domain and ensure HTTPS.
Apply the payment schema to your production database.
For additional help:
- Stripe Documentation: https://stripe.com/docs
- Ballerina Stripe Connector: https://central.ballerina.io/ballerinax/stripe
- CircularSync Documentation: Check the docs folder
- Implement payment method management (save/delete cards)
- Add subscription billing for premium features
- Implement refund functionality
- Add multi-currency support
- Integration with accounting systems