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

# Preview Refund Allocation

> Computes how a refund would be allocated across the Checkout Session's payment methods,
without executing any refund. Takes the same request body as the refund endpoint and
returns the per-payment-method allocations so you can preview a split-cart refund before
committing.



## OpenAPI

````yaml /openapi.json post /v1/checkout/sessions/{id}/refund_allocation
openapi: 3.1.0
info:
  title: Flex API
  description: >-
    The Flex API powers HSA/FSA payment processing for healthcare commerce:
    checkout sessions, payment intents, subscriptions, customers, refunds,
    disputes, and eligibility. Authenticate with your partner API key as a
    Bearer token. All endpoints are scoped to your partner account, and test
    mode is fully supported via test API keys.
  version: 0.1.0
servers:
  - url: https://api.withflex.com
security:
  - BearerAuth: []
tags:
  - name: Balance Transactions
  - name: Captures
  - name: Checkout Sessions
  - name: Coupons
  - name: Customers
  - name: Disputes
  - name: Events
  - name: Exports
  - name: Files
  - name: Invoices
  - name: Letters
  - name: Orders
  - name: Payment Intents
  - name: Payment Links
  - name: Payouts
  - name: Prices
  - name: Products
  - name: Promo Codes
  - name: Receipts
  - name: Refunds
  - name: Setup Intents
  - name: Shipping Rates
  - name: Subscriptions
paths:
  /v1/checkout/sessions/{id}/refund_allocation:
    post:
      tags:
        - Checkout Sessions
      summary: Preview Refund Allocation
      description: >-
        Computes how a refund would be allocated across the Checkout Session's
        payment methods,

        without executing any refund. Takes the same request body as the refund
        endpoint and

        returns the per-payment-method allocations so you can preview a
        split-cart refund before

        committing.
      operationId: v1.checkout_sessions.preview_refund_allocation
      parameters:
        - in: path
          name: id
          required: true
          schema:
            examples:
              - fcs_01J9XR8M3K7VZ8N2YB4WJ6T0RA
            type: string
          style: simple
          example: fcs_01J9XR8M3K7VZ8N2YB4WJ6T0RA
      requestBody:
        description: An envelope wrapping a single checkout session object.
        content:
          application/json:
            schema:
              $ref: >-
                #/components/schemas/CheckoutSessionBody_for_RefundCheckoutSessionRequest
            example:
              checkout_session:
                line_items: []
        required: true
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RefundAllocationResponse'
              example:
                allocations:
                  - payment_method_id: fpm_01J9XR8M3K7VZ8N2YB4WJ6T0RA
                    last4: '4242'
                    amount: 2500
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HttpErrorOut'
              example:
                code: string
                detail: string
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HttpErrorOut'
              example:
                code: string
                detail: string
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HttpErrorOut'
              example:
                code: string
                detail: string
        '409':
          description: Conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HttpErrorOut'
              example:
                code: string
                detail: string
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
              example:
                detail:
                  - loc:
                      - string
                    msg: string
                    type: string
        '429':
          description: Too Many Requests
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HttpErrorOut'
              example:
                code: string
                detail: string
      security:
        - BearerAuth:
            - checkout_sessions:write
