Exemplo n.º 1
0
    def create_payment(self, pay_request: Dict):
        """Create payment record in BCOL."""
        current_app.logger.debug('<create_payment')
        pay_response = None
        # Call the query profile service to fetch profile
        data = {
            'Version': current_app.config.get('BCOL_DEBIT_ACCOUNT_VERSION'),
            'Feecode': pay_request.get('feeCode'),
            'Userid': pay_request.get('userId'),
            'Key': pay_request.get('invoiceNumber'),
            'Account': '',
            'RateType': '',
            'Folio': pay_request.get('folioNumber'),
            'FormNumber': pay_request.get('formNumber', ''),
            'Quantity': pay_request.get('quantity', ''),
            'Rate': pay_request.get('rate', ''),
            'Amount': pay_request.get('amount', ''),
            'Remarks': pay_request.get('remarks', 'BCOL Payment from BCROS'),
            'RedundantFlag': pay_request.get('reduntantFlag', ' '),
            'linkcode': current_app.config.get('BCOL_LINK_CODE')
        }
        try:
            response = self.debit_account(data)
            current_app.logger.debug(response)

            if self.__get(response, 'ReturnCode') != '0000':
                raise BusinessException(Error.BCOL003)

            transaction = response['TranID']
            pay_response = {
                'statutoryFee': self.__get(response, 'StatFee'),
                'totalAmount': self.__get(response, 'Totamt'),
                'tsFee': self.__get(response, 'TSFee'),
                'gst': self.__get(response, 'Totgst'),
                'pst': self.__get(response, 'Totpst'),
                'accountNumber': self.__get(transaction, 'Account'),
                'userId': self.__get(transaction, 'UserID'),
                'date': self.__get(transaction, 'AppliedDate') + ':' + self.__get(transaction, 'AppliedTime'),
                'feeCode': self.__get(transaction, 'FeeCode'),
                'key': self.__get(transaction, 'Key'),
                'sequenceNo': self.__get(transaction, 'SequenceNo'),
            }

        except Exception as e:
            current_app.logger.error(e)
            raise BusinessException(Error.BCOL003)

        current_app.logger.debug('>query_profile')
        return pay_response
Exemplo n.º 2
0
    def __authenticate_user(self, user_id: str, password: str) -> bool:  # pylint: disable=no-self-use
        """Validate the user by ldap lookup."""
        current_app.logger.debug('<<< _validate_user')
        ldap_conn = None
        try:
            ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)  # pylint: disable=no-member
            ldap_conn = ldap.initialize(
                current_app.config.get('BCOL_LDAP_SERVER'), trace_level=2
            )
            ldap_conn.set_option(ldap.OPT_REFERRALS, 0)  # pylint: disable=no-member
            ldap_conn.set_option(ldap.OPT_PROTOCOL_VERSION, 3)  # pylint: disable=no-member
            ldap_conn.set_option(ldap.OPT_X_TLS, ldap.OPT_X_TLS_DEMAND)  # pylint: disable=no-member
            ldap_conn.set_option(ldap.OPT_X_TLS_DEMAND, True)  # pylint: disable=no-member
            ldap_conn.set_option(ldap.OPT_DEBUG_LEVEL, 255)  # pylint: disable=no-member

            username = current_app.config.get('BCOL_LDAP_USER_DN_PATTERN').format(
                user_id
            )
            ldap_conn.simple_bind_s(username, password)
        except Exception as error:  # NOQA
            current_app.logger.warning(error)
            raise BusinessException(Error.INVALID_CREDENTIALS)
        finally:
            if ldap_conn:
                ldap_conn.unbind_s()

        current_app.logger.debug('>>> _validate_user')
