The Discount Function API now supports discount code rejection, allowing apps to conditionally reject discount codes with a custom message.
This is a companion discussion topic for the original entry at https://shopify.dev/changelog/discount-rejection-support-for-discount-functions