def test_payments_marked_for_delete(session): """Assert a payment is stored. Start with a blank database. """ payment_account = factory_payment_account() payment = factory_payment() payment_account.save() payment.save() invoice = factory_invoice(status_code=InvoiceStatus.DELETE_ACCEPTED.value, payment_account=payment_account) # invoice.invoice_status_code == InvoiceStatus.DELETE_ACCEPTED.value invoice.save() invoices = Invoice.find_invoices_marked_for_delete() assert len(invoices) == 1
def delete_marked_payments(app): """Update stale payment records. This is to handle edge cases where the user has completed payment and some error occured and payment status is not up-to-date. """ invoices_to_delete = InvoiceModel.find_invoices_marked_for_delete() if len(invoices_to_delete) == 0: app.logger.info( f'Delete Invoice Job Ran at {datetime.datetime.now()}.But No records found!' ) for invoice in invoices_to_delete: try: app.logger.info( 'Delete Payment Job found records.Payment Id: {}'.format( invoice.id)) PaymentService.delete_invoice(invoice.id) app.logger.info( 'Delete Payment Job Updated records.Payment Id: {}'.format( invoice.id)) except BusinessException as err: # just catch and continue .Don't stop app.logger.error('Error on delete_payment') app.logger.error(err)