feat: tiered pricing engine with validation, bill breakdown, and comprehensive tests#62
Open
Th3Slack3r wants to merge 1 commit into
Open
feat: tiered pricing engine with validation, bill breakdown, and comprehensive tests#62Th3Slack3r wants to merge 1 commit into
Th3Slack3r wants to merge 1 commit into
Conversation
…, and comprehensive tests Implements Tiered Pricing Engine for issue Nexussyn#1: - Migration: add_tiered_pricing.sql (already present, idempotent) - Logic: getTierPrice, calculateBatchCost, calculateBill in tier-engine.ts with safe-integer validation on all inputs - Tests: 29 unit tests covering all 4 tiers, boundary crossings, batch cost, bill breakdown, and input validation Closes Nexussyn#1
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
Implements the Tiered Pricing Engine for issue #1 — a 4-tier pricing system for x402 API calls designed to increase revenue by ~30%.
Changes
src/pricing/tier-engine.ts— Core pricing logic:getTierPrice(callCount, priorityFlag)— returns price per call based on tiercalculateBatchCost(startCount, numCalls, priority)— batch cost calculation with tier boundary crossingcalculateBill(startCount, numCalls, priority)— full bill with per-tier breakdowntests/pricing.test.ts— 29 unit tests covering:calculateBillwith per-tier breakdownsmigrations/add_tiered_pricing.sql— Idempotent SQL migration (unchanged):tier,price_per_call,priority_flagcolumns tox402_callspricing_tierslookup table with upsert semanticsAcceptance Criteria
tiercolumn to relevant payment tableget_tier_price(call_count, priority_flag)returns correct priceValidation
Closes #1
Wallet: 0x09239d9722910bf0f6d685fb5f1af38ba660cb1d