feat: #77 Implement discount codes and promotional pricing - #146
Merged
manoahLinks merged 2 commits intoMar 28, 2026
Merged
Conversation
…ass-live#77) Add organizer-controlled discount codes to the event_manager contract, allowing percentage-based price reductions during ticket purchase. New public functions: - create_discount(event_id, code, percentage, max_uses, expiration): organizer-only; creates a named discount code with optional usage limit (0 = unlimited) and optional expiration timestamp (0 = none) - get_discount(event_id, code): query a discount code's details - purchase_ticket_with_discount(buyer, event_id, tier_index, code): applies a valid discount code and purchases a ticket at the reduced price; decrements uses_remaining atomically New storage: - DataKey::Discount(u32, String): (event_id, code) -> DiscountCode New type: - DiscountCode { code, percentage, max_uses, uses_remaining, expiration } Validation enforced by create_discount: - Organizer-only (require_auth) - percentage must be 1–100 - expiration (if set) must be in the future - duplicate codes per event are rejected - cancelled events cannot receive new codes Validation enforced by purchase_ticket_with_discount: - code must exist (DiscountNotFound) - code must not be expired (DiscountExpired) - code must have remaining uses when max_uses > 0 (DiscountMaxUsesReached) Events emitted: - discount_created (event_id, code, percentage, max_uses, expiration) - discount_applied (event_id, buyer, code, base_price, final_price) New error variants: - DiscountNotFound = 24 - DiscountExpired = 25 - DiscountMaxUsesReached = 26 - InvalidDiscountPercentage = 27 - DiscountAlreadyExists = 28 - InvalidExpiration = 29 Also includes the cumulative base cleanup from crowdpass-live#75 and crowdpass-live#76 (merge-conflict artifacts in lib.rs/test.rs) since upstream main has not yet merged those PRs. Test results: 65 passed; 0 failed
|
@jayteemoney Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
event_managerSoroban contractpurchase_ticket_with_discountentry-point applies the code and emits bothticket_purchasedanddiscount_appliedeventsRequirements fulfilled
DataKey::Discount(u32, String)→DiscountCodecreate_discount(event_id, code, percentage, max_uses, expiration)apply_discountvalidation during purchaseapply_discount_codecalled bypurchase_ticket_with_discountuses_remainingdecremented atomically; rejected when exhaustedenv.ledger().timestamp()New public functions
create_discount(event_id, code, percentage, max_uses, expiration)get_discount(event_id, code)purchase_ticket_with_discount(buyer, event_id, tier_index, code)Validation
create_discountguards: organizer auth, event not cancelled, percentage 1–100, expiration in the future (if set), no duplicate codes.purchase_ticket_with_discountguards: all standard purchase checks + code exists, not expired, uses remaining.New storage / types / errors
DiscountCodestruct:code,percentage,max_uses,uses_remaining,expirationErrors:
DiscountNotFound = 24,DiscountExpired = 25,DiscountMaxUsesReached = 26,InvalidDiscountPercentage = 27,DiscountAlreadyExists = 28,InvalidExpiration = 29Events:
discount_created,discount_appliedTest results
Closes #77