> ## 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 Razorpay Subscription

> Create a Razorpay Subscription and mirror it locally, then return Checkout options for authorization. The backend first evaluates the caller's INSERT policy on payments.razorpay_subscriptions so apps can restrict which subjects can start subscriptions.



## OpenAPI

````yaml https://raw.githubusercontent.com/InsForge/InsForge/main/openapi/payments.yaml post /api/payments/razorpay/{environment}/subscriptions
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/razorpay/{environment}/subscriptions:
    post:
      tags:
        - Razorpay Payments
      summary: Create Razorpay Subscription
      description: >-
        Create a Razorpay Subscription and mirror it locally, then return
        Checkout options for authorization. The backend first evaluates the
        caller's INSERT policy on payments.razorpay_subscriptions so apps can
        restrict which subjects can start subscriptions.
      parameters:
        - $ref: '#/components/parameters/EnvironmentPath'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateRazorpaySubscriptionBody'
            example:
              planId: plan_123
              totalCount: 12
              subject:
                type: team
                id: team_123
              customerEmail: buyer@example.com
      responses:
        '201':
          description: Razorpay subscription created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateRazorpaySubscriptionResponse'
        '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:
    CreateRazorpaySubscriptionBody:
      type: object
      required:
        - planId
        - subject
      anyOf:
        - required:
            - totalCount
        - required:
            - endAt
      additionalProperties: false
      description: >-
        Notes keys starting with insforge_ are reserved and rejected. Either
        totalCount or endAt is required.
      properties:
        planId:
          type: string
          minLength: 1
          example: plan_123
        totalCount:
          type: integer
          minimum: 1
        endAt:
          type: integer
          minimum: 1
          description: Unix timestamp in seconds.
        quantity:
          type: integer
          minimum: 1
        startAt:
          type: integer
          minimum: 1
          description: Unix timestamp in seconds.
        expireBy:
          type: integer
          minimum: 1
          description: Unix timestamp in seconds.
        customerNotify:
          type: boolean
        offerId:
          type: string
          nullable: true
          minLength: 1
          maxLength: 255
        description:
          type: string
          nullable: true
          maxLength: 2048
        subject:
          $ref: '#/components/schemas/BillingSubject'
        customerName:
          type: string
          nullable: true
          minLength: 1
          maxLength: 255
        customerEmail:
          type: string
          format: email
          nullable: true
        customerContact:
          type: string
          nullable: true
          minLength: 1
          maxLength: 32
        callbackUrl:
          type: string
          format: uri
          nullable: true
        notes:
          description: Native Razorpay subscription notes, available in webhook payloads.
          allOf:
            - $ref: '#/components/schemas/Metadata'
    CreateRazorpaySubscriptionResponse:
      type: object
      required:
        - subscription
        - checkoutOptions
      properties:
        subscription:
          $ref: '#/components/schemas/RazorpaySubscription'
        checkoutOptions:
          type: object
          required:
            - key
            - subscription_id
            - prefill
          additionalProperties: false
          properties:
            key:
              type: string
              example: rzp_test_xxx
            subscription_id:
              type: string
              example: sub_123
            name:
              type: string
              nullable: true
            description:
              type: string
              nullable: true
            callback_url:
              type: string
              nullable: true
            prefill:
              $ref: '#/components/schemas/RazorpayCheckoutPrefill'
    PaymentEnvironment:
      type: string
      enum:
        - test
        - live
    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
    RazorpaySubscription:
      type: object
      required:
        - environment
        - subscriptionId
        - planId
        - customerId
        - subjectType
        - subjectId
        - status
        - currentStart
        - currentEnd
        - endedAt
        - quantity
        - chargeAt
        - startAt
        - endAt
        - totalCount
        - authAttempts
        - paidCount
        - remainingCount
        - shortUrl
        - hasScheduledChanges
        - changeScheduledAt
        - offerId
        - authorizationPaymentId
        - authorizationVerifiedAt
        - notes
        - providerCreatedAt
        - syncedAt
        - createdAt
        - updatedAt
      properties:
        environment:
          $ref: '#/components/schemas/RazorpayEnvironment'
        subscriptionId:
          type: string
          example: sub_123
        planId:
          type: string
          example: plan_123
        customerId:
          type: string
          nullable: true
          example: cust_123
        subjectType:
          type: string
          nullable: true
        subjectId:
          type: string
          nullable: true
        status:
          $ref: '#/components/schemas/RazorpaySubscriptionStatus'
        currentStart:
          type: string
          format: date-time
          nullable: true
        currentEnd:
          type: string
          format: date-time
          nullable: true
        endedAt:
          type: string
          format: date-time
          nullable: true
        quantity:
          type: integer
          nullable: true
        chargeAt:
          type: string
          format: date-time
          nullable: true
        startAt:
          type: string
          format: date-time
          nullable: true
        endAt:
          type: string
          format: date-time
          nullable: true
        totalCount:
          type: integer
          nullable: true
        authAttempts:
          type: integer
          nullable: true
        paidCount:
          type: integer
          nullable: true
        remainingCount:
          type: integer
          nullable: true
        shortUrl:
          type: string
          nullable: true
        hasScheduledChanges:
          type: boolean
        changeScheduledAt:
          type: string
          format: date-time
          nullable: true
        offerId:
          type: string
          nullable: true
        authorizationPaymentId:
          type: string
          nullable: true
          example: pay_123
        authorizationVerifiedAt:
          type: string
          format: date-time
          nullable: true
        notes:
          $ref: '#/components/schemas/Metadata'
        providerCreatedAt:
          type: string
          format: date-time
          nullable: true
        syncedAt:
          type: string
          format: date-time
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
    RazorpayCheckoutPrefill:
      type: object
      additionalProperties: false
      properties:
        name:
          type: string
          nullable: true
        email:
          type: string
          format: email
          nullable: true
        contact:
          type: string
          nullable: true
    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
    RazorpayEnvironment:
      $ref: '#/components/schemas/PaymentEnvironment'
    RazorpaySubscriptionStatus:
      type: string
      enum:
        - created
        - authenticated
        - active
        - pending
        - halted
        - cancelled
        - completed
        - expired
        - paused
  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

````