Checkout
Cometh ConnectCometh MarketplaceCometh Checkout
  • 🚀QUICKSTART
    • What is Checkout?
    • Prepare your collection
    • Create a Checkout project
    • Setup Checkout project
    • Integrate your Checkout button
  • Features
    • Per user price or return urls
  • 🔌Integrations
    • Purchase link
    • React
  • 📖RESOURCES
    • Supported chains/cryptos
    • USDC smart contracts
    • Transactions status
Powered by GitBook
On this page
  1. Integrations

React

PreviousPurchase linkNextSupported chains/cryptos

Last updated 7 months ago

The provides a component and some hooks to easily integrate Cometh Checkout inside your React app. You can use it to easily launch Cometh Checkout in a iFrame, popup or seperate tab, and handle processing the transaction after the payment.

Install

npm i @cometh/checkout-sdk-react

or

yarn install @cometh/checkout-sdk-react

Basic Usage

1. Initialize SDK

import {useCheckout} from '@cometh/checkout-sdk-react'

const {startCheckout, success, error} = useCheckout(apiKey)

By default the Checkout process will be displayed as a popup. To change this, use the appropriate display option:

const {startCheckout, success, error} = useCheckout(apiKey, {
    display: 'tab' // 'tab', 'iframe' or 'popup' (default)
})

2. Start checkout flow

const productId = '1'
const user = {
    walletAddress: '0x1234567890',
    email: 'test@email.com'
}

await startCheckout(productId, user)

3. Handle Results

import {useEffect} from "react";

useEffect(() => {
    if (success) {
        console.log('checkout success', success)
    }
    if (error) {
        console.log('checkout error', error)
    }
}, [success, error]);
🔌
React library