import { s as PaymentGatewayAdapter } from "../payment.adapter-BOT9T6jQ.js"; //#region src/adapters/moyasar.adapter.d.ts interface MoyasarConfig { /** Secret API key (sk_live_xxx or sk_test_xxx) */ secretKey: string; /** Publishable API key for frontend (pk_live_xxx or pk_test_xxx) */ publishableKey: string; /** Webhook secret for signature verification */ webhookSecret?: string; /** Default callback URL after 3DS verification */ callbackUrl: string; /** API base URL (defaults to production) */ apiUrl?: string; } /** Moyasar payment status */ type MoyasarPaymentStatus = "initiated" | "paid" | "failed" | "authorized" | "captured" | "refunded" | "voided"; /** Moyasar token status */ type MoyasarTokenStatus = "initiated" | "verified" | "failed"; /** Response from Moyasar payments API */ interface MoyasarPayment { id: string; status: MoyasarPaymentStatus; amount: number; fee: number; currency: string; refunded: number; captured: number; description?: string; callback_url?: string; invoice_id?: string; ip?: string; created_at: string; updated_at: string; metadata?: Record; source: { type: string; token?: string; transaction_url?: string; message?: string; gateway_id?: string; response_code?: string; name?: string; last_four?: string; brand?: string; }; } /** Response from Moyasar tokens API */ interface MoyasarToken { id: string; status: MoyasarTokenStatus; brand: string; funding: string; country: string; month: string; year: string; name: string; last_four: string; verification_url?: string; metadata?: Record; message?: string; created_at: string; updated_at: string; } /** Moyasar webhook payload */ interface MoyasarWebhookPayload { id: string; type: "payment.created" | "payment.updated" | "payment.paid" | "payment.failed"; data: MoyasarPayment; created_at: string; } /** Moyasar API error types */ type MoyasarErrorType = "invalid_request_error" | "authentication_error" | "rate_limit_error" | "api_connection_error" | "account_inactive_error" | "api_error" | "3ds_auth_error"; /** HTTP status codes used by Moyasar */ type MoyasarHttpStatus = 200 | 400 | 401 | 403 | 404 | 405 | 429 | 500 | 503; /** Gateway response codes (2-digit codes from acquirer) */ type MoyasarGatewayResponseCode = "00" | "01" | "02" | "03" | "04" | "05" | "06" | "07" | "08" | "09" | "10" | "11" | "12" | "13" | "14" | "15" | "16" | "19" | "21" | "22" | "23" | "25" | "30" | "31" | "33" | "34" | "35" | "36" | "37" | "38" | "39" | "40" | "41" | "42" | "43" | "44" | "51" | "52" | "53" | "54" | "55" | "56" | "57" | "59" | "60" | "61" | "62" | "63" | "64" | "65" | "66" | "67" | "75" | "79" | "82" | "90" | "91" | "92" | "93" | "94" | "96"; /** Error response from Moyasar API */ interface MoyasarErrorResponse { type: MoyasarErrorType; message: string | null; errors?: Record; } /** Payment declined error codes and their descriptions */ interface PaymentErrorInfo { code: string; message: string; isRetryable: boolean; userAction: "use_different_card" | "retry_later" | "contact_bank" | "check_details" | "none"; } /** * Comprehensive Moyasar adapter error with user-friendly messages */ declare class MoyasarAdapterError extends Error { readonly type: MoyasarErrorType | "http_error" | "payment_declined" | "network_error"; readonly code: string; readonly httpStatus?: number | undefined; readonly userMessage?: string | undefined; readonly isRetryable: boolean; readonly userAction: PaymentErrorInfo["userAction"]; readonly fieldErrors?: Record | undefined; constructor(message: string, type?: MoyasarErrorType | "http_error" | "payment_declined" | "network_error", code?: string, httpStatus?: number | undefined, userMessage?: string | undefined, isRetryable?: boolean, userAction?: PaymentErrorInfo["userAction"], fieldErrors?: Record | undefined); /** Create from HTTP response */ static fromHttpResponse(status: number, errorResponse?: MoyasarErrorResponse): MoyasarAdapterError; /** Create from payment source message (bank decline, 3DS failure, etc.) */ static fromPaymentMessage(message: string, paymentId?: string): MoyasarAdapterError; /** Create from gateway response code */ static fromGatewayCode(code: string): MoyasarAdapterError; } /** Helper to extract error info from a payment response */ declare function getPaymentErrorInfo(payment: MoyasarPayment): PaymentErrorInfo | null; /** * Create a Moyasar payment adapter for subscriptions. * * **Important**: Moyasar doesn't have native subscription support. * This adapter uses token-based recurring payments: * * 1. Frontend collects card → creates token via Moyasar.js * 2. Token stored as `gatewayCustomerId` in subscription * 3. Renewal job charges token using `createSubscription()` method * 4. Webhook confirms payment → subscription renewed * * @example * ```typescript * import { moyasarAdapter } from '@abshahin/subscriptions/adapters/moyasar'; * * const payment = moyasarAdapter({ * secretKey: process.env.MOYASAR_LIVE_SECRET_KEY!, * publishableKey: process.env.MOYASAR_LIVE_PUBLIC_KEY!, * callbackUrl: 'https://platform.example.com/subscriptions/callback', * }); * ``` */ declare function moyasarAdapter(config: MoyasarConfig): PaymentGatewayAdapter; /** * Charge a saved token for subscription renewal. * Use this in your renewal cron job. * * @example * ```typescript * import { chargeToken } from '@abshahin/subscriptions/adapters/moyasar'; * * // In your renewal cron job: * const result = await chargeToken({ * secretKey: process.env.MOYASAR_LIVE_SECRET_KEY!, * tokenId: subscription.gatewayCustomerId!, * amount: plan.price * 100, // Convert to smallest unit * description: `Renewal for ${subscription.tenantId}`, * callbackUrl: 'https://platform.example.com/subscriptions/callback', * metadata: { tenantId: subscription.tenantId, planId: subscription.planId }, * }); * ``` */ declare function chargeToken(params: { secretKey: string; tokenId: string; amount: number; currency?: string; description?: string; callbackUrl: string; metadata?: Record; }): Promise; //#endregion export { MoyasarAdapterError, MoyasarConfig, MoyasarErrorResponse, MoyasarErrorType, MoyasarGatewayResponseCode, MoyasarHttpStatus, MoyasarPayment, MoyasarPaymentStatus, MoyasarToken, MoyasarTokenStatus, MoyasarWebhookPayload, PaymentErrorInfo, chargeToken, getPaymentErrorInfo, moyasarAdapter }; //# sourceMappingURL=moyasar.adapter.d.ts.map