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.
 
 
 

95 lines
2.6 KiB

import pymysql
import sys
import json
import random
import threading
import logging
import stripe
from concurrent.futures import ThreadPoolExecutor, as_completed
from datetime import datetime
from typing import List, Dict, Union, Any
from stripe_payment_processor import StripePaymentProcessor
from config import Config
from sqlalchemy import and_
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_script_start, log_script_completion, log_batch_created,
log_payment_intent_followup
)
from notification_service import NotificationService
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler('payment_processing.log'),
logging.StreamHandler(sys.stdout)
]
)
logger = logging.getLogger(__name__)
# Initialize Splynx API
splynx = Splynx(url=SPLYNX_URL, key=SPLYNX_KEY, secret=SPLYNX_SECRET)
def find_set_pending_splynx_invoices(splynx, splynx_id: int) -> List[Dict[str, Any]]:
"""
Mark Splynx invoices as pending for a given customer.
Args:
splynx: Splynx API client instance
splynx_id: Customer ID in Splynx
Returns:
List of updated invoice dictionaries
"""
result = splynx.get(
url=f"/api/2.0/admin/finance/invoices?main_attributes[customer_id]={splynx_id}&main_attributes[status]=not_paid"
)
invoice_pay = {"status": "pending"}
updated_invoices = []
for pay in result:
res = splynx.put(url=f"/api/2.0/admin/finance/invoices/{pay['id']}", params=invoice_pay)
if res:
updated_invoices.append(res)
return updated_invoices
if __name__ == "__main__":
## Payment Method:
## 2 - Direct Debit (Automatic)
## 3 - Card Payment (Automatic)
## 9 - Payment Plan
### Running Mode
## batch = Monthly Direct Debit/Credit Cards
## payintent = Check outstanding Payment Intents and update
## payplan = Check for Payment Plans to run
## refund = Check outstanding Refunds and update
start_time = datetime.now()
# Create Flask application context
app = create_app()
with app.app_context():
customers = (
db.session.query(Payments)
.filter(and_(Payments.PaymentBatch_ID.in_((108,109)), Payments.PI_FollowUp == True))
.all()
)
for pay in customers:
print(pay.Splynx_ID)
find_set_pending_splynx_invoices(splynx, pay.Splynx_ID)