2011-08-03 39 views
1

我使用下面的代碼如何獲得authorize.NET CIM php sdk的resultCode和代碼/消息?

$customerProfile = new AuthorizeNetCustomer; 
    $customerProfile->description = "Description of customer"; 
    $customerProfile->merchantCustomerId = "honululu27"; 
    $customerProfile->email = "[email protected]"; 

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

回答

0

echo $ response-> getCustomerProfileId(); //只在成功時顯示
echo $ response-> xml-> customerProfileId; //只有在成功

的情況下,這是有道理的,因爲你只能得到一個剖面ID如果API調用成功顯示出來

回聲$響應 - > XML-> resultCode爲; //一直沒有出現

嘗試echo $response->xml->messages->resultCode

回聲$響應 - > XML-> MESSAGE->代碼; //從未示出了

嘗試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,,[email protected],none,none,none,none,none,none,none,none,0.00,0.00,0.00,FALSE,none,72784EF27A4DD684150C39B923FC4478,,2,,,,,,,,,,,XXXX1111,Visa,,,,,,,,,,,,,,,,</string> 
    </validationDirectResponseList> 
</createCustomerProfileResponse> 
相關問題