Skip to main content

Xendit WireMock (Local)

This project includes a local WireMock service to mock Xendit API interactions.

Start/Stop

./scripts/wiremock.sh up
./scripts/wiremock.sh logs
./scripts/wiremock.sh down

WireMock runs at http://localhost:8080.

End-to-End Mock Flow

Run an automated backend flow test against WireMock:

npm run test:wiremock

This script will:

  1. Start WireMock
  2. Apply local D1 migrations
  3. Build and start Workers preview
  4. Execute payment create -> status -> webhook -> license verify checks
  5. Validate provider failure and timeout behavior (expects 502 mapping)
  6. Tear down WireMock

Configure Backend to Use WireMock

Set local env values for Workers preview:

export XENDIT_API_URL=http://localhost:8080
export XENDIT_SECRET_KEY=local-mock-key
export XENDIT_WEBHOOK_TOKEN=local-webhook-token

Then run preview:

npm run preview

Available Mock Endpoints

  • POST /qr_codes success (qr_mock_pending)
  • POST /qr_codes failure when reference_id contains fail
  • POST /qr_codes timeout scenario id when reference_id contains timeout
  • GET /qr_codes/qr_mock_pending => PENDING
  • GET /qr_codes/qr_mock_completed => COMPLETED
  • GET /qr_codes/qr_mock_failed => FAILED
  • GET /qr_codes/qr_mock_timeout => delayed response for timeout testing

Webhook Payload Samples

  • infra/wiremock/__files/webhook-completed.json
  • infra/wiremock/__files/webhook-failed.json

Use with backend webhook route:

curl -X POST http://localhost:8787/api/v1/payments/webhook \
-H 'content-type: application/json' \
-H 'x-callback-token: local-webhook-token' \
--data @infra/wiremock/__files/webhook-completed.json