Beispiel #1
0
    def update_account(self, name: str, cfs_account: CfsAccountModel, payment_info: Dict[str, Any]) -> CfsAccountModel:
        """Update account in CFS."""
        if str(payment_info.get('bankInstitutionNumber')) != cfs_account.bank_number or \
                str(payment_info.get('bankTransitNumber')) != cfs_account.bank_branch_number or \
                str(payment_info.get('bankAccountNumber')) != cfs_account.bank_account_number:
            # This means, PAD account details have changed. So update banking details for this CFS account
            # Call cfs service to add new bank info.
            bank_details = CFSService.update_bank_details(name=cfs_account.payment_account.auth_account_name,
                                                          party_number=cfs_account.cfs_party,
                                                          account_number=cfs_account.cfs_account,
                                                          site_number=cfs_account.cfs_site,
                                                          payment_info=payment_info)

            instrument_number = bank_details.get('payment_instrument_number', None)

            # Make the current CFS Account as INACTIVE in DB
            cfs_account.status = CfsAccountStatus.INACTIVE.value
            cfs_account.flush()

            # Create new CFS Account
            updated_cfs_account = CfsAccountModel()
            updated_cfs_account.bank_account_number = payment_info.get('bankAccountNumber')
            updated_cfs_account.bank_number = payment_info.get('bankInstitutionNumber')
            updated_cfs_account.bank_branch_number = payment_info.get('bankTransitNumber')
            updated_cfs_account.cfs_site = cfs_account.cfs_site
            updated_cfs_account.cfs_party = cfs_account.cfs_party
            updated_cfs_account.cfs_account = cfs_account.cfs_account
            updated_cfs_account.payment_account = cfs_account.payment_account
            updated_cfs_account.status = CfsAccountStatus.ACTIVE.value
            updated_cfs_account.payment_instrument_number = instrument_number
            updated_cfs_account.flush()
        return cfs_account
Beispiel #2
0
 def create_account(self, name: str, contact_info: Dict[str, Any], payment_info: Dict[str, Any], **kwargs) -> any:
     """Create account in PayBC."""
     # Create CFS Account model instance and store the bank details
     cfs_account = CfsAccountModel()
     # Create CFS account
     cfs_account_details = self.create_cfs_account(name, contact_info, receipt_method=None)
     # Update model with response values
     cfs_account.cfs_account = cfs_account_details.get('account_number')
     cfs_account.cfs_site = cfs_account_details.get('site_number')
     cfs_account.cfs_party = cfs_account_details.get('party_number')
     cfs_account.status = CfsAccountStatus.ACTIVE.value
     return cfs_account
Beispiel #3
0
def create_cfs_account(cfs_account: CfsAccountModel,
                       pay_account: PaymentAccountModel):
    """Create CFS account for routing slip."""
    routing_slip: RoutingSlipModel = RoutingSlipModel.find_by_payment_account_id(
        pay_account.id)
    try:
        # TODO add status check so that LINKED etc can be skipped.
        # for RS , entity/business number=party name ; RS Number=site name
        cfs_account_details: Dict[str, any] = CFSService.create_cfs_account(
            identifier=pay_account.name,
            contact_info={},
            site_name=routing_slip.number,
            is_fas=True)
        cfs_account.cfs_account = cfs_account_details.get('account_number')
        cfs_account.cfs_party = cfs_account_details.get('party_number')
        cfs_account.cfs_site = cfs_account_details.get('site_number')
        cfs_account.status = CfsAccountStatus.ACTIVE.value
        # Create receipt in CFS for the payment.
        CFSService.create_cfs_receipt(
            cfs_account=cfs_account,
            rcpt_number=routing_slip.number,
            rcpt_date=routing_slip.routing_slip_date.strftime('%Y-%m-%d'),
            amount=routing_slip.total,
            payment_method=pay_account.payment_method,
            access_token=CFSService.get_fas_token().json().get('access_token'))
        cfs_account.commit()
        return

    except Exception as e:  # NOQA # pylint: disable=broad-except

        capture_message(
            f'Error on creating Routing Slip CFS Account: account id={pay_account.id}, '
            f'auth account : {pay_account.auth_account_id}, ERROR : {str(e)}',
            level='error')
        current_app.logger.error(e)
        cfs_account.rollback()
        return
