Skip to content

Commit 1e4beb8

Browse files
authored
πŸ› Fixes link to payment form (#4778)
1 parent 2c48d13 commit 1e4beb8

File tree

4 files changed

+44
-40
lines changed

4 files changed

+44
-40
lines changed

β€Žservices/web/server/src/simcore_service_webserver/payments/_api.pyβ€Ž

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from ..wallets.api import get_wallet_by_user, get_wallet_with_permissions_by_user
2121
from ..wallets.errors import WalletAccessForbiddenError
2222
from . import _db
23-
from ._client import get_payments_service_api
23+
from ._client import create_fake_payment, get_payments_service_api
2424
from ._socketio import notify_payment_completed
2525

2626
_logger = logging.getLogger(__name__)
@@ -89,15 +89,17 @@ async def create_payment_to_wallet(
8989
initiated_at = arrow.utcnow().datetime
9090

9191
# payment service
92-
payment_service_api = get_payments_service_api(app)
93-
submission_link, payment_id = await payment_service_api.create_payment(
92+
# FAKE ------------
93+
submission_link, payment_id = await create_fake_payment(
94+
app,
9495
price_dollars=price_dollars,
9596
product_name=product_name,
9697
user_id=user_id,
9798
name=user.name,
9899
email=user.email,
99100
osparc_credits=osparc_credits,
100101
)
102+
# -----
101103
# gateway responded, we store the transaction
102104
await _db.create_payment_transaction(
103105
app,

β€Žservices/web/server/src/simcore_service_webserver/payments/_client.pyβ€Ž

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import asyncio
22
import contextlib
33
import logging
4-
import os
54
from dataclasses import dataclass
65
from decimal import Decimal
76
from uuid import uuid4
@@ -12,7 +11,7 @@
1211
from yarl import URL
1312

1413
from .._constants import APP_SETTINGS_KEY
15-
from .settings import PaymentsSettings
14+
from .settings import PaymentsSettings, get_plugin_settings
1615

1716
_logger = logging.getLogger(__name__)
1817

@@ -70,41 +69,42 @@ async def is_healthy(self) -> bool:
7069
_logger.debug("Payments service is not healty: %s", err)
7170
return False
7271

73-
# NOTE: Functions below FAKE behaviour of payments service
74-
async def create_payment(
75-
self,
76-
price_dollars: Decimal,
77-
osparc_credits: Decimal,
78-
product_name: str,
79-
user_id: UserID,
80-
name: str,
81-
email: str,
82-
):
83-
assert self # nosec
84-
assert osparc_credits > 0 # nosec
85-
assert name # nosec
86-
assert email # nosec
87-
assert product_name # nosec
88-
assert price_dollars > 0 # nosec
89-
90-
body = {
91-
"price_dollars": price_dollars,
92-
"osparc_credits": osparc_credits,
93-
"user_id": user_id,
94-
"name": name,
95-
"email": email,
96-
}
97-
_logger.info("Sending -> payments-service %s", body)
98-
99-
await asyncio.sleep(1)
100-
101-
# Fake response of payment service --------
102-
transaction_id = f"{uuid4()}"
103-
base_url = URL(
104-
os.environ.get("PAYMENTS_GATEWAY_URL", "https://faker-payment-gateway.com")
105-
)
106-
submission_link = base_url.with_path("/pay").with_query(id=transaction_id)
107-
return submission_link, transaction_id
72+
73+
# NOTE: Functions below FAKE behaviour of payments service
74+
async def create_fake_payment(
75+
app: web.Application,
76+
*,
77+
price_dollars: Decimal,
78+
osparc_credits: Decimal,
79+
product_name: str,
80+
user_id: UserID,
81+
name: str,
82+
email: str,
83+
):
84+
assert osparc_credits > 0 # nosec
85+
assert name # nosec
86+
assert email # nosec
87+
assert product_name # nosec
88+
assert price_dollars > 0 # nosec
89+
90+
body = {
91+
"price_dollars": price_dollars,
92+
"osparc_credits": osparc_credits,
93+
"user_id": user_id,
94+
"name": name,
95+
"email": email,
96+
}
97+
98+
# Fake response of payment service --------
99+
_logger.info("Sending -> payments-service %s", body)
100+
await asyncio.sleep(1)
101+
transaction_id = f"{uuid4()}"
102+
# -------------
103+
104+
settings: PaymentsSettings = get_plugin_settings(app)
105+
base_url = URL(settings.PAYMENTS_FAKE_GATEWAY_URL)
106+
submission_link = base_url.with_path("/pay").with_query(id=transaction_id)
107+
return submission_link, transaction_id
108108

109109

110110
#

β€Žservices/web/server/tests/unit/with_dbs/03/wallets/conftest.pyβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def app_environment(
3232
"WEBSERVER_DB_LISTENER": "0",
3333
"WEBSERVER_DEV_FEATURES_ENABLED": "1",
3434
"WEBSERVER_GARBAGE_COLLECTOR": "null",
35+
"PAYMENTS_FAKE_GATEWAY_URL": "https://some-fake-gateway.com",
3536
},
3637
)
3738

β€Žservices/web/server/tests/unit/with_dbs/03/wallets/payments/test_payments.pyβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ async def test_payments_worfklow(
9090
payment = WalletPaymentCreated.parse_obj(data)
9191

9292
assert payment.payment_id
93+
assert payment.payment_form_url.host == "some-fake-gateway.com"
9394
assert payment.payment_form_url.query
9495
assert payment.payment_form_url.query.endswith(payment.payment_id)
9596

0 commit comments

Comments
Β (0)