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

18099 - PAY API - endpoint to add EFT Allowed flag to an account #1307

Merged
merged 12 commits into from
Oct 30, 2023
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""18099-eft allowed flag

Revision ID: 2ef58b39cafc
Revises: 194cdd7cf986
Create Date: 2023-10-26 13:31:50.959562

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '2ef58b39cafc'
down_revision = '194cdd7cf986'
branch_labels = None
depends_on = None


def upgrade():
op.execute("set statement_timeout=20000;")
op.add_column('payment_accounts', sa.Column('eft_enable', sa.Boolean, nullable=True))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably default the new flag to false and make it not nullable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sounds good



def downgrade():
op.execute("set statement_timeout=20000;")
op.drop_column('payment_accounts', 'eft_enable')
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""18099-eft allowed flag

Revision ID: 7d5231f2b9ac
Revises: 2ef58b39cafc
Create Date: 2023-10-26 13:55:46.291450

"""
from alembic import op


# revision identifiers, used by Alembic.
revision = '7d5231f2b9ac'
down_revision = '2ef58b39cafc'
branch_labels = None
depends_on = None


def upgrade():
"""Update eft_enable in payment_accounts table."""
# eft_enable set to true when it has invoices paid with EFT/DIRECT_PAY payment method historically
op.execute("set statement_timeout=20000;")
conn = op.get_bind()
conn.execute('UPDATE payment_accounts \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is necessary, we want to enable specific accounts via notebook. It will also give us flexibility to enable a subset of accounts if we want and we want to send a welcome email when we enable it for accounts.

A new route/endpoint is beneficial as we can secure it differently than the existing payment account endpoints and have separate logic like the welcome email when we enable this flag.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this file, it gonna handle by ticket 18100

SET eft_enable = true \
WHERE id IN ( \
SELECT pa.id \
FROM payment_accounts pa \
RIGHT JOIN invoices i ON i.payment_account_id = pa.id \
WHERE i.payment_method_code IN (\'EFT\', \'DIRECT_PAY\') \
)')

def downgrade():
pass
2 changes: 1 addition & 1 deletion pay-api/src/pay_api/models/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from .base_schema import BaseSchema
from .db import db, ma
from .invoice_reference import InvoiceReferenceSchema
from .payment_account import PaymentAccountSchema, PaymentAccountSearchModel
from .payment_account import PaymentAccount, PaymentAccountSchema, PaymentAccountSearchModel
from .payment_line_item import PaymentLineItem, PaymentLineItemSchema
from .receipt import ReceiptSchema
from ..utils.util import current_local_time
Expand Down
2 changes: 2 additions & 0 deletions pay-api/src/pay_api/models/payment_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class PaymentAccount(VersionedModel): # pylint: disable=too-many-instance-attri
'created_name',
'created_on',
'credit',
'eft_enable',
'name',
'pad_activation_date',
'pad_tos_accepted_by',
Expand Down Expand Up @@ -77,6 +78,7 @@ class PaymentAccount(VersionedModel): # pylint: disable=too-many-instance-attri

credit = db.Column(db.Numeric(19, 2), nullable=True)
billable = db.Column(Boolean(), default=True)
eft_enable = db.Column(Boolean(), default=False)

# before this date , the account shouldn't get used
pad_activation_date = db.Column(db.DateTime, nullable=True)
Expand Down
14 changes: 14 additions & 0 deletions pay-api/src/pay_api/services/payment_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from pay_api.models import PaymentAccount as PaymentAccountModel
from pay_api.models import PaymentAccountSchema
from pay_api.models import StatementSettings as StatementSettingsModel
from pay_api.models.invoice import Invoice
from pay_api.services.cfs_service import CFSService
from pay_api.services.distribution_code import DistributionCode
from pay_api.services.queue_publisher import publish_response
Expand Down Expand Up @@ -68,6 +69,7 @@ def __init__(self):
self._cfs_account_id: Optional[int] = None
self._cfs_account_status: Optional[str] = None
self._billable: Optional[bool] = None
self._eft_enable: Optional[bool] = None

@property
def _dao(self):
Expand All @@ -89,6 +91,7 @@ def _dao(self, value: PaymentAccountModel):
self.pad_tos_accepted_date: datetime = self._dao.pad_tos_accepted_date
self.credit: Decimal = self._dao.credit
self.billable: bool = self._dao.billable
self.eft_enable: bool = self._dao.eft_enable

cfs_account: CfsAccountModel = CfsAccountModel.find_effective_by_account_id(self.id)
if cfs_account:
Expand Down Expand Up @@ -305,6 +308,17 @@ def billable(self, value: bool):
self._billable = value
self._dao.billable = value

@property
def eft_enable(self):
"""Return the eft_enable."""
return self._eft_enable

@eft_enable.setter
def eft_enable(self, value: bool):
"""Set the eft_enable."""
self._eft_enable = value
self._dao.eft_enable = value

def save(self):
"""Save the information to the DB."""
return self._dao.save()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class _Config(): # pylint: disable=too-few-public-methods
Used as the base for all the other configurations.
"""

LEGISLATIVE_TIMEZONE = os.getenv('LEGISLATIVE_TIMEZONE', 'America/Vancouver')
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
PAY_LD_SDK_KEY = os.getenv('PAY_LD_SDK_KEY', None)

Expand Down
Loading