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

# Validate a discount code against the cart

> Server-side quote using the same function as checkout (variant/method price → discount → VAT). For several lines the discount is computed once per cart and split proportionally over the lines the code covers (`lines[].discountShare`, adding up to the cent). An invalid code is `valid: false`, not an error. Does not reserve a code use.



## OpenAPI

````yaml /openapi.en.json post /api/v2/storefront/v1/shops/{shopId}/discounts/validate
openapi: 3.0.0
info:
  title: ItemShop v2 API
  description: >-
    REST API platformy ItemShop v2 (NestJS + Fastify). Wszystkie ścieżki mają
    prefiks /api/v2.
  version: 2.0.0
  contact: {}
servers:
  - url: https://itemshop.dev
    description: Production (API under /api/v2, same origin as the panel)
  - url: http://localhost:3000
    description: Local
security: []
tags: []
paths:
  /api/v2/storefront/v1/shops/{shopId}/discounts/validate:
    post:
      tags:
        - Storefront v1
      summary: Validate a discount code against the cart
      description: >-
        Server-side quote using the same function as checkout (variant/method
        price → discount → VAT). For several lines the discount is computed once
        per cart and split proportionally over the lines the code covers
        (`lines[].discountShare`, adding up to the cent). An invalid code is
        `valid: false`, not an error. Does not reserve a code use.
      operationId: validateDiscount
      parameters:
        - name: shopId
          required: true
          in: path
          description: >-
            Shop ID (ObjectId). Also accepts the `uniqueName`, an active custom
            domain or `<uniqueName>.<hosting domain>`.
          schema:
            type: string
            example: 664f1a2b3c4d5e6f7a8b9c0d
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/StorefrontValidateDiscountDto'
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StorefrontDiscountQuoteResponseDto'
        '400':
          description: >-
            `VALIDATION_FAILED`, `CART_EMPTY`, `CART_TOO_LARGE`,
            `INVALID_QUANTITY`, `PRODUCT_VARIANT_REQUIRED`…
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StorefrontErrorDto'
        '403':
          description: Origin outside the shop domains (`ORIGIN_NOT_ALLOWED`)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StorefrontErrorDto'
        '404':
          description: >-
            Shop/resource not found or the shop is blocked (`SHOP_NOT_FOUND`,
            `PRODUCT_NOT_FOUND`, `ORDER_NOT_FOUND`)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StorefrontErrorDto'
        '429':
          description: Rate limit exceeded (`RATE_LIMITED`)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StorefrontErrorDto'
