Skip to content

Latest commit

Β 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TropiPay Wallet Demo - Client Integration Guide

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.


🎯 For TropiPay Integration Partners

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.

What You'll Learn

  • βœ… 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

πŸ—οΈ Architecture Overview

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
Loading

Technology Stack

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

πŸš€ Quick Start for Integration Partners

Prerequisites

  • Node.js 16+ installed
  • TropiPay Developer Account
  • Client ID and Client Secret from TropiPay

1. Get Your TropiPay Credentials

  1. Register at TropiPay Developer Portal
  2. Create a new credential
  3. Copy your Client ID and Client Secret
  4. Configure redirect URLs if needed
  5. You can get a detailed api doc here

2. Clone and Setup

# Clone the repository
git clone <repository-url>
cd tropipay-wallet

# Install frontend dependencies
npm install

# Install backend dependencies
cd backend
npm install

3. Environment Configuration

Create 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.db

4. Run the Application

Terminal 1 - Start Backend:

cd backend
npm start
# Backend will run on http://localhost:3001

Terminal 2 - Start Frontend:

npm start
# Frontend will open on http://localhost:3000

5. Login with Your Credentials

  1. Open http://localhost:3000
  2. Enter your TropiPay Client ID and Client Secret
  3. Select environment (Development recommended for testing)
  4. Click "Iniciar SesiΓ³n"

πŸ“‘ TropiPay API Integration Guide

Authentication Flow

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-id

Implementation: See backend/services/tropiPayService.js:115

Core API Endpoints

1. Account Management

// 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

2. Transfer Processing

// 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

3. Beneficiary Management

// 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

4. Transaction History

// 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


🏦 Key Integration Components

1. TropiPayService (Microservice Layer)

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)

2. UserService (Business Logic Layer)

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

3. Database Service

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)

🎨 Frontend Implementation Guide

State Management with React Context

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();

Key React Components

1. Authentication Components

  • LoginPage: OAuth2 client credentials form with environment selection
  • RegisterPage: New user registration with TropiPay integration
  • AuthContainer: Authentication flow coordinator

2. Dashboard Components

  • Dashboard: Multi-currency account overview with quick actions
  • AccountsPage: Detailed account management with card-based UI
  • ProfilePage: User profile and KYC status display

3. Transfer Components

  • TransferPage: 4-step transfer wizard (Form β†’ Simulate β†’ 2FA β†’ Confirm)
  • BeneficiariesPage: Beneficiary management with search and filtering
  • AddBeneficiaryPage: International beneficiary creation wizard

4. Transaction Components

  • MovementsPage: Transaction history with advanced filtering
  • Navigation: Responsive navigation with user context

API Service Layer

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);

πŸ”’ Security Implementation

1. Authentication Security

  • βœ… OAuth2 Client Credentials flow
  • βœ… Token-based authentication with expiration
  • βœ… Secure credential storage (backend only)
  • βœ… Environment-based configuration

2. Transfer Security

  • βœ… Two-factor authentication (SMS/Google Authenticator)
  • βœ… Transfer simulation before execution
  • βœ… Amount and balance validation
  • βœ… Reference and confirmation tracking

3. API Security

  • βœ… HTTPS enforcement in production
  • βœ… CORS configuration
  • βœ… Request/response logging
  • βœ… Error sanitization

4. Data Security

  • βœ… No sensitive data in frontend
  • βœ… Encrypted token storage
  • βœ… Local database encryption options
  • βœ… Input validation and sanitization

🌍 Multi-Environment Support

Development Environment

  • 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

Production Environment

  • API URL: https://www.tropipay.com/api/v3
  • Features: Full security, real transactions
  • Logging: Error logging only
  • Usage: Live applications

Environment Configuration

// 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
  }
};

πŸ’° Currency and Amount Handling

TropiPay Amount Format

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);

