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

# Sell a product

> Enrolls the customer in the product and opens an invoice for it, already `open` and ready to be paid. When the payment confirms, product delivery (email and download link) happens on its own.

The customer is identified by `customer.externalId`: calling again with the same `externalId` reuses the customer and enrollment instead of creating duplicates. The amount comes from the product's published price unless you send `amount`.




## OpenAPI

````yaml /api-reference/openapi.en.json post /billing/products/{productID}/invoices
openapi: 3.1.0
info:
  title: Infi API
  version: 0.0.1
  description: >
    The Infi REST API: catalog, customers, usage metering, subscriptions,

    invoices, payments and checkout.


    **Authentication.** Send your secret key as `Authorization: Bearer
    sk_test_…`

    (sandbox) or `sk_live_…` (production). The key prefix selects the
    environment.

    Checkout routes (`/pay/*`) and `/public/*` take no key: they run in the

    payer's browser.


    **Idempotency.** Every request that changes data requires an

    `Idempotency-Key` header. A retry with the same key returns the original

    response instead of running again.


    **Amounts.** Money and quantities travel as decimal strings (`"150.00"`,

    `"0.0001"`), never as floating-point numbers.


    **Errors.** The body carries `error_code` (stable, branch on it), `message`

    (for humans) and `tracer_id` (send it to support). Rate-limit and
    idempotency

    errors are nested under `error`, with `code` and `request_id`.
servers:
  - url: https://api-sandbox.beinfi.com
    description: Sandbox
  - url: https://api.beinfi.com
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Catalog
  - name: Customers
  - name: Metering
  - name: Subscriptions
  - name: Invoices
  - name: Payments
  - name: Checkout
  - name: Coupons
  - name: Billing
  - name: Account
  - name: Webhooks
  - name: Test account
  - name: Rail
  - name: Storefronts
paths:
  /billing/products/{productID}/invoices:
    parameters:
      - $ref: '#/components/parameters/ProductID'
    post:
      tags:
        - Invoices
      summary: Sell a product
      description: >
        Enrolls the customer in the product and opens an invoice for it, already
        `open` and ready to be paid. When the payment confirms, product delivery
        (email and download link) happens on its own.


        The customer is identified by `customer.externalId`: calling again with
        the same `externalId` reuses the customer and enrollment instead of
        creating duplicates. The amount comes from the product's published price
        unless you send `amount`.
      operationId: createProductInvoice
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateProductInvoiceRequest'
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Invoice'
          description: Created.
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '422':
          $ref: '#/components/responses/ValidationFailed'
