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

# Retrieve a subscription's upcoming invoice

> Estimates the next invoice: fees billed up front for the next period, plus fees billed at the end and usage so far for the current one. On a trial, the conversion invoice; with a cancellation scheduled, the final invoice. Returns `404 no_upcoming_invoice` for a subscription that has ended, is paused, or hasn't started, or whose retired plan has no successor (it pauses at the boundary). Plan changes scheduled for the boundary, the next Pricing Journey step, and a plan retirement's move to its successor are applied.



## OpenAPI

````yaml /api/openapi.yaml get /subscriptions/{subscription}/upcoming-invoice
openapi: 3.1.0
info:
  title: Bouclay API
  version: 1.0.0
  summary: Integrator API for Bouclay subscriptions, invoices, payments, and webhooks.
  description: >
    Bouclay is managed recurring-billing infrastructure for African payment

    gateways. Integrators connect their own gateway account (Bachs, with Nomba,

    Paystack and Flutterwave in early access) and use this API to manage
    customers, catalog, subscriptions,

    entitlements, usage metering, invoices, payment-method checkout sessions,
    payments, and

    outbound event history.


    Bouclay never holds funds — every charge, refund, and payout happens on your

    own gateway account, with your own keys. Which gateway settles a given
    charge

    is Bouclay's concern, not yours: a stored card always charges through the

    gateway that issued its token.


    ## Early access


    Some of this API is documented ahead of its release, so you can build

    against it now. Those operations carry an **Early access** badge, and so

    do the request fields that depend on them (graduated, volume and package

    pricing, usage-based prices, usage thresholds). Until a feature is turned

    on for your account, its endpoints answer `404 not_found`, its fields are

    refused with a `422`, and a restricted key cannot be given its scopes.

    Ask us to turn it on. Nothing you already rely on changes when it is.
servers:
  - url: https://bouclay.com/api/v1
    description: Production
security:
  - SecretKeyAuth: []
tags:
  - name: Customers
  - name: Customer addresses
  - name: Payment methods
  - name: Entitlements
    description: >-
      Early access: answers `404 not_found` until it is turned on for your
      account.
  - name: Credits
    description: >-
      What a customer has left to spend. Money owed back to a customer is their
      balance, one per currency; their next invoice spends it after tax, like a
      payment, and collects the rest. Promotional credit you give is held in
      lots (credit grants), each with its own expiry; the next invoice spends it
      before tax, so it lowers the VAT like a discount.
  - name: Catalog
  - name: Payment links
    description: >-
      A shareable checkout page for one price, the same link a price's "Payment
      link" makes in the dashboard. Buyers enter their email and pay; a
      subscription price starts the subscription once paid.
  - name: Meters
    description: >-
      Early access: answers `404 not_found` until it is turned on for your
      account.
  - name: Usage
    description: >-
      Early access: answers `404 not_found` until it is turned on for your
      account.
  - name: Discounts
    description: >-
      Early access: answers `404 not_found` until it is turned on for your
      account.
  - name: Subscriptions
  - name: Invoices
  - name: Metrics
    description: >-
      Early access: answers `404 not_found` until it is turned on for your
      account. Revenue metrics measured from each subscription's monthly
      recurring amount (MRR). `active` and `past_due` subscriptions count;
      trials, pauses and metered usage do not. Amounts are major units, rates
      are percentages (105.25 means 105.25%), and currencies are never summed.
  - name: Credit notes
    description: >-
      A credit note corrects an issued invoice without changing it: "of this
      invoice, this much is no longer owed". Each one has its own number in an
      unbroken sequence (`{prefix}-CN-0001`) and never changes once issued. On
      an unpaid invoice the credit comes off `amountDue`; on a paid one it goes
      back to the customer, refunded to the card, added to the customer balance
      or settled outside Bouclay. What the customer balance paid of an invoice
      always goes back to the balance first. An invoice always satisfies
      `amountDue = total - amountPaid - amountCredited - balanceApplied`. Every
      refund also issues a credit note.
  - name: Payments
  - name: Refunds
    description: >-
      A refund goes back through the gateway that took the payment. Refund part
      of a payment and it stays `succeeded`; refund all of it and it becomes
      `refunded`.
  - name: Chargebacks
    description: >-
      A chargeback is a payment the customer's bank took back. Record one when
      your payment provider reports it, with the provider's dispute reference,
      then record how the dispute ended. While it is open, Bouclay doesn't
      charge or chase the subscription. A chargeback on a credit top-up takes
      back the unspent credit and its bonus; winning the dispute puts back
      exactly that. Uses the `refunds` scope.
  - name: Events
  - name: Checkout sessions
  - name: Portal sessions
  - name: Webhook endpoints
