Может быть, кто-то может мне помочь с проблемой, с которой я сталкиваюсь в отношении объектов SimpleXML.
Я интегрируюсь с менеджером CIM authorize.net и отправляю в профиле клиента.Когда я отправил его, необработанный xml-ответ прошел через анализатор и превратился в объект SimpleXML.
Вот код, который используется для отправки запроса:
$content =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>".
"<createCustomerProfileRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">".
MerchantAuthenticationBlock().
"<profile>".
//"<merchantCustomerId>".$userInsertedId."</merchantCustomerId>". // Your own identifier for the customer.
"<description>'New User Purchase'</description>".
"<email>" . $_GET["email"] . "</email>".
"<paymentProfiles>".
"<billTo>".
"<firstName>".$_GET["firstname"]."</firstName>".
"<lastName>".$_GET["lastname"]."</lastName>".
"<address>".$_GET["street"]."</address>".
"<city>".$_GET["city"]."</city>".
"<state>".$_GET["state"]."</state>".
"<zip>".$_GET["zip"]."</zip>".
"<country>".$_GET["country"]."</country>".
"<phoneNumber>".$_GET["phone"]."</phoneNumber>".
"</billTo>".
"<payment>".
"<creditCard>".
"<cardNumber>".$_GET["number"]."</cardNumber>".
"<expirationDate>".$_GET["year"]."-".$_GET["month"]."</expirationDate>". // required format for API is YYYY-MM
"<cardCode>".$_GET["code"]."</cardCode>".
"</creditCard>".
"</payment>".
"</paymentProfiles>".
"</profile>".
"<validationMode>testMode</validationMode>".
"</createCustomerProfileRequest>";
$CCresponse = send_xml_request($content);
//echo($CCresponse);
$parsedresponse = parse_api_response($CCresponse);
function parse_api_response($content)
{
$parsedresponse = simplexml_load_string($content, "SimpleXMLElement", LIBXML_NOWARNING);
if ("Ok" != $parsedresponse->messages->resultCode)
{
echo "The operation failed with the following errors:<br>";
foreach ($parsedresponse->messages->message as $msg)
{
echo "[" . htmlspecialchars($msg->code) . "] " . htmlspecialchars($msg->text) . "<br>";
}
echo "<br>";
}
return $parsedresponse;
}
Когда я делаю следующее:
$parsedresponse = parse_api_response($CCresponse);
print_r($parsedresponse);
Я получаю следующий вывод:
SimpleXMLElement Object
(
[messages] => SimpleXMLElement Object
(
[resultCode] => Ok
[message] => SimpleXMLElement Object
(
[code] => I00001
[text] => Successful.
)
)
[customerProfileId] => 15642446
[customerPaymentProfileIdList] => SimpleXMLElement Object
(
[numericString] => 13865552
)
[customerShippingAddressIdList] => SimpleXMLElement Object
(
)
[validationDirectResponseList] => SimpleXMLElement Object
(
[string] => 1|1|1|(TESTMODE) This transaction has been approved.|000000|P|0|none|Test transaction for ValidateCustomerPaymentProfile.|1.00|CC|auth_only||*****|******||****|*******|******|******|USA|1234567890||email@email.com|none|none|none|none|none|none|none|none|0.00|0.00|0.00|FALSE|none|207BCBBF78E85CF174C87AE286B472D2|||||||||||||*******|*******||||||||||||||||
)
)
)
)
Итак, похоже, все работает.Но когда я пытаюсь углубиться в объект SimpleXML и сделаю следующее:
echo $code = (string) $parsedresponse->messages->resultCode;
Я получаю вывод «OkOk», кажется, что он работает поверх него дважды.Это сводит меня с ума, и я не могу понять, какого черта здесь происходит.Может кто-нибудь указать мне правильное направление здесь, чтобы я мог получить это работает?
Спасибо!