Pseudo Code Generator

API Transaction Processing Logic

This pseudo code outlines the process for handling a list of API transactions, including updating summaries and managing responses based on specific API names. It features modular functions for updating company owners, appointment


Empty image or helper icon

Prompt

public TransactionWrapper processAPITransactions(List apiTransactionList, Map inputMap,
     List transaction_record){
        Map bfTransSummToUpdate = new Map();
        //QTAPO-14674 Storing Address Match on API Transaction -Start
        //ESP-6823 process Buyflow API Transactions
        WrapperClassForProcessAPITransactions wrapperClass=new WrapperClassForProcessAPITransactions();
        for(Buyflow_API_Transactions__c apiTrx : apiTransactionList){
            String addrssMatch;                    
            if(apiTrx.API_Name__c.equalsIgnoreCase(SERVICEADDDRESSVALIDATIONS)){
                wrapperClass=apiNameIsServiceAddressValidations(apiTrx,addrssMatch,bfTransSummToUpdate);
                apiTrx=wrapperClass.apiTrx;
                addrssMatch=wrapperClass.addrssMatch;
                bfTransSummToUpdate=wrapperClass.bfTransSummToUpdate;
            } else if(apiTrx.API_Name__c.equalsIgnoreCase('AddressBusinessService') || 
            apiTrx.API_Name__c.equalsIgnoreCase('SubmitByGeoAddressId')){
                addrssMatch = handleAddressBusinessService(apiTrx,addrssMatch);                
                //ESP-8151 - start
                if(apiTrx.API_Name__c.equalsIgnoreCase('AddressBusinessService') && apiTrx.API_Response_JSON__c != null
                && captureCompanyOnwerIdBMFlow(apiTrx.API_Response_JSON__c) != null){
                    BF_Transactions_Summary__c summRec = bfTransSummToUpdate.get(apiTrx.Buyflow_Transaction_Summary_ID__c);
                    String companyOwnerId = captureCompanyOnwerIdBMFlow(apiTrx.API_Response_JSON__c);
                    if(summRec!=NULL){
                        summRec.CompanyOwnerId__c = companyOwnerId;
                    }else{
                        bfTransSummToUpdate.put(apiTrx.Buyflow_Transaction_Summary_ID__c, new BF_Transactions_Summary__c(
                            Id = apiTrx.Buyflow_Transaction_Summary_ID__c,CompanyOwnerId__c = companyOwnerId)
                                                ); 
                    }
                }
                //ESP-8151 - end 
            } else if(apiTrx.API_Name__c.equalsIgnoreCase('serviceAddresses') && 
            apiTrx.API_Status_Code__c=='200'){ //BMP-3822
                wrapperClass=apiNameIsServiceAddresses(apiTrx,addrssMatch,bfTransSummToUpdate);
                apiTrx=wrapperClass.apiTrx;
                addrssMatch=wrapperClass.addrssMatch;
                bfTransSummToUpdate=wrapperClass.bfTransSummToUpdate;
            }
            //ESP-6823 performUnifiedQualProcess
            else if(apiTrx.API_Name__c.equalsIgnoreCase('performUnifiedQual')){
                wrapperClass=apiNameIsPerformUnifiedQual(apiTrx,addrssMatch,bfTransSummToUpdate);
                apiTrx=wrapperClass.apiTrx;
                addrssMatch=wrapperClass.addrssMatch;
                bfTransSummToUpdate=wrapperClass.bfTransSummToUpdate;
            } else if(apiTrx.API_Name__c.equalsIgnoreCase('FindAvailableServicesV4')){
                wrapperClass=apiNameIsFindAvailableServicesV4(apiTrx,addrssMatch,bfTransSummToUpdate);
                apiTrx=wrapperClass.apiTrx;
                addrssMatch=wrapperClass.addrssMatch;
                bfTransSummToUpdate=wrapperClass.bfTransSummToUpdate;
            } else if (apiTrx.API_Name__c.equalsIgnoreCase('GetOffers') && (apiTrx.Buyflow_Transaction_Summary_ID__c != null && String.isNotBlank(apiTrx.API_Response_JSON__c)
            && apiTrx.API_Response_JSON__c.startsWith('{'))){
                wrapperClass=apiNameIsGetOffers(apiTrx,bfTransSummToUpdate);
                apiTrx=wrapperClass.apiTrx;
                bfTransSummToUpdate=wrapperClass.bfTransSummToUpdate;
            }else if(apiTrx.API_Name__c.equalsIgnoreCase('BIWF_GetOffers') || apiTrx.API_Name__c.equalsIgnoreCase('BIWF_GetOffers_SFCC')){
                wrapperClass=apiNameIsBIWFGetOffers(apiTrx,bfTransSummToUpdate);
                apiTrx=wrapperClass.apiTrx;
                bfTransSummToUpdate=wrapperClass.bfTransSummToUpdate;
            } else if(apiTrx.API_Name__c.equalsIgnoreCase('serviceAddressesValidationsO2') || apiTrx.API_Name__c.equalsIgnoreCase('O2ServiceAddresses')){
                try{
                    addrssMatch = handleO2ServiceValidationResponse(apiTrx, addrssMatch,bfTransSummToUpdate);
                }catch(Exception e){
                    System.debug('handleO2ServiceValidationResponse Exception '+e.getCause()+', '+e.getMessage());
                    System.debug('handleO2ServiceValidationResponse Exception '+e.getLineNumber()+', '+e.getStackTraceString());
                }
            }
            apiTrx.Qual_Results__c = addrssMatch; 
            if(!apiTrx.API_Response_JSON__c.startsWith('<')){
                String respJson = apiTrx.API_Response_JSON__c;
                apiTrx.API_Response_JSON__c = String.isNotBlank(respJson) && JSON.serializePretty(JSON.deserializeUntyped(respJson)).length() < Integer.valueOf(System.Label.MAX_RESPONSE_LENGTH_ALLOWED) ?JSON.serializePretty(JSON.deserializeUntyped(respJson)):(String.isBlank(respJson)?'':'{"Error":"Response too Long"}');
            }
            
            //BMP-274 -- Storing Appointment reference number
            // ESP-6823 ReserveAppointmentProcess
            if (apiTrx.API_Name__c.equalsIgnoreCase('ReserveAppointment') && inputMap.get('AppointmentReferenceNumber')!=null && String.isNotBlank(String.valueOf(inputMap.get('AppointmentReferenceNumber')))){
                BF_Transactions_Summary__c summRec = bfTransSummToUpdate.get(apiTrx.Buyflow_Transaction_Summary_ID__c);
                if(summRec!=NULL){
                    summRec.Appointment_Order_ID__c = String.valueOf(inputMap.get('AppointmentReferenceNumber'));
                }else{
                    bfTransSummToUpdate.put(apiTrx.Buyflow_Transaction_Summary_ID__c, new BF_Transactions_Summary__c(
                        Id = apiTrx.Buyflow_Transaction_Summary_ID__c,
                        Appointment_Order_ID__c = String.valueOf(inputMap.get('AppointmentReferenceNumber'))
                    ));   
                }   
            }
            
            //BMP-4198 -- update status to success when atleast one retrieveAppointment callout was successful  
            //// ESP-6823 retrieveAppointmentProces
            if (apiTrx.API_Name__c.equalsIgnoreCase('retrieveAppointment') && transaction_record[0].Source__c == 'Martens' &&
                    String.isNotBlank(apiTrx.API_Response_JSON__c)){
                List retrieveApptsResp = (List) JSON.deserializeUntyped(apiTrx.API_Response_JSON__c);
                if (retrieveApptsResp != null) {
                    for (Object appt : retrieveApptsResp) {
                        Map apptsRespone = (Map)appt;
                        if (apptsRespone != null && apptsRespone.get('availableAppointment') != null) {
                            List oppts = (List)apptsRespone.get('availableAppointment');
                            if (oppts != null && !oppts.isEmpty() && oppts.get(0) != null) {
                                apiTrx.API_Status__c = 'success';  
                                break;
                            }
                        }
                    }
                }                
            }
            
        }                
        //QTAPO-14674 Storing Address Match on API Transaction -end
        TransactionWrapper wrap = new TransactionWrapper();
        wrap.apiTransactionList= apiTransactionList;
        if (!bfTransSummToUpdate.isEmpty()) {
            wrap.bfTransSummToUpdate = bfTransSummToUpdate.values();
        }
        return wrap; 
    }

