sdk-php icon indicating copy to clipboard operation
sdk-php copied to clipboard

Name cannot begin with the '0' character, hexadecimal value 0x30.

Open deep12650 opened this issue 11 years ago • 2 comments

Hello Team,

I am facing this issue and am not able to fix it. can you guys please suggest me why is it showing error. This code creates Customer profile ID, Payment Profile ID and saving address successfully but when i make transaction it give error. Please help me. Thanks

My Code:

   $customerProfile = new AuthorizeNetCustomer;
   $customerProfile->description = "Description of customer";
   $customerProfile->merchantCustomerId = $user->id;
   $customerProfile->email = $user->email;
   $address = new AuthorizeNetAddress;
   $address->firstName = "john";
   $address->lastName = "Doe";
   $address->phoneNumber = "555-555-5555";
   $customerProfile->shipToList[] = $address;

   $paymentProfile = new AuthorizeNetPaymentProfile;
   $paymentProfile->customerType = "individual";
   $paymentProfile->payment->creditCard->cardNumber = "4111111111111111";
   $paymentProfile->payment->creditCard->expirationDate = "2017-10";
   $customerProfile->paymentProfiles[] = $paymentProfile;

   $request = new AuthorizeNetCIM;
   $response = $request->createCustomerProfile($customerProfile);
   $new_customer_id = $response->xml->customerProfileId;
   $paymentProfileId = $response->xml->customerPaymentProfileIdList->numericString;
   $customerAddressId = $response->xml->customerShippingAddressIdList->numericString;

   $transaction = new AuthorizeNetTransaction;
   $transaction->amount = "9.79";
   $transaction->customerProfileId = $new_customer_id;
   $transaction->customerPaymentProfileId = $paymentProfileId;
   $transaction->customerShippingAddressId = $customerAddressId;

   $transaction->cardCode = "111";
   $response = $request->createCustomerProfileTransaction("AuthCapture", $transaction);
   print_r($response); 

Error -

[code] => E00003 [text] => Name cannot begin with the '0' character, hexadecimal value 0x30. Line 2, position 291.

deep12650 avatar Jul 06 '15 17:07 deep12650

The problem here is the way that values are returned out of a simpleXML element. Reading a parameter such as "$response->xml->customerProfileId" still returns a simpleXML element by default, but the $transaction->customerProfileId is looking for a string.

The resolution to this is simply to cast these particular XML elements as strings. You could do this either when reading them from the XML or when entering them into the transaction object. Personally, I would recommend doing it when you read them out of the XML. It would just be a simple change as shown in the three lines below:

 $new_customer_id = (string) $response->xml->customerProfileId;
 $paymentProfileId = (string) $response->xml->customerPaymentProfileIdList->numericString;
 $customerAddressId = (string) $response->xml->customerShippingAddressIdList->numericString;

TrevorW avatar Jul 06 '15 23:07 TrevorW

Closing this one as no additional response.

brianmc avatar Oct 16 '15 05:10 brianmc