cancel
Showing results for 
Search instead for 
Did you mean: 

Silent Post Refund Variable

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!

three3
Contributor
8 REPLIES 8

x_type will say "refund"


-------------------------------------------------------------------------------------------------------------------------------------------
John Conde :: Certified Authorize.Net Developer (Brainyminds) :: Official Authorize.Net Blogger

NEW! Handling Authorize.Net's Webhooks with PHP

Integrate Every Authorize.Net JSON API with One PHP Class (Sample code included)

Tutorials for integrating Authorize.Net with PHP: AIM, ARB, CIM, Silent Post
All About Authorize.Net's Silent Post
stymiee
Expert
Expert

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?

 

At a glance that piece of code looks correct. It's possible the problem lies elsewhere.


-------------------------------------------------------------------------------------------------------------------------------------------
John Conde :: Certified Authorize.Net Developer (Brainyminds) :: Official Authorize.Net Blogger

NEW! Handling Authorize.Net's Webhooks with PHP

Integrate Every Authorize.Net JSON API with One PHP Class (Sample code included)

Tutorials for integrating Authorize.Net with PHP: AIM, ARB, CIM, Silent Post
All About Authorize.Net's Silent Post

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":

 

 

  • AUTH_CAPTURE
  • AUTH_ONLY
  • PRIOR_AUTH_CAPTURE
  • CAPTURE_ONLY
  • CREDIT
  • VOID
I cannot seem to find anything for REFUNDed transactions. Thanks again and I hope we get this figured out.

 

CREDIT is the one you're looking for. I forgot that is the "official" term for refund. That should solve your problem.


-------------------------------------------------------------------------------------------------------------------------------------------
John Conde :: Certified Authorize.Net Developer (Brainyminds) :: Official Authorize.Net Blogger

NEW! Handling Authorize.Net's Webhooks with PHP

Integrate Every Authorize.Net JSON API with One PHP Class (Sample code included)

Tutorials for integrating Authorize.Net with PHP: AIM, ARB, CIM, Silent Post
All About Authorize.Net's Silent Post

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!

 

 

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') ;
}

 

 


-------------------------------------------------------------------------------------------------------------------------------------------
John Conde :: Certified Authorize.Net Developer (Brainyminds) :: Official Authorize.Net Blogger

NEW! Handling Authorize.Net's Webhooks with PHP

Integrate Every Authorize.Net JSON API with One PHP Class (Sample code included)

Tutorials for integrating Authorize.Net with PHP: AIM, ARB, CIM, Silent Post
All About Authorize.Net's Silent Post

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.