components:
  schemas:
    StorefrontValidateDiscountDto:
      type: object
      properties:
        code:
          type: string
          minLength: 1
          maxLength: 50
          pattern: ^[A-Za-z0-9_-]+$
          example: LATO10
        items:
          minItems: 1
          maxItems: 20
          description: >-
            Cart lines (1–20). Several lines = a payment group: one order per
            line and one payment for the total (adr/0002)
          type: array
          items:
            $ref: '#/components/schemas/StorefrontCartItemDto'
        paymentMethodCode:
          type: string
          minLength: 1
          maxLength: 100
          description: Payment method — the product may have a different price for it
          example: imoje
      required:
        - code
        - items
    StorefrontDiscountQuoteResponseDto:
      type: object
      properties:
        success:
          type: boolean
          example: true
        data:
          $ref: '#/components/schemas/StorefrontDiscountQuoteDto'
      required:
        - success
        - data
    StorefrontErrorDto:
      type: object
      properties:
        success:
          type: boolean
          example: false
        statusCode:
          type: number
          example: 404
        code:
          enum:
            - VALIDATION_FAILED
            - BAD_REQUEST
            - NOT_FOUND
            - SHOP_NOT_FOUND
            - PRODUCT_NOT_FOUND
            - ORDER_NOT_FOUND
            - PRODUCT_UNAVAILABLE
            - PRODUCT_VARIANT_REQUIRED
            - INVALID_PRODUCT_VARIANT
            - INVALID_QUANTITY
            - OUT_OF_STOCK
            - CART_EMPTY
            - NICK_REQUIRED
            - EMAIL_REQUIRED
            - CART_TOO_LARGE
            - DISCOUNT_INVALID
            - LEGAL_CONSENT_REQUIRED
            - LEGAL_DOCUMENTS_CHANGED
            - SHOP_PAYMENT_NOT_READY
            - PAYMENT_INIT_FAILED
            - ORDER_BLOCKED
            - RETURN_URL_NOT_ALLOWED
            - VOUCHER_NOT_FOUND
            - VOUCHER_USED
            - VOUCHER_EXPIRED
            - IDEMPOTENCY_KEY_REQUIRED
            - IDEMPOTENCY_KEY_REUSED
            - CHECKOUT_ATTEMPT_CLOSED
            - CHECKOUT_IN_PROGRESS
            - CAPTCHA_REQUIRED
            - ORIGIN_NOT_ALLOWED
            - FORBIDDEN
            - UNAUTHORIZED
            - PAYLOAD_TOO_LARGE
            - CONFLICT
            - RATE_LIMITED
            - SERVICE_UNAVAILABLE
            - INTERNAL_ERROR
          type: string
          description: Machine-readable error code — translate UI messages by this
          example: SHOP_NOT_FOUND
        message:
          type: string
          description: >-
            Developer message (language not guaranteed; do not show it to
            buyers)
          example: Shop not found
        error:
          type: string
          description: Same as `message` (compatibility with the rest of the API)
          example: Shop not found
          deprecated: true
        details:
          type: object
          description: Validation details
        timestamp:
          type: string
          format: date-time
          example: '2026-10-27T12:00:00.000Z'
        path:
          type: string
          example: /api/v2/storefront/v1/shops/moj-sklep
      required:
        - success
        - statusCode
        - code
        - message
        - error
        - timestamp
        - path
    StorefrontCartItemDto:
      type: object
      properties:
        productId:
          type: string
          example: 664f1a2b3c4d5e6f7a8b9c0d
        quantity:
          type: number
          minimum: 1
          maximum: 100000
          example: 1
          default: 1
        variantId:
          type: string
          description: >-
            `variants[].id` (one of variantId/variant required when pricingMode
            = variants)
          example: 664f1a2b3c4d5e6f7a8b9c11
        variant:
          type: string
          minLength: 1
          maxLength: 80
          description: Variant name (instead of variantId)
          example: 30 dni
      required:
        - productId
    StorefrontDiscountQuoteDto:
      type: object
      properties:
        valid:
          type: boolean
          example: true
        code:
          type: string
          nullable: true
          example: LATO10
        reason:
          type: string
          nullable: true
          description: Rejection reason (for developers)
          example: null
        subtotal:
          type: number
          description: Total before discount
          example: 39.98
        discountAmount:
          type: number
          example: 4
        total:
          type: number
          description: Amount due (after discount and VAT) — exactly what checkout charges
          example: 35.98
        currency:
          type: string
          example: PLN
        lines:
          description: Per-line quote in `items[]` order; the line totals add up to `total`
          type: array
          items:
            $ref: '#/components/schemas/StorefrontQuoteLineDto'
      required:
        - valid
        - code
        - reason
        - subtotal
        - discountAmount
        - total
        - currency
        - lines
    StorefrontQuoteLineDto:
      type: object
      properties:
        productId:
          type: string
          example: 664f1a2b3c4d5e6f7a8b9c0d
        subtotal:
          type: number
          description: Before discount
          example: 19.99
        discountShare:
          type: number
          description: >-
            This line's share of the cart discount (proportional to value, to
            the cent)
          example: 2
        total:
          type: number
          description: Amount due for the line (after discount and VAT)
          example: 17.99
      required:
        - productId
        - subtotal
        - discountShare
        - total

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.