2 changed files with 142 additions and 26 deletions
@ -1,42 +1,39 @@ |
|||
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 |
|||
|
|||
|
|||
splynx = Splynx(url=SPLYNX_URL, key=SPLYNX_KEY, secret=SPLYNX_SECRET) |
|||
|
|||
results = { |
|||
"deleted": 0, |
|||
"error": 0 |
|||
} |
|||
|
|||
api_key = Config.STRIPE_LIVE_API_KEY |
|||
|
|||
stripe.api_key = api_key |
|||
|
|||
|
|||
def splynx_invoices(splynx_id: int) -> 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, |
|||
'status': ['IN', ['not_paid', 'pending']] |
|||
}, |
|||
} |
|||
query_string = splynx.build_splynx_query_params(params) |
|||
result = splynx.get(url=f"/api/2.0/admin/finance/invoices?{query_string}") |
|||
|
|||
print(f"Count: {len(result)} - {json.dumps(result,indent=2)}") |
|||
if __name__ == "__main__": |
|||
customers = stripe.Customer.search(query="email:'tom.bj@icloud.com'") |
|||
print(customers) |
|||
|
|||
|
|||
cust = splynx.Customer(31) |
|||
print(f"cust: {json.dumps(cust,indent=2)}") |
|||
|
|||
params = { |
|||
'additional_attributes': { |
|||
'stripe_customer_id': customers['data'][-1]['id'] |
|||
} |
|||
} |
|||
|
|||
update_cust = splynx.put(url=f"/api/2.0/admin/customers/customer/31", params=params) |
|||
|
|||
if __name__ == "__main__": |
|||
app = create_app() |
|||
|
|||
customer_id = '1219464' |
|||
results = splynx_invoices(customer_id) |
|||
print(f"update_cust: {update_cust}") |
|||
|
|||
print(json.dumps(results,indent=2)) |
|||
cust = splynx.Customer(31) |
|||
print(f"cust: {json.dumps(cust,indent=2)}") |
|||
|
|||
print(cust['additional_attributes']['stripe_customer_id']) |
|||
Loading…
Reference in new issue