-
Added Stripe Dependency
- Updated
Ballerina.tomlwithballerinax/stripe:3.0.0
- Updated
-
Created Payment Module (
modules/payment/)payment_service.bal- Core Stripe integration functionspayment_controller.bal- HTTP API endpointstypes.bal- Type definitionsModule.md- Documentation
-
API Endpoints (Port 8098)
POST /api/payment/create-intent- Create payment intentPOST /api/payment/confirm-payment- Confirm paymentGET /api/payment/intent/{id}- Get payment statusPOST /api/payment/customer- Create Stripe customerPOST /api/payment/webhook- Handle webhooks
-
Database Schema
payment_intentstable for tracking paymentspayment_methodstable for user payment methodsstripe_customerstable for customer mapping- Enhanced
wallet_transactionswith payment references
-
Configuration
- Added Stripe keys to
Config.toml.template - Integrated with existing auth middleware
- Added Stripe keys to
-
Package Installation
@stripe/stripe-jsand@stripe/react-stripe-js(with --legacy-peer-deps)
-
Created Components
StripeDepositModal.tsx- Complete payment flow modal- Updated
DepositModal.tsx- Added Stripe option - Removed incompatible React Stripe components
-
Created Services
paymentService.ts- API communication service- Updated
stripe.ts- Stripe utilities (React 19 compatible)
-
API Routes (Frontend)
/api/payment/create-intent- Proxy to backend/api/payment/confirm-payment- Proxy to backend/api/payment/intent/[id]- Proxy to backend/api/payment/customer- Proxy to backend
-
Configuration
- Added
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEYto.env - Added
NEXT_PUBLIC_PAYMENT_API_URLto.env
- Added
- User selects "Credit/Debit Card" in deposit modal
- Amount validation and payment intent creation
- Stripe.js loads dynamically (React 19 compatible)
- Secure card input with real-time validation
- Payment confirmation and wallet balance update
- Transaction logging and audit trail
- Server-side payment intent creation
- Client-side card tokenization (never store card data)
- Payment confirmation with backend verification
- Webhook support for payment events
- User authentication required for all operations
- Multi-step payment flow with clear progress
- Real-time validation and error handling
- Loading states and success feedback
- Mobile-responsive design
- Dark mode support
- Get Stripe Keys from Stripe Dashboard
- Update Config.toml:
stripeSecretKey = "sk_test_your-secret-key" stripeWebhookSecret = "whsec_your-webhook-secret"
- Run Database Migration:
psql -U username -d database -f backend/scripts/payment_schema.sql
- Start Backend:
cd backend && bal run
- Install Dependencies (already done):
npm install @stripe/stripe-js @stripe/react-stripe-js --legacy-peer-deps
- Update .env:
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_your-publishable-key NEXT_PUBLIC_PAYMENT_API_URL=http://localhost:8098
- Start Frontend:
npm run dev
- Successful Payment: 4242424242424242
- Declined Payment: 4000000000000002
- Authentication Required: 4000002500003155
- Navigate to wallet dashboard
- Click "Deposit Funds"
- Select "Credit/Debit Card" option
- Enter amount and continue
- Use test card details
- Complete payment and verify wallet update
- Replace test keys with live keys
- Set up webhook endpoint with HTTPS
- Configure proper error monitoring
- Set up database backups
- Implement rate limiting
- Add compliance features (PCI DSS)
- Complete setup guide:
STRIPE_SETUP.md - Payment schema:
backend/scripts/payment_schema.sql - API documentation:
backend/modules/payment/Module.md
Due to React 19 compatibility issues with @stripe/react-stripe-js, we implemented:
- Direct Stripe.js integration without React components
- Dynamic script loading for Stripe.js
- Custom card element integration
- Manual payment flow handling
This approach is more reliable and gives us full control over the payment experience.