Author Topic: IPN failure email after refund  (Read 5547 times)

philtr

  • Beginner
  • *
  • Posts: 1
IPN failure email after refund
« on: June 22, 2011, 12:53:24 pm »
Hi guys, i've had to issue a couple of refunds today (for the first time) and I received the following email from Paypal:-

Quote
Subject: PayPal IPN Transaction on your site

Hello,
a Failed PayPal Transaction on http://<snip> your attention.
-----------------------------------------------------------
Order ID: 104
User ID:
Payment Status returned by PayPal: Refunded

Response from www.paypal.com: HTTP/1.1 200 OK

VERIFIED

The status in the admin area for each refunded order then changes to cancelled. Any idea why I would've got this after issuing a refund?

stinga

  • Contributing Developer
  • Full Member
  • *
  • Posts: 872
    • Squangle ltd
Re: IPN failure email after refund
« Reply #1 on: June 29, 2011, 13:42:07 pm »
PayPal send you an IPN to say it has been refunded.
VM sees the IPN but does not know what to do with it, so to be safe it marks the order as cancelled.
You need to modify the code so that it sets the status to refund.
You get the same issue with a PayPal dispute, I am going to go through ours and make it work properly.
Stinga.
614869 products in 747 categories with 15749 products in 1 category.
                                             Document Complete   Fully Loaded
                Load Time First Byte Start Render   Time      Requests      Time      Requests
First View     2.470s     0.635s     1.276s          2.470s       31            2.470s      31
Repeat View  1.064s     0.561s     1.100s          1.064s       4             1.221s       4

Prosperity_7

  • Beginner
  • *
  • Posts: 3
Re: IPN failure email after refund
« Reply #2 on: August 07, 2011, 02:43:23 am »
Did someone ever find a solution to this?  I have everything else working properly except for this error I get when issuing a partial refund.  Please advise......I'm desperate and need to get this resolved soon!

stinga

  • Contributing Developer
  • Full Member
  • *
  • Posts: 872
    • Squangle ltd
Re: IPN failure email after refund
« Reply #3 on: August 12, 2011, 18:32:34 pm »
G'day,

Someone else asked this very question of me recently. Was it you?

A simple solution would be to modify notify.php and check the refund value, if full cancel of partial just update the order.
Stinga.
614869 products in 747 categories with 15749 products in 1 category.
                                             Document Complete   Fully Loaded
                Load Time First Byte Start Render   Time      Requests      Time      Requests
First View     2.470s     0.635s     1.276s          2.470s       31            2.470s      31
Repeat View  1.064s     0.561s     1.100s          1.064s       4             1.221s       4

djreason

  • Jr. Member
  • **
  • Posts: 125
    • Game Room and Man Cave Supplies
Re: IPN failure email after refund
« Reply #4 on: August 14, 2012, 16:26:18 pm »
Can someone please post how to modify notify.php when a refund is issued through paypal?  right now, any refunds done through paypal, partial or complete refunds, are all changing my orders to Failed and it is not ideal.  Would want it to switch order status to partial refund or refunded accordingly.  Need to know how to update notify.php or any other files to make this work.  I do not know how to code, so need specifics please.

stinga

  • Contributing Developer
  • Full Member
  • *
  • Posts: 872
    • Squangle ltd
Re: IPN failure email after refund
« Reply #5 on: August 15, 2012, 20:28:01 pm »
G'day

First you need to decide what you want to happen, then explain it to a programmer who can do the work for you. It is quite easy if you know how, but you need to make the decisions on what you want your system to do.

I would suspect nothing since it is an accounting issue and has nothing to do with the order.
Stinga.
614869 products in 747 categories with 15749 products in 1 category.
                                             Document Complete   Fully Loaded
                Load Time First Byte Start Render   Time      Requests      Time      Requests
First View     2.470s     0.635s     1.276s          2.470s       31            2.470s      31
Repeat View  1.064s     0.561s     1.100s          1.064s       4             1.221s       4

AH

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3047
  • VirtueMart Version: 3.6.11
