> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cnaught.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Checkout Session

> Creates a Checkout Session that, when completed, will result in an order
for the specified amount of carbon credits (in kilograms). The total price
must be at least $0.50 (the corresponding amount will depend on the per kg
price of the specified portfolio). The Quotes API can be used to check the
price before attempting to create a session.




## OpenAPI

````yaml api-reference/openapi.yaml post /checkout/sessions
openapi: 3.1.0
info:
  title: CNaught Carbon Credits API Documentation
  contact:
    email: support@cnaught.com
    name: CNaught
    url: https://cnaught.com/
  version: v1
  description: |
    Carbon Credits API Documentation
  termsOfService: https://cnaught.com/terms
  license:
    name: MIT
    url: https://spdx.org/licenses/MIT.html
servers:
  - url: https://api.cnaught.com/v1
    description: CNaught API
security:
  - ApiKey: []
tags:
  - name: Orders
    description: Endpoints for placing orders and retrieving information about orders
  - name: Quotes
    description: Endpoints for obtaining price quotes for orders
  - name: Climate Impact
    description: >-
      Endpoints for retrieving climate impact data and hosted public impact page
      configuration
  - name: Subaccounts
    description: Endpoints for creating and retrieving information about subaccounts
paths:
  /checkout/sessions:
    post:
      tags:
        - Checkout Sessions
      summary: Create Checkout Session
      description: >
        Creates a Checkout Session that, when completed, will result in an order

        for the specified amount of carbon credits (in kilograms). The total
        price

        must be at least $0.50 (the corresponding amount will depend on the per
        kg

        price of the specified portfolio). The Quotes API can be used to check
        the

        price before attempting to create a session.
      operationId: CreateCheckoutSession
      parameters:
        - $ref: '#/components/parameters/SubaccountId'
          description: >-
            The Subaccount the Checkout Session will create an order for when
            successfully completed
      requestBody:
        description: Checkout Session Parameters
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CheckoutSessionParams'
            examples:
              Example:
                value:
                  amount_kg: 100
                  success_url: >-
                    https://www.example.com/confirmation?my_query=my_value&session_id={CHECKOUT_SESSION_ID}
                  cancel_url: https://www.example.com/purchase-credits
                  description: on behalf of Jane Smith
                  notification_config:
                    url: https://www.example.com/callback
      responses:
        '201':
          description: Checkout Session
          headers:
            Location:
              schema:
                type: string
                description: URL for retrieving the Checkout Session
                examples:
                  - https://api.cnaught.com/v1/checkout/sessions/zpQ6QSNRQh
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CheckoutSession'
              examples:
                New Checkout Session:
                  value:
                    id: zpQ6QSNRQh
                    amount_kg: 100
                    price_usd_cents: 200
                    success_url: >-
                      https://www.example.com/confirmation?my_query=my_value&session_id={CHECKOUT_SESSION_ID}
                    cancel_url: https://www.example.com/purchase-credits
                    checkout_url: https://checkout.cnaught.com/pay/zpQ6QSNRQh
                    state: open
                    created_on: '2022-07-31T18:00:00.000000Z'
                    expires_on: '2022-08-01T18:00:00.000000Z'
                    completed_on: null
                    portfolio_id: mHvNvWbq
                    order_description: on behalf of Jane Smith
                    order_webhook_url: https://www.example.com/callback
        '400':
          description: Bad Request
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/BadRequestProblemDetails'
              example:
                errors:
                  amount_kg:
                    - '''amount_kg'' must be greater than 0'
                type: https://api.cnaught.com/v1/errors/invalid-parameters
                title: Your request parameters didn't validate
                status: 400
        '401':
          $ref: '#/components/responses/Unauthorized'
components:
  parameters:
    SubaccountId:
      name: X-Subaccount-Id
      in: header
      required: false
      description: >-
        If present, scopes the operation to the subaccount with given id. See
        [Subaccounts](/api/reference/#tag/Subaccounts) for more info.
      schema:
        type: string
  schemas:
    CheckoutSessionParams:
      type: object
      required:
        - amount_kg
        - success_url
        - cancel_url
      properties:
        amount_kg:
          type: number
          description: >-
            Amount of carbon credits to be purchased upon checkout completion,
            in kilograms
          examples:
            - 100
        success_url:
          type: string
          description: >
            The URL the customer will be redirected to after the payment is
            completed. The `{CHECKOUT_SESSION_ID}`

            template can be used to include the session id in a query parameter.
            Make sure to include the template

            exactly as `{CHECKOUT_SESSION_ID}` (i.e. do not replace it with the
            actual session id).
          examples:
            - https://www.example.com/confirmation
            - >-
              https://www.example.com/confirmation?session_id={CHECKOUT_SESSION_ID}
            - >-
              https://www.example.com/confirmation?my_query=my_value&session_id={CHECKOUT_SESSION_ID}
        cancel_url:
          type: string
          description: >-
            The URL the customer will be directed to if they decide to cancel
            payment and return to your website
          examples:
            - https://www.example.com/purchase-credits
        portfolio_id:
          type:
            - string
            - 'null'
          description: >
            Optional id of the portfolio to use for fulfilling the order
            resulting from the Checkout Session.

            If not specified, the user or subaccount's default portfolio will be
            used (depending on if a subaccount is provided).
          examples:
            - a23bF6
        description:
          type:
            - string
            - 'null'
          description: >-
            Optional public description for the order that will be shown on the
            certificate, as provided when order was placed
          maxLength: 512
          examples:
            - on behalf of Jane Smith
        notification_config:
          $ref: '#/components/schemas/NotificationConfig'
    CheckoutSession:
      type: object
      properties:
        id:
          type: string
          description: Identifier that can be used to retrieve the Checkout Session
          examples:
            - zpQ6QSNRQh
        amount_kg:
          type: number
          description: >-
            Amount of carbon credits to be purchased upon checkout completion,
            in kilograms
          examples:
            - 10.5
        price_usd_cents:
          type: number
          description: Total price to be charged upon checkout completion, in USD cents
          examples:
            - 2350
        success_url:
          type: string
          description: URL the customer will be redirected to after they complete Checkout.
          examples:
            - https://www.example.com/purchase/success
        cancel_url:
          type: string
          description: >-
            URL the customer will be redirected to if they click the "back"
            button in Checkout.
          examples:
            - https://www.example.com/purchase
        checkout_url:
          type: string
          description: >-
            URL to the Checkout Session. Redirect the customer to this URL to
            take them to Checkout.
          examples:
            - https://checkout.cnaught.com/pay/zpQ6QSNRQh
        state:
          type: string
          description: >
            The status of the Checkout Session, one of `open`, `complete`, or
            `expired`.

            * `open` - The checkout session is still in progress. Payment
            processing has not started.

            * `complete` - The checkout session is complete. Payment processing
            may still be in progress.

            * `expired` - The checkout session has expired. No further
            processing will occur.
        expires_on:
          type: string
          description: Timestamp of when the session will expire.
        completed_on:
          type:
            - string
            - 'null'
          description: >-
            Timestamp of when the session was completed. Null if session has not
            been completed.
        portfolio_id:
          type: string
          description: >-
            Id of the portfolio the customer will purchase from when completing
            Checkout.
        subaccount_id:
          type:
            - string
            - 'null'
          description: Id of the subaccount associated with the customer
        order_description:
          type:
            - string
            - 'null'
          description: >-
            Description to be associated with the order created from this
            session.
        order_webhook_url:
          type:
            - string
            - 'null'
          description: Webhook URL for updates to the order created from this session.
    BadRequestProblemDetails:
      allOf:
        - $ref: '#/components/schemas/BaseProblemDetails'
        - type: object
          properties:
            errors:
              description: >-
                Invalid properties object where each property is the key, mapped
                to a list of reasons why the property is invalid
              type:
                - object
                - 'null'
              additionalProperties:
                type: array
                items:
                  type: string
    NotificationConfig:
      type:
        - object
        - 'null'
      description: |
        Optional configuration for a callback url to invoke with updates
        when the status of an order changes.
      required:
        - url
      properties:
        url:
          type: string
          description: callback url to invoke when status of the order changes
          maxLength: 2048
          examples:
            - https://www.example.com/callback
    BaseProblemDetails:
      type: object
      description: Problem details object returned on errors
      properties:
        title:
          type: string
          description: Short, human-readable summary of the problem
        details:
          type: string
          description: Longer, human-readable description of the problem
        type:
          type: string
          description: URI that identifies the problem type
        status:
          type: integer
          description: HTTP status code of the error
  responses:
    Unauthorized:
      description: Request Unauthorized
      content:
        application/problem+json:
          schema:
            properties:
              title:
                type: string
                description: Short, human-readable summary of the problem type
              status:
                type: integer
                description: HTTP status code of the error
          example:
            title: Authorization has been denied for this request
            status: 401
  securitySchemes:
    ApiKey:
      type: http
      scheme: bearer

````