【问题标题】:Pulling values from CIM - authorize.net从 CIM 中提取值 - authorize.net
【发布时间】:2012-07-20 03:15:55
【问题描述】:

我已经制定了从 CIM 获取信息的脚本:

$content = 
  "<?xml version=\"1.0\" encoding=\"utf-8\"?>" .
  "<getCustomerProfileRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">" .
  merchantAuthenticationBlock().
  "<customerProfileId>$cid</customerProfileId>" .
  "</getCustomerProfileRequest>";

$response = send_xml_request($content);
$parsedresponse = parse_api_response($response);

那么,现在如何将返回值写入变量?

我试过了:

$customerPaymentProfileId = $parsedresponse->customerPaymentProfileId;
$customerShippingAddressId = $parsedresponse->customerShippingAddressId;

但这会将变量返回为空。我觉得我错过了一些简单的东西。

【问题讨论】:

    标签: php xml authorize.net authorize.net-cim


    【解决方案1】:

    要查看$parsedresponse 的结构,请执行print_r($parsedresponse)var_dump($parsedresponse)。从那里您可以看到数组的结构并从那里获取您的值。

    仅供参考,付款资料位于数组中,因此您需要遍历它们以获取它们的值。假设 parsedresponse 是根 XML 节点,您可以像这样获取它们:

    foreach ($parsedresponse->profile->paymentProfiles as $profile)
    {
        echo $profile->customerPaymentProfileId;
    }
    

    仅供参考,这是此响应的示例数组结构(来自AuthnetXML 示例代码。我是这个库的作者):

    <?xml version="1.0" encoding="utf-8"?>
    <getCustomerProfileResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
      <messages>
        <resultCode>Ok</resultCode>
        <message>
          <code>I00001</code>
          <text>Successful.</text>
        </message>
      </messages>
      <profile>
        <merchantCustomerId>12345</merchantCustomerId>
        <email>user@example.com</email>
        <customerProfileId>5427896</customerProfileId>
        <paymentProfiles>
          <billTo>
            <firstName>John</firstName>
            <lastName>Smith</lastName>
            <address>123 Main Street</address>
            <city>Townsville</city>
            <state>NJ</state>
            <zip>12345</zip>
            <phoneNumber>800-555-1234</phoneNumber>
          </billTo>
          <customerPaymentProfileId>4796541</customerPaymentProfileId>
          <payment>
            <creditCard>
              <cardNumber>XXXX1111</cardNumber>
              <expirationDate>XXXX</expirationDate>
            </creditCard>
          </payment>
        </paymentProfiles>
        <paymentProfiles>
          <billTo>
            <firstName>John</firstName>
            <lastName>Doe</lastName>
            <company/>
            <address>123 Main St.</address>
            <city>Bellevue</city>
            <state>WA</state>
            <zip>98004</zip>
            <country>USA</country>
            <phoneNumber>800-555-1234</phoneNumber>
            <faxNumber>800-555-1234</faxNumber>
          </billTo>
          <customerPaymentProfileId>4796585</customerPaymentProfileId>
          <payment>
            <creditCard>
              <cardNumber>XXXX1111</cardNumber>
              <expirationDate>XXXX</expirationDate>
            </creditCard>
          </payment>
        </paymentProfiles>
        <shipToList>
          <firstName>John</firstName>
          <lastName>Smith</lastName>
          <address>123 Main Street</address>
          <city>Townsville</city>
          <state>NJ</state>
          <zip>12345</zip>
          <phoneNumber>800-555-1234</phoneNumber>
          <customerAddressId>4907537</customerAddressId>
        </shipToList>
        <shipToList>
          <firstName>John</firstName>
          <lastName>Doe</lastName>
          <company/>
          <address>123 Main St.</address>
          <city>Bellevue</city>
          <state>WA</state>
          <zip>98004</zip>
          <country>USA</country>
          <phoneNumber>800-555-1234</phoneNumber>
          <faxNumber>800-555-1234</faxNumber>
          <customerAddressId>4907591</customerAddressId>
        </shipToList>
      </profile>
    </getCustomerProfileResponse>
    

    【讨论】:

    • 做到了,约翰! $var = $parsedresponse-&gt;profile-&gt;paymentProfiles-&gt;customerPaymentProfileId; echo $var; 这会将所请求客户的付款资料 ID 分配给一个变量,然后该变量可用于各种用途。先生,你就是男人!
    猜你喜欢
    • 1970-01-01
    • 2013-07-01
    • 2013-04-08
    • 2011-10-01
    • 2011-05-14
    • 1970-01-01
    • 2011-10-21
    • 2016-04-17
    • 2011-10-20
    相关资源
    最近更新 更多