Browse Source

more fixups

master
Alan Woodman 2 months ago
parent
commit
223be5fc3a
  1. 1
      .gitignore
  2. 3
      blueprints/main.py
  3. 2
      emailclass.py
  4. 113
      query_mysql.py

1
.gitignore

@ -145,3 +145,4 @@ dmypy.json
# Cython debug symbols # Cython debug symbols
cython_debug/ cython_debug/
*.csv

3
blueprints/main.py

@ -483,7 +483,7 @@ def get_stripe_customer_id(splynx_id):
with connection.cursor() as cursor: with connection.cursor() as cursor:
cursor.execute(query, (splynx_id,)) cursor.execute(query, (splynx_id,))
result = cursor.fetchone() result = cursor.fetchone()
print(f"MYSQL: {result}")
if result and result['stripe_customer_id']: if result and result['stripe_customer_id']:
print(f"Found Stripe customer ID in MySQL: {result['stripe_customer_id']}") print(f"Found Stripe customer ID in MySQL: {result['stripe_customer_id']}")
return result['stripe_customer_id'] return result['stripe_customer_id']
@ -1345,6 +1345,7 @@ def payment_plans_detail(plan_id):
@login_required @login_required
def api_stripe_customer_id(splynx_id): def api_stripe_customer_id(splynx_id):
"""Get Stripe customer ID for a Splynx customer.""" """Get Stripe customer ID for a Splynx customer."""
print(f"\n\nSplynx/Stripe finding customer\n\n")
try: try:
stripe_customer_id = get_stripe_customer_id(splynx_id) stripe_customer_id = get_stripe_customer_id(splynx_id)
if stripe_customer_id: if stripe_customer_id:

2
emailclass.py

@ -5,7 +5,7 @@ from email.mime.multipart import MIMEMultipart
port = 587 # For starttls port = 587 # For starttls
smtp_server = "smtp.fibrenet.net.au" smtp_server = "smtp.fibrenet.net.au"
sender_email = "alan.woodman@interphone.com.au" sender_email = "alan.woodman@interphone.com.au"
receiver_email = "alan.woodman@interphone.com.au" receiver_email = "alan.woodman@interphone.com.au,helen.barbour@interphone.com.au,suzie.mcgregor@interphone.com.au"
#password = input("Type your password and press enter:") #password = input("Type your password and press enter:")
class SendEmail(): class SendEmail():

113
query_mysql.py

