Jump to content

php and xml


dadamssg87

Recommended Posts

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>

 

Link to comment
https://forums.phpfreaks.com/topic/245146-php-and-xml/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.