@cedros/pay-react
Version:
React frontend library for Cedros Pay - unified Stripe and Solana x402 payments
110 lines • 3.64 kB
TypeScript
import { StripeSessionRequest, StripeSessionResponse, PaymentResult } from '../types';
import { RouteDiscoveryManager } from './RouteDiscoveryManager';
import { NormalizedCartItem } from '../utils/cartHelpers';
/**
* Options for processing a cart checkout
*/
export interface ProcessCartCheckoutOptions {
items: NormalizedCartItem[];
successUrl?: string;
cancelUrl?: string;
metadata?: Record<string, string>;
customerEmail?: string;
couponCode?: string;
}
/**
* Public interface for Stripe payment management.
*
* Use this interface for type annotations instead of the concrete StripeManager class.
* This allows internal implementation changes without breaking your code.
*
* @example
* ```tsx
* function MyComponent() {
* const { stripeManager } = useCedrosContext();
* // stripeManager is typed as IStripeManager
* await stripeManager.createSession({ resource: 'item-1' });
* }
* ```
*/
export interface IStripeManager {
/**
* Initialize Stripe.js library
*/
initialize(): Promise<void>;
/**
* Create a Stripe checkout session for a single item
*/
createSession(request: StripeSessionRequest): Promise<StripeSessionResponse>;
/**
* Redirect to Stripe checkout page
*/
redirectToCheckout(sessionId: string): Promise<PaymentResult>;
/**
* Complete payment flow: create session and redirect
*/
processPayment(request: StripeSessionRequest): Promise<PaymentResult>;
/**
* Create a Stripe cart checkout session for multiple items
*/
processCartCheckout(options: ProcessCartCheckoutOptions): Promise<PaymentResult>;
}
/**
* Internal implementation of Stripe payment management.
*
* @internal
* **DO NOT USE THIS CLASS DIRECTLY**
*
* This concrete class is not part of the stable API and may change without notice.
* Constructor signatures, method signatures, and internal implementation details
* are subject to change in any release (including patch releases).
*
* **Correct Usage:**
* ```typescript
* import { useCedrosContext } from '@cedros/pay-react';
*
* function MyComponent() {
* const { stripeManager } = useCedrosContext();
* // stripeManager is typed as IStripeManager (stable interface)
* await stripeManager.processPayment({ ... });
* }
* ```
*
* **Incorrect Usage (WILL BREAK):**
* ```typescript
* import { StripeManager } from '@cedros/pay-react'; // ❌ Not exported
* const manager = new StripeManager(...); // ❌ Unsupported
* ```
*
* @see {@link IStripeManager} for the stable interface
* @see API_STABILITY.md for our API stability policy
*/
export declare class StripeManager implements IStripeManager {
private stripe;
private readonly publicKey;
private readonly routeDiscovery;
private readonly rateLimiter;
private readonly circuitBreaker;
constructor(publicKey: string, routeDiscovery: RouteDiscoveryManager);
/**
* Initialize Stripe.js library
*/
initialize(): Promise<void>;
/**
* Create a Stripe checkout session
*/
createSession(request: StripeSessionRequest): Promise<StripeSessionResponse>;
/**
* Redirect to Stripe checkout
*/
redirectToCheckout(sessionId: string): Promise<PaymentResult>;
/**
* Handle complete payment flow: create session and redirect
*/
processPayment(request: StripeSessionRequest): Promise<PaymentResult>;
/**
* Create a Stripe cart checkout session for multiple items
*/
processCartCheckout(options: ProcessCartCheckoutOptions): Promise<PaymentResult>;
}
//# sourceMappingURL=StripeManager.d.ts.map