Skip to content

Commit 4ac968c

Browse files
committed
Add env variables for mock verkkokauppa Backend and Frontend URLs
1 parent e3911e6 commit 4ac968c

12 files changed

Lines changed: 33 additions & 20 deletions

File tree

.env.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ TUNNISTAMO_ALLOWED_REDIRECT_HOSTS=local-tilavaraus.hel.fi:3000,local-tilavaraus.
2424
#VERKKOKAUPPA_ORDER_API_URL=
2525
#VERKKOKAUPPA_PAYMENT_API_URL=
2626
#VERKKOKAUPPA_PRODUCT_API_URL=
27-
#USE_MOCK_VERKKOKAUPPA_API=
27+
#MOCK_VERKKOKAUPPA_API_ENABLED=True
28+
#MOCK_VERKKOKAUPPA_FRONTEND_URL=http://localhost:3000
29+
#MOCK_VERKKOKAUPPA_BACKEND_URL=http://localhost:8000

api/graphql/tests/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ def _setup_verkkokauppa_env_variables(settings):
1717
settings.VERKKOKAUPPA_PAYMENT_API_URL = "http://test-payment:1234"
1818
settings.VERKKOKAUPPA_MERCHANT_API_URL = "http://test-merchant:1234"
1919
settings.VERKKOKAUPPA_NAMESPACE = "tilanvaraus"
20-
settings.USE_MOCK_VERKKOKAUPPA_API = False
20+
settings.MOCK_VERKKOKAUPPA_API_ENABLED = False
21+
settings.MOCK_VERKKOKAUPPA_FRONTEND_URL = "http://mock-verkkokauppa.com"
22+
settings.MOCK_VERKKOKAUPPA_BACKEND_URL = "http://mock-verkkokauppa.com"

api/graphql/types/reservations/serializers/confirm_serializers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def validate(self, data, prefill_from_profile=False):
9090

9191
active_price = ReservationUnitPricingHelper.get_active_price(reservation_unit)
9292
if active_price.pricing_type == PricingType.PAID or self.instance.price_net > 0:
93-
if not reservation_unit.payment_product and not settings.USE_MOCK_VERKKOKAUPPA_API:
93+
if not reservation_unit.payment_product and not settings.MOCK_VERKKOKAUPPA_API_ENABLED:
9494
raise ValidationErrorWithCode(
9595
"Reservation unit is missing payment product",
9696
ValidationErrorCodes.MISSING_PAYMENT_PRODUCT,
@@ -150,7 +150,7 @@ def save(self, **kwargs) -> Reservation:
150150
)
151151
else:
152152
verkkokauppa_order: Order
153-
if settings.USE_MOCK_VERKKOKAUPPA_API:
153+
if settings.MOCK_VERKKOKAUPPA_API_ENABLED:
154154
verkkokauppa_order = create_mock_verkkokauppa_order(self.instance)
155155
else:
156156
order_params: CreateOrderParams = get_verkkokauppa_order_params(self.instance)

merchants/mock_verkkokauppa_api/views.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ def get(self, request: WSGIRequest, *args, **kwargs) -> HttpResponseRedirect:
4949

5050
def post(self, request: WSGIRequest, *args, **kwargs) -> HttpResponseRedirect | HttpResponse:
5151
payment_order = self.get_payment_order(order_uuid=kwargs.get("order_uuid"))
52-
# Assume that the second URL in CORS_ALLOWED_ORIGINS is the Frontend UI URL
53-
frontend_url = settings.CORS_ALLOWED_ORIGINS[1].strip("/")
52+
frontend_url = settings.MOCK_VERKKOKAUPPA_FRONTEND_URL.strip("/")
5453

5554
if "payment_success" in request.POST:
5655
self.handle_payment_success(payment_order=payment_order)

merchants/verkkokauppa/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def create_mock_verkkokauppa_order(reservation: Reservation) -> Order:
150150
price_vat = round_decimal(Decimal(quantity * reservation.price_net * (reservation.tax_percentage_value / 100)), 2)
151151

152152
# Assume that the first URL in CORS_ALLOWED_ORIGINS is the backend URL
153-
base_url = settings.CORS_ALLOWED_ORIGINS[0].strip("/")
153+
base_url = settings.MOCK_VERKKOKAUPPA_BACKEND_URL.strip("/")
154154
# Reservation URI in the django admin
155155
mock_verkkokauppa_checkout_url = reverse("mock_verkkokauppa", args=[order_uuid]).strip("/")
156156
admin_url = reverse("admin:reservations_reservation_change", args=[reservation.id]).strip("/")