Exemplo n.º 3
0
    def query_profile(self, bcol_user_id: str, password: str):
        """Query for profile and return the results."""
        current_app.logger.debug('<query_profile')
        # Validate the user first
        self.__authenticate_user(bcol_user_id, password)

        # Call the query profile service to fetch profile
        data = {
            'Version': current_app.config.get('BCOL_DEBIT_ACCOUNT_VERSION'),
            'Userid': bcol_user_id,  # 'pc25020',
            'linkcode': current_app.config.get('BCOL_LINK_CODE'),
        }
        try:
            profile_resp = self.get_profile_response(data)
            current_app.logger.debug(profile_resp)
            auth_code = self.__get(profile_resp, 'AuthCode')
            if auth_code != 'P':
                raise BusinessException(Error.NOT_A_PRIME_USER)

            response = {
                'userId': self.__get(profile_resp, 'Userid'),
                'accountNumber': self.__get(profile_resp, 'AccountNumber'),
                'authCode': auth_code,
                'authCodeDesc': auth_code_mapping()[
                    self.__get(profile_resp, 'AuthCode')
                ],
                'accountType': self.__get(profile_resp, 'AccountType'),
                'accountTypeDesc': account_type_mapping()[
                    self.__get(profile_resp, 'AccountType')
                ],
                'gstStatus': self.__get(profile_resp, 'GSTStatus'),
                'gstStatusDesc': tax_status_mapping()[
                    self.__get(profile_resp, 'GSTStatus')
                ],
                'pstStatus': self.__get(profile_resp, 'PSTStatus'),
                'pstStatusDesc': tax_status_mapping()[
                    self.__get(profile_resp, 'PSTStatus')
                ],
                'userName': self.__get(profile_resp, 'UserName'),
                'orgName': self.__get(profile_resp, 'org-name'),
                'orgType': self.__get(profile_resp, 'org-type'),
                'phone': self.__get(profile_resp, 'UserPhone'),
                'fax': self.__get(profile_resp, 'UserFax'),
            }
            address = profile_resp['Address']
            if address:
                country = self.standardize_country(self.__get(address, 'Country'))

                response['address'] = {
                    'line1': self.__get(address, 'AddressA'),
                    'line2': self.__get(address, 'AddressB'),
                    'city': self.__get(address, 'City'),
                    'province': self.__get(address, 'Prov'),
                    'country': country,
                    'postalCode': self.__get(address, 'PostalCode'),
                }
            query_profile_flags = profile_resp['queryProfileFlag']
            if query_profile_flags:
                flags: list = []
                for flag in query_profile_flags:
                    flags.append(flag['name'])
                response['profile_flags'] = flags
        except zeep.exceptions.Fault as fault:
            current_app.logger.error(fault)
            parsed_fault_detail = BcolSoap().get_profile_client().wsdl.types.deserialize(fault.detail[0])
            current_app.logger.error(parsed_fault_detail)
            raise PaymentException(message=self.__get(parsed_fault_detail, 'message'),
                                   code=self.__get(parsed_fault_detail, 'returnCode'))
        except BusinessException as e:
            raise e
        except Exception as e:  # NOQA
            current_app.logger.error(e)
            raise BusinessException(Error.SYSTEM_ERROR)

        current_app.logger.debug('>query_profile')
        return response
