This guide walks you through using sandbox simulations to test various payment scenarios efficiently. You’ll learn how to simulate successful payments, fraud detection, insufficient funds, and other real-world scenarios without complex manual setup or extended wait times.
Understanding Sandbox Simulations
In production environments, payment processing involves asynchronous workflows, network processing windows, and various unpredictable outcomes. While our sandbox maintains this asynchronous behavior to ensure realistic testing, we’ve introduced a powerful simulation feature that gives you control over test transaction outcomes. The core of this system is theconfig
object with its sandbox_outcome
field. Think of this as your way to instruct the sandbox exactly how a test transaction should behave, while still maintaining the proper asynchronous flow that mirrors production behavior.
Sandbox simulations maintain asynchronous processing to match production behavior. While outcomes are deterministic, they still follow realistic timing patterns to ensure your integration handles asynchronous workflows correctly.
How Simulations Work
When you create an entity (customer
, paykey
, charge
, or payout
) in the sandbox, you can include a config
object that specifies your desired outcome:
"sandbox_outcome": "paid"
on a charge causes it to:
- Process normally through the initial states
- Transition to
scheduled
->pending
status - Automatically move to
paid
status within a few minutes
In the sandbox environment, simulated payments process every minute rather than waiting for standard network windows. This accelerates your testing cycle while maintaining realistic state transitions.
Available Simulation Outcomes
Understanding the available simulation options helps you create comprehensive test scenarios that cover all possible production behaviors. Let’s explore what you can simulate for each entity type.Control customer verification status during creation:
Outcome | Description | Use Case |
---|---|---|
standard | Customer undergoes normal review process | Testing standard onboarding flow |
verified | Customer automatically becomes verified | Testing post-verification features |
rejected | Customer automatically gets rejected | Testing rejection handling |
review | Customer enters manual review status | Testing review queue workflows |
Reversal scenarios are particularly valuable for testing reconciliation logic, as they simulate payments that initially succeed but are later reversed—a common real-world scenario that can be challenging to handle correctly.
Practical Examples
Let’s walk through complete testing scenarios, starting from creating test entities to processing payments. These examples demonstrate how to build realistic test cases from start to finish.Prerequisites
Before testing payment flows, ensure you have:- Created a sandbox organization and account
- Obtained your sandbox API credentials
- Set up webhook endpoints for receiving notifications
Example 1: Testing Successful Payment Flow
This example demonstrates the complete happy path for payment processing.1
Create a verified customer
First, create a customer that’s pre-verified to skip the review process:Save the
customer_id
from the response—you’ll need it for the next steps.2
Create an active paykey
Create a payment method that’s immediately active:The response includes a
paykey
that you’ll use to create charges.3
Create a successful charge
Now create a charge that will automatically succeed:This charge will:
- Create with status
created
- Move to
pending
as it enters processing - Transition to
paid
within a few minutes
4
Monitor webhook events
Your webhook endpoint should receive these status events:
created
- Initial charge creationscheduled
- Transaction verified and queued for originatonpending
- Charge delivered to networkpaid
- Funding complete
Example 2: Testing Fraud Detection
This scenario helps you verify your system properly handles fraud prevention measures.1
Create test entities
Use a new
customer
and paykey
creation process from Example 1, or reuse existing test entities.2
Create a charge flagged for fraud
3
Handle the cancellation
The charge will be immediately cancelled. Your system should:
- Receive a
cancelled
webhook status - Display appropriate messaging to users
- Log the fraud detection for analysis
Example 3: Testing Payment Reversals
Reversals represent a particularly challenging scenario since the payment initially succeeds. This example shows how to test your reversal handling logic.1
Create a customer with review status
For this test, let’s create a customer that requires review:
2
Create a paykey
3
Create a charge that will reverse
4
Track the complete lifecycle
This creates a realistic reversal scenario where:
- The charge processes normally
- Transitions to
paid
status - Your webhook receives a success notification
- Minutes later, the charge reverses to
reversed
status - Your webhook receives a reversal notification with code R01
Example 4: Testing Daily Limit Holds
This scenario tests your ability to handle and release held payments.on_hold
status. You can then test releasing the hold through your admin interface or API endpoints.
Production Behavior
Understanding how sandbox simulations behave in production is crucial for safe deployment. The system is designed with multiple safeguards to prevent any simulation logic from affecting production operations.In production environments:
- The
sandbox_outcome
field is nullable at the API level - If included, it must be set to
"standard"
to pass validation - The field is excluded from all API responses
- No simulation logic runs in production systems
- Test code accidentally deployed to production won’t cause unexpected behavior
- Production API responses remain clean and consistent
- There’s no performance impact from simulation logic
- Your production integration remains secure and predictable
Best Practices
To maximize the value of sandbox simulations, consider these comprehensive testing strategies.Create Comprehensive Test Suites
Build test suites that cover every possible outcome your integration might encounter:Document Test Data
Maintain clear documentation of your test scenarios and their purposes:Troubleshooting
When simulations don’t behave as expected, check these common issues and their solutions.Simulation not working as expected
Simulation not working as expected
Symptoms:
- Entity doesn’t follow the specified outcome
- Unexpected status transitions
- Missing webhook events
- Verify you’re using the sandbox environment URL:
https://sandbox.straddle.io
- Check that the outcome value is spelled exactly as documented
- Ensure the
config
object is properly formatted in your JSON request - Confirm your API credentials have the necessary permissions
Timing seems incorrect
Timing seems incorrect
Symptoms:
- Transitions happen too quickly or slowly
- Unexpected delays between states
- Webhooks arrive out of order
- Remember sandbox processes payments every minute (not real ACH timing)
- Network latency can affect webhook delivery order
- Use webhook event timestamps, not arrival time, for sequencing
- Implement idempotency to handle duplicate webhook deliveries
Webhook events missing or duplicated
Webhook events missing or duplicated
Symptoms:
- Expected webhooks don’t arrive
- Receiving duplicate webhook events
- Webhook signature validation fails
- Verify your webhook endpoint returns 200 status quickly
- Check webhook endpoint configuration in your account settings
- Ensure your endpoint can handle concurrent requests
- Implement proper webhook signature validation
- Log all received webhooks for debugging
Production code includes sandbox config
Production code includes sandbox config
Symptoms:
- Concerns about sandbox config in production
- Validation errors in production
- Unexpected behavior after deployment
- The field is safely ignored in production
- Use environment variables to conditionally include config
- Set up separate test and production code paths
- Add production deployment checks to catch test code
While sandbox simulations make testing significantly easier, always perform end-to-end testing with standard processing before deploying to production. This ensures your integration handles the full complexity of real-world payment processing, including edge cases and timing variations that simulations might not capture.