dadamssg87 Posted August 18, 2011 Share Posted August 18, 2011 I'm trying to figure out how to grab the last "customerPaymentProfileId" in return xml of authorize.net's api. There can be several customerPaymentProfileId's, i just want to grab the last one that appears. I'm good on executing the api call and getting the return xml and putting it in an $xml variable like so... <?php $xml = new SimpleXMLElement($response); $this->paymentProfileId = (int) $xml->customerPaymentProfileId; ?> I can get a single customerPaymentProfileId like i did above but I just don't know how to cycle through sections of the xml. I'd like to get all of the payment profiles in an array and then grab the last one in the array. You can see the full xml response on page 101-103 on the authnet api cim documentation here -> http://www.authorize.net/support/CIM_XML_guide.pdf or i've copied it below <?xml version="1.0" encoding="utf-8"?> <getCustomerProfileResponse xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> <messages> <resultCode>Ok</resultCode> <message> <code>I00001</code> <text>Successful.</text> </message> </messages> <profile> <merchantCustomerId>custId123</merchantCustomerId> <description>some description</description> <email>[email protected]</email> <customerProfileId>10000</customerProfileId> <paymentProfiles> <billTo> <firstName>John</firstName> <lastName>Doe</lastName> <company></company> <address>123 Main St.</address> <city>Bellevue</city> <state>WA</state> <zip>98004</zip> <country>USA</country> <phoneNumber>000-000-0000</phoneNumber> <faxNumber></faxNumber> </billTo> <customerPaymentProfileId>20000</customerPaymentProfileId> <payment> <creditCard> <cardNumber>XXXX1111</cardNumber> <expirationDate>XXXX</expirationDate> </creditCard> </payment> </paymentProfiles> <paymentProfiles> <customerPaymentProfileId>20001</customerPaymentProfileId> <payment> <bankAccount> <accountType>checking</accountType> <routingNumber>XXXX0000</routingNumber> <accountNumber>XXXX0000</accountNumber> <nameOnAccount>John Doe</nameOnAccount> <bankName>Bank of Washington</bankName> </bankAccount> </payment> </paymentProfiles> <shipToList> <firstName>John</firstName> <lastName>Doe</lastName> <company></company> <address>123 Main St.</address> <city>Bellevue</city> <state>WA</state> <zip>98004</zip> <country>USA</country> <phoneNumber>000-000-0000</phoneNumber> <faxNumber></faxNumber> </shipToList> <shipToList> <firstName>Jane</firstName> <lastName>Doe</lastName> <address>123 Main St.</address> <city>Bellevue</city> <state>WA</state> <zip>98004</zip> <country>USA</country> <phoneNumber>000-000-0000</phoneNumber> </shipToList> </profile> </getCustomerProfileResponse> Quote Link to comment https://forums.phpfreaks.com/topic/245146-php-and-xml/ Share on other sites More sharing options...
dadamssg87 Posted August 18, 2011 Author Share Posted August 18, 2011 got it using xpath(). <?php $payment_profiles = $xml->xpath('profile/paymentProfiles/customerPaymentProfileId'); $most_recent = array_pop($payment_profiles); ?> Quote Link to comment https://forums.phpfreaks.com/topic/245146-php-and-xml/#findComment-1259156 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.