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

# Create Stripe Checkout Session

> Create a local checkout attempt with the caller's user context and then create a Stripe Checkout Session. Subscription mode requires a billing subject.



## OpenAPI

````yaml https://raw.githubusercontent.com/InsForge/InsForge/main/openapi/payments.yaml post /api/payments/stripe/{environment}/checkout-sessions
openapi: 3.0.3
info:
  title: Insforge Payments API
  version: 1.0.0
  description: >-
    Provider-specific Stripe and Razorpay payment setup, runtime flows, catalog
    management, sync, and webhook projections
servers: []
security: []
tags:
  - name: Stripe Payments
    description: >-
      Stripe Checkout, Billing Portal, catalog, sync, customer, subscription,
      and transaction routes
  - name: Razorpay Payments
    description: >-
      Razorpay Orders, Subscriptions, catalog, manual webhook setup, sync,
      customer, and transaction routes
  - name: Payment Webhooks
    description: Provider webhook ingestion routes
paths:
  /api/payments/stripe/{environment}/checkout-sessions:
    post:
      tags:
        - Stripe Payments
      summary: Create Stripe Checkout Session
      description: >-
        Create a local checkout attempt with the caller's user context and then
        create a Stripe Checkout Session. Subscription mode requires a billing
        subject.
      parameters:
        - $ref: '#/components/parameters/EnvironmentPath'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateCheckoutSessionBody'
            example:
              mode: subscription
              lineItems:
                - priceId: price_123
                  quantity: 1
              successUrl: https://app.example.com/billing/success
              cancelUrl: https://app.example.com/billing/cancel
              subject:
                type: team
                id: team_123
              customerEmail: buyer@example.com
              idempotencyKey: checkout-team_123-pro
      responses:
        '201':
          description: Checkout Session created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateCheckoutSessionResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '500':
          $ref: '#/components/responses/InternalError'
      security:
        - bearerAuth: []
components:
  parameters:
    EnvironmentPath:
      name: environment
      in: path
      required: true
      schema:
        $ref: '#/components/schemas/PaymentEnvironment'
      description: Payment provider environment.
  schemas:
    CreateCheckoutSessionBody:
      type: object
      required:
        - mode
        - lineItems
        - successUrl
        - cancelUrl
      additionalProperties: false
      description: Metadata keys starting with insforge_ are reserved and rejected.
      properties:
        mode:
          $ref: '#/components/schemas/CheckoutMode'
        lineItems:
          type: array
          minItems: 1
          maxItems: 100
          items:
            $ref: '#/components/schemas/CreateCheckoutSessionLineItem'
        successUrl:
          type: string
          format: uri
        cancelUrl:
          type: string
          format: uri
        subject:
          $ref: '#/components/schemas/BillingSubject'
        customerEmail:
          type: string
          format: email
          nullable: true
        metadata:
          $ref: '#/components/schemas/Metadata'
        idempotencyKey:
          type: string
          minLength: 1
          maxLength: 200
    CreateCheckoutSessionResponse:
      type: object
      required:
        - checkoutSession
      properties:
        checkoutSession:
          $ref: '#/components/schemas/CheckoutSession'
    PaymentEnvironment:
      type: string
      enum:
        - test
        - live
    CheckoutMode:
      type: string
      enum:
        - payment
        - subscription
    CreateCheckoutSessionLineItem:
      type: object
      required:
        - priceId
      additionalProperties: false
      properties:
        priceId:
          type: string
          minLength: 1
          example: price_123
        quantity:
          type: integer
          minimum: 1
          maximum: 999
          default: 1
    BillingSubject:
      type: object
      required:
        - type
        - id
      additionalProperties: false
      properties:
        type:
          type: string
          minLength: 1
          maxLength: 100
          example: team
        id:
          type: string
          minLength: 1
          maxLength: 255
          example: team_123
    Metadata:
      type: object
      additionalProperties:
        type: string
    CheckoutSession:
      type: object
      required:
        - id
        - environment
        - mode
        - status
        - paymentStatus
        - subjectType
        - subjectId
        - customerEmail
        - checkoutSessionId
        - customerId
        - paymentIntentId
        - subscriptionId
        - url
        - lastError
        - createdAt
        - updatedAt
      properties:
        id:
          type: string
          format: uuid
        environment:
          $ref: '#/components/schemas/StripeEnvironment'
        mode:
          $ref: '#/components/schemas/CheckoutMode'
        status:
          $ref: '#/components/schemas/CheckoutSessionStatus'
        paymentStatus:
          allOf:
            - $ref: '#/components/schemas/CheckoutSessionPaymentStatus'
          nullable: true
        subjectType:
          type: string
          nullable: true
        subjectId:
          type: string
          nullable: true
        customerEmail:
          type: string
          format: email
          nullable: true
        checkoutSessionId:
          type: string
          nullable: true
          example: cs_test_123
        customerId:
          type: string
          nullable: true
          example: cus_123
        paymentIntentId:
          type: string
          nullable: true
          example: pi_123
        subscriptionId:
          type: string
          nullable: true
          example: sub_123
        url:
          type: string
          nullable: true
          example: https://checkout.stripe.com/c/pay/cs_test_123
        lastError:
          type: string
          nullable: true
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
    ErrorResponse:
      type: object
      required:
        - error
        - message
        - statusCode
      properties:
        error:
          type: string
          example: INVALID_INPUT
        message:
          type: string
          example: 'environment: Invalid enum value'
        statusCode:
          type: integer
          example: 400
        nextActions:
          type: string
          nullable: true
    StripeEnvironment:
      $ref: '#/components/schemas/PaymentEnvironment'
    CheckoutSessionStatus:
      type: string
      enum:
        - initialized
        - open
        - completed
        - expired
        - failed
    CheckoutSessionPaymentStatus:
      type: string
      enum:
        - paid
        - unpaid
        - no_payment_required
  responses:
    BadRequest:
      description: Invalid request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Forbidden:
      description: Forbidden
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    InternalError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````