Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganized G2P Payments Bridge to G2P Cash Transfer Bridge. Fixed GCTB Mojaloop connector. #8

Merged
merged 4 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .copier-answers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ github_ci_precommit: true
github_ci_pypi_publish: true
github_ci_tests: true
github_ci_tests_codecov: true
module_name: g2p_payments_bridge
module_name: g2p_cash_transfer_bridge
org_name: OpenG2P
org_slug: OpenG2P
package_name: g2p-payments-bridge
repo_name: G2P Payments Bridge
repo_slug: g2p-payments-bridge
package_name: g2p-cash-transfer-bridge
repo_name: G2P Cash Transfer Bridge
repo_slug: g2p-cash-transfer-bridge

12 changes: 11 additions & 1 deletion .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ jobs:
runs-on: ubuntu-latest
env:
NAMESPACE: ${{ secrets.docker_hub_organisation }}
SERVICE_NAME: g2p-payments-bridge
SERVICE_NAME: g2p-cash-transfer-bridge
PAYMENT_BACKEND_SERVICE_NAME: gctb-payment-backend
steps:
- uses: actions/checkout@v3
- name: Docker build and push
Expand All @@ -23,18 +24,27 @@ jobs:
fi

IMAGE_ID=$NAMESPACE/$SERVICE_NAME
PAYMENT_BACKEND_IMAGE_ID=$NAMESPACE/$PAYMENT_BACKEND_SERVICE_NAME

# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
PAYMENT_BACKEND_IMAGE_ID=$(echo $PAYMENT_BACKEND_IMAGE_ID | tr '[A-Z]' '[a-z]')
VERSION=$BRANCH_NAME
if [[ $BRANCH_NAME == master || $BRANCH_NAME == main ]]; then
VERSION=develop
fi
echo IMAGE_ID=$IMAGE_ID
echo PAYMENT_BACKEND_IMAGE_ID=$PAYMENT_BACKEND_IMAGE_ID
echo VERSION=$VERSION

docker build . \
--file Dockerfile \
--tag $IMAGE_ID:$VERSION

docker push $IMAGE_ID:$VERSION

docker build . \
--file payment-backend.Dockerfile \
--tag $PAYMENT_BACKEND_IMAGE_ID:$VERSION

