# PCI Subscription Creation Endpoint

{% hint style="success" %}
The PCI flow is available only to merchants who have achieved PCI compliance and can securely handle credit card information.
{% endhint %}

#### Endpoint

<mark style="color:orange;background-color:orange;">**POST**</mark> `https://cc-api-stg.directa24.com/v3/subscriptions`

#### Process

1. Merchant collects payment details directly from customer
2. Merchant submits complete subscription request including credit card data
3. System processes payment and creates subscription immediately
4. API returns subscription confirmation directly in the response

<details>

<summary>Request Example</summary>

```json
{
  "invoice_id": "INV123456",
  "amount": 70.00,
  "currency": "BRL",
  "country": "BR",
  "payer": {
    "id": "PAYER123",
    "document": "123456789",
    "document_type": "CPF",
    "email": "customer@example.com",
    "first_name": "John",
    "last_name": "Doe"
  },
  "description": "Premium Subscription",
  "subscription": {
    "start_date": "2025-01-01",
    "plan": "MONTHLY",
    "plan_unit": 1,
    "auto_renewal": false
  },
  "credit_card": {
    "cvv": "123",
    "card_number": "4111111111111111",
    "expiration_month": "12",
    "expiration_year": "25",
    "holder_name": "John Doe"
  },
  "client_ip": "192.168.1.1",
  "back_url": "https://example.com/back",
  "success_url": "https://example.com/success",
  "error_url": "https://example.com/error",
  "notification_url": "https://example.com/notify"
}
```

</details>

{% openapi src="<https://1770394879-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnTyHI84quh3WRqHk04Z4%2Fuploads%2FV9wb6l7QhVZcgL07UX5J%2Fpci-subs-creation-v3.yml?alt=media&token=ad924011-334b-432a-b32d-36e6706ce457>" path="/v3/subscriptions" method="post" %}
[pci-subs-creation-v3.yml](https://1770394879-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnTyHI84quh3WRqHk04Z4%2Fuploads%2FV9wb6l7QhVZcgL07UX5J%2Fpci-subs-creation-v3.yml?alt=media\&token=ad924011-334b-432a-b32d-36e6706ce457)
{% endopenapi %}

### Successful Response Structure

<table><thead><tr><th>Field</th><th width="121.640625">Type</th><th>Description</th><th>Example</th></tr></thead><tbody><tr><td><code>subscription_id</code></td><td>Integer</td><td>Unique identifier of the created subscription</td><td>1234</td></tr></tbody></table>

**Example response**

```json
{
  "subscription_id": 358
}
```

### Error Response Structure

<table><thead><tr><th>Field</th><th width="128.3515625">Type</th><th>Description</th><th>Example</th></tr></thead><tbody><tr><td><code>code</code></td><td>Integer</td><td>Error code indicating the type of error</td><td>400</td></tr><tr><td><code>description</code></td><td>String</td><td>Human-readable description of the error</td><td>"Invalid input data"</td></tr><tr><td><code>type</code></td><td>String</td><td>Machine-readable error type identifier</td><td>"VALIDATION_ERROR"</td></tr></tbody></table>

#### Bad Request - Invalid input data

```json
{
  "code": 400,
  "description": "Invalid input data",
  "type": "VALIDATION_ERROR"
}
```

#### Unprocessable Entity - Validation error

```json
{
  "code": 422,
  "description": "Validation error",
  "type": "VALIDATION_ERROR"
}
```

#### Service Unavailable - Error creating subscription

```json
{
  "code": 503,
  "description": "Error creating subscription",
  "type": "SERVICE_ERROR"
}
```

### Subscription Plans

The following subscription frequencies are supported:

| Plan       | Description                   |
| ---------- | ----------------------------- |
| `DAILY`    | Recurring billing every day   |
| `WEEKLY`   | Recurring billing every week  |
| `MONTHLY`  | Recurring billing every month |
| `ANNUALLY` | Recurring billing every year  |

{% hint style="success" %}

### Tests in STG Environment.

To test the Subscriptions API in the staging environment, use the parameter `plan` with the value `TEST` inside the `subscription[]` object when calling either the OneShot or PCI endpoints.

This triggers simulated deposits **every minute**, along with the corresponding webhook events, so you can quickly verify the full subscription lifecycle.\
The number of deposits generated depends on the value of the `plan_unit` parameter, making it easy to observe the expected behavior in just a few minutes.
{% endhint %}
