KosmoKrator

payments

PayPal Lua API for KosmoKrator Agents

Agent-facing Lua documentation and function reference for the PayPal KosmoKrator integration.

7 functions 6 read 1 write Bearer token auth

Lua Namespace

Agents call this integration through app.integrations.paypal.*. Use lua_read_doc("integrations.paypal") inside KosmoKrator to discover the same reference at runtime.

Agent-Facing Lua Docs

This is the rendered version of the full Lua documentation exposed to agents when they inspect the integration namespace.

PayPal — Lua API Reference

list_orders

List PayPal checkout orders with optional filters.

Parameters

NameTypeRequiredDescription
page_sizeintegernoNumber of orders per page (default: 20, max: 100)
start_idstringnoOrder ID to start from (for pagination)
start_timestringnoStart time filter (ISO 8601, e.g., "2025-01-01T00:00:00Z")
end_timestringnoEnd time filter (ISO 8601, e.g., "2025-12-31T23:59:59Z")
statusstringnoFilter by status: CREATED, SAVED, APPROVED, VOIDED, COMPLETED, PAYER_ACTION_REQUIRED

Examples

-- List recent orders
local result = app.integrations.paypal.list_orders({
  page_size = 10
})

for _, order in ipairs(result.orders or {}) do
  print(order.id .. " — " .. order.status)
end
-- Filter by status and date range
local result = app.integrations.paypal.list_orders({
  status = "COMPLETED",
  start_time = "2025-01-01T00:00:00Z",
  end_time = "2025-12-31T23:59:59Z"
})

get_order

Get details of a specific PayPal checkout order.

Parameters

NameTypeRequiredDescription
order_idstringyesThe PayPal order ID

Example

local result = app.integrations.paypal.get_order({
  order_id = "5O190127TN364715T"
})

print("Status: " .. result.status)
print("Intent: " .. result.intent)

for _, unit in ipairs(result.purchase_units or {}) do
  print("Amount: " .. unit.amount.value .. " " .. unit.amount.currency_code)
end

create_order

Create a new PayPal checkout order.

Parameters

NameTypeRequiredDescription
intentstringyesCAPTURE or AUTHORIZE
purchase_unitsarrayyesArray of purchase units with amount objects
payerarraynoPayer information (name, email, address)
payment_sourcearraynoPayment source configuration (paypal, card)

Purchase Unit Structure

Each purchase unit must include an amount object:

{
  amount = {
    currency_code = "USD",
    value = "10.00"
  },
  description = "Order description"
}

Examples

-- Create a simple capture order
local result = app.integrations.paypal.create_order({
  intent = "CAPTURE",
  purchase_units = {
    {
      amount = {
        currency_code = "USD",
        value = "29.99"
      },
      description = "Premium subscription"
    }
  }
})

print("Order ID: " .. result.id)
print("Status: " .. result.status)

-- Get the approval URL
for _, link in ipairs(result.links or {}) do
  if link.rel == "approve" then
    print("Approval URL: " .. link.href)
  end
end
-- Create an order with payer details
local result = app.integrations.paypal.create_order({
  intent = "CAPTURE",
  purchase_units = {
    {
      amount = {
        currency_code = "EUR",
        value = "49.99",
        breakdown = {
          item_total = { currency_code = "EUR", value = "49.99" }
        }
      },
      items = {
        {
          name = "Service Plan",
          unit_amount = { currency_code = "EUR", value = "49.99" },
          quantity = "1"
        }
      }
    }
  },
  payer = {
    name = { given_name = "John", surname = "Doe" },
    email_address = "[email protected]"
  }
})

list_payments

List PayPal payments with optional filters.

Parameters

NameTypeRequiredDescription
countintegernoNumber of payments to return (default: 10, max: 20)
start_idstringnoPayment ID to start from (for pagination)
start_timestringnoStart time filter (ISO 8601)
end_timestringnoEnd time filter (ISO 8601)
sort_bystringnoSort field: create_time or update_time
sort_orderstringnoSort direction: asc or desc

Example

