@pwngh/economy-lab
    Preparing search index...

    Variable clawbackConst

    clawback: (
        fields: FieldsOf<K>,
    ) => {
        actor: Principal;
        amount: Amount;
        idempotencyKey: string;
        key?: string;
        kind: "clawback";
        orderId?: string;
        reason?: string;
        userId: string;
    } = ...

    Builds a clawback operation: books the credit side of a bank chargeback or fraud recovery (the dollars move back at the payment processor, outside this ledger). It debits the user's spendable for whatever is still there, books the unrecoverable shortfall to RECEIVABLE, and credits the full amount back to STORED_VALUE, un-issuing the credits rather than booking revenue the platform never earned. Restricted to a system or operator actor; in production the verified dispute webhook is the usual caller. It has no rejected path — a well-formed clawback always commits, even against an empty wallet. An orderId-tied clawback shares the reversed:<orderId> claim with refund, so an already-reversed order returns duplicate; for a disputed sale, refund first, then claw back untied from the order.

    Type Declaration

      • (
            fields: FieldsOf<K>,
        ): {
            actor: Principal;
            amount: Amount;
            idempotencyKey: string;
            key?: string;
            kind: "clawback";
            orderId?: string;
            reason?: string;
            userId: string;
        }
      • Parameters

        • fields: FieldsOf<K>

        Returns {
            actor: Principal;
            amount: Amount;
            idempotencyKey: string;
            key?: string;
            kind: "clawback";
            orderId?: string;
            reason?: string;
            userId: string;
        }

    const outcome = await economy.submit(clawback({
    idempotencyKey: idempotencyKey('whk', 'evt_5521'),
    actor: systemActor('webhook:billing'),
    userId: 'usr_buyer',
    amount: toAmount('CREDIT', 60_000n), // the disputed 600 credits
    reason: 'fraudulent_charge',
    }));