Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
domdinicola committed Jan 2, 2025
1 parent 3ad52a5 commit f2649e0
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 82 deletions.
6 changes: 5 additions & 1 deletion src/hope_payment_gateway/api/docs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from django.urls import re_path

from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView
from drf_spectacular.views import (
SpectacularAPIView,
SpectacularRedocView,
SpectacularSwaggerView,
)

app_name = "docs"

Expand Down
5 changes: 4 additions & 1 deletion src/hope_payment_gateway/api/western_union/filters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from django_filters import rest_framework as filters

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


class CorridorFilter(filters.FilterSet):
Expand Down
5 changes: 4 additions & 1 deletion src/hope_payment_gateway/api/western_union/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from rest_framework import serializers
from rest_framework.serializers import Serializer

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


class CorridorSerializer(serializers.ModelSerializer):
Expand Down
10 changes: 8 additions & 2 deletions src/hope_payment_gateway/api/western_union/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
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.filters import (
CorridorFilter,
ServiceProviderCodeFilter,
)
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.apps.fsp.western_union.models import (
Corridor,
ServiceProviderCode,
)
from hope_payment_gateway.libs.ftp import FTPClient


Expand Down
10 changes: 8 additions & 2 deletions src/hope_payment_gateway/apps/fsp/moneygram/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@
SENT,
UNFUNDED,
)
from hope_payment_gateway.apps.fsp.utils import get_from_delivery_mechanism, get_phone_number
from hope_payment_gateway.apps.fsp.utils import (
get_from_delivery_mechanism,
get_phone_number,
)
from hope_payment_gateway.apps.gateway.flows import PaymentRecordFlow
from hope_payment_gateway.apps.gateway.models import FinancialServiceProvider, PaymentRecord
from hope_payment_gateway.apps.gateway.models import (
FinancialServiceProvider,
PaymentRecord,
)

logger = logging.getLogger(__name__)

Expand Down
15 changes: 1 addition & 14 deletions src/hope_payment_gateway/apps/fsp/moneygram/handlers.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
from constance import config as constance_config

from hope_payment_gateway.apps.gateway.models import FinancialServiceProvider, FinancialServiceProviderConfig
from hope_payment_gateway.apps.gateway.registry import FSPProcessor


class MoneyGramHandler(FSPProcessor):
@staticmethod
def get_configuration(config_key, delivery_mechanism):
vendor_number = constance_config.MONEYGRAM_VENDOR_NUMBER
wu = FinancialServiceProvider.objects.get(vendor_number=vendor_number)
try:
config = FinancialServiceProviderConfig.objects.get(
key=config_key, fsp=wu, delivery_mechanism__code=delivery_mechanism
).configuration
except FinancialServiceProviderConfig.DoesNotExist:
config = wu.configuration
return config
pass
5 changes: 4 additions & 1 deletion src/hope_payment_gateway/apps/fsp/western_union/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

from hope_payment_gateway.apps.fsp.western_union.api.client import WesternUnionClient
from hope_payment_gateway.apps.fsp.western_union.api.request import requests_request
from hope_payment_gateway.apps.fsp.western_union.models import Corridor, ServiceProviderCode
from hope_payment_gateway.apps.fsp.western_union.models import (
Corridor,
ServiceProviderCode,
)


@admin.register(Corridor)
Expand Down
30 changes: 25 additions & 5 deletions src/hope_payment_gateway/apps/fsp/western_union/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,34 @@

