The Fiserv CardPointe integration now supports switching between sandbox (UAT) and production environments using a single environment variable. This allows you to test in sandbox and then switch to production without changing multiple configuration values.
Old Structure (conflicting):
CARDPOINTE_API_URL=...
CARDPOINTE_MERCHANT_ID=...
CARDPOINTE_API_USERNAME=...
CARDPOINTE_API_PASSWORD=...
New Structure (environment-aware):
# Control which environment to use
FISERV_ENVIRONMENT="sandbox" # or "production"
# Sandbox credentials
FISERV_SANDBOX_API_URL="https://fts-uat.cardconnect.com"
FISERV_SANDBOX_MERCHANT_ID="490000000069"
FISERV_SANDBOX_API_USERNAME="testing"
FISERV_SANDBOX_API_PASSWORD="testing123"
# Production credentials
FISERV_PRODUCTION_API_URL="https://fts.cardconnect.com"
FISERV_PRODUCTION_MERCHANT_ID="496501158885"
FISERV_PRODUCTION_API_USERNAME="quarryllc"
FISERV_PRODUCTION_API_PASSWORD="CmAC4h5J4R3%m9Iktw5clxAv"
app/services/payment_processors/fiserv_adapter.rbFISERV_ENVIRONMENT:
self.fiserv_api_url - Returns sandbox or production API URLself.fiserv_merchant_id - Returns sandbox or production merchant IDself.fiserv_api_username - Returns sandbox or production usernameself.fiserv_api_password - Returns sandbox or production passwordENV["CARDPOINTE_*"] references with helper method calls.kamal/secretsCARDPOINTE_* variables to FISERV_SANDBOX_* and FISERV_PRODUCTION_*FISERV_ENVIRONMENT variable (defaults to "sandbox" for safety)config/deploy.ymlFISERV_ENVIRONMENT control variableapp/controllers/fiserv_validation_controller.rbPaymentProcessors::FiservAdapter.fiserv_api_urllib/tasks_scripts/fiserv_validation_test.rbThe system is currently configured to use sandbox by default:
# In .kamal/secrets
export FISERV_ENVIRONMENT="sandbox"
All transactions will use the UAT environment with test credentials.
When ready to go live:
Update .kamal/secrets:
export FISERV_ENVIRONMENT="production"
Deploy:
source .kamal/secrets && \
export KAMAL_REGISTRY_PASSWORD && \
export RAILS_MASTER_KEY && \
export POSTGRES_PASSWORD && \
kamal deploy
All transactions will now use production credentials automatically.
To test new features or troubleshoot issues:
Update .kamal/secrets:
export FISERV_ENVIRONMENT="sandbox"
Deploy:
source .kamal/secrets && \
export KAMAL_REGISTRY_PASSWORD && \
export RAILS_MASTER_KEY && \
export POSTGRES_PASSWORD && \
kamal deploy
Before switching to production, verify sandbox still works:
Ensure .kamal/secrets has FISERV_ENVIRONMENT="sandbox"
Load the secrets:
source .kamal/secrets
Test the validation page:
Visit: https://admin.quarryrents.com/fiserv-validation
Run a few test transactions:
Verify all tests complete successfully
FISERV_ENVIRONMENT is not set or has an invalid valueFISERV_ENVIRONMENT) needs to be changed to switch environments.kamal/secrets and deployed as environment variablesThe Fiserv validation page (/fiserv-validation) is only accessible when:
development environment, ORThis prevents accidental production testing and ensures the validation page is only used in appropriate environments.
Production credentials are already configured in .kamal/secrets:
https://fts.cardconnect.com496501158885quarryllcCmAC4h5J4R3%m9Iktw5clxAv# In production server via Kamal
kamal app exec -i "bin/rails runner 'puts \"Environment: #{ENV[\"FISERV_ENVIRONMENT\"]}\"; puts \"API URL: #{PaymentProcessors::FiservAdapter.fiserv_api_url}\"; puts \"Merchant ID: #{PaymentProcessors::FiservAdapter.fiserv_merchant_id}\"'"
# Check what's loaded in .kamal/secrets
source .kamal/secrets
echo "Environment: $FISERV_ENVIRONMENT"
echo "Sandbox URL: $FISERV_SANDBOX_API_URL"
echo "Production URL: $FISERV_PRODUCTION_API_URL"
bin/rails runner "puts PaymentProcessors::FiservAdapter.fiserv_api_url"
Potential future improvements: