gopay
This commit is contained in:
74
backend/thirdparty/gopay/client.py
vendored
Normal file
74
backend/thirdparty/gopay/client.py
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
try:
|
||||
# Expecting official SDK providing `payments` with required methods
|
||||
from gopay import payments as _payments # type: ignore
|
||||
except Exception: # pragma: no cover
|
||||
_payments = None
|
||||
|
||||
|
||||
def _get_client():
|
||||
if _payments is None:
|
||||
raise ImproperlyConfigured(
|
||||
"GoPay SDK not installed or not importable. Install and configure the GoPay SDK."
|
||||
)
|
||||
# If your SDK requires explicit initialization with credentials, do it here.
|
||||
# Example (pseudo):
|
||||
# return PaymentsClient(
|
||||
# goid=settings.GOPAY_GOID,
|
||||
# client_id=settings.GOPAY_CLIENT_ID,
|
||||
# client_secret=settings.GOPAY_CLIENT_SECRET,
|
||||
# gateway_url=settings.GOPAY_GATEWAY_URL,
|
||||
# )
|
||||
return _payments
|
||||
|
||||
|
||||
def create_payment(payload: dict):
|
||||
return _get_client().create_payment(payload)
|
||||
|
||||
|
||||
def get_status(payment_id: str | int):
|
||||
return _get_client().get_status(payment_id)
|
||||
|
||||
|
||||
def refund_payment(payment_id: str | int, amount: int):
|
||||
return _get_client().refund_payment(payment_id, amount)
|
||||
|
||||
|
||||
def create_recurrence(payment_id: str | int, payload: dict):
|
||||
return _get_client().create_recurrence(payment_id, payload)
|
||||
|
||||
|
||||
def void_recurrence(payment_id: str | int):
|
||||
return _get_client().void_recurrence(payment_id)
|
||||
|
||||
|
||||
def capture_authorization(payment_id: str | int):
|
||||
return _get_client().capture_authorization(payment_id)
|
||||
|
||||
|
||||
def capture_authorization_partial(payment_id: str | int, payload: dict):
|
||||
return _get_client().capture_authorization_partial(payment_id, payload)
|
||||
|
||||
|
||||
def get_card_details(card_id: str | int):
|
||||
return _get_client().get_card_details(card_id)
|
||||
|
||||
|
||||
def delete_card(card_id: str | int):
|
||||
return _get_client().delete_card(card_id)
|
||||
|
||||
|
||||
def get_payment_instruments(goid: str | int, currency: str):
|
||||
return _get_client().get_payment_instruments(goid, currency)
|
||||
|
||||
|
||||
def get_payment_instruments_all(goid: str | int):
|
||||
return _get_client().get_payment_instruments_all(goid)
|
||||
|
||||
|
||||
def get_account_statement(statement_request: dict):
|
||||
return _get_client().get_account_statement(statement_request)
|
||||
Reference in New Issue
Block a user