A complete reference implementation for TropiPay API integration
This demo wallet provides TropiPay clients with a comprehensive example of how to integrate TropiPay's API services to build their own digital wallet applications. The implementation demonstrates best practices, security patterns, and UI/UX design for financial applications.
This repository serves as your complete integration guide and reference implementation for building wallet applications on top of TropiPay's infrastructure. Every component demonstrates real-world usage patterns you can adapt for your own projects.
- β Complete OAuth2 authentication flow with Client Credentials
- β Multi-environment setup (Development/Production)
- β Account management with real-time balance updates
- β International money transfers with fee simulation
- β Two-factor authentication (SMS + Google Authenticator)
- β Beneficiary management with IBAN/SWIFT validation
- β Transaction history with advanced filtering
- β Multi-currency support (USD, EUR, CUP)
- β Security best practices for financial applications
- β Responsive UI/UX patterns for web and mobile
graph TB
A[React Frontend] --> B[Backend API Proxy]
B --> C[TropiPay API]
B --> D[SQLite Database]
subgraph "Frontend Layer"
A --> A1[Authentication]
A --> A2[Dashboard]
A --> A3[Transfers]
A --> A4[Beneficiaries]
A --> A5[Movements]
end
subgraph "Backend Services"
B --> B1[TropiPayService]
B --> B2[UserService]
B --> B3[Database Service]
end
subgraph "TropiPay Integration"
C --> C1[OAuth2 Authentication]
C --> C2[Account Management]
C --> C3[Transfer Processing]
C --> C4[Beneficiary Management]
C --> C5[Transaction History]
end
Frontend (React)
- React 18 + Context API for state management
- TailwindCSS for responsive design
- Axios for API communication
- Lucide React for icons
- React Hot Toast for notifications
Backend (Node.js)
- Express.js API server
- SQLite3 for local data caching
- Axios for TropiPay API integration
- CORS configured for React frontend
TropiPay Integration
- OAuth2 Client Credentials flow
- RESTful API consumption
- Multi-environment support (dev/prod)
- Real-time data synchronization
- Node.js 16+ installed
- TropiPay Developer Account
- Client ID and Client Secret from TropiPay
- Register at TropiPay Developer Portal
- Create a new credential
- Copy your Client ID and Client Secret
- Configure redirect URLs if needed
- You can get a detailed api doc here
# Clone the repository
git clone <repository-url>
cd tropipay-wallet
# Install frontend dependencies
npm install
# Install backend dependencies
cd backend
npm installCreate a .env file in the backend/ directory:
# TropiPay Environment Configuration
TROPIPAY_DEFAULT_ENV=development
TROPIPAY_DEV_API_URL=https://sandbox.tropipay.me/api/v3
TROPIPAY_PROD_API_URL=https://www.tropipay.com/api/v3
# Server Configuration
PORT=3001
FRONTEND_URL=http://localhost:3000
# API Configuration
API_TIMEOUT=10000
ENABLE_API_LOGGING=true
# Database Configuration
DB_PATH=./tropipay_wallet.dbTerminal 1 - Start Backend:
cd backend
npm start
# Backend will run on http://localhost:3001Terminal 2 - Start Frontend:
npm start
# Frontend will open on http://localhost:3000- Open http://localhost:3000
- Enter your TropiPay Client ID and Client Secret
- Select environment (Development recommended for testing)
- Click "Iniciar SesiΓ³n"
The wallet implements OAuth2 Client Credentials flow:
// Step 1: Get Access Token
POST https://sandbox.tropipay.me/api/v3/access/token
{
"client_id": "your_client_id",
"client_secret": "your_client_secret",
"grant_type": "client_credentials"
}
// Step 2: Use Token for API Calls
Authorization: Bearer {access_token}
X-DEVICE-ID: your-device-idImplementation: See backend/services/tropiPayService.js:115
// Get user accounts
GET /accounts/
Headers: Authorization: Bearer {token}
// Response: Array of account objects with balances
[{
"accountId": "123",
"currency": "USD",
"balance": 50000, // in centavos
"available": 50000,
"blocked": 0
}]Implementation: See backend/services/tropiPayService.js:144
// Simulate transfer (get fees and rates)
POST /booking/payout/simulate
{
"accountId": "123",
"beneficiaryId": "456",
"amount": 10000, // in centavos
"currency": "USD"
}
// Execute transfer
POST /booking/payout
{
"accountId": "123",
"beneficiaryId": "456",
"amount": 10000,
"reference": "Transfer reference",
"smsCode": "123456" // if 2FA required
}Implementation: See backend/services/tropiPayService.js:196
// Get beneficiaries with pagination
GET /deposit_accounts/?offset=0&limit=20
// Create new beneficiary
POST /deposit_accounts
{
"name": "John Doe",
"lastName": "Smith",
"accountNumber": "ES9121000418450200051332",
"currency": "EUR",
"country": "ES",
"bankName": "BBVA Spain"
}Implementation: See backend/services/tropiPayService.js:157
// Get account movements
GET /accounts/{accountId}/movements?offset=0&limit=20
// Response includes transaction details
{
"rows": [{
"id": "txn_123",
"amount": 5000,
"type": "TRANSFER_OUT",
"status": "COMPLETED",
"createdAt": "2024-01-15T10:30:00Z"
}],
"totalCount": 150
}Implementation: See backend/services/tropiPayService.js:182
Purpose: Pure TropiPay API communication layer
Location: backend/services/tropiPayService.js
// Example usage
const tropiPayService = require('./services/tropiPayService');
// Switch environments dynamically
tropiPayService.switchEnvironment('production');
// Make authenticated API calls
const accounts = await tropiPayService.getAccounts(accessToken);
const simulation = await tropiPayService.simulateTransfer(accessToken, transferData);Key Features:
- β Environment switching (dev/prod)
- β Automatic currency conversion (centavos β units)
- β Comprehensive API logging
- β Error handling and interceptors
- β No database dependencies (stateless)
Purpose: Coordinates TropiPay API with local database
Location: backend/services/userService.js
const userService = require('./services/userService');
// Authenticate user and sync data
const user = await userService.authenticateUser(clientId, clientSecret, 'development');
// Refresh user accounts from TropiPay
const accounts = await userService.refreshUserAccounts(userId);
// Execute transfer with validation
const result = await userService.executeUserTransfer(userId, transferData);Key Features:
- β User session management
- β Local data caching
- β Offline fallback capabilities
- β Business logic and validation
- β Error recovery patterns
Purpose: SQLite operations for local data persistence
Location: backend/database.js
Schema:
-- Users table
users (id, client_id, client_secret, access_token, token_expires_at, user_data)
-- Accounts cache
accounts (user_id, account_id, currency, balance, account_data)
-- Beneficiaries cache
beneficiaries (user_id, beneficiary_id, beneficiary_data)Location: src/context/AuthContext.js
// Authentication state management
const {
user, // Current user data
accounts, // User accounts array
isLoading, // Loading state
login, // Login function
logout, // Logout function
refreshAccounts // Refresh accounts function
} = useAuth();- LoginPage: OAuth2 client credentials form with environment selection
- RegisterPage: New user registration with TropiPay integration
- AuthContainer: Authentication flow coordinator
- Dashboard: Multi-currency account overview with quick actions
- AccountsPage: Detailed account management with card-based UI
- ProfilePage: User profile and KYC status display
- TransferPage: 4-step transfer wizard (Form β Simulate β 2FA β Confirm)
- BeneficiariesPage: Beneficiary management with search and filtering
- AddBeneficiaryPage: International beneficiary creation wizard
- MovementsPage: Transaction history with advanced filtering
- Navigation: Responsive navigation with user context
Location: src/services/backendApi.js
// Frontend API client
import backendAPI from '../services/backendApi';
// Authentication
const response = await backendAPI.login(credentials);
// Account operations
const accounts = await backendAPI.getAccounts(userId);
// Transfer operations
const simulation = await backendAPI.simulateTransfer(userId, transferData);
const result = await backendAPI.executeTransfer(userId, transferData);- β OAuth2 Client Credentials flow
- β Token-based authentication with expiration
- β Secure credential storage (backend only)
- β Environment-based configuration
- β Two-factor authentication (SMS/Google Authenticator)
- β Transfer simulation before execution
- β Amount and balance validation
- β Reference and confirmation tracking
- β HTTPS enforcement in production
- β CORS configuration
- β Request/response logging
- β Error sanitization
- β No sensitive data in frontend
- β Encrypted token storage
- β Local database encryption options
- β Input validation and sanitization
- API URL:
https://sandbox.tropipay.me/api/v3 - Features: Demo mode, test data, bypassed 2FA
- Logging: Detailed API request/response logging
- Usage: Development and testing
- API URL:
https://www.tropipay.com/api/v3 - Features: Full security, real transactions
- Logging: Error logging only
- Usage: Live applications
// Dynamic environment switching
const config = {
development: {
apiUrl: 'https://sandbox.tropipay.me/api/v3',
enableLogging: true,
bypassSMS: true
},
production: {
apiUrl: 'https://www.tropipay.com/api/v3',
enableLogging: false,
bypassSMS: false
}
};TropiPay API uses centavos (smallest currency units) for all amounts:
// Conversion utilities (included)
const tropiPayService = require('./services/tropiPayService');
// Convert display amounts to API format
const apiAmount = tropiPayService.convertToCentavos(100.50); // 10050 centavos
// Convert API amounts to display format
const displayAmount = tropiPayService.convertFromCentavos(10050); // 100.50
// Handle account arrays
const accounts = tropiPayService.convertAccountsFromCentavos(rawAccounts);- USD - US Dollars (primary)
- EUR - Euros (international transfers)
- CUP - Cuban Pesos (local transfers)
- β Mobile-first approach with TailwindCSS
- β Touch-friendly interfaces for mobile devices
- β Adaptive navigation (sidebar desktop, bottom mobile)
- β Optimized forms for different screen sizes
- β Skeleton loaders for account data
- β Spinner components during API calls
- β Progress indicators for multi-step flows
- β Optimistic UI updates where appropriate
- β User-friendly error messages
- β Retry mechanisms for failed requests
- β Offline mode with cached data
- β Form validation with visual feedback
- β Keyboard navigation support
- β Screen reader compatible
- β High contrast mode support
- β ARIA labels and semantic HTML
// Automatic account refresh after transfers
const executeTransfer = async (transferData) => {
const result = await backendAPI.executeTransfer(userId, transferData);
await refreshAccounts(); // Update balances immediately
return result;
};- β SQLite caching for account data
- β Graceful degradation when API unavailable
- β Local data persistence between sessions
- β Sync on reconnection
- Accounts: Cached locally, refreshed on login and manual refresh
- Beneficiaries: Cached locally, synced on create/update
- Movements: Fetched on-demand, no caching (for accuracy)
- User Profile: Cached, refreshed on profile updates
- β Pre-filled demo credentials for quick testing
- β
Bypassed SMS 2FA (use code:
123456) - β Test beneficiaries and accounts
- β Simulated transfer scenarios
# Backend development with auto-reload
cd backend
npm run dev
# Frontend development with hot reload
npm start
# Database migration and setup
cd backend
npm run migrate- β
Built-in health check endpoint:
GET /health - β Comprehensive API logging in development
- β Error simulation and testing
- β Environment switching for testing
// API Request/Response logging
π === TROPIPAY API REQUEST ===
π€ POST https://sandbox.tropipay.me/api/v3/access/token
π Headers: { "Content-Type": "application/json" }
π¦ Payload: { "grant_type": "client_credentials" }
β
=== TROPIPAY API RESPONSE ===
π₯ 200 POST /access/token
π¦ Response Data: { "access_token": "...", "expires_in": 3600 }- β User action tracking
- β Error boundary components
- β Performance monitoring hooks
- β API call success/failure rates
- Environment Variables:
NODE_ENV=production
TROPIPAY_DEFAULT_ENV=production
TROPIPAY_PROD_API_URL=https://www.tropipay.com/api/v3
PORT=3001
ENABLE_API_LOGGING=false- Build and Deploy:
# Build frontend
npm run build
# Start backend with PM2
pm2 start backend/server.js --name "tropipay-wallet-backend"
# Serve frontend (nginx/apache)
# Point to build/ directory- Database Setup:
# Production database location
DB_PATH=/var/lib/tropipay-wallet/database.db
# Run migrations
cd backend && npm run migrate# Example Dockerfile structure
FROM node:18-alpine
# Backend setup
WORKDIR /app/backend
COPY backend/package*.json ./
RUN npm ci --only=production
# Frontend build
WORKDIR /app
COPY package*.json ./
RUN npm ci && npm run build
# Expose port and start
EXPOSE 3001
CMD ["npm", "run", "start:backend"]- Authentication:
backend/services/tropiPayService.js:115 - Account Management:
src/components/AccountsPage.js - Transfer Flow:
src/components/TransferPage.js - Beneficiary Creation:
src/components/AddBeneficiaryPage.js
- GitHub Issues: Report bugs and feature requests
- TropiPay Support: Technical integration support
- Community Forum: Share implementations and best practices
- Branding: Update colors in
tailwind.config.jsand CSS variables - Features: Add/remove components based on your needs
- Currencies: Extend currency support in
tropiPayService.js - Validation: Customize form validation rules
- UI/UX: Modify components while keeping TropiPay integration
- β Keep TropiPay service layer isolated
- β Implement proper error handling
- β Use environment configuration
- β Cache data appropriately
- β Follow security guidelines
- β Test in development environment first
This demo wallet is provided as a reference implementation for TropiPay integration partners. You are free to:
- β Use this code as a starting point for your wallet
- β Modify and customize for your specific needs
- β Deploy in production with your own branding
- β Share and collaborate with other developers
Requirements:
- Maintain TropiPay API integration standards
- Follow security best practices
- Credit TropiPay in your documentation
1. Authentication Errors
- β Verify Client ID and Client Secret
- β Check environment configuration
- β Ensure API URLs are correct
2. Transfer Failures
- β Verify account balances
- β Check beneficiary information
- β Validate 2FA codes
3. Connection Issues
- β Check CORS configuration
- β Verify backend is running on port 3001
- β
Test health endpoint:
GET /health
- Check logs: Backend console and browser developer tools
- Health check: Visit
http://localhost:3001/health - API testing: Use provided endpoints with valid credentials
- Documentation: Review TropiPay API documentation
- Support: Contact TropiPay technical support for integration help
π Start Building Your TropiPay Wallet Today!
This demo provides everything you need to integrate TropiPay's powerful financial services into your own application. Follow the integration patterns, adapt the components to your needs, and launch your wallet with confidence.
Happy Coding! π»β¨