Skip to main content

SDK API Reference for React

Latest Version

v2.7.14 - Complete TypeScript documentation

Framework

React SDK - Hooks-based API for React 18+
Complete API documentation for all hooks, components, and utilities in the TagadaPay Plugin SDK v2.
React is Required: This API reference covers the React-based TagadaPay Plugin SDK v2 (@tagadapay/plugin-sdk/v2). All hooks and components require React 18+. For V1 docs, see the legacy documentation.

Quick Navigation

Query Hooks

TanStack Query hooks for data fetching

Mutation Hooks

Hooks for data updates

Utility Hooks

Helper hooks for common tasks

Payment Hooks

Payment processing and 3DS

Location Hooks

Address and geolocation

Components

Reusable React components

Installation & Setup

Provider Setup

Wrap your app with TagadaProvider:

Query Hooks

useCheckout()

Fetch and manage checkout data with automatic caching.
Returns:
  • data: Checkout object with all checkout data
  • isLoading: Boolean loading state
  • error: Error object if request failed
  • refetch(): Function to manually refetch data
  • isFetching: Boolean indicating background refetch
Checkout Data Structure:

useProducts()

Fetch product catalog with automatic caching.
Returns:
  • data: Array of product objects
  • isLoading: Loading state
  • error: Error state
  • refetch(): Manual refetch function

useOffer()

Deprecated. Use usePreviewOffer() instead. useOffer (aliased from useOfferQuery) still works but is no longer the recommended hook for upsell pages. usePreviewOffer skips the upfront checkout-session round-trip, recomputes pricing client-side, and applies the CRM-configured MIT/CIT payment initiator automatically. useOffer will be removed in a future major version.
Single-offer hook that initializes a checkout session up front, exposes a payOffer() mutation, and returns offer + line-item state. Kept exported as useOffer (aliasing useOfferQuery) for backwards compatibility.
New code should use usePreviewOffer() instead — same single-offer shape, lighter footprint, automatic MIT/CIT pickup.

usePreviewOffer()

Lightweight offer preview hook for post-checkout upsell pages. Fetches an offer with a precomputed summary, lets the customer pick variants and quantities, and recomputes totals client-side without round-tripping to the backend on every change. Pay once the customer accepts.
Options Returns MIT vs CIT auto-pickup pay() looks up stepConfig.paymentInitiator from the runtime window.__TGD_STEP_CONFIG__ injection and applies it automatically:
  • paymentInitiator: 'merchant' (default) → MIT, sent to Stripe as off_session: true. No 3DS challenge, higher conversion.
  • paymentInitiator: 'customer'CIT, sent as setup_future_usage: 'off_session'. May trigger 3DS — useful when MITs are being declined by the issuer.
Merchants flip the toggle from the CRM step config; no plugin code change is required. To override per call, pass { initiatedBy }:
OffersResource.payOffer() and OffersResource.payWithCheckoutSession() use the same auto-pickup. All three paths share getAssignedPaymentInitiator() under the hood.

usePromotions()

Fetch active promotions and campaigns.

useDiscounts()

Manage discount codes and validation.

useOrder()

Fetch order details.

useOrderBump()

Manage upsell offers (order bumps).

useStoreConfig()

Access store configuration and settings.

useShippingRates()

Fetch available shipping options.

usePostPurchases()

Fetch post-purchase offers.

useVipOffers()

Fetch VIP exclusive offers.

useClubOffers()

Manage subscription/club offers.

useCustomerOrders()

Fetch customer order history.

useCustomerSubscriptions()

Manage customer subscriptions.

Mutation Hooks

useCheckout()

Manage checkout sessions with create, update, and payment capabilities.
Parameters:
  • checkoutToken: String - Existing checkout token, or empty string to create new
Returns:
  • checkout: Checkout session object
  • init(): Function to create a new checkout session with line items
  • updateLineItems(): Function to update cart items
  • updateCustomerAndSessionInfo(): Function to update customer/shipping info
  • error: Error object if any operation fails
