Hello everyone,
I have successfully integrated the Silent Post feature with our system for ARB subscriptions. What I am now trying to do is when we refund a payment via the merchant interface, how do I distinguish a refund from all other transactions? Is the a special variable that is set for a refunded payment? Any help is appreciated!
05-23-2011 05:50 PM
x_type will say "refund"
05-24-2011 10:23 AM
Okay, great, thanks for the reply. I tried using that variable but it does not seem to work for me still. Here is the code from my Silent Post script that is trying to handle "Refunded" payments.
//Check to see if this is a REFUND } elseif ($_POST['x_type'] == 'refund') { //Look for the transaction_id in the payments table and DELETE it $transaction_id = $_POST['x_trans_id'] ; $query = "DELETE FROM payments WHERE transaction_id = $transaction_id LIMIT 1" ; $result = mysqli_query($dbc, $query) ; $num = mysqli_affected_rows($dbc) ; if ($num == 1) { //The payment was found in the payments table and deleted //Create a dummy variable $done = 'Yes' ; } }
Do you see something that I did wrong?
05-25-2011 04:31 PM
At a glance that piece of code looks correct. It's possible the problem lies elsewhere.
05-26-2011 05:06 AM
Okay thanks of the response again. Well I did some more looking around in my script and I noticed that I was not "connecting to the database" so that is why it was not working. However, when I "VOID" a transaction, it works perfectly. But when I "REFUND" a transaction it still does not work. Do you know what could be causing this? The only thing I can figure is that seems as if "x_type" is not capable for refunding transactions. When I looked at the AIM PDF, it has these listed as possible values for "x_type":
05-26-2011 06:39 AM - edited 05-26-2011 06:40 AM
CREDIT is the one you're looking for. I forgot that is the "official" term for refund. That should solve your problem.
05-26-2011 08:18 AM
Okay, I tried to use "CREDIT", but that did not work either. Here is my updated code:
//Check to see if this is a 'voided' transaction } elseif ($_POST['x_type'] == 'void') { //Connect to the database require('mysql_connect.php'); //Look for the transaction_id in the payments table and DELETE it $transaction_id = $_POST['x_trans_id'] ; $query = "DELETE FROM payments WHERE transaction_id = $transaction_id LIMIT 1" ; $result = mysqli_query($dbc, $query) ; //Check to see if this is a 'refunded' transaction } elseif ($_POST['x_type'] == 'credit') { //Connect to the database require('mysql_connect.php'); //Look for the transaction_id in the payments table and DELETE it $transaction_id = $_POST['x_trans_id'] ; $query = "DELETE FROM payments WHERE transaction_id = $transaction_id LIMIT 1" ; $result = mysqli_query($dbc, $query) ; } else { //The script/person is not from Authorize.net //Redirect to home page header('Location: www.blah.com') ; }
I am not sure why this did not work, because the VOID works perfectly. I tried CREDIT and REFUND and neither seem to work. Any more suggestions? Thanks again!
05-26-2011 02:34 PM
It looks good to me. So I am unsure where your error might be.
But if nothing else you can improve your code. If voids and refunds do the same thing use the same code for both of them:
//Check to see if this is a 'voided' OR "CREDIT" transaction } elseif ($_POST['x_type'] === 'VOID' || $_POST['x_type'] === 'CREDIT') { //Connect to the database require('mysql_connect.php'); //Look for the transaction_id in the payments table and DELETE it $transaction_id = $_POST['x_trans_id'] ; $query = "DELETE FROM payments WHERE transaction_id = $transaction_id LIMIT 1" ; $result = mysqli_query($dbc, $query) ; //Check to see if this is a 'refunded' transaction } else { //The script/person is not from Authorize.net //Redirect to home page header('Location: www.blah.com') ; }
05-27-2011 06:06 AM
Okay great. I have updated my code as stated by you. The "void" still works but the "credit" does not. Just so you know, if "VOID" is in all caps, the code does not work. But if "void" is in all lower case, it works perfectly. However, I have tried "Credit", "CREDIT", and "credit" and none of those combinations work when I refund a transaction.
I am not sure if this is correct, but I noticed after I refund a transaction, a new transaction ID is created for that refund. I am guessing the new transaction ID is the one being sent off to the Silent Post URL and not the original transaction ID that was first associated with the successful payment.
05-27-2011 07:05 AM