Skip to main content

Usage

const {
  data,
  isLoading,
  isError,
  isSuccess,
  error,
  refetch,
  fetchSkuPurchase,
} = useGetSkuPurchase({
  id: "purchase-id",
  getBearerToken: getToken,
});

Input Parameters

ParameterTypeRequiredDescription
idstringYesThe purchase transaction ID
getBearerToken() => Promise<string>YesFunction returning the auth token
queryOptionsUseQueryOptionsNoReact Query options (e.g. staleTime, enabled)

Return Value

PropertyTypeDescription
dataTransaction | undefinedThe purchase record
isLoadingbooleanTrue while fetching
isErrorbooleanTrue if an error occurred
isSuccessbooleanTrue if the query succeeded
errorError | nullError details
refetch() => voidRe-run the query
fetchSkuPurchase(input) => Promise<Transaction>Imperatively fetch a purchase by ID

Example Implementation

import { useGetSkuPurchase } from "@chipi-stack/chipi-react";
import { useAuth } from "@clerk/nextjs";

export function PurchaseStatus({ purchaseId }: { purchaseId: string }) {
  const { getToken } = useAuth();

  const { data: purchase, isLoading, error } = useGetSkuPurchase({
    id: purchaseId,
    getBearerToken: getToken,
  });

  if (isLoading) return <p>Loading purchase...</p>;
  if (error) return <p>Error: {error.message}</p>;
  if (!purchase) return <p>Purchase not found</p>;

  return (
    <div>
      <p>Transaction: {purchase.id}</p>
      <p>Status: {purchase.status}</p>
      <p>Amount: {purchase.amount}</p>
    </div>
  );
}
  • usePurchaseSku — Create the purchase in the first place
  • useGetSkuList — Browse available SKUs