Skip to content

Commit

Permalink
🐛 Fixes link to payment form (ITISFoundation#4778)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov authored Sep 20, 2023
1 parent 2c48d13 commit 1e4beb8
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -89,15 +89,17 @@ 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,
name=user.name,
email=user.email,
osparc_credits=osparc_credits,
)
# -----
# gateway responded, we store the transaction
await _db.create_payment_transaction(
app,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import asyncio
import contextlib
import logging
import os
from dataclasses import dataclass
from decimal import Decimal
from uuid import uuid4
Expand All @@ -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__)

Expand Down Expand Up @@ -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


#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 1e4beb8

Please sign in to comment.