China Invoice Verification API Contract Tests

Test the field-based Chinese invoice verification request and response with versioned local fixtures for digital, ordinary VAT, and special VAT invoices.

ArticlesPublished by ChinaValidatePublished December 3, 2026Last updated December 3, 2026

Verify a Chinese invoice using its printed details.

View API documentationAPI workspace
China Invoice Verification API Contract Tests

A change to an invoice mapper can pass ordinary application tests and still produce a request in the wrong format. A spreadsheet import might turn an invoice number into an integer, while a shared amount field might send the net amount in the slot meant for the digital invoice's tax-inclusive total. Neither change necessarily causes a syntax error. A contract test checks the exact request the application emits and the result the caller records.

Start with the field endpoint's documented three invoice types. Keep a local request fixture for each type, plus responses for a match, a mismatch, and a completed check without a usable record. Add a separate fixture for a request error. These tests can run without the API key or a real invoice. The test suite checks the application contract with known data. A separate authorized live verification can establish what a particular document returned. ChinaValidate invoice verification API

The field differences that matter

The endpoint documents an invoice type, invoice number and issue date for every request. It also documents different particulars for the supported formats. For a digital invoice, the tax-inclusive total is the relevant amount. An older type with a code uses the printed invoice code. For ordinary VAT invoices with a code, the last six digits of the verification code are required. For special VAT invoices with a code, the amount before tax is the relevant amount. Encode identifiers and amounts in the documented string representations.

The State Taxation Administration describes the fully digital electronic invoice's 20-digit number. A digital fixture can require exactly 20 digits. Preserve those digits even if the language or storage engine can represent that particular number numerically. An older invoice-number example can deliberately start with zero. Together the cases detect rounding and lost leading characters without imposing a universal length rule on older formats. Read the actual input requirements for the invoice family supported by your integration. State Taxation Administration digital invoice announcement

Request fixture What the fixture should establish Useful negative variant
Digital invoice Full invoice number, issue date, and tax-inclusive amount are serialized as strings A mapper writes the net amount instead of the gross field
Ordinary VAT invoice with code Invoice code and the last six verification digits are carried forward A leading zero disappears from the verification code
Special VAT invoice with code The invoice code and amount before tax are sent The client places the gross total where the net amount belongs
Valid invoice with no verification record in the result A request completes and the client keeps an explicit outcome The application wrongly treats an empty array as a successful match
Invalid or failed request The application records a request failure separately A response parsed over HTTP 200 is automatically labeled verified

Those examples serve different purposes. A required-field schema catches an omitted field. A fixture comparison can catch a valid-looking string made from the wrong source field. For a digital fixture, use net and gross values that actually differ and expect the exact gross amount in the outgoing JSON. Choose a verification code whose six digits include a leading zero. These deliberately discriminating values make the test fail when someone swaps mappings or changes how a number is formatted.

Schema validation at the caller boundary

JSON Schema can express shared fields and conditional requirements. The following example is a local guard for a field-request builder, based on documented requirements. It models the fields this caller uses. It leaves additional fields possible so the caller can be extended intentionally. Add fixture assertions to check values and a real calendar date validator if your import accepts dates entered by users. The text pattern here checks the eight-character representation. JSON Schema conditional validation

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "required": ["invoice_type", "invoice_number", "issue_date"],
  "properties": {
    "invoice_type": {"enum": ["digital", "vat_ordinary", "vat_special"]},
    "invoice_number": {"type": "string", "minLength": 1},
    "issue_date": {"type": "string", "pattern": "^[0-9]{8}$"},
    "invoice_code": {"type": "string", "minLength": 1},
    "verification_code": {"type": "string", "pattern": "^[0-9]{6}$"},
    "net_amount": {"type": "string", "minLength": 1},
    "total_amount": {"type": "string", "minLength": 1}
  },
  "allOf": [
    {
      "if": {"properties": {"invoice_type": {"const": "digital"}}},
      "then": {
        "required": ["total_amount"],
        "properties": {"invoice_number": {"pattern": "^[0-9]{20}$"}}
      }
    },
    {
      "if": {"properties": {"invoice_type": {"const": "vat_ordinary"}}},
      "then": {"required": ["invoice_code", "verification_code"]}
    },
    {
      "if": {"properties": {"invoice_type": {"const": "vat_special"}}},
      "then": {"required": ["invoice_code", "net_amount"]}
    }
  ]
}

