/** * Stripe Integration for WORKWAY * * Enables payment processing workflows: * - Payment intents and charges * - Customer management * - Subscription lifecycle * - Webhook event parsing * * Implements the SDK patterns: * - ActionResult narrow waist for output * - IntegrationError narrow waist for errors * - StandardData for normalized data * * @example * ```typescript * import { Stripe } from '@workwayco/integrations/stripe'; * * const stripe = new Stripe({ secretKey: env.STRIPE_SECRET_KEY }); * * // Create a payment intent * const payment = await stripe.createPaymentIntent({ * amount: 2000, // $20.00 * currency: 'usd', * customer: 'cus_xxx' * }); * * // List recent payments * const payments = await stripe.listPayments({ limit: 10 }); * * // Create a subscription * const subscription = await stripe.createSubscription({ * customer: 'cus_xxx', * priceId: 'price_xxx' * }); * ``` */ import { ActionResult } from '@workwayco/sdk'; import { BaseAPIClient } from '../core/base-client.js'; /** * Stripe integration configuration */ export interface StripeConfig { /** Stripe secret key (sk_live_xxx or sk_test_xxx) */ secretKey: string; /** Optional: Override API endpoint (for testing) */ apiUrl?: string; /** Optional: API version (default: 2023-10-16) */ apiVersion?: string; /** Request timeout in milliseconds (default: 30000) */ timeout?: number; } /** * Stripe Payment Intent */ export interface StripePaymentIntent { id: string; object: 'payment_intent'; amount: number; amount_received: number; currency: string; status: 'requires_payment_method' | 'requires_confirmation' | 'requires_action' | 'processing' | 'requires_capture' | 'canceled' | 'succeeded'; customer: string | null; description: string | null; metadata: Record; created: number; client_secret: string; payment_method: string | null; receipt_email: string | null; } /** * Stripe Customer */ export interface StripeCustomer { id: string; object: 'customer'; email: string | null; name: string | null; phone: string | null; description: string | null; metadata: Record; created: number; balance: number; currency: string | null; default_source: string | null; delinquent: boolean; } /** * Stripe Subscription */ export interface StripeSubscription { id: string; object: 'subscription'; customer: string; status: 'incomplete' | 'incomplete_expired' | 'trialing' | 'active' | 'past_due' | 'canceled' | 'unpaid' | 'paused'; current_period_start: number; current_period_end: number; cancel_at_period_end: boolean; canceled_at: number | null; created: number; metadata: Record; items: { data: Array<{ id: string; price: { id: string; product: string; unit_amount: number | null; currency: string; recurring: { interval: 'day' | 'week' | 'month' | 'year'; interval_count: number; } | null; }; quantity: number; }>; }; } /** * Stripe Charge */ export interface StripeCharge { id: string; object: 'charge'; amount: number; amount_refunded: number; currency: string; status: 'succeeded' | 'pending' | 'failed'; customer: string | null; description: string | null; metadata: Record; created: number; paid: boolean; refunded: boolean; receipt_url: string | null; payment_intent: string | null; } /** * Stripe Webhook Event */ export interface StripeWebhookEvent { id: string; object: 'event'; type: string; data: { object: Record; previous_attributes?: Record; }; created: number; livemode: boolean; api_version: string; } /** * Stripe List Response */ export interface StripeList { object: 'list'; data: T[]; has_more: boolean; url: string; } export interface CreatePaymentIntentOptions { /** Amount in cents */ amount: number; /** Three-letter ISO currency code */ currency: string; /** Customer ID */ customer?: string; /** Description */ description?: string; /** Metadata */ metadata?: Record; /** Receipt email */ receipt_email?: string; /** Automatic payment methods */ automatic_payment_methods?: { enabled: boolean; }; } export interface ListPaymentsOptions { /** Maximum number of results (default: 10, max: 100) */ limit?: number; /** Pagination cursor */ starting_after?: string; /** Filter by customer */ customer?: string; /** Filter by creation date (Unix timestamp) */ created?: { gte?: number; lte?: number; }; } export interface CreateCustomerOptions { /** Customer email */ email?: string; /** Customer name */ name?: string; /** Customer phone */ phone?: string; /** Description */ description?: string; /** Metadata */ metadata?: Record; /** Payment method to attach */ payment_method?: string; } export interface CreateSubscriptionOptions { /** Customer ID */ customer: string; /** Price ID */ priceId: string; /** Quantity (default: 1) */ quantity?: number; /** Trial period days */ trial_period_days?: number; /** Metadata */ metadata?: Record; /** Cancel at period end */ cancel_at_period_end?: boolean; } export interface ListSubscriptionsOptions { /** Maximum number of results (default: 10, max: 100) */ limit?: number; /** Pagination cursor */ starting_after?: string; /** Filter by customer */ customer?: string; /** Filter by status */ status?: 'active' | 'past_due' | 'canceled' | 'all'; } /** * Stripe Integration * * Implements the WORKWAY SDK patterns for Stripe API access. * Extends BaseAPIClient for standardized HTTP handling. * * Note: Stripe uses form-urlencoded content type, not JSON. * We override stripeRequest() to handle this difference. */ export declare class Stripe extends BaseAPIClient { private readonly apiVersion; constructor(config: StripeConfig); /** * Stripe-specific request method that uses form-urlencoded content type * and includes the Stripe-Version header. */ private stripeRequest; /** * Create a payment intent */ createPaymentIntent(options: CreatePaymentIntentOptions): Promise>; /** * Retrieve a payment intent */ getPaymentIntent(id: string): Promise>; /** * List payment intents */ listPaymentIntents(options?: ListPaymentsOptions): Promise>>; /** * Create a customer */ createCustomer(options?: CreateCustomerOptions): Promise>; /** * Retrieve a customer */ getCustomer(id: string): Promise>; /** * List customers */ listCustomers(options?: { limit?: number; starting_after?: string; email?: string; }): Promise>>; /** * Create a subscription */ createSubscription(options: CreateSubscriptionOptions): Promise>; /** * Retrieve a subscription */ getSubscription(id: string): Promise>; /** * Cancel a subscription */ cancelSubscription(id: string, options?: { cancel_at_period_end?: boolean; }): Promise>; /** * List subscriptions */ listSubscriptions(options?: ListSubscriptionsOptions): Promise>>; /** * List charges */ listCharges(options?: ListPaymentsOptions): Promise>>; /** * Retrieve a charge */ getCharge(id: string): Promise>; /** * Parse and verify a webhook event * * @param payload - Raw request body * @param signature - Stripe-Signature header * @param webhookSecret - Webhook endpoint secret */ parseWebhookEvent(payload: string, signature: string, webhookSecret: string): Promise>; /** * Get capabilities for Stripe actions */ private getCapabilities; /** * Extract rate limit information from response headers * Stripe uses standard rate limit headers */ private extractRateLimit; /** * Handle Stripe API errors */ private handleStripeError; /** * Map Stripe error types to ErrorCode */ private mapStripeError; /** * Handle general errors */ private handleError; } //# sourceMappingURL=index.d.ts.map