Repository navigation
Add promo code support to billing API #685
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
alisawavezen12
wants to merge
13
commits into
master
Choose a base branch
from
feat/promocodes
base: master
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
13 commits
Select commit
Hold shift + click to select a range
7534e06
step 1
alisawavezen12 8b42f9f
redemptions
alisawavezen12 6b5988f
chore
alisawavezen12 a2e1536
chore
alisawavezen12 68ec256
chore
alisawavezen12 51647cb
chore
alisawavezen12 ea0aa88
lint fix
alisawavezen12 e1b3003
chore
alisawavezen12 0b8a222
Merge branch 'master' into feat/promocodes
alisawavezen12 0fc4e66
Bump version up to 1.6.1
github-actions[bot] 4386d72
fix
alisawavezen12 8698c72
chore
alisawavezen12 7b4bac5
Sign subscription dates in payment checksums
alisawavezen12 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
48 changes: 48 additions & 0 deletions
48
migrations/20261013000000-create-promo-code-collections.js
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,48 @@ | ||
| /** | ||
| * Create promo code collections and prevent repeated use by a user or workspace. | ||
| * MongoDB creates the collections when their indexes are created. | ||
| */ | ||
| module.exports = { | ||
| /** | ||
| * Create unique indexes for promo codes and successful redemptions. | ||
| * | ||
| * @param {Db} db - MongoDB database receiving the promo code indexes. | ||
| * @returns {Promise<void>} Resolves when all indexes have been created. | ||
| */ | ||
| async up(db) { | ||
| await db.collection('promoCodes').createIndex({ | ||
| code: 1, | ||
| }, { | ||
| name: 'promoCode', | ||
| unique: true, | ||
| }); | ||
|
|
||
| await db.collection('promoCodeRedemptions').createIndex({ | ||
| promoCodeId: 1, | ||
| userId: 1, | ||
| }, { | ||
| name: 'promoCodeUser', | ||
| unique: true, | ||
| }); | ||
|
|
||
| await db.collection('promoCodeRedemptions').createIndex({ | ||
| promoCodeId: 1, | ||
| workspaceId: 1, | ||
| }, { | ||
| name: 'promoCodeWorkspace', | ||
| unique: true, | ||
| }); | ||
| }, | ||
|
|
||
| /** | ||
| * Remove the promo code indexes while preserving collection data. | ||
| * | ||
| * @param {Db} db - MongoDB database containing the promo code indexes. | ||
| * @returns {Promise<void>} Resolves when all indexes have been removed. | ||
| */ | ||
| async down(db) { | ||
| await db.collection('promoCodeRedemptions').dropIndex('promoCodeWorkspace'); | ||
| await db.collection('promoCodeRedemptions').dropIndex('promoCodeUser'); | ||
| await db.collection('promoCodes').dropIndex('promoCode'); | ||
| }, | ||
| }; |
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.
Now the same field means different things depending on the promo code: for regular payments it's the team membership
_id(as in master), for promo payments it's the user id.In this repo,
userIdof a plan purchase is read only by the newvalidatePromoOperation(). I'd keepmember._idfor all payments and drop theuserIdcomparison there:transactionId, workspace, plan and amount are enough to match the operation, and the redemption already gets the user id from the signed checksum. If we want to store the real user id, let's change it for all payments in a separate PR.