Forums

Save data to Database from Authorize.Net

rjrinc 18 Nov, 2015
Hello,

I have been looking for information on how to setup a form to save and update data from the Authorize.net response. I have been unable to get the data in the PLUGINS array into the database. I have a basic form setup and currently working on the On Submit - On Approved event in the form setup. I have the form sending a email and saving the form fields to the database, however I'm unable to capture the response data from Authorize into the database. I see the data in the data Array in debug under the PLUGINS array, and I can dump the form variables in the email and see them there via var_dump($form->data); So it seems that I have no problem getting the form field data but I'm not able to get the data in the PLUGINS array.

I need a way to capture it and save this response info from authorize into the database. I have tried to create table field names that match the variables like response_code, response_subcode but it does not save anything in the record. How is this done? Any direction or explanation would be great. Thanks in advance.

- Chris
GreyHead 19 Nov, 2015
Hi Chris,

I think that the data is in $form->data['_PLUGINS_']['authorise.net']

You can try adding a Model ID to the DB Save_PLUGINS_.authorise.net or use a Custom Code action to copy all (or what you need, back to the $form->data array so it will save without the Model ID
<?php
$temp = $form->data['_PLUGINS_']['authorise.net'];
$form->data = array_merge($form->data, $temp);
?>
This might cause problems if there are any duplicated names but that can be fixed by tweaking the code a bit.

Bob
rjrinc 25 Nov, 2015
Thanks Bob. I'm using this code:
<?php
$temp = $form->data['_PLUGINS_']['authorize_net'];
$form->data = array_merge($form->data, $temp);
?>

currently in a Custom Code block inside the Submit event inside the Authorize.net block inside the On Approved block before the DB block.

It appears to be allowing the data from Authorize to be populated in the table like I need.

Now I need to understand how to add some update conditions into the DB Save block. I want to check against the current logged in user values. I would like to update the record if the logged in user email address matches the email address in the record in the table connected to the form in the DB Save block.

How is this done? I tried:
<?php
$user = JFactory::getUser();
return array( 'Data.Email' => $user->email );
?>


But this gives me a fatal error of "Cannot use object of type JUser as array" and points to the file "administrator/components/com_chronoforms5/chronoforms/actions/db_save/db_save.php on line 93"

Any suggestions on how to update records would be great. I came across this FAQ on using WHERE in the conditions box . Is there anything that covers updating?
-Chris
GreyHead 29 Nov, 2015
Hi Chris,

Looking at your code I would expect it to work . . . Ah no - I checked the code and the problem is that Max has used $user for something else. If you change the $user in your code so say $juser then all should be OK.

Bob
rjrinc 30 Nov, 2015
Hi Bob,

Thanks for the help. I have updated my code to leverage what you suggested in the db save block:
<?php 
$juser = JFactory::getUser();
 return array( 'DuesData.Email' => $juser->email);
?>

This does allow me to update a table where the logged in user email matches against email field particular table.

What I would like to do now is get the dollar amount returned by Authorize.Net and save that in the database along with the other values from the form data. I'm able to get what I need from authorize and save it except for the x_amount that is returned back from Authorize. Is there a way to capture this variable and store it in a field in this DB save block?
-Chris
GreyHead 01 Dec, 2015
Hi Chris,

If I understand correctly the problem is that the amount ends up in $form->data['x_amount'] after the merge and you need to save it to a column with a different name like 'amount' ??

If so then add this after the merge
$form->data['amount'] = $form->data['x_amount'];

Bob
This topic is locked and no more replies can be posted.