Skip to content
Snippets Groups Projects
Verified Commit 3189a9e3 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Implement configuration of payment backends

parent e67e9486
No related branches found
No related tags found
1 merge request!3Implement payment backends and interaction
This commit is part of merge request !3. Comments created here will be created in the context of that merge request.
from django.apps import apps
from aleksis.core.util.apps import AppConfig
from aleksis.core.util.core_helpers import get_site_preferences
class DefaultConfig(AppConfig):
......@@ -11,3 +14,39 @@ class DefaultConfig(AppConfig):
}
licence = "EUPL-1.2+"
copyright_info = (([2022], "Dominik George", "dominik.george@teckids.org"),)
def ready(self):
from django.conf import settings # noqa
settings.PAYMENT_MODEL = "tezor.Invoice"
settings.PAYMENT_VARIANTS = {
"dummy": ("payments.dummy.DummyProvider", {})
}
for app_config in apps.app_configs.values():
if hasattr(app_config, "get_payment_variants"):
variants = app_config.get_payment_variants()
for name, config in variants.items():
if name not in settings.PAYMENT_VARIANTS:
settings.PAYMENT_VARIANTS[name] = config
def get_payment_variants(self):
prefs = get_site_preferences()
variants = {}
if prefs["payments__sofort_api_id"]:
variants["sofort"] = ("payments.sofort.SofortProvider", {
"id": prefs["payments__sofort_api_id"],
"key": prefs["payments__sofort_api_key"],
"project_id": prefs["payments__sofort_project_id"],
"endpoint": "https://api.sofort.com/api/xml",
})
if prefs["payments__paypal_client_id"]:
variants["paypal"] = ("payments.paypal.PaypalProvider", {
"client_id": prefs["payments__paypal_client_id"],
"secret": prefs["payments__paypal_secret"],
"capture": not prefs["payments__paypal_capture"],
"endpoint": "https://api.paypal.com",
})
return variants
from django.utils.translation import gettext_lazy as _
from dynamic_preferences.preferences import Section
from dynamic_preferences.types import BooleanPreference, StringPreference
from aleksis.core.registries import site_preferences_registry
payments = Section("payments", verbose_name=_("Payments"))
@site_preferences_registry.register
class SofortAPIID(StringPreference):
"""Sofort payment backend - API ID."""
section = payments
name = "sofort_api_id"
verbose_name = _("Sofort / Klarna - API ID")
default = ""
required = False
@site_preferences_registry.register
class SofortAPIKey(StringPreference):
"""Sofort payment backend - API key."""
section = payments
name = "sofort_api_key"
verbose_name = _("Sofort / Klarna - API Key")
default = ""
required = False
@site_preferences_registry.register
class SofortProjectID(StringPreference):
"""Sofort payment backend - project ID."""
section = payments
name = "sofort_project_id"
verbose_name = _("Sofort / Klarna - Project ID")
default = ""
required = False
@site_preferences_registry.register
class PaypalClientID(StringPreference):
"""PayPal payment backend - client ID."""
section = payments
name = "paypal_client_id"
verbose_name = _("PayPal - Client ID")
default = ""
required = False
@site_preferences_registry.register
class PaypalSecret(StringPreference):
"""PayPal payment backend - secret."""
section = payments
name = "paypal_secret"
verbose_name = _("PayPal - Secret")
default = ""
required = False
@site_preferences_registry.register
class PaypalCapture(BooleanPreference):
"""PayPal payment backend - use Authorize & Capture."""
section = payments
name = "paypal_capture"
verbose_name = _("PayPal - Use Authorize & Capture")
default = False
required = False
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment