Reply
Highlighted
Member
Posts: 6
Registered: ‎02-20-2013
Accepted Solution

Questions about Response object

We had been using AIM and switched to SIM temporarily while migrating to new server and installing composer and rewriting with the new API and PHP SDK. I have it installed and made a test page that goes to my sandbox and seems to be working fine.

 

However, in the past with AIM, I had gotten some variables out of the response:

 

    $firstname=$response->ship_to_first_name;
    $lastname=$response->ship_to_last_name;
    $address=$response->ship_to_address;
    $city=$response->ship_to_city;
    $state=$response->ship_to_state;
    $zip=$response->ship_to_zip_code;
    $country=$response->ship_to_country;
    $custid=$response->customer_id;

Now I'm not seeing a way to get this with the new API. I had wanted to be able to retrieve these variables again. I also had used some custom fields but not sure how that would work if I cannot even get back the address. Does anyone have any ideas? 

For AIM, I'd call the custom fields this way:

$sale->setCustomField("substart", $substart);
$sale->setCustomField("subend", $subend);
$sale->setCustomField("subtype", $subtype);

And retrieve them like this:

    $substart=$response->substart;
    $subend=$response->subend;
    $subtype=$response->subtype;

Is this no longer an option? I can probably come up with a work-around but this is easiest for us.

 

I did a print_r on the response and this is what I got and didn't see what I wanted:

net\authorize\api\contract\v1\TransactionResponseType Object ( 
[responseCode:net\authorize\api\contract\v1\TransactionResponseType:private] => 1
[rawResponseCode:net\authorize\api\contract\v1\TransactionResponseType:private] => [authCode:net\authorize\api\contract\v1\TransactionResponseType:private] => JAIUNQ [avsResultCode:net\authorize\api\contract\v1\TransactionResponseType:private] => Y [cvvResultCode:net\authorize\api\contract\v1\TransactionResponseType:private] => P [cavvResultCode:net\authorize\api\contract\v1\TransactionResponseType:private] => 2 [transId:net\authorize\api\contract\v1\TransactionResponseType:private] => 40004966918 [refTransID:net\authorize\api\contract\v1\TransactionResponseType:private] => [transHash:net\authorize\api\contract\v1\TransactionResponseType:private] => F87AE5CCF40319E8A66E844A86487432 [testRequest:net\authorize\api\contract\v1\TransactionResponseType:private] => 0 [accountNumber:net\authorize\api\contract\v1\TransactionResponseType:private] => XXXX1111 [entryMode:net\authorize\api\contract\v1\TransactionResponseType:private] => [accountType:net\authorize\api\contract\v1\TransactionResponseType:private] => Visa [splitTenderId:net\authorize\api\contract\v1\TransactionResponseType:private] => [prePaidCard:net\authorize\api\contract\v1\TransactionResponseType:private] => [messages:net\authorize\api\contract\v1\TransactionResponseType:private] => Array ( [0] => net\authorize\api\contract\v1\TransactionResponseType\MessagesAType\MessageAType Object ( [code:net\authorize\api\contract\v1\TransactionResponseType\MessagesAType\MessageAType:private] => 1 [description:net\authorize\api\contract\v1\TransactionResponseType\MessagesAType\MessageAType:private] => This transaction has been approved. ) )
[errors:net\authorize\api\contract\v1\TransactionResponseType:private] => Array ( ) [splitTenderPayments:net\authorize\api\contract\v1\TransactionResponseType:private] => Array ( ) [userFields:net\authorize\api\contract\v1\TransactionResponseType:private] => Array ( ) [shipTo:net\authorize\api\contract\v1\TransactionResponseType:private] => [secureAcceptance:net\authorize\api\contract\v1\TransactionResponseType:private] => [emvResponse:net\authorize\api\contract\v1\TransactionResponseType:private] => [transHashSha2:net\authorize\api\contract\v1\TransactionResponseType:private] => [profile:net\authorize\api\contract\v1\TransactionResponseType:private] => )

