-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
273 additions
and
260 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
.vscode | ||
merchants_orig | ||
store | ||
### Python ### | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
|
This file contains 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 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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,30 @@ | ||
# from starlette_admin.contrib.sqla import Admin | ||
|
||
# from merchants.database import engine | ||
|
||
# admin = Admin(engine, title="Merchants Admin") | ||
|
||
|
||
class IntegrationAdminMixin: | ||
exclude_fields_from_list = ["id", "config"] | ||
exclude_fields_from_create = ["id"] | ||
exclude_fields_from_edit = ["id"] | ||
fields_default_sort = ["slug"] | ||
searchable_fields = ["name", "slug", "integration_class", "config"] | ||
|
||
|
||
class PaymentAdminMixin: | ||
exclude_fields_from_list = [ | ||
"id", | ||
"integration_slug", | ||
"integration_payload", | ||
"integration_response", | ||
"modified_at", | ||
] | ||
exclude_fields_from_create = ["id"] | ||
exclude_fields_from_edit = ["id"] | ||
|
||
|
||
# admin.add_view(UserAdmin(User, icon="fas fa-person")) | ||
# admin.add_view(PaymentAdmin(Payment, icon="fas fa-wallet")) | ||
# admin.add_view(IntegrationAdmin(Integration, icon="fas fa-list")) |
This file contains 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,47 @@ | ||
from typing import Any | ||
|
||
import rich | ||
from fastapi import APIRouter, Body, Request | ||
|
||
# from merchants.config import settings | ||
# from merchants.FastapiAdmin import admin | ||
# from merchants.version import __version__ as __merchants_version__ | ||
|
||
fastapi_route = APIRouter() | ||
|
||
# app = FastAPI( | ||
# title=settings.PROJECT_NAME, | ||
# version=__merchants_version__, | ||
# description="A unified payment processing toolkit for Starlette/FastAPI applications", | ||
# debug=settings.DEBUG, | ||
# ) | ||
|
||
default_body = Body(None) | ||
|
||
|
||
@fastapi_route.post( | ||
"/update-payment/{integration}", | ||
name="update_payment", | ||
description="This route processes the status updates from the integrations.", | ||
) | ||
async def update_payment( | ||
integration: str, | ||
request: Request, | ||
body_payload: Any = default_body, | ||
): | ||
rich.print(f"{body_payload = }") | ||
rich.print(f"{integration = }") | ||
rich.print(f"{request.headers = }") | ||
rich.print(f"{request.query_params = }") | ||
body = await request.body() | ||
rich.print(f"{body = }") | ||
return {"message": "Hello World"} | ||
|
||
|
||
# app.include_router(app_route, prefix=settings.MERCHANTS_API_ROUTER_PREFIX) | ||
# admin.debug = app.debug | ||
# admin.mount_to(app) | ||
|
||
|
||
# url_list = [{"path": route.path, "name": route.name} for route in app.routes] | ||
# rich.print(url_list) |
This file contains 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 @@ | ||
from typing import Any | ||
|
||
# Intentionally the same structure as django-payments for compatibility reasons | ||
INTEGRATIONS: dict[str, tuple[str, dict]] = { | ||
"default": ( | ||
"merchants.integrations.dummy", | ||
{}, | ||
), | ||
} | ||
|
||
|
||
INTEGRATIONS_CACHE: dict[str, Any] = {} |
This file contains 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,46 @@ | ||
import rich | ||
|
||
|
||
def integration_factory(slug: str, config: dict): | ||
rich.print(f"Creating integration {slug} ...") | ||
|
||
return {} | ||
|
||
|
||
def find_integration(slug: str): | ||
rich.print(f"Searching for integration: {slug} ...") | ||
|
||
return { | ||
"name": "Simple Integration", | ||
"slug": "dummy", | ||
"is_active": True, | ||
"integration_class": "merchants.integrations.dummy", | ||
"config": { | ||
"not_needed": True, | ||
}, | ||
} | ||
|
||
|
||
def load_integration(slug: str): | ||
rich.print(f"Loading {slug} to cache...") | ||
|
||
|
||
def process_payment(payment): | ||
rich.print(payment) | ||
|
||
if payment.status not in ["created"]: | ||
raise AttributeError("Only created payments can start the process.") | ||
|
||
integration, _ = find_integration(payment.integration_slug) | ||
# if not payment.integration_id: | ||
# if getattr(settings, "LOAD_FROM_DATABASE", None): | ||
# integration_config = None | ||
# else: | ||
# integration_config = getattr(settings, payment.integration_slug, None) | ||
# else: | ||
# rich.print(f"Using integration: {payment.integration} ...") | ||
# integration_config = payment.integration.config | ||
|
||
rich.print(f"{integration = }") | ||
|
||
return payment |
This file contains 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 |
---|---|---|
@@ -1,31 +1,15 @@ | ||
import secrets | ||
|
||
from pydantic import HttpUrl, computed_field | ||
from pydantic_settings import BaseSettings, SettingsConfigDict | ||
from pydantic_settings import BaseSettings | ||
|
||
|
||
class Settings(BaseSettings): | ||
model_config = SettingsConfigDict(env_file=".env", env_ignore_empty=True, extra="ignore") | ||
SECRET_KEY: str = secrets.token_urlsafe(32) | ||
USE_HTTPS: bool = False | ||
DOMAIN: str = "tardis.local" | ||
DEBUG: bool = True | ||
|
||
@computed_field # type: ignore[prop-decorator] | ||
@property | ||
def server_host(self) -> str: | ||
if self.USE_HTTPS: | ||
return f"https://{self.DOMAIN}" | ||
return f"http://{self.DOMAIN}" | ||
|
||
PROJECT_NAME: str = "Merchants" | ||
SENTRY_DSN: HttpUrl | None = None | ||
|
||
SQLALCHEMY_DATABASE_URL: str = "sqlite:///merchants.db" | ||
PROCESS_ON_SAVE: bool = True | ||
"""Process the payment before commiting to database.""" | ||
|
||
ALLOWED_DOMAINS: list[str] | None = None | ||
LOAD_FROM_DATABASE: bool = False | ||
"""Retrieves Integrations from database.""" | ||
|
||
PROCESS_ON_SAVE: bool = True | ||
API_ROUTER_PREFIX: str = "/merchants" | ||
"""Base URI for Application.""" | ||
|
||
|
||
settings = Settings() # type: ignore |
This file contains 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,2 @@ | ||
def get_integration(slug: str) -> dict: | ||
return {} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.