local result = app.integrations.paypal.list_payments({
  count = 10,
  sort_by = "create_time",
  sort_order = "desc"
})

for _, payment in ipairs(result.payments or {}) do
  print(payment.id .. " — " .. payment.state .. " — " .. payment.transactions[1].amount.total)
end

get_payment

Get details of a specific PayPal payment.

Parameters

NameTypeRequiredDescription
payment_idstringyesThe PayPal payment ID

Example

local result = app.integrations.paypal.get_payment({
  payment_id = "PAY-1AB23456CD789012EFGHIJKL"
})

print("State: " .. result.state)
print("Intent: " .. result.intent)

for _, tx in ipairs(result.transactions or {}) do
  print("Amount: " .. tx.amount.total .. " " .. tx.amount.currency)
  print("Description: " .. (tx.description or "N/A"))
end

list_invoices

List PayPal invoices.

Parameters

NameTypeRequiredDescription
pageintegernoPage number (default: 1)
page_sizeintegernoInvoices per page (default: 20, max: 100)
total_requiredbooleannoInclude total count in response (default: false)
fieldsstringnoComma-separated fields to return

Example

local result = app.integrations.paypal.list_invoices({
  page = 1,
  page_size = 20,
  total_required = true
})

if result.total_items then
  print("Total invoices: " .. result.total_items)
end

for _, inv in ipairs(result.items or {}) do
  print(inv.id .. " — " .. (inv.status or "UNKNOWN") .. " — " .. (inv.invoice_number or ""))
end

get_current_user

Get the authenticated PayPal user’s profile information.

Parameters

NameTypeRequiredDescription
schemastringnoSchema to return: paypalv1.1 or openid

Example

local result = app.integrations.paypal.get_current_user({})

print("Name: " .. (result.name or "N/A"))
print("Email: " .. (result.email or "N/A"))
print("User ID: " .. (result.user_id or "N/A"))

Multi-Account Usage

If you have multiple PayPal accounts configured, use account-specific namespaces:

-- Default account (always works)
app.integrations.paypal.list_orders({})

-- Explicit default (portable across setups)
app.integrations.paypal.default.list_orders({})

-- Named accounts
app.integrations.paypal.business.list_orders({})
app.integrations.paypal.personal.list_orders({})

All functions are identical across accounts — only the credentials differ.

Raw agent markdown
# PayPal — Lua API Reference

## list_orders

List PayPal checkout orders with optional filters.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `page_size` | integer | no | Number of orders per page (default: 20, max: 100) |
| `start_id` | string | no | Order ID to start from (for pagination) |
| `start_time` | string | no | Start time filter (ISO 8601, e.g., `"2025-01-01T00:00:00Z"`) |
| `end_time` | string | no | End time filter (ISO 8601, e.g., `"2025-12-31T23:59:59Z"`) |
| `status` | string | no | Filter by status: `CREATED`, `SAVED`, `APPROVED`, `VOIDED`, `COMPLETED`, `PAYER_ACTION_REQUIRED` |

### Examples

```lua
-- List recent orders
local result = app.integrations.paypal.list_orders({
  page_size = 10
})

for _, order in ipairs(result.orders or {}) do
  print(order.id .. " — " .. order.status)
end
```

```lua
-- Filter by status and date range
local result = app.integrations.paypal.list_orders({
  status = "COMPLETED",
  start_time = "2025-01-01T00:00:00Z",
  end_time = "2025-12-31T23:59:59Z"
})
```

---

## get_order

Get details of a specific PayPal checkout order.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `order_id` | string | yes | The PayPal order ID |

### Example

```lua
local result = app.integrations.paypal.get_order({
  order_id = "5O190127TN364715T"
})

print("Status: " .. result.status)
print("Intent: " .. result.intent)

for _, unit in ipairs(result.purchase_units or {}) do
  print("Amount: " .. unit.amount.value .. " " .. unit.amount.currency_code)
end
```

---

## create_order