It seems everything says private. Maybe there's something I'm not understanding but any help would be appreciated. Thanks.


Accepted Solutions
Highlighted
Solution
Accepted by Aaron (All Star)
‎06-23-2017 10:13 AM
Member
Posts: 6
Registered: ‎02-20-2013

Re: Questions about Response object

I got a foreach loop to work:

	  $myfields=$tresponse->getUserFields();
	  $i=0;	  
	  foreach($myfields as $key => $value){
		  $key=$tresponse->getUserFields()[$i]->getName();
		  $value=$tresponse->getUserFields()[$i]->getValue();
		  $$key=$value;
		  $i++;
	  }

So at the end I can get the variable by the name I put in originally.

View solution in original post


All Replies
Highlighted
All Star
Posts: 699
Registered: ‎11-03-2016

Re: Questions about Response object

Hi @deevoo,

 

To see everything that you could send or get back in the response from the API, check out the API Reference. One specific section you'd be interested in is the userFields section, where you can send name/value pairs for whatever you want. These user fields aren't stored with the transaction, but will come back in the response. You can even test that interactively in the "Try it" tab in the API Reference.

 

You can see from the API Reference that transaction data like address is not sent back in the response. If you want this kind of data, you'd either want to capture that before the transaction is sent off, or echo it back in some userFields.

 

If you need to see a sample of how to parse the response or pull individual fields out, we have a bunch of sample code on GitHub. If you want to see an example of how exactly to send these user fields using the PHP SDK, I just updated the main charge-credit-card.php sample to show that.

Highlighted
Member
Posts: 6
Registered: ‎02-20-2013

Re: Questions about Response object

So now the question is how to get it back as a response. I just tried everything I could think of and nothing seems to be working. I didn't see it in the example you directed me to.

I tried $tresponse->getUserField()[0];

I tried $tresponse->getUserField[0]();

I tried $tresponse->nameOfField();

I tried $tresponse->getUserField("nameOfField");

and a host of other ways.

I'm sure it's something simple to you but without an example showing what to call for, I'm having difficulty. I'm seeing it in the log it's generating but I'm not able to call it back.

Highlighted
All Star
Posts: 699
Registered: ‎11-03-2016

Re: Questions about Response object

Sorry about that. Try

$tresponse->getUserFields();

with an 's' 

Highlighted
Member
Posts: 6
Registered: ‎02-20-2013

Re: Questions about Response object

Thanks, Aaron. That got me started - it seems there was a little more to it though.

I was having some trouble and seeing it was a multidimensional array tried going that route but kept getting response errors (PHP Fatal error:  Uncaught Error: Cannot use object of type net\authorize\api\contract\v1\UserFieldType as array)

 

$myField=$tresponse->getUserFields();
$myField[0][0]=$myField[0][1];

 

Finally ended up with:

 

$tresponse->getUserFields()[0]->getName();
$tresponse->getUserFields()[0]->getValue();
$tresponse->getUserFields()[1]->getName();
$tresponse->getUserFields()[1]->getValue();

to get the values after looking at this page https://github.com/AuthorizeNet/sdk-php/blob/master/lib/net/authorize/api/contract/v1/UserFieldType....

 

 

I really don't need the names since I know what is going in and what order so it's good to be able to get the values back. I may even be able to figure out a "for loop" to get the name and value pairs if I need to. Thanks again.

Highlighted
Solution
Accepted by Aaron (All Star)
‎06-23-2017 10:13 AM
Member
Posts: 6
Registered: ‎02-20-2013

Re: Questions about Response object

I got a foreach loop to work:

	  $myfields=$tresponse->getUserFields();
	  $i=0;	  
	  foreach($myfields as $key => $value){
		  $key=$tresponse->getUserFields()[$i]->getName();
		  $value=$tresponse->getUserFields()[$i]->getValue();
		  $$key=$value;
		  $i++;
	  }

So at the end I can get the variable by the name I put in originally.