//#region src/adapters/payment.adapter.d.ts /** * Gateway customer representation */ interface GatewayCustomer { id: string; email: string; name?: string; metadata?: Record; } /** * Gateway subscription representation */ interface GatewaySubscription { id: string; customerId: string; status: string; priceId?: string; currentPeriodStart: Date; currentPeriodEnd: Date; cancelAt: Date | null; canceledAt: Date | null; trialStart: Date | null; trialEnd: Date | null; metadata?: Record; } /** * Checkout session for payment */ interface CheckoutSession { id: string; url: string; expiresAt: Date; } /** * Customer portal session */ interface PortalSession { id: string; url: string; } /** * Webhook event from payment gateway */ interface WebhookEvent { id: string; type: string; data: Record; createdAt: Date; } /** * Input for creating a customer */ interface CreateCustomerInput { email: string; name?: string; metadata?: Record; } /** * Input for creating a gateway subscription */ interface CreateGatewaySubscriptionInput { customerId: string; priceId: string; trialDays?: number; metadata?: Record; } /** * Input for updating a gateway subscription */ interface UpdateGatewaySubscriptionInput { priceId?: string; cancelAtPeriodEnd?: boolean; metadata?: Record; } /** * Options for canceling a subscription */ interface CancelOptions { /** * Cancel immediately or at period end * @default false (cancel at period end) */ immediately?: boolean; /** * Reason for cancellation */ reason?: string; } /** * Input for creating a checkout session */ interface CreateCheckoutInput { customerId?: string; customerEmail?: string; priceId: string; successUrl: string; cancelUrl: string; trialDays?: number; metadata?: Record; } /** * Input for charging a one-time payment */ interface ChargePaymentInput { /** Customer/token ID to charge */ customerId: string; /** Amount in smallest currency unit (e.g., cents, halalas) */ amount: number; /** Currency code (e.g., 'USD', 'SAR') */ currency: string; /** Payment description */ description?: string; /** Callback URL for 3DS verification */ callbackUrl?: string; /** Additional metadata */ metadata?: Record; } /** * Result of a payment charge */ interface ChargePaymentResult { /** Payment ID from gateway */ id: string; /** Payment status */ status: 'paid' | 'pending' | 'failed'; /** Amount charged */ amount: number; /** Currency */ currency: string; /** URL for 3DS verification (if pending) */ verificationUrl?: string; /** Error message if failed */ errorMessage?: string; /** Machine-readable error code */ errorCode?: string; /** Whether the error is retryable */ isRetryable?: boolean; /** Suggested user action */ userAction?: 'use_different_card' | 'retry_later' | 'contact_bank' | 'check_details' | 'none'; /** Gateway-specific response code */ gatewayCode?: string; /** HTTP status if applicable */ httpStatus?: number; } /** * Payment gateway adapter interface * * Implement this interface to integrate with payment providers like Stripe, Paddle, etc. * This is optional - you can manage subscriptions manually without a payment gateway. */ interface PaymentGatewayAdapter { /** * Provider name for logging and identification */ readonly provider: string; /** * Create a customer in the payment gateway */ createCustomer(data: CreateCustomerInput): Promise; /** * Get a customer by ID */ getCustomer(customerId: string): Promise; /** * Update customer details */ updateCustomer?(customerId: string, data: Partial): Promise; /** * Create a subscription in the payment gateway */ createSubscription(data: CreateGatewaySubscriptionInput): Promise; /** * Get a subscription by ID */ getSubscription(subscriptionId: string): Promise; /** * Update a subscription (e.g., change plan) */ updateSubscription(subscriptionId: string, data: UpdateGatewaySubscriptionInput): Promise; /** * Cancel a subscription */ cancelSubscription(subscriptionId: string, options?: CancelOptions): Promise; /** * Pause a subscription (if supported) */ pauseSubscription?(subscriptionId: string): Promise; /** * Resume a paused subscription */ resumeSubscription?(subscriptionId: string): Promise; /** * Create a checkout session for new subscriptions */ createCheckoutSession(data: CreateCheckoutInput): Promise; /** * Create a customer portal session for managing billing */ createPortalSession(customerId: string, returnUrl: string): Promise; /** * Charge a one-time payment (for upgrades, renewals, etc.) * This uses a saved token/customer ID to charge directly. */ chargePayment?(data: ChargePaymentInput): Promise; /** * Get the reusable payment source from a completed payment. * Use this to save the payment method for future renewals. * @param paymentId - The payment ID from gateway * @returns Token/source ID that can be reused, or null if not applicable */ getPaymentSource?(paymentId: string): Promise; /** * Construct and verify a webhook event * @param payload - Raw webhook payload * @param signature - Webhook signature header */ constructWebhookEvent(payload: string | Uint8Array, signature: string): Promise; } /** * No-op payment adapter for manual subscription management */ declare const noopPaymentAdapter: PaymentGatewayAdapter; //#endregion export { GatewayCustomer as a, PortalSession as c, CheckoutSession as i, WebhookEvent as l, ChargePaymentInput as n, GatewaySubscription as o, ChargePaymentResult as r, PaymentGatewayAdapter as s, CancelOptions as t, noopPaymentAdapter as u }; //# sourceMappingURL=payment.adapter-BOT9T6jQ.d.ts.map