← ClaudeAtlas

payuni-querylisted

Implements PAYUNi transaction query functionality using Query API. Use when building order status checking, transaction verification, or payment confirmation features for 統一金流.
Oelshafei1/skills · ★ 1 · Web & Frontend · score 80
Install: claude install-skill Oelshafei1/skills
# 統一金流交易查詢任務 你的任務是在用戶的專案中實作統一金流交易查詢功能。 ## Step 1: 確認需求 用戶輸入: `$ARGUMENTS` 詢問用戶: 1. **查詢情境**:需要什麼查詢功能? - 單筆訂單查詢(客戶查詢、客服查詢) - 批次對帳(每日/定時對帳) - 支付狀態確認(NotifyURL 備援) 2. **專案框架**:你使用什麼框架? - 確認是否已有 PAYUNi 環境設定 ## Step 2: 建立查詢功能 在現有的支付模組中加入查詢方法,或建立新模組。 **核心功能:** 1. `generateQueryParams(orderNo)` - 產生查詢參數 2. `queryTrade(orderNo)` - 查詢單筆交易 ## Step 3: 實作程式碼 ### Node.js/TypeScript 範例 ```typescript import crypto from 'crypto'; const config = { merchantId: process.env.PAYUNI_MERCHANT_ID!, hashKey: process.env.PAYUNI_HASH_KEY!, hashIV: process.env.PAYUNI_HASH_IV!, isTest: process.env.PAYUNI_TEST_MODE === 'true', }; function getQueryEndpoint(): string { return config.isTest ? 'https://sandbox-api.payuni.com.tw/api/query' : 'https://api.payuni.com.tw/api/query'; } function encrypt(data: string): string { const key = Buffer.from(config.hashKey.padEnd(32, '\0').slice(0, 32), 'utf8'); const iv = Buffer.from(config.hashIV.padEnd(16, '\0').slice(0, 16), 'utf8'); const cipher = crypto.createCipheriv('aes-256-cbc', key, iv); let encrypted = cipher.update(data, 'utf8', 'hex'); encrypted += cipher.final('hex'); return encrypted; } function generateHashInfo(encryptInfo: string): string { return crypto .createHash('sha256') .update(encryptInfo) .digest('hex') .toUpperCase(); } async function queryTrade(orderNo: string): Promise<{ success: boolean; data?: any; error?: string; }> { try { const queryData = { M