When I try and create a new CIM using the test credit card number on a live account, I expect to get an invalid credit number response. Instead, I am getting E00027There is one or more missing or invalid required fields.
I think somehow I am submitting as TEST instead of LIVE.
AuthorizeNetCIM_Response Object ( [xml] => SimpleXMLElement Object ( [messages] => SimpleXMLElement Object ( [resultCode] => Error [message] => SimpleXMLElement Object ( [code] => E00027 [text] => There is one or more missing or invalid required fields. ) ) [customerPaymentProfileIdList] => SimpleXMLElement Object ( ) [customerShippingAddressIdList] => SimpleXMLElement Object ( ) [validationDirectResponseList] => SimpleXMLElement Object ( [string] => 3,1,290,There is one or more missing or invalid required fields.,,P,0,none,Test transaction for ValidateCustomerPaymentProfile.,0.00,CC,auth_only,51797,,,,,,,,,,,me@mydomain,,,,,,,,,0.00,0.00,0.00,FALSE,none,F68A9C87C1E1472521704EF38C21F647,,,,,,,,,,,,,XXXX1111,Visa,,,,,,,,,,,,,,,, ) ) [response] => ?ErrorE00027There is one or more missing or invalid required fields.3,1,290,There is one or more missing or invalid required fields.,,P,0,none,Test transaction for ValidateCustomerPaymentProfile.,0.00,CC,auth_only,51797,,,,,,,,,,,me@mydomain,,,,,,,,,0.00,0.00,0.00,FALSE,none,F68A9C87C1E1472521704EF38C21F647,,,,,,,,,,,,,XXXX1111,Visa,,,,,,,,,,,,,,,, [xpath_xml] => SimpleXMLElement Object ( [messages] => SimpleXMLElement Object ( [resultCode] => Error [message] => SimpleXMLElement Object ( [code] => E00027 [text] => There is one or more missing or invalid required fields. ) ) [customerPaymentProfileIdList] => SimpleXMLElement Object ( ) [customerShippingAddressIdList] => SimpleXMLElement Object ( ) [validationDirectResponseList] => SimpleXMLElement Object ( [string] => 3,1,290,There is one or more missing or invalid required fields.,,P,0,none,Test transaction for ValidateCustomerPaymentProfile.,0.00,CC,auth_only,51797,,,,,,,,,,,me@mydomain,,,,,,,,,0.00,0.00,0.00,FALSE,none,F68A9C87C1E1472521704EF38C21F647,,,,,,,,,,,,,XXXX1111,Visa,,,,,,,,,,,,,,,, ) ) ) 1 |
Using the SDK, I updated the class to see what happens when I make Sandbox URL the live url as I was getting an error. I also updated the class to make sure it defaults to live mode.
<?php /** * Easily interact with the Authorize.Net CIM XML API. * * @package AuthorizeNet * @subpackage AuthorizeNetCIM * @link http://www.authorize.net/support/CIM_XML_guide.pdf CIM XML Guide */ /** * A class to send a request to the CIM XML API. * * @package AuthorizeNet * @subpackage AuthorizeNetCIM */ class AuthorizeNetCIM extends AuthorizeNetRequest { const LIVE_URL = "https://api.authorize.net/xml/v1/request.api"; // const SANDBOX_URL = "https://apitest.authorize.net/xml/v1/request.api"; const SANDBOX_URL = "https://api.authorize.net/xml/v1/request.api"; private $_xml; private $_refId = false; private $_validationMode = "liveMode"; // "none","testMode","liveMode" private $_extraOptions; private $_transactionTypes = array( 'AuthOnly', 'AuthCapture', 'CaptureOnly', 'PriorAuthCapture', 'Refund', 'Void', ); /** * Optional. Used if the merchant wants to set a reference ID. * * @param string $refId */ public function setRefId($refId) { $this->_refId = $refId; } /** * Create a customer profile. * * @param AuthorizeNetCustomer $customerProfile * @param string $validationMode * * @return AuthorizeNetCIM_Response */ public function createCustomerProfile($customerProfile, $validationMode = "liveMode") { $this->_validationMode = $validationMode; $this->_constructXml("createCustomerProfileRequest"); $profile = $this->_xml->addChild("profile"); $this->_addObject($profile, $customerProfile); return $this->_sendRequest(); } /** * Create a customer payment profile. * * @param int $customerProfileId * @param AuthorizeNetPaymentProfile $paymentProfile * @param string $validationMode * * @return AuthorizeNetCIM_Response */ public function createCustomerPaymentProfile($customerProfileId, $paymentProfile, $validationMode = "liveMode") { $this->_validationMode = $validationMode; $this->_constructXml("createCustomerPaymentProfileRequest"); $this->_xml->addChild("customerProfileId", $customerProfileId); $profile = $this->_xml->addChild("paymentProfile"); $this->_addObject($profile, $paymentProfile); return $this->_sendRequest(); } /** * Create a shipping address. * * @param int $customerProfileId * @param AuthorizeNetAddress $shippingAddress * * @return AuthorizeNetCIM_Response */ public function createCustomerShippingAddress($customerProfileId, $shippingAddress) { $this->_constructXml("createCustomerShippingAddressRequest"); $this->_xml->addChild("customerProfileId", $customerProfileId); $address = $this->_xml->addChild("address"); $this->_addObject($address, $shippingAddress); return $this->_sendRequest(); } /** * Create a transaction. * * @param string $transactionType * @param AuthorizeNetTransaction $transaction * @param string $extraOptionsString * * @return AuthorizeNetCIM_Response */ public function createCustomerProfileTransaction($transactionType, $transaction, $extraOptionsString = "") { $this->_constructXml("createCustomerProfileTransactionRequest"); $transactionParent = $this->_xml->addChild("transaction"); $transactionChild = $transactionParent->addChild("profileTrans" . $transactionType); $this->_addObject($transactionChild, $transaction); $this->_extraOptions = $extraOptionsString . "x_encap_char=|"; return $this->_sendRequest(); } /** * Delete a customer profile. * * @param int $customerProfileId * * @return AuthorizeNetCIM_Response */ public function deleteCustomerProfile($customerProfileId) { $this->_constructXml("deleteCustomerProfileRequest"); $this->_xml->addChild("customerProfileId", $customerProfileId); return $this->_sendRequest(); } /** * Delete a payment profile. * * @param int $customerProfileId * @param int $customerPaymentProfileId * * @return AuthorizeNetCIM_Response */ public function deleteCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId) { $this->_constructXml("deleteCustomerPaymentProfileRequest"); $this->_xml->addChild("customerProfileId", $customerProfileId); $this->_xml->addChild("customerPaymentProfileId", $customerPaymentProfileId); return $this->_sendRequest(); } /** * Delete a shipping address. * * @param int $customerProfileId * @param int $customerAddressId * * @return AuthorizeNetCIM_Response */ public function deleteCustomerShippingAddress($customerProfileId, $customerAddressId) { $this->_constructXml("deleteCustomerShippingAddressRequest"); $this->_xml->addChild("customerProfileId", $customerProfileId); $this->_xml->addChild("customerAddressId", $customerAddressId); return $this->_sendRequest(); } /** * Get all customer profile ids. * * @return AuthorizeNetCIM_Response */ public function getCustomerProfileIds() { $this->_constructXml("getCustomerProfileIdsRequest"); return $this->_sendRequest(); } /** * Get a customer profile. * * @param int $customerProfileId * * @return AuthorizeNetCIM_Response */ public function getCustomerProfile($customerProfileId) { $this->_constructXml("getCustomerProfileRequest"); $this->_xml->addChild("customerProfileId", $customerProfileId); return $this->_sendRequest(); } /** * Get a payment profile. * * @param int $customerProfileId * @param int $customerPaymentProfileId * * @return AuthorizeNetCIM_Response */ public function getCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId) { $this->_constructXml("getCustomerPaymentProfileRequest"); $this->_xml->addChild("customerProfileId", $customerProfileId); $this->_xml->addChild("customerPaymentProfileId", $customerPaymentProfileId); return $this->_sendRequest(); } /** * Get a shipping address. * * @param int $customerProfileId * @param int $customerAddressId * * @return AuthorizeNetCIM_Response */ public function getCustomerShippingAddress($customerProfileId, $customerAddressId) { $this->_constructXml("getCustomerShippingAddressRequest"); $this->_xml->addChild("customerProfileId", $customerProfileId); $this->_xml->addChild("customerAddressId", $customerAddressId); return $this->_sendRequest(); } /** * Update a profile. * * @param int $customerProfileId * @param AuthorizeNetCustomer $customerProfile * * @return AuthorizeNetCIM_Response */ public function updateCustomerProfile($customerProfileId, $customerProfile) { $this->_constructXml("updateCustomerProfileRequest"); $customerProfile->customerProfileId = $customerProfileId; $profile = $this->_xml->addChild("profile"); $this->_addObject($profile, $customerProfile); return $this->_sendRequest(); } /** * Update a payment profile. * * @param int $customerProfileId * @param int $customerPaymentProfileId * @param AuthorizeNetPaymentProfile $paymentProfile * @param string $validationMode * * @return AuthorizeNetCIM_Response */ public function updateCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId, $paymentProfile, $validationMode = "liveMode") { $this->_validationMode = $validationMode; $this->_constructXml("updateCustomerPaymentProfileRequest"); $this->_xml->addChild("customerProfileId", $customerProfileId); $paymentProfile->customerPaymentProfileId = $customerPaymentProfileId; $profile = $this->_xml->addChild("paymentProfile"); $this->_addObject($profile, $paymentProfile); return $this->_sendRequest(); } /** * Update a shipping address. * * @param int $customerProfileId * @param int $customerShippingAddressId * @param AuthorizeNetAddress $shippingAddress * * @return AuthorizeNetCIM_Response */ public function updateCustomerShippingAddress($customerProfileId, $customerShippingAddressId, $shippingAddress) { $this->_constructXml("updateCustomerShippingAddressRequest"); $this->_xml->addChild("customerProfileId", $customerProfileId); $shippingAddress->customerAddressId = $customerShippingAddressId; $sa = $this->_xml->addChild("address"); $this->_addObject($sa, $shippingAddress); return $this->_sendRequest(); } /** * Update the status of an existing order that contains multiple transactions with the same splitTenderId. * * @param int $splitTenderId * @param string $splitTenderStatus * * @return AuthorizeNetCIM_Response */ public function updateSplitTenderGroup($splitTenderId, $splitTenderStatus) { $this->_constructXml("updateSplitTenderGroupRequest"); $this->_xml->addChild("splitTenderId", $splitTenderId); $this->_xml->addChild("splitTenderStatus", $splitTenderStatus); return $this->_sendRequest(); } /** * Validate a customer payment profile. * * @param int $customerProfileId * @param int $customerPaymentProfileId * @param int $customerShippingAddressId * @param int $cardCode * @param string $validationMode * * @return AuthorizeNetCIM_Response */ public function validateCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId, $customerShippingAddressId, $cardCode, $validationMode = "liveMode") { $this->_validationMode = $validationMode; $this->_constructXml("validateCustomerPaymentProfileRequest"); $this->_xml->addChild("customerProfileId",$customerProfileId); $this->_xml->addChild("customerPaymentProfileId",$customerPaymentProfileId); $this->_xml->addChild("customerShippingAddressId",$customerShippingAddressId); $this->_xml->addChild("cardCode",$cardCode); return $this->_sendRequest(); } /** * Get hosted profile page request token * * @param string $customerProfileId * @param mixed $settings * * @return AuthorizeNetCIM_Response */ public function getHostedProfilePageRequest($customerProfileId, $settings=0) { $this->_constructXml("getHostedProfilePageRequest"); $this->_xml->addChild("customerProfileId", $customerProfileId); if (!empty($settings)) { $hostedSettings = $this->_xml->addChild("hostedProfileSettings"); foreach ($settings as $key => $val) { $setting = $hostedSettings->addChild("setting"); $setting->addChild("settingName", $key); $setting->addChild("settingValue", $val); } } return $this->_sendRequest(); } /** * @return string */ protected function _getPostUrl() { return ($this->_sandbox ? self::SANDBOX_URL : self::LIVE_URL); } /** * * * @param string $response * * @return AuthorizeNetCIM_Response */ protected function _handleResponse($response) { return new AuthorizeNetCIM_Response($response); } /** * Prepare the XML post string. */ protected function _setPostString() { ($this->_validationMode != "none" ? $this->_xml->addChild('validationMode',$this->_validationMode) : ""); $this->_post_string = $this->_xml->asXML(); // Add extraOptions CDATA if ($this->_extraOptions) { $this->_xml->addChild("extraOptions"); $this->_post_string = str_replace(array("<extraOptions></extraOptions>","<extraOptions/>"),'<extraOptions><![CDATA[' . $this->_extraOptions . ']]></extraOptions>', $this->_xml->asXML()); $this->_extraOptions = false; } // Blank out our validation mode, so that we don't include it in calls that // don't use it. $this->_validationMode = "none"; } /** * Start the SimpleXMLElement that will be posted. * * @param string $request_type The action to be performed. */ private function _constructXml($request_type) { $string = '<?xml version="1.0" encoding="utf-8"?><'.$request_type.' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"></'.$request_type.'>'; $this->_xml = @new SimpleXMLElement($string); $merchant = $this->_xml->addChild('merchantAuthentication'); $merchant->addChild('name',$this->_api_login); $merchant->addChild('transactionKey',$this->_transaction_key); ($this->_refId ? $this->_xml->addChild('refId',$this->_refId) : ""); } /** * Add an object to an SimpleXMLElement parent element. * * @param SimpleXMLElement $destination The parent element. * @param Object $object An object, array or value. */ private function _addObject($destination, $object) { $array = (array)$object; foreach ($array as $key => $value) { if ($value && !is_object($value)) { if (is_array($value) && count($value)) { foreach ($value as $index => $item) { $items = $destination->addChild($key); $this->_addObject($items, $item); } } else { $destination->addChild($key,$value); } } elseif (is_object($value) && self::_notEmpty($value)) { $dest = $destination->addChild($key); $this->_addObject($dest, $value); } } } /** * Checks whether an array or object contains any values. * * @param Object $object * * @return bool */ private static function _notEmpty($object) { $array = (array)$object; foreach ($array as $key => $value) { if ($value && !is_object($value)) { return true; } elseif (is_object($value)) { if (self::_notEmpty($value)) { return true; } } } return false; } } /** * A class to parse a response from the CIM XML API. * * @package AuthorizeNet * @subpackage AuthorizeNetCIM */ class AuthorizeNetCIM_Response extends AuthorizeNetXMLResponse { /** * @return AuthorizeNetAIM_Response */ public function getTransactionResponse() { return new AuthorizeNetAIM_Response($this->_getElementContents("directResponse"), ",", "|", array()); } /** * @return array Array of AuthorizeNetAIM_Response objects for each payment profile. */ public function getValidationResponses() { $responses = (array)$this->xml->validationDirectResponseList; $return = array(); foreach ((array)$responses["string"] as $response) { $return[] = new AuthorizeNetAIM_Response($response, ",", "", array()); } return $return; } /** * @return AuthorizeNetAIM_Response */ public function getValidationResponse() { return new AuthorizeNetAIM_Response($this->_getElementContents("validationDirectResponse"), ",", "|", array()); } /** * @return array */ public function getCustomerProfileIds() { $ids = (array)$this->xml->ids; return $ids["numericString"]; } /** * @return array */ public function getCustomerPaymentProfileIds() { $ids = (array)$this->xml->customerPaymentProfileIdList; return $ids["numericString"]; } /** * @return array */ public function getCustomerShippingAddressIds() { $ids = (array)$this->xml->customerShippingAddressIdList; return $ids["numericString"]; } /** * @return string */ public function getCustomerAddressId() { return $this->_getElementContents("customerAddressId"); } /** * @return string */ public function getCustomerProfileId() { return $this->_getElementContents("customerProfileId"); } /** * @return string */ public function getPaymentProfileId() { return $this->_getElementContents("customerPaymentProfileId"); } }
This is the code that is creating the CIM profile
if(isset($_POST)){ if($_POST["sitepass"]=sitepass and $_POST["action"]="newCIM"){ // first check to see if a previous profile exists. If it does, then delete it and update the database. if(isset($_POST["currentCIM"])){ if (strlen($_POST["currentCIM"]) > 5){ $old_CIM = $_POST["currentCIM"]; $request = new AuthorizeNetCIM; $request->deleteCustomerProfile($old_CIM); UpdateContactCIM( $_POST["contactid"],"0","0","0" ,$db); } } if(isset($_POST["removeProfile"])){ if ($_POST["removeProfile"]="1"){ $old_CIM = $_POST["currentCIM"]; $request = new AuthorizeNetCIM; $request->deleteCustomerProfile($old_CIM); UpdateContactCIM( $_POST["contactid"],"0","0","0" ,$db); die("1|Profile Removed"); } } $contact_id = $_POST["contactid"]; $contact_first = $_POST["firstname"]; $contact_last = $_POST["lastname"]; $contact_address = $_POST["address"]; $contact_city = $_POST["city"]; $contact_st = $_POST["st"]; $contact_zip = $_POST["zip"]; $contact_email = $_POST["email"]; $contact_phone = $_POST["phone"]; $contact_card = $_POST["creditcard"]; $contact_card_yr = $_POST["year"]; $contact_card_mo = $_POST["month"]; $contact_name = $contact_first." ".$contact_last; $exp_date = $contact_card_yr."-".$contact_card_mo; $request = new AuthorizeNetCIM; // Create new customer profile $customerProfile = new AuthorizeNetCustomer; $customerProfile->description = $contact_name; $customerProfile->merchantCustomerId = $contact_id; $customerProfile->email = $contact_email; // Add payment profile. $paymentProfile = new AuthorizeNetPaymentProfile; $paymentProfile->customerType = "individual"; $paymentProfile->payment->creditCard->cardNumber = $contact_card; $paymentProfile->payment->creditCard->expirationDate = $exp_date; $customerProfile->paymentProfiles[] = $paymentProfile; $response = $request->createCustomerProfile($customerProfile); die(print_r($response)); $validationResponses = $response->getValidationResponses(); foreach ($validationResponses as $vr) { echo $vr->approved; } //profile/paymentProfiles/customerPaymentProfileId $arrProfile = $response->xpath('customerPaymentProfileIdList/numericString'); if ($arrProfile){ $paymentProfileId = $arrProfile[0]; // get the payment id } else { $paymentProfileId = 0; } if ($response->isOk()) { $customerProfileId = $response->getCustomerProfileId(); $address = new AuthorizeNetAddress; $address->firstName = $contact_first; $address->lastName = $contact_last; //$address->company = "John Doe Company"; $address->address = $contact_address; $address->city = $contact_city; $address->state = $contact_st; $address->zip = $contact_zip; //$address->country = "USA"; $address->phoneNumber = $contact_phone; //$address->faxNumber = "555-555-5556"; $response = $request->createCustomerShippingAddress($customerProfileId, $address); $customerAddressId = $response->getCustomerAddressId(); //$customerPaymentID = $response->getCustomerPaymentProfileIds(); // Update database with profile id UpdateContactCIM($contact_id,$customerProfileId,$customerAddressId,$paymentProfileId ,$db); // Create Payment echo "1|".$customerProfileId."-".$customerAddressId." - ".$paymentProfileId. "- "; } else { echo "0|".$response->xml->messages->message->text; } } else { echo "0|Internal Error-create profile"; } }
In my config file I have the log in an pass set to the live credentials.
define("AUTHORIZENET_API_LOGIN_ID", $login_id); define("AUTHORIZENET_TRANSACTION_KEY", $trans_key);
12-02-2014 03:24 PM
Login into your merchant account
Account Settings - Payment Forms - Form Fields - Check to see which fields is checked as required.
And the Doc said 290 is
12-02-2014 04:04 PM