Send email to admin if IPN fails

Discussion in 'Customization & add-ons' started by netserv3, Nov 16, 2015.

  1. netserv3

    netserv3 aMember Pro Customer

    Joined:
    Aug 29, 2006
    Messages:
    19
    Hello,
    I am using bluesnap payment plugin and sometimes the IPN post from bluesnap does not update user's payment record because payment terms do not match or the invoice ID is lost (when the buyer refreshes his browser in the payment process). Although an exception is created in the log but I want the script to send an email to admin informing about this problem. I tried to use php's mail function in different functions of the bluesnap payment plugin but these functions are not executed. I searched aMember's event system documentation but could not find the event constant related to it.

    Can someone help me?
  2. jenolan

    jenolan aMember Coder

    Joined:
    Nov 3, 2006
    Messages:
    493
    Hi, I can't see any log in the code can you tell me the log message and I will try and track it down and see if I can suggest a patch.
  3. netserv3

    netserv3 aMember Pro Customer

    Joined:
    Aug 29, 2006
    Messages:
    19
    Ok, here is a typical log entry:

    incoming-request
    <invoice-log-item type="incoming-request">
    <url>
    <method>POST</method>
    <scheme>https</scheme>
    <base_url>/em</base_url>
    <path_info>/payment/bluesnap/ipn</path_info>
    <host>www.mydomain.com</host>
    <remote_addr>38.99.111.160</remote_addr>
    </url>
    <params>
    <param name="invoiceCountry">PL</param>
    <param name="invoiceZipCode">86-132</param>
    <param name="invoiceFirstName">ABC</param>
    <param name="invoiceFaxNumber"/>
    <param name="invoiceState"/>
    <param name="invoiceAddress2"/>
    <param name="invoiceEmail">abc@onet.eu</param>
    <param name="invoiceLastName">XYZ</param>
    <param name="invoiceAddress1">W. K. 13 B /1</param>
    <param name="invoiceCompany"/>
    <param name="invoiceCity">Niemcz</param>
    <param name="invoiceExtension"/>
    <param name="invoiceMobilePhone"/>
    <param name="invoiceTitle"/>
    <param name="lastName">XYZ</param>
    <param name="country">PL</param>
    <param name="city">Niemcz</param>
    <param name="email">abc@onet.eu</param>
    <param name="overridePrice">31.00</param>
    <param name="invoiceAmount">38.13</param>
    <param name="invoiceAmountUSD">38.13</param>
    <param name="templateId">-99</param>
    <param name="productName">My Product 1</param>
    <param name="referenceNumber">76791095</param>
    <param name="contractName">Full Version Renewal</param>
    <param name="currency">USD</param>
    <param name="remoteAddress">79.184.35.23</param>
    <param name="contractChargePrice">31.00</param>
    <param name="quantity">1</param>
    <param name="invoiceChargeCurrency">USD</param>
    <param name="cardSubType">DEBIT</param>
    <param name="invoiceChargeAmount">38.13</param>
    <param name="referrer"/>
    <param name="contractPrice">31.00</param>
    <param name="testMode">N</param>
    <param name="invoiceLocalAmount">38.13</param>
    <param name="contractLocalPrice">31.00</param>
    <param name="invoiceLocalCurrency">USD</param>
    <param name="custom1">4NEC6</param>
    <param name="vatId"/>
    <param name="taxAmountUSD">7.13</param>
    <param name="taxRate">23.00</param>
    <param name="taxChargeAmount">7.13</param>
    <param name="authKey"/>
    <param name="transactionType">CHARGE</param>
    <param name="bluesnapNode">2</param>
    <param name="plimusNode">2</param>
    <param name="couponCode"/>
    <param name="licenseKey"/>
    <param name="cvvSent">Y</param>
    <param name="avsSent">Y</param>
    <param name="cvvResponse">Good match </param>
    <param name="avsResponse"/>
    </params>
    </invoice-log-item> ​
    exception
    <invoice-log-item type="exception">
    <type>Am_Exception_Paysystem_TransactionInvalid</type>
    <message>Subscriptions terms in the IPN does not match subscription terms in our Invoice</message>
    <trace>
    <call>
    <function>Am_Paysystem_Transaction_Incoming-&gt;validate</function>
    <file>/home/hd/public_html/em/library/Am/Paysystem/Transaction/Abstract.php</file>
    <line>48</line>
    </call>
    <call>
    <function>Am_Paysystem_Transaction_Abstract-&gt;process</function>
    <file>/home/hd/public_html/em/library/Am/Paysystem/Transaction/Incoming.php</file>
    <line>250</line>
    </call>
    <call>
    <function>Am_Paysystem_Transaction_Incoming-&gt;process</function>
    <file>/home/hd/public_html/em/library/Am/Paysystem/Abstract.php</file>
    <line>471</line>
    </call>
    <call>
    <function>Am_Paysystem_Abstract-&gt;directAction</function>
    <file>/home/hd/public_html/em/application/default/controllers/DirectController.php</file>
    <line>28</line>
    </call>
    <call>
    <function>DirectController-&gt;__call</function>
    <file>/home/hd/public_html/em/library/Am/Controller.php</file>
    <line>118</line>
    </call>
    <call>
    <function>Am_Controller-&gt;dispatch</function>
    <file>/home/hd/public_html/em/library/Zend/Controller/Dispatcher/Standard.php</file>
    <line>308</line>
    </call>
    <call>
    <function>Zend_Controller_Dispatcher_Standard-&gt;dispatch</function>
    <file>/home/hd/public_html/em/library/Zend/Controller/Front.php</file>
    <line>954</line>
    </call>
    <call>
    <function>Zend_Controller_Front-&gt;dispatch</function>
    <file>/home/hd/public_html/em/library/Am/App.php</file>
    <line>1985</line>
    </call>
    <call>
    <function>Am_App-&gt;run</function>
    <file>/home/hd/public_html/em/index.php</file>
    <line>92</line>
    </call>
    </trace>
    </invoice-log-item>
  4. jenolan

    jenolan aMember Coder

    Joined:
    Nov 3, 2006
    Messages:
    493
    Assuming you do not need help with the mail itself, goto library/am/paysystem/transaction/incoming.php find
    Code:
            if (empty($this->invoice->_autoCreated) && !$this->validateTerms())
                throw new Am_Exception_Paysystem_TransactionInvalid("Subscriptions terms in the IPN does not match subscription terms in our Invoice");
    
    change like this...
    Code:
            if (empty($this->invoice->_autoCreated) && !$this->validateTerms())
            {
                // Add mail call BEFORE exception is raised....
                throw new Am_Exception_Paysystem_TransactionInvalid("Subscriptions terms in the IPN does not match subscription terms in our Invoice");
            }
    
  5. netserv3

    netserv3 aMember Pro Customer

    Joined:
    Aug 29, 2006
    Messages:
    19
    Ok, I will try it, but these changes will be removed with updates and there are other types of IPN failure possible as well.

    1. I want to do this in either the plugin bluesnap (old name plimus) or in site.php
    2. The email should be sent on any type of error in processing the IPN post.

Share This Page