function getCustomerProfile($params) { //Authorize.net CIM Credentials from CE plugin $myapilogin = $this->settings->get('plugin_authnetcim_Authorize.Net CIM API Login ID'); $mYtRaNsaCTiOnKEy = $this->settings->get('plugin_authnetcim_Authorize.Net CIM Transaction Key'); $sandbox = $this->settings->get('plugin_authnetcim_Authorize.Net CIM Test Mode'); $USE_DEVELOPMENT_SERVER = $sandbox ? AuthnetCIM::USE_DEVELOPMENT_SERVER : AuthnetCIM::USE_PRODUCTION_SERVER; $profile_id == ''; $Billing_Profile_ID = ''; $profile_id_array = array(); $user = new User($params['CustomerID']); if ($user->getCustomFieldsValue('Billing-Profile-ID', $Billing_Profile_ID) && $Billing_Profile_ID != '') { $profile_id_array = unserialize($Billing_Profile_ID); if (is_array($profile_id_array) && isset($profile_id_array['authnetcim'])) { $profile_id = $profile_id_array['authnetcim']; } } if ($profile_id == '') { // Create or get customer Authnet CIM profile $customerProfile = $this->createCustomerProfile($params); if ($customerProfile['error']) { return $customerProfile; } else { $profile_id = $customerProfile['profile_id']; } } try { $cim = new AuthnetCIM($myapilogin, $mYtRaNsaCTiOnKEy, $USE_DEVELOPMENT_SERVER); $cim->setParameter('customerProfileId', $profile_id); $cim->getCustomerProfile(); if ($cim->isSuccessful()) { $profile_id = $cim->getProfileID(); if (!is_array($profile_id_array)) { $profile_id_array = array(); } $profile_id_array['authnetcim'] = $profile_id; $user->updateCustomTag('Billing-Profile-ID', serialize($profile_id_array)); $user->save(); return array('error' => false, 'profile_id' => $profile_id, 'payment_profile_id' => $cim->getPaymentProfileId(), 'shipping_profile_id' => $cim->getCustomerAddressId()); } else { // If the profileID, paymentProfileId, or shippingAddressId for this request is not valid for this merchant, reset the id and try again. if ($cim->getCode() == 'E00040') { if (is_array($profile_id_array)) { unset($profile_id_array['authnetcim']); } else { $profile_id_array = array(); } $user->updateCustomTag('Billing-Profile-ID', serialize($profile_id_array)); $user->save(); return $this->getCustomerProfile($params); } return array('error' => true, 'detail' => $cim->getResponseSummary()); } } catch (AuthnetCIMException $e) { return array('error' => true, 'detail' => $e); } }