This repository was archived by the owner on Jun 3, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Support regional Pro pricing #220
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -27,6 +27,26 @@ | |||||||||||||||||
| }, | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| BILLING_REGION_IN = "IN" | ||||||||||||||||||
| BILLING_REGION_GLOBAL = "GLOBAL" | ||||||||||||||||||
| BILLING_REGION_ALIASES = { | ||||||||||||||||||
| "IN": BILLING_REGION_IN, | ||||||||||||||||||
| "IND": BILLING_REGION_IN, | ||||||||||||||||||
| "INDIA": BILLING_REGION_IN, | ||||||||||||||||||
| "GLOBAL": BILLING_REGION_GLOBAL, | ||||||||||||||||||
| "US": BILLING_REGION_GLOBAL, | ||||||||||||||||||
| "USD": BILLING_REGION_GLOBAL, | ||||||||||||||||||
| "INTERNATIONAL": BILLING_REGION_GLOBAL, | ||||||||||||||||||
| "WORLD": BILLING_REGION_GLOBAL, | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| PLAN_REGIONAL_PRICES: dict[str, dict[str, dict[str, Any]]] = { | ||||||||||||||||||
| "pro": { | ||||||||||||||||||
| BILLING_REGION_IN: {"price_minor_unit": 9_900, "currency": "INR"}, | ||||||||||||||||||
| BILLING_REGION_GLOBAL: {"price_minor_unit": 300, "currency": "USD"}, | ||||||||||||||||||
| }, | ||||||||||||||||||
| } | ||||||||||||||||||
|
greptile-apps[bot] marked this conversation as resolved.
|
||||||||||||||||||
|
|
||||||||||||||||||
| TOP_UP_PACKS: dict[str, dict[str, Any]] = { | ||||||||||||||||||
| "topup_99": {"price_paise": 9_900, "credits": 5_000, "currency": "INR"}, | ||||||||||||||||||
| "topup_199": {"price_paise": 19_900, "credits": 12_000, "currency": "INR"}, | ||||||||||||||||||
|
|
@@ -75,6 +95,42 @@ def workflow_multiplier(job_type: str, payload: Mapping[str, Any]) -> float: | |||||||||||||||||
| return WORKFLOW_MULTIPLIERS.get(job_type, 1.0) | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def normalize_billing_region(region: str | None) -> str: | ||||||||||||||||||
| # Client-provided region is only a pricing hint; blank hints use global | ||||||||||||||||||
| # pricing to avoid undercharging when a client cannot derive location. | ||||||||||||||||||
| if not region or not region.strip(): | ||||||||||||||||||
| return BILLING_REGION_GLOBAL | ||||||||||||||||||
| return BILLING_REGION_ALIASES.get(region.strip().upper(), BILLING_REGION_GLOBAL) | ||||||||||||||||||
|
Comment on lines
+98
to
+103
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The To ensure consistent default behavior for all empty or whitespace-only inputs, we should check if the stripped string is empty before performing the lookup.
Suggested change
greptile-apps[bot] marked this conversation as resolved.
|
||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def plan_price(plan_id: str, region: str | None = None) -> dict[str, Any]: | ||||||||||||||||||
| plan = PLANS[plan_id] | ||||||||||||||||||
| normalized_region = normalize_billing_region(region) | ||||||||||||||||||
| regional_price = PLAN_REGIONAL_PRICES.get(plan_id, {}).get(normalized_region) | ||||||||||||||||||
| if not regional_price: | ||||||||||||||||||
| return { | ||||||||||||||||||
| "price_minor_unit": int(plan.get("price_paise") or 0), | ||||||||||||||||||
| "currency": str(plan.get("currency") or "INR"), | ||||||||||||||||||
| } | ||||||||||||||||||
| return { | ||||||||||||||||||
| "price_minor_unit": int(regional_price["price_minor_unit"]), | ||||||||||||||||||
| "currency": str(regional_price.get("currency") or plan.get("currency") or "INR"), | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def plan_price_options(plan_id: str) -> dict[str, dict[str, Any]]: | ||||||||||||||||||
| options = PLAN_REGIONAL_PRICES.get(plan_id) | ||||||||||||||||||
| if not options: | ||||||||||||||||||
| return {} | ||||||||||||||||||
| return { | ||||||||||||||||||
| region: { | ||||||||||||||||||
| "price_minor_unit": int(price["price_minor_unit"]), | ||||||||||||||||||
| "currency": str(price.get("currency") or "INR"), | ||||||||||||||||||
| } | ||||||||||||||||||
| for region, price in options.items() | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def nominal_paise_per_credit(plan_id: str) -> float: | ||||||||||||||||||
| plan = PLANS[plan_id] | ||||||||||||||||||
| credits = int(plan.get("monthly_credits") or plan.get("trial_credits") or 0) | ||||||||||||||||||
|
|
||||||||||||||||||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| from src.utils import billing | ||
|
|
||
|
|
||
| def test_pro_plan_has_india_and_global_prices() -> None: | ||
| assert billing.plan_price("pro", "IN") == { | ||
| "price_minor_unit": 9_900, | ||
| "currency": "INR", | ||
| } | ||
| assert billing.plan_price("pro", "GLOBAL") == { | ||
| "price_minor_unit": 300, | ||
| "currency": "USD", | ||
| } | ||
| assert billing.PLANS["pro"]["monthly_credits"] == 5_000 | ||
|
|
||
|
|
||
| def test_billing_region_defaults_to_global_and_unknowns_are_global() -> None: | ||
| assert billing.normalize_billing_region(None) == billing.BILLING_REGION_GLOBAL | ||
| assert billing.normalize_billing_region("") == billing.BILLING_REGION_GLOBAL | ||
| assert billing.normalize_billing_region(" ") == billing.BILLING_REGION_GLOBAL | ||
| assert billing.normalize_billing_region("india") == billing.BILLING_REGION_IN | ||
| assert billing.normalize_billing_region("outside-india") == billing.BILLING_REGION_GLOBAL | ||
| assert billing.normalize_billing_region("UK") == billing.BILLING_REGION_GLOBAL | ||
|
|
||
|
|
||
| def test_plan_price_options_are_serializable() -> None: | ||
| assert billing.plan_price_options("pro") == { | ||
| "IN": {"price_minor_unit": 9_900, "currency": "INR"}, | ||
| "GLOBAL": {"price_minor_unit": 300, "currency": "USD"}, | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
billing_regionaccepted but silently ignored in verify handlerbilling_regionis added toVerifyPaymentRequestbutverify_razorpay_paymentnever readsrequest.billing_region— it neither cross-checks it against the stored checkout'sbilling_regionnor uses it for any grant logic. Callers who pass it will see no effect, and the API surface implies a behavior that isn't implemented.