Skip to content

Commit

Permalink
Remove Stripe integration and add staging configuration file (#659)
Browse files Browse the repository at this point in the history
* Remove Stripe integration and add staging configuration file

* Clean up
  • Loading branch information
ivntsng authored Dec 9, 2024
1 parent fe89ee1 commit 6431be8
Show file tree
Hide file tree
Showing 21 changed files with 17 additions and 1,515 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ env:
ONSHAPE_API: ${{ secrets.ONSHAPE_API }}
ONSHAPE_ACCESS_KEY: ${{ secrets.ONSHAPE_ACCESS_KEY }}
ONSHAPE_SECRET_KEY: ${{ secrets.ONSHAPE_SECRET_KEY }}
STRIPE_SECRET_KEY: ${{ secrets.STRIPE_SECRET_KEY }}
STRIPE_WEBHOOK_SECRET: ${{ secrets.STRIPE_WEBHOOK_SECRET }}
STRIPE_CONNECT_WEBHOOK_SECRET: ${{ secrets.STRIPE_CONNECT_WEBHOOK_SECRET }}

jobs:
run-tests:
Expand Down
37 changes: 5 additions & 32 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

To get started, clone the repository and check out the [Project Tracker](https://github.com/orgs/kscalelabs/projects/8/views/1).

You can contribute to the K-Scale Store project in various ways, such as reporting bugs, submitting pull requests, raising issues, or creating suggestions.
You can contribute to the K-Scale WWW project in various ways, such as reporting bugs, submitting pull requests, raising issues, or creating suggestions.

> [!IMPORTANT]
> You **MUST** access the locally run website through `127.0.0.1:3000` and **NOT** `localhost:3000`. This is because the CORS policy is configured to only allow requests from the exact domain `127.0.0.1:3000`.
Expand All @@ -29,15 +29,14 @@ You can contribute to the K-Scale Store project in various ways, such as reporti
4. [Syncing Frontend and Backend](#syncing-frontend-and-backend)
5. [React Setup](#react-setup)
6. [Testing](#testing)
7. [Stripe Setup](#stripe-setup)

---

## Development Setup

### Configuration

Backend settings are located in the `store/settings/` directory. You can specify which settings to use by setting the `ENVIRONMENT` variable to the corresponding config file stem in `store/settings/configs/`. For local development, this should typically be set to `local`.
Backend settings are located in the `www/settings/` directory. You can specify which settings to use by setting the `ENVIRONMENT` variable to the corresponding config file stem in `www/settings/configs/`. For local development, this should typically be set to `local`.

Place the required environment variables in `env.sh` or `.env.local`.

Expand Down Expand Up @@ -80,12 +79,6 @@ export VITE_GOOGLE_CLIENT_ID=''
# For OnShape
export ONSHAPE_ACCESS_KEY=''
export ONSHAPE_SECRET_KEY=''

# For Stripe
export VITE_STRIPE_PUBLISHABLE_KEY=''
export STRIPE_SECRET_KEY=''
export STRIPE_WEBHOOK_SECRET=''
export STRIPE_CONNECT_WEBHOOK_SECRET=''
```

### Google OAuth Configuration
Expand Down Expand Up @@ -188,23 +181,23 @@ pip install -e '.[dev]' # Using vanilla pip
If additional packages are missing, try:

```bash
uv pip install -r store/requirements.txt -r store/requirements-dev.txt # Using uv
uv pip install -r www/requirements.txt -r www/requirements-dev.txt # Using uv
```

### Initializing the Test Databases

Initialize the test databases with:

```bash
python -m store.app.db create
python -m www.app.db create
```

### Running the FastAPI Application

Serve the FastAPI application in development mode:

```bash
make start-backend
make start
```

## Syncing Frontend and Backend
Expand Down Expand Up @@ -253,28 +246,8 @@ To run tests, use the following commands:

```bash
make test
make test-frontend # Run only the frontend tests
make test-backend # Run only the backend tests
```

## Stripe Setup

Run this to recieve stripe webhooks locally:

```bash
stripe listen --forward-to localhost:8080/stripe/webhook
```

Run this to recieve stripe connect webhooks locally:

```bash
stripe listen --forward-connect-to localhost:8080/stripe/connect/webhook
```

Make sure to set the `STRIPE_WEBHOOK_SECRET` and `STRIPE_CONNECT_WEBHOOK_SECRET` environment variables to the values
shown in the terminal and source it to the terminal you are running
`make start-backend` in.

## Optional

Install pre-commit from [here](https://pre-commit.com/) to run the formatting and static checks automatically when you commit.
Expand Down
6 changes: 0 additions & 6 deletions env.sh.example
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,3 @@ export GOOGLE_CLIENT_SECRET=''
# For OnShape
export ONSHAPE_ACCESS_KEY=''
export ONSHAPE_SECRET_KEY=''

# For Stripe developer mode.
export VITE_STRIPE_PUBLISHABLE_KEY=''
export STRIPE_SECRET_KEY=''
export STRIPE_WEBHOOK_SECRET=''
export STRIPE_CONNECT_WEBHOOK_SECRET=''
1 change: 0 additions & 1 deletion tests/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def test_user_auth_functions(test_client: TestClient, tmpdir: Path) -> None:
"child_ids": "",
"slug": "test-listing",
"username": "testuser",
"stripe_link": "",
},
headers=auth_headers,
)
Expand Down
1 change: 0 additions & 1 deletion tests/test_krec.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ async def test_krec_upload(test_client: TestClient, tmpdir: Path) -> None:
"child_ids": "",
"slug": "test-listing",
"username": "testuser",
"stripe_link": "",
},
headers=auth_headers,
)
Expand Down
1 change: 0 additions & 1 deletion tests/test_listings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def test_listings(test_client: TestClient, tmpdir: Path) -> None:
"child_ids": "",
"slug": "test-listing",
"username": "testuser",
"stripe_link": "",
},
headers=auth_headers,
)
Expand Down
34 changes: 1 addition & 33 deletions www/app/crud/listings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ListingsCrud(ArtifactsCrud, BaseCrud):

@classmethod
def get_gsis(cls) -> set[str]:
return super().get_gsis().union({"listing_id", "name", "stripe_product_id"})
return super().get_gsis().union({"listing_id", "name"})

@overload
async def get_listing(self, listing_id: str, throw_if_missing: Literal[True]) -> Listing: ...
Expand Down Expand Up @@ -158,14 +158,6 @@ async def edit_listing(
tags: list[str] | None = None,
onshape_url: str | None = None,
slug: str | None = None,
price_amount: int | None = None,
stripe_product_id: str | None = None,
stripe_price_id: str | None = None,
preorder_release_date: int | None = None,
preorder_deposit_amount: int | None = None,
stripe_preorder_deposit_id: str | None = None,
inventory_type: str | None = None,
inventory_quantity: int | None = None,
) -> None:
listing = await self.get_listing(listing_id)
if listing is None:
Expand All @@ -180,22 +172,6 @@ async def edit_listing(
updates["description"] = description
if slug is not None:
updates["slug"] = slug
if price_amount is not None:
updates["price_amount"] = price_amount
if stripe_product_id is not None:
updates["stripe_product_id"] = stripe_product_id
if stripe_price_id is not None:
updates["stripe_price_id"] = stripe_price_id
if preorder_release_date is not None:
updates["preorder_release_date"] = preorder_release_date
if preorder_deposit_amount is not None:
updates["preorder_deposit_amount"] = preorder_deposit_amount
if stripe_preorder_deposit_id is not None:
updates["stripe_preorder_deposit_id"] = stripe_preorder_deposit_id
if inventory_type is not None:
updates["inventory_type"] = inventory_type
if inventory_quantity is not None:
updates["inventory_quantity"] = inventory_quantity

coroutines = []
if tags is not None:
Expand Down Expand Up @@ -412,11 +388,3 @@ async def set_featured_listings(self, listing_ids: list[str]) -> None:
"updated_at": int(time.time()),
}
)

async def get_listing_by_stripe_product_id(self, stripe_product_id: str) -> Listing | None:
"""Get a listing by its stripe product ID."""
listings = await self._get_items_from_secondary_index(
secondary_index_name="stripe_product_id", secondary_index_value=stripe_product_id, item_class=Listing
)
# stripe_product_id should be unique, return the first item if it exists
return listings[0] if listings else None
130 changes: 0 additions & 130 deletions www/app/crud/orders.py

This file was deleted.

26 changes: 2 additions & 24 deletions www/app/crud/robots.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
from typing import NotRequired, TypedDict, Unpack

from www.app.crud.base import BaseCrud, ItemNotFoundError
from www.app.model import Listing, Order, Robot
from www.app.model import Listing, Robot


class RobotData(TypedDict):
user_id: str
listing_id: str
name: str
description: NotRequired[str | None]
order_id: NotRequired[str | None]
updated_at: NotRequired[int]


Expand All @@ -21,28 +20,19 @@ class RobotsCrud(BaseCrud):

@classmethod
def get_gsis(cls) -> set[str]:
return super().get_gsis().union({"listing_id", "order_id"})
return super().get_gsis().union({"listing_id"})

async def create_robot(self, **robot_data: Unpack[RobotData]) -> Robot:
# Verify listing exists
listing = await self._get_item(robot_data["listing_id"], Listing)
if not listing:
raise ItemNotFoundError(f"Listing with ID {robot_data['listing_id']} not found")

# Verify order exists if order_id is provided
if order_id := robot_data.get("order_id"):
order = await self._get_item(order_id, Order)
if not order:
raise ItemNotFoundError(f"Order with ID {order_id} not found")
if order.user_id != robot_data["user_id"]:
raise ItemNotFoundError(f"Order with ID {order_id} does not belong to this user")

robot = Robot.create(
user_id=robot_data["user_id"],
listing_id=robot_data["listing_id"],
name=robot_data["name"],
description=robot_data.get("description"),
order_id=robot_data.get("order_id"),
)
await self._add_item(robot)
return robot
Expand All @@ -66,14 +56,6 @@ async def update_robot(self, robot_id: str, update_data: RobotData) -> Robot:
if not robot:
raise ItemNotFoundError("Robot not found")

# Verify order exists if order_id is being updated
if order_id := update_data.get("order_id"):
order = await self._get_item(order_id, Order)
if not order:
raise ItemNotFoundError(f"Order with ID {order_id} not found")
if order.user_id != robot.user_id:
raise ItemNotFoundError(f"Order with ID {order_id} does not belong to this user")

update_data["updated_at"] = int(time.time())
# Convert TypedDict to regular dict
update_dict = dict(update_data)
Expand All @@ -84,7 +66,3 @@ async def update_robot(self, robot_id: str, update_data: RobotData) -> Robot:

async def delete_robot(self, robot: Robot) -> None:
await self._delete_item(robot)

async def get_robot_by_order_id(self, order_id: str) -> Robot | None:
robots = await self._get_items_from_secondary_index("order_id", order_id, Robot)
return robots[0] if robots else None
Loading

0 comments on commit 6431be8

Please sign in to comment.