@cedros/pay-react
Version:
React frontend library for Cedros Pay - unified Stripe and Solana x402 payments
138 lines • 4.54 kB
TypeScript
import { WalletAdapter } from '@solana/wallet-adapter-base';
import { CartItem } from './index';
/**
* Payment method types (extensible)
*/
export type PaymentMethod = 'stripe' | 'crypto';
/**
* Future payment methods (for type-safe extensibility)
*/
export type FuturePaymentMethod = PaymentMethod | 'ach' | 'sepa' | 'bank-transfer';
/**
* Payment success result (extensible for future data)
*/
export interface PaymentSuccessResult {
transactionId: string;
method: PaymentMethod;
timestamp?: number;
}
/**
* Payment error (extensible for future error details)
*/
export interface PaymentErrorDetail {
message: string;
code?: string;
method?: PaymentMethod;
}
/**
* Checkout-related options
* Handles customer info, coupons, redirects, and FUTURE: subscriptions, currency
*/
export interface CheckoutOptions {
/** Customer email for receipts and Stripe checkout */
customerEmail?: string;
/** Coupon code for discounts (works with both Stripe and x402) */
couponCode?: string;
/** Stripe redirect URL on successful payment */
successUrl?: string;
/** Stripe redirect URL on cancelled payment */
cancelUrl?: string;
/** Metadata for tracking (e.g., userId, sessionId, orderId) */
metadata?: Record<string, string>;
}
/**
* Display/UI-related options
* Handles labels, visibility, layout, and FUTURE: payment method selection
*/
export interface DisplayOptions {
/** Label for card payment button */
cardLabel?: string;
/** Label for crypto payment button */
cryptoLabel?: string;
/** Label for unified purchase button */
purchaseLabel?: string;
/** Show card payment option */
showCard?: boolean;
/** Show crypto payment option */
showCrypto?: boolean;
/** Show unified purchase button instead of separate buttons */
showPurchaseButton?: boolean;
/** Layout direction for dual payment buttons */
layout?: 'vertical' | 'horizontal';
/** Hide inline success/error messages */
hideMessages?: boolean;
/** Custom CSS class name */
className?: string;
/**
* Custom modal renderer for purchase button
* Note: Uses simplified callback signatures (string-based) for internal consistency with PurchaseButton
*/
renderModal?: (props: {
isOpen: boolean;
onClose: () => void;
resource?: string;
items?: CartItem[];
cardLabel?: string;
cryptoLabel?: string;
showCard?: boolean;
showCrypto?: boolean;
onPaymentAttempt?: (method: PaymentMethod) => void;
onPaymentSuccess?: (txId: string) => void;
onPaymentError?: (error: string) => void;
customerEmail?: string;
successUrl?: string;
cancelUrl?: string;
metadata?: Record<string, string>;
couponCode?: string;
testPageUrl?: string;
hideMessages?: boolean;
}) => React.ReactNode;
}
/**
* Props passed to custom modal renderer
*/
export interface ModalRenderProps {
isOpen: boolean;
onClose: () => void;
resource?: string;
items?: CartItem[];
cardLabel?: string;
cryptoLabel?: string;
showCard?: boolean;
showCrypto?: boolean;
onPaymentAttempt?: (method: PaymentMethod) => void;
onPaymentSuccess?: (result: PaymentSuccessResult) => void;
onPaymentError?: (error: PaymentErrorDetail) => void;
customerEmail?: string;
successUrl?: string;
cancelUrl?: string;
metadata?: Record<string, string>;
couponCode?: string;
testPageUrl?: string;
hideMessages?: boolean;
}
/**
* Callback/event handler options
* Handles payment lifecycle events, and FUTURE: checkout lifecycle hooks
*/
export interface CallbackOptions {
/** Called when user initiates payment (for analytics) */
onPaymentAttempt?: (method: PaymentMethod) => void;
/** Called on successful payment */
onPaymentSuccess?: (result: PaymentSuccessResult) => void;
/** Called on payment error */
onPaymentError?: (error: PaymentErrorDetail) => void;
}
/**
* Advanced/power-user options
* Handles wallet config, testing, and FUTURE: custom validation, fee calculation
*/
export interface AdvancedOptions {
/** Custom wallet adapters (overrides default pool) */
wallets?: WalletAdapter[];
/** Auto-detect wallets and skip modal if none found */
autoDetectWallets?: boolean;
/** URL to open for crypto testing (e.g., Storybook test page) */
testPageUrl?: string;
}
//# sourceMappingURL=componentOptions.d.ts.map