Search code examples
xmlauthorize.netauthorize.net-cim

How do I get the resultCode and code/messages for authorize.NET CIM php sdk?


I am using the following code

$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;
    }

Now, as you can probably tell, i am a novice at this, so I can't figure out how to display the message text and code. The only thing working is the customer id, which shows up in case of success, but what about all the other xml fields like messages?


Solution

  • echo $response->getCustomerProfileId(); //shows up only in case of success
    echo $response->xml->customerProfileId; //shows up only in case of success

    That makes sense since you only get a profile ID if the API call is successful

    echo $response->xml->resultCode; //never shows up

    Try echo $response->xml->messages->resultCode

    echo $response->xml->message->code; //never shows up

    Try echo $response->xml->messages->message->code

    Here is a sample response which shows the XML structure of a CIM response. It should help you see why the code you have isn't working.

    <?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>