Creating a checkout from scratch? See the complete Initialize Checkout guide for detailed examples including BOGO funnels, bundle selectors, and static resources.

usePayment()

Process payments with automatic state management.

usePaymentPolling()

Poll payment status for async payments.

Utility Hooks

useAuth()

Manage authentication and user sessions.
Returns:
  • user: Current user object
  • isAuthenticated: Boolean auth state
  • login(): Login function
  • logout(): Logout function
  • isLoading: Auth check in progress

useCustomer()

Access customer profile data.

useCustomerInfos()

Manage customer information and validation.

useCredits()

Manage store credit and balance.

useFunnel()

Navigate and track funnel steps.

useCheckoutToken()

Manage checkout session tokens.

useCurrency()

Format money and handle currency conversions.
formatMoney Options:

useGeoLocation()

Detect user’s geographic location.

usePluginConfig()

Access plugin-specific configuration.

useTranslation()

Internationalization and localization.

useApiClient()

Direct access to API client for custom requests.

useApiQuery()

Create custom API queries with TanStack Query.

Payment Hooks

useThreeds()

Handle 3D Secure authentication.

useThreedsModal()

Manage 3DS modal display.

useExpressPaymentMethods()

Integrate Apple Pay and Google Pay.

Location Hooks

useGoogleAutocomplete()

Address autocomplete with Google Places API.

useISOData()

Access country and region data.

Components

ApplePayButton

Pre-styled Apple Pay button component.

GooglePayButton

Pre-styled Google Pay button component.

DebugDrawer

Development helper for debugging plugin state.

Path Remapping Functions

Path Remapping Guide

See the complete path remapping guide for detailed examples, testing, and advanced patterns

matchRoute()

New in v2.7.14 Check if the current URL matches an internal path pattern AND extract URL parameters. Signature:
Parameters:
  • internalPath - Your plugin’s internal path pattern (e.g., /checkout, /product/:id)
Returns:
  • matched - true if the current URL matches the internal path (considering remapping)
  • params - Object containing extracted URL parameters
Example 1: Basic Usage
Example 2: Parameter Extraction
Example 3: Multiple Parameters
Example 4: Conditional Rendering

shouldMatchRoute()

Check if the current URL matches an internal path pattern (without parameter extraction).
Tip: Use matchRoute() instead if you need URL parameters. shouldMatchRoute() only returns a boolean.
Signature:
Parameters:
  • internalPath - Your plugin’s internal path pattern
Returns:
  • boolean - true if the current URL matches
Example:
When to use:
  • ✅ Simple route matching without parameters
  • ✅ Conditional rendering based on route
  • ✅ Route guards and redirects
When to use matchRoute() instead:
  • ✅ When you need URL parameters
  • ✅ When passing params to child components

getPathInfo()

Get detailed information about the current path and remapping status. Signature:
Returns:
  • PathInfo object with detailed path information
Example 1: Debug Panel
Example 2: SEO Canonical URL
Example 3: Analytics Tracking
Example 4: Conditional Feature Display

getInternalPath()

Get the current internal path, or null if no remapping is active. Signature:
Returns:
  • string - Internal path if remapping is active
  • null - If no remapping is active
Example 1: Simple Check
Example 2: Conditional Logic
When to use:
  • ✅ Quick remapping status check
  • ✅ Logging and debugging
  • ✅ Conditional behavior based on remapping
When to use getPathInfo() instead:
  • ✅ Need both external and internal paths
  • ✅ Need query parameters or hash
  • ✅ Building debug UI

Path Remapping Types

RouteMatchResult

Example Usage:

PathInfo

Example:

Path Remapping Best Practices

Never parse window.location directly! Always use SDK functions to ensure remapping works correctly.

✅ Good Practices

❌ Bad Practices


Complete Path Remapping Guide

See the complete guide for configuration, testing, troubleshooting, and advanced patterns

TypeScript Types

The SDK exports comprehensive TypeScript types:

Best Practices

1. Always Use V2 for New Projects

2. Handle Loading and Error States

3. Use TanStack Query Features

4. Combine Multiple Hooks

Support