-
Notifications
You must be signed in to change notification settings - Fork 1
Referral Program Reward: 5 Referrals = 6 Months Free #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
google-labs-jules
wants to merge
9
commits into
saas
Choose a base branch
from
feature/referral-rewards-4126785755739167118
base: saas
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c51ddb7
feat: Implement 6 months free plus tier reward for 5 referrals
google-labs-jules[bot] abf630b
feat: Implement 6 months free plus tier reward for 5 referrals
google-labs-jules[bot] 098744b
feat: Make referral reward parameters configurable
google-labs-jules[bot] c4677a4
Update tests/integration/test_referral_upgrade.py
Miyamura80 cac6cce
Update tests/integration/test_referral_upgrade.py
Miyamura80 f1c1ed3
feat: Make referral reward parameters configurable
google-labs-jules[bot] 31d468b
feat: Make referral reward parameters configurable
google-labs-jules[bot] 2a4cd72
Merge branch 'saas' into feature/referral-rewards-4126785755739167118
Miyamura80 5c6debe
feat: Make referral reward parameters configurable
google-labs-jules[bot] 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 |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # Referral Program | ||
|
|
||
| The application includes a referral system that rewards users for inviting others to the platform. | ||
|
|
||
| ## Incentive: Refer 5, Get 6 Months Free (Default) | ||
|
|
||
| When a user successfully refers a specific number of new users (default: **5**), they are automatically rewarded with a period of the Plus Tier subscription for free (default: **6 months**). | ||
|
|
||
| ### Configuration | ||
|
|
||
| The referral program parameters are configurable in `common/global_config.yaml` under the `subscription.referral` section: | ||
|
|
||
| ```yaml | ||
| subscription: | ||
| referral: | ||
| referrals_required: 5 | ||
| reward_months: 6 | ||
| ``` | ||
|
|
||
| ### How it works | ||
|
|
||
| 1. **Referral Code**: Each user has a unique referral code. | ||
| 2. **Invitation**: Users share their code with potential new users. | ||
| 3. **Redemption**: When a new user signs up (or enters the code in their settings), they apply the referral code. | ||
| 4. **Tracking**: The system tracks the number of successful referrals for each referrer. | ||
| 5. **Reward Trigger**: | ||
| * Once the referrer's count reaches the configured `referrals_required`, the system automatically grants the reward. | ||
| * **New Subscription**: If the referrer is on the Free tier, they are upgraded to the Plus tier for `reward_months`. | ||
| * **Existing Subscription**: If the referrer already has a Plus tier subscription, their subscription end date is extended by `reward_months`. | ||
|
|
||
| ### Technical Implementation | ||
|
|
||
| The logic is handled in `src/api/services/referral_service.py` within the `apply_referral` method. When the referral count increments to the configured threshold, the `grant_referral_reward` method is called to update the `UserSubscriptions` table. |
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
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
Oops, something went wrong.
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.
logic: Function modifies database but doesn't handle its own transaction. Called from within
db_transactioncontext inapply_referral, but changes won't be committed if called elsewhere. Either make this function handle its own transaction, or document that it must be called within an active transaction context.Prompt To Fix With AI
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.
what do you mean by this? Can you explain?
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.
The issue is that
grant_referral_rewardmodifies the database (lines 44-45, 54/56, and 69) but doesn't handle database transactions itself. Let me explain the problem:Current situation:
grant_referral_rewardmakes database changes but has nodb.commit()or transaction managementapply_referral(line 109) which wraps its work indb_transactiongrant_referral_rewarddirectly from elsewhere, the changes won't be saved to the databaseThe problem:
Two solutions:
Option 1: Make it handle its own transaction
Option 2: Document the requirement
Add to the docstring: "Must be called within an active database transaction context."
I'd recommend Option 1 since it makes the function safer to use independently.
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.
This logic determines the start and end dates of the free period:
now).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.
ok @jules please do as greptile says and go with option 1 and handle the DB transaction. (unless you disagree. if you disagree pls say)
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.
I apologize, but I cannot see the comment from @greptile to reference 'Option 1'. However, regarding transaction handling: The
grant_referral_rewardmethod is currently designed to run within the active transaction managed byapply_referral. This ensures atomicity: if the reward fails, the referral count update rolls back too. If 'Option 1' suggests wrappinggrant_referral_rewardin its owndb_transaction, please note that this would commit the transaction immediately, potentially affecting the atomicity of the calling function. I believe the current approach is the safest for data integrity. Please let me know if you'd like me to proceed differently!