cancel
Showing results for 
Search instead for 
Did you mean: 

E00003 The element 'creditCard' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has invalid c

We have implemented authorize.net on our site. Some users pay successfully via their card. But some users are getting problems. Tried to solve this but there is not thread like this error message.

 

Here is the full error message -

 

E00003 The element 'creditCard' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has invalid child element 'expirationDate' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'. List of possible elements expected: 'cardNumber' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'.

 

Here is my php code - 

 

public function chargeCreditCard($card_number,$cvv_code,$expiration_date,$amount, $course_title, $country_name, $registration_code, $submitted_data)
{
// Common setup for API credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName(config('services.authorize.user'));
$merchantAuthentication->setTransactionKey(config('services.authorize.key'));

$refId = 'ref'.time();
// Create the payment data for a credit card
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber($card_number);
$creditCard->setExpirationDate($expiration_date);
$creditCard->setCardCode($cvv_code);

$paymentOne = new AnetAPI\PaymentType();
$paymentOne->setCreditCard($creditCard);
// Create a order
$order = new AnetAPI\OrderType();
$order->setInvoiceNumber($registration_code);
$order->setDescription($course_title." "."course registration");

// Set the customer's Bill To address
$customerAddress = new AnetAPI\CustomerAddressType();
$customerAddress->setFirstName($submitted_data->first_name);
$customerAddress->setLastName($submitted_data->last_name);
$customerAddress->setCompany($submitted_data->organization ?? '');
$customerAddress->setAddress($submitted_data->address);
$customerAddress->setCity($submitted_data->city);
$customerAddress->setState($submitted_data->state);
$customerAddress->setZip($submitted_data->zip);
$customerAddress->setCountry($country_name);
$customerAddress->setPhoneNumber($submitted_data->phone);

$customerData = new AnetAPI\CustomerDataType();
$customerData->setEmail($submitted_data->email);

// Set the customer's Bill To address
$shipto = new AnetAPI\NameAndAddressType();
$shipto->setFirstName($submitted_data->first_name);
$shipto->setLastName($submitted_data->last_name);
$shipto->setCompany($submitted_data->organization ?? '');
$shipto->setAddress($submitted_data->address);
$shipto->setCity($submitted_data->city);
$shipto->setState($submitted_data->state);
$shipto->setZip($submitted_data->zip);
$shipto->setCountry($country_name);

// Add some merchant defined fields.
$merchantDefinedField1 = new AnetAPI\UserFieldType();
$merchantDefinedField1->setName("x_ship_to_phone");
$merchantDefinedField1->setValue($submitted_data->phone);
$merchantDefinedField2 = new AnetAPI\UserFieldType();
$merchantDefinedField2->setName("x_ship_to_email");
$merchantDefinedField2->setValue($submitted_data->email);
$merchantDefinedField3 = new AnetAPI\UserFieldType();
$merchantDefinedField3->setName("cc_number");
$merchantDefinedField3->setValue('XXXX-'.substr($card_number,-4));
$merchantDefinedField4 = new AnetAPI\UserFieldType();
$merchantDefinedField4->setName("cc_expdate");
$merchantDefinedField4->setValue($expiration_date);
$merchantDefinedField5 = new AnetAPI\UserFieldType();
$merchantDefinedField5->setName("cc_emailid");
$merchantDefinedField5->setValue($submitted_data->email);

// Create a transaction
$transactionRequestType = new AnetAPI\TransactionRequestType();
$transactionRequestType->setTransactionType("authCaptureTransaction");
$transactionRequestType->setAmount($amount);
$transactionRequestType->setOrder($order);
$transactionRequestType->setPayment($paymentOne);
$transactionRequestType->setBillTo($customerAddress);
$transactionRequestType->setShipTo($shipto);
$transactionRequestType->setCustomer($customerData);
$transactionRequestType->addToUserFields($merchantDefinedField1);
$transactionRequestType->addToUserFields($merchantDefinedField2);
$transactionRequestType->addToUserFields($merchantDefinedField3);
$transactionRequestType->addToUserFields($merchantDefinedField4);
$transactionRequestType->addToUserFields($merchantDefinedField5);

$request = new AnetAPI\CreateTransactionRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setRefId($refId);
$request->setTransactionRequest($transactionRequestType);
$controller = new AnetController\CreateTransactionController($request);

if (env('AUTHORIZE_MODE') != 'sandbox'){
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION);

} else {
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
}

if ($response != null)
{
$tresponse = $response->getTransactionResponse();
if (($tresponse != null) && ($tresponse->getResponseCode()=="1"))
{
return [
'success' => true,
'transaction_id' => $tresponse->getTransId(),
'payment_status' => Registrant::PAYMENT_PAID
];
}elseif(($tresponse != null) && ($tresponse->getResponseCode()=="4")){
return [
'success' => true,
'transaction_id' => $tresponse->getTransId(),
'payment_status' => Registrant::PAYMENT_PENDING
];
}
else
{
$tresponse = $response->getTransactionResponse();

if ($tresponse != null && $tresponse->getErrors() != null) {
echo " Error Code : " . $error_code = $tresponse->getErrors()[0]->getErrorCode() . "\n";
echo " Error Message : " . $message = $tresponse->getErrors()[0]->getErrorText() . "\n";
} else {
echo " Error Code : " . $error_code = $response->getMessages()->getMessage()[0]->getCode() . "\n";
echo " Error Message : " . $message = $response->getMessages()->getMessage()[0]->getText() . "\n";
}
return [
'success' => false,
'message' => $error_code.' '.$message
];
}
}
else
{
return [
'success' => false
];
}
}

 

I will be so much grateful to you if you help me please. We already missed some users payment and getting bad reputation of the website.

mashpy
Member
5 REPLIES 5

I would assume something is wrong with $card_number going to the function.

kabutotx
Regular Contributor

No. Look at the message carefully. Something wrong on the expiredate. but what is wrong?

 

 

 

E00003 The element 'creditCard' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has invalid child element 'expirationDate' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'. List of possible elements expected: 'cardNumber' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'.

I have seen this message if a field is missing or out of order and it hits on the next field. For example it could be looking for cardNimber and it finds exporationDate instead.

 

Can the sdk log the xml it sends to see?

kabutotx
Regular Contributor

Can you say me how you solved this issue?

 Looking for the same issue.  Thanks for creating it. i got the solution.

oursainsburys
Member