Exemplo n.º 4
0
    def create_payment(self, pay_request: Dict, is_staff: bool):
        """Create payment record in BCOL."""
        current_app.logger.debug('<create_payment')
        padded_amount = self._pad_zeros(pay_request.get('amount', '0'))
        # Call the query profile service to fetch profile
        data = {
            'Version': current_app.config.get('BCOL_DEBIT_ACCOUNT_VERSION'),
            'Feecode': pay_request.get('feeCode'),
            'Userid': pay_request.get('userId'),
            'Key': pay_request.get('invoiceNumber'),
            'Account': pay_request.get('accountNumber', ''),
            'RateType': pay_request.get('rateType', ''),
            'Folio': pay_request.get('folioNumber', None),
            'FormNumber': pay_request.get('formNumber', ''),  # Also DAT Number
            'Quantity': pay_request.get('quantity', ''),
            'Rate': padded_amount,
            'Amount': padded_amount,
            'Remarks': pay_request.get('remarks', 'BCOL Payment from BCROS'),
            'RedundantFlag': pay_request.get('reduntantFlag', ' '),
            'linkcode': current_app.config.get('BCOL_LINK_CODE')
        }

        try:
            current_app.logger.debug(f'Is staff payment ? = {is_staff} ')

            response = self.apply_charge(
                data) if is_staff else self.debit_account(data)
            current_app.logger.debug(response)

            if self.__get(response, 'ReturnCode') != '0000':
                raise BusinessException(Error.PAYMENT_ERROR)

            transaction = response['TranID']
            pay_response = {
                'statutoryFee':
                self.__get(response, 'StatFee'),
                'totalAmount':
                self.__get(response, 'Totamt'),
                'tsFee':
                self.__get(response, 'TSFee'),
                'gst':
                self.__get(response, 'Totgst'),
                'pst':
                self.__get(response, 'Totpst'),
                'accountNumber':
                self.__get(transaction, 'Account'),
                'userId':
                self.__get(transaction, 'UserID'),
                'date':
                self.__get(transaction, 'AppliedDate') + ':' +
                self.__get(transaction, 'AppliedTime'),
                'feeCode':
                self.__get(transaction, 'FeeCode'),
                'key':
                self.__get(transaction, 'Key'),
                'sequenceNo':
                self.__get(transaction, 'SequenceNo'),
            }

        except zeep.exceptions.Fault as fault:
            current_app.logger.error(fault)
            parsed_fault_detail = BcolSoap().get_payment_client(
            ).wsdl.types.deserialize(fault.detail[0])
            current_app.logger.error(parsed_fault_detail)
            raise PaymentException(message=self.__get(parsed_fault_detail,
                                                      'message'),
                                   code=self.__get(parsed_fault_detail,
                                                   'returnCode'))
        except BusinessException as e:
            raise e
        except Exception as e:
            current_app.logger.error(e)
            raise BusinessException(Error.PAYMENT_ERROR)

        current_app.logger.debug('>query_profile')
        return pay_response
Exemplo n.º 5
0
    def query_profile(self, bcol_user_id: str, password: str):
        """Query for profile and return the results."""
        current_app.logger.debug('<query_profile')
        # Validate the user first
        self.__authenticate_user(bcol_user_id, password)

        # Call the query profile service to fetch profile
        data = {
            'Version': current_app.config.get('BCOL_DEBIT_ACCOUNT_VERSION'),
            'Userid': bcol_user_id,  # 'pc25020',
            'linkcode': current_app.config.get('BCOL_LINK_CODE'),
        }
        try:
            profile_resp = self.get_profile_response(data)
            response = {
                'userId':
                self.__get(profile_resp, 'Userid'),
                'accountNumber':
                self.__get(profile_resp, 'AccountNumber'),
                'authCode':
                self.__get(profile_resp, 'AuthCode'),
                'authCodeDesc':
                auth_code_mapping()[self.__get(profile_resp, 'AuthCode')],
                'accountType':
                self.__get(profile_resp, 'AccountType'),
                'accountTypeDesc':
                account_type_mapping()[self.__get(profile_resp,
                                                  'AccountType')],
                'gstStatus':
                self.__get(profile_resp, 'GSTStatus'),
                'gstStatusDesc':
                tax_status_mapping()[self.__get(profile_resp, 'GSTStatus')],
                'pstStatus':
                self.__get(profile_resp, 'PSTStatus'),
                'pstStatusDesc':
                tax_status_mapping()[self.__get(profile_resp, 'PSTStatus')],
                'userName':
                self.__get(profile_resp, 'UserName'),
                'orgName':
                self.__get(profile_resp, 'org-name'),
                'orgType':
                self.__get(profile_resp, 'org-type'),
                'phone':
                self.__get(profile_resp, 'UserPhone'),
                'fax':
                self.__get(profile_resp, 'UserFax'),
            }
            address = profile_resp['Address']
            if address:
                response['address'] = {
                    'line1': self.__get(address, 'AddressA'),
                    'line2': self.__get(address, 'AddressB'),
                    'city': self.__get(address, 'City'),
                    'province': self.__get(address, 'Prov'),
                    'country': self.__get(address, 'Country'),
                    'postalCode': self.__get(address, 'PostalCode'),
                }
            query_profile_flags = profile_resp['queryProfileFlag']
            if query_profile_flags:
                flags: list = []
                for flag in query_profile_flags:
                    flags.append(flag['name'])
                response['profile_flags'] = flags

        except Exception as e:
            current_app.logger.error(e)
            raise BusinessException(Error.BCOL002)

        current_app.logger.debug('>query_profile')
        return response