Run the validator against the serialized body passed to the transport, not only the intermediate object used by the mapper. Parsing the serialized body back in the test demonstrates the types sent to the endpoint. Be careful with a framework's automatic coercion of numbers and strings. A schema test should make a wrong type visible, and a round-trip fixture should reconstruct the exact expected identifier. Use examples with fake values so the request can be committed as a test file without bringing supplier invoice data into the source repository.

Give the fixture two distinct source amounts and assert that the outgoing amount ends up at the right key for that invoice type. A negative fixture can still satisfy the schema if the wrong human-readable amount is a valid string. Add a different test for a digital payload with the gross field omitted entirely. This separates the failure caused by a mapper's field selection from a structural omission handled by the schema. Assertions on exact serialized identifiers also make it easier to trace the issue to a spreadsheet importer or a model setter.

Response fixtures that exercise actual decisions

The PDF and OFD endpoints have separate request contracts. Here the verification response fixtures target the field endpoint. Check the status visible to the HTTP client, the JSON application's code and the actual invoice outcome in verification_status. When the response has a usable item in data.items, retain its result and link it to the original request. Test a response that contains an explicit mismatch while the request itself completed. Test a no-record response separately so a parser that sees an empty list cannot turn it into an approval. ChinaValidate invoice verification response and errors

Consider a caller that sets an invoice badge as soon as the HTTP action succeeds. The response fixture for an application error should still use the transport status shown by the documentation for an application response. If the badge changes to matched, the test has exposed the wrong condition. A timeout fixture should have no application response at all. The record can then distinguish a known failure from an attempt with an unknown upstream outcome. Attach a request reference when one is available to your callable integration.

Preserve response fields the caller needs for its decision. A response can include buyer and seller information as well as the invoice values. The parser can validate the subset required by its own flow and preserve original fields in a separate evidence record where policy permits. In a localized response, test that the matched state and identifiers do not depend on translated names or display text. Add a fixture with optional fields absent to prove that useful observations remain usable. Tests that demand every optional field can fail for documented, legitimate responses.

Electronic invoices and traditional VAT invoices can produce distinct workflow decisions. If the organization archives a checked invoice against a ledger entry, validate the link between the exact source and the verification outcome. The joint Ministry of Finance and National Archives Administration notice addresses the handling of electronic accounting vouchers in the wider accounting process. A verification marker alone provides only one part of that evidence. A test that checks the stored link and submission record is more informative than a test that checks a green status label. Electronic accounting vouchers notice

A test run without paid calls

Separate request construction, transport and response mapping so the same fixture can exercise the application's normal entry point through a test transport. Have the test capture the request method, endpoint and serialized JSON. The fixture can return a specific body or simulate an exception. Use a dummy authorization value if you need to assert that the header was set. Do not export keys or invoice bodies into the test logs. A contract fixture should communicate the state or field that broke, with synthetic data that can be shared with the developer responsible for the integration.

Version the example records alongside the code that consumes them. When the API documentation changes, compare the affected fields and update the fixture through a review. An optional property appearing in a payload may only require that the parser tolerate it. A changed request requirement may require both client mapping and validation changes. Keeping fixtures narrow lets one meaningful mismatch surface before a large set of unrelated expected outputs needs attention.

Run the suite against formatted spreadsheet values as well as clean caller inputs if the integration imports a spreadsheet. Include an old invoice number with a leading zero and a digital invoice number that is too large to round-trip through common numeric types. Add a date entered as readable text in a local format, and confirm that a successful conversion emits the required compact format. Finally, exercise the same fixtures with the review record writer and verify that the saved outcome points back to the request and source. A passing suite should show the full route from the original field to the recorded verification state.