Beispiel #1
0
    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)
Beispiel #2
0
    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()
Beispiel #3
0
    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)