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

    Variable refundConst

    refund: (
        fields: FieldsOf<K>,
    ) => {
        actor: Principal;
        idempotencyKey: string;
        kind: "refund";
        orderId: string;
        reason?: string;
    } = ...

    Builds a refund operation: reverses the completed sale recorded under orderId, leg for leg. The buyer gets the full price back; each seller's earned clawback is capped at the balance they still hold, with any uncollectable remainder booked to RECEIVABLE so no user account goes negative. The same transaction revokes the buyer's (or gift recipient's) entitlement to the SKU. Restricted to a system or operator actor — a self-serve refund would be a fraud vector. Rejects only with UNKNOWN_ORDER. An order is reversed at most once: refund and an order-tied clawback share a reversed:<orderId> claim, so a second reversal of the same order returns the recorded transaction as duplicate, as does a retry under the same idempotencyKey.

    Type Declaration

      • (
            fields: FieldsOf<K>,
        ): {
            actor: Principal;
            idempotencyKey: string;
            kind: "refund";
            orderId: string;
            reason?: string;
        }
      • Parameters

        • fields: FieldsOf<K>

        Returns {
            actor: Principal;
            idempotencyKey: string;
            kind: "refund";
            orderId: string;
            reason?: string;
        }

    const outcome = await economy.submit(refund({
    idempotencyKey: idempotencyKey('refund', 'ord_8821'),
    actor: systemActor('support'),
    orderId: 'ord_8821',
    reason: 'buyer request',
    }));