I'm using the PHP SDK to contact the gateway like so:
// create a request object $request = new AuthorizeNetCIM(API_LOGIN_ID, TRANSACTION_KEY); $request->setSandbox(AUTHORIZENET_SANDBOX); $request->setLogFile(AUTHORIZENET_LOG_FILE); $response = $request->getCustomerProfile($authorizenet_customer_profile_id);
This brings back a result, but the PHP SDK doesn't seem to be able to do anything very useful with it:
$response->getCustomerProfileIds() returns NULL even with a valid response
$response->getCustomerPaymentProfileIds() returns NULL even with a valid response
$response->getCustomerShippingAddressIds() returns NULL even with a valid response
$response->getCustomerAddressId() returns FALSE even with a valid response
$response->getCustomerProfileId() actually does return a profile id but that's useless. i had to have the profile id to call the original gateway function.
$response->getPaymentProfileId() actually returns *one* of the payment profile ids regardless of how many are returned.
Given this sad peformance, I attempted to do some var_dumps on the object returned and some casting to sort things out. This has turned out to be a nightmare because the response XML is totally different when a user has a single payment account versus when they have several. This code works great when a user has several accounts. When they have one, it creates a useless 3-element array:
$prof_array = (array)$response->xml->profile;
$payment_profiles = $prof_array["paymentProfiles"];
$result = array();
foreach($payment_profiles as $prof){
$arr = array();
$arr["payment_profile_id"] = (int)$prof->customerPaymentProfileId;
if ($prof->payment->creditCard) {
$arr["type"] = "creditCard";
$arr["card_number"] = (string)$prof->payment->creditCard->cardNumber;
} elseif ($prof->payment->bankAccount) {
$ba = $prof->payment->bankAccount;
$arr["type"] = "bankAccount";
$arr["account_type"] = (string)$ba->accountType;
$arr["routing_number"] = (string)$ba->routingNumber;
$arr["account_number"] = (string)$ba->accountNumber;
$arr["name_on_account"] = (string)$ba->nameOnAccount;
$arr["bank_name"] = (string)$ba->bankName;
}
$result[] = $arr;
}
Can anyone tell me the proper way to extract the masked card number (e.g., XXXX1234) and/or bank account details from a getCustomerProfile call? I'm really disappointed with the PHP SDK.
โ01-14-2013 08:58 PM
Bump!
Seriously, can anyone tell me if I'm missing something in the PHP SDK? Alternatively, can anyone recommend the most efficient technique for retrieving a well-structured data object listing of all the payment profiles that belong to a given customer profile id? The technique needs to work whether the customer has multiple profiles or just one.
โ01-16-2013 09:15 AM
This seems to be working for me. $pprofile is payment profile, and you'll have to do some twiddling with the specific values, but thiis works with one or multiple profiles.
$profile = $request->getCustomerProfile($profile_id_here);
if (!$profile->isOk())
$errors[] = $profile->xml->messages->message->text;
else for ($i = 0; $pprofile = $profile->xml->profile->paymentProfiles[$i]; $i++) {
if ($pprofile->payment->bankAccount)
$display['profiles'][] = array($pprofile->customerPaymentProfileId, "Bank Account {$pprofile->payment->bankAccount->routingNumber}-{$pprofile->payment->bankAccount->accountNumber}");
elseif ($pprofile->payment->creditCard)
$display['profiles'][] = array($pprofile->customerPaymentProfileId, "Credit Card XXXXXXXX{$pprofile->payment->creditCard->cardNumber}");
}
โ01-21-2013 05:30 AM