Testing suite
Test Payment Workflows End-to-End With Zero Financial Risk
Built-in MockProvider, sandbox card fixtures, network delay simulators, and test utilities to run automated integration tests in your CI/CD pipeline.
vitest · better-payment/testing
- 4111 1111 1111 1111approved
- 4000 0000 0000 0002insufficient funds
- 4000 0000 0000 32203D Secure required
3 passed · 0 failed
Why it matters
Why this earns its place in your stack
Built-in MockProvider
Zero API credentials required: test charges and 3D redirects locally offline.
Decline Scenario Simulator
Simulate insufficient funds, expired cards, and 3D SMS failures deterministically.
Network Jitter & Timeout Testing
Validate that double-charge protections hold up under extreme network timeouts.
Vitest & Jest Ready
Mock and assert payment execution states effortlessly in your test runners.
Simple, readable, direct.
Without Better Payment
Unreliable sandbox environments that go down frequently and stall pull request merges.
With Better Payment
Deterministic local mock engines that execute in milliseconds inside GitHub Actions.
TypeScript
import { createBetterPayment, MockProvider } from "better-payment";
import { describe, it, expect } from "vitest";
describe("Checkout Flow", () => {
it("handles insufficient funds gracefully", async () => {
const payment = createBetterPayment({
defaultProvider: "mock",
providers: {
mock: new MockProvider({ simulateDecline: "INSUFFICIENT_FUNDS" })
}
});
await expect(payment.createPayment({ ... }))
.rejects.toThrow("INSUFFICIENT_FUNDS");
});
});