cancel
Showing results for 
Search instead for 
Did you mean: 

Can't Get getCustomerPaymentProfile() To Work

EDIT: I realized that by using getCustomerProfile I CAN get the last 4 digits to show of the CC (the point of this post).

 

With that said, I will leave the question open, though, just as I am curious as to why I am able to get the customer profile data to show but nothing shows properly when I use getCustomerPaymentProfile. So while my issue is technically solved (getting the last 4 digits of their cc info) I am curious to see why one function works and one does not. Thanks

 

#### Original Post Before Edit ####

 

 

Hey,

 

Everything else seems to work fine for me. Yet when I try to pull the payment data, so I can have repeat customers see a reminder of the last CC they used (I just want them to see the last 4 digits, that's all). Creating profiles is a snap for me. Getting the basic address profile data is easy. Getting the payment profile data, not so much. Curious as to what I am doing wrong. Ty

 

require('AuthnetCIM.class.php');

$request = new AuthnetCIM('mylogin', 'my_trans_id', AuthnetCIM::USE_DEVELOPMENT_SERVER);

$profile_id="xxxxxx";
$payment_profile_id="xxxxxx";

# A guesswork attempt to pull data by passing the payment profile id that I have stored

$request->setParameter('customerPaymentProfileId', $payment_profile_id);

$request->getCustomerPaymentProfile();

print_r($request); // just to test out the printout


The error I receive is:

 

customerProfileId' element is invalid - The value '' is invalid according to its datatype 'AnetApi/xml/v1/schema/AnetApiSchema.xsd:numericString' - The Pattern constraint failed.

 

Above that I receive this:

 

E00003


As an error as well.

 

So, what code am I missing to remedy this? Once again, getting shipping or billing data is easy. Getting the payment data, I can't figure it out for some reason.

 

Thanks.

jbh1977
Contributor
5 REPLIES 5

Shouldn't it setParameter the profile_id too?

RaynorC1emen7
Expert

I thought so but when I tried it originally I received an error. I must have done something else wrong. Now, when I add this line:

 

$request->setParameter('customerProfileId', $profile_id);

But call

 

$request->getCustomerPaymentProfile();

I get no errors and the name, addy and last 4 digits show. Go figure...

 

Thanks.

One last q - what is the best way to retrieve this value? (the cc 4 digit number)

 

I saw some code that parses through the xml but it's not working for me. Would any basic xml php function get the job done?

 

Has anybody had success parsing through it or is there documentation I am not aware of that shows how?

Thanks.

For instance:

 

Cannot access private property AuthnetCIM::$response

 

is the error I get when I try something like this:

 

echo $request->response;

I am trying to strip the cc info that's listed between <CardNumber></CardNumber>

 That data comes from:

 

 [response:private] => <?xml version="1.0" encoding="utf-8"?><getCustomerPaymentProfileResponse 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><paymentProfile><customerType>individual</customerType>.....<creditCard><cardNumber>XXXX0012</cardNumber><expirationDate>XXXX</expirationDate></creditCard></payment></paymentProfile></getCustomerPaymentProfileResponse>

How do you guys pull this info out?

Thanks.

Got it. I had to use another version of the CIM class to get it to work.

 

Ty.

 

PS. For reference, for those wondering, here is what I did:

 

require('anet_php_sdk/lib/shared/AuthorizeNetXMLResponse.php');


require('anet_php_sdk/lib/shared/AuthorizeNetRequest.php');


require('anet_php_sdk/lib/AuthorizeNetCIM.php');


$request = new AuthorizeNetCIM('login', 'trans_key');

$profile_id="profile_id_of_customer";

$response = $request-> getCustomerProfile($profile_id);

foreach($response->xml->profile->paymentProfiles AS $key => $paymentid) {
echo "<P>";
	echo $paymentid->payment->creditCard->cardNumber . "<br />";
echo "</p>";

}

 Not pretty but I just got it to work. Hope this helps somebody. FYI, it returns the CC # as xxxx1111 (1111 = the last 4 digits as they were entered).