Skip to content

In commerce module there should be dedicated feature/method for generating discount/coupon codes. #3670

@jainarpit1910

Description

@jainarpit1910

Clear and concise description of the problem

As a developer using faker, I want a dedicated method for generating discount or coupon codes so that I can easily generate realistic, configurable, and reusable coupon codes for testing e-commerce systems, promotions, and checkout flows.

Currently, Faker provides generic string helpers like faker.string.alphanumeric() which work technically, but they are not designed specifically for the real-world needs of commerce use cases, such as:

  • Coupon code formats (e.g., SALE20, WELCOME-5)
  • Length constraints
  • Prefix/suffix handling
  • Readable human-friendly codes
  • Avoiding ambiguous characters (O, 0, I, l)

Easily generating batches of coupon codes

A dedicated API under a Commerce-related namespace (such as faker.commerce.couponCode()) would improve usability, clarity, and consistency for developers working with e-commerce data.

I am willing to submit a PR for this issue if the maintainers agree with the proposal and design.

Suggested solution

In module faker.commerce, we could provide a method like:

faker.commerce.couponCode(options?)

Example implementation design:

faker.commerce.couponCode({
  length: 10,
  prefix: 'SALE-',
  suffix: '-2025',
  readable: true,
  exclude: ['O', '0', 'I', '1']
});

Expected behavior:

  • Generate human-readable coupon codes

  • Allow configuration for:

    • length
    • prefix / suffix
    • allowed / disallowed characters
    • uppercase output
    • numeric-only / alpha-numeric modes, etc.

Alternative

Currently, Faker provides generic string helpers like faker.string.alphanumeric() which work technically, but they are not designed specifically for the real-world needs of commerce use cases.

Additional context

Coupon / discount code generation is a very common testing need for:

  • Cart systems
  • Checkout flows
  • Marketing campaigns
  • Referral programs
  • QA automation
  • Load testing

Most developers currently re-implement this logic manually using faker.string or custom helper functions, which leads to:

  • Duplicate implementations across projects
  • Inconsistent formatting
  • Harder-to-maintain test data
  • Less expressive test code

Providing a native faker API improves:

  • Developer experience
  • Code readability
  • Standardization of fake commerce data
  • Adoption in commerce simulation use cases

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions