> ## Documentation Index
> Fetch the complete documentation index at: https://developers.uqpay.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 授权决策

> 使用 Python SDK 处理 PGP 加密的卡授权决策。

授权决策让你的集成能够实时批准或拒绝卡交易。SDK会解密UQPAY发送的请求、调用你的决策函数，并加密响应。

实现处理器前，请阅读[授权决策流程、前置条件、响应码和超时要求](/zh/card-issuance/v1.6/guide/authorization-decisions)。

```python theme={null}
from uqpay.crypto import generate_auth_decision_key_pair

# Generate a key pair once and store securely
keys = generate_auth_decision_key_pair(name="MyApp", email="ops@example.com")

# Configure at startup
client.issuing.auth_decision.configure(
    private_key=keys["private_key"],
    uqpay_public_key="<UQPAY public key from dashboard>",
)

# Define your decision function
def decide(transaction: dict) -> dict:
    if transaction.get("amount", 0) > 10000:
        return {"response_code": "05"}  # Decline
    return {"response_code": "00", "partner_reference_id": "ref-001"}

# In your HTTP handler:
encrypted_response = client.issuing.auth_decision.handle(
    body=request.get_data(),
    headers=dict(request.headers),
    decide=decide,
)
```

请将私钥和passphrase保存在secret manager或环境变量中，切勿提交到源码仓库。