Answer

Pseudo Code for Processing API Transactions

Overview

This pseudo code represents the logic to process a list of API transactions (apiTransactionList) by evaluating each transaction based on its API name. It updates a summary record map and manages responses accordingly.

Data Structures

  • apiTransactionList: List of API Transactions to process.
  • inputMap: Input parameters provided for transaction processing.
  • transaction_record: List holding transaction summaries.
  • bfTransSummToUpdate: Map to track transactions that need updating.

Function Definition

Define the function to process API transactions:

Function processAPITransactions(apiTransactionList, inputMap, transaction_record) 
    Initialize bfTransSummToUpdate as empty map
    Initialize wrapperClass as new WrapperClassForProcessAPITransactions()

    For each apiTrx in apiTransactionList do
        Initialize addrssMatch to NULL

        If apiTrx.API_Name equals SERVICEADDDRESSVALIDATIONS then
            Call function apiNameIsServiceAddressValidations(apiTrx, addrssMatch, bfTransSummToUpdate)
            Update apiTrx, addrssMatch, and bfTransSummToUpdate with return values

        Else If apiTrx.API_Name equals 'AddressBusinessService' or 'SubmitByGeoAddressId' then
            addrssMatch = handleAddressBusinessService(apiTrx, addrssMatch)
            If apiTrx.API_Name equals 'AddressBusinessService' then
                If apiTrx.API_Response_JSON is not NULL 
                    And captureCompanyOnwerIdBMFlow(apiTrx.API_Response_JSON) is not NULL then
                    updateCompanyOwner(bfTransSummToUpdate, apiTrx)

        Else If apiTrx.API_Name equals 'serviceAddresses' AND apiTrx.API_Status_Code equals '200' then
            Call function apiNameIsServiceAddresses(apiTrx, addrssMatch, bfTransSummToUpdate)
            Update apiTrx, addrssMatch, and bfTransSummToUpdate with return values

        Else If apiTrx.API_Name equals 'performUnifiedQual' then
            Call function apiNameIsPerformUnifiedQual(apiTrx, addrssMatch, bfTransSummToUpdate)
            Update apiTrx, addrssMatch, and bfTransSummToUpdate with return values

        Else If apiTrx.API_Name equals 'FindAvailableServicesV4' then
            Call function apiNameIsFindAvailableServicesV4(apiTrx, addrssMatch, bfTransSummToUpdate)
            Update apiTrx, addrssMatch, and bfTransSummToUpdate with return values

        Else If apiTrx.API_Name equals 'GetOffers' then
            If apiTrx.Buyflow_Transaction_Summary_ID is not NULL 
                AND apiTrx.API_Response_JSON is valid JSON then
                Call function apiNameIsGetOffers(apiTrx, bfTransSummToUpdate)
                Update apiTrx and bfTransSummToUpdate with return values

        Else If apiTrx.API_Name equals 'BIWF_GetOffers' or 'BIWF_GetOffers_SFCC' then
            Call function apiNameIsBIWFGetOffers(apiTrx, bfTransSummToUpdate)
            Update apiTrx and bfTransSummToUpdate with return values

        Else If apiTrx.API_Name equals 'serviceAddressesValidationsO2' or 'O2ServiceAddresses' then
            Try 
                addrssMatch = handleO2ServiceValidationResponse(apiTrx, addrssMatch, bfTransSummToUpdate)
            Catch Exception e 
                Log exception details

        End If

        apiTrx.Qual_Results = addrssMatch 
        Validate API Response JSON and handle length restrictions

        If apiTrx.API_Name equals 'ReserveAppointment' then
            updateAppointmentReference(bfTransSummToUpdate, apiTrx, inputMap)

        If apiTrx.API_Name equals 'retrieveAppointment' then
            updateTransactionStatus(apiTrx, transaction_record)

    End For

    Prepare TransactionWrapper for return
    wrap.apiTransactionList = apiTransactionList
    If bfTransSummToUpdate is not empty then 
        wrap.bfTransSummToUpdate = values of bfTransSummToUpdate

    Return wrap
