Skip to content
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

feat(billing): implement stripe checkout #323

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions apps/api/drizzle/0005_colorful_dreaming_celestial.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CREATE TABLE IF NOT EXISTS "checkout_sessions" (
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL,
"user_id" uuid NOT NULL,
"session_id" varchar NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL,
CONSTRAINT "checkout_sessions_session_id_unique" UNIQUE("session_id")
);
--> statement-breakpoint
ALTER TABLE "user_wallets" ALTER COLUMN "deployment_allowance" SET DATA TYPE numeric(20, 2);--> statement-breakpoint
ALTER TABLE "user_wallets" ALTER COLUMN "fee_allowance" SET DATA TYPE numeric(20, 2);--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "checkout_sessions" ADD CONSTRAINT "checkout_sessions_user_id_userSetting_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."userSetting"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
279 changes: 279 additions & 0 deletions apps/api/drizzle/meta/0005_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
{
"id": "d6102ad7-0e0c-4ef8-8712-6a626f5ad2a1",
"prevId": "43dc008c-31b1-4d9b-871f-21b6991441cc",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.user_wallets": {
"name": "user_wallets",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "uuid",
"primaryKey": false,
"notNull": false
},
"address": {
"name": "address",
"type": "varchar",
"primaryKey": false,
"notNull": false
},
"stripe_customer_id": {
"name": "stripe_customer_id",
"type": "varchar",
"primaryKey": false,
"notNull": false
},
"deployment_allowance": {
"name": "deployment_allowance",
"type": "numeric(20, 2)",
"primaryKey": false,
"notNull": true,
"default": "'0.00'"
},
"fee_allowance": {
"name": "fee_allowance",
"type": "numeric(20, 2)",
"primaryKey": false,
"notNull": true,
"default": "'0.00'"
},
"trial": {
"name": "trial",
"type": "boolean",
"primaryKey": false,
"notNull": false,
"default": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {
"user_wallets_user_id_userSetting_id_fk": {
"name": "user_wallets_user_id_userSetting_id_fk",
"tableFrom": "user_wallets",
"tableTo": "userSetting",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"user_wallets_user_id_unique": {
"name": "user_wallets_user_id_unique",
"nullsNotDistinct": false,
"columns": [
"user_id"
]
},
"user_wallets_address_unique": {
"name": "user_wallets_address_unique",
"nullsNotDistinct": false,
"columns": [
"address"
]
}
}
},
"public.checkout_sessions": {
"name": "checkout_sessions",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "uuid_generate_v4()"
},
"user_id": {
"name": "user_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"session_id": {
"name": "session_id",
"type": "varchar",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {
"checkout_sessions_user_id_userSetting_id_fk": {
"name": "checkout_sessions_user_id_userSetting_id_fk",
"tableFrom": "checkout_sessions",
"tableTo": "userSetting",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"checkout_sessions_session_id_unique": {
"name": "checkout_sessions_session_id_unique",
"nullsNotDistinct": false,
"columns": [
"session_id"
]
}
}
},
"public.userSetting": {
"name": "userSetting",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "uuid_generate_v4()"
},
"userId": {
"name": "userId",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"username": {
"name": "username",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"email": {
"name": "email",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"emailVerified": {
"name": "emailVerified",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false
},
"stripeCustomerId": {
"name": "stripeCustomerId",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"bio": {
"name": "bio",
"type": "text",
"primaryKey": false,
"notNull": false
},
"subscribedToNewsletter": {
"name": "subscribedToNewsletter",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false
},
"youtubeUsername": {
"name": "youtubeUsername",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"twitterUsername": {
"name": "twitterUsername",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"githubUsername": {
"name": "githubUsername",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"userSetting_userId_unique": {
"name": "userSetting_userId_unique",
"nullsNotDistinct": false,
"columns": [
"userId"
]
},
"userSetting_username_unique": {
"name": "userSetting_username_unique",
"nullsNotDistinct": false,
"columns": [
"username"
]
}
}
}
},
"enums": {},
"schemas": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
7 changes: 7 additions & 0 deletions apps/api/drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@
"when": 1724065113448,
"tag": "0004_spooky_cerise",
"breakpoints": true
},
{
"idx": 5,
"version": "7",
"when": 1724745930642,
"tag": "0005_colorful_dreaming_celestial",
"breakpoints": true
}
]
}
5 changes: 5 additions & 0 deletions apps/api/env/.env.functional.test
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ DEPLOYMENT_GRANT_DENOM=uakt
LOG_LEVEL=debug
BILLING_ENABLED=true
ANONYMOUS_USER_TOKEN_SECRET=ANONYMOUS_USER_TOKEN_SECRET
STRIPE_SECRET_KEY=STRIPE_SECRET_KEY
STRIPE_PRICE_ID=STRIPE_PRICE_ID
STRIPE_WEBHOOK_SECRET=STRIPE_WEBHOOK_SECRET
ALLOWED_CHECKOUT_REFERRERS=["http://localhost:3000"]
STRIPE_CHECKOUT_REDIRECT_URL=http://localhost:3000
3 changes: 2 additions & 1 deletion apps/api/env/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ PORT=80
ServerOrigin=https://api.cloudmos.io
DRIZZLE_MIGRATIONS_FOLDER=./dist/drizzle
SENTRY_ENABLED=true
BILLING_ENABLED=false
BILLING_ENABLED=false
STRIPE_CHECKOUT_REDIRECT_URL=https://console.akash.network
3 changes: 2 additions & 1 deletion apps/api/env/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ POSTGRES_DB_URI=
SecretToken=
SentryDSN=
SENTRY_DSN=
StripeSecretKey=
UserDatabaseCS=
STRIPE_SECRET_KEY=
STRIPE_PRICE_ID=

# Configuration
AKASHLYTICS_CORS_WEBSITE_URLS=
Expand Down
2 changes: 2 additions & 0 deletions apps/api/env/.env.staging
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ Auth0Issuer=https://dev-5aprb0lr.us.auth0.com/
SENTRY_TRACES_RATE=1.0
SENTRY_ENABLED=true
BILLING_ENABLED=true
STRIPE_PRICE_ID=price_1Ps0Y0Csz6Fy2xVWVy8GMTA9
STRIPE_CHECKOUT_REDIRECT_URL=https://beta.cloudmos.io
5 changes: 4 additions & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@cosmjs/math": "^0.32.4",
"@cosmjs/proto-signing": "^0.32.4",
"@cosmjs/stargate": "^0.32.4",
"@dotenvx/dotenvx": "^1.9.0",
"@hono/node-server": "1.4.0",
"@hono/sentry": "^1.0.0",
"@hono/swagger-ui": "0.2.1",
Expand All @@ -50,6 +51,7 @@
"@opentelemetry/instrumentation-pino": "^0.41.0",
"@opentelemetry/sdk-node": "^0.52.1",
"@sentry/node": "^7.55.2",
"@supercharge/promise-pool": "^3.2.0",
"@types/jsonwebtoken": "^9.0.6",
"@ucast/core": "^1.10.2",
"async-sema": "^3.1.1",
Expand All @@ -62,6 +64,7 @@
"dotenv": "^12.0.4",
"dotenv-expand": "^11.0.6",
"drizzle-orm": "^0.31.2",
"exponential-backoff": "^3.1.1",
"hono": "3.12.0",
"http-assert": "^1.5.0",
"http-errors": "^2.0.0",
Expand All @@ -83,7 +86,7 @@
"sequelize": "^6.21.3",
"sequelize-typescript": "^2.1.5",
"sql-formatter": "^15.3.2",
"stripe": "^10.14.0",
"stripe": "^16.8.0",
"tsyringe": "^4.8.0",
"uuid": "^9.0.1"
},
Expand Down
Loading
Loading