Create a new PayPal checkout order.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `intent` | string | yes | `CAPTURE` or `AUTHORIZE` |
| `purchase_units` | array | yes | Array of purchase units with amount objects |
| `payer` | array | no | Payer information (name, email, address) |
| `payment_source` | array | no | Payment source configuration (paypal, card) |

### Purchase Unit Structure

Each purchase unit must include an `amount` object:

```lua
{
  amount = {
    currency_code = "USD",
    value = "10.00"
  },
  description = "Order description"
}
```

### Examples

```lua
-- Create a simple capture order
local result = app.integrations.paypal.create_order({
  intent = "CAPTURE",
  purchase_units = {
    {
      amount = {
        currency_code = "USD",
        value = "29.99"
      },
      description = "Premium subscription"
    }
  }
})

print("Order ID: " .. result.id)
print("Status: " .. result.status)

-- Get the approval URL
for _, link in ipairs(result.links or {}) do
  if link.rel == "approve" then
    print("Approval URL: " .. link.href)
  end
end
```

```lua
-- Create an order with payer details
local result = app.integrations.paypal.create_order({
  intent = "CAPTURE",
  purchase_units = {
    {
      amount = {
        currency_code = "EUR",
        value = "49.99",
        breakdown = {
          item_total = { currency_code = "EUR", value = "49.99" }
        }
      },
      items = {
        {
          name = "Service Plan",
          unit_amount = { currency_code = "EUR", value = "49.99" },
          quantity = "1"
        }
      }
    }
  },
  payer = {
    name = { given_name = "John", surname = "Doe" },
    email_address = "[email protected]"
  }
})
```

---

## list_payments

List PayPal payments with optional filters.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `count` | integer | no | Number of payments to return (default: 10, max: 20) |
| `start_id` | string | no | Payment ID to start from (for pagination) |
| `start_time` | string | no | Start time filter (ISO 8601) |
| `end_time` | string | no | End time filter (ISO 8601) |
| `sort_by` | string | no | Sort field: `create_time` or `update_time` |
| `sort_order` | string | no | Sort direction: `asc` or `desc` |

### Example

```lua
local result = app.integrations.paypal.list_payments({
  count = 10,
  sort_by = "create_time",
  sort_order = "desc"
})

for _, payment in ipairs(result.payments or {}) do
  print(payment.id .. " — " .. payment.state .. " — " .. payment.transactions[1].amount.total)
end
```

---

## get_payment

Get details of a specific PayPal payment.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `payment_id` | string | yes | The PayPal payment ID |

### Example

```lua
local result = app.integrations.paypal.get_payment({
  payment_id = "PAY-1AB23456CD789012EFGHIJKL"
})

print("State: " .. result.state)
print("Intent: " .. result.intent)

for _, tx in ipairs(result.transactions or {}) do
  print("Amount: " .. tx.amount.total .. " " .. tx.amount.currency)
  print("Description: " .. (tx.description or "N/A"))
end
```

---

## list_invoices

List PayPal invoices.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `page` | integer | no | Page number (default: 1) |
| `page_size` | integer | no | Invoices per page (default: 20, max: 100) |
| `total_required` | boolean | no | Include total count in response (default: false) |
| `fields` | string | no | Comma-separated fields to return |

### Example

```lua
local result = app.integrations.paypal.list_invoices({
  page = 1,
  page_size = 20,
  total_required = true
})

if result.total_items then
  print("Total invoices: " .. result.total_items)
end

for _, inv in ipairs(result.items or {}) do
  print(inv.id .. " — " .. (inv.status or "UNKNOWN") .. " — " .. (inv.invoice_number or ""))
end
```

---

## get_current_user

Get the authenticated PayPal user's profile information.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `schema` | string | no | Schema to return: `paypalv1.1` or `openid` |

### Example

```lua
local result = app.integrations.paypal.get_current_user({})

print("Name: " .. (result.name or "N/A"))
print("Email: " .. (result.email or "N/A"))
print("User ID: " .. (result.user_id or "N/A"))
```

---

## Multi-Account Usage

If you have multiple PayPal accounts configured, use account-specific namespaces:

