{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/lune/json-schema/lune-payment-schema.json",
  "title": "Payment",
  "description": "A Payment represents a payment for orders placed through Lune Pay.\n\nThe Payment entity contains a reference to the order.\n",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/lune-payments-api-openapi.yml#/components/schemas/Payment",
  "oneOf": [
    {
      "$ref": "#/$defs/OrderPayment"
    }
  ],
  "$defs": {
    "Metadata": {
      "description": "An arbitrary dictionary (key-value pairs) to store application-specific information.\n\nLune doesn't use this information for order processing. Its purpose is for the API\nclients to be able to attach arbitrary information (to an order for example) and\nthen retrieve it.\n",
      "type": "object",
      "additionalProperties": {
        "type": "string"
      }
    },
    "NullEnum": {
      "type": [
        "string",
        "null"
      ],
      "x-lune-name": "Null",
      "description": "The property is set to `null`.",
      "enum": [
        null
      ]
    },
    "OrderBase": {
      "type": "object",
      "description": "Order object",
      "required": [
        "id",
        "idempotency_key",
        "type",
        "status",
        "currency",
        "offset_cost",
        "total_cost",
        "commission",
        "quantity",
        "created_at",
        "bundles",
        "projects",
        "certificate",
        "public_certificate_url",
        "metadata",
        "offset_link_id",
        "email",
        "payment_method"
      ],
      "properties": {
        "id": {
          "type": "string",
          "description": "The order's unique identifier"
        },
        "idempotency_key": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 100,
          "description": "Account-unique identifier provided by the client.\n\n`idempotency_key` has two purposes:\n1. Clients can use `idempotency_key` to prevent duplicate orders.\n2. Clients can use `idempotency_key` to reconcile orders with other entities on their system.\n\nIf an order with the same `idempotency_key` already exists, the API returns\nHTTP 409 Conflict with error code `order_idempotency_already_exists`. To\nretrieve the existing order, use the\n`GET /v1/orders/by-idempotency-key/{idempotency_key}` endpoint.\n",
          "default": null
        },
        "type": {
          "type": "string",
          "description": "Identifies whether the order has been placed by quantity (kg CO2) or value (monetary amount)",
          "enum": [
            "quantity",
            "value"
          ]
        },
        "status": {
          "type": "string",
          "description": "Order status",
          "enum": [
            "received",
            "placed",
            "paid",
            "retiring",
            "cancelled",
            "complete",
            "failed"
          ]
        },
        "currency": {
          "type": "string",
          "description": "Order currency code"
        },
        "offset_cost": {
          "type": [
            "string",
            "null"
          ],
          "description": "The net offset cost being purchased. May be lower than `requested_value`.\n\nThis property is set when bundles are assigned to the order.\nUnit: order currency\n",
          "pattern": "^[0-9]+(\\.[0-9]+)?$"
        },
        "total_cost": {
          "type": [
            "string",
            "null"
          ],
          "description": "The total cost for the order inclusive of fees.\n\nUnit: order currency\n",
          "pattern": "^[0-9]+(\\.[0-9]+)?$"
        },
        "commission": {
          "type": [
            "string",
            "null"
          ],
          "description": "Lune's fee.\n\nThis property is set when bundles are assigned to the order.\nUnit: order currency\n",
          "pattern": "^[0-9]+(\\.[0-9]+)?$"
        },
        "quantity": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^[0-9]+(\\.[0-9]+)?$",
          "description": "Quantity of CO2 offsets purchased in tonnes."
        },
        "payment_method": {
          "description": "How the order will be paid.\nWhen `card`, Lune will attempt to charge the card and pay this order. When `invoice`, Lune will email an invoice with payment instructions.",
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "invoice",
            "card",
            null
          ]
        },
        "created_at": {
          "type": "string",
          "format": "date-time",
          "description": "Order creation timestamp"
        },
        "bundles": {
          "type": [
            "array",
            "null"
          ],
          "description": "bundles are set when the order's status is `placed`, `paid`, `retiring` or `complete`.\n\nThe bundles associated with the order including their relative quantity and cost breakdown.\n",
          "items": {
            "$ref": "#/$defs/OrderBundle"
          }
        },
        "projects": {
          "type": [
            "array",
            "null"
          ],
          "description": "Projects are set when the order's status is `retiring` or `complete`.\n\nThe projects associated with the order including their relative quantity and cost breakdown.\n\nOrders are placed against bundles, not projects. Projects in a bundle may change based on supply.\n\nThis property is set as soon as we can guarantee project supply.\n",
          "items": {
            "$ref": "#/$defs/OrderProject"
          }
        },
        "certificate": {
          "type": [
            "string",
            "null"
          ],
          "description": "Carbon credits PDF certificate URL.\n\nThis property is set when an order has state 'complete'\n\nThe property is set (and the certificate is available) regardless of the\nSustainability page configuration.\n\nThe URL requires API authentication and cannot be accessed anonymously.\n"
        },
        "public_certificate_url": {
          "type": [
            "string",
            "null"
          ],
          "description": "The Carbon credits certificate public URL.\n\nOnce the Sustainability page of the associated account is enabled and configured to include the\ncertificate section, and the order is set to 'complete', this URL will link to the publicly accessible certificate.\n"
        },
        "metadata": {
          "$ref": "#/$defs/Metadata"
        },
        "offset_link_id": {
          "type": [
            "string",
            "null"
          ],
          "description": "The offset link identifier, if the order was placed through an offset link"
        },
        "email": {
          "type": [
            "string",
            "null"
          ],
          "description": "End-user email.\n\nThis property is currently populated on orders placed through offset links.\n"
        }
      }
    },
    "OrderBundle": {
      "type": "object",
      "required": [
        "bundle_id",
        "bundle_name",
        "quantity",
        "unit_price",
        "gross_unit_price",
        "offset_cost",
        "insufficient_available_quantity"
      ],
      "properties": {
        "bundle_id": {
          "type": "string",
          "description": "The bundle's unique identifier"
        },
        "bundle_name": {
          "type": "string",
          "description": "The bundle's name"
        },
        "primary_image": {
          "type": "string",
          "description": "A bundle's image URL"
        },
        "quantity": {
          "type": "string",
          "pattern": "^[0-9]+(\\.[0-9]+)?$",
          "description": "Quantity for the specific bundle (tonnes CO2)"
        },
        "unit_price": {
          "type": "string",
          "description": "Bundle unit price per tonne CO2\n\nUnit: order currency\n",
          "pattern": "^[0-9]+(\\.[0-9]+)?$"
        },
        "gross_unit_price": {
          "type": "string",
          "description": "Bundle unit price per tonne CO2 inclusive of fees.\n\nUnit: order currency\n",
          "pattern": "^[0-9]+(\\.[0-9]+)?$"
        },
        "offset_cost": {
          "type": "string",
          "description": "The bundle's net offset cost being purchased.\n\nUnit: order currency\n",
          "pattern": "^[0-9]+(\\.[0-9]+)?$"
        },
        "insufficient_available_quantity": {
          "type": [
            "boolean",
            "null"
          ],
          "description": "If true, there is no inventory necessary to fully satisfy the order for this bundle.\n"
        }
      }
    },
    "OrderByQuantityProperties": {
      "type": "object",
      "required": [
        "requested_quantity",
        "requested_value",
        "estimate_id"
      ],
      "properties": {
        "requested_quantity": {
          "type": "string",
          "pattern": "^[0-9]+(\\.[0-9]+)?$",
          "description": "Requested quantity of CO2 offsets to purchase in tonnes."
        },
        "requested_value": {
          "description": "Requested value of CO2 offsets to purchase in the account's currency.",
          "oneOf": [
            {
              "$ref": "#/$defs/NullEnum"
            }
          ]
        },
        "estimate_id": {
          "description": "The emission calculation unique identifier",
          "oneOf": [
            {
              "$ref": "#/$defs/NullEnum"
            }
          ]
        }
      }
    },
    "OrderPayment": {
      "x-lune-name": "Order payment",
      "type": "object",
      "required": [
        "type",
        "order"
      ],
      "properties": {
        "order": {
          "allOf": [
            {
              "$ref": "#/$defs/OrderBase"
            },
            {
              "$ref": "#/$defs/OrderByQuantityProperties"
            }
          ]
        },
        "type": {
          "type": "string",
          "enum": [
            "order"
          ]
        }
      }
    },
    "OrderProject": {
      "type": "object",
      "required": [
        "project_id",
        "project_name",
        "project_type",
        "project_slug",
        "quantity",
        "unit_price",
        "offset_cost",
        "status"
      ],
      "properties": {
        "project_id": {
          "type": "string",
          "description": "The project's unique identifier"
        },
        "project_name": {
          "type": "string",
          "description": "The project's name"
        },
        "project_type": {
          "type": "string",
          "description": "The project's offset type, eg Forest conservation, Afforestation, Direct Air Capture"
        },
        "project_slug": {
          "type": "string",
          "description": "The project's unique slug"
        },
        "project_logo": {
          "type": "string",
          "description": "URL to the project's logo"
        },
        "quantity": {
          "type": "string",
          "pattern": "^[0-9]+(\\.[0-9]+)?$",
          "description": "Carbon offset purchased (tonnes CO2)"
        },
        "unit_price": {
          "type": "string",
          "description": "Project unit price per tonne CO2\n\nUnit: order currency\n",
          "pattern": "^[0-9]+(\\.[0-9]+)?$"
        },
        "offset_cost": {
          "type": "string",
          "description": "The net offset cost being purchased.\n\nUnit: order currency\n",
          "pattern": "^[0-9]+(\\.[0-9]+)?$"
        },
        "status": {
          "description": "Describes whether credits for a project have been allocated to an order or retired\n",
          "type": "string",
          "enum": [
            "allocated",
            "retired"
          ]
        }
      }
    }
  }
}