-
Notifications
You must be signed in to change notification settings - Fork 501
Custom item customers #855
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a30a864
type fix
BilalG1 d6397fa
custom customer type
BilalG1 5e5c0ae
merge dev
BilalG1 d0e4e09
small fixes
BilalG1 1018ee5
fix test
BilalG1 553ffe0
fix issues
BilalG1 7e95b6b
revert import changes
BilalG1 da6f000
fix test
BilalG1 e8501bf
Merge dev into custom-item-customers
N2D4 917f7a8
Merge dev into custom-item-customers
N2D4 b592421
Merge dev into custom-item-customers
N2D4 f38aa1e
customCustomerId
BilalG1 509762d
merge dev
BilalG1 13ef13f
offer and item pages, edits, deletes (#856)
BilalG1 93fb85a
Merge branch 'dev' into custom-item-customers
BilalG1 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
15 changes: 15 additions & 0 deletions
15
apps/backend/prisma/migrations/20250820164831_custom_customer_types/migration.sql
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,15 @@ | ||
| /* | ||
| Warnings: | ||
|
|
||
| - Added the required column `customerType` to the `ItemQuantityChange` table without a default value. This is not possible if the table is not empty. | ||
|
|
||
| */ | ||
| -- AlterEnum | ||
| ALTER TYPE "CustomerType" ADD VALUE 'CUSTOM'; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "ItemQuantityChange" ADD COLUMN "customerType" "CustomerType" NOT NULL, | ||
| ALTER COLUMN "customerId" SET DATA TYPE TEXT; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "Subscription" ALTER COLUMN "customerId" SET DATA TYPE TEXT; | ||
12 changes: 12 additions & 0 deletions
12
apps/backend/prisma/migrations/20250821175509_test_mode_subscriptions/migration.sql
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,12 @@ | ||
| /* | ||
| Warnings: | ||
|
|
||
| - Added the required column `creationSource` to the `Subscription` table without a default value. This is not possible if the table is not empty. | ||
|
|
||
| */ | ||
| -- CreateEnum | ||
| CREATE TYPE "SubscriptionCreationSource" AS ENUM ('PURCHASE_PAGE', 'TEST_MODE'); | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "Subscription" ADD COLUMN "creationSource" "SubscriptionCreationSource" NOT NULL, | ||
| ALTER COLUMN "stripeSubscriptionId" DROP NOT NULL; |
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
66 changes: 66 additions & 0 deletions
66
apps/backend/src/app/api/latest/internal/payments/test-mode-purchase-session/route.tsx
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,66 @@ | ||
| import { createSmartRouteHandler } from "@/route-handlers/smart-route-handler"; | ||
| import { adaptSchema, adminAuthTypeSchema, yupNumber, yupObject, yupString } from "@stackframe/stack-shared/dist/schema-fields"; | ||
| import { purchaseUrlVerificationCodeHandler } from "@/app/api/latest/payments/purchases/verification-code-handler"; | ||
| import { StackAssertionError, StatusError } from "@stackframe/stack-shared/dist/utils/errors"; | ||
| import { getPrismaClientForTenancy } from "@/prisma-client"; | ||
| import { addInterval } from "@stackframe/stack-shared/dist/utils/dates"; | ||
| import { typedToUppercase } from "@stackframe/stack-shared/dist/utils/strings"; | ||
|
|
||
| export const POST = createSmartRouteHandler({ | ||
| metadata: { | ||
| hidden: true, | ||
| }, | ||
| request: yupObject({ | ||
| auth: yupObject({ | ||
| type: adminAuthTypeSchema.defined(), | ||
| project: adaptSchema.defined(), | ||
| tenancy: adaptSchema.defined(), | ||
| }).defined(), | ||
| body: yupObject({ | ||
| full_code: yupString().defined(), | ||
| price_id: yupString().defined(), | ||
| }), | ||
| }), | ||
| response: yupObject({ | ||
| statusCode: yupNumber().oneOf([200]).defined(), | ||
| bodyType: yupString().oneOf(["success"]).defined(), | ||
| }), | ||
| handler: async ({ auth, body }) => { | ||
| const { full_code, price_id } = body; | ||
| const { data, id: codeId } = await purchaseUrlVerificationCodeHandler.validateCode(full_code); | ||
| if (auth.tenancy.id !== data.tenancyId) { | ||
| throw new StatusError(400, "Tenancy id does not match value from code data"); | ||
| } | ||
| const prisma = await getPrismaClientForTenancy(auth.tenancy); | ||
| const pricesMap = new Map(Object.entries(data.offer.prices)); | ||
| const selectedPrice = pricesMap.get(price_id); | ||
| if (!selectedPrice) { | ||
| throw new StatusError(400, "Price not found on offer associated with this purchase code"); | ||
| } | ||
| if (!selectedPrice.interval) { | ||
| throw new StackAssertionError("unimplemented; prices without an interval are currently not supported"); | ||
| } | ||
| await prisma.subscription.create({ | ||
| data: { | ||
| tenancyId: auth.tenancy.id, | ||
| customerId: data.customerId, | ||
| customerType: typedToUppercase(data.offer.customerType), | ||
| status: "active", | ||
| offer: data.offer, | ||
| currentPeriodStart: new Date(), | ||
| currentPeriodEnd: addInterval(new Date(), selectedPrice.interval), | ||
| cancelAtPeriodEnd: false, | ||
| creationSource: "TEST_MODE", | ||
| }, | ||
| }); | ||
| await purchaseUrlVerificationCodeHandler.revokeCode({ | ||
| tenancy: auth.tenancy, | ||
| id: codeId, | ||
| }); | ||
|
|
||
| return { | ||
| statusCode: 200, | ||
| bodyType: "success", | ||
| }; | ||
| }, | ||
| }); |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.