components:
  schemas:
    CheckoutSessionBody_for_RefundCheckoutSessionRequest:
      description: An envelope wrapping a single checkout session object.
      type: object
      required:
        - checkout_session
      properties:
        checkout_session:
          $ref: '#/components/schemas/RefundCheckoutSessionRequest'
          description: The checkout session payload.
      example:
        checkout_session:
          line_items: []
    RefundAllocationResponse:
      description: >-
        Preview of how a refund would be distributed across the session's
        payment methods.
      type: object
      required:
        - allocations
      properties:
        allocations:
          description: >-
            The computed refund amount allocated to each payment method. No
            refund is executed.
          type: array
          items:
            $ref: '#/components/schemas/RefundAllocation'
      example:
        allocations:
          - payment_method_id: fpm_01J9XR8M3K7VZ8N2YB4WJ6T0RA
            last4: '4242'
            amount: 2500
    HttpErrorOut:
      title: HttpError
      description: The error response returned when a request cannot be completed.
      type: object
      required:
        - code
        - detail
      properties:
        code:
          description: A short machine-readable error code identifying the type of error.
          type: string
        detail:
          description: A human-readable explanation of what went wrong.
          type: string
      example:
        code: string
        detail: string
    HTTPValidationError:
      description: The error response returned when request validation fails (HTTP 422).
      type: object
      required:
        - detail
      properties:
        detail:
          description: The list of validation errors, one entry per invalid field.
          type: array
          items:
            $ref: '#/components/schemas/ValidationErrorItem'
      example:
        detail:
          - loc:
              - string
            msg: string
            type: string
    RefundCheckoutSessionRequest:
      description: >-
        Parameters for refunding a Checkout Session. Specify what to refund
        either by `line_items` or by a total `amount`; omit both to refund the
        full remaining amount.
      type: object
      example:
        line_items:
          - {}
      properties:
        refund_metadata:
          description: >-
            Set of key-value pairs to set on the Checkout Session's `metadata`
            when the refund succeeds. `null` to leave the session metadata
            unchanged.
          type:
            - object
            - 'null'
          additionalProperties:
            type: string
          example:
            order_id: '8842'
            channel: shopify
        amount_tax:
          description: >-
            Portion of the refund attributable to tax, in the smallest currency
            unit (e.g., `175` = $1.75 USD).
          type:
            - integer
            - 'null'
          format: int32
          example: 2500
        amount_shipping:
          description: >-
            Portion of the refund attributable to shipping, in the smallest
            currency unit (e.g., `599` = $5.99 USD).
          type:
            - integer
            - 'null'
          format: int32
          example: 2500
        amount_discount:
          description: >-
            Portion of the refund attributable to discounts, in the smallest
            currency unit (e.g., `500` = $5.00 USD).
          type:
            - integer
            - 'null'
          format: int32
          example: 2500
        payment_methods:
          description: >-
            Explicit allocation to specific payment methods. When provided,
            bypasses automatic HSA-based allocation and refunds exact amounts to
            each payment method. This feature is currently in beta. Contact the
            Flex team to request access.
          type:
            - array
            - 'null'
          items:
            $ref: '#/components/schemas/PaymentMethodRefundRequest'
        line_items:
          description: The line items to refund, with the amount to refund for each.
          type: array
          items:
            $ref: '#/components/schemas/LineItemRefundRequest'
        amount:
          description: >-
            The total amount to refund, in the smallest currency unit (e.g.,
            `2500` = $25.00 USD).
          type: integer
          format: int64
          minimum: 0
          maximum: 4294967295
    RefundAllocation:
      description: How much of a refund is allocated to a specific payment method.
      type: object
      required:
        - amount
        - last4
        - payment_method_id
      properties:
        payment_method_id:
          description: >-
            ID of the PaymentMethod this portion of the refund would be returned
            to.
          type: string
          example: fpm_01J9XR8M3K7VZ8N2YB4WJ6T0RA
        last4:
          description: >-
            Last four digits of the payment method's card, for display. Falls
            back to `"unknown"` if it cannot be resolved.
          type: string
          example: '4242'
        amount:
          description: >-
            Amount that would be refunded to this payment method, in the
            smallest currency unit (e.g., `2500` = $25.00 USD).
          type: integer
          format: int64
          example: 2500
      example:
        payment_method_id: fpm_01J9XR8M3K7VZ8N2YB4WJ6T0RA
        last4: '4242'
        amount: 2500
    ValidationErrorItem:
      description: >-
        Validation errors have their own schema to provide context for invalid
        requests eg. mismatched types and out of bounds values. There may be any
        number of these per 422 UNPROCESSABLE ENTITY error.
      type: object
      required:
        - loc
        - msg
        - type
      properties:
        loc:
          description: >-
            The location as a [`Vec`] of [`String`]s -- often in the form
            `["body", "field_name"]`, `["query", "field_name"]`, etc. They may,
            however, be arbitarily deep.
          type: array
          items:
            type: string
        msg:
          description: The message accompanying the validation error item.
          type: string
        type:
          description: >-
            The type of error, often "type_error" or "value_error", but
            sometimes with more context like as "value_error.number.not_ge"
          type: string
      example:
        loc:
          - string
        msg: string
        type: string
    PaymentMethodRefundRequest:
      description: >-
        Request to refund a specific amount to a specific payment method.


        When multiple `PaymentMethodRefundRequest` entries have the same
        `payment_method_id`, their amounts are aggregated during validation.


        # Fields * `payment_method_id` - The payment method to refund to *
        `amount` - Amount to refund in cents (must be non-negative)
      type: object
      required:
        - amount
        - payment_method_id
      properties:
        payment_method_id:
          description: ID of the PaymentMethod to refund to.
          type: string
          example: fpm_01J9XR8M3K7VZ8N2YB4WJ6T0RA
        amount:
          description: >-
            Amount to refund to this payment method, in the smallest currency
            unit (e.g., `2500` = $25.00 USD). Must be non-negative.
          type: integer
          format: int32
          example: 2500
      example:
        payment_method_id: fpm_01J9XR8M3K7VZ8N2YB4WJ6T0RA
        amount: 2500
    LineItemRefundRequest:
      description: Identifies a single line item to refund and how much of it to refund.
      type: object
      example:
        product: fprod_01J9XR8M3K7VZ8N2YB4WJ6T0RA
      properties:
        amount_to_refund:
          description: >-
            The amount to refund for this line item, in the smallest currency
            unit (e.g., `2500` = $25.00 USD). Omit to refund the full amount for
            the item.
          type:
            - integer
            - 'null'
          format: int64
          minimum: 0
          maximum: 4294967295
          example: 2500
        product:
          type: string
          example: fprod_01J9XR8M3K7VZ8N2YB4WJ6T0RA
          description: ID of the Product identifying the line item.
        price:
          type: string
          example: fprice_01J9XR8M3K7VZ8N2YB4WJ6T0RA
          description: ID of the Price identifying the line item.
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: Use a Bearer token to access this API.

````