diff --git a/services/web/server/src/simcore_service_webserver/payments/_api.py b/services/web/server/src/simcore_service_webserver/payments/_api.py index 0628c200f84..1eaceb6b75b 100644 --- a/services/web/server/src/simcore_service_webserver/payments/_api.py +++ b/services/web/server/src/simcore_service_webserver/payments/_api.py @@ -20,7 +20,7 @@ from ..wallets.api import get_wallet_by_user, get_wallet_with_permissions_by_user from ..wallets.errors import WalletAccessForbiddenError from . import _db -from ._client import get_payments_service_api +from ._client import create_fake_payment, get_payments_service_api from ._socketio import notify_payment_completed _logger = logging.getLogger(__name__) @@ -89,8 +89,9 @@ async def create_payment_to_wallet( initiated_at = arrow.utcnow().datetime # payment service - payment_service_api = get_payments_service_api(app) - submission_link, payment_id = await payment_service_api.create_payment( + # FAKE ------------ + submission_link, payment_id = await create_fake_payment( + app, price_dollars=price_dollars, product_name=product_name, user_id=user_id, @@ -98,6 +99,7 @@ async def create_payment_to_wallet( email=user.email, osparc_credits=osparc_credits, ) + # ----- # gateway responded, we store the transaction await _db.create_payment_transaction( app, diff --git a/services/web/server/src/simcore_service_webserver/payments/_client.py b/services/web/server/src/simcore_service_webserver/payments/_client.py index c31923bdabd..75ccf7c44a7 100644 --- a/services/web/server/src/simcore_service_webserver/payments/_client.py +++ b/services/web/server/src/simcore_service_webserver/payments/_client.py @@ -1,7 +1,6 @@ import asyncio import contextlib import logging -import os from dataclasses import dataclass from decimal import Decimal from uuid import uuid4 @@ -12,7 +11,7 @@ from yarl import URL from .._constants import APP_SETTINGS_KEY -from .settings import PaymentsSettings +from .settings import PaymentsSettings, get_plugin_settings _logger = logging.getLogger(__name__) @@ -70,41 +69,42 @@ async def is_healthy(self) -> bool: _logger.debug("Payments service is not healty: %s", err) return False - # NOTE: Functions below FAKE behaviour of payments service - async def create_payment( - self, - price_dollars: Decimal, - osparc_credits: Decimal, - product_name: str, - user_id: UserID, - name: str, - email: str, - ): - assert self # nosec - assert osparc_credits > 0 # nosec - assert name # nosec - assert email # nosec - assert product_name # nosec - assert price_dollars > 0 # nosec - - body = { - "price_dollars": price_dollars, - "osparc_credits": osparc_credits, - "user_id": user_id, - "name": name, - "email": email, - } - _logger.info("Sending -> payments-service %s", body) - - await asyncio.sleep(1) - - # Fake response of payment service -------- - transaction_id = f"{uuid4()}" - base_url = URL( - os.environ.get("PAYMENTS_GATEWAY_URL", "https://faker-payment-gateway.com") - ) - submission_link = base_url.with_path("/pay").with_query(id=transaction_id) - return submission_link, transaction_id + +# NOTE: Functions below FAKE behaviour of payments service +async def create_fake_payment( + app: web.Application, + *, + price_dollars: Decimal, + osparc_credits: Decimal, + product_name: str, + user_id: UserID, + name: str, + email: str, +): + assert osparc_credits > 0 # nosec + assert name # nosec + assert email # nosec + assert product_name # nosec + assert price_dollars > 0 # nosec + + body = { + "price_dollars": price_dollars, + "osparc_credits": osparc_credits, + "user_id": user_id, + "name": name, + "email": email, + } + + # Fake response of payment service -------- + _logger.info("Sending -> payments-service %s", body) + await asyncio.sleep(1) + transaction_id = f"{uuid4()}" + # ------------- + + settings: PaymentsSettings = get_plugin_settings(app) + base_url = URL(settings.PAYMENTS_FAKE_GATEWAY_URL) + submission_link = base_url.with_path("/pay").with_query(id=transaction_id) + return submission_link, transaction_id # diff --git a/services/web/server/tests/unit/with_dbs/03/wallets/conftest.py b/services/web/server/tests/unit/with_dbs/03/wallets/conftest.py index 8fa877ded8e..d825c7c13f3 100644 --- a/services/web/server/tests/unit/with_dbs/03/wallets/conftest.py +++ b/services/web/server/tests/unit/with_dbs/03/wallets/conftest.py @@ -32,6 +32,7 @@ def app_environment( "WEBSERVER_DB_LISTENER": "0", "WEBSERVER_DEV_FEATURES_ENABLED": "1", "WEBSERVER_GARBAGE_COLLECTOR": "null", + "PAYMENTS_FAKE_GATEWAY_URL": "https://some-fake-gateway.com", }, ) diff --git a/services/web/server/tests/unit/with_dbs/03/wallets/payments/test_payments.py b/services/web/server/tests/unit/with_dbs/03/wallets/payments/test_payments.py index 32e87672cff..8dbc2c1d126 100644 --- a/services/web/server/tests/unit/with_dbs/03/wallets/payments/test_payments.py +++ b/services/web/server/tests/unit/with_dbs/03/wallets/payments/test_payments.py @@ -90,6 +90,7 @@ async def test_payments_worfklow( payment = WalletPaymentCreated.parse_obj(data) assert payment.payment_id + assert payment.payment_form_url.host == "some-fake-gateway.com" assert payment.payment_form_url.query assert payment.payment_form_url.query.endswith(payment.payment_id)