# Payment Processing API

## Overview

The Payment Processing API allows developers to integrate payment processing functionality into their applications, including creating payments, retrieving payment details, and managing refunds.

## Base URL

```
https://api.paymentprocessing.com/v1
```

## Authentication

This API uses API keys for authentication. Include your API key in the Authorization header for each request.

## Endpoints

### POST /payments

**Description**: Creates a new payment.

**Request Headers**:

```
Content-Type: application/json
Authorization: Bearer <your_api_key>
```

**Request Body**:

```json
{
  "amount": 100.00,
  "currency": "USD",
  "source": "tok_visa",
  "description": "Payment for order #12345"
}
```

**Response**:

* **Success (201 Created)**:

  ```json
  {
    "id": "pay_12345",
    "amount": 100.00,
    "currency": "USD",
    "status": "succeeded",
    "created_at": "2024-06-10T12:00:00Z"
  }
  ```
* **Error (400 Bad Request)**:

  ```json
  {
    "error": "Invalid payment source"
  }
  ```

### GET /payments/{id}

**Description**: Retrieves the details of a specific payment by ID.

**Request Headers**:

```
Authorization: Bearer <your_api_key>
```

**Request Parameters**:

* `id` (path parameter): The unique ID of the payment.

**Response**:

* **Success (200 OK)**:

  ```json
  {
    "id": "pay_12345",
    "amount": 100.00,
    "currency": "USD",
    "status": "succeeded",
    "created_at": "2024-06-10T12:00:00Z"
  }
  ```
* **Error (404 Not Found)**:

  ```json
  {
    "error": "Payment not found"
  }
  ```

### POST /refunds

**Description**: Creates a refund for a specific payment.

**Request Headers**:

```
Content-Type: application/json
Authorization: Bearer <your_api_key>
```

**Request Body**:

```json
{
  "payment_id": "pay_12345",
  "amount": 50.00
}
```

**Response**:

* **Success (201 Created)**:

  ```json
  {
    "id": "refund_67890",
    "payment_id": "pay_12345",
    "amount": 50.00,
    "status": "succeeded",
    "created_at": "2024-06-10T13:00:00Z"
  }
  ```
* **Error (400 Bad Request)**:

  ```json
  {
    "error": "Invalid refund amount"
  }
  ```

## Example Code Snippets

### Creating a Payment (Python)

```python
import requests

url = "https://api.paymentprocessing.com/v1/payments"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <your_api_key>"
}
data = {
    "amount": 100.00,
    "currency": "USD",
    "source": "tok_visa",
    "description": "Payment for order #12345"
}

response = requests.post(url, json=data, headers=headers)
print(response.json())
```

### Retrieving a Payment (JavaScript)

```javascript
const fetch = require('node-fetch');

const url = 'https://api.paymentprocessing.com/v1/payments/pay_12345';
const options = {
  method: 'GET',
  headers: {
    'Authorization': 'Bearer <your_api_key>'
  }
};

fetch(url, options)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));
```
