Reply
Member
Posts: 6
Registered: ‎10-14-2015

Trouble Integrating API

[ Edited ]

Hey all,

 

I am having trouble testing the API. Whenever I try the test codes, I don't get any errors, but instead it seems that I am having issues with this line of code:

 

$controller = new AnetController\CreateTransactionController($request);

 

I have the whole piece of code below, but it is just a copy of the Create Customer Profile sample code. I have tried using my sandbox API Login ID and Transaction Key as well. Any advice would be greatly appreciated!

 

require 'vendor/autoload.php';
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
define("AUTHORIZENET_LOG_FILE", "phplog");
// Common setup for API credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName("556KThWQ6vf2");
$merchantAuthentication->setTransactionKey("***");
$refId = 'ref' . time();

// Create the payment data for a credit card
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber( "4111111111111111" );
$creditCard->setExpirationDate( "2038-12");
$paymentCreditCard = new AnetAPI\PaymentType();
$paymentCreditCard->setCreditCard($creditCard);

// Create the Bill To info
$billto = new AnetAPI\CustomerAddressType();
$billto->setFirstName("Ellen");
$billto->setLastName("Johnson");
$billto->setCompany("Souveniropolis");
$billto->setAddress("14 Main Street");
$billto->setCity("Pecan Springs");
$billto->setState("TX");
$billto->setZip("44628");
$billto->setCountry("USA");

// Create a Customer Profile Request
// 1. create a Payment Profile
// 2. create a Customer Profile
// 3. Submit a CreateCustomerProfile Request
// 4. Validate Profiiel ID returned

$paymentprofile = new AnetAPI\CustomerPaymentProfileType();

$paymentprofile->setCustomerType('individual');
$paymentprofile->setBillTo($billto);
$paymentprofile->setPayment($paymentCreditCard);
$paymentprofiles[] = $paymentprofile;
$customerprofile = new AnetAPI\CustomerProfileType();
$customerprofile->setDescription("Customer 2 Test PHP");
$merchantCustomerId = time().rand(1,150);
$customerprofile->setMerchantCustomerId($merchantCustomerId);
$customerprofile->setEmail("test2@domain.com");
$customerprofile->setPaymentProfiles($paymentprofiles);

$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 "SUCCESS: PROFILE ID : " . $response->getCustomerProfileId() . "\n";
}
else
{
echo "ERROR : Invalid response\n";
echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n";

}

Posts: 2,765
Topics: 57
Kudos: 251
Blog Posts: 67
Registered: ‎12-05-2011

Re: Trouble Integrating API

When you submit the transaction, what response is returned by the gateway?

 

Richard

Member
Posts: 6
Registered: ‎10-14-2015

Re: Trouble Integrating API

Hey Richard,

 

Thanks for the reply. I'm not actually getting a response from the gateway. The code seems to be breaking at the $controller variable. It's almost like it can't find CreateCustomerProfileController. Could I have installed the SDK incorrectly? Or do you have any other ideas?

Posts: 2,765
Topics: 57
Kudos: 251
Blog Posts: 67
Registered: ‎12-05-2011

Re: Trouble Integrating API

When you look at your connection logs, do you see that you were able to successfully connect to the gateway?

 

Richard

Member
Posts: 6
Registered: ‎10-14-2015

Re: Trouble Integrating API

I'm not sure exactly how to check this, but I don't think it is connecting.

Member
Posts: 6
Registered: ‎10-14-2015

Re: Trouble Integrating API

So I figured out the problem. I was having issues with the SerializerBuilder due to using the wrong composer.json file during the installation of the SDK. If anyone else has this issue, the solution can be found here: https://community.developer.authorize.net/t5/Integration-and-Testing/Basic-Installation-Problem/m-p/...