components:
  parameters:
    ProductID:
      name: productID
      in: path
      required: true
      schema:
        type: string
        format: uuid
      description: Product ID.
  schemas:
    CreateProductInvoiceRequest:
      type: object
      required:
        - customer
      properties:
        customer:
          type: object
          required:
            - externalId
          properties:
            externalId:
              type: string
            email:
              type:
                - string
                - 'null'
            name:
              type:
                - string
                - 'null'
            taxId:
              type:
                - string
                - 'null'
          description: >-
            The buyer. `externalId` is required and identifies the customer
            stably (their id in your system, or their email): the same key
            reuses the existing customer. `email`, `name` and `taxId` (CPF or
            CNPJ) are optional.
        amount:
          type:
            - string
            - 'null'
          description: >-
            Amount to charge, as a decimal string. Defaults to the product's
            published price.
        description:
          type:
            - string
            - 'null'
          description: Line description on the invoice. Defaults to the product name.
        currency:
          type: string
          description: Currency, as an ISO 4217 code. Defaults to `BRL`.
        dueDate:
          type:
            - string
            - 'null'
          format: date-time
          description: Due date.
        send:
          type: boolean
          description: '`true` emails the invoice to the buyer as soon as it is created.'
        successUrl:
          type:
            - string
            - 'null'
          description: Where checkout sends the buyer after payment.
        cancelUrl:
          type:
            - string
            - 'null'
          description: Where checkout sends the buyer if they back out.
    Invoice:
      type: object
      properties:
        id:
          type: string
          format: uuid
        customerId:
          type:
            - string
            - 'null'
          format: uuid
          description: >-
            The customer's product enrollment id. Set on product, usage and
            subscription invoices.
        payerId:
          type:
            - string
            - 'null'
          format: uuid
          description: The paying customer's id. Set on one-off invoices.
        subscriptionId:
          type:
            - string
            - 'null'
          format: uuid
          description: The subscription that generated the invoice
        invoiceNumber:
          type:
            - string
            - 'null'
          description: Sequential invoice number
        status:
          type: string
          enum:
            - draft
            - open
            - paid
            - void
            - uncollectible
          description: >-
            `draft` (being built), `open` (issued, awaiting payment), `paid`,
            `void` (canceled) or `uncollectible` (written off).
        currency:
          type: string
          description: Currency, as an ISO 4217 code (`BRL`).
        subtotal:
          type: string
          description: Sum of line items before tax and discounts.
        tax:
          type: string
          description: Tax on the invoice.
        total:
          type: string
          description: The invoice's final amount.
        amountDue:
          type: string
          description: How much is still owed.
        periodStart:
          type:
            - string
            - 'null'
          format: date-time
          description: Start of the billed period
        periodEnd:
          type:
            - string
            - 'null'
          format: date-time
          description: End of the billed period
        dueDate:
          type:
            - string
            - 'null'
          format: date-time
          description: Due date.
        finalizedAt:
          type:
            - string
            - 'null'
          format: date-time
          description: When the invoice was issued.
        paidAt:
          type:
            - string
            - 'null'
          format: date-time
          description: When the invoice was paid.
        successUrl:
          type:
            - string
            - 'null'
          description: Where checkout sends the buyer after payment.
        cancelUrl:
          type:
            - string
            - 'null'
          description: Where checkout sends the buyer if they back out.
        createdAt:
          type: string
          format: date-time
        lineItems:
          type: array
          items:
            $ref: '#/components/schemas/InvoiceLineItem'
      description: >-
        What a customer owes: line items, totals and status. Status: `draft` →
        `open` → `paid`, or `void` / `uncollectible`.
    InvoiceLineItem:
      type: object
      properties:
        id:
          type: string
          format: uuid
        type:
          type: string
          enum:
            - usage
            - recurring
            - proration
            - credit
            - adjustment
            - commitment
            - manual
          description: >-
            `usage` (metered usage), `recurring` (recurring fee), `proration`
            (pro-rata adjustment for a mid-period change), `credit`,
            `adjustment` (usage that arrived after its period was already
            invoiced), `commitment` (top-up to the minimum commitment) or
            `manual` (free-form line).
        meterId:
          type:
            - string
            - 'null'
          format: uuid
          description: The meter the usage came from
        priceId:
          type:
            - string
            - 'null'
          format: uuid
          description: The price applied to this line.
        description:
          type: string
        quantity:
          type: string
          description: Quantity billed
        unitPrice:
          type:
            - string
            - 'null'
          description: Price per unit
        amount:
          type: string
          description: Line total
        proration:
          type: boolean
          description: '`true` when the line is a pro-rated amount.'
      description: One line on an invoice.
    Error:
      type: object
      required:
        - message
        - error_code
        - tracer_id
      properties:
        message:
          type: string
          description: Human-readable sentence.
        error_code:
          $ref: '#/components/schemas/ErrorCode'
          description: Stable error code. Branch on it.
        tracer_id:
          type: string
          description: Request id. Include it when contacting support.
      description: >-
        The standard error body. It is flat (no `error` wrapper) and the trace
        id is `tracer_id`.
    NotFoundError:
      type: object
      required:
        - message
        - error_code
        - tracer_id
        - resource
      properties:
        message:
          type: string
        error_code:
          $ref: '#/components/schemas/ErrorCode'
        tracer_id:
          type: string
        resource:
          type: string
    ValidationError:
      type: object
      required:
        - message
        - error_code
        - tracer_id
        - errors
      properties:
        message:
          type: string
        error_code:
          $ref: '#/components/schemas/ErrorCode'
        tracer_id:
          type: string
        errors:
          type: array
          items:
            type: object
            required:
              - field
              - value
              - constraint
              - description
            properties:
              field:
                type: string
              value:
                type: string
              constraint:
                type: string
              description:
                type: string
          description: >-
            Per-field detail (`field`, `description`). Always present on a
            `422`; may be empty.
      description: >-
        Body of a `422`. Same shape as `Error`, plus `errors[]` with per-field
        detail. That is where the sentence telling you what to fix lives (for
        example, "product has no published version").
    ErrorCode:
      type: string
      examples:
        - internal_error
        - validation_failed
        - bad_request
        - unauthorized
        - forbidden
        - not_found
        - conflict
        - rate_limited
      description: >-
        Stable error code. The list is open: besides the generic codes, each
        area defines its own (`coupon_expired`, `insufficient_balance`,
        `version_not_draft`, `idempotency_key_reused`…). Handle a code you do
        not recognize by its HTTP status and show `message`; do not fail parsing
        the response.
  responses:
    Unauthorized:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
      description: Missing or invalid API key.
    NotFound:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/NotFoundError'
      description: Resource not found.
    ValidationFailed:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ValidationError'
      description: One or more fields are invalid. Per-field detail is in `errors[]`.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Your account's secret key: `Authorization: Bearer sk_test_…` or
        `sk_live_…`. Server-side only.

````