{
  "openapi": "3.1.1",
  "info": {
    "title": "Invoices",
    "description": "Endpoints for partners that create B2B invoice orders through Entur.",
    "termsOfService": "https://developer.entur.no/terms-of-service",
    "contact": {
      "name": "Entur Team Betaling",
      "url": "https://enturas.atlassian.net/wiki/spaces/TB1/overview",
      "email": "teambetaling@entur.org"
    },
    "version": "2026.11.3",
    "x-stability-level": "beta"
  },
  "servers": [
    {
      "url": "https://api.entur.io/sales",
      "description": "Entur's Production environment"
    },
    {
      "url": "https://api.staging.entur.io/sales",
      "description": "Entur's Staging environment"
    },
    {
      "url": "https://api.dev.entur.io/sales",
      "description": "Entur's Development environment"
    }
  ],
  "security": [
    {
      "jwt": []
    }
  ],
  "tags": [
    {
      "name": "B2B Invoices",
      "description": "B2B invoice operations for partners"
    }
  ],
  "paths": {
    "/v1/b2b/credit-check/{organisationNumber}": {
      "get": {
        "tags": [
          "B2B Invoices"
        ],
        "summary": "Check credit for a business customer",
        "description": "Checks whether a company is approved for invoice purchases and returns its available credit limit. The invoice provider may reject invoice creation if the purchase amount exceeds the company's available credit. Calling this before creating a B2B invoice is optional, but recommended to avoid a failed invoice creation.",
        "operationId": "getCreditCheck",
        "parameters": [
          {
            "$ref": "#/components/parameters/organisationNumber"
          }
        ],
        "responses": {
          "200": {
            "description": "Credit check result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreditCheckResponse"
                },
                "examples": {
                  "approved": {
                    "summary": "Company approved for invoice purchases",
                    "value": {
                      "organisationNumber": "817352812",
                      "companyName": "MONOZUKI AS",
                      "approved": true,
                      "currency": "NOK",
                      "availableLimit": "487160.62",
                      "perOrderLimit": "487160.62"
                    }
                  },
                  "declined": {
                    "summary": "Company declined",
                    "value": {
                      "organisationNumber": "817352812",
                      "companyName": "MONOZUKI AS",
                      "approved": false,
                      "declineReasons": [
                        "TOO_HIGH_RISK"
                      ],
                      "currency": "NOK",
                      "availableLimit": "0.00",
                      "perOrderLimit": "0.00"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/badRequest"
          },
          "401": {
            "$ref": "#/components/responses/unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/forbidden"
          },
          "404": {
            "$ref": "#/components/responses/notFound"
          },
          "500": {
            "$ref": "#/components/responses/internalServerError"
          }
        },
        "x-entur-permissions": {
          "value": "invoice.partner.invoices:les"
        }
      },
      "parameters": [
        {
          "$ref": "#/components/parameters/ET-Client-Name"
        },
        {
          "$ref": "#/components/parameters/X-Correlation-Id"
        }
      ]
    },
    "/v1/b2b/invoices": {
      "post": {
        "tags": [
          "B2B Invoices"
        ],
        "summary": "Create a B2B invoice",
        "description": "Creates a B2B invoice for an existing Entur order. The request must reference a payment transaction (via `paymentId` and `transactionId`) that was created in Entur's payment service with payment type `TWO_B2B` or `TWO_B2B_CONSOLIDATED`. The payment type determines how the invoice is issued: `TWO_B2B` invoices are issued immediately, while `TWO_B2B_CONSOLIDATED` invoices are created as drafts and not issued to the buyer until they are included in a consolidated invoice (see the consolidated invoices endpoint). Unless a separate agreement with Entur and the invoice provider has been made for the partner to handle buyer verification independently, the buyer must verify the purchase by navigating to the returned `paymentUrl`.",
        "operationId": "createB2bInvoice",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/B2bInvoiceRequest"
              },
              "examples": {
                "with-optional-fields": {
                  "summary": "Create a B2B invoice with optional buyer fields",
                  "value": {
                    "orderId": "CPPT96C8",
                    "redirectUrl": "https://partner-app.example.com/payment/complete",
                    "paymentId": 436801,
                    "transactionId": 123123321,
                    "organisationNumber": "817352812",
                    "buyerInfo": {
                      "firstName": "Ola",
                      "lastName": "Nordmann",
                      "email": "ola.nordmann@acme.org",
                      "phoneNumber": "+4749999999",
                      "department": "Sales Dpt",
                      "project": "Some project",
                      "reference": "PO-12345"
                    }
                  }
                },
                "minimal": {
                  "summary": "Create a B2B invoice with required fields only",
                  "value": {
                    "orderId": "CPPT96C8",
                    "redirectUrl": "https://partner-app.example.com/payment/complete",
                    "paymentId": 436801,
                    "transactionId": 123123321,
                    "organisationNumber": "817352812",
                    "buyerInfo": {
                      "firstName": "Ola",
                      "lastName": "Nordmann",
                      "email": "ola.nordmann@acme.org",
                      "phoneNumber": "+4749999999"
                    }
                  }
                }
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "description": "B2B invoice created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/B2bInvoiceCreateResponse"
                },
                "examples": {
                  "created": {
                    "summary": "B2B invoice created successfully",
                    "value": {
                      "paymentUrl": "https://checkout.two.inc/mi/order/dLBPjwCr6UTf5nS9setTSv40UqSjDsE",
                      "invoiceId": 900001
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/createInvoiceBadRequest"
          },
          "401": {
            "$ref": "#/components/responses/unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/createInvoiceForbidden"
          },
          "500": {
            "$ref": "#/components/responses/internalServerError"
          }
        },
        "x-entur-permissions": {
          "value": "invoice.partner.invoices:opprett"
        }
      },
      "parameters": [
        {
          "$ref": "#/components/parameters/ET-Client-Name"
        },
        {
          "$ref": "#/components/parameters/X-Correlation-Id"
        }
      ]
    },
    "/v1/b2b/invoices/{invoiceId}": {
      "get": {
        "tags": [
          "B2B Invoices"
        ],
        "summary": "Get a B2B invoice",
        "description": "Returns a B2B invoice order belonging to the caller's organisation, with its status, lines and fees.",
        "operationId": "getB2bInvoice",
        "parameters": [
          {
            "$ref": "#/components/parameters/invoiceId"
          }
        ],
        "responses": {
          "200": {
            "description": "The invoice",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/B2bInvoiceResponse"
                },
                "examples": {
                  "invoiced": {
                    "summary": "Invoice invoiced on its own",
                    "value": {
                      "invoiceId": 900001,
                      "orderId": "CPPT96C8",
                      "invoiceType": "TWO_B2B",
                      "status": "INVOICED",
                      "totalAmount": "948.00",
                      "currency": "NOK",
                      "invoiceLines": [
                        {
                          "id": 212345,
                          "orderLineId": "83c87fa0-062a-471a-a840-6296717edefc",
                          "productDescription": "Vy Ordinær Stavanger stasjon - Bergen stasjon",
                          "quantity": 1,
                          "amount": "899.00",
                          "taxAmount": "96.32",
                          "taxRate": "12",
                          "operation": "CHARGE",
                          "createdAt": "2026-10-06T08:15:30Z",
                          "updatedAt": "2026-10-06T08:15:30Z"
                        }
                      ],
                      "invoiceFees": [
                        {
                          "orderFeeId": "44c5af69-6ab0-0b5a-8c31-2dc8a78c2abe",
                          "description": "Fakturagebyr",
                          "feeType": "INVOICE",
                          "orderLineIds": [
                            "83c87fa0-062a-471a-a840-6296717edefc"
                          ],
                          "amount": "49.00",
                          "taxAmount": "9.80",
                          "taxRate": "25",
                          "currency": "NOK",
                          "operation": "CHARGE"
                        }
                      ],
                      "createdAt": "2026-10-06T08:15:30Z",
                      "updatedAt": "2026-10-06T08:16:02Z"
                    }
                  },
                  "partially-credited": {
                    "summary": "Invoice where one of two lines has been credited",
                    "value": {
                      "invoiceId": 900001,
                      "orderId": "CPPT96C8",
                      "invoiceType": "TWO_B2B",
                      "status": "PARTIALLY_CREDITED",
                      "totalAmount": "948.00",
                      "currency": "NOK",
                      "invoiceLines": [
                        {
                          "id": 212345,
                          "orderLineId": "83c87fa0-062a-471a-a840-6296717edefc",
                          "productDescription": "Vy Ordinær Stavanger stasjon - Bergen stasjon",
                          "quantity": 1,
                          "amount": "899.00",
                          "taxAmount": "96.32",
                          "taxRate": "12",
                          "operation": "CHARGE",
                          "createdAt": "2026-10-06T08:15:30Z",
                          "updatedAt": "2026-10-06T08:15:30Z"
                        },
                        {
                          "id": 212346,
                          "orderLineId": "a709853e-9de1-4bb5-a7dc-e01b3d267cd0",
                          "productDescription": "Vy Ordinær Stavanger stasjon - Bergen stasjon",
                          "quantity": 1,
                          "amount": "899.00",
                          "taxAmount": "96.32",
                          "taxRate": "12",
                          "operation": "CHARGE",
                          "createdAt": "2026-10-06T08:15:30Z",
                          "updatedAt": "2026-10-06T08:15:30Z"
                        },
                        {
                          "id": 212399,
                          "orderLineId": "83c87fa0-062a-471a-a840-6296717edefc",
                          "productDescription": "Vy Ordinær Stavanger stasjon - Bergen stasjon",
                          "quantity": 1,
                          "amount": "-899.00",
                          "taxAmount": "-96.32",
                          "taxRate": "12",
                          "operation": "CREDIT",
                          "createdAt": "2026-10-12T10:02:11Z",
                          "updatedAt": "2026-10-12T10:02:11Z"
                        }
                      ],
                      "invoiceFees": [
                        {
                          "orderFeeId": "44c5af69-6ab0-0b5a-8c31-2dc8a78c2abe",
                          "description": "Fakturagebyr",
                          "feeType": "INVOICE",
                          "orderLineIds": [
                            "83c87fa0-062a-471a-a840-6296717edefc"
                          ],
                          "amount": "49.00",
                          "taxAmount": "9.80",
                          "taxRate": "25",
                          "currency": "NOK",
                          "operation": "CHARGE"
                        }
                      ],
                      "createdAt": "2026-10-06T08:15:30Z",
                      "updatedAt": "2026-10-12T10:02:11Z"
                    }
                  },
                  "consolidated": {
                    "summary": "Invoice invoiced through a consolidated invoice",
                    "value": {
                      "invoiceId": 900002,
                      "orderId": "CPPT96C8",
                      "invoiceType": "TWO_B2B_CONSOLIDATED",
                      "status": "CONSOLIDATED",
                      "totalAmount": "948.00",
                      "currency": "NOK",
                      "invoiceLines": [
                        {
                          "id": 212345,
                          "orderLineId": "83c87fa0-062a-471a-a840-6296717edefc",
                          "productDescription": "Vy Ordinær Stavanger stasjon - Bergen stasjon",
                          "quantity": 1,
                          "amount": "899.00",
                          "taxAmount": "96.32",
                          "taxRate": "12",
                          "operation": "CHARGE",
                          "createdAt": "2026-10-06T08:15:30Z",
                          "updatedAt": "2026-10-06T08:15:30Z"
                        }
                      ],
                      "invoiceFees": [
                        {
                          "orderFeeId": "44c5af69-6ab0-0b5a-8c31-2dc8a78c2abe",
                          "description": "Fakturagebyr",
                          "feeType": "INVOICE",
                          "orderLineIds": [
                            "83c87fa0-062a-471a-a840-6296717edefc"
                          ],
                          "amount": "49.00",
                          "taxAmount": "9.80",
                          "taxRate": "25",
                          "currency": "NOK",
                          "operation": "CHARGE"
                        }
                      ],
                      "createdAt": "2026-10-06T08:15:30Z",
                      "updatedAt": "2026-10-06T08:16:02Z",
                      "consolidatedInvoiceId": 900100
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/getInvoiceForbidden"
          },
          "404": {
            "$ref": "#/components/responses/getInvoiceNotFound"
          },
          "500": {
            "$ref": "#/components/responses/internalServerError"
          }
        },
        "x-entur-permissions": {
          "value": "invoice.partner.invoices:les"
        }
      },
      "parameters": [
        {
          "$ref": "#/components/parameters/ET-Client-Name"
        },
        {
          "$ref": "#/components/parameters/X-Correlation-Id"
        }
      ]
    },
    "/v1/b2b/consolidated-invoices": {
      "post": {
        "tags": [
          "B2B Invoices"
        ],
        "summary": "Create a consolidated invoice",
        "description": "Consolidates one or more B2B invoice drafts into a single invoice, so the buyer receives one invoice for all of them. All referenced invoice orders must have been created with payment type `TWO_B2B_CONSOLIDATED`, belong to the same company, and not already be part of a consolidated invoice. The billing details of the first invoice order in the request are used as the template for the consolidated invoice. The consolidated invoice is issued immediately and cannot be undone.",
        "operationId": "createConsolidatedInvoice",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ConsolidatedInvoiceRequest"
              },
              "examples": {
                "with-reference": {
                  "summary": "Consolidate invoice orders with a merchant reference",
                  "value": {
                    "invoiceIds": [
                      900001,
                      900002,
                      900003
                    ],
                    "reference": "PROJECT-2026-10"
                  }
                },
                "without-reference": {
                  "summary": "Consolidate invoice orders without a reference",
                  "value": {
                    "invoiceIds": [
                      900001,
                      900002
                    ]
                  }
                }
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "description": "Consolidated invoice created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConsolidatedInvoiceResponse"
                },
                "examples": {
                  "created": {
                    "summary": "Consolidated invoice created",
                    "value": {
                      "consolidatedInvoiceId": 900100
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/consolidatedInvoiceBadRequest"
          },
          "401": {
            "$ref": "#/components/responses/unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/consolidatedInvoiceForbidden"
          },
          "404": {
            "$ref": "#/components/responses/consolidatedInvoiceNotFound"
          },
          "500": {
            "$ref": "#/components/responses/internalServerError"
          }
        },
        "x-entur-permissions": {
          "value": "invoice.partner.invoices:opprett"
        }
      },
      "parameters": [
        {
          "$ref": "#/components/parameters/ET-Client-Name"
        },
        {
          "$ref": "#/components/parameters/X-Correlation-Id"
        }
      ]
    },
    "/v1/b2b/invoices/{invoiceId}/pdf": {
      "get": {
        "tags": [
          "B2B Invoices"
        ],
        "summary": "Download the PDF of a B2B invoice",
        "description": "Returns the invoice PDF for a B2B invoice order that is invoiced on its own. Invoice orders created for consolidated invoicing have no PDF of their own; fetch the PDF of the consolidated invoice instead.",
        "operationId": "getB2bInvoicePdf",
        "parameters": [
          {
            "$ref": "#/components/parameters/invoiceId"
          },
          {
            "$ref": "#/components/parameters/pdfLanguage"
          },
          {
            "$ref": "#/components/parameters/pdfOriginal"
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/invoicePdf"
          },
          "400": {
            "$ref": "#/components/responses/invoicePdfBadRequest"
          },
          "401": {
            "$ref": "#/components/responses/unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/invoicePdfForbidden"
          },
          "404": {
            "$ref": "#/components/responses/invoicePdfNotFound"
          },
          "409": {
            "$ref": "#/components/responses/invoicePdfConflict"
          },
          "500": {
            "$ref": "#/components/responses/internalServerError"
          },
          "502": {
            "$ref": "#/components/responses/invoicePdfBadGateway"
          }
        },
        "x-entur-permissions": {
          "value": "invoice.partner.invoices:les"
        }
      },
      "parameters": [
        {
          "$ref": "#/components/parameters/ET-Client-Name"
        },
        {
          "$ref": "#/components/parameters/X-Correlation-Id"
        }
      ]
    },
    "/v1/b2b/consolidated-invoices/{consolidatedInvoiceId}/pdf": {
      "get": {
        "tags": [
          "B2B Invoices"
        ],
        "summary": "Download the PDF of a consolidated invoice",
        "description": "Returns the invoice PDF for a consolidated invoice.",
        "operationId": "getConsolidatedInvoicePdf",
        "parameters": [
          {
            "$ref": "#/components/parameters/consolidatedInvoiceId"
          },
          {
            "$ref": "#/components/parameters/pdfLanguage"
          },
          {
            "$ref": "#/components/parameters/pdfOriginal"
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/invoicePdf"
          },
          "400": {
            "$ref": "#/components/responses/invoicePdfBadRequest"
          },
          "401": {
            "$ref": "#/components/responses/unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/invoicePdfForbidden"
          },
          "404": {
            "$ref": "#/components/responses/invoicePdfNotFound"
          },
          "409": {
            "$ref": "#/components/responses/invoicePdfConflict"
          },
          "500": {
            "$ref": "#/components/responses/internalServerError"
          },
          "502": {
            "$ref": "#/components/responses/invoicePdfBadGateway"
          }
        },
        "x-entur-permissions": {
          "value": "invoice.partner.invoices:les"
        }
      },
      "parameters": [
        {
          "$ref": "#/components/parameters/ET-Client-Name"
        },
        {
          "$ref": "#/components/parameters/X-Correlation-Id"
        }
      ]
    }
  },
  "components": {
    "schemas": {
      "CreditCheckResponse": {
        "required": [
          "approved",
          "availableLimit",
          "companyName",
          "currency",
          "organisationNumber",
          "perOrderLimit"
        ],
        "type": "object",
        "properties": {
          "organisationNumber": {
            "type": "string",
            "description": "Organisation number of the company",
            "examples": [
              "817352812"
            ]
          },
          "companyName": {
            "type": "string",
            "description": "Registered name of the company",
            "examples": [
              "MONOZUKI AS"
            ]
          },
          "approved": {
            "type": "boolean",
            "description": "True if the company is approved for invoice purchases. If approved, verify that the order amount does not exceed either availableLimit or perOrderLimit before creating the order."
          },
          "declineReasons": {
            "type": "array",
            "description": "Why the company was declined. Present only when approved is false, UNDEFINED if no specific reason is given. Values may be added over time, so handle unknown values.",
            "items": {
              "type": "string"
            },
            "examples": [
              [
                "TOO_HIGH_RISK"
              ]
            ]
          },
          "currency": {
            "type": "string",
            "description": "ISO 4217 currency code for the amounts",
            "examples": [
              "NOK"
            ]
          },
          "availableLimit": {
            "pattern": "^-?[0-9]+\\.[0-9]{2}$",
            "type": "string",
            "description": "Remaining credit for invoice purchases, in currency",
            "examples": [
              "487160.62"
            ]
          },
          "perOrderLimit": {
            "pattern": "^-?[0-9]+\\.[0-9]{2}$",
            "type": "string",
            "description": "Maximum amount for a single order",
            "examples": [
              "487160.62"
            ]
          }
        },
        "description": "Result of a credit check for a company"
      },
      "ConsolidatedInvoiceRequest": {
        "required": [
          "invoiceIds"
        ],
        "type": "object",
        "properties": {
          "invoiceIds": {
            "minItems": 1,
            "type": "array",
            "description": "IDs of the B2B invoice orders to include, as returned when the orders were created. Each ID must appear only once.",
            "items": {
              "type": "integer",
              "format": "int64"
            },
            "examples": [
              [
                900001,
                900002,
                900003
              ]
            ]
          },
          "reference": {
            "type": "string",
            "description": "Optional merchant reference, passed on to the invoice provider",
            "examples": [
              "PROJECT-2026-10"
            ]
          }
        },
        "description": "Request to consolidate several B2B invoice orders into one invoice"
      },
      "ConsolidatedInvoiceResponse": {
        "required": [
          "consolidatedInvoiceId"
        ],
        "type": "object",
        "properties": {
          "consolidatedInvoiceId": {
            "type": "integer",
            "description": "Entur's ID of the consolidated invoice",
            "format": "int64",
            "examples": [
              900100
            ]
          }
        },
        "description": "The created consolidated invoice"
      },
      "B2bInvoiceRequest": {
        "required": [
          "buyerInfo",
          "orderId",
          "organisationNumber",
          "paymentId",
          "redirectUrl",
          "transactionId"
        ],
        "type": "object",
        "properties": {
          "orderId": {
            "type": "string",
            "description": "The Entur order ID for which to create the invoice",
            "examples": [
              "CPPT96C8"
            ]
          },
          "redirectUrl": {
            "type": "string",
            "description": "The URL the buyer is redirected to after completing verification with the invoice provider",
            "examples": [
              "https://partner-app.example.com/payment/complete"
            ]
          },
          "paymentId": {
            "type": "integer",
            "description": "The payment ID associated with this invoice",
            "format": "int64",
            "examples": [
              436801
            ]
          },
          "transactionId": {
            "type": "integer",
            "description": "The transaction ID from payment-service connected to this invoice. The transaction must have payment type TWO_B2B or TWO_B2B_CONSOLIDATED.",
            "format": "int64",
            "examples": [
              123123321
            ]
          },
          "organisationNumber": {
            "pattern": "^[89][0-9]{8}$",
            "type": "string",
            "description": "Norwegian organisation number of the company being invoiced (9 digits, starting with 8 or 9). Company details such as name and address are automatically retrieved from Brønnøysundregistrene by the invoice provider.",
            "examples": [
              "817352812"
            ]
          },
          "buyerInfo": {
            "$ref": "#/components/schemas/BuyerInfo"
          }
        },
        "description": "Request to create a B2B invoice"
      },
      "BuyerInfo": {
        "required": [
          "email",
          "firstName",
          "lastName",
          "phoneNumber"
        ],
        "type": "object",
        "properties": {
          "firstName": {
            "type": "string",
            "description": "The buyer's first name",
            "examples": [
              "Ola"
            ]
          },
          "lastName": {
            "type": "string",
            "description": "The buyer's last name",
            "examples": [
              "Nordmann"
            ]
          },
          "email": {
            "type": "string",
            "description": "The buyer's email address",
            "examples": [
              "ola.nordmann@acme.org"
            ]
          },
          "phoneNumber": {
            "type": "string",
            "description": "The buyer's phone number",
            "examples": [
              "+4749999999"
            ]
          },
          "department": {
            "type": "string",
            "description": "The buyer's department. If provided, it will appear on the invoice.",
            "examples": [
              "Sales Dpt"
            ]
          },
          "project": {
            "type": "string",
            "description": "The project the purchase relates to. If provided, it will appear on the invoice.",
            "examples": [
              "Some project"
            ]
          },
          "reference": {
            "maxLength": 140,
            "type": "string",
            "description": "Merchant reference for the purchase, e.g. a purchase order number. If provided, it will appear on the invoice.",
            "examples": [
              "PO-12345"
            ]
          }
        },
        "description": "Contact information for the buyer"
      },
      "B2bInvoiceCreateResponse": {
        "required": [
          "invoiceId",
          "paymentUrl"
        ],
        "type": "object",
        "properties": {
          "paymentUrl": {
            "type": "string",
            "description": "URL the buyer must navigate to in order to verify the invoice purchase",
            "examples": [
              "https://checkout.two.inc/mi/order/dLBPjwCr6UTf5nS9setTSv40UqSjDsE"
            ]
          },
          "invoiceId": {
            "type": "integer",
            "description": "Entur's internal ID of the created invoice",
            "format": "int64",
            "examples": [
              900001
            ]
          }
        },
        "description": "The created B2B invoice"
      },
      "ApiError": {
        "required": [
          "error",
          "exception",
          "message",
          "path",
          "status",
          "timestamp",
          "title"
        ],
        "type": "object",
        "properties": {
          "title": {
            "type": "string",
            "description": "A short, human-readable summary of the problem type."
          },
          "detail": {
            "type": "string",
            "description": "A human-readable explanation specific to this occurrence of the problem."
          },
          "errors": {
            "type": "array",
            "description": "Validation errors, if any.",
            "items": {
              "type": "string"
            }
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          },
          "status": {
            "type": "integer",
            "format": "int32"
          },
          "error": {
            "type": "string"
          },
          "exception": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "path": {
            "type": "string"
          }
        }
      },
      "B2bInvoiceLine": {
        "required": [
          "amount",
          "createdAt",
          "id",
          "operation",
          "orderLineId",
          "productDescription",
          "quantity",
          "taxAmount",
          "taxRate"
        ],
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "description": "Id of the invoice line. Credit lines get their own id.",
            "format": "int64",
            "examples": [
              212345
            ]
          },
          "orderLineId": {
            "type": "string",
            "description": "Id of the order line the product belongs to",
            "examples": [
              "83c87fa0-062a-471a-a840-6296717edefc"
            ]
          },
          "productDescription": {
            "type": "string",
            "description": "Description of the purchased product",
            "examples": [
              "Vy Ordinær Stavanger stasjon - Bergen stasjon"
            ]
          },
          "quantity": {
            "type": "integer",
            "description": "Quantity purchased",
            "format": "int32",
            "examples": [
              1
            ]
          },
          "amount": {
            "type": "string",
            "description": "Amount including VAT, in the invoice currency. Negative for credited amounts.",
            "examples": [
              "899.00"
            ]
          },
          "taxAmount": {
            "type": "string",
            "description": "VAT included in the amount. Negative for credited amounts.",
            "examples": [
              "96.32"
            ]
          },
          "taxRate": {
            "type": "string",
            "description": "VAT rate in percent",
            "examples": [
              "12"
            ]
          },
          "operation": {
            "type": "string",
            "description": "How the line affects the invoice. Current values: CHARGE, CREDIT, ADJUST. New values may be added; clients must accept unknown values.",
            "examples": [
              "CHARGE"
            ]
          },
          "createdAt": {
            "type": "string",
            "description": "When the line was created",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "description": "When the line was last updated",
            "format": "date-time"
          }
        },
        "description": "A product line on the invoice"
      },
      "B2bInvoiceFee": {
        "required": [
          "amount",
          "description",
          "feeType",
          "operation",
          "orderFeeId",
          "orderLineIds",
          "taxAmount"
        ],
        "type": "object",
        "properties": {
          "orderFeeId": {
            "type": "string",
            "description": "Id of the fee on the order",
            "examples": [
              "44c5af69-6ab0-0b5a-8c31-2dc8a78c2abe"
            ]
          },
          "description": {
            "type": "string",
            "description": "Description of the fee",
            "examples": [
              "Fakturagebyr"
            ]
          },
          "feeType": {
            "type": "string",
            "description": "Type of fee, e.g. INVOICE, CHANGE or REFUNDING",
            "examples": [
              "INVOICE"
            ]
          },
          "orderLineIds": {
            "type": "array",
            "description": "Order lines the fee is associated with",
            "items": {
              "type": "string"
            },
            "examples": [
              [
                "83c87fa0-062a-471a-a840-6296717edefc"
              ]
            ]
          },
          "amount": {
            "type": "string",
            "description": "Amount including VAT, in the invoice currency. Negative for credited amounts.",
            "examples": [
              "49.00"
            ]
          },
          "taxAmount": {
            "type": "string",
            "description": "VAT included in the amount. Negative for credited amounts.",
            "examples": [
              "9.80"
            ]
          },
          "taxRate": {
            "type": "string",
            "description": "VAT rate in percent",
            "examples": [
              "25"
            ]
          },
          "currency": {
            "type": "string",
            "description": "Currency in ISO 4217 format",
            "examples": [
              "NOK"
            ]
          },
          "operation": {
            "type": "string",
            "description": "How the line affects the invoice. Current values: CHARGE, CREDIT, ADJUST. New values may be added; clients must accept unknown values.",
            "examples": [
              "CHARGE"
            ]
          }
        },
        "description": "A fee on the invoice"
      },
      "B2bInvoiceResponse": {
        "required": [
          "createdAt",
          "currency",
          "invoiceFees",
          "invoiceId",
          "invoiceLines",
          "invoiceType",
          "orderId",
          "status",
          "totalAmount"
        ],
        "type": "object",
        "properties": {
          "invoiceId": {
            "type": "integer",
            "description": "Entur's id of the invoice",
            "format": "int64",
            "examples": [
              900001
            ]
          },
          "orderId": {
            "type": "string",
            "description": "The Entur order the invoice belongs to",
            "examples": [
              "CPPT96C8"
            ]
          },
          "invoiceType": {
            "type": "string",
            "description": "TWO_B2B for invoices invoiced on their own, TWO_B2B_CONSOLIDATED for invoices that are invoiced through a consolidated invoice",
            "examples": [
              "TWO_B2B"
            ]
          },
          "status": {
            "type": "string",
            "description": "Status of the invoice. Current values:\n- PENDING: created, but not yet invoiced\n- INVOICED: invoiced to the buyer\n- AWAITING_CONSOLIDATION: ready to be included in a consolidated invoice\n- CONSOLIDATED: invoiced through a consolidated invoice, see consolidatedInvoiceId\n- PARTIALLY_CREDITED: part of the invoice has been credited\n- CREDITED: the whole invoice has been credited\n\nNew values may be added; clients must accept unknown values. Payment status is not included.",
            "examples": [
              "INVOICED"
            ]
          },
          "totalAmount": {
            "type": "string",
            "description": "Sum of all lines and fees including VAT, net of credits",
            "examples": [
              "948.00"
            ]
          },
          "currency": {
            "type": "string",
            "description": "Currency in ISO 4217 format",
            "examples": [
              "NOK"
            ]
          },
          "consolidatedInvoiceId": {
            "type": "integer",
            "description": "Id of the consolidated invoice this invoice is part of. Set when the invoice is invoiced through a consolidated invoice, and remains set if the invoice is later credited.",
            "format": "int64",
            "examples": [
              900100
            ]
          },
          "invoiceLines": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/B2bInvoiceLine"
            }
          },
          "invoiceFees": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/B2bInvoiceFee"
            }
          },
          "createdAt": {
            "type": "string",
            "description": "When the invoice was created",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "description": "When the invoice was last updated",
            "format": "date-time"
          }
        },
        "description": "A B2B invoice order"
      }
    },
    "responses": {
      "badRequest": {
        "description": "Invalid organisation number",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            },
            "examples": {
              "invalid-format": {
                "summary": "Organisation number has the wrong format",
                "value": {
                  "title": "Bad Request",
                  "timestamp": "2026-10-06T08:15:30Z",
                  "status": 400,
                  "error": "Bad Request",
                  "exception": "javax.validation.ValidationException",
                  "message": "Validation failed",
                  "path": "/v1/b2b/credit-check/12345",
                  "errors": [
                    "organisationNumber: must match \"^[89][0-9]{8}$\""
                  ]
                }
              },
              "invalid-check-digit": {
                "summary": "Organisation number has an invalid check digit",
                "value": {
                  "title": "Bad Request",
                  "timestamp": "2026-10-06T08:15:30Z",
                  "status": 400,
                  "error": "Bad Request",
                  "exception": "org.entur.invoice.faulthandling.exceptions.BadRequestException",
                  "message": "Invalid organization number 812345678",
                  "path": "/v1/b2b/credit-check/812345678"
                }
              }
            }
          }
        }
      },
      "unauthorized": {
        "description": "Missing or invalid access token. The response has no body, see the WWW-Authenticate header."
      },
      "forbidden": {
        "description": "Missing permission to perform credit checks",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            },
            "examples": {
              "default": {
                "value": {
                  "title": "Forbidden",
                  "timestamp": "2026-10-06T08:15:30Z",
                  "status": 403,
                  "error": "Forbidden",
                  "exception": "org.springframework.security.authorization.AuthorizationDeniedException",
                  "message": "Access Denied",
                  "path": "/v1/b2b/credit-check/817352812"
                }
              }
            }
          }
        }
      },
      "notFound": {
        "description": "Company not found",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            },
            "examples": {
              "default": {
                "value": {
                  "title": "Not Found",
                  "timestamp": "2026-10-06T08:15:30Z",
                  "status": 404,
                  "error": "Not Found",
                  "exception": "org.entur.invoice.faulthandling.exceptions.NotFoundException",
                  "message": "Company with organization number 899999991 not found",
                  "path": "/v1/b2b/credit-check/899999991"
                }
              }
            }
          }
        }
      },
      "internalServerError": {
        "description": "Internal Server Error",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            },
            "examples": {
              "default": {
                "value": {
                  "title": "Internal Server Error",
                  "timestamp": "2026-10-06T08:15:30Z",
                  "status": 500,
                  "error": "Internal Server Error",
                  "exception": "org.entur.invoice.faulthandling.exceptions.InvoiceException",
                  "message": "Unexpected server error",
                  "path": "/v1/b2b/credit-check/817352812"
                }
              }
            }
          }
        }
      },
      "consolidatedInvoiceBadRequest": {
        "description": "Invalid consolidation request",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            },
            "examples": {
              "empty-invoice-ids": {
                "summary": "No invoice orders to consolidate",
                "value": {
                  "title": "Bad Request",
                  "timestamp": "2026-10-06T08:15:30Z",
                  "status": 400,
                  "error": "Bad Request",
                  "exception": "javax.validation.ValidationException",
                  "message": "Validation failed",
                  "path": "/v1/b2b/consolidated-invoices",
                  "errors": [
                    "consolidatedInvoiceRequest:size must be between 1 and 2147483647"
                  ]
                }
              }
            }
          }
        }
      },
      "consolidatedInvoiceForbidden": {
        "description": "Missing permission to create consolidated invoices",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            },
            "examples": {
              "default": {
                "value": {
                  "title": "Forbidden",
                  "timestamp": "2026-10-06T08:15:30Z",
                  "status": 403,
                  "error": "Forbidden",
                  "exception": "org.springframework.security.authorization.AuthorizationDeniedException",
                  "message": "Access Denied",
                  "path": "/v1/b2b/consolidated-invoices"
                }
              }
            }
          }
        }
      },
      "createInvoiceBadRequest": {
        "description": "Invalid request",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            },
            "examples": {
              "missing-field": {
                "summary": "A required field is missing",
                "value": {
                  "title": "Bad Request",
                  "timestamp": "2026-10-06T08:15:30Z",
                  "status": 400,
                  "error": "Bad Request",
                  "exception": "javax.validation.ValidationException",
                  "message": "Validation failed",
                  "path": "/v1/b2b/invoices",
                  "errors": [
                    "buyerInfo.email: must not be null"
                  ]
                }
              }
            }
          }
        }
      },
      "createInvoiceForbidden": {
        "description": "Missing permission to create B2B invoices",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            },
            "examples": {
              "default": {
                "value": {
                  "title": "Forbidden",
                  "timestamp": "2026-10-06T08:15:30Z",
                  "status": 403,
                  "error": "Forbidden",
                  "exception": "org.springframework.security.authorization.AuthorizationDeniedException",
                  "message": "Access Denied",
                  "path": "/v1/b2b/invoices"
                }
              }
            }
          }
        }
      },
      "consolidatedInvoiceNotFound": {
        "description": "One or more invoice orders not found",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            },
            "examples": {
              "default": {
                "value": {
                  "title": "Not Found",
                  "timestamp": "2026-10-06T08:15:30Z",
                  "status": 404,
                  "error": "Not Found",
                  "exception": "org.entur.invoice.faulthandling.exceptions.NotFoundException",
                  "message": "Invoice order with id 900004 not found",
                  "path": "/v1/b2b/consolidated-invoices"
                }
              }
            }
          }
        }
      },
      "invoicePdf": {
        "description": "The invoice as PDF",
        "content": {
          "application/pdf": {
            "schema": {}
          }
        }
      },
      "invoicePdfBadRequest": {
        "description": "Invalid query parameter",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            },
            "examples": {
              "invalid-language": {
                "summary": "Unsupported language",
                "value": {
                  "title": "Bad Request",
                  "timestamp": "2026-10-06T08:15:30Z",
                  "status": 400,
                  "error": "Bad Request",
                  "exception": "org.entur.invoice.faulthandling.exceptions.BadRequestException",
                  "message": "Unsupported language de_DE",
                  "path": "/v1/b2b/invoices/900001/pdf"
                }
              }
            }
          }
        }
      },
      "invoicePdfForbidden": {
        "description": "Missing permission to read invoices",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            },
            "examples": {
              "forbidden": {
                "summary": "Missing permission",
                "value": {
                  "title": "Forbidden",
                  "timestamp": "2026-10-06T08:15:30Z",
                  "status": 403,
                  "error": "Forbidden",
                  "exception": "org.springframework.security.authorization.AuthorizationDeniedException",
                  "message": "Access Denied",
                  "path": "/v1/b2b/invoices/900001/pdf"
                }
              }
            }
          }
        }
      },
      "invoicePdfNotFound": {
        "description": "Invoice not found",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            },
            "examples": {
              "invoice-not-found": {
                "summary": "Invoice does not exist or is not a B2B invoice",
                "value": {
                  "title": "Not Found",
                  "timestamp": "2026-10-06T08:15:30Z",
                  "status": 404,
                  "error": "Not Found",
                  "exception": "org.entur.invoice.faulthandling.exceptions.NotFoundException",
                  "message": "Invoice with id 900001 not found",
                  "path": "/v1/b2b/invoices/900001/pdf"
                }
              },
              "consolidated-invoice-not-found": {
                "summary": "Consolidated invoice does not exist",
                "value": {
                  "title": "Not Found",
                  "timestamp": "2026-10-06T08:15:30Z",
                  "status": 404,
                  "error": "Not Found",
                  "exception": "org.entur.invoice.faulthandling.exceptions.NotFoundException",
                  "message": "Consolidated invoice with id 900100 not found",
                  "path": "/v1/b2b/consolidated-invoices/900100/pdf"
                }
              }
            }
          }
        }
      },
      "invoicePdfConflict": {
        "description": "The invoice has no PDF in its current state",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            },
            "examples": {
              "part-of-consolidated-invoice": {
                "summary": "Invoice order created for consolidated invoicing",
                "value": {
                  "title": "Conflict",
                  "timestamp": "2026-10-06T08:15:30Z",
                  "status": 409,
                  "error": "Conflict",
                  "exception": "org.entur.invoice.faulthandling.exceptions.ConflictException",
                  "message": "Invoice 900001 is invoiced through a consolidated invoice. Fetch the PDF of the consolidated invoice instead",
                  "path": "/v1/b2b/invoices/900001/pdf"
                }
              },
              "consolidation-not-succeeded": {
                "summary": "Consolidation has not succeeded",
                "value": {
                  "title": "Conflict",
                  "timestamp": "2026-10-06T08:15:30Z",
                  "status": 409,
                  "error": "Conflict",
                  "exception": "org.entur.invoice.faulthandling.exceptions.ConflictException",
                  "message": "Consolidated invoice 900100 has status FAILED and has no PDF",
                  "path": "/v1/b2b/consolidated-invoices/900100/pdf"
                }
              }
            }
          }
        }
      },
      "invoicePdfBadGateway": {
        "description": "The invoice provider failed to return the PDF",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            },
            "examples": {
              "provider-failed": {
                "summary": "Invoice provider error",
                "value": {
                  "title": "Bad Gateway",
                  "timestamp": "2026-10-06T08:15:30Z",
                  "status": 502,
                  "error": "Bad Gateway",
                  "exception": "org.entur.invoice.faulthandling.exceptions.InvoiceProviderException",
                  "message": "Failed to fetch invoice PDF from the invoice provider",
                  "path": "/v1/b2b/invoices/900001/pdf"
                }
              }
            }
          }
        }
      },
      "getInvoiceForbidden": {
        "description": "Missing permission to read invoices",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            },
            "examples": {
              "forbidden": {
                "summary": "Missing permission",
                "value": {
                  "title": "Forbidden",
                  "timestamp": "2026-10-06T08:15:30Z",
                  "status": 403,
                  "error": "Forbidden",
                  "exception": "org.springframework.security.authorization.AuthorizationDeniedException",
                  "message": "Access Denied",
                  "path": "/v1/b2b/invoices/900001"
                }
              }
            }
          }
        }
      },
      "getInvoiceNotFound": {
        "description": "Invoice not found",
        "content": {
          "application/problem+json": {
            "schema": {
              "$ref": "#/components/schemas/ApiError"
            },
            "examples": {
              "invoice-not-found": {
                "summary": "Invoice does not exist, is not a B2B invoice or belongs to another organisation",
                "value": {
                  "title": "Not Found",
                  "timestamp": "2026-10-06T08:15:30Z",
                  "status": 404,
                  "error": "Not Found",
                  "exception": "org.entur.invoice.faulthandling.exceptions.NotFoundException",
                  "message": "Invoice with id 900001 not found",
                  "path": "/v1/b2b/invoices/900001"
                }
              }
            }
          }
        }
      }
    },
    "parameters": {
      "organisationNumber": {
        "name": "organisationNumber",
        "in": "path",
        "description": "Norwegian organisation number (9 digits, starting with 8 or 9)",
        "required": true,
        "style": "simple",
        "explode": false,
        "schema": {
          "pattern": "^[89][0-9]{8}$",
          "type": "string",
          "examples": [
            "817352812"
          ]
        }
      },
      "invoiceId": {
        "name": "invoiceId",
        "in": "path",
        "description": "Id of the B2B invoice order, as returned when it was created",
        "required": true,
        "style": "simple",
        "explode": false,
        "schema": {
          "type": "integer",
          "format": "int64",
          "examples": [
            900001
          ]
        }
      },
      "consolidatedInvoiceId": {
        "name": "consolidatedInvoiceId",
        "in": "path",
        "description": "Id of the consolidated invoice, as returned when it was created",
        "required": true,
        "style": "simple",
        "explode": false,
        "schema": {
          "type": "integer",
          "format": "int64",
          "examples": [
            900100
          ]
        }
      },
      "pdfLanguage": {
        "name": "lang",
        "in": "query",
        "description": "Language of the PDF",
        "required": false,
        "style": "form",
        "explode": true,
        "schema": {
          "type": "string",
          "default": "nb_NO",
          "enum": [
            "nb_NO",
            "en_US",
            "sv_SE"
          ]
        }
      },
      "pdfOriginal": {
        "name": "original",
        "in": "query",
        "description": "If the invoice has been credited, the credit note is returned by default. Set to true to get the original invoice instead.",
        "required": false,
        "style": "form",
        "explode": true,
        "schema": {
          "type": "boolean",
          "default": false
        }
      },
      "ET-Client-Name": {
        "name": "ET-Client-Name",
        "in": "header",
        "description": "Entur Client Header.\nIt is required that all consumers identify themselves by using this header.\nEntur will deploy strict rate-limiting policies on API-consumers who do not identify with a header and reserves the right to block unidentified consumers.\nThe structure of ET-Client-Name should be: `<company>-<application>`.",
        "required": false,
        "style": "simple",
        "explode": false,
        "schema": {
          "type": "string"
        }
      },
      "X-Correlation-Id": {
        "name": "X-Correlation-Id",
        "in": "header",
        "description": "Correlation id",
        "required": false,
        "style": "simple",
        "explode": false,
        "schema": {
          "type": "string"
        }
      }
    },
    "securitySchemes": {
      "jwt": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    }
  }
}