1

我正在使用以下代码

$customerProfile = new AuthorizeNetCustomer;
    $customerProfile->description = "Description of customer";
    $customerProfile->merchantCustomerId = "honululu27";
    $customerProfile->email = "user2@domain.com";

    // Add payment profile.
    $paymentProfile = new AuthorizeNetPaymentProfile;
    $paymentProfile->payment->creditCard->cardNumber = "4111111111111111";
    $paymentProfile->payment->creditCard->expirationDate = "2015-10";
    $customerProfile->paymentProfiles[] = $paymentProfile;

    //Check customer
    $request = new AuthorizeNetCIM;
    $response = $request->createCustomerProfile($customerProfile);
    echo $response->getCustomerProfileId(); //shows up only in case of success
    echo $response->xml->resultCode; //never shows up
        echo $response->xml->message->code; //never shows up
        echo $response->xml->customerProfileId; //shows up only in case of success

        // Confused about the portion below
    if($response->isOk())
    {
        echo "Success";
        echo $response->getCustomerProfileId();
    }
    else
    {
        echo "FAILED";
        echo $response->xml->resultCode;
    }

现在,您可能会说,我是这方面的新手,所以我不知道如何显示消息文本和代码。唯一有效的是客户 ID,它会在成功的情况下显示出来,但是所有其他 xml 字段(如消息)呢?

4

1 回答 1

0

回声 $response->getCustomerProfileId(); //仅在成功的情况下显示
echo $response->xml->customerProfileId; //仅在成功的情况下显示

这是有道理的,因为如果 API 调用成功,您只会获得配置文件 ID

echo $response->xml->resultCode; //永远不会出现

尝试echo $response->xml->messages->resultCode

echo $response->xml->消息->代码;//永远不会出现

尝试echo $response->xml->messages->message->code

这是一个示例响应,它显示了 CIM 响应的 XML 结构。它应该可以帮助您了解为什么您拥有的代码不起作用。

<?xml version="1.0" encoding="utf-8"?>
<createCustomerProfileResponse 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>
  <customerProfileId>5427896</customerProfileId>
  <customerPaymentProfileIdList>
    <numericString>4796541</numericString>
  </customerPaymentProfileIdList>
  <customerShippingAddressIdList>
    <numericString>4907537</numericString>
  </customerShippingAddressIdList>
  <validationDirectResponseList>
    <string>1,1,1,This transaction has been approved.,EY6CR8,Y,2165732750,none,Test transaction for ValidateCustomerPaymentProfile.,0.00,CC,auth_only,12345,John,Smith,,123 Main Street,Townsville,NJ,12345,,800-555-1234,,user@example.com,none,none,none,none,none,none,none,none,0.00,0.00,0.00,FALSE,none,72784EF27A4DD684150C39B923FC4478,,2,,,,,,,,,,,XXXX1111,Visa,,,,,,,,,,,,,,,,</string>
  </validationDirectResponseList>
</createCustomerProfileResponse>
于 2011-12-03T02:22:29.973 回答