def get_receipt(self, payment_account: PaymentAccount, pay_response_url: str, invoice_reference: InvoiceReference): """Get receipt from paybc for the receipt number or get receipt against invoice number.""" current_app.logger.debug('<paybc_service_Getting token') access_token: str = CFSService.get_token().json().get('access_token') current_app.logger.debug('<Getting receipt') receipt_url = current_app.config.get('CFS_BASE_URL') + '/cfs/parties/{}/accs/{}/sites/{}/rcpts/'.format( payment_account.cfs_party, payment_account.cfs_account, payment_account.cfs_site) parsed_url = parse_url_params(pay_response_url) receipt_number: str = parsed_url.get('receipt_number') if 'receipt_number' in parsed_url else None if not receipt_number: # Find all receipts for the site and then match with invoice number receipts_response = self.get(receipt_url, access_token, AuthHeaderType.BEARER, ContentType.JSON, retry_on_failure=True).json() for receipt in receipts_response.get('items'): expanded_receipt = self.__get_receipt_by_number(access_token, receipt_url, receipt.get('receipt_number')) for invoice in expanded_receipt.get('invoices'): if invoice.get('invoice_number') == invoice_reference.invoice_number: return receipt.get('receipt_number'), parser.parse( expanded_receipt.get('receipt_date')), float(invoice.get('amount_applied')) if receipt_number: receipt_response = self.__get_receipt_by_number(access_token, receipt_url, receipt_number) receipt_date = parser.parse(receipt_response.get('receipt_date')) amount: float = 0 for invoice in receipt_response.get('invoices'): if invoice.get('invoice_number') == invoice_reference.invoice_number: amount += float(invoice.get('amount_applied')) return receipt_number, receipt_date, amount return None
def get_bank_info( party_number: str, # pylint: disable=too-many-arguments account_number: str, site_number: str): """Get bank details to the site.""" current_app.logger.debug('<Updating CFS payment details ') site_payment_url = current_app.config.post( 'CFS_BASE_URL' ) + f'/cfs/parties/{party_number}/accs/{account_number}/sites/{site_number}/payment/' access_token: str = CFSService.get_token().json().get('access_token') payment_details = CFSService.get(site_payment_url, access_token, AuthHeaderType.BEARER, ContentType.JSON) return payment_details.json()
def run_update(pay_account_id, num_records): """Update bank info.""" current_app.logger.info( f'<<<< Running Update for account id from :{pay_account_id} and total:{num_records} >>>>' ) pad_accounts: List[PaymentAccountModel] = db.session.query(PaymentAccountModel).filter( PaymentAccountModel.payment_method == PaymentMethod.PAD.value) \ .filter(PaymentAccountModel.id >= pay_account_id) \ .order_by(PaymentAccountModel.id.asc()) \ .limit(num_records) \ .all() access_token: str = CFSService.get_token().json().get('access_token') current_app.logger.info( f'<<<< Total number of records founds: {len(pad_accounts)}') current_app.logger.info( f'<<<< records founds: {[accnt.id for accnt in pad_accounts]}') if len(pad_accounts) == 0: return for payment_account in pad_accounts: cfs_account: CfsAccountModel = CfsAccountModel.find_effective_by_account_id( payment_account.id) current_app.logger.info( f'<<<< Running Update for account id :{payment_account.id} and cfs_account:{cfs_account.id} >>>>' ) # payment_details = get_bank_info(cfs_account.cfs_party, cfs_account.cfs_account, cfs_account.cfs_site) # current_app.logger.info(payment_details) name = re.sub(r'[^a-zA-Z0-9]+', ' ', payment_account.name) payment_info: Dict[str, any] = { 'bankInstitutionNumber': cfs_account.bank_number, 'bankTransitNumber': cfs_account.bank_branch_number, 'bankAccountNumber': cfs_account.bank_account_number, 'bankAccountName': name } save_bank_details(access_token, cfs_account.cfs_party, cfs_account.cfs_account, cfs_account.cfs_site, payment_info) current_app.logger.info( f'<<<< Successfully Updated for account id :{payment_account.id} and cfs_account:{cfs_account.id} >>>>' )