Testing your integration
Fake provider
Section titled “Fake provider”import { Sarraf } from "@sarrafjs/core";import { fakeProvider } from "@sarrafjs/testing";
const fake = fakeProvider("paymob"); // stands in for any provider idconst pay = new Sarraf({ providers: { paymob: fake } });
await pay.checkout.create({ provider: "paymob", reference: "o1", /* … */ });const webhook = fake.simulate("o1", "succeeded"); // correctly signed requestconst event = await pay.webhooks.verifyAndParse("paymob", webhook);Real adapters with signed test webhooks
Section titled “Real adapters with signed test webhooks”Each adapter ships helpers under /testing:
import { paymobTransaction, signPaymobCallback } from "@sarrafjs/paymob/testing";import { kashierWebhookData, signKashierWebhook } from "@sarrafjs/kashier/testing";import { fawryNotification, signFawryNotification } from "@sarrafjs/fawry/testing";
const req = signPaymobCallback(paymobTransaction({ success: false }), process.env.TEST_HMAC!);Mock HTTP
Section titled “Mock HTTP”import { createMockFetch } from "@sarrafjs/testing";
const fetch = createMockFetch([ { method: "POST", url: "/v1/intention/", respond: { status: 201, body: { id: "pi_1", client_secret: "cs" } } },]);const pay = new Sarraf({ providers, http: { fetch } });Contributing adapters
Section titled “Contributing adapters”Every adapter must pass runConformanceTests() from @sarrafjs/core/conformance. See CONTRIBUTING.