|
|
@ -447,12 +447,23 @@ 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 |
|
|
|
|
|
handle_failed_payment_notification( |
|
|
|
|
|
payment_record=payment, |
|
|
|
|
|
error_details=payment.Error, |
|
|
|
|
|
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 |
|
|
# Send notification and create ticket for failed payments |
|
|
handle_failed_payment_notification( |
|
|
handle_failed_payment_notification( |
|
|
payment_record=payment, |
|
|
payment_record=payment, |
|
|
@ -460,6 +471,7 @@ def processPaymentResult(pay_id, result, key): |
|
|
payment_type=key |
|
|
payment_type=key |
|
|
) |
|
|
) |
|
|
else: |
|
|
else: |
|
|
|
|
|
print("Payment successful!") |
|
|
if result.get('needs_fee_update'): |
|
|
if result.get('needs_fee_update'): |
|
|
payment.PI_FollowUp = True |
|
|
payment.PI_FollowUp = True |
|
|
# Mark invoices as pending when PI_FollowUp is set |
|
|
# Mark invoices as pending when PI_FollowUp is set |
|
|
@ -491,11 +503,11 @@ def processPaymentResult(pay_id, result, key): |
|
|
payment.Fee_Tax = fee_type['amount'] |
|
|
payment.Fee_Tax = fee_type['amount'] |
|
|
elif fee_type['type'] == "stripe_fee": |
|
|
elif fee_type['type'] == "stripe_fee": |
|
|
payment.Fee_Stripe = fee_type['amount'] |
|
|
payment.Fee_Stripe = fee_type['amount'] |
|
|
except Exception as e: |
|
|
#except Exception as e: |
|
|
logger.error(f"processPaymentResult: {e}\nResult: {json.dumps(result)}") |
|
|
# logger.error(f"processPaymentResult: {e}\nResult: {json.dumps(result)}") |
|
|
payment.PI_FollowUp = True |
|
|
# payment.PI_FollowUp = True |
|
|
if PROCESS_LIVE: |
|
|
# if PROCESS_LIVE: |
|
|
find_set_pending_splynx_invoices(payment.Splynx_ID) |
|
|
# 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": |
|
|
|