You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.8 KiB
59 lines
1.8 KiB
import json
|
|
from typing import List, Dict, Union, Any
|
|
from app import create_app, db
|
|
from models import Payments, PaymentBatch, SinglePayments, PaymentPlans
|
|
from splynx import Splynx, SPLYNX_URL, SPLYNX_KEY, SPLYNX_SECRET
|
|
from services import log_activity
|
|
|
|
|
|
splynx = Splynx(url=SPLYNX_URL, key=SPLYNX_KEY, secret=SPLYNX_SECRET)
|
|
|
|
results = {
|
|
"deleted": 0,
|
|
"error": 0
|
|
}
|
|
|
|
|
|
|
|
def delete_splynx_invoices(splynx_id: int, payintent: str) -> List[Dict[str, Any]]:
|
|
#result = splynx.get(url=f"/api/2.0/admin/finance/invoices?main_attributes[customer_id]={splynx_id}&main_attributes[status]=paid&main_attributes[date]=2025-08-21")
|
|
params = {
|
|
'main_attributes': {
|
|
'customer_id': splynx_id,
|
|
'field_1': payintent
|
|
},
|
|
}
|
|
query_string = splynx.build_splynx_query_params(params)
|
|
result = splynx.get(url=f"/api/2.0/admin/finance/payments?{query_string}")
|
|
|
|
print(f"Count: {len(result)} - {json.dumps(result,indent=2)}")
|
|
|
|
delete = splynx.delete(url=f"/api/2.0/admin/finance/payments/{result[0]['id']}")
|
|
if delete:
|
|
results['deleted'] += 1
|
|
details = f"Deleted Splynx Payment ID: {result[0]['id']} for Splynx Customer: {splynx_id}"
|
|
else:
|
|
results['error'] += 1
|
|
details = f"Error deleting Splynx Payment ID: {result[0]['id']} for Splynx Customer: {splynx_id}"
|
|
log_activity(
|
|
user_id=1,
|
|
action="DELETE_SPLYNX_PAYMENT",
|
|
entity_type="Script",
|
|
details=details
|
|
)
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app = create_app()
|
|
|
|
|
|
with app.app_context():
|
|
payments = db.session.query(Payments).filter(Payments.Refund == True).all()
|
|
|
|
for pay in payments:
|
|
delete_splynx_invoices(pay.Splynx_ID, pay.Payment_Intent)
|
|
|
|
print(json.dumps(results,indent=2))
|
|
|
|
|