Cooperative Sync API

Cooperative software (any stack) keeps QOOP-Pay updated through one authenticated endpoint. Each accepted event updates the member's inputs and recomputes their wallet limit via the eligibility formula — the response tells the cooperative system what the member can now spend. The reverse direction exists too: QOOP-Pay POSTs purchase.created webhooks to the cooperative's configured URL so their software learns about member purchases (set it in Coop portal → Developer → Webhooks).

Endpoint

POST /api/v1/coop/sync
Authorization: CoopSync <key_id>:<secret>
Content-Type: application/json

{
  "event_type": "salary.updated",        // member.created | contribution.posted | loan.posted | salary.updated
                                         // | member.updated | member.deactivated | member.reactivated
  "member_ref": "LAG-0001",              // the cooperative's own member id
  "cooperative_ref": "NG-COOP-8842",     // the cooperative's QOOP-Pay registry id
  "occurred_at": "2026-11-21T10:00:00Z", // ISO timestamp — part of the idempotency key
  "amounts": { "salary": "45000.00" }
}

Events and fields

event_typeamounts fields usedEffect
member.createdfull_name, email, phone, contribution, salary, monthly_repayment, date_joinedCreates user + membership + wallet (auto-approved), computes initial limit
contribution.postedcontributionAdds to member contributions + society total; credits wallet; recomputes limit
loan.postedoutstanding_loans, monthly_repaymentSets loan inputs (absolute values); recomputes limit
salary.updatedsalarySets salary; recomputes limit
member.updatedsalary, monthly_repayment, contribution, outstanding_loans — any subsetSets each provided input to the ABSOLUTE value given; recomputes limit
member.deactivated—Deactivates membership + blocks portal sign-in (both environments); no amount fields
member.reactivated—Restores sign-in + membership; does NOT recompute the limit

Test vs live credentials

Every cooperative holds one credential per environment. Test keys carry the cs_test_ prefix and live keys cs_live_; the credential you authenticate with decides the environment for the whole request. Money postings from test events land in the member's test ledger (never live balances), and formula-input changes (salary, contributions, loans) run as a dry-run — the response echoes what the limit would be, but the member's record stays untouched. Identity operations are the one exception: deactivate/reactivate apply in BOTH environments (below). Use the test credential for integration; the live credential is for production go-live.

Environment semantics by event

EventLIVE credentialTEST credential
member.createdUser + membership + wallet created; contribution posts to the live ledger; society total updated; limit appliedUser + membership + wallet created (identity applies); contribution posts to the test ledger; mirrors and society total untouched; limit echoed from the live formula
contribution.postedMirrors + society total updated; wallet credited (live ledger); limit reappliedWallet test balance credited; mirrors and society total untouched; limit echoed
loan.posted / salary.updated / member.updatedFormula-input mirrors set; limit recomputed and appliedDry-run: validated + recorded, mirrors untouched; limit echoed
member.deactivated / member.reactivatedAppliesApplies identically — identity operations, not money (D48 rule)

Member lifecycle (deactivate / reactivate)

member.deactivated sets the membership inactive AND blocks portal sign-in in one lockstep move (the same semantics as the coop admin toggle). It applies in BOTH environments — it is an identity operation, not a money posting, so the test dry-run rule does not apply. member.reactivated restores both; it never recomputes the wallet limit (the next eligibility pass does). Both are idempotent: deactivating an already deactivated member (or reactivating an active one) succeeds with "replayed": true and no write.

Responses

Money/formula events (member.created, contribution.posted, loan.posted, salary.updated, member.updated):

{
  "wallet_limit": "188100.00",
  "wallet_balance": "188100.00",
  "components": { "PA": "4000000.00", "SA": "1787919.46", "LC": "188100.00" }
}

Identity events (member.deactivated / member.reactivated):

{ "member_ref": "LAG-0001", "active": false }   // + "replayed": true when already in that state

Formula: wallet = LEAST(PA, SA, LC) where PA = contributions + 0.5·loans, SA = seniority-weighted share of society cash, LC = (0.33·salary + monthly repayment) × loan period. Limit changes post an eligibility_update entry to the member's wallet history.

Reading member state

GET /api/v1/coop/member?member_ref=LAG-0001
Authorization: CoopSync <key_id>:<secret>

-> 200
{
  "member_ref": "LAG-0001",
  "full_name": "Babatunde Adeleke",
  "status": "active",              // active | deactivated | pending_review | unknown
  "wallet_balance": "128700.00",   // scoped to the credential's environment
  "wallet_limit": "188100.00",
  "components": { "PA": "…", "SA": "…", "LC": "…" },
  "environment": "live"
}
GET /api/v1/coop/member/history?member_ref=LAG-0001&limit=50
Authorization: CoopSync <key_id>:<secret>

-> 200
{
  "member_ref": "LAG-0001",
  "environment": "live",
  "count": 2,
  "entries": [
    { "txn_ref": "QP-…", "direction": "D", "amount": "5000.00",
      "balance_after": "123700.00", "entry_type": "purchase_debit",
      "description": "Purchase — …", "created_at": "2026-11-22T10:14:00Z" }
  ]                                 // newest first; limit default 25, cap 100
}

wallet_balance and the history entries are scoped to the credential's environment (live mirror vs test ledger); wallet_limit and components always echo the live formula.

Webhooks to the cooperative

Set the cooperative's webhook URL in Coop portal → Developer → Webhooks. QOOP-Pay then POSTs JSON to it, signed with X-QOOPay-Signature (HMAC-SHA256 of the raw body with your signing secret) and tagged X-QOOP-Pay-Event. Failed deliveries retry 3 times with backoff.

POST <your webhook_url>
X-QOOPay-Signature: sha256=…
X-QOOP-Pay-Event: purchase.created

{
  "event": "purchase.created",
  "member_ref": "LAG-0001",
  "member_name": "Babatunde Adeleke",
  "order_amount": "5000.00",
  "qpay_fee": "75.00",        // the member-borne QPay fee — visible to the cooperative
  "merchant": "Slot Systems Limited",
  "order_id": "ORD-88",
  "transaction_ref": "QP-ORD-88",
  "environment": "live",
  "occurred_at": "2026-11-22T10:14:00Z"
}

webhook.test carries the same envelope with a health-check message (send it from the Developer page). The QPay fee is included because it is charged by the member's own cooperative — their software reconciles it; merchants never see it.

Idempotency

Events are keyed on (cooperative_ref, member_ref, event_type, occurred_at) per environment. Re-sending the same payload returns the stored result with "replayed": true and makes no changes. The same (type, occurred_at) delivered on live AND test are two independent deliveries.

Errors

StatusMeaning
401Bad credentials (key_id unknown, secret mismatch, inactive)
403Credential belongs to a different cooperative
404Unknown cooperative_ref / member_ref
409member.created for an existing member_ref
422Validation failure (bad event_type, missing refs, bad timestamp)
Credentials are issued by QOOP-Pay ops per cooperative — the secret is shown once and stored hashed (same policy as merchant keys). Coop admins can regenerate either namespace's secret themselves in Coop portal → Developer; the key_id never changes.