# ABA PayWay Pre-Authorization

Create pre-authorization transactions to temporarily hold funds before final charge.

## Features

- ✅ Temporary fund holds without immediate charge
- ✅ Support for ABA PAY, KHQR, and Cards
- ✅ Flexible completion with adjusted amounts (cards)
- ✅ Auto-expiration after 30 days
- ✅ Optional payout distribution on completion

## Quick Start

```typescript
import { generatePurchaseHash, generateReqTime, generateTransactionId, encodeItems } from 'aba-payway-sdk/utils';

// Backend: Generate pre-auth form parameters
const formParams = {
  req_time: generateReqTime(),
  merchant_id: 'ec000002',
  tran_id: generateTransactionId(),
  amount: 200.00,
  currency: 'USD',
  type: 'pre-auth', // 👈 Key difference
  firstname: 'John',
  lastname: 'Doe',
  email: 'john@example.com',
  phone: '012345678',
  items: encodeItems([{ name: 'Hotel Reservation', quantity: 1, price: 200.00 }]),
  return_url: Buffer.from('https://yourapp.com/return').toString('base64'),
  hash: ''
};

formParams.hash = generatePurchaseHash(formParams, apiKey);

// Later: Complete the pre-auth
const result = await client.completePreAuth({
  tranId: 'TRAN-12345',
  completeAmount: 200.00,
  rsaPublicKey: process.env.PAYWAY_RSA_PUBLIC_KEY
});
```

## Documentation

- **[SKILL.md](./SKILL.md)** - Complete usage guide
- **[EXAMPLES.md](./EXAMPLES.md)** - Code examples for all scenarios
- **[REFERENCE.md](./REFERENCE.md)** - Full API reference

## Use Cases

- Hotel reservations
- Car rentals
- Gas stations
- Variable shipping costs
- Service deposits
- Marketplaces with variable pricing

## Transaction Flow

1. **Create Pre-Auth** - Hold funds (type: 'pre-auth')
2. **Complete** - Charge customer (within 30 days)
3. **Cancel** - Release hold (optional)

## Requirements

- RSA Public Key (for complete/cancel operations)
- 30-day action window before auto-cancellation

## Support

- Email: payway@ababank.com
- Telegram: @payway_aba
- Hotline: 023 225 333 / 087 225 333
