Capxul Docs
HooksPayments

useCapxulCancelPayment

Mutation hook for cancelling a payment by id — a published stub that is not yet implemented in the current alpha.

Cancels a payment by id. Pair it with useCapxulPayment to read the payment's status before and after.

Not yet implemented

In the published alpha, client.payments.cancel is a stub: every call fails with a NOT_IMPLEMENTED CapxulError ("payments.cancel is not yet implemented"). The hook and its types are published so UI can be wired ahead of the implementation, but no payment can be cancelled through this surface today. See Capability status.

Import

import { useCapxulCancelPayment } from "@capxul/sdk-react";

Usage

"use client";

import { useCapxulCancelPayment } from "@capxul/sdk-react";

function CancelButton({ paymentId }: { paymentId: string }) {
  const cancelPayment = useCapxulCancelPayment();

  return (
    <div>
      <button
        disabled={cancelPayment.isPending}
        onClick={() => cancelPayment.mutate(paymentId)}
      >
        Cancel payment
      </button>
      {cancelPayment.error ? <p>{cancelPayment.error.message}</p> : null}
    </div>
  );
}

Parameters

The hook itself takes no parameters. The mutation takes the payment id:

paymentId

string

The id of the payment to cancel, as returned by useCapxulPay or listed by useCapxulPayments.

Return type

import { type UseCapxulCancelPaymentReturn } from "@capxul/sdk-react";
// UseMutationResult<Payment, CapxulError, string>

On success, data will be the updated Payment. In the current alpha the mutation never succeeds (see the callout above).

The hook returns TanStack Query's UseMutationResult. The most-used fields:

FieldDescription
mutateFire the mutation (fire-and-forget; pair with onSuccess/onError callbacks).
mutateAsyncFire the mutation and get a Promise of the result. Rejects with a CapxulError on failure.
dataThe mutation result (typed per hook, shown above). undefined until the first success.
errorA CapxulError when the last attempt failed, otherwise null.
isPendingtrue while the mutation is in flight. Use it to disable submit buttons.
resetClear the mutation state (data, error) back to idle.

Mutations do not retry by default. The full field list is in the TanStack Query useMutation reference; see also the TanStack Query integration guide.

Cache behavior

On success this mutation refreshes the personal money state: the payments list (and payment detail queries under it), the personal account balance, and the personal insights summary and history. Until the client method is implemented, onSuccess is unreachable and nothing is invalidated.

Errors

Every call currently fails with NOT_IMPLEMENTED — surfaced as a CapxulError on error / thrown from mutateAsync.

Client method

This hook wraps client.payments.cancel(paymentId) on the core SDK.

On this page