Re: IPN failure email after refund
« Reply #6 on: August 17, 2012, 19:44:05 pm »
This should get you started

You need to change two files
ps_paypal.php

Add the ability to configure the Refund order status and have this setting saved in the ps_paypal.cfg.php file notify.php will look for this when determining what status to set the order to on an IPN  "Payment_status" of "Refunded" from PayPal

Then you will need to modify notify.php to get it to identify this status and change the order appropriately.
That way the refunded IPN will be managed differently from the Succesful, Pending or Failed.

See (section of code below) to recognise the IPN "payment_status" of "refunded" status from paypal
The line below identifies the IPN payment_status (I have added the "refunded" test to show you how it can then be modified to do something different if it spots a refund rather than just set to whatever you configured on the payment method for failed transactions)

if (preg_match ("/Completed/", $payment_status) || preg_match ("/Pending/", $payment_status) || preg_match ("/Refunded/", $payment_status)) {


The code below will need to be modified to handle the refund status and update the order status.  I have not done this for you.


Code: [Select]
  //-------------------------------------------
      // ...read the results of the verification...
      // If VERIFIED = continue to process the TX...
      //-------------------------------------------
        if (preg_match ( "/VERIFIED/", $res) || @PAYPAL_VERIFIED_ONLY == '0' ) {
            //----------------------------------------------------------------------
            // If the payment_status is Completed... Get the password for the product
            // from the DB and email it to the customer.
            //----------------------------------------------------------------------
            if (preg_match ("/Completed/", $payment_status) || preg_match ("/Pending/", $payment_status)) {
                 
                if (empty($order_id)) {
                    $mailsubject = "PayPal IPN Transaction on your site: Order ID not found";
                    $mailbody = "The right order_id wasn't found during a PayPal transaction on your website.
                    The Order ID received was: $invoice\n\nTransaction ID: ".$txn_id;
                    vmMail($mosConfig_mailfrom, $mosConfig_fromname, $debug_email_address, $mailsubject, $mailbody );
                    exit();
                }
               
                // AMOUNT and CURRENCY CODE CHECK
$amount_check = round($db->f("order_total"), 2 );
                               
                if( $mc_gross != $amount_check
                   || $currency_code != $db->f('order_currency') ) {
                    $mailsubject = "PayPal IPN Error: Order Total/Currency Check failed";
                    $mailbody = "During a paypal transaction on your site the received amount didn't match the order total.
                    Order ID: ".$db->f('order_id').".
                    Order Number: $invoice.
                    The amount received was: $mc_gross $currency_code.
                    It should be: $amount_check ".$db->f("order_currency").".";
                   
                    vmMail($mosConfig_mailfrom, $mosConfig_fromname, $debug_email_address, $mailsubject, $mailbody );
                    exit();
                }
               
                // UPDATE THE ORDER STATUS to 'Completed'
                if(eregi ("Completed", $payment_status)) {
                    $d['order_status'] = PAYPAL_VERIFIED_STATUS;                   
                }
                // UPDATE THE ORDER STATUS to 'Pending'
                elseif(eregi ("Pending", $payment_status)) {
                    $d['order_status'] = PAYPAL_PENDING_STATUS;
                }
                require_once ( CLASSPATH . 'ps_order.php' );
                $ps_order= new ps_order;
                $ps_order->order_status_update($d);
                $mailsubject = "PayPal IPN txn on your site";
                $mailbody = "Hello,\n\n";
                $mailbody .= "a PayPal transaction for you has been made on your website!\n";
                $mailbody .= "-----------------------------------------------------------\n";
                $mailbody .= "Transaction ID: $txn_id\n";
                $mailbody .= "Payer Email: $payer_email\n";
                $mailbody .= "Order ID: $order_id\n";
                $mailbody .= "Payment Status returned by PayPal: $payment_status\n";
                $mailbody .= "Order Status Code: ".$d['order_status'];
                vmMail($mosConfig_mailfrom, $mosConfig_fromname, $debug_email_address, $mailsubject, $mailbody );
            }



regards
A

Joomla 3.9.15
php 7.2