Beispiel #4
0
    def _create_cfs_account(cls, pending_account: CfsAccountModel,
                            pay_account: PaymentAccountModel, auth_token: str):
        # If PAD Account creation in CFS is paused, then just continue
        # TODO Remove once PAD account bugs are fixed and stable on CAS side.
        if current_app.config.get('CFS_STOP_PAD_ACCOUNT_CREATION') and \
                pay_account.payment_method == PaymentMethod.PAD.value:
            current_app.logger.info(
                'Continuing to next record as CFS PAD account creation is stopped.'
            )
            return

        current_app.logger.info(
            f'Creating pay system instance for {pay_account.payment_method} for account {pay_account.id}.'
        )

        # For an existing CFS Account, call update.. This is to handle PAD update when CFS is offline
        try:
            account_contact = cls._get_account_contact(
                auth_token, pay_account.auth_account_id)

            contact_info: Dict[str, str] = {
                'city': account_contact.get('city'),
                'postalCode': account_contact.get('postalCode'),
                'province': account_contact.get('region'),
                'addressLine1': account_contact.get('street'),
                'country': account_contact.get('country')
            }

            payment_info: Dict[str, any] = {
                'bankInstitutionNumber': pending_account.bank_number,
                'bankTransitNumber': pending_account.bank_branch_number,
                'bankAccountNumber': pending_account.bank_account_number,
                'bankAccountName': pay_account.name
            }

            if pending_account.cfs_account and pending_account.cfs_party and pending_account.cfs_site:
                # This means, PAD account details have changed. So update banking details for this CFS account
                bank_details = CFSService.update_bank_details(
                    name=pay_account.auth_account_id,
                    party_number=pending_account.cfs_party,
                    account_number=pending_account.cfs_account,
                    site_number=pending_account.cfs_site,
                    payment_info=payment_info)
                pending_account.payment_instrument_number = bank_details.get(
                    'payment_instrument_number', None)
            else:  # It's a new account, now create
                # If the account have banking information, then create a PAD account else a regular account.
                if pending_account.bank_number and pending_account.bank_branch_number \
                        and pending_account.bank_account_number:
                    cfs_account_details = CFSService.create_cfs_account(
                        identifier=pay_account.auth_account_id,
                        contact_info=contact_info,
                        payment_info=payment_info,
                        receipt_method=RECEIPT_METHOD_PAD_DAILY)
                else:
                    cfs_account_details = CFSService.create_cfs_account(
                        identifier=pay_account.auth_account_id,
                        contact_info=contact_info,
                        receipt_method=None)

                pending_account.payment_instrument_number = cfs_account_details.get(
                    'payment_instrument_number', None)
                pending_account.cfs_account = cfs_account_details.get(
                    'account_number')
                pending_account.cfs_site = cfs_account_details.get(
                    'site_number')
                pending_account.cfs_party = cfs_account_details.get(
                    'party_number')

        except Exception as e:  # NOQA # pylint: disable=broad-except
            # publish to mailer queue.
            is_user_error = False
            if pay_account.payment_method == PaymentMethod.PAD.value:
                is_user_error = CreateAccountTask._check_user_error(e.response)  # pylint: disable=no-member
            capture_message(
                f'Error on creating CFS Account: account id={pay_account.id}, '
                f'auth account : {pay_account.auth_account_id}, ERROR : {str(e)}',
                level='error')
            current_app.logger.error(e)
            pending_account.rollback()

            if is_user_error:
                capture_message(
                    f'User Input needed for creating CFS Account: account id={pay_account.id}, '
                    f'auth account : {pay_account.auth_account_id}, ERROR : Invalid Bank Details',
                    level='error')
                mailer.publish_mailer_events('PadSetupFailed', pay_account)
                pending_account.status = CfsAccountStatus.INACTIVE.value
                pending_account.save()
            return

        # If the account has an activation time set ,
        # before that it shud be set to the  PENDING_PAD_ACTIVATION status.
        is_account_in_pad_confirmation_period = pay_account.pad_activation_date is not None and \
            pay_account.pad_activation_date > datetime.today()
        pending_account.status = CfsAccountStatus.PENDING_PAD_ACTIVATION.value if \
            is_account_in_pad_confirmation_period else CfsAccountStatus.ACTIVE.value
        pending_account.save()