## Overview

Authorization and capture is a two-step process for processing payments. This approach is ideal for businesses that need to verify availability of funds before actually charging the customer, such as for pre-orders or hotel reservations.

## Two-step process

1. **Authorization:** Reservepay verifies that the customer has sufficient funds and places a hold on the amount. The funds are not yet transferred to your account.
2. **Capture:** You confirm the transaction and the funds are officially transferred from the customer to your account.

## How to use authorization and capture

To use this two-step process, you must set the `capture` parameter to `false` when initiating a payment flow.

### Step 1: Authorize a payment

When calling the `merchants/initiate-payment-flow` endpoint, set `capture: false`.

```ts
await fetch('https://api.reservepay.com/merchants/initiate-payment-flow', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Api-Version': '2025-04-01',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    amount: '10000',
    currency: 'THB',
    payment_session_id: 'sess_1234567890',
    capture: false, // Set to false for authorization only
    return_url: 'https://example.com/return'
  })
})
```

Once the customer completes the payment flow, the payment status will transition to `AUTHORIZED`.

### Step 2: Capture the payment

To complete the transaction and transfer the funds, call the `merchants/capture-payment` endpoint with the `payment_id`.

```ts
await fetch('https://api.reservepay.com/merchants/capture-payment', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Api-Version': '2025-04-01',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    payment_id: 'pay_1234567890'
  })
})
```

## Releasing an authorization

If you decide not to proceed with the transaction, you should release the hold on the customer's funds by reversing the authorization. Use the `merchants/reverse-payment` endpoint for this purpose.

## Important considerations

- **Expiration:** Authorizations typically expire after a certain period (e.g., 7 days). If you don't capture the payment before it expires, the hold will be released automatically.