docker push $PAYMENT_BACKEND_IMAGE_ID:$VERSION
7 changes: 6 additions & 1 deletion .github/workflows/openapi-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ jobs:
with:
python-version: "3.10"
- name: Install app
run: python -m pip install ./g2p-payments-bridge-core
run: |
python -m pip install git+https://github.com/openg2p/openg2p-fastapi-common.git@develop\#egg=openg2p-fastapi-common\&subdirectory=openg2p-fastapi-common
python -m pip install git+https://github.com/openg2p/openg2p-fastapi-common.git@develop\#egg=openg2p-fastapi-auth\&subdirectory=openg2p-fastapi-auth
python -m pip install git+https://github.com/openg2p/openg2p-fastapi-common.git@develop\#egg=openg2p-common-g2pconnect-id-mapper\&subdirectory=openg2p-common-g2pconnect-id-mapper
python -m pip install ./g2p-cash-transfer-bridge-core
python -m pip install ./g2p-cash-transfer-bridge-api
- name: Generate openapi json
run: |
mkdir -p api-docs/generated
Expand Down
29 changes: 11 additions & 18 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,24 @@ jobs:
python-version: "3.10"
- name: Install build dependencies
run: pip install build
- name: Build distribution g2p-payments-bridge-core
run: python -m build ./g2p-payments-bridge-core
- name: Build distribution g2p-cash-transfer-bridge-core
run: python -m build ./g2p-cash-transfer-bridge-core
- name: Publish
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: g2p-payments-bridge-core/dist
packages-dir: g2p-cash-transfer-bridge-core/dist
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Build distribution gpb-translate-id-fa
run: python -m build ./gpb-translate-id-fa
- name: Publish gpb-translate-id-fa
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: gpb-translate-id-fa/dist
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Build distribution gpb-simple-mpesa-payment-backend
run: python -m build ./gpb-simple-mpesa-payment-backend
- name: Publish gpb-simple-mpesa-payment-backend
- name: Build distribution g2p-cash-transfer-bridge-api
run: python -m build ./g2p-cash-transfer-bridge-api
- name: Publish
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: gpb-simple-mpesa-payment-backend/dist
packages-dir: g2p-cash-transfer-bridge-api/dist
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Build distribution gpb-mojaloop-sdk-payment-backend
run: python -m build ./gpb-mojaloop-sdk-payment-backend
- name: Publish gpb-mojaloop-sdk-payment-backend
- name: Build distribution gctb-translate-id-fa
run: python -m build ./gctb-translate-id-fa
- name: Publish gctb-translate-id-fa
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: gpb-mojaloop-sdk-payment-backend/dist
packages-dir: gctb-translate-id-fa/dist
password: ${{ secrets.PYPI_API_TOKEN }}
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ RUN python3 -m pip install \
git+https://github.com/openg2p/openg2p-fastapi-common.git@develop\#egg=openg2p-fastapi-common\&subdirectory=openg2p-fastapi-common \
git+https://github.com/openg2p/openg2p-fastapi-common.git@develop\#egg=openg2p-fastapi-auth\&subdirectory=openg2p-fastapi-auth \
git+https://github.com/openg2p/openg2p-fastapi-common.git@develop\#egg=openg2p-common-g2pconnect-id-mapper\&subdirectory=openg2p-common-g2pconnect-id-mapper \
./src/g2p-payments-bridge-core \
./src/gpb-translate-id-fa \
./src/gpb-simple-mpesa-payment-backend \
./src/gpb-mojaloop-sdk-payment-backend
./src/g2p-cash-transfer-bridge-core \
./src/g2p-cash-transfer-bridge-api \
./src/gctb-translate-id-fa

