Skip to content

Commit

Permalink
Refactor models
Browse files Browse the repository at this point in the history
  • Loading branch information
PSNAppz committed Aug 7, 2024
1 parent 01c9268 commit 5166bb0
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 109 deletions.
2 changes: 1 addition & 1 deletion openg2p-g2p-bridge-example-bank-celery/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
EXAMPLE_BANK_HOST=0.0.0.0
EXAMPLE_BANK_PORT=8003
EXAMPLE_BANK_PROCESS_PAYMENT_FREQUENCY=3600
EXAMPLE_BANK_PAYMENT_INITIATE_ATTEMPTS=3
EXAMPLE_BANK_PAYMENT_INITIATE_ATTEMPTS=3
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from decimal import Decimal

from openg2p_g2p_bridge_example_bank_models.models import (
Expand All @@ -16,7 +17,6 @@
_config = Settings.get_config()
_engine = get_engine()

import logging

_logger = logging.getLogger(_config.logging_default_logger_name)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from .account import (
Account,
)
from .account_statement import (
AccountingLog,
AccountStatement,
DebitCreditTypes,
)
from .payment_request import (
FundBlock,
InitiatePaymentBatchRequest,
InitiatePaymentRequest,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
from datetime import datetime
from enum import Enum

from openg2p_fastapi_common.models import BaseORMModelWithTimes
from sqlalchemy import DateTime, Float, Integer, String, Text
from sqlalchemy import Enum as SqlEnum
from sqlalchemy import Float, String
from sqlalchemy.orm import Mapped, mapped_column


class PaymentStatus(Enum):
PENDING = "PENDING"
SUCCESS = "SUCCESS"
FAILED = "FAILED"


class DebitCreditTypes(Enum):
DEBIT = "debit"
CREDIT = "credit"


class Account(BaseORMModelWithTimes):
__tablename__ = "accounts"
account_holder_name: Mapped[str] = mapped_column(String)
Expand All @@ -26,94 +11,3 @@ class Account(BaseORMModelWithTimes):
book_balance: Mapped[float] = mapped_column(Float)
available_balance: Mapped[float] = mapped_column(Float)
blocked_amount: Mapped[float] = mapped_column(Float, default=0)


class FundBlock(BaseORMModelWithTimes):
__tablename__ = "fund_blocks"
block_reference_no: Mapped[str] = mapped_column(String, index=True, unique=True)
account_number: Mapped[str] = mapped_column(String)
currency: Mapped[str] = mapped_column(String)
amount: Mapped[float] = mapped_column(Float)
amount_released: Mapped[float] = mapped_column(Float, default=0)


class InitiatePaymentBatchRequest(BaseORMModelWithTimes):
batch_id: Mapped[str] = mapped_column(String, index=True, unique=True)
payment_initiate_attempts: Mapped[int] = mapped_column(Integer, default=0)
payment_status: Mapped[PaymentStatus] = mapped_column(
SqlEnum(PaymentStatus), default=PaymentStatus.PENDING
)


class InitiatePaymentRequest(BaseORMModelWithTimes):
__tablename__ = "initiate_payment_requests"
batch_id: Mapped[str] = mapped_column(String, index=True, unique=False)
payment_reference_number = mapped_column(
String, index=True, unique=True
) # disbursement id
remitting_account: Mapped[str] = mapped_column(String, nullable=False)
remitting_account_currency: Mapped[str] = mapped_column(String, nullable=False)
payment_amount: Mapped[float] = mapped_column(Float, nullable=False)
payment_date: Mapped[str] = mapped_column(String, nullable=False)
funds_blocked_reference_number: Mapped[str] = mapped_column(String, nullable=False)

beneficiary_name: Mapped[str] = mapped_column(String)
beneficiary_account: Mapped[str] = mapped_column(String)
beneficiary_account_currency: Mapped[str] = mapped_column(String)
beneficiary_account_type: Mapped[str] = mapped_column(String)
beneficiary_bank_code: Mapped[str] = mapped_column(String)
beneficiary_branch_code: Mapped[str] = mapped_column(String)

beneficiary_mobile_wallet_provider: Mapped[str] = mapped_column(
String, nullable=True
)
beneficiary_phone_no: Mapped[str] = mapped_column(String, nullable=True)

beneficiary_email: Mapped[str] = mapped_column(String, nullable=True)
beneficiary_email_wallet_provider: Mapped[str] = mapped_column(
String, nullable=True
)

narrative_1: Mapped[str] = mapped_column(
String, nullable=True
) # disbursement narrative
narrative_2: Mapped[str] = mapped_column(String, nullable=True) # program pneumonic
narrative_3: Mapped[str] = mapped_column(
String, nullable=True
) # cycle code pneumonic
narrative_4: Mapped[str] = mapped_column(String, nullable=True) # beneficiary id
narrative_5: Mapped[str] = mapped_column(String, nullable=True)
narrative_6: Mapped[str] = mapped_column(String, nullable=True)


class AccountingLog(BaseORMModelWithTimes):
__tablename__ = "accounting_logs"
reference_no: Mapped[str] = mapped_column(String, index=True, unique=True)
corresponding_block_reference_no: Mapped[str] = mapped_column(String, nullable=True)
customer_reference_no: Mapped[str] = mapped_column(String, index=True)
debit_credit: Mapped[DebitCreditTypes] = mapped_column(SqlEnum(DebitCreditTypes))
account_number: Mapped[str] = mapped_column(String, index=True)
transaction_amount: Mapped[float] = mapped_column(Float)
transaction_date: Mapped[datetime] = mapped_column(DateTime)
transaction_currency: Mapped[str] = mapped_column(String)
transaction_code: Mapped[str] = mapped_column(String, nullable=True)

narrative_1: Mapped[str] = mapped_column(String, nullable=True) # disbursement id
narrative_2: Mapped[str] = mapped_column(String, nullable=True) # beneficiary id
narrative_3: Mapped[str] = mapped_column(String, nullable=True) # program pneumonic
narrative_4: Mapped[str] = mapped_column(
String, nullable=True
) # cycle code pneumonic
narrative_5: Mapped[str] = mapped_column(String, nullable=True) # beneficiary email
narrative_6: Mapped[str] = mapped_column(
String, nullable=True
) # beneficiary phone number


class AccountStatement(BaseORMModelWithTimes):
__tablename__ = "account_statements"
account_number: Mapped[str] = mapped_column(String, index=True)
account_statement_lob: Mapped[str] = mapped_column(Text, nullable=True)
account_statement_date: Mapped[datetime.date] = mapped_column(
DateTime, default=datetime.date(datetime.utcnow())
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from datetime import datetime
from enum import Enum

from openg2p_fastapi_common.models import BaseORMModelWithTimes
from sqlalchemy import DateTime, Float, String, Text
from sqlalchemy import Enum as SqlEnum
from sqlalchemy.orm import Mapped, mapped_column


class DebitCreditTypes(Enum):
DEBIT = "debit"
CREDIT = "credit"


class AccountStatement(BaseORMModelWithTimes):
__tablename__ = "account_statements"
account_number: Mapped[str] = mapped_column(String, index=True)
account_statement_lob: Mapped[str] = mapped_column(Text, nullable=True)
account_statement_date: Mapped[datetime.date] = mapped_column(
DateTime, default=datetime.date(datetime.utcnow())
)


class AccountingLog(BaseORMModelWithTimes):
__tablename__ = "accounting_logs"
reference_no: Mapped[str] = mapped_column(String, index=True, unique=True)
corresponding_block_reference_no: Mapped[str] = mapped_column(String, nullable=True)
customer_reference_no: Mapped[str] = mapped_column(String, index=True)
debit_credit: Mapped[DebitCreditTypes] = mapped_column(SqlEnum(DebitCreditTypes))
account_number: Mapped[str] = mapped_column(String, index=True)
transaction_amount: Mapped[float] = mapped_column(Float)
transaction_date: Mapped[datetime] = mapped_column(DateTime)
transaction_currency: Mapped[str] = mapped_column(String)
transaction_code: Mapped[str] = mapped_column(String, nullable=True)

narrative_1: Mapped[str] = mapped_column(String, nullable=True) # disbursement id
narrative_2: Mapped[str] = mapped_column(String, nullable=True) # beneficiary id
narrative_3: Mapped[str] = mapped_column(String, nullable=True) # program pneumonic
narrative_4: Mapped[str] = mapped_column(
String, nullable=True
) # cycle code pneumonic
narrative_5: Mapped[str] = mapped_column(String, nullable=True) # beneficiary email
narrative_6: Mapped[str] = mapped_column(
String, nullable=True
) # beneficiary phone number
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from enum import Enum

from openg2p_fastapi_common.models import BaseORMModelWithTimes
from sqlalchemy import Enum as SqlEnum
from sqlalchemy import Float, Integer, String
from sqlalchemy.orm import Mapped, mapped_column


class PaymentStatus(Enum):
PENDING = "PENDING"
SUCCESS = "SUCCESS"
FAILED = "FAILED"


class FundBlock(BaseORMModelWithTimes):
__tablename__ = "fund_blocks"
block_reference_no: Mapped[str] = mapped_column(String, index=True, unique=True)
account_number: Mapped[str] = mapped_column(String)
currency: Mapped[str] = mapped_column(String)
amount: Mapped[float] = mapped_column(Float)
amount_released: Mapped[float] = mapped_column(Float, default=0)


class InitiatePaymentBatchRequest(BaseORMModelWithTimes):
__tablename__ = "initiate_payment_batch_requests"
batch_id: Mapped[str] = mapped_column(String, index=True, unique=True)
payment_initiate_attempts: Mapped[int] = mapped_column(Integer, default=0)
payment_status: Mapped[PaymentStatus] = mapped_column(
SqlEnum(PaymentStatus), default=PaymentStatus.PENDING
)


class InitiatePaymentRequest(BaseORMModelWithTimes):
__tablename__ = "initiate_payment_requests"
batch_id: Mapped[str] = mapped_column(String, index=True, unique=False)
payment_reference_number = mapped_column(
String, index=True, unique=True
) # disbursement id
remitting_account: Mapped[str] = mapped_column(String, nullable=False)
remitting_account_currency: Mapped[str] = mapped_column(String, nullable=False)
payment_amount: Mapped[float] = mapped_column(Float, nullable=False)
payment_date: Mapped[str] = mapped_column(String, nullable=False)
funds_blocked_reference_number: Mapped[str] = mapped_column(String, nullable=False)

beneficiary_name: Mapped[str] = mapped_column(String)
beneficiary_account: Mapped[str] = mapped_column(String)
beneficiary_account_currency: Mapped[str] = mapped_column(String)
beneficiary_account_type: Mapped[str] = mapped_column(String)
beneficiary_bank_code: Mapped[str] = mapped_column(String)
beneficiary_branch_code: Mapped[str] = mapped_column(String)

beneficiary_mobile_wallet_provider: Mapped[str] = mapped_column(
String, nullable=True
)
beneficiary_phone_no: Mapped[str] = mapped_column(String, nullable=True)

beneficiary_email: Mapped[str] = mapped_column(String, nullable=True)
beneficiary_email_wallet_provider: Mapped[str] = mapped_column(
String, nullable=True
)

narrative_1: Mapped[str] = mapped_column(
String, nullable=True
) # disbursement narrative
narrative_2: Mapped[str] = mapped_column(String, nullable=True) # program pneumonic
narrative_3: Mapped[str] = mapped_column(
String, nullable=True
) # cycle code pneumonic
narrative_4: Mapped[str] = mapped_column(String, nullable=True) # beneficiary id
narrative_5: Mapped[str] = mapped_column(String, nullable=True)
narrative_6: Mapped[str] = mapped_column(String, nullable=True)

0 comments on commit 5166bb0

Please sign in to comment.