cancel
Showing results for 
Search instead for 
Did you mean: 

CIM response is slow, then normal

Hi All.  Just wondering if anyone else sees this behavior. I have a page that calls getCustomerProfileRequest and displays the payment profiles. (I'm using AuthnetXML.class.php.)  If I have called that page within the last few minutes, it seems to come up again pretty fast -- about 1 second.  However, the first time the page is called, or after waiting more than, say, ten minutes (I haven't accurately timed it), the page takes about 10 seconds to display.  I get the same results whether calling my sandbox account or the real merchant account.

 

Has anyone else experienced this?  Any theories as to why?  Thanks.

alanm123
Contributor
1 REPLY 1

Here's the only CIM-related code that runs on the page. It's the only code that's different from my other (fast) pages. I can't find any obvious problem with it. But maybe I'm doing something wrong.

 

$cimArray holds the user's CIM data, if any. If not, it's an empty array.

$cimArray['cim_id'] would be the user's CustomerProfileId.

 

 

 

## fn to generate authnetxml object with my login, transkey:
function newAuthNetXML() {
   $xml = new AuthnetXML(
      AUTHNET_LOGIN,
      AUTHNET_TRANSKEY,
      AUTHNET_USE_SANDBOX
   );
   return $xml;
}

 

function get_Customer_XML($cim_id) {
   if(!$cim_id) return '';
   $xml = newAuthNetXML();
   $idArray = array('customerProfileId'=>$cim_id);
   $xml->getCustomerProfileRequest($idArray);
   return $xml;
}

 

 

if(count($cimArray)){
   // tp_cim record found
   $cust = get_Customer_XML($cimArray['cim_id']); // returns the authnet cim xml response object
   if ($cust) {
      // there is a matching authnet cim customer profile
    if($cust->profile->paymentProfiles) {
      $data['cc_info_on_file'] = true;
      $data['cc_number_on_file'] = getCurrentCcNumber($cust->profile->paymentProfiles);
      $data['cc_profile_id'] = getCurrentCcProfileId($cust->profile->paymentProfiles);
      //exit($cust);
      //$data['paymentProfiles'] = $cust->profile->paymentProfiles;
      // if it doesn't match the current record, fix it:
      if($data['cc_profile_id'] != $cimArray['payment_profile_id']) {
        $tmpArray=array('payment_profile_id' => $data['cc_profile_id']);
        updateExistingRecord('tp_cim', currentUserID(), $tmpArray);
      }
    }
    else {
      // cim record exists, but no credit card info available.
      // make sure our working record reflects this: remove paymentprofile id, set auto-fund=0, amount=0
      $new_cim_info = array('auto_refill'=>0,'auto_refill_amount'=>0,'payment_profile_id'=>'');
      array_merge($cimArray, $new_cim_info); // uses new values in the current tp_cim array
      updateExistingRecord('tp_cim', currentUserID(), $new_cim_info); // updates the database
    }
  } else {
    // our record is invalid. The cim_id was not found in our authnet account.
    $cimArray = array();
    // but let's not alter our records, since it could be a temporary cim connection glitch.
  }
}
else {
  // no tp_cim record found. Values will be initialized in the javascript.
}

alanm123
Contributor