import { Env } from './config/Env'; import type { TapPayConfig } from './config/TapPayConfig'; import type { BindCardRequest, PayByPrimeRequest, PayByTokenRequest, RecordRequest, RefundRequest } from './payments/PaymentRequest'; import type { BindCardResponse, CapCancelResponse, CapTodayResponse, PaymentResponse, RecordResponse, RefundCancelResponse, RefundResponse, RemoveCardResponse, TradeHistoryResponse } from './payments/PaymentResponse'; /** * TapPay 後端付款客戶端 * * 與 TapPay 後端 API 互動的核心類別。 * 提供付款處理、退款、卡片管理和交易查詢等方法。 * * @example * ```typescript * import { TapPayClient, Env, Currency } from '@carllee1983/tappay-backend-payment-node' * * const client = new TapPayClient({ * partnerKey: 'your_partner_key', * merchantId: 'your_merchant_id', * env: Env.Sandbox * }) * * const response = await client.payByPrime({ * prime: 'prime_from_frontend', * amount: 100, * currency: Currency.TWD, * details: 'Test Payment' * }) * ``` */ export declare class TapPayClient { private readonly config; private readonly paymentService; private readonly transactionService; private readonly cardService; /** * 建立 TapPay 客戶端實例 * * @param config - TapPay 客戶端配置 * @throws {TapPayConfigError} 當配置無效時(例如:缺少必要欄位、timeout 為負數等) * * @example * ```typescript * const client = new TapPayClient({ * partnerKey: 'partner_key_from_portal', * merchantId: 'merchant_id_from_portal', * env: Env.Sandbox, * timeout: 30000 // 30 秒 * }) * ``` */ constructor(config: TapPayConfig); /** * 驗證客戶端配置 * * 檢查必要的配置欄位是否有效,如果無效則拋出 TapPayConfigError。 * * @param config - TapPay 客戶端配置 * @throws {TapPayConfigError} 當配置無效時拋出 * @private */ private validateConfig; /** * 使用 Prime Token 付款 * * 使用前端 SDK 產生的 prime token 進行付款。 * 每個 prime token 只能使用一次,有效期限為 90 秒。 * * @param options - 付款選項(不包含 partner_key 和 merchant_id) * @returns Promise 解析為付款回應 * @throws {TapPayValidationError} 當必要欄位缺失或無效時 * @throws {TapPayError} 當 API 回應錯誤時 * @throws {TapPayTimeoutError} 當請求超時時 * * @example * ```typescript * const response = await client.payByPrime({ * prime: 'test_prime_123', * amount: 100, * currency: Currency.TWD, * details: 'Test Payment', * cardholder: { * phone_number: '+886912345678', * name: 'Test User', * email: 'test@example.com' * } * }) * console.log(response.rec_trade_id) * ``` */ payByPrime(options: Omit): Promise; /** * 使用卡片 Token 付款 * * 使用已儲存的卡片憑證進行付款。 * 需要從之前使用 remember=true 的 Pay by Prime 交易中取得的 card_key 和 card_token。 * * @param options - 付款選項(包含卡片憑證) * @returns Promise 解析為付款回應 * @throws {TapPayValidationError} 當必要欄位缺失或無效時 * @throws {TapPayError} 當 API 回應錯誤時 * @throws {TapPayTimeoutError} 當請求超時時 * * @example * ```typescript * const response = await client.payByToken({ * card_key: 'saved_card_key', * card_token: 'saved_card_token', * amount: 100, * currency: Currency.TWD, * details: 'Recurring Payment' * }) * ``` */ payByToken(options: Omit): Promise; /** * 退款交易 * * 處理全額或部分退款。 * 省略 amount 參數則進行全額退款。 * * @param recTradeId - TapPay 交易 ID * @param options - 可選的退款選項(amount, bank_refund_id) * @returns Promise 解析為退款回應 * @throws {TapPayValidationError} 當交易 ID 無效或退款金額為負數時 * @throws {TapPayError} 當 API 回應錯誤時 * @throws {TapPayTimeoutError} 當請求超時時 * * @example * ```typescript * // 全額退款 * await client.refund('D20231201123456789') * * // 部分退款 * await client.refund('D20231201123456789', { amount: 50 }) * ``` */ refund(recTradeId: string, options?: Omit): Promise; /** * 取消退款 * * 在銀行批次處理前取消待處理的退款。 * 目前僅支援台新銀行。 * * @param recTradeId - TapPay 交易 ID * @param refundId - 要取消的退款 ID * @returns Promise 解析為取消退款回應 * @throws {TapPayValidationError} 當交易 ID 或退款 ID 無效時 * @throws {TapPayError} 當 API 回應錯誤時 * @throws {TapPayTimeoutError} 當請求超時時 * * @example * ```typescript * await client.cancelRefund('D20231201123456789', 'R20231201123456789') * ``` */ cancelRefund(recTradeId: string, refundId: string): Promise; /** * 立即請款(當日) * * 立即請款交易(當日)。 * 用於將延遲請款交易的請款日期改為當日。 * * @param recTradeId - TapPay 交易 ID * @returns Promise 解析為請款回應 * @throws {TapPayValidationError} 當交易 ID 無效時 * @throws {TapPayError} 當 API 回應錯誤時 * @throws {TapPayTimeoutError} 當請求超時時 * * @example * ```typescript * await client.capToday('D20231201123456789') * ``` */ capToday(recTradeId: string): Promise; /** * 取消請款 * * 在銀行批次處理前取消待處理的請款。 * * @param recTradeId - TapPay 交易 ID * @returns Promise 解析為取消請款回應 * @throws {TapPayValidationError} 當交易 ID 無效時 * @throws {TapPayError} 當 API 回應錯誤時 * @throws {TapPayTimeoutError} 當請求超時時 * * @example * ```typescript * await client.cancelCapture('D20231201123456789') * ``` */ cancelCapture(recTradeId: string): Promise; /** * 綁定卡片 * * 綁定卡片以供未來的 token 付款使用。 * 會執行一筆 1 TWD 的測試交易並立即退款。 * * @param options - 綁定卡片選項 * @returns Promise 解析為綁定卡片回應(包含 card_key 和 card_token) * @throws {TapPayValidationError} 當必要欄位缺失或無效時 * @throws {TapPayError} 當 API 回應錯誤時 * @throws {TapPayTimeoutError} 當請求超時時 * * @example * ```typescript * const response = await client.bindCard({ * prime: 'prime_from_frontend', * currency: Currency.TWD, * cardholder: { * phone_number: '+886912345678', * name: 'Test User', * email: 'test@example.com' * } * }) * * if (response.card_secret) { * const { card_key, card_token } = response.card_secret * // 儲存以供未來付款使用 * } * ``` */ bindCard(options: Omit): Promise; /** * 移除綁定的卡片 * * 從 TapPay 伺服器移除已綁定的卡片。 * * @param cardKey - 要移除的卡片 key * @param cardToken - 要移除的卡片 token * @returns Promise 解析為移除卡片回應 * @throws {TapPayValidationError} 當 cardKey 或 cardToken 無效時 * @throws {TapPayError} 當 API 回應錯誤時 * @throws {TapPayTimeoutError} 當請求超時時 * * @example * ```typescript * await client.removeCard('card_key_123', 'card_token_123') * ``` */ removeCard(cardKey: string, cardToken: string): Promise; /** * 查詢交易記錄 * * 使用篩選和分頁功能取得交易記錄。 * 時間範圍篩選限制為 90 天。 * * @param options - 查詢選項(篩選、分頁、排序) * @returns Promise 解析為交易記錄回應 * @throws {TapPayError} 當 API 回應錯誤時 * @throws {TapPayTimeoutError} 當請求超時時 * * @example * ```typescript * const records = await client.getRecords({ * records_per_page: 10, * page: 0, * filters: { * rec_trade_id: 'D20231201123456789' * } * }) * ``` */ getRecords(options?: Omit): Promise; /** * 根據 ID 取得單筆交易 * * 便利方法,用於查詢單筆交易記錄。 * * @param recTradeId - TapPay 交易 ID * @returns Promise 解析為交易記錄,如果找不到則返回 null * @throws {TapPayValidationError} 當交易 ID 無效時 * @throws {TapPayError} 當 API 回應錯誤時 * @throws {TapPayTimeoutError} 當請求超時時 * * @example * ```typescript * const record = await client.getTransaction('D20231201123456789') * if (record) { * console.log(`Status: ${record.status}`) * } * ``` */ getTransaction(recTradeId: string): Promise; /** * 取得交易歷史記錄 * * 取得詳細的交易歷史記錄,包含所有事件(授權、請款、退款等)。 * * @param recTradeId - TapPay 交易 ID * @returns Promise 解析為交易歷史回應 * @throws {TapPayValidationError} 當交易 ID 無效時 * @throws {TapPayError} 當 API 回應錯誤時 * @throws {TapPayTimeoutError} 當請求超時時 * * @example * ```typescript * const history = await client.getTradeHistory('D20231201123456789') * history.trade_history?.forEach(event => { * console.log(`${event.event_type}: ${event.status}`) * }) * ``` */ getTradeHistory(recTradeId: string): Promise; /** * 取得當前環境 * * @returns 當前使用的 TapPay API 環境(Sandbox 或 Production) * @readonly */ get environment(): Env; /** * 檢查是否使用沙盒環境 * * @returns 如果使用沙盒環境則返回 true,否則返回 false * @readonly */ get isSandbox(): boolean; /** * 取得商家 ID * * @returns 商家 ID * @readonly */ get merchantId(): string; } //# sourceMappingURL=TapPayClient.d.ts.map