跳转到主要内容

Documentation Index

Fetch the complete documentation index at: https://developers-sandbox.uqpaytech.com/llms.txt

Use this file to discover all available pages before exploring further.

授权决策允许你实时批准或拒绝卡交易。UQPAY 会向你的端点发送 PGP 加密的交易通知体,你解密后做出决策,再返回加密响应。 SDK 处理所有 PGP 加解密,你只需写业务逻辑。

生成 PGP 密钥对

生成密钥对,将公钥发给 UQPAY,私钥安全保存:
import { generateAuthDecisionKeyPair } from '@uqpay/sdk'

const { publicKey, privateKey } = await generateAuthDecisionKeyPair({
  name: 'Acme Corp',
  email: '[email protected]',
})

配置 PGP 密钥

创建 client 后,一次性配置 PGP 密钥。可传文件路径(.asc.pgp.gpg)或密钥 ASCII 字符串:
await client.issuing.authDecision.configure({
  privateKey: './keys/my-private.asc',
  uqpayPublicKey: './keys/uqpay-public.asc',
  passphrase: process.env.PGP_PASSPHRASE, // 可选
})

创建处理器

createHandler 构造一个兼容 Express 的请求处理器,你只需实现 decide 回调:
const handler = client.issuing.authDecision.createHandler({
  decide: async (transaction) => {
    // transaction 中包含 billing_amount、merchant_name、card_id 等字段
    if (transaction.billing_amount > 10000) {
      return { response_code: '51' } // 余额不足
    }
    return { response_code: '00', partner_reference_id: 'ref-001' }
  },
  onError: (err) => console.error('Auth decision error:', err),
})

app.post('/auth-decision', handler)
SDK 会自动把 transaction_id 注入响应,并完成所有 PGP 加解密。

工作原理