cancel
Showing results for 
Search instead for 
Did you mean: 

getPaymentProfiles() in PHP SDK not returning defaultPaymentProfile

GetDefaultPaymentProfile() returns NULL when called on payment profiles returned by a call to customerProfile->getPaymentProfiles(). It should return 1 or 0 (true/false). The script attached at the bottom of this post reproduces the problem. Copy it to /sample-code-php/CustomerProfiles and run it from there. It produces an output similar to the following:

 

$ php CustomerProfiles/get-customer-payment-profiles.php

Succesfully created customer profile : 1501185315
Create Customer Payment Profile SUCCESS: 1500749818
Create Customer Payment Profile SUCCESS: 1500749819
GetCustomerProfile SUCCESS :
Profile Has 2 Payment Profiles
payment profile id: 1500749819 (NULL)
payment profile id: 1500749818 (NULL)

Where you see (NULL) it should display true and false. On a separate note, the XML logged to phplog file does not show that both payment profiles are returned when customer profile is retrieved but they obviously are as GetPaymentProfiles() returns all their details. Looks like the log is not a true reflection of all that is crossing the wire. I would appreciate if authorize.net dev team looks into both of these issues and provides a response.

 

 

 

<?php
require 'vendor/autoload.php';

use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;

define("AUTHORIZENET_LOG_FILE", "phplog");

$customerProfile = createCustomerProfile("123@test.com");
createPaymentProfile($customerProfile->getCustomerProfileId(), "000-000-0009", true);
createPaymentProfile($customerProfile->getCustomerProfileId(), "000-000-0008");
$customerProfile = getCustomerProfile($customerProfile->getCustomerProfileId());
$paymentProfiles = $customerProfile->getPaymentProfiles();

foreach ($paymentProfiles as $paymentProfile) {
	echo 'payment profile id: ' . $paymentProfile->getCustomerPaymentProfileId(); 
	echo ' (' . var_export($paymentProfile->getDefaultPaymentProfile(), true) . ")\n";
}


function createCustomerProfile($email) {
	$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
	$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
	$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);
	$refId = 'ref' . time();
	
	$customerprofile = new AnetAPI\CustomerProfileType();
	$customerprofile->setDescription("Customer 2 Test PHP");

	$customerprofile->setMerchantCustomerId("M_".$email);
	$customerprofile->setEmail($email);
	
	$request = new AnetAPI\CreateCustomerProfileRequest();
	$request->setMerchantAuthentication($merchantAuthentication);
	$request->setRefId( $refId);
	$request->setProfile($customerprofile);
	$controller = new AnetController\CreateCustomerProfileController($request);
	
	$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
	if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) {
			echo "Succesfully created customer profile : " . $response->getCustomerProfileId() . "\n";
	} else {
			echo "ERROR :  Invalid response\n";
			$errorMessages = $response->getMessages()->getMessage();
			echo "Response : " . $errorMessages[0]->getCode() . "  " .$errorMessages[0]->getText() . "\n";
	}
	return $response;
}

function createPaymentProfile($customerProfileId, $phoneNumber, $isDefaultPaymentProfile=false) {
	$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
	$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
	$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);
	$refId = 'ref' . time();
	
	$creditCard = new AnetAPI\CreditCardType();
	$creditCard->setCardNumber("4242424242424242");
	$creditCard->setExpirationDate("2038-12");
	$creditCard->setCardCode("142");
	$paymentCreditCard = new AnetAPI\PaymentType();
	$paymentCreditCard->setCreditCard($creditCard);

	$billto = new AnetAPI\CustomerAddressType();
	$billto->setFirstName("Ellen".$phoneNumber);
	$billto->setLastName("Johnson");
	$billto->setCompany("Souveniropolis");
	$billto->setAddress("14 Main Street");
	$billto->setCity("Pecan Springs");
	$billto->setState("TX");
	$billto->setZip("44628");
	$billto->setCountry("USA");
	$billto->setPhoneNumber($phoneNumber);
	$billto->setfaxNumber("999-999-9999");

	$paymentprofile = new AnetAPI\CustomerPaymentProfileType();
	$paymentprofile->setCustomerType('individual');
	$paymentprofile->setBillTo($billto);
	$paymentprofile->setPayment($paymentCreditCard);
	$paymentprofile->setDefaultPaymentProfile($isDefaultPaymentProfile);

	$paymentprofilerequest = new AnetAPI\CreateCustomerPaymentProfileRequest();
	$paymentprofilerequest->setMerchantAuthentication($merchantAuthentication);

	$paymentprofilerequest->setCustomerProfileId($customerProfileId);
	$paymentprofilerequest->setPaymentProfile($paymentprofile);

	// Create the controller and get the response
	$controller = new AnetController\CreateCustomerPaymentProfileController($paymentprofilerequest);
	$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
	if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) {
			echo "Create Customer Payment Profile SUCCESS: " . $response->getCustomerPaymentProfileId() . "\n";
	} else {
			echo "Create Customer Payment Profile: ERROR Invalid response\n";
			$errorMessages = $response->getMessages()->getMessage();
			echo "Response : " . $errorMessages[0]->getCode() . "  " .$errorMessages[0]->getText() . "\n";

	}
	
	return $response;
}

function getCustomerProfile($customerProfileId) {
	$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
	$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
	$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);
	$refId = 'ref' . time();

	$request = new AnetAPI\GetCustomerProfileRequest();
	$request->setMerchantAuthentication($merchantAuthentication);
	$request->setCustomerProfileId($customerProfileId);
	$controller = new AnetController\GetCustomerProfileController($request);
	$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
	if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
	{
	echo "GetCustomerProfile SUCCESS : " .  "\n";
	$profileSelected = $response->getProfile();
	$paymentProfilesSelected = $profileSelected->getPaymentProfiles();
	echo "Profile Has " . count($paymentProfilesSelected). " Payment Profiles" . "\n";

	if($response->getSubscriptionIds() != null) 
	{
		if($response->getSubscriptionIds() != null)
		{

			echo "List of subscriptions:";
			foreach($response->getSubscriptionIds() as $subscriptionid)
				echo $subscriptionid . "\n";
		}
	}
	}
	else
	{
	echo "ERROR :  GetCustomerProfile: Invalid response\n";
	$errorMessages = $response->getMessages()->getMessage();
	echo "Response : " . $errorMessages[0]->getCode() . "  " .$errorMessages[0]->getText() . "\n";
	}
	return $response->getProfile();
}
?>

 

dcoho
Member
2 REPLIES 2

Hello @dcoho

 

I would suggest creating an issue on GitHub and include your sample code to replicate this error.  This will notify the team who managed our SDKs so they can take action right away.

 

Richard

RichardH
Administrator Administrator
Administrator

I did: https://github.com/AuthorizeNet/sdk-php/issues/230

 

However, Github interface for inserting code is broken (as you can see from discoloring of code pasted)