Overview
AndanDo integrates with PayPal for processing tour bookings and payments. The PayPal configuration supports both sandbox (testing) and live production environments.PayPal integration uses the REST API for creating orders, capturing payments, and managing transactions.
Configuration
PayPal settings are configured in thePayPal section of appsettings.json:
appsettings.json
Configuration Properties
Mode
The PayPal environment mode.- Type:
string - Required: No
- Default:
"sandbox"(defined inPaypalOptions.cs:5) - Values:
"sandbox"or"live"
ClientId
Your PayPal application’s Client ID.- Type:
string - Required: Yes
- Format: Long alphanumeric string
- Location: Found in PayPal Developer Dashboard
ClientSecret
Your PayPal application’s Client Secret.- Type:
string - Required: Yes
- Format: Long alphanumeric string
- Security: Keep confidential, never commit to source control
BaseUrl
The PayPal API base URL.- Type:
string - Required: No
- Default:
"https://api-m.sandbox.paypal.com"(defined inPaypalOptions.cs:8) - Sandbox:
https://api-m.sandbox.paypal.com - Live:
https://api-m.paypal.com
The
BaseUrl should automatically change based on Mode, but can be explicitly set if needed.PaypalOptions Class
The configuration is bound to thePaypalOptions class:
Services/Paypal/PaypalOptions.cs
Service Registration
The PayPal service is registered inProgram.cs:
Program.cs
AddHttpClient automatically configures an HttpClient instance for the PaypalService, enabling efficient HTTP connection pooling.Environment-Specific Configuration
Getting PayPal Credentials
Create a PayPal Developer Account
Create a PayPal Developer Account
- Go to PayPal Developer Dashboard
- Sign in with your PayPal account (or create one)
- Click Apps & Credentials
- Select Sandbox for testing or Live for production
- Click Create App
- Enter your app name (e.g., “AndanDo”)
- Select your sandbox business account
- Click Create App
- Copy the Client ID and Secret from the app details page
Sandbox credentials are separate from live credentials. You’ll need to create apps in both environments.
Sandbox Testing Accounts
Sandbox Testing Accounts
PayPal provides test accounts for sandbox testing:
- Go to Sandbox → Accounts in the Developer Dashboard
- PayPal creates default personal and business test accounts
- Use these accounts to test payments without real money
- Click View/Edit account to see login credentials
- Visa:
4032039861089129 - Mastercard:
5497803644557597 - Amex:
379402515662075 - Expiry: Any future date
- CVV: Any 3-4 digits
Storing Credentials Securely
Development (User Secrets)
Development (User Secrets)
Use User Secrets for local development:Verify:
Production (Environment Variables)
Production (Environment Variables)
Use environment variables in production:Or in
appsettings.Production.json (without the secret):Azure App Service / Key Vault
Azure App Service / Key Vault
Store PayPal secrets in Azure Key Vault:Reference in App Service Application Settings:
PayPal API Integration
Typical PayPal payment flow in AndanDo:Testing PayPal Integration
Unit Testing with Mock Configuration
Unit Testing with Mock Configuration
Integration Testing with Sandbox
Integration Testing with Sandbox
Troubleshooting
Authentication failed
Authentication failed
Error:
401 Unauthorized when calling PayPal APICause: Invalid ClientId or ClientSecret.Solutions:- Verify credentials are copied correctly from PayPal Dashboard
- Ensure you’re using sandbox credentials with sandbox URLs
- Check that credentials haven’t expired or been revoked
- Verify the credentials match the environment (sandbox vs live)
Invalid request
Invalid request
Error:
400 Bad Request or 422 Unprocessable EntitySolutions:- Verify request payload format matches PayPal API documentation
- Check amount format (must be string with 2 decimal places)
- Ensure currency code is valid (USD, EUR, etc.)
- Validate all required fields are present
- Check PayPal API version compatibility
Configuration not loading
Configuration not loading
Error: Options are empty or have default valuesSolutions:
- Verify
appsettings.jsoncontains thePayPalsection - Check
Program.csincludes the configuration binding - Ensure JSON syntax is valid (no trailing commas)
- Verify environment-specific files are properly named
- Check environment variables format:
PayPal__ClientId(double underscore)
HTTPS certificate errors
HTTPS certificate errors
Error: SSL/TLS certificate validation failuresSolutions:
- Ensure you’re using HTTPS URLs, not HTTP
- Update .NET runtime to latest version
- Verify system time is correct (affects certificate validation)
- Check corporate proxy/firewall isn’t intercepting HTTPS
PayPal Webhooks
To receive payment notifications, configure webhooks in PayPal Dashboard:- Go to Apps & Credentials → Your App → Webhooks
- Click Add Webhook
- Enter your webhook URL:
https://yourdomain.com/api/webhooks/paypal - Select event types to subscribe to:
PAYMENT.CAPTURE.COMPLETEDPAYMENT.CAPTURE.DENIEDCHECKOUT.ORDER.APPROVED
- Click Save
Webhooks require your application to be publicly accessible. Use ngrok or similar for local testing.