Supported Currencies

  • USD - US Dollars (primary)
  • EUR - Euros (international transfers)
  • CUP - Cuban Pesos (local transfers)

πŸ“± User Experience Patterns

Responsive Design

  • βœ… Mobile-first approach with TailwindCSS
  • βœ… Touch-friendly interfaces for mobile devices
  • βœ… Adaptive navigation (sidebar desktop, bottom mobile)
  • βœ… Optimized forms for different screen sizes

Loading States

  • βœ… Skeleton loaders for account data
  • βœ… Spinner components during API calls
  • βœ… Progress indicators for multi-step flows
  • βœ… Optimistic UI updates where appropriate

Error Handling

  • βœ… User-friendly error messages
  • βœ… Retry mechanisms for failed requests
  • βœ… Offline mode with cached data
  • βœ… Form validation with visual feedback

Accessibility

  • βœ… Keyboard navigation support
  • βœ… Screen reader compatible
  • βœ… High contrast mode support
  • βœ… ARIA labels and semantic HTML

πŸ”„ Data Synchronization

Real-time Updates

// Automatic account refresh after transfers
const executeTransfer = async (transferData) => {
  const result = await backendAPI.executeTransfer(userId, transferData);
  await refreshAccounts(); // Update balances immediately
  return result;
};

Offline Support

  • βœ… SQLite caching for account data
  • βœ… Graceful degradation when API unavailable
  • βœ… Local data persistence between sessions
  • βœ… Sync on reconnection

Cache Strategy

  • 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

πŸ§ͺ Testing and Development

Demo Mode Features

  • βœ… Pre-filled demo credentials for quick testing
  • βœ… Bypassed SMS 2FA (use code: 123456)
  • βœ… Test beneficiaries and accounts
  • βœ… Simulated transfer scenarios

Development Tools

# 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

API Testing

  • βœ… Built-in health check endpoint: GET /health
  • βœ… Comprehensive API logging in development
  • βœ… Error simulation and testing
  • βœ… Environment switching for testing

πŸ“Š Monitoring and Logging

Backend Logging

// 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 }

Frontend Monitoring

  • βœ… User action tracking
  • βœ… Error boundary components
  • βœ… Performance monitoring hooks
  • βœ… API call success/failure rates

πŸš€ Deployment Guide

Production Deployment

  1. 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
  1. 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
  1. Database Setup:
# Production database location
DB_PATH=/var/lib/tropipay-wallet/database.db

# Run migrations
cd backend && npm run migrate

Docker Deployment

# 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"]

πŸ“š Additional Resources

TropiPay Documentation

Code Examples

  • Authentication: backend/services/tropiPayService.js:115
  • Account Management: src/components/AccountsPage.js
  • Transfer Flow: src/components/TransferPage.js
  • Beneficiary Creation: src/components/AddBeneficiaryPage.js

Support and Community

  • GitHub Issues: Report bugs and feature requests
  • TropiPay Support: Technical integration support
  • Community Forum: Share implementations and best practices

🀝 Contributing to Your Integration

Customization Guide

  1. Branding: Update colors in tailwind.config.js and CSS variables
  2. Features: Add/remove components based on your needs
  3. Currencies: Extend currency support in tropiPayService.js
  4. Validation: Customize form validation rules
  5. UI/UX: Modify components while keeping TropiPay integration

Best Practices for Clients

  • βœ… Keep TropiPay service layer isolated
  • βœ… Implement proper error handling
  • βœ… Use environment configuration
  • βœ… Cache data appropriately
  • βœ… Follow security guidelines
  • βœ… Test in development environment first

πŸ“„ License and Usage

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

πŸ†˜ Support and Troubleshooting

Common Issues

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

Getting Help

  1. Check logs: Backend console and browser developer tools
  2. Health check: Visit http://localhost:3001/health
  3. API testing: Use provided endpoints with valid credentials
  4. Documentation: Review TropiPay API documentation
  5. 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! πŸ’»βœ¨

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages