如何获取authorize.NET CIM php sdk的resultCode和代码/消息?

时间:2011-08-03 10:56:12

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

我正在使用以下代码

$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字段如消息呢?

1 个答案:

答案 0 :(得分:0)

  

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

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

  

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

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

  

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

尝试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>