# Purchase

One-time payment with automatic capture. The payment is captured immediately when the customer completes the checkout.

## Use cases

- E-commerce checkout
- One-time purchases
- Digital goods
- Immediate fulfilment

## Steps

### 1. Create payment intent — `POST /payments`

Create a payment intent on your server with capture_method set to 'automatic'. This returns a client_secret for the SDK.

Request body:

```json
{
  "amount": 6500,
  "currency": "ZAR",
  "confirm": false,
  "description": "Test payment from Interactive Docs",
  "return_url": "https://example.com/flows/simple-purchase?status=complete",
  "is_iframe_redirection_enabled": true,
  "billing": {
    "address": {
      "line1": "123 Main Street",
      "line2": "Apartment 4B",
      "city": "Cape Town",
      "state": "Western Cape",
      "zip": "8001",
      "country": "ZA",
      "first_name": "John",
      "last_name": "Doe"
    },
    "phone": {
      "number": "821234567",
      "country_code": "+27"
    },
    "email": "john.doe@example.com"
  },
  "shipping": {
    "address": {
      "line1": "456 Delivery Road",
      "line2": "Unit 7",
      "city": "Cape Town",
      "state": "Western Cape",
      "zip": "8001",
      "country": "ZA",
      "first_name": "John",
      "last_name": "Doe"
    },
    "phone": {
      "number": "821234567",
      "country_code": "+27"
    },
    "email": "john.doe@example.com"
  },
  "capture_method": "automatic",
  "authentication_type": "no_three_ds"
}
```

### 2. Mount SDK

Initialise the Orchestration SDK with the client_secret and mount the UnifiedCheckout component.

### 3. Customer pays

Customer enters payment details and clicks Pay. The SDK handles the payment confirmation.

### 4. Handle result

Check the payment status and display success or error message to the customer.

## Response

Payment endpoints return the payment object. Key fields to read:

- `payment_id` — the payment identifier.
- `status` — current payment status (see the state transitions below).
- `client_secret` — pass to the SDK to complete the payment client-side.
- `next_action` — present when a redirect or 3-D Secure challenge is required.

## Key parameters

- capture_method: 'automatic'
- Single-step capture

## Flow diagram

```mermaid
flowchart LR
    A[Create Payment] --> B[Mount SDK]
    B --> C[Customer Pays]
    C --> D{Payment Result}
    D -->|Success| E[Order Complete]
    D -->|Failed| F[Show Error]
```

## Payment state transitions

```mermaid
stateDiagram-v2
    [*] --> requires_payment_method: Create Payment
    requires_payment_method --> processing: Customer Submits
    processing --> succeeded: Payment Captured
    processing --> failed: Payment Failed
    succeeded --> [*]
    failed --> requires_payment_method: Retry
```

---

Interactive version: https://playground.peachpayments.com/flows/simple-purchase
