Fix payment plugin launch validation
This commit is contained in:
@@ -19,13 +19,39 @@ def _is_dummy_payment_app(app_label: str) -> bool:
|
|||||||
return "payment_dummy" in parts or normalized == "payment_dummy"
|
return "payment_dummy" in parts or normalized == "payment_dummy"
|
||||||
|
|
||||||
|
|
||||||
|
def _load_config_payload() -> dict:
|
||||||
|
config_path = Path(__file__).resolve().parent / "ocyan.json"
|
||||||
|
if not config_path.exists():
|
||||||
|
return {}
|
||||||
|
with config_path.open("r", encoding="utf-8") as handle:
|
||||||
|
return json.load(handle)
|
||||||
|
|
||||||
|
|
||||||
|
def get_declared_plugins() -> list[str]:
|
||||||
|
payload = _load_config_payload()
|
||||||
|
return [str(plugin) for plugin in payload.get("ocyan_plugins", [])]
|
||||||
|
|
||||||
|
|
||||||
|
def get_declared_payment_apps(installed_apps: list[str] | None = None) -> list[str]:
|
||||||
|
declared_plugins = [plugin for plugin in get_declared_plugins() if "payment" in plugin.lower()]
|
||||||
|
if declared_plugins:
|
||||||
|
return declared_plugins
|
||||||
|
installed_apps = installed_apps or list(settings.INSTALLED_APPS)
|
||||||
|
return [app for app in installed_apps if "payment" in app.lower()]
|
||||||
|
|
||||||
|
|
||||||
|
def get_checkout_apps() -> list[str]:
|
||||||
|
return [app for app in settings.INSTALLED_APPS if "checkout" in app.lower()]
|
||||||
|
|
||||||
|
|
||||||
def validate_payment_provider_config() -> None:
|
def validate_payment_provider_config() -> None:
|
||||||
installed_apps = list(settings.INSTALLED_APPS)
|
installed_apps = list(settings.INSTALLED_APPS)
|
||||||
payment_apps = [app for app in installed_apps if "payment" in app.lower()]
|
payment_apps = get_declared_payment_apps(installed_apps)
|
||||||
checkout_apps = [app for app in installed_apps if "checkout" in app.lower()]
|
checkout_apps = get_checkout_apps()
|
||||||
|
config_plugins = get_declared_plugins()
|
||||||
|
|
||||||
if not payment_apps:
|
if not payment_apps:
|
||||||
raise CommandError("No payment app found in INSTALLED_APPS.")
|
raise CommandError("No payment app declared for this project.")
|
||||||
if not checkout_apps:
|
if not checkout_apps:
|
||||||
raise CommandError("No checkout app found in INSTALLED_APPS.")
|
raise CommandError("No checkout app found in INSTALLED_APPS.")
|
||||||
if not any("oscar_checkout" in app.lower() for app in checkout_apps):
|
if not any("oscar_checkout" in app.lower() for app in checkout_apps):
|
||||||
@@ -34,9 +60,9 @@ def validate_payment_provider_config() -> None:
|
|||||||
raise CommandError(
|
raise CommandError(
|
||||||
"Demo data plugin detected in INSTALLED_APPS. Remove all demodata plugins before launch."
|
"Demo data plugin detected in INSTALLED_APPS. Remove all demodata plugins before launch."
|
||||||
)
|
)
|
||||||
if any(_is_dummy_payment_app(app) for app in payment_apps):
|
if any(_is_dummy_payment_app(app) for app in config_plugins):
|
||||||
raise CommandError(
|
raise CommandError(
|
||||||
"Dummy payment app detected in INSTALLED_APPS. Use a real provider plugin before production launch."
|
"Dummy payment app is declared in ocyan.json. Use a real provider plugin before production launch."
|
||||||
)
|
)
|
||||||
|
|
||||||
if any("mollie" in app.lower() for app in payment_apps):
|
if any("mollie" in app.lower() for app in payment_apps):
|
||||||
@@ -58,11 +84,7 @@ def validate_payment_provider_config() -> None:
|
|||||||
"Mollie key must be a live key for production launch (expected prefix 'live_')."
|
"Mollie key must be a live key for production launch (expected prefix 'live_')."
|
||||||
)
|
)
|
||||||
|
|
||||||
config_path = Path(__file__).resolve().parent / "ocyan.json"
|
if config_plugins:
|
||||||
if config_path.exists():
|
|
||||||
with config_path.open("r", encoding="utf-8") as handle:
|
|
||||||
config_payload = json.load(handle)
|
|
||||||
config_plugins = [str(plugin) for plugin in config_payload.get("ocyan_plugins", [])]
|
|
||||||
if any(_is_demo_data(plugin) for plugin in config_plugins):
|
if any(_is_demo_data(plugin) for plugin in config_plugins):
|
||||||
raise CommandError(
|
raise CommandError(
|
||||||
"Demo data plugin detected in ocyan.json. Remove it before launch."
|
"Demo data plugin detected in ocyan.json. Remove it before launch."
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ from mandelstudio.idea_marketplace import (
|
|||||||
SHORT_DESCRIPTION_ATTRIBUTE_CODE,
|
SHORT_DESCRIPTION_ATTRIBUTE_CODE,
|
||||||
)
|
)
|
||||||
from mandelstudio.launch_validation import (
|
from mandelstudio.launch_validation import (
|
||||||
_is_dummy_payment_app,
|
get_checkout_apps,
|
||||||
|
get_declared_payment_apps,
|
||||||
validate_payment_provider_config,
|
validate_payment_provider_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -38,11 +39,8 @@ class Command(BaseCommand):
|
|||||||
validate_payment_provider_config()
|
validate_payment_provider_config()
|
||||||
|
|
||||||
installed_apps = list(settings.INSTALLED_APPS)
|
installed_apps = list(settings.INSTALLED_APPS)
|
||||||
if any(_is_dummy_payment_app(app) for app in installed_apps):
|
payment_apps = get_declared_payment_apps(installed_apps)
|
||||||
raise CommandError(
|
checkout_apps = get_checkout_apps()
|
||||||
"Dummy payment app detected in INSTALLED_APPS. Use a real provider plugin before production launch."
|
|
||||||
)
|
|
||||||
|
|
||||||
config_path = Path(__file__).resolve().parents[2] / "ocyan.json"
|
config_path = Path(__file__).resolve().parents[2] / "ocyan.json"
|
||||||
if config_path.exists():
|
if config_path.exists():
|
||||||
with config_path.open("r", encoding="utf-8") as handle:
|
with config_path.open("r", encoding="utf-8") as handle:
|
||||||
|
|||||||
Reference in New Issue
Block a user