A school discount with no code, because the discount is the email domain
We used to give schools a discount code. A teacher asked for one, we minted it, and then we maintained the parts that follow from a code existing: an admin CRUD for the codes, a redemption table so per-user and per-year limits could be enforced, a validate endpoint, and a support thread every time somebody pasted a code with a smart quote in it. The replacement is that a school is registered by…
Schools now receive a discount based on their email domain rather than a manual discount code. This change simplifies the process by eliminating the need for users to remember or type in a code. The discount is automatically applied based on the school's email domain, with the matching rule being the longest suffix, not an exact match.
To determine the applicable discount, the system first checks if the email domain exists in the registration database. If multiple domains are involved (e.g., a trust with subdomains), the most specific domain takes precedence. For example, jane@pupils.beaumont.school would match "pupils.beaumont.school" before "beaumont.school".
The implementation involves a function that takes an email address as input and returns an array of candidate domains. The function handles various edge cases, such as invalid email formats, domains without mailboxes, and common consumer mailbox providers. The resulting candidate domains are then used to identify the applicable discount.
This change affects the user experience by streamlining the discount application process and reducing the potential for errors caused by mistyping or losing discount codes. The system also ensures that the discount is applied consistently across all pages and interactions within the platform.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.