@ -447,55 +447,67 @@ def processPaymentResult(pay_id, result, key):
payment = db.session.query(Payments).filter(Payments.id == pay_id).first() payment = db.session.query(Payments).filter(Payments.id == pay_id).first()
elif key == "singlepay": elif key == "singlepay":
payment = db.session.query(SinglePayments).filter(SinglePayments.id == pay_id).first() payment = db.session.query(SinglePayments).filter(SinglePayments.id == pay_id).first()
try: #try:
if result.get('error') and not result.get('needs_fee_update'): if result.get('error') and not result.get('needs_fee_update'):
payment.Error = f"Error Type: {result['error_type']}\nError: {result['error']}" payment.Error = f"Error Type: {result['error_type']}\nError: {result['error']}"
payment.Success = result['success'] payment.Success = result['success']
payment.PI_JSON = json.dumps(result) payment.PI_JSON = json.dumps(result)
# Send notification and create ticket for failed payments # Send notification and create ticket for failed payments
handle_failed_payment_notification( handle_failed_payment_notification(
payment_record=payment, payment_record=payment,
error_details=payment.Error, error_details=payment.Error,
payment_type=key payment_type=key
)
elif result.get('failure_details'):
payment.Error = f"Error Type: {result.get('failure_details').get('decline_code')}\nError: {result['failure_reason']}"
payment.Success = result['success']
payment.PI_JSON = json.dumps(result)
# Send notification and create ticket for failed payments
handle_failed_payment_notification(
payment_record=payment,
error_details=payment.Error,
payment_type=key
)
else:
print("Payment successful!")
if result.get('needs_fee_update'):
payment.PI_FollowUp = True
# Mark invoices as pending when PI_FollowUp is set
if PROCESS_LIVE:
find_set_pending_splynx_invoices(payment.Splynx_ID)
payment.Payment_Intent = result['payment_intent_id']
payment.Success = result['success']
if result['success'] and PROCESS_LIVE:
find_pay_splynx_invoices(payment.Splynx_ID)
add_payment_splynx(
splynx_id=payment.Splynx_ID,
pi_id=result['payment_intent_id'],
pay_id=payment.id,
amount=payment.Payment_Amount
) )
if result.get('payment_method_type') == "card":
payment.Payment_Method = result['estimated_fee_details']['card_display_brand']
elif result.get('payment_method_type') == "au_becs_debit":
payment.Payment_Method = result['payment_method_type']
if payment.PI_JSON:
combined = {**json.loads(payment.PI_JSON), **result}
payment.PI_JSON = json.dumps(combined)
else: else:
if result.get('needs_fee_update'): payment.PI_JSON = json.dumps(result)
payment.PI_FollowUp = True if result.get('fee_details'):
# Mark invoices as pending when PI_FollowUp is set payment.Fee_Total = result['fee_details']['total_fee']
if PROCESS_LIVE: for fee_type in result['fee_details']['fee_breakdown']:
find_set_pending_splynx_invoices(payment.Splynx_ID) if fee_type['type'] == "tax":
payment.Payment_Intent = result['payment_intent_id'] payment.Fee_Tax = fee_type['amount']
payment.Success = result['success'] elif fee_type['type'] == "stripe_fee":
if result['success'] and PROCESS_LIVE: payment.Fee_Stripe = fee_type['amount']
find_pay_splynx_invoices(payment.Splynx_ID) #except Exception as e:
add_payment_splynx( # logger.error(f"processPaymentResult: {e}\nResult: {json.dumps(result)}")
splynx_id=payment.Splynx_ID, # payment.PI_FollowUp = True
pi_id=result['payment_intent_id'], # if PROCESS_LIVE:
pay_id=payment.id, # find_set_pending_splynx_invoices(payment.Splynx_ID)
amount=payment.Payment_Amount
)
if result.get('payment_method_type') == "card":
payment.Payment_Method = result['estimated_fee_details']['card_display_brand']
elif result.get('payment_method_type') == "au_becs_debit":
payment.Payment_Method = result['payment_method_type']
if payment.PI_JSON:
combined = {**json.loads(payment.PI_JSON), **result}
payment.PI_JSON = json.dumps(combined)
else:
payment.PI_JSON = json.dumps(result)
if result.get('fee_details'):
payment.Fee_Total = result['fee_details']['total_fee']
for fee_type in result['fee_details']['fee_breakdown']:
if fee_type['type'] == "tax":
payment.Fee_Tax = fee_type['amount']
elif fee_type['type'] == "stripe_fee":
payment.Fee_Stripe = fee_type['amount']
except Exception as e:
logger.error(f"processPaymentResult: {e}\nResult: {json.dumps(result)}")
payment.PI_FollowUp = True
if PROCESS_LIVE:
find_set_pending_splynx_invoices(payment.Splynx_ID)
def _update_payment(): def _update_payment():
return True # Just need to trigger commit, payment is already modified return True # Just need to trigger commit, payment is already modified
@ -721,7 +733,7 @@ def process_payintent_mode(processor):
try: try:
intent_result = processor.check_payment_intent(pi.Payment_Intent) intent_result = processor.check_payment_intent(pi.Payment_Intent)
logger.debug(f"Intent result: {json.dumps(intent_result, indent=2)}") logger.debug(f"Intent result: {json.dumps(intent_result, indent=2)}")
print(f"\n\npayintent result: {json.dumps(intent_result, indent=2)}\n\n")
if intent_result['status'] == "succeeded": if intent_result['status'] == "succeeded":
pi.PI_FollowUp_JSON = json.dumps(intent_result) pi.PI_FollowUp_JSON = json.dumps(intent_result)
pi.PI_FollowUp = False pi.PI_FollowUp = False
@ -729,11 +741,12 @@ def process_payintent_mode(processor):
pi.Success = True pi.Success = True
# Mark invoices as paid when payment intent succeeds # Mark invoices as paid when payment intent succeeds
if PROCESS_LIVE: #if PROCESS_LIVE:
find_pay_splynx_invoices(pi.Splynx_ID) # find_pay_splynx_invoices(pi.Splynx_ID)
#if intent_result.get('charge_id').startswith('ch_'): #if intent_result.get('charge_id').startswith('ch_'):
# pi.Stripe_Charge_ID = intent_result.get('charge_id') # pi.Stripe_Charge_ID = intent_result.get('charge_id')
print("\nProcess payment results coz it succeeded")
processPaymentResult(pay_id=pi.id, result=intent_result, key=key) processPaymentResult(pay_id=pi.id, result=intent_result, key=key)
succeeded_count += 1 succeeded_count += 1
elif intent_result['status'] == "failed": elif intent_result['status'] == "failed":

Loading…
Cancel
Save