Skip to content

Commit

Permalink
Staging 2 master (#88)
Browse files Browse the repository at this point in the history
* add moneygram (#74)

* partial

* export enhancements

* ftp

* tweak reg expr

* fix sentry

* fix

* fix

* Update licence (#80)

* upgrades (#79)

* smartenv (#83)

* fix sentry envs

* remove vision (#84)

* fix template

* fix template (#85)

* Templ (#86)

* fix template

* fix exception

* refactor storages (#87)

---------

Co-authored-by: sergey-misuk-valor <[email protected]>
  • Loading branch information
domdinicola and sergey-misuk-valor authored Oct 14, 2024
1 parent c6dd806 commit 2477731
Show file tree
Hide file tree
Showing 52 changed files with 1,018 additions and 720 deletions.
21 changes: 4 additions & 17 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
Copyright (c) 2014 - 2024 UNICEF. All rights reserved.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License below for more details.

------------------------------------------------------------------------
GNU AFFERO GENERAL PUBLIC LICENSE
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007

Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

Expand Down Expand Up @@ -656,7 +643,7 @@ the "copyright" line and a pointer to where the full notice is found.
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.

Also add information on how to contact you by electronic and paper mail.

Expand All @@ -671,4 +658,4 @@ specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<http://www.gnu.org/licenses/>.
<https://www.gnu.org/licenses/>.
4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.11-slim-bookworm as base
FROM python:3.12-slim-bookworm as base

RUN apt update \
&& apt install --no-install-recommends -y \
Expand All @@ -13,7 +13,7 @@ RUN apt update \
&& chown -R hpg:hpg /code /tmp /data /static

ENV PACKAGES_DIR=/packages
ENV PYPACKAGES=$PACKAGES_DIR/__pypackages__/3.11
ENV PYPACKAGES=$PACKAGES_DIR/__pypackages__/3.12
ENV LIB_DIR=$PYPACKAGES/lib
ENV PYTHONPATH=$PYTHONPATH:$LIB_DIR:/code/src
ENV PATH=$PATH:$PYPACKAGES/bin
Expand Down
824 changes: 346 additions & 478 deletions pdm.lock

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ includes = []
dev = [
"argh",
"black",
"django-regex",
"django-webtest",
"drf-api-checker",
"factory-boy",
"faker",
"flake8",
"flake8-bugbear",
Expand All @@ -50,14 +52,15 @@ dev = [
"openpyxl-stubs",
"parameterized",
"parso",
"pre-commit",
"pytest",
"pytest-cov",
"pytest-django",
"pytest-echo",
"pytest-factoryboy",
"pytest-xdist",
"requests-mock",
"responses",
"snapshottest",
"types-freezegun",
"types-requests",
"types-python-dateutil",
Expand All @@ -71,7 +74,7 @@ authors = [
{name = "ddinicola"},
{name = "Domenico DiNicola", email = "[email protected]"},
]
requires-python = ">=3.11"
requires-python = ">=3.12"
dependencies = [
"Django",
"celery[redis]",
Expand All @@ -96,18 +99,18 @@ dependencies = [
"django-model-utils",
"django-mptt",
"django-smart-admin",
"django-smart-env",
"django-storages[azure]",
"django-strategy-field",
"django-viewflow",
"dj-static",
"drf-spectacular[sidecar]",
"factory-boy",
"flower",
"gunicorn",
"newrelic",
"natural-keys",
"paramiko",
"phonenumbers",
"pre-commit",
"psycopg[binary]",
"sentry-sdk",
"social-auth-app-django",
Expand All @@ -119,7 +122,6 @@ dependencies = [
"wheel",
"uwsgi",
"zeep",
"flower>=2.0.1",
]
name = "hope_payment_gateway"
version = "0.1"
Expand Down
2 changes: 1 addition & 1 deletion src/hope_payment_gateway/api/fsp/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Meta:
fields = {
"remote_id": ["exact"],
"name": ["exact"],
"vision_vendor_number": ["exact"],
"vendor_number": ["exact"],
}


Expand Down
16 changes: 13 additions & 3 deletions src/hope_payment_gateway/api/fsp/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,20 @@ class Meta:

class FinancialServiceProviderConfigNestedSerializer(serializers.ModelSerializer):
delivery_mechanism_name = serializers.CharField(source="delivery_mechanism.name", allow_null=True)
delivery_mechanism_code = serializers.CharField(source="delivery_mechanism.code", allow_null=True)
delivery_mechanism_transfer_type = serializers.CharField(source="delivery_mechanism.transfer_type", allow_null=True)

class Meta:
model = FinancialServiceProviderConfig
fields = ("id", "key", "label", "delivery_mechanism", "delivery_mechanism_name")
fields = (
"id",
"key",
"label",
"delivery_mechanism",
"delivery_mechanism_name",
"delivery_mechanism_transfer_type",
"delivery_mechanism_code",
)


class FinancialServiceProviderLightSerializer(PayloadMixin, serializers.ModelSerializer):
Expand All @@ -58,7 +68,7 @@ class Meta:
fields = (
"id",
"name",
"vision_vendor_number",
"vendor_number",
)


Expand All @@ -71,7 +81,7 @@ class Meta:
"id",
"remote_id",
"name",
"vision_vendor_number",
"vendor_number",
"configs",
)

Expand Down
2 changes: 1 addition & 1 deletion src/hope_payment_gateway/api/fsp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class FinancialServiceProviderViewSet(ProtectedMixin, LoggingAPIViewSet):
queryset = FinancialServiceProvider.objects.prefetch_related("configs")

filterset_class = FinancialServiceProviderFilter
search_fields = ["name", "vision_vendor_number", "remote_id"]
search_fields = ["name", "vendor_number", "remote_id"]


class ConfigurationViewSet(ProtectedMixin, LoggingAPIViewSet):
Expand Down
2 changes: 2 additions & 0 deletions src/hope_payment_gateway/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@
router.register(r"wu/corridors", wu_views.CorridorViewSet, basename="wu-corridor")
router.register(r"wu/provider_code", wu_views.ServiceProviderCodeViewSet, basename="wu-service-provider-code")

router.register(r"wu/files", wu_views.FileViewset, basename="wu-files")


urlpatterns = router.urls
13 changes: 13 additions & 0 deletions src/hope_payment_gateway/api/western_union/serializers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from rest_framework import serializers
from rest_framework.serializers import Serializer

from hope_payment_gateway.apps.fsp.western_union.models import Corridor, ServiceProviderCode

Expand All @@ -13,3 +14,15 @@ class ServiceProviderCodeSerializer(serializers.ModelSerializer):
class Meta:
model = ServiceProviderCode
fields = ("description", "code", "country", "currency")


class FileSerializer(Serializer):
name = serializers.SerializerMethodField()
url = serializers.SerializerMethodField()

def get_name(self, obj):
return str(obj)

def get_url(self, obj):
request = self.context.get("request")
return request.build_absolute_uri(str(obj))
31 changes: 29 additions & 2 deletions src/hope_payment_gateway/api/western_union/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
from rest_framework.viewsets import ModelViewSet
from django.http import FileResponse

from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet, ViewSet

from hope_payment_gateway.api.western_union.filters import CorridorFilter, ServiceProviderCodeFilter
from hope_payment_gateway.api.western_union.serializers import CorridorSerializer, ServiceProviderCodeSerializer
from hope_payment_gateway.api.western_union.serializers import (
CorridorSerializer,
FileSerializer,
ServiceProviderCodeSerializer,
)
from hope_payment_gateway.apps.fsp.western_union.models import Corridor, ServiceProviderCode
from hope_payment_gateway.libs.ftp import FTPClient


class ProtectedMixin:
Expand All @@ -24,3 +32,22 @@ class ServiceProviderCodeViewSet(ProtectedMixin, ModelViewSet):

filterset_class = ServiceProviderCodeFilter
search_fields = ["description", "code"]


class FileViewset(ViewSet):
serializer_class = FileSerializer
filter_backends = list()
lookup_field = "filename"
lookup_value_regex = r"[\w.;_@]+"

def get_queryset(self):
return FTPClient().ls()

def list(self, request):
serializer = self.serializer_class(instance=FTPClient().ls(), many=True, context={"request": request})
return Response(serializer.data)

def retrieve(self, request, filename=None):
response = FileResponse(FTPClient().download(filename))
response["Content-Disposition"] = 'attachment; filename="%s"' % filename
return response
2 changes: 2 additions & 0 deletions src/hope_payment_gateway/apps/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from hope_payment_gateway.apps.core.models import System, User

admin.site.site_header = "Payment Gateway"


@admin.register(User)
class UserAdminPlus(UserAdminPlus):
Expand Down
9 changes: 9 additions & 0 deletions src/hope_payment_gateway/apps/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
from unicef_security.models import AbstractUser, SecurityMixin


class Singleton(type):
_instances = {}

def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]


class User(SecurityMixin, AbstractUser):
class Meta:
app_label = "core"
Expand Down
50 changes: 0 additions & 50 deletions src/hope_payment_gateway/apps/core/storage.py

This file was deleted.

19 changes: 19 additions & 0 deletions src/hope_payment_gateway/apps/core/templates/request.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends "admin_extra_buttons/action_page.html" %}
{% load static %}

{% block content %}

<i>{% autoescape on %}
{{ msg | linebreaksbr }}
{% endautoescape %}
</i>

<pre>
{% if format == "json" %}
{{ content | pprint }}
{% else %}
{{ content }}
{% endif %}
</pre>

{% endblock %}
Empty file.
Loading

0 comments on commit 2477731

Please sign in to comment.