from hope_payment_gateway.apps.core.models import Singleton
from hope_payment_gateway.apps.fsp.client import FSPClient
from hope_payment_gateway.apps.fsp.utils import get_from_delivery_mechanism, get_phone_number
from hope_payment_gateway.apps.fsp.western_union.api import MONEY_IN_TIME, WALLET, WIC, WMF, agent, web
from hope_payment_gateway.apps.fsp.utils import (
get_from_delivery_mechanism,
get_phone_number,
)
from hope_payment_gateway.apps.fsp.western_union.api import (
MONEY_IN_TIME,
WALLET,
WIC,
WMF,
agent,
web,
)
from hope_payment_gateway.apps.fsp.western_union.api.utils import integrate_payload
from hope_payment_gateway.apps.fsp.western_union.exceptions import (
InvalidCorridorError,
PayloadException,
PayloadMissingKeyError,
)
from hope_payment_gateway.apps.fsp.western_union.models import Corridor, ServiceProviderCode
from hope_payment_gateway.apps.fsp.western_union.models import (
Corridor,
ServiceProviderCode,
)
from hope_payment_gateway.apps.gateway.flows import PaymentRecordFlow
from hope_payment_gateway.apps.gateway.models import FinancialServiceProvider, PaymentRecord, PaymentRecordState
from hope_payment_gateway.apps.gateway.models import (
FinancialServiceProvider,
PaymentRecord,
PaymentRecordState,
)
from hope_payment_gateway.config.settings import WESTERN_UNION_CERT, WESTERN_UNION_KEY

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -678,7 +695,10 @@ def das_delivery_option_template( # noqa
if field not in base:
base[field] = {}
base = base[field]
if first_value == ["wallet_details", "service_provider_code"]:
if first_value == [
"wallet_details",
"service_provider_code",
]:
service_provider_code = True
else:
service_provider_code = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
from zeep.exceptions import ValidationError

from hope_payment_gateway.apps.core.permissions import WhitelistPermission
from hope_payment_gateway.apps.fsp.western_union.api import CANCEL, PURGED, REFUND, REJECT_APN, SUCCESS, SUCCESS_APN
from hope_payment_gateway.apps.fsp.western_union.api import (
CANCEL,
PURGED,
REFUND,
REJECT_APN,
SUCCESS,
SUCCESS_APN,
)
from hope_payment_gateway.apps.fsp.western_union.api.client import WesternUnionClient
from hope_payment_gateway.apps.fsp.western_union.exceptions import InvalidRequest
from hope_payment_gateway.apps.gateway.flows import PaymentRecordFlow
Expand Down
19 changes: 1 addition & 18 deletions src/hope_payment_gateway/apps/fsp/western_union/handlers.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
from constance import config as constance_config

from hope_payment_gateway.apps.gateway.models import FinancialServiceProvider, FinancialServiceProviderConfig
from hope_payment_gateway.apps.gateway.registry import FSPProcessor


class WesternUnionHandler(FSPProcessor):
@staticmethod
def get_configuration(config_key: str, delivery_mechanism_code: str):
vendor_number = constance_config.WESTERN_UNION_VENDOR_NUMBER
wu = FinancialServiceProvider.objects.get(vendor_number=vendor_number)
payload = wu.configuration
try:
fsp = FinancialServiceProviderConfig.objects.get(
key=config_key, fsp=wu, delivery_mechanism__code=delivery_mechanism_code
)

payload.update(fsp.configuration)
payload["delivery_mechanism"] = fsp.delivery_mechanism.code
except FinancialServiceProviderConfig.DoesNotExist:
pass
return payload
pass


class CSVExportStrategy(FSPProcessor):
Expand Down
5 changes: 4 additions & 1 deletion src/hope_payment_gateway/apps/fsp/western_union/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from django.urls import re_path

from hope_payment_gateway.apps.fsp.western_union.api.webhook import NisNotificationJSONView, NisNotificationXMLView
from hope_payment_gateway.apps.fsp.western_union.api.webhook import (
NisNotificationJSONView,
NisNotificationXMLView,
)

app_name = "western_union"

Expand Down
11 changes: 9 additions & 2 deletions src/hope_payment_gateway/apps/gateway/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@
from jsoneditor.forms import JSONEditor
from viewflow.fsm import TransitionNotAllowed

from hope_payment_gateway.apps.fsp.moneygram.client import InvalidTokenError, MoneyGramClient, PayloadMissingKeyError
from hope_payment_gateway.apps.fsp.moneygram.client import (
InvalidTokenError,
MoneyGramClient,
PayloadMissingKeyError,
)
from hope_payment_gateway.apps.fsp.western_union.api.client import WesternUnionClient
from hope_payment_gateway.apps.fsp.western_union.exceptions import InvalidCorridorError, PayloadException
from hope_payment_gateway.apps.fsp.western_union.exceptions import (
InvalidCorridorError,
PayloadException,
)
from hope_payment_gateway.apps.gateway.actions import (
TemplateExportForm,
export_as_template,
Expand Down
4 changes: 3 additions & 1 deletion src/hope_payment_gateway/apps/gateway/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class AppConfig(BaseAppConfig):
verbose_name = "Gateway"

def ready(self) -> None:
from hope_payment_gateway.apps.fsp.western_union.handlers import WesternUnionHandler
from hope_payment_gateway.apps.fsp.western_union.handlers import (
WesternUnionHandler,
)

registry.register(WesternUnionHandler)
11 changes: 11 additions & 0 deletions src/hope_payment_gateway/apps/gateway/registry.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.core.exceptions import ObjectDoesNotExist
from strategy_field.registry import Registry


Expand All @@ -11,6 +12,16 @@ def label(self) -> str:
def notify(self) -> None:
pass

def get_configuration(self, config_key, delivery_mechanism):
payload = self.fsp.configuration
try:
config = self.fsp.configs.get(key=config_key, delivery_mechanism__code=delivery_mechanism).configuration
payload["delivery_mechanism"] = delivery_mechanism
payload.update(config)
except ObjectDoesNotExist:
config = self.fsp.configuration
return config


class DefaultProcessor(FSPProcessor):
pass
Expand Down
Loading

0 comments on commit f2649e0

Please sign in to comment.