Reply
Highlighted
Member
Posts: 4
Registered: ‎03-09-2011

customerPaymentProfileId return value blank after creating new payment profile

I'm using the XML API with PHP for a system where a new user can sign up for a monthly subscription service with an initial setup fee too.

 

Long story short, everything is set up and has been working fine for months, however I occasionally have this problem:

When the user enters their payment information it first uses the createCustomerProfile function to create their profile, then it uses the createCustomerPaymentProfile function to create their payment profile.

Sometimes (I haven't been able to pinpoint what causes it) the createCustomerPaymentProfile will return Success, and the payment profile will be created in the Authorize.net CIM system, however the new customerPaymentProfileId value that should be returned with the success message is blank.

 

I'm not sure if it's not coming back at all in the XML response or if it's the class I'm using to communicate with the API (John Conde's CIM class: http://www.johnconde.net/blog/tutorial-integrate-the-authorize-net-cim-api-with-php/ )

 

Here are the important code snippets from my script:

//set params for request
$cim->setParameter('customerProfileId', $cimID);
$cim->setParameter('billToFirstName', $params['firstname']);
//... other params
$cim->createCustomerPaymentProfile();

if($cim->isSuccessful()){
	//this is where it should be retrieving the new ID:
	$payment_profile_id = $cim->getPaymentProfileId();
//...other stuff
}

 

And relevant snippets from the class I'm using:

private $paymentProfileId;
//...

public function createCustomerPaymentProfile($type = 'credit'){
	//here it builds the proper XML to send
	//...
	$this->process();
}

//...

private function process(){
	$this->ch = curl_init();
	curl_setopt($this->ch, CURLOPT_URL, $this->url);
	curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($this->ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
	curl_setopt($this->ch, CURLOPT_HEADER, 0);
	curl_setopt($this->ch, CURLOPT_POSTFIELDS, $this->xml);
	curl_setopt($this->ch, CURLOPT_POST, 1);
	curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0);
	$this->response = curl_exec($this->ch);
	if($this->response){
		$this->parseResults();
		if($this->resultCode === 'Ok'){
			$this->success = true;
			$this->error   = false;
		}
		else {
			$this->success = false;
			$this->error   = true;
		}
		curl_close($this->ch);
		unset($this->ch);
	}
	else {
		throw new AuthnetCIMException('Connection error: ' . curl_error($this->ch) . ' (' . curl_errno($this->ch) . ')', self::EXCEPTION_CURL);
	}
}

//...

private function parseResults(){
	$response = str_replace('xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"', '', $this->response);
	$xml = new SimpleXMLElement($response);
	//..
	$this->resultCode = (string) $xml->messages->resultCode;
	$this->code = (string) $xml->messages->message->code;
	$this->text = (string) $xml->messages->message->text;
	$this->validation = (string) $xml->validationDirectResponse;
	$this->directResponse = (string) $xml->directResponse;
	$this->profileId = (int) $xml->customerProfileId;
	$this->paymentProfileId = (int) $xml->customerPaymentProfileId;
	//bunch of other return vars
	$this->results = explode(',', $this->directResponse);
}

//...

public function getPaymentProfileId(){
	return $this->paymentProfileId;
}

 

Thanks a lot in advance for any help!

Highlighted
Posts: 1,609
Topics: 15
Kudos: 201
Solutions: 121
Registered: ‎06-23-2011

Re: customerPaymentProfileId return value blank after creating new payment profile

[ Edited ]

There is already CIM support in the PHP SDK. Download the latest version, open the file called CIM.markdown in the doc folder (Wordpad will work fine) to get applicable code samples. It's generally best to not use a third-party class if you can avoid it, since we have no way of telling short of implementing it ourselves if you're using it properly. And there's really no need to.

Highlighted
Member
Posts: 4
Registered: ‎03-09-2011

Re: customerPaymentProfileId return value blank after creating new payment profile

Thanks for the suggestion, but I couldn't avoid it.  We needed an easy-to-implement solution that's ready to go, not the giant mess of code examples that (last I checked) is the SDK.  This class works great 99.9% of the time... How many ways could there possibly be to build and execute a curl call?  Plus the class throws very detailed errors if anything goes wrong.

If it returns that the call was successful (which I can check in my account) then it means that Authnet returned a success message.  I was just wondering if anyone knew of any circumstances where a success message would be returned without the new Profile ID.

Highlighted
Posts: 1,609
Topics: 15
Kudos: 201
Solutions: 121
Registered: ‎06-23-2011

Re: customerPaymentProfileId return value blank after creating new payment profile

What happens if you try to create a profile again when no profile ID is returned? Do you get an error, no profile ID, or a profile ID?

Highlighted
Member
Posts: 4
Registered: ‎03-09-2011

Re: customerPaymentProfileId return value blank after creating new payment profile

Well I haven't tried creating just a new payment profile after it fails because our system isn't set up to do that really.  For each user signup it creates a new CIM profile and then a payment profile under it.

I tried going through the process a few times and it did the same thing each time, created the profiles but didn't return the new payment profile ID.

 

What I'm thinking it might be:

Our system is set up to use not only our Authorize.net account but other merchants can plug in their info and it will go through their account.  This particular merchant I'm testing with apparently has a very past due account.  Think that could be it?

Highlighted
Posts: 1,609
Topics: 15
Kudos: 201
Solutions: 121
Registered: ‎06-23-2011

Re: customerPaymentProfileId return value blank after creating new payment profile

The class you're using could just be dropping the ID along the way. Try implementing using the CIM code examples and see if you get an ID back from that.