An Azure Function that processes debit transactions. This function takes a transaction ID and transaction data as input and calls the E-check Debit API.
- Async Processing: Built with async/await for optimal performance
- Error Handling: Comprehensive error handling with detailed logging
- Request Tracking: Each request gets a unique request ID for tracking
- Timeout Management: Configurable timeouts for external API calls
- Environment Configuration: Uses environment variables for configuration
-
Python 3.8 or higher
-
Azure Functions Core Tools
- ubuntu
-
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
-
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
-
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-$(lsb_release -cs)-prod $(lsb_release -cs) main" > /etc/apt/sources.list.d/dotnetdev.list'
-
apt-get update
-
apt-get install azure-functions-core-tools-4
-
- ubuntu
-
Azure subscription (for deployment)
-
Install dependencies:
chmod +x setup.sh ./setup.sh source venv/bin/activate -
Configure environment variables: Copy
.env.templateto.envand update the values:cp .env.template .env
Edit
.envwith your actual API credentials:_BASE_URL=https://your-actual--url.com _AUTH_TOKEN=your-actual-auth-token -
Run locally:
func start
- Method: POST
- Path:
/api/debit - Authentication: Function key required
{
"transaction_id": "TXN123456"
}{
"success": true,
"status_code": 200,
"response_data": " API response data",
"transaction_id": "TXN123456",
"request_id": "uuid-here",
"processing_time_ms": 1250.5
}{
"success": false,
"status_code": 400,
"error_message": "Error description",
"transaction_id": "TXN123456",
"request_id": "uuid-here",
"processing_time_ms": 150.2
}- Install Azure CLI:
- curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
- chmod +x deployment.sh
- ./deployment.sh
- Create a Storage Account from the Portal
- ./deployment.sh
-
Add environment variables: Portal > Function App > Settings > Environment Variables
-
Validate variables using this command: az functionapp config appsettings list --name payliance-function-app-1756466897 --resource-group payliance-rg --output table
-
func azure functionapp publish payliance-poc --python
The function uses the following default values:
- Routing Number:
121000358 - Account Number:
5428610017522 - SEC Code:
POS(if not provided) - Account Type:
Personal Checking - Request Timeout: 30 seconds
- Connection Timeout: 10 seconds
The function provides comprehensive logging including:
- Request processing start/end
- API call details
- Error conditions
- Processing time metrics
- Request IDs for correlation
Logs are available in:
- Local development: Console output
- Azure: Application Insights and Function App logs
The function handles various error scenarios:
- Missing required fields: Returns 400 with descriptive error
- API timeouts: Returns 408 with timeout message
- HTTP errors: Returns appropriate status code with error details
- Network errors: Returns 500 with connection error details
- Unexpected errors: Returns 500 with generic error message
curl -X POST "http://localhost:7071/api/debit" \
-H "Content-Type: application/json" \
-d '{
"transaction_id": "TEST123"
}'- Store sensitive configuration (API tokens) in Azure Key Vault for production
- Use managed identity for Azure resource access
- Enable authentication/authorization on the Function App
- Implement IP restrictions if needed
- Monitor and alert on function executions
- Import errors: Ensure all dependencies are in
requirements.txt - Authentication errors: Verify
_AUTH_TOKENis correct - Connection errors: Check
_BASE_URLand network connectivity - Timeout errors: Adjust timeout values if needed
Enable verbose logging by setting log level in host.json or through environment variables.
az servicebus queue update --name transactions --namespace-name transactions-payliance --resource-group payliance-rg --max-delivery-count 5 --lock-duration PT5M
./setup_local_testing.sh python3 test_servicebus_local.py --send-message --transaction-id "10525241839999953614" ./cleanup_local_testing.sh