Skip to main content

Chaos engineering for payment flows

Project description

Carbon Layer

Chaos engineering for payment flows.

Every company processing payments tests the happy path — payment succeeds, order fulfilled — and ships. What breaks in production is everything else: dispute spikes your system doesn't respond to, refund storms that break reconciliation, gateway errors that leave orders stuck, webhook sequences your handlers were never tested against.

Carbon Layer lets you simulate these failure modes against your own integration before your customers encounter them. Run a scenario, point it at your webhook endpoint, and see exactly what your system handles and what it doesn't.


Installation

pip install carbon-layer

PostgreSQL is required for storage. Create a database before the first run:

createdb carbon

Or use Docker:

docker run -d --name carbon-pg \
  -e POSTGRES_PASSWORD=carbon \
  -e POSTGRES_DB=carbon \
  -p 5433:5432 postgres:15

Set the connection string via environment variable or .env file:

DATABASE_URL=postgresql://postgres:carbon@localhost:5433/carbon

Quickstart

No Razorpay account needed to get started. The mock adapter simulates the full payment lifecycle locally.

List available scenarios:

carbon scenarios-list

Run a scenario:

carbon run dispute-spike --provider mock
carbon report --run-id <run_id>

Webhook Simulation

The real value of Carbon Layer is testing your webhook handlers. Point it at your endpoint and it fires Razorpay-format events — payment.captured, dispute.created, refund.processed, and more — after the scenario runs. Payloads are signed with X-Razorpay-Signature (HMAC-SHA256), the same as Razorpay's live webhooks.

carbon run dispute-spike --provider mock --webhook-url http://localhost:8000/webhooks/razorpay

The report shows how your endpoint responded for each event type — 2xx, 4xx, 5xx, or timeout. No Razorpay account required.


Scenarios

Scenario What it tests
dispute-spike 15% dispute rate — does your system respond and submit evidence?
payment-decline-spike 30% payment failure rate — does your retry and order state logic hold?
refund-storm Mass refunds on captured payments — does reconciliation break?
flash-sale High order and payment volume — does throughput hold?
gateway-error-burst Intermittent gateway errors — are orders left in inconsistent state?
min-amount Minimum paise transactions — are edge-case amounts handled correctly?
max-amount Large-value transactions — are limits and approvals handled correctly?

Parameter Overrides

Override scenario parameters at runtime without editing YAML:

carbon run dispute-spike --provider mock --set baseline_orders=500 --set dispute_rate=0.3

Use --set multiple times for multiple parameters. Unknown keys are ignored with a warning.


HTML Reports

Export a shareable HTML report after any run:

carbon report --run-id <run_id> --format html

Writes carbon_report_<run_id>.html to the current directory. Self-contained, no external dependencies — safe to share with your team or attach to an incident report.


CI/CD Integration

Use --callback-url to POST a JSON run summary to your pipeline after a scenario completes:

carbon run dispute-spike --provider mock \
  --webhook-url http://localhost:8000/webhooks/razorpay \
  --callback-url http://localhost:8000/carbon/results

The callback payload includes pass/fail status, findings summary, and webhook delivery counts. Your pipeline can fail the build if passed is false.


Using with Razorpay

To run scenarios against your Razorpay test account:

carbon run dispute-spike \
  --provider razorpay \
  --api-key rzp_test_xxx \
  --api-secret yyy \
  --webhook-url https://your-staging-app.com/webhooks/razorpay

Or set credentials via environment variables: RAZORPAY_API_KEY and RAZORPAY_API_SECRET.

Note: Razorpay's test API does not support server-side payment creation or dispute creation. Scenarios that require these (e.g. dispute-spike) use the mock adapter automatically for those actions. Use --provider mock if you don't have Razorpay test credentials.


License

Apache 2.0 — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

carbon_layer-0.2.0.tar.gz (34.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

carbon_layer-0.2.0-py3-none-any.whl (38.9 kB view details)

Uploaded Python 3

File details

Details for the file carbon_layer-0.2.0.tar.gz.

File metadata

  • Download URL: carbon_layer-0.2.0.tar.gz
  • Upload date:
  • Size: 34.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for carbon_layer-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1f013b4d668ded6726c797b13a0c0bffea90a2fabb27f099dc43f12f66ebb229
MD5 0dd6fcc4dea2216d46a05dd3c261e5ef
BLAKE2b-256 4ba372f6bc511197e637e66c8f087746d064c7c72a4b58df6503e9aeae976d06

See more details on using hashes here.

File details

Details for the file carbon_layer-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: carbon_layer-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 38.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for carbon_layer-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af841a285eed3607b9ef81d51a6eb10606a6d407f35913a29433518d80973524
MD5 d072d829a6c2a3d1b29a3119257e771f
BLAKE2b-256 665a2f71d04beb0731966aa371cc1c7eed20bf08258c5215c7837c206c02bbdf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page