Choose a card type
How many?
1

Test data only. Local fixtures do not issue cards, verify accounts or provide payment authorization. Use them only in authorized tests. Why?

VisaTEST CARD
•••• •••• •••• ••••
Cardholder—
ExpiresMM/YY
CVV•••
  • Generated fields are not uploaded
  • Randomly generated in your browser
  • Every number passes the Luhn check

Keep the checksum result separate from the form decision

A checksum result is a fact about a digit string. What the form does with that result is a configured policy. If those two are stored in one valid flag, changing a validation option can make a failed checksum appear to have passed. This exercise preserves both results so a test can see exactly what changed.

The generator produces 16- or 19-digit strings starting with 62 or 81, and every generated number passes Luhn. It also supplies a three-digit synthetic security code. The fixed download includes deliberately failing checksum variants that the generator itself will not produce.

Select a policy explicitly

Braintree’s card-validator documentation documents luhnValidateUnionPay, which enables Luhn validation for UnionPay rather than using the library’s default exception. That is a documented library behavior, not evidence that every checkout should ignore checksum failures. Match the requirements of the provider and the library version used in your integration.

The downloadable example has two named local test profiles: require-luhn asks for a correction on failure, while observe-only records the failure without using it as a local gate. Missing or misspelled policies return policy-required. The observe-only case is a comparison fixture, not a recommendation to bypass production validation or to submit generated numbers to a live gateway.

Number and policyChecksum resultLocal decision
6212345678901232, require-luhnPasslocal-checks-complete
6212345678901233, require-luhnFailcorrect-number
Same failing number, observe-onlyStill faillocal-checks-complete
Either number, no policyPass or fail remains visiblepolicy-required
A 65 prefix with observe-onlyNot checkedoutside-profile

The failing pair differs only in its last digit. The example never repairs that digit automatically. If you want to understand why the result changes, the Luhn walkthrough explains the arithmetic independently.

Run the checksum and policy comparison

Keep the policy fixtures and the executable UnionPay checks in one directory:

node --test unionpay-policy.test.mjs

The fixture includes both prefixes at 16 and 19 digits, the altered check digit, missing configuration, an unknown policy name, and values outside the target shape. The runner also changes each digit of a passing number and checks that every single-digit substitution fails Luhn.

function passesLuhn(number) {
  let sum = 0;
  for (let i = number.length - 1, double = false; i >= 0; i -= 1, double = !double) {
    let digit = Number(number[i]);
    if (double) digit = digit * 2 > 9 ? digit * 2 - 9 : digit * 2;
    sum += digit;
  }
  return sum % 10 === 0;
}

function assessUnionPay(number, policy) {
  if (typeof number !== 'string' || !/^(62|81)(?:\d{14}|\d{17})$/.test(number)) {
    return { checksum: 'not-checked', decision: 'outside-profile' };
  }
  const checksum = passesLuhn(number) ? 'pass' : 'fail';
  if (policy !== 'require-luhn' && policy !== 'observe-only') {
    return { checksum, decision: 'policy-required' };
  }
  return {
    checksum,
    decision: checksum === 'fail' && policy === 'require-luhn'
      ? 'correct-number' : 'local-checks-complete'
  };
}

The function accepts unformatted strings only. Its shape gate matches this generator’s 62/81 and 16/19-digit profile. It does not cover all UnionPay products or perform a BIN lookup. In particular, the 17-digit control is outside this test profile; the result must not be presented as a universal network restriction.

Apply the comparison without hiding an error

Replace assessUnionPay with an adapter around your own configured validation layer and keep separate assertions for the checksum and the form’s action. Test the same malformed input under both local profiles so an option change cannot rewrite the checksum field. Keep unknown configuration distinct from an intentional observe-only decision.

In the UI, check that feedback points to the card-number field and explains what the user can correct. A local decision of local-checks-complete must not bypass expiry, security code, merchant acceptance or other required checks. None of these fixture decisions is an authorization result.

If a 62 value is labeled Maestro, diagnose that separately with the overlapping-rule exercise. If a 19-digit value changes during serialization, use the Visa string-preservation tests. These failures should not be hidden by changing the checksum policy.

Use the gateway sandbox reference for provider-approved test inputs and response behavior. The local failing pair here only exercises the validation contract.

Frequently Asked Questions

Do numbers from this generator pass Luhn?
Yes. The generator calculates a Luhn check digit for every output. The failing numbers in the download are separate, deliberately altered fixtures.
Should every UnionPay checksum failure be allowed through?
No universal rule follows from the brand alone. Use the requirements of your provider and validation library. The example compares explicitly selected local policies and treats a missing policy as unresolved.
What does local-checks-complete mean?
Only that the configured local number checks have completed. It does not mean the payment is ready, an account exists, other fields are valid or a gateway will authorize the transaction.
Why is a 17-digit fixture outside this example’s profile?
The sample deliberately matches the generator’s 16- and 19-digit lengths. It is not a claim that every 17-digit UnionPay number is invalid; configure a wider profile only when your integration requires it.