CMD python3 main.py migrate; \
python3 main.py run
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# G2P Payments Bridge
[![Pre-commit Status](https://github.com/OpenG2P/g2p-payments-bridge/actions/workflows/pre-commit.yml/badge.svg?branch=develop)](https://github.com/OpenG2P/g2p-payments-bridge/actions/workflows/pre-commit.yml?query=branch%3Adevelop)
[![Build Status](https://github.com/OpenG2P/g2p-payments-bridge/actions/workflows/test.yml/badge.svg?branch=develop)](https://github.com/OpenG2P/g2p-payments-bridge/actions/workflows/test.yml?query=branch%3Adevelop)
[![codecov](https://codecov.io/gh/OpenG2P/g2p-payments-bridge/branch/develop/graph/badge.svg)](https://codecov.io/gh/OpenG2P/g2p-payments-bridge)
[![openapi](https://img.shields.io/badge/open--API-swagger-brightgreen)](https://validator.swagger.io/?url=https://raw.githubusercontent.com/OpenG2P/g2p-payments-bridge/develop/api-docs/generated/openapi.json)
# G2P Cash Transfer Bridge
[![Pre-commit Status](https://github.com/OpenG2P/g2p-cash-transfer-bridge/actions/workflows/pre-commit.yml/badge.svg?branch=develop)](https://github.com/OpenG2P/g2p-cash-transfer-bridge/actions/workflows/pre-commit.yml?query=branch%3Adevelop)
[![Build Status](https://github.com/OpenG2P/g2p-cash-transfer-bridge/actions/workflows/test.yml/badge.svg?branch=develop)](https://github.com/OpenG2P/g2p-cash-transfer-bridge/actions/workflows/test.yml?query=branch%3Adevelop)
[![codecov](https://codecov.io/gh/OpenG2P/g2p-cash-transfer-bridge/branch/develop/graph/badge.svg)](https://codecov.io/gh/OpenG2P/g2p-cash-transfer-bridge)
[![openapi](https://img.shields.io/badge/open--API-swagger-brightgreen)](https://validator.swagger.io/?url=https://raw.githubusercontent.com/OpenG2P/g2p-cash-transfer-bridge/develop/api-docs/generated/openapi.json)

Module to offer interoperability with G2P Connect for cash disbursement

## Available Packages

Package | Version | Summary
----- | ------- | -------
[g2p-payments-bridge-core](g2p-payments-bridge-core/) | 0.1.0 | G2P Payments Bridge: Core
[gpb-translate-id-fa](gpb-translate-id-fa/) | 0.1.0 | G2P Payments Bridge: Translate ID to Financial Address
[gpb-simple-mpesa-payment-backend](gpb-simple-mpesa-payment-backend/) | 0.1.0 | G2P Payments Bridge: Simple-mpesa Payment Backend.
[gpb-mojaloop-sdk-payment-backend](gpb-mojaloop-sdk-payment-backend/) | 0.1.0 | G2P Payments Bridge: Mojaloop SDK Scheme Adapter Payment Backend.
[g2p-cash-transfer-bridge-core](g2p-cash-transfer-bridge-core/) | 0.1.0 | G2P Cash Transfer Bridge: Core
[gctb-translate-id-fa](gctb-translate-id-fa/) | 0.1.0 | G2P Cash Transfer Bridge: Translate ID to Financial Address
[gctb-simple-mpesa-payment-backend](gctb-simple-mpesa-payment-backend/) | 0.1.0 | G2P Cash Transfer Bridge: Simple-mpesa Payment Backend.
[gctb-mojaloop-sdk-payment-backend](gctb-mojaloop-sdk-payment-backend/) | 0.1.0 | G2P Cash Transfer Bridge: Mojaloop SDK Scheme Adapter Payment Backend.

## Licenses

Expand Down
File renamed without changes.
9 changes: 9 additions & 0 deletions g2p-cash-transfer-bridge-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# G2P Cash Transfer Bridge: API
[![Pre-commit Status](https://github.com/OpenG2P/g2p-cash-transfer-bridge/actions/workflows/pre-commit.yml/badge.svg?branch=develop)](https://github.com/OpenG2P/g2p-cash-transfer-bridge/actions/workflows/pre-commit.yml?query=branch%3Adevelop)
[![Build Status](https://github.com/OpenG2P/g2p-cash-transfer-bridge/actions/workflows/test.yml/badge.svg?branch=develop)](https://github.com/OpenG2P/g2p-cash-transfer-bridge/actions/workflows/test.yml?query=branch%3Adevelop)
[![codecov](https://codecov.io/gh/OpenG2P/g2p-cash-transfer-bridge/branch/develop/graph/badge.svg)](https://codecov.io/gh/OpenG2P/g2p-cash-transfer-bridge)
[![openapi](https://img.shields.io/badge/open--API-swagger-brightgreen)](https://validator.swagger.io/?url=https://raw.githubusercontent.com/OpenG2P/g2p-cash-transfer-bridge/develop/api-docs/generated/openapi.json)
![PyPI](https://img.shields.io/pypi/v/g2p-cash-transfer-bridge-api?label=pypi%20package)
![PyPI - Downloads](https://img.shields.io/pypi/dm/g2p-cash-transfer-bridge-api)

API module for G2P Cash Transfer Bridge, which contains API layer and multiplexer for different payment backends. This implements G2P Connect Disburse APIs.
27 changes: 27 additions & 0 deletions g2p-cash-transfer-bridge-api/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "g2p-cash-transfer-bridge-api"
version = "0.1.0"
authors = [
{ name="OpenG2P", email="[email protected]" },
]
description = "G2P Cash Transfer Bridge: API"
readme = "README.md"
requires-python = ">=3.7"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
"Operating System :: OS Independent",
]
dependencies=[
"g2p-cash-transfer-bridge-core",
]

[project.urls]
Homepage = "https://openg2p.org"
Documentation = "https://docs.openg2p.org/"
Repository = "https://github.com/OpenG2P/g2p-cash-transfer-bridge"
Source = "https://github.com/OpenG2P/g2p-cash-transfer-bridge"
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# ruff: noqa: E402

import asyncio

from .config import Settings
from .models.orm.payment_list import PaymentListItem

_config = Settings.get_config()

from openg2p_fastapi_common.app import Initializer
from g2p_cash_transfer_bridge_core.app import Initializer

from .controllers.disbursement_controller import DisbursementController
from .services.payment_multiplexer import PaymentMultiplexerService
Expand All @@ -19,11 +16,3 @@ def initialize(self, **kwargs):
# Initialize all Services, Controllers, any utils here.
PaymentMultiplexerService()
DisbursementController().post_init()

def migrate_database(self, args):
super().migrate_database(args)

async def migrate():
await PaymentListItem.create_migrate()

asyncio.run(migrate())
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from typing import List

from openg2p_fastapi_common.config import Settings
from g2p_cash_transfer_bridge_core.config import Settings
from pydantic import BaseModel, model_validator
from pydantic_settings import SettingsConfigDict


class PayerFaPayeeFaMapping(BaseModel):
Expand Down Expand Up @@ -40,23 +39,7 @@ class FaBackendMapping(BaseModel):


class Settings(Settings):
model_config = SettingsConfigDict(
env_prefix="gpb_core_", env_file=".env", extra="allow"
)

openapi_title: str = "G2P Payments Bridge"
openapi_description: str = """
This module implements G2P Connect Disburse APIs.
It contains API layer and multiplexer for different payment backends.

***********************************
Further details goes here
***********************************
"""
openapi_version: str = "0.1.0"
db_dbname: str = "gpbdb"

response_sender_id: str = "g2p.payments.bridge.openg2p"
response_sender_id: str = "g2p.cash.transfer.bridge.openg2p"
get_backend_name_from_translate: bool = True

# TODO: Convert this to ORM Model rather than config
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import asyncio
import uuid

from openg2p_fastapi_common.controller import BaseController

from ..config import Settings
from ..models.disburse import (
from g2p_cash_transfer_bridge_core.models.disburse import (
DisburseHttpRequest,
DisburseHttpResponse,
DisburseResponse,
DisburseTxnStatusHttpRequest,
DisburseTxnStatusHttpResponse,
SingleDisburseResponse,
)
from ..models.msg_header import MsgResponseHeader, MsgStatusEnum
from ..services.payment_multiplexer import PaymentMultiplexerService
from g2p_cash_transfer_bridge_core.models.msg_header import (
MsgResponseHeader,
MsgStatusEnum,
)
from g2p_cash_transfer_bridge_core.services.payment_multiplexer import (
PaymentMultiplexerService,
)
from openg2p_fastapi_common.controller import BaseController

from ..config import Settings

_config = Settings.get_config()

Expand Down Expand Up @@ -43,7 +48,7 @@ async def disburse_sync_disburse(self, request: DisburseHttpRequest):

async def process_disbursement():
disburse_txn = request.message.model_copy()
await self.payment_multiplexer.make_disbursements(disburse_txn)
await self.payment_multiplexer.disburse(disburse_txn)

asyncio.create_task(process_disbursement())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
import re
import uuid

from openg2p_fastapi_common.errors.http_exceptions import BadRequestError
from openg2p_fastapi_common.service import BaseService

from g2p_payments_bridge_core.models.orm.payment_list import PaymentListItem

from ..config import Settings
from ..models.disburse import (
from g2p_cash_transfer_bridge_core.models.disburse import (
DisburseRequest,
DisburseResponse,
DisburseTxnStatusRequest,
Expand All @@ -17,13 +11,22 @@
SingleDisburseTxnStatusResponse,
TxnStatusAttributeTypeEnum,
)
from .id_translate_service import IdTranslateService
from g2p_cash_transfer_bridge_core.models.orm.payment_list import PaymentListItem
from g2p_cash_transfer_bridge_core.services.id_translate_service import (
IdTranslateService,
)
from g2p_cash_transfer_bridge_core.services.payment_multiplexer import (
PaymentMultiplexerService as CorePaymentMultiplexerService,
)
from openg2p_fastapi_common.errors.http_exceptions import BadRequestError

from ..config import Settings

_config = Settings.get_config()
_logger = logging.getLogger(__name__)


class PaymentMultiplexerService(BaseService):
class PaymentMultiplexerService(CorePaymentMultiplexerService):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self._id_translate_service = IdTranslateService.get_component()
Expand All @@ -40,7 +43,7 @@ async def get_payment_backend_from_fa(self, fa: str):
return mapping.name
return None

async def make_disbursements(self, disburse_request: DisburseRequest):
async def disburse(self, disburse_request: DisburseRequest):
if _config.get_backend_name_from_translate:
payee_fa_list = []
try:
Expand Down Expand Up @@ -79,7 +82,7 @@ async def disbursement_status(
ref_ids = status_request.txnstatus_request.attribute_value
if not isinstance(ref_ids, list):
raise BadRequestError(
"GPB-PMS-350", "attribute_value is supposed to be a list."
"GCTB-PMS-350", "attribute_value is supposed to be a list."
)
payment_list = await PaymentListItem.get_by_request_ids(ref_ids)
return DisburseTxnStatusResponse(
Expand Down Expand Up @@ -112,7 +115,7 @@ async def disbursement_status(
txn_id = status_request.txnstatus_request.attribute_value
if not isinstance(ref_ids, str):
raise BadRequestError(
"GPB-PMS-350", "attribute_value is supposed to be a string."
"GCTB-PMS-350", "attribute_value is supposed to be a string."
)
payment_list = await PaymentListItem.get_by_batch_id(txn_id)
return DisburseTxnStatusResponse(
Expand Down
1 change: 1 addition & 0 deletions g2p-cash-transfer-bridge-core/LICENSE
9 changes: 9 additions & 0 deletions g2p-cash-transfer-bridge-core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# G2P Cash Transfer Bridge: Core
[![Pre-commit Status](https://github.com/OpenG2P/g2p-cash-transfer-bridge/actions/workflows/pre-commit.yml/badge.svg?branch=develop)](https://github.com/OpenG2P/g2p-cash-transfer-bridge/actions/workflows/pre-commit.yml?query=branch%3Adevelop)
[![Build Status](https://github.com/OpenG2P/g2p-cash-transfer-bridge/actions/workflows/test.yml/badge.svg?branch=develop)](https://github.com/OpenG2P/g2p-cash-transfer-bridge/actions/workflows/test.yml?query=branch%3Adevelop)
[![codecov](https://codecov.io/gh/OpenG2P/g2p-cash-transfer-bridge/branch/develop/graph/badge.svg)](https://codecov.io/gh/OpenG2P/g2p-cash-transfer-bridge)
[![openapi](https://img.shields.io/badge/open--API-swagger-brightgreen)](https://validator.swagger.io/?url=https://raw.githubusercontent.com/OpenG2P/g2p-cash-transfer-bridge/develop/api-docs/generated/openapi.json)
![PyPI](https://img.shields.io/pypi/v/g2p-cash-transfer-bridge-core?label=pypi%20package)
![PyPI - Downloads](https://img.shields.io/pypi/dm/g2p-cash-transfer-bridge-core)

Core module for G2P Cash Transfer Bridge.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "g2p-payments-bridge-core"
name = "g2p-cash-transfer-bridge-core"
version = "0.1.0"
authors = [
{ name="OpenG2P", email="[email protected]" },
]
description = "G2P Payments Bridge: Core"
description = "G2P Cash Transfer Bridge: Core"
readme = "README.md"
requires-python = ">=3.7"
classifiers = [
Expand All @@ -24,5 +24,5 @@ dependencies=[
[project.urls]
Homepage = "https://openg2p.org"
Documentation = "https://docs.openg2p.org/"
Repository = "https://github.com/OpenG2P/g2p-payments-bridge"
Source = "https://github.com/OpenG2P/g2p-payments-bridge"
Repository = "https://github.com/OpenG2P/g2p-cash-transfer-bridge"
Source = "https://github.com/OpenG2P/g2p-cash-transfer-bridge"
Loading
Loading