Service for managing Charges within the SDK Provides functionality for creating and configuring charges

Hierarchy (View Summary)

Constructors

Methods

  • Creates a new charge in the Coinbase Commerce platform

    Parameters

    • params: CreateChargeParams

      The charge creation parameters

      • Optionalcancel_url?: string
      • Optionaldescription?: string
      • local_price: { amount: string; currency: string }
      • Optionalmetadata?: Record<string, unknown>
      • Optionalname?: string
      • pricing_type: "fixed_price" | "no_price"
      • Optionalredirect_url?: string

    Returns Promise<APIResponse<ChargeResponse>>

    A promise that resolves to the created charge

    const { data: charge } = await commerce.charges.createCharge({
    pricing_type: 'fixed_price',
    local_price: {
    amount: '100.00',
    currency: 'USD'
    }
    });

    When the API request fails or validation fails

  • Retrieves a specific charge by ID from the Coinbase Commerce platform

    Parameters

    • charge_id: string

      The unique identifier of the charge to retrieve

    Returns Promise<APIResponse<ChargeResponse>>

    A promise that resolves to the charge details

    const { data: charge } = await commerce.charges.getCharge('charge_id_123');
    console.log(charge.data.status);

    When the API request fails or the charge is not found

  • Retrieves a list of charges from the Coinbase Commerce platform

    Parameters

    • Optionalparams: GetChargesParams

      Optional parameters for the list request

      • Optionalending_before?: string
      • Optionallimit?: number
      • Optionalorder?: "asc" | "desc"
      • Optionalstarting_after?: string

    Returns Promise<APIResponse<ChargesResponse>>

    A promise that resolves to a paginated list of charges

    // Get first page of charges
    const { data: charges } = await commerce.charges.getCharges({
    limit: 10,
    order: 'desc'
    });

    // Get next page using cursor
    const nextPage = await commerce.charges.getCharges({
    starting_after: charges.pagination.cursor_range[1]
    });

    When the API request fails or invalid parameters are provided

  • Hydrates an existing charge with Web3 data

    Parameters

    • charge_id: string

      The unique identifier of the charge to hydrate

    • params: HydrateChargeParams

      The hydration parameters

      • chain_id: number
      • sender: string

    Returns Promise<APIResponse<ChargeResponse>>

    A promise that resolves to the hydrated charge

    const { data: hydratedCharge } = await commerce.charges.hydrateCharge(
    'charge_id_123',
    {
    sender: '0x5770D0616b99E89817A8D9BDe61fddc3A941BdF7',
    chain_id: 1
    }
    );

    When the API request fails, the charge is not found, or hydration fails

  • Processes a payment for a charge using Web3

    Parameters

    Returns Promise<PayChargeResponse>

    A promise that resolves to the payment transaction details

    const { data: charge } = await commerce.charges.hydrateCharge('charge_id', {
    sender: walletClient.account.address,
    chain_id: 1
    });

    const paymentResult = await commerce.charges.payCharge({
    charge: charge.data,
    walletClient,
    currency: {
    contractAddress: '0x...' // ERC20 token address
    }
    });

    console.log(`Transaction submitted: ${paymentResult.transactionHash}`);

    With type VALIDATION when:

    • The charge hasn't been hydrated
    • The wallet is not connected
    • There's a chain ID mismatch
    • The payment currency is not supported
    • No commerce contract is found on the chain

    With type UNKNOWN for other transaction-related errors