Overview
CompuTécnicos integrates with PayPal to process online payments. The platform supports both sandbox (testing) and production environments, with automatic currency conversion from Colombian Pesos (COP) to US Dollars (USD).Prerequisites
Before configuring PayPal:- A PayPal Business account
- Access to the PayPal Developer Dashboard
- Basic understanding of PayPal REST API
Configuration Parameters
The PayPal integration is configured inconfig/paypal_config.php using environment variables:
Your PayPal REST API Client ID.How to obtain:
- Log in to PayPal Developer Dashboard
- Navigate to “Apps & Credentials”
- Create a new app or select an existing one
- Copy the Client ID
Your PayPal REST API Client Secret.Found in the same location as the Client ID in the PayPal Developer Dashboard.
The PayPal environment to use.Valid values:
sandbox- Test environment for developmentproduction- Live environment for real transactions
Additional Settings
The following settings are configured directly inconfig/paypal_config.php:
The currency for PayPal transactions. Set to USD for international compatibility.
Currency conversion rate from Colombian Pesos (COP) to US Dollars (USD).Default rate:
0.00025 (approximately 1 USD = 4000 COP)This is a simplified conversion rate. For production use, consider integrating with a real-time currency exchange API.
Setup Instructions
Create PayPal App
- Go to PayPal Developer Dashboard
- Click “Apps & Credentials”
- Click “Create App”
- Choose a name for your app (e.g., “CompuTécnicos”)
- Select “Merchant” as the app type
- Click “Create App”
Get API Credentials
After creating your app:
- Copy the Client ID from the app details page
- Click “Show” under Secret and copy the Client Secret
- Save these credentials securely
Test in Sandbox
- Use PayPal’s sandbox test accounts
- Create a personal (buyer) test account
- Process test transactions using the sandbox credentials
- Verify payments appear in the sandbox dashboard
Configuration File Structure
Theconfig/paypal_config.php file returns an array with the following structure:
Currency Conversion
Since CompuTécnicos operates in Colombia with prices in COP, but PayPal transactions use USD: Conversion Formula:- Product price: 100,000 COP
- PayPal amount: 100,000 × 0.00025 = 25 USD
The default exchange rate (0.00025) is approximate. For accurate, real-time rates, integrate with a currency exchange API like:
Security Best Practices
Protect API Credentials
- Store Client ID and Secret in environment variables only
- Never hardcode credentials in source code
- Add
.envto.gitignore - Use different credentials for development and production
Validate Payments Server-Side
Never trust client-side payment confirmations. Always verify payment status through PayPal’s API on the server.
Implement Webhooks
Set up PayPal webhooks to receive real-time payment notifications and handle asynchronous events.
Testing in Sandbox
Creating Test Accounts
- Go to Sandbox Accounts
- Click “Create Account”
- Select “Personal” (Buyer) account type
- Set the country to your target market
- Configure the balance and credit card details
- Click “Create Account”
Test Credentials
PayPal sandbox provides:- Test email addresses
- Test passwords
- Virtual balance
- Fake credit card numbers
Making Test Payments
- Use your sandbox Client ID and Secret
- Process a payment in your application
- Log in with a sandbox buyer account
- Complete the payment flow
- Verify the transaction in the sandbox dashboard
Troubleshooting
Authentication Failed
Error: “Authentication failed” or “Invalid client credentials” Solutions:- Verify Client ID and Secret are correct
- Ensure you’re using sandbox credentials with
PAYPAL_ENVIRONMENT=sandbox - Check for extra spaces or quotes in environment variables
- Regenerate credentials in PayPal Developer Dashboard
Currency Issues
Error: Payment amounts don’t match expected values Solutions:- Verify the exchange rate is set correctly
- Check that amounts are being converted from COP to USD
- Ensure currency is set to “USD” in the config
- Round amounts to 2 decimal places for USD
Environment Mismatch
Error: Transactions failing in production Solutions:- Verify you’re using production credentials, not sandbox
- Ensure
PAYPAL_ENVIRONMENT=production - Check that your PayPal business account is verified
- Verify your app has production access enabled
SSL/HTTPS Issues
Error: “SSL certificate verification failed” Solutions:- Ensure your server has up-to-date SSL certificates
- Verify your PHP installation has cURL with SSL support
- Check that your redirect URIs use HTTPS in production