Jump to content

[SOLVED] Using Paypal IPN to set Order Status to Refunded


pxloft
 Share

Recommended Posts

Hi all, after a long time of struggling, I finally came up with a solution to allow the status of an order to be set to "refunded" once it is refunded in from the paypal module "Process Refund".

 

Now, it is a little cheat, but if you have a better (and easier) ideas on how to achieve this, please let me know.

 

Basically what happens when you refund something from the paypal module on the order details page of your prestashop, is Paypal sends an IPN back to your validation.php file, (found in yourprestashopsite.com/modules/paypalusa/controllers/front/validation.php), with a "payment_status" of "refunded".

 

What you want to do is catch that refunded status and do something with it. The tricky part is that the currency validation "if" statement catches it and throws it out immediately because it has a negative value.

 

The trick is in modifying this part of the code to compare the positive value of the cart with the direct negative value. 

 

I have attached the code for your viewing. It works just as I need it too: when the user creates an order, it changes the order status to "payment accepted" and when I click "process refund" I can simply process the refund in paypal and change the status all with just one click. HURAHH!! 

 

Again, if you have any other idea of how to make this code better, please let me know. Also let me know if this helped you!

 

If you are trying to follow along, my code begins around line 96 in my validation.php file.

 

Take care!

else{
/* Forcing the context currency to the order currency */

$context->currency = $currency;

$positiveVersion = $cart->getOrderTotal(true);
$negativeVersion = "-".$cart->getOrderTotal(true);


/* Check again negative version to allow for refunds IPN */
/* on payment_status=refund Change the status to Refunded */
if (Tools::getValue('mc_gross') != ($positiveVersion || $negativeVersion))

$errors[] = $this->paypal_usa->l('Invalid Amount paid');

else
{
/* Step 4 - Determine the order status in accordance with the response from PayPal 
Edited by pxloft (see edit history)

Share this post


Link to post
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More