End Function

Helper Functions

Update Company Owner

Function updateCompanyOwner(bfTransSummToUpdate, apiTrx)
    Retrieve summRec = bfTransSummToUpdate.get(apiTrx.Buyflow_Transaction_Summary_ID)
    If summRec is not NULL then
        summRec.CompanyOwnerId = captureCompanyOnwerIdBMFlow(apiTrx.API_Response_JSON)
    Else
        Create new BF_Transactions_Summary entry in bfTransSummToUpdate with company owner ID
    End If
End Function

Update Appointment Reference

Function updateAppointmentReference(bfTransSummToUpdate, apiTrx, inputMap)
    Retrieve summRec = bfTransSummToUpdate.get(apiTrx.Buyflow_Transaction_Summary_ID)
    If summRec is not NULL then
        summRec.Appointment_Order_ID = inputMap['AppointmentReferenceNumber']
    Else
        Create new BF_Transactions_Summary entry in bfTransSummToUpdate with appointment ID
    End If
End Function

Update Transaction Status

Function updateTransactionStatus(apiTrx, transaction_record)
    If transaction_record[0].Source equals 'Martens' AND apiTrx.API_Response_JSON is not blank then
        Deserialize apiTrx.API_Response_JSON into retrieveApptsResp
        For each appt in retrieveApptsResp do
            Check if appointment is available
            If available then
                Set apiTrx.API_Status to 'success'
                Break
            End If
        End For
    End If
End Function

Summary

This pseudo code structure highlights the processing flow, key decision points, and modular helper functions involved in processing API transactions while updating transaction summaries accordingly. The code is documented for clarity in understanding its purpose and functionality.

Create your Thread using our flexible tools, share it with friends and colleagues.

Your current query will become the main foundation for the thread, which you can expand with other tools presented on our platform. We will help you choose tools so that your thread is structured and logically built.

Description

This pseudo code outlines the process for handling a list of API transactions, including updating summaries and managing responses based on specific API names. It features modular functions for updating company owners, appointment references, and transaction statuses.