Skip to content

fix(rest/python): match discount codes case-insensitively#128

Merged
carolinerg1 merged 1 commit into
Universal-Commerce-Protocol:mainfrom
vishkaty:fix/discount-case-insensitive
Jul 13, 2026
Merged

fix(rest/python): match discount codes case-insensitively#128
carolinerg1 merged 1 commit into
Universal-Commerce-Protocol:mainfrom
vishkaty:fix/discount-case-insensitive

Conversation

@vishkaty

Copy link
Copy Markdown
Contributor

What

docs/specification/discount.md (Operations → Request behavior) says:

Case-insensitive: Codes are matched case-insensitively by business

The server looked codes up by exact primary key (get_discountsession.get(Discount, code), and get_discounts_by_codes.in_(codes)), with no normalization. The seed data is uppercase (test_data/flower_shop/discounts.csv: 10OFF, WELCOME20, FIXED500), so a buyer submitting 10off got no discount.

On the seeded flower shop (bouquet_roses, 3500), same checkout differing only in the code's case:

submitted discounts.applied total
10OFF ["10OFF"] 3150
10off [] 3500

Fix

Compare on func.upper() in both discount lookups; the applied entry echoes the canonical stored code. A code that is already the correct case is unaffected.

Test

Adds an integration test that seeds 10OFF and submits 10off: before the fix nothing is applied; after, the discount applies (asserts applied == ["10OFF"] and a 10% discount total). Full integration_test.py stays green (6 passed), ruff check / ruff format --check clean. Verified against the last main-compatible python-sdk commit (f54858e).

Note (separate, happy to follow up)

The spec's Response behavior also says rejected codes are communicated via messages[]; today an unmatched code is dropped silently. I kept this PR to the case-insensitivity fix to stay single-concern, but I'm glad to send a small follow-up adding a messages[] entry for rejected codes if that's welcome.

@damaz91 damaz91 added status:needs-triage Signal that the PR is ready for human triage status:under-review and removed status:needs-triage Signal that the PR is ready for human triage labels Jul 12, 2026
@damaz91
damaz91 self-requested a review July 13, 2026 12:44
The discount spec says codes are matched case-insensitively by business
(docs/specification/discount.md, Operations -> Request behavior), but the
server looked codes up by exact primary key, so the seeded 10OFF was not
applied when a buyer submitted 10off.

get_discount / get_discounts_by_codes now compare on func.upper(); the
applied entry echoes the canonical stored code. Adds an integration test
asserting a lowercase submission applies the uppercase-seeded discount.
@damaz91
damaz91 force-pushed the fix/discount-case-insensitive branch from 2d8d59c to c14ef29 Compare July 13, 2026 12:59
@damaz91

damaz91 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Great fix, thanks for the help @vishkaty !

@carolinerg1
carolinerg1 merged commit 14756f9 into Universal-Commerce-Protocol:main Jul 13, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants