> ## 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.

# Authorization decision

> Handle real-time card transaction authorization decisions with PGP encryption using the UQPAY Node.js SDK.

Authorization decision lets you approve or decline card transactions in real time. UQPAY sends a PGP-encrypted transaction payload to your endpoint. You decrypt it, make a decision, and return an encrypted response.

The SDK handles all PGP encryption and decryption. You only write the business logic.

## Generate a PGP key pair

Generate a key pair and send the public key to UQPAY. Store the private key securely.

```ts theme={null}
import { generateAuthDecisionKeyPair } from '@uqpay/sdk'

const { publicKey, privateKey } = await generateAuthDecisionKeyPair({
  name: 'Acme Corp',
  email: 'issuing.tech@acme.com',
})
```

## Configure PGP keys

After creating the client, configure the PGP keys once. You can pass file paths (`.asc`, `.pgp`, `.gpg`) or armored key strings:

```ts theme={null}
await client.issuing.authDecision.configure({
  privateKey: './keys/my-private.asc',
  uqpayPublicKey: './keys/uqpay-public.asc',
  passphrase: process.env.PGP_PASSPHRASE, // optional
})
```

## Create the handler

Use `createHandler` to build an Express-compatible request handler. You only need to implement the `decide` callback:

```ts theme={null}
const handler = client.issuing.authDecision.createHandler({
  decide: async (transaction) => {
    // transaction contains: billing_amount, merchant_name, card_id, etc.
    if (transaction.billing_amount > 10000) {
      return { response_code: '51' } // Insufficient Funds
    }
    return { response_code: '00', partner_reference_id: 'ref-001' }
  },
  onError: (err) => console.error('Auth decision error:', err),
})

app.post('/auth-decision', handler)
```

The SDK automatically injects `transaction_id` into the response and handles all PGP encryption and decryption.

## How it works

```mermaid theme={null}
sequenceDiagram
    participant UQPAY
    participant Your Server
    UQPAY->>Your Server: PGP-encrypted transaction
    Your Server->>Your Server: SDK decrypts payload
    Your Server->>Your Server: decide() returns response_code
    Your Server->>Your Server: SDK encrypts response
    Your Server->>UQPAY: PGP-encrypted decision
```
