Skip to content

Commit

Permalink
Merge pull request #22 from astoria-tech/azlyth/stripe-sandbox
Browse files Browse the repository at this point in the history
Integrate with Stripe (test mode)
  • Loading branch information
azlyth authored Feb 17, 2025
2 parents b1f3464 + f1f9db2 commit 4582fae
Show file tree
Hide file tree
Showing 15 changed files with 1,135 additions and 19 deletions.
3 changes: 1 addition & 2 deletions .cursorignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/.envrc
**/.envrc
.envrc
13 changes: 12 additions & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
- /app/node_modules
environment:
- NODE_ENV=development
- NEXT_PUBLIC_STRIPE_KEY=${NEXT_PUBLIC_STRIPE_KEY}
depends_on:
- backend

Expand All @@ -21,6 +22,7 @@ services:
- LOCALMART_UBER_DIRECT_CUSTOMER_ID=${LOCALMART_UBER_DIRECT_CUSTOMER_ID}
- LOCALMART_UBER_DIRECT_CLIENT_ID=${LOCALMART_UBER_DIRECT_CLIENT_ID}
- LOCALMART_UBER_DIRECT_CLIENT_SECRET=${LOCALMART_UBER_DIRECT_CLIENT_SECRET}
- STRIPE_SECRET_KEY=${STRIPE_SECRET_KEY}
- PYTHONPATH=/app
ports:
- "8000:8000"
Expand All @@ -30,6 +32,15 @@ services:
depends_on:
- pocketbase

stripe-cli:
image: stripe/stripe-cli
container_name: stripe-cli
command: "listen --api-key ${STRIPE_SECRET_KEY} --forward-to backend:8000/api/v0/webhooks/stripe"
environment:
- STRIPE_API_KEY=${STRIPE_SECRET_KEY}
depends_on:
- backend

pocketbase:
image: ghcr.io/muchobien/pocketbase:latest
ports:
Expand Down Expand Up @@ -68,4 +79,4 @@ services:
- meilisearch

volumes:
pocketbase_data:
pocketbase_data:
115 changes: 115 additions & 0 deletions db/pb_migrations/1739301952_created_payment_methods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = new Collection({
"createRule": "@request.auth.id != ''",
"deleteRule": "@request.auth.id = user.id",
"fields": [
{
"id": "user_relation",
"name": "user",
"type": "relation",
"required": true,
"presentable": false,
"system": false,
"cascadeDelete": true,
"collectionId": "_pb_users_auth_",
"maxSelect": 1,
"minSelect": 1
},
{
"id": "stripe_payment_method",
"name": "stripe_payment_method_id",
"type": "text",
"required": true,
"presentable": false,
"system": false,
"hidden": false
},
{
"id": "last4",
"name": "last4",
"type": "text",
"required": true,
"presentable": false,
"system": false,
"hidden": false
},
{
"id": "brand",
"name": "brand",
"type": "text",
"required": true,
"presentable": false,
"system": false,
"hidden": false
},
{
"id": "exp_month",
"name": "exp_month",
"type": "number",
"required": true,
"presentable": false,
"system": false,
"hidden": false,
"min": 1,
"max": 12,
"onlyInt": true
},
{
"id": "exp_year",
"name": "exp_year",
"type": "number",
"required": true,
"presentable": false,
"system": false,
"hidden": false,
"min": 2024,
"onlyInt": true
},
{
"id": "is_default",
"name": "is_default",
"type": "bool",
"required": true,
"presentable": false,
"system": false,
"hidden": false
},
{
"id": "created",
"name": "created",
"type": "autodate",
"required": false,
"presentable": false,
"system": false,
"hidden": false,
"onCreate": true,
"onUpdate": false
},
{
"id": "updated",
"name": "updated",
"type": "autodate",
"required": false,
"presentable": false,
"system": false,
"hidden": false,
"onCreate": true,
"onUpdate": true
}
],
"id": "payment_methods",
"indexes": ["CREATE UNIQUE INDEX idx_unique_payment_method ON payment_methods (user, stripe_payment_method_id)"],
"listRule": "@request.auth.id = user.id",
"name": "payment_methods",
"system": false,
"type": "base",
"updateRule": "@request.auth.id = user.id",
"viewRule": "@request.auth.id = user.id"
});

