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>mark@example.com</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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.