paths:
  /subscriptions/{subscription}/upcoming-invoice:
    parameters:
      - $ref: '#/components/parameters/SubscriptionId'
    get:
      tags:
        - Subscriptions
      summary: Retrieve a subscription's upcoming invoice
      description: >-
        Estimates the next invoice: fees billed up front for the next period,
        plus fees billed at the end and usage so far for the current one. On a
        trial, the conversion invoice; with a cancellation scheduled, the final
        invoice. Returns `404 no_upcoming_invoice` for a subscription that has
        ended, is paused, or hasn't started, or whose retired plan has no
        successor (it pauses at the boundary). Plan changes scheduled for the
        boundary, the next Pricing Journey step, and a plan retirement's move to
        its successor are applied.
      operationId: retrieveUpcomingInvoice
      responses:
        '200':
          description: The estimate.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/ResourceEnvelope'
                  - type: object
                    properties:
                      data:
                        $ref: '#/components/schemas/UpcomingInvoice'
        '404':
          $ref: '#/components/responses/Error'
components:
  parameters:
    SubscriptionId:
      name: subscription
      in: path
      required: true
      schema:
        type: string
      example: sub_123
  schemas:
    ResourceEnvelope:
      type: object
      required:
        - data
        - meta
      properties:
        data:
          type: object
        meta:
          $ref: '#/components/schemas/Meta'
    UpcomingInvoice:
      type: object
      description: >-
        The next invoice a subscription will receive, estimated on read and
        never stored. Built from the same lines and pricing as the real one;
        usage is priced as measured so far.
      properties:
        object:
          type: string
          enum:
            - upcoming_invoice
        subscription:
          type: string
        currency:
          type: string
        boundary:
          type: string
          format: date-time
          description: >-
            The period end, trial end, or scheduled cancellation this invoice
            belongs to.
        billsAt:
          type: string
          format: date-time
          description: >-
            When the invoice will be created, after the usage grace window when
            usage is billed.
        isFinal:
          type: boolean
          description: True when a cancellation is scheduled and this is the last invoice.
        subtotal:
          $ref: '#/components/schemas/MajorAmount'
        discountTotal:
          $ref: '#/components/schemas/MajorAmount'
        grantApplied:
          $ref: '#/components/schemas/MajorAmount'
          description: >-
            Credit it would spend before tax (promotional, and prepaid taxed
            when bought), at what the customer holds today.
        taxTotal:
          $ref: '#/components/schemas/MajorAmount'
        taxes:
          type: array
          items:
            $ref: '#/components/schemas/InvoiceTax'
        total:
          $ref: '#/components/schemas/MajorAmount'
        minimumCommitment:
          $ref: '#/components/schemas/MinimumCommitmentCheck'
        spendingCap:
          description: >-
            The period's spending cap and what it has spent so far, usage not
            yet billed included. Null without a cap.
          type:
            - object
            - 'null'
          properties:
            amount:
              type: number
              description: >-
                The period's cap, in major units. Less only when the period was
                cut short by a cancellation or paused for part of it.
            spent:
              type: number
              description: >-
                What the period has spent toward it, after discounts and before
                tax, before anything is taken back.
            behavior:
              type: string
              enum:
                - cap
                - warn
            takenBack:
              type: number
              description: >-
                What the invoice's `maximum` lines take off. Always 0 for a cap
                that only warns.
        lines:
          type: array
          items:
            type: object
            properties:
              description:
                type: string
              kind:
                type: string
                enum:
                  - plan
                  - addon
                  - usage
                  - credit
                  - minimum
                  - maximum
              billingTiming:
                type: string
                enum:
                  - advance
                  - arrears
              periodStart:
                type: string
                format: date-time
              periodEnd:
                type:
                  - string
                  - 'null'
                format: date-time
              price:
                type:
                  - string
                  - 'null'
              quantity:
                type: integer
              usageQuantity:
                type:
                  - integer
                  - 'null'
              meter:
                type:
                  - string
                  - 'null'
              amount:
                $ref: '#/components/schemas/MajorAmount'
              discountAmount:
                $ref: '#/components/schemas/MajorAmount'
              grantApplied:
                $ref: '#/components/schemas/MajorAmount'
              total:
                $ref: '#/components/schemas/MajorAmount'
    Meta:
      type: object
      required:
        - requestId
      properties:
        requestId:
          type: string
          example: req_550e8400-e29b-41d4-a716-446655440000
    MajorAmount:
      type:
        - number
        - 'null'
      minimum: 0
      description: Major currency units. For example, 15000 means NGN 15,000.
    InvoiceTax:
      type: object
      description: >-
        One tax rate on an invoice, as it is printed: added on top of the
        subtotal, or included in the prices (VAT-inclusive pricing).
      properties:
        name:
          type: string
          example: VAT
        rate:
          type:
            - number
            - 'null'
          description: The rate as a percentage. Null for tax that came without a rate.
          example: 7.5
        reason:
          type:
            - string
            - 'null'
          description: >-
            Why the rate applies, when it needs saying. For example, `export of
            services` on a zero-rated export, printed as "VAT (0%, export of
            services)".
        inclusive:
          type: boolean
          description: >-
            True when the tax is inside the line amounts rather than added on
            top.
        amount:
          $ref: '#/components/schemas/MajorAmount'
    MinimumCommitmentCheck:
      type:
        - object
        - 'null'
      description: >-
        The minimum commitment the invoice held the period it closes to. Null
        when the subscription had none for the period. On an upcoming invoice,
        what counted so far.
      properties:
        amount:
          type: number
          description: >-
            The period's minimum, in major units, prorated for the part of the
            period it applied (a mid-period change, a pause, a cancellation).
        counted:
          type: number
          description: >-
            What the period billed toward it, this invoice included: fees,
            usage, prorations and credits, after discounts and before tax.
        shortfall:
          type: number
          description: What the invoice's `minimum` lines bill, `max(0, amount - counted)`.
    ErrorResponse:
      type: object
      required:
        - error
        - meta
      properties:
        error:
          type: object
          required:
            - type
            - code
            - detail
          properties:
            type:
              type: string
              enum:
                - request_error
                - api_error
              description: >-
                `api_error` with code `internal_error` (HTTP 500) means the
                fault is ours: retry with the same Idempotency-Key.
              example: request_error
            code:
              type: string
              enum:
                - authentication_failed
                - permission_denied
                - invalid_field
                - invalid_cursor
                - idempotency_conflict
                - meter_not_found
                - meter_archived
                - customer_not_found
                - timestamp_in_future
                - usage_period_closed
                - subscription_paused
                - missing_property
                - invalid_value
                - conflict
                - subscription_suspended
                - no_upcoming_invoice
                - not_found
                - request_error
                - internal_error
            detail:
              type: string
            errors:
              type: array
              items:
                type: object
                required:
                  - field
                  - message
                properties:
                  field:
                    type: string
                  message:
                    type: string
        meta:
          $ref: '#/components/schemas/Meta'
  responses:
    Error:
      description: Structured API error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    SecretKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: '{sk|rk}_{mode}_{random}'
      description: >
        Use a Bouclay secret key (`sk_test_...`, `sk_live_...`) or restricted
        key

        (`rk_test_...`, `rk_live_...`).


        A secret key can call every endpoint. A restricted key can only call the

        endpoints its scopes cover. A scope is `{resource}:{access}`, for
        example

        `customers:read` or `refunds:write`, and write includes read. `GET`

        requests need read access and everything else needs write, except

        `POST /subscriptions/{id}/items/{item}/preview`, which only needs

        `subscriptions:read`. A request outside the key's scopes gets `403

        permission_denied` naming the missing scope, and its `Idempotency-Key`

        is not used up.


        | Resource | Endpoints | Access |

        | --- | --- | --- |

        | `customers` | customers, their addresses and payment methods | read,
        write |

        | `entitlements` | `/customers/{id}/entitlements` | read |

        | `credits` | `/customers/{id}/credit-balance`, credit purchases, credit
        grants, auto-reloads, credit holds (committing one records its usage) |
        read, write |

        | `catalog` | products, plans, prices | read, write |

        | `meters` | meters | read, write |

        | `usage` | meter events, `/customers/{id}/usage` | read, write |

        | `discounts` | discounts | read |

        | `subscriptions` | subscriptions | read, write |

        | `invoices` | invoices | read, write |

        | `credit_notes` | credit notes, `POST /invoices/{id}/credit-notes` (a
        refund to the card also needs `refunds:write`) | read, write |

        | `payments` | payments | read |

        | `refunds` | refunds, `POST /payments/{id}/refunds`, chargebacks and
        their outcome | read, write |

        | `checkout_sessions` | checkout sessions | read, write |

        | `portal_sessions` | portal sessions | write |

        | `events` | events | read |

        | `webhook_endpoints` | webhook endpoints | read, write |

        | `metrics` | metrics | read |


        Publishable keys (`pk_...`) are rejected by server-side API endpoints. A

        key's mode scopes what it can see and charge: a test key can never reach

        a live card.

````

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