merchants/verkkokauppa/tests/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ def _setup_verkkokauppa_env_variables(settings):
1111
settings.VERKKOKAUPPA_PAYMENT_API_URL = "http://test-payment:1234"
1212
settings.VERKKOKAUPPA_MERCHANT_API_URL = "http://test-merchant:1234"
1313
settings.VERKKOKAUPPA_NAMESPACE = "tilanvaraus"
14-
settings.USE_MOCK_VERKKOKAUPPA_API = False
14+
settings.MOCK_VERKKOKAUPPA_API_ENABLED = False
15+
settings.MOCK_VERKKOKAUPPA_FRONTEND_URL = "http://mock-verkkokauppa.com"
16+
settings.MOCK_VERKKOKAUPPA_BACKEND_URL = "http://mock-verkkokauppa.com"
1517

1618

1719
@pytest.fixture()

reservation_units/utils/reservation_unit_reservation_state_helper.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ def __has_valid_pricing(cls, reservation_unit: ReservationUnit) -> bool:
124124
if active_price is None:
125125
return False
126126

127-
# If USE_MOCK_VERKKOKAUPPA_API is True there is no need to check for payment products,
128-
if settings.USE_MOCK_VERKKOKAUPPA_API:
127+
# If MOCK_VERKKOKAUPPA_API_ENABLED is True there is no need to check for payment products,
128+
if settings.MOCK_VERKKOKAUPPA_API_ENABLED:
129129
return True
130130

131131
# Pricing is FREE
@@ -137,9 +137,9 @@ def __has_valid_pricing(cls, reservation_unit: ReservationUnit) -> bool:
137137

138138
@classmethod
139139
def __has_valid_pricing_query(cls) -> Q:
140-
# If USE_MOCK_VERKKOKAUPPA_API is True there is no need to check for payment products,
140+
# If MOCK_VERKKOKAUPPA_API_ENABLED is True there is no need to check for payment products,
141141
# as the products are created when a reservation is made.
142-
if settings.USE_MOCK_VERKKOKAUPPA_API:
142+
if settings.MOCK_VERKKOKAUPPA_API_ENABLED:
143143
return Q(active_pricing_type__isnull=False)
144144

145145
return (
@@ -314,7 +314,7 @@ def __is_reservation_closed(cls, reservation_unit: ReservationUnit) -> bool:
314314
or (
315315
active_price.pricing_type == PricingType.PAID
316316
and reservation_unit.payment_product is None
317-
and not settings.USE_MOCK_VERKKOKAUPPA_API # Don't show as closed if using Mock Verkkokauppa API
317+
and not settings.MOCK_VERKKOKAUPPA_API_ENABLED # Don't show as closed if using Mock Verkkokauppa API
318318
)
319319
)
320320

@@ -323,7 +323,7 @@ def __get_is_reservation_closed_query(cls) -> QueryState:
323323
now = local_datetime()
324324

325325
payment_product_query = Q(active_pricing_type=PricingType.PAID) & Q(payment_product__isnull=True)
326-
if settings.USE_MOCK_VERKKOKAUPPA_API:
326+
if settings.MOCK_VERKKOKAUPPA_API_ENABLED:
327327
payment_product_query = Q()
328328

329329
return QueryState(

reservations/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def refund_paid_reservation_task(reservation_pk: int) -> None:
6464
if not payment_order:
6565
return
6666

67-
if not settings.USE_MOCK_VERKKOKAUPPA_API:
67+
if not settings.MOCK_VERKKOKAUPPA_API_ENABLED:
6868
refund = VerkkokauppaAPIClient.refund_order(order_uuid=payment_order.remote_id)
6969
payment_order.refund_id = refund.refund_id
7070
payment_order.save()

reservations/tests/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ def _setup_verkkokauppa_env_variables(settings):
1717
settings.VERKKOKAUPPA_PAYMENT_API_URL = "http://test-payment:1234"
1818
settings.VERKKOKAUPPA_MERCHANT_API_URL = "http://test-merchant:1234"
1919
settings.VERKKOKAUPPA_NAMESPACE = "tilanvaraus"
20-
settings.USE_MOCK_VERKKOKAUPPA_API = False
20+
settings.MOCK_VERKKOKAUPPA_API_ENABLED = False
21+
settings.MOCK_VERKKOKAUPPA_FRONTEND_URL = "http://mock-verkkokauppa.com"
22+
settings.MOCK_VERKKOKAUPPA_BACKEND_URL = "http://mock-verkkokauppa.com"

tests/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ def _setup_verkkokauppa_env_variables(settings):
8383
settings.VERKKOKAUPPA_PAYMENT_API_URL = "http://test-payment:1234"
8484
settings.VERKKOKAUPPA_MERCHANT_API_URL = "http://test-merchant:1234"
8585
settings.VERKKOKAUPPA_NAMESPACE = "tilanvaraus"
86-
settings.USE_MOCK_VERKKOKAUPPA_API = False
86+
settings.MOCK_VERKKOKAUPPA_API_ENABLED = False
87+
settings.MOCK_VERKKOKAUPPA_FRONTEND_URL = "http://mock-verkkokauppa.com"
88+
settings.MOCK_VERKKOKAUPPA_BACKEND_URL = "http://mock-verkkokauppa.com"
8789

8890

8991
@pytest.hookimpl()

0 commit comments

Comments
 (0)