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.
52 lines
2.0 KiB
52 lines
2.0 KiB
import json
|
|
import stripe
|
|
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
|
|
from config import Config
|
|
from sqlalchemy import and_
|
|
|
|
|
|
splynx = Splynx(url=SPLYNX_URL, key=SPLYNX_KEY, secret=SPLYNX_SECRET)
|
|
|
|
|
|
api_key = Config.STRIPE_LIVE_API_KEY
|
|
|
|
stripe.api_key = api_key
|
|
|
|
|
|
def find_pay_splynx_invoices(splynx_id: int, result: dict) -> List[Dict[str, Any]]:
|
|
#result = splynx.get(url=f"/api/2.0/admin/finance/invoices?main_attributes[customer_id]={splynx_id}&main_attributes[status]=not_paid&main_attributes[status]=pending")
|
|
|
|
invoice_pay = {
|
|
"status": "paid"
|
|
}
|
|
|
|
for pay in result:
|
|
res = splynx.put(url=f"/api/2.0/admin/finance/invoices/{pay['id']}", params=invoice_pay)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app = create_app()
|
|
i = 1
|
|
#cust_bill = splynx.get(url=f"/api/2.0/admin/customers/customer-billing/31")
|
|
#print(json.dumps(cust_bill,indent=2))
|
|
with app.app_context():
|
|
custs = db.session.query(PaymentBatch,Payments)\
|
|
.join(Payments, Payments.PaymentBatch_ID == PaymentBatch.id)\
|
|
.filter(and_(PaymentBatch.id.in_((102,103)), Payments.Success == True))\
|
|
.all()
|
|
print(len(custs))
|
|
for cust in custs:
|
|
cust_bill = splynx.get(url=f"/api/2.0/admin/customers/customer-billing/{cust.Payments.Splynx_ID}")
|
|
print(f"{i}/{len(custs)}")
|
|
if cust_bill['deposit'] == 0:
|
|
result = splynx.get(url=f"/api/2.0/admin/finance/invoices?main_attributes[customer_id]={cust.Payments.Splynx_ID}&main_attributes[status]=pending")
|
|
#print(json.dumps(result,indent=2))
|
|
if len(result) > 0:
|
|
print(f"\t{cust.Payments.Splynx_ID} - Has unpaid invoices")
|
|
find_pay_splynx_invoices(splynx_id=cust.Payments.Splynx_ID, result=result)
|
|
i += 1
|
|
|