return app.save(collection);
}, (app) => {
const collection = app.findCollectionByNameOrId("payment_methods");
return app.delete(collection);
})
59 changes: 59 additions & 0 deletions db/pb_migrations/1739302173_updated_orders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = app.findCollectionByNameOrId("pbc_3527180448");

// add payment intent field
collection.fields.addAt(collection.fields.length, new Field({
"id": "stripe_payment_intent",
"name": "stripe_payment_intent_id",
"type": "text",
"required": false,
"presentable": false,
"system": false,
"hidden": false,
"autogeneratePattern": "",
"max": 0,
"min": 0,
"pattern": "",
"primaryKey": false
}));

// add payment method relation
collection.fields.addAt(collection.fields.length, new Field({
"id": "stripe_payment_method",
"name": "payment_method",
"type": "relation",
"required": false,
"presentable": false,
"system": false,
"hidden": false,
"collectionId": "payment_methods",
"cascadeDelete": false,
"maxSelect": 1,
"minSelect": 0
}));

// add payment status field
collection.fields.addAt(collection.fields.length, new Field({
"id": "stripe_payment_status",
"name": "payment_status",
"type": "select",
"required": true,
"presentable": false,
"system": false,
"hidden": false,
"values": ["pending", "processing", "succeeded", "failed", "refunded"],
"maxSelect": 1
}));

return app.save(collection);
}, (app) => {
const collection = app.findCollectionByNameOrId("pbc_3527180448");

// remove fields
collection.fields.removeById("stripe_payment_intent");
collection.fields.removeById("stripe_payment_method");
collection.fields.removeById("stripe_payment_status");

return app.save(collection);
})
65 changes: 65 additions & 0 deletions db/pb_migrations/1739302174_created_stripe_customers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
const collection = new Collection({
"createRule": "@request.auth.id != ''",
"deleteRule": "@request.auth.id = user.id",
"fields": [
{
"id": "user_relation",
"name": "user",
"type": "relation",
"required": true,
"presentable": false,
"system": false,
"cascadeDelete": true,
"collectionId": "_pb_users_auth_",
"maxSelect": 1,
"minSelect": 1
},
{
"id": "stripe_customer",
"name": "stripe_customer_id",
"type": "text",
"required": true,
"presentable": false,
"system": false,
"hidden": false
},
{
"id": "created",
"name": "created",
"type": "autodate",
"required": false,
"presentable": false,
"system": false,
"hidden": false,
"onCreate": true,
"onUpdate": false
},
{
"id": "updated",
"name": "updated",
"type": "autodate",
"required": false,
"presentable": false,
"system": false,
"hidden": false,
"onCreate": true,
"onUpdate": true
}
],
"id": "stripe_customers",
"indexes": ["CREATE UNIQUE INDEX idx_unique_customer ON stripe_customers (user, stripe_customer_id)"],
"listRule": "@request.auth.id = user.id",
"name": "stripe_customers",
"system": false,
"type": "base",
"updateRule": "@request.auth.id = user.id",
"viewRule": "@request.auth.id = user.id"
});

return app.save(collection);
}, (app) => {
const collection = app.findCollectionByNameOrId("stripe_customers");
return app.delete(collection);
})
30 changes: 25 additions & 5 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"dependencies": {
"@headlessui/react": "^2.2.0",
"@heroicons/react": "^2.2.0",
"@stripe/react-stripe-js": "^3.1.1",
"@stripe/stripe-js": "^5.6.0",
"next": "15.1.5",
"pocketbase": "^0.25.1",
"react": "^19.0.0",
Expand Down
Loading

0 comments on commit 4582fae

Please sign in to comment.