Hooks
usePayment
Description
A hook that provides payment modal controls and real-time payment intent status. It handles the complete payment flow from modal interactions to transaction monitoring.
Usage
| Name | Type | Description |
|---|---|---|
| openPaymentModal | function(params: {fiat_amount: string, fiat_currency: 'TWD' | 'USD', callback_url?: string, order_data?: Record<string, any>, group_key?: string} | {payment_intent_id: string}) | Opens the payment modal. Can either start a new payment process or resume an existing one using a payment_intent_id. |
| closePaymentModal | function(): void | Closes the payment modal and cancels the ongoing payment process. |
| data | { payment_intent_id: string; payment_chain_id: string; payment_address: string; token_address: string; symbol: string; decimals: number; crypto_amount: string; fiat_amount: string; fiat_currency: 'TWD' | 'USD'; payment_deadline: number; status: PaymentStatus; payment_tx_hash: string | null; received_crypto_amount: string | null; aggregated_crypto_amount: string | null; refund_amount: string | null; refund_tx_hash: string | null; callback_url: string | null; order_data: Record<string, any> | null; group_key: string | null; } | undefined | The details of the current payment, including its status and metadata. For detailed field descriptions, please refer to the Payment Intent Fields section. |
| txHash | string | undefined | The transaction hash of the current payment. |
| error | Error | undefined | The error of the current payment. |
| isLoading | boolean | Indicates whether the payment process is in progress (e.g., waiting for user action or blockchain confirmation). |
| isSuccess | boolean | Indicates whether the payment was successfully completed. |
| isError | boolean | Indicates whether the payment has failed. |
The callback_url is optional. If provided, a notification will be sent to the specified callback endpoint when the payment status changes. Your server can then record the payment information for further processing.
The fiat_amount must be at least 0.01. Values less than 0.01 will be rejected.
When using order_data, you can include any order-related information (up to 1000 characters when marshalled), and your server will receive this information at your configured callback endpoint. (if provided)
The group_key parameter is optional and can be used to classify payment intents, making it easier to filter them in the KryptoGO Studio or via the API.
Example
const {
openPaymentModal,
closePaymentModal,
data,
txHash,
error,
isLoading,
isSuccess,
isError
} = usePayment();
// Start a new payment
<Button onClick={() => openPaymentModal({
fiat_amount: '10',
fiat_currency: 'TWD',
callback_url: 'https://{{endpoint-to-server}}',
order_data: {
order_product_id: '1234567890',
order_product_name: 'Good Thing',
},
group_key: 'product_purchase'
})}>
Open Payment Modal
</Button>
// Resume an existing payment
<Button onClick={() => openPaymentModal({
payment_intent_id: 'pi_xxxxxxxxxxxx'
})}>
Resume Payment
</Button>useSolanaWallet
Description
A hook for the Solana wallet that the payment modal connects. The SDK discovers Solana wallets through the Wallet Standard , so any installed wallet that registers itself (such as Phantom or OKX Wallet) appears in wallets. The hook works inside KryptogoKitProvider.
Earlier SDK versions re-exported every @solana/wallet-adapter-react API (useWallet, useConnection, WalletProvider, and others). That re-export has been removed. Use useSolanaWallet for the payment modal’s Solana wallet, or depend on your own Solana wallet library.
Usage
| Name | Type | Description |
|---|---|---|
| wallets | SolanaWallet[] | Registered Wallet Standard wallets, plus Phantom and OKX Wallet when they have not registered. Each has name, icon, url, and readyState. |
| wallet | SolanaWallet | null | The selected wallet, connected or not. |
| address | string | null | The base58 address of the connected account. |
| connected | boolean | Whether a Solana account is connected. |
| connecting | boolean | Whether a connection request is in progress. |
| select | function(name: string | null): void | Selects a wallet by name. Selecting another wallet disconnects the current one. |
| connect | function(): Promise<void> | Connects the selected wallet. On iOS Safari, Phantom and OKX Wallet that have not registered open the current page in their in-app browser. |
| disconnect | function(): Promise<void> | Disconnects the wallet and clears the selection. |
readyState is 'Installed' for a registered wallet, 'Loadable' when connect redirects into the wallet app, and 'NotDetected' when connect opens the wallet’s download page.
Example
const { address, connected, disconnect } = useSolanaWallet();
{connected && <Button onClick={() => disconnect()}>Disconnect {address}</Button>}