Refresh Payment Transaction Status

This document defines the Batch which is responsible to fetch the latest Payment status from the Gateway and updates the associated Payment Transaction record in Salesforce.


🛠️ Batch Job: BatchGetPaymentTransactionStatus

  • 🔍 Retrieves current payment status (e.g., Settled, Failed) by making an API call to the payment gateway

  • 📥 Updates corresponding cm_finance__Payment_Transaction__c records in Salesforce with:

    • Latest Payment Status

    • Gateway Error Message (if any)


⚙️ Custom Query Filter

  • 🧩 Controlled via PaymentStatus_WhereClause in Payment Guru Common Setting (Custom Metadata)

  • 🧠 Use this metadata to dynamically control which transactions are picked for status update


⏱️ Scheduling

  • ⏰ Can be scheduled via Apex Scheduler

  • 🔁 Enables automatic periodic updates (e.g., Daily, Weekly) without manual intervention


💻 Execution Script

👉 Run batch without filter (uses metadata-based query):

Database.executeBatch(new BatchGetPaymentTransactionStatus(), 1); 

👉 Run batch with a custom SOQL query:

String sQuery = 'SELECT Id, cm_finance__Payment_Status__c, cm_finance__Transaction_Status__c, cm_finance__Gateway_Error_Message__c, cm_finance__Transaction_Id__c, cm_finance__Payment_Gateway__c FROM cm_finance__Payment_Transaction__c WHERE cm_finance__Payment_Status__c = \'Accepted\''; 
Database.executeBatch(new BatchGetPaymentTransactionStatus(sQuery), 1); 

✅ Benefits

  • 📊 Accurate, real-time transaction statuses

  • 🔒 Reduced manual reconciliation effort

  • ⚡ Supports automation and reporting