Ejemplo n.º 1
0
def test_bcol_soap(app):
    """Test BCOL SOAP Initialization."""
    with app.app_context():
        bcol_soap = BcolSoap()
        assert bcol_soap is not None
        assert bcol_soap.get_profile_client() is not None
        assert bcol_soap.get_payment_client() is not None
Ejemplo n.º 2
0
 def debit_account(self, data: Dict):  # pragma: no cover # pylint: disable=no-self-use
     """Debit BCOL account."""
     client = BcolSoap().get_payment_client()
     return zeep.helpers.serialize_object(client.service.debitAccount(req=data))
Ejemplo 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
Ejemplo n.º 4
0
 def get_profile_response(self, data: Dict):  # pragma: no cover # pylint: disable=no-self-use
     """Get Query Profile Response."""
     client = BcolSoap().get_profile_client()
     return zeep.helpers.serialize_object(client.service.queryProfile(req=data))
Ejemplo n.º 5
0
def test_bcol_soap_multiple_instances(app):
    """Test BCOL SOAP Initialization for multiple instances."""
    with app.app_context():
        bcol_soap = BcolSoap()
        bcol_soap2 = BcolSoap()
        assert bcol_soap == bcol_soap2
Ejemplo n.º 6
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
Ejemplo n.º 7
0
 def apply_charge(self, data: Dict):  # pragma: no cover # pylint: disable=no-self-use
     """Debit BCOL account as a staff user."""
     client = BcolSoap().get_applied_chg_client()
     return zeep.helpers.serialize_object(
         client.service.appliedCharge(req=data))