import { FastifyPluginAsync, FastifyRequest, FastifyReply } from 'fastify'; /** * 通知處理器介面。 */ interface NotifyHandlerInterface { /** * 驗證通知資料。 */ verify(data: NotifyRawData): boolean; /** * 取得解密後的資料。 */ getData(): Record; /** * 是否成功。 */ isSuccess(): boolean; /** * 取得狀態。 */ getStatus(): string; /** * 取得訊息。 */ getMessage(): string; } /** * 原始通知資料。 */ interface NotifyRawData { Status?: string; MerchantID?: string; TradeInfo?: string; TradeSha?: string; Version?: string; [key: string]: unknown; } /** * 支付結果資料。 */ interface PaymentResultData { MerchantID?: string; MerchantOrderNo?: string; TradeNo?: string; Amt?: number; PaymentType?: string; PayTime?: string; IP?: string; PayBankCode?: string; /** 信用卡授權碼 */ Auth?: string; /** 卡號末四碼 */ Card4No?: string; /** 卡號前六碼 */ Card6No?: string; /** ECI 值 */ ECI?: string; /** 分期期數 */ Inst?: number; /** 首期金額 */ InstFirst?: number; /** 每期金額 */ InstEach?: number; [key: string]: unknown; } /** * ATM 取號結果資料。 */ interface AtmResultData { MerchantID?: string; MerchantOrderNo?: string; TradeNo?: string; Amt?: number; BankCode?: string; CodeNo?: string; ExpireDate?: string; ExpireTime?: string; [key: string]: unknown; } /** * 超商取號結果資料。 */ interface CvsResultData { MerchantID?: string; MerchantOrderNo?: string; TradeNo?: string; Amt?: number; PaymentType?: string; CodeNo?: string; StoreType?: string; ExpireDate?: string; ExpireTime?: string; /** 條碼第一段 */ Barcode_1?: string; /** 條碼第二段 */ Barcode_2?: string; /** 條碼第三段 */ Barcode_3?: string; [key: string]: unknown; } /** * 超商取貨付款結果資料。 */ interface CvscomResultData { MerchantID?: string; MerchantOrderNo?: string; TradeNo?: string; Amt?: number; PaymentType?: string; StoreType?: string; StoreCode?: string; StoreName?: string; StoreAddr?: string; TradeType?: number; CVSCOMName?: string; CVSCOMPhone?: string; LgsNo?: string; LgsType?: string; [key: string]: unknown; } /** * 支付完成通知處理器。 * * 處理藍新金流 ReturnURL / NotifyURL 回傳的支付結果通知。 */ declare class PaymentNotify implements NotifyHandlerInterface { private readonly aesEncoder; private readonly checkValueEncoder; /** * 原始通知資料。 */ private rawData; /** * 解密後的交易資料。 */ private data; /** * 是否已驗證。 */ private verified; /** * 建立通知處理器。 * * @param hashKey HashKey * @param hashIV HashIV */ constructor(hashKey: string, hashIV: string); /** * 從設定建立通知處理器。 */ static create(hashKey: string, hashIV: string): PaymentNotify; /** * 驗證通知資料。 */ verify(data: NotifyRawData): boolean; /** * 驗證並拋出例外。 */ verifyOrFail(data: NotifyRawData): this; /** * 解析解密後的資料。 */ private parseDecryptedData; /** * 取得解密後的資料。 */ getData(): Record; /** * 取得原始通知資料。 */ getRawData(): NotifyRawData; /** * 是否成功。 */ isSuccess(): boolean; /** * 取得狀態。 */ getStatus(): string; /** * 取得訊息。 */ getMessage(): string; /** * 取得特店編號。 */ getMerchantID(): string; /** * 取得特店訂單編號。 */ getMerchantOrderNo(): string; /** * 取得藍新金流交易序號。 */ getTradeNo(): string; /** * 取得交易金額。 */ getAmt(): number; /** * 取得支付方式。 */ getPaymentType(): string; /** * 取得交易時間。 */ getPayTime(): string; /** * 取得 IP 位址。 */ getIP(): string; /** * 取得付款銀行。 */ getPayBankCode(): string; /** * 取得授權碼(信用卡)。 */ getAuthCode(): string; /** * 取得卡號末四碼(信用卡)。 */ getCard4No(): string; /** * 取得卡號前六碼(信用卡)。 */ getCard6No(): string; /** * 取得 ECI 值(3D 驗證)。 */ getECI(): string; /** * 取得分期期數。 */ getInst(): number; /** * 取得首期金額。 */ getInstFirst(): number; /** * 取得每期金額。 */ getInstEach(): number; /** * 取得交易結果物件。 */ getResult(): PaymentResultData; /** * 是否已驗證。 */ isVerified(): boolean; } /** * ATM 取號通知處理器。 * * 處理 ATM 虛擬帳號取號完成的通知。 */ declare class AtmNotify implements NotifyHandlerInterface { private readonly aesEncoder; private readonly checkValueEncoder; /** * 原始通知資料。 */ private rawData; /** * 解密後的交易資料。 */ private data; /** * 是否已驗證。 */ private verified; /** * 建立通知處理器。 */ constructor(hashKey: string, hashIV: string); /** * 從設定建立通知處理器。 */ static create(hashKey: string, hashIV: string): AtmNotify; /** * 驗證通知資料。 */ verify(data: NotifyRawData): boolean; /** * 驗證並拋出例外。 */ verifyOrFail(data: NotifyRawData): this; /** * 解析解密後的資料。 */ private parseDecryptedData; /** * 取得解密後的資料。 */ getData(): Record; /** * 取得原始通知資料。 */ getRawData(): NotifyRawData; /** * 是否成功。 */ isSuccess(): boolean; /** * 取得狀態。 */ getStatus(): string; /** * 取得訊息。 */ getMessage(): string; /** * 取得特店訂單編號。 */ getMerchantOrderNo(): string; /** * 取得藍新金流交易序號。 */ getTradeNo(): string; /** * 取得交易金額。 */ getAmt(): number; /** * 取得銀行代碼。 */ getBankCode(): string; /** * 取得虛擬帳號。 */ getCodeNo(): string; /** * 取得繳費截止日。 */ getExpireDate(): string; /** * 取得繳費截止時間。 */ getExpireTime(): string; /** * 取得交易結果物件。 */ getResult(): AtmResultData; /** * 是否已驗證。 */ isVerified(): boolean; } /** * 超商取號通知處理器。 * * 處理超商代碼/條碼繳費取號完成的通知。 */ declare class CvsNotify implements NotifyHandlerInterface { private readonly aesEncoder; private readonly checkValueEncoder; /** * 原始通知資料。 */ private rawData; /** * 解密後的交易資料。 */ private data; /** * 是否已驗證。 */ private verified; /** * 建立通知處理器。 */ constructor(hashKey: string, hashIV: string); /** * 從設定建立通知處理器。 */ static create(hashKey: string, hashIV: string): CvsNotify; /** * 驗證通知資料。 */ verify(data: NotifyRawData): boolean; /** * 驗證並拋出例外。 */ verifyOrFail(data: NotifyRawData): this; /** * 解析解密後的資料。 */ private parseDecryptedData; /** * 取得解密後的資料。 */ getData(): Record; /** * 取得原始通知資料。 */ getRawData(): NotifyRawData; /** * 是否成功。 */ isSuccess(): boolean; /** * 取得狀態。 */ getStatus(): string; /** * 取得訊息。 */ getMessage(): string; /** * 取得特店訂單編號。 */ getMerchantOrderNo(): string; /** * 取得藍新金流交易序號。 */ getTradeNo(): string; /** * 取得交易金額。 */ getAmt(): number; /** * 取得支付方式。 */ getPaymentType(): string; /** * 取得繳費代碼。 */ getCodeNo(): string; /** * 取得超商類型。 */ getStoreType(): string; /** * 取得繳費截止日。 */ getExpireDate(): string; /** * 取得繳費截止時間。 */ getExpireTime(): string; /** * 取得條碼第一段。 */ getBarcode1(): string; /** * 取得條碼第二段。 */ getBarcode2(): string; /** * 取得條碼第三段。 */ getBarcode3(): string; /** * 取得交易結果物件。 */ getResult(): CvsResultData; /** * 是否已驗證。 */ isVerified(): boolean; } /** * 超商取貨付款通知處理器。 * * 處理超商取貨付款的通知。 */ declare class CvscomNotify implements NotifyHandlerInterface { private readonly aesEncoder; private readonly checkValueEncoder; /** * 原始通知資料。 */ private rawData; /** * 解密後的交易資料。 */ private data; /** * 是否已驗證。 */ private verified; /** * 建立通知處理器。 */ constructor(hashKey: string, hashIV: string); /** * 從設定建立通知處理器。 */ static create(hashKey: string, hashIV: string): CvscomNotify; /** * 驗證通知資料。 */ verify(data: NotifyRawData): boolean; /** * 驗證並拋出例外。 */ verifyOrFail(data: NotifyRawData): this; /** * 解析解密後的資料。 */ private parseDecryptedData; /** * 取得解密後的資料。 */ getData(): Record; /** * 取得原始通知資料。 */ getRawData(): NotifyRawData; /** * 是否成功。 */ isSuccess(): boolean; /** * 取得狀態。 */ getStatus(): string; /** * 取得訊息。 */ getMessage(): string; /** * 取得特店訂單編號。 */ getMerchantOrderNo(): string; /** * 取得藍新金流交易序號。 */ getTradeNo(): string; /** * 取得交易金額。 */ getAmt(): number; /** * 取得支付方式。 */ getPaymentType(): string; /** * 取得超商類型。 */ getStoreType(): string; /** * 取得門市代碼。 */ getStoreCode(): string; /** * 取得門市名稱。 */ getStoreName(): string; /** * 取得門市地址。 */ getStoreAddr(): string; /** * 取得取貨人姓名。 */ getCVSCOMName(): string; /** * 取得取貨人電話。 */ getCVSCOMPhone(): string; /** * 取得物流編號。 */ getLgsNo(): string; /** * 取得物流類型。 */ getLgsType(): string; /** * 取得交易結果物件。 */ getResult(): CvscomResultData; /** * 是否已驗證。 */ isVerified(): boolean; } /** * 藍新金流設定介面 */ interface NewebPayConfig { merchantId: string; hashKey: string; hashIV: string; testMode?: boolean; returnUrl?: string; notifyUrl?: string; customerUrl?: string; clientBackUrl?: string; } declare module 'fastify' { interface FastifyRequest { newebpayNotify?: PaymentNotify | AtmNotify | CvsNotify | CvscomNotify; } } declare const newebpayPlugin: FastifyPluginAsync; declare const paymentNotifyPreHandler: (config: NewebPayConfig) => (req: FastifyRequest, _reply: FastifyReply) => Promise; declare const atmNotifyPreHandler: (config: NewebPayConfig) => (req: FastifyRequest, _reply: FastifyReply) => Promise; declare const cvsNotifyPreHandler: (config: NewebPayConfig) => (req: FastifyRequest, _reply: FastifyReply) => Promise; declare const cvscomNotifyPreHandler: (config: NewebPayConfig) => (req: FastifyRequest, _reply: FastifyReply) => Promise; export { atmNotifyPreHandler, cvsNotifyPreHandler, cvscomNotifyPreHandler, newebpayPlugin, paymentNotifyPreHandler };