```lua
-- Default account (always works)
app.integrations.paypal.list_orders({})

-- Explicit default (portable across setups)
app.integrations.paypal.default.list_orders({})

-- Named accounts
app.integrations.paypal.business.list_orders({})
app.integrations.paypal.personal.list_orders({})
```

All functions are identical across accounts — only the credentials differ.

Metadata-Derived Lua Example

local result = app.integrations.paypal.paypal_list_orders({
  page_size = 1,
  start_id = "example_start_id",
  start_time = "example_start_time",
  end_time = "example_end_time",
  status = "example_status"
})
print(result)

Functions

paypal_list_orders

List PayPal checkout orders. Returns order IDs, statuses, and amounts. Use filters to narrow results by status or date range.

Operation
Read read
Full name
paypal.paypal_list_orders
ParameterTypeRequiredDescription
page_size integer no Number of orders to return per page (default: 20, max: 100).
start_id string no The ID of the first order to return. Used for pagination.
start_time string no Start time for filtering (ISO 8601, e.g., "2025-01-01T00:00:00Z").
end_time string no End time for filtering (ISO 8601, e.g., "2025-12-31T23:59:59Z").
status string no Filter by order status: CREATED, SAVED, APPROVED, VOIDED, COMPLETED, PAYER_ACTION_REQUIRED.

paypal_get_order

Get details of a specific PayPal checkout order by its order ID. Returns full order information including status, payer details, and line items.

Operation
Read read
Full name
paypal.paypal_get_order
ParameterTypeRequiredDescription
order_id string yes The PayPal order ID (e.g., "5O190127TN364715T").

paypal_create_order

Create a new PayPal checkout order. Specify the intent, purchase units with amounts, and optional payer details. Returns the created order with approval links.

Operation
Write write
Full name
paypal.paypal_create_order
ParameterTypeRequiredDescription
intent string yes The order intent: "CAPTURE" to capture funds immediately, or "AUTHORIZE" to authorize and capture later.
purchase_units array yes Array of purchase units. Each unit must have an "amount" object with "currency_code" and "value". May include "description", "items", and "shipping".
payer array no Payer information: name, email_address, address, phone.
payment_source array no Payment source configuration (e.g., paypal, card).

paypal_list_payments

List PayPal payments. Returns payment IDs, states, amounts, and transaction details. Use filters to narrow results by count or date range.

Operation
Read read
Full name
paypal.paypal_list_payments
ParameterTypeRequiredDescription
count integer no Number of payments to return (default: 10, max: 20).
start_id string no The ID of the first payment to return. Used for pagination.
start_time string no Start time for filtering (ISO 8601, e.g., "2025-01-01T00:00:00Z").
end_time string no End time for filtering (ISO 8601, e.g., "2025-12-31T23:59:59Z").
sort_by string no Sort field: "create_time" or "update_time".
sort_order string no Sort direction: "asc" or "desc".

paypal_get_payment

Get details of a specific PayPal payment by its payment ID. Returns full payment information including state, amount, payer details, and transactions.

Operation
Read read
Full name
paypal.paypal_get_payment
ParameterTypeRequiredDescription
payment_id string yes The PayPal payment ID (e.g., "PAY-1AB23456CD789012EFGHIJKL").

paypal_list_invoices

List PayPal invoices. Returns invoice IDs, numbers, statuses, amounts, and recipient details. Use pagination parameters to navigate through results.

Operation
Read read
Full name
paypal.paypal_list_invoices
ParameterTypeRequiredDescription
page integer no Page number for pagination (default: 1).
page_size integer no Number of invoices per page (default: 20, max: 100).
total_required boolean no Whether to include the total count of invoices in the response (default: false).
fields string no Comma-separated list of fields to return (e.g., "items,payments").

paypal_get_current_user

Get the authenticated PayPal user's profile information. Returns the user's name, email, and other account details.

Operation
Read read
Full name
paypal.paypal_get_current_user
ParameterTypeRequiredDescription
schema string no Schema to return: "paypalv1.1" or "openid". Default: "paypalv1.1".