def _save_account(cls, account_request: Dict[str, any], payment_account: PaymentAccountModel, is_sandbox: bool = False): """Update and save payment account and CFS account model.""" # pylint:disable=cyclic-import, import-outside-toplevel from pay_api.factory.payment_system_factory import PaymentSystemFactory payment_account.auth_account_id = account_request.get('accountId') # If the payment method is CC, set the payment_method as DIRECT_PAY if payment_method := get_str_by_path(account_request, 'paymentInfo/methodOfPayment'): payment_account.payment_method = payment_method payment_account.bcol_account = account_request.get( 'bcolAccountNumber', None) payment_account.bcol_user_id = account_request.get( 'bcolUserId', None)
def create(business_info: Dict[str, Any], account_details: Dict[str, str], payment_system: str, authorization: Dict[str, Any]): """Create Payment account record.""" current_app.logger.debug('<create') auth_account_id = get_str_by_path(authorization, 'account/id') payment_account: PaymentAccountModel = PaymentAccountModel.find_by_auth_account_id(auth_account_id) new_payment_account: bool = False is_premium_payment: bool = False if not payment_account: payment_account = PaymentAccountModel() payment_account.auth_account_id = auth_account_id payment_account = payment_account.save() new_payment_account = True dao = None if payment_system == PaymentSystem.BCOL.value: dao = BcolPaymentAccount() dao.account_id = payment_account.id dao.bcol_account_id = account_details.get('bcol_account_id', None) dao.bcol_user_id = account_details.get('bcol_user_id', None) is_premium_payment = True elif payment_system == PaymentSystem.INTERNAL.value: dao = InternalPaymentAccount() dao.corp_number = business_info.get('businessIdentifier', None) dao.corp_type_code = business_info.get('corpType', None) dao.account_id = payment_account.id elif payment_system == PaymentSystem.PAYBC.value: dao = CreditPaymentAccount() dao.corp_number = business_info.get('businessIdentifier', None) dao.corp_type_code = business_info.get('corpType', None) dao.paybc_account = account_details.get('account_number', None) dao.paybc_party = account_details.get('party_number', None) dao.paybc_site = account_details.get('site_number', None) dao.account_id = payment_account.id dao = dao.save() if new_payment_account and is_premium_payment: PaymentAccount._persist_default_statement_frequency(payment_account.id) p = PaymentAccount() p.populate(dao) # pylint: disable=protected-access current_app.logger.debug('>create') return p
def _save_account(cls, account_request: Dict[str, any], payment_account: PaymentAccountModel): """Update and save payment account and CFS account model.""" # pylint:disable=cyclic-import, import-outside-toplevel from pay_api.factory.payment_system_factory import PaymentSystemFactory # If the payment method is CC, set the payment_method as DIRECT_PAY payment_method: str = get_str_by_path(account_request, 'paymentInfo/methodOfPayment') if not payment_method or payment_method == PaymentMethod.CC.value: payment_method = PaymentMethod.DIRECT_PAY.value payment_account.payment_method = payment_method payment_account.auth_account_id = account_request.get('accountId') payment_account.auth_account_name = account_request.get( 'accountName', None) payment_account.bcol_account = account_request.get( 'bcolAccountNumber', None) payment_account.bcol_user_id = account_request.get('bcolUserId', None) payment_account.pad_tos_accepted_by = account_request.get( 'padTosAcceptedBy', None) payment_account.pad_tos_accepted_date = datetime.now() payment_info = account_request.get('paymentInfo') billable = payment_info.get('billable', True) payment_account.billable = billable # Steps to decide on creating CFS Account or updating CFS bank account. # Updating CFS account apart from bank details not in scope now. # Create CFS Account IF: # 1. New payment account # 2. Existing payment account: # - If the account was on DIRECT_PAY and switching to Online Banking, and active CFS account is not present. # - If the account was on DRAWDOWN and switching to PAD, and active CFS account is not present cfs_account: CfsAccountModel = CfsAccountModel.find_effective_by_account_id(payment_account.id) \ if payment_account.id else None pay_system = PaymentSystemFactory.create_from_payment_method( payment_method=payment_method) if pay_system.get_payment_system_code() == PaymentSystem.PAYBC.value: if cfs_account is None: cfs_account = pay_system.create_account( name=payment_account.auth_account_name, contact_info=account_request.get('contactInfo'), payment_info=account_request.get('paymentInfo')) if cfs_account: cfs_account.payment_account = payment_account cfs_account.flush() # If the account is PAD and bank details changed, then update bank details else: # Update details in CFS pay_system.update_account( name=payment_account.auth_account_name, cfs_account=cfs_account, payment_info=payment_info) elif cfs_account is not None: # if its not PAYBC ,it means switching to either drawdown or internal ,deactivate the cfs account cfs_account.status = CfsAccountStatus.INACTIVE.value cfs_account.flush() is_pad = payment_method == PaymentMethod.PAD.value if is_pad: # override payment method for since pad has 3 days wait period effective_pay_method, activation_date = PaymentAccount._get_payment_based_on_pad_activation( payment_account) payment_account.pad_activation_date = activation_date payment_account.payment_method = effective_pay_method payment_account.save()
def _save_account(cls, account_request: Dict[str, any], payment_account: PaymentAccountModel): """Update and save payment account and CFS account model.""" # pylint:disable=cyclic-import, import-outside-toplevel from pay_api.factory.payment_system_factory import PaymentSystemFactory # If the payment method is CC, set the payment_method as DIRECT_PAY payment_method: str = get_str_by_path(account_request, 'paymentInfo/methodOfPayment') if not payment_method or payment_method == PaymentMethod.CC.value: payment_method = PaymentMethod.DIRECT_PAY.value payment_account.payment_method = payment_method payment_account.auth_account_id = account_request.get('accountId') payment_account.auth_account_name = account_request.get( 'accountName', None) payment_account.bcol_account = account_request.get( 'bcolAccountNumber', None) payment_account.bcol_user_id = account_request.get('bcolUserId', None) payment_account.pad_tos_accepted_by = account_request.get( 'padTosAcceptedBy', None) if payment_account.pad_tos_accepted_by is not None: payment_account.pad_tos_accepted_date = datetime.now() payment_info = account_request.get('paymentInfo') billable = payment_info.get('billable', True) payment_account.billable = billable payment_account.flush() # Steps to decide on creating CFS Account or updating CFS bank account. # Updating CFS account apart from bank details not in scope now. # Create CFS Account IF: # 1. New payment account # 2. Existing payment account: # - If the account was on DIRECT_PAY and switching to Online Banking, and active CFS account is not present. # - If the account was on DRAWDOWN and switching to PAD, and active CFS account is not present cfs_account: CfsAccountModel = CfsAccountModel.find_effective_by_account_id(payment_account.id) \ if payment_account.id else None pay_system = PaymentSystemFactory.create_from_payment_method( payment_method=payment_method) if pay_system.get_payment_system_code() == PaymentSystem.PAYBC.value: if cfs_account is None: cfs_account = pay_system.create_account( name=payment_account.auth_account_name, contact_info=account_request.get('contactInfo'), payment_info=account_request.get('paymentInfo')) if cfs_account: cfs_account.payment_account = payment_account cfs_account.flush() # If the account is PAD and bank details changed, then update bank details else: # Update details in CFS pay_system.update_account( name=payment_account.auth_account_name, cfs_account=cfs_account, payment_info=payment_info) is_pad = payment_method == PaymentMethod.PAD.value if is_pad: # override payment method for since pad has 3 days wait period effective_pay_method, activation_date = PaymentAccount._get_payment_based_on_pad_activation( payment_account) payment_account.pad_activation_date = activation_date payment_account.payment_method = effective_pay_method elif pay_system.get_payment_system_code() == PaymentSystem.CGI.value: # if distribution code exists, put an end date as previous day and create new. dist_code_svc: DistributionCode = DistributionCode.find_active_by_account_id( payment_account.id) if dist_code_svc and dist_code_svc.distribution_code_id: end_date: datetime = datetime.now() - timedelta(days=1) dist_code_svc.end_date = end_date.date() dist_code_svc.save() # Create distribution code details. if revenue_account := payment_info.get('revenueAccount'): revenue_account.update( dict( accountId=payment_account.id, name=payment_account.auth_account_name, )) DistributionCode.save_or_update(revenue_account)