Author Topic: Core/Payment/IATS.php code bugs/fixes  (Read 9900 times)

Offline adixon

  • I post frequently
  • ***
  • Posts: 314
  • Karma: 19
    • Blackfly Solutions
Core/Payment/IATS.php code bugs/fixes
« on: May 13, 2010, 07:27:03 am »
I was notified recently that that recurring payments were not being handled by the IATS contributed processor. It turns out there were two problems:

1. It wasn't handling the 'indefinite # of intervals' option that had been introduced in the past year or so. I noticed that there was another processor that might not be handling it either - in IATS case, there was a test of # of intervals > 1, so that it could handle a single recurring interval the same was as a single payment. Conclusion: the new code now converts "indefinitely" to 10 years. I think it would have been a good idea for those of us maintaining payment processors to have a way to wave big red flags when this change was introduced ...

2. I hadn't understood how CiviCRM handles the additional recurring payments after the first one - CiviCRM requires some kind of callback from the payment processor each time a payment goes through, to enable CiviCRM to add the payment. I don't think IATS does this, so even if the additional recurring payments are now going through, they won't get recorded in CiviCRM (i.e. it'll have to be manually imported).

There were a couple of other bugs or potential bugs in the code that have been fixed as well. You can use the attached diff to patch both 3.0 and 3.1 (likely 3.2 as well, though I haven't tested it).

Please reply here &/or notify me directly of any issues.

Big thanks to Matthew Clarke for pretty much all of the hard work here.

Offline micheas

  • I’m new here
  • *
  • Posts: 14
  • Karma: 1
    • Green Campaigns
Re: Core/Payment/IATS.php code bugs/fixes
« Reply #1 on: December 16, 2010, 06:08:57 am »
These seem to be included in civicrm 3.3.1

However when I try using a donate page that uses IATS nothing is returned, and nothing shows up in the logs.

If I change to paypal the form works, so I strongly suspect that it is something related to the upgrade.

The page was working with civicrm 3.0.2 (iirc)

Offline adixon

  • I post frequently
  • ***
  • Posts: 314
  • Karma: 19
    • Blackfly Solutions
Re: Core/Payment/IATS.php code bugs/fixes
« Reply #2 on: December 16, 2010, 06:12:32 am »
Can you provide a fuller error report?

1. Drupal/Joomla?

2. "nothing is returned" - are you talking about what's on your screen, or in the admin, or on the IATS interface? etc.

Offline micheas

  • I’m new here
  • *
  • Posts: 14
  • Karma: 1
    • Green Campaigns
Re: Core/Payment/IATS.php code bugs/fixes
« Reply #3 on: December 16, 2010, 10:46:52 am »
Thanks a lot for your reply.

This is with Joomla 1.5 and civicrm 3.3.1

By nothing I mean that when I try accessing the donation form wget returns:
Code: [Select]
Connecting to www.marininstitute.org|38.99.65.117|:80... connected.
HTTP request sent, awaiting response... No data received.
Retrying.

I cannot even figure out where to put
Code: [Select]
echo 'I am here';
 die;

to narrow the problem down. No messages in syslog. nothing in the apache log.

And if I change the processor to paypal everything works, with no warnings. So I think it is the IATS code, but I am just guessing, it could be a side effect for all I know.

Offline adixon

  • I post frequently
  • ***
  • Posts: 314
  • Karma: 19
    • Blackfly Solutions
Re: Core/Payment/IATS.php code bugs/fixes
« Reply #4 on: December 16, 2010, 11:07:08 am »
1. The first thing I notice is that I believe the IATS processor db entries are in 3.3, so an upgrade might scramble that entry. See the message at the top of this child forum in case that's clearer. In any case, do look at the information about the processor to make sure it's still there and okay.

2. A blank screen with no logging - sounds like it's maybe hung up trying to contact IATS in the back end? Try putting in some break points in the IATS processor code (look for a file called IATS.php).

Offline micheas

  • I’m new here
  • *
  • Posts: 14
  • Karma: 1
    • Green Campaigns
Re: Core/Payment/IATS.php code bugs/fixes
« Reply #5 on: December 16, 2010, 12:00:33 pm »
I have been munging IATS.php but cannot figure out what a meaningful breakpoint is.

(maybe because I have never really learned php)

Is there any hints you might have for me?

Offline joshstuart

  • I post occasionally
  • **
  • Posts: 41
  • Karma: 2
    • ACORN Canada
  • CiviCRM version: 4.0
  • CMS version: Joomla 1.6
Re: Core/Payment/IATS.php code bugs/fixes
« Reply #6 on: January 10, 2011, 11:07:12 am »
@Micheas - When I reached out to IATS (having a similar problem) they informed me that I was using an old version (2005) of the IATS.php file and offered up the most revised version. 

Might be worth a shot.

Offline adixon

  • I post frequently
  • ***
  • Posts: 314
  • Karma: 19
    • Blackfly Solutions
Re: Core/Payment/IATS.php code bugs/fixes
« Reply #7 on: January 10, 2011, 01:06:58 pm »
That would have been a previous version - the latest API has been in CIviCRM for the past couple of versions.

Offline joshstuart

  • I post occasionally
  • **
  • Posts: 41
  • Karma: 2
    • ACORN Canada
  • CiviCRM version: 4.0
  • CMS version: Joomla 1.6
Re: Core/Payment/IATS.php code bugs/fixes
« Reply #8 on: January 11, 2011, 07:06:53 am »
hmmm. Since we updated to 3.3.1 we've been getting a 500 error on all our 'live' donation pages - and I'm trying to figure out why. 

I'd updated the payment processor info from IATS.ticketmaster.com to Iatspayments.com, so that'd not it. 

We're running Joomla! 1.5.21.


Offline Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Core/Payment/IATS.php code bugs/fixes
« Reply #9 on: January 11, 2011, 10:42:57 am »
Try adding this function to CRM/Core/Payment/IATS.php


    static function &singleton( $mode, &$paymentProcessor ) {
        $processorName = $paymentProcessor['name'];
        if (self::$_singleton[$processorName] === null ) {
            self::$_singleton[$processorName] = new CRM_Core_Payment_IATS( $mode, $paymentProcessor );
        }
        return self::$_singleton[$processorName];
    }
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Offline Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Core/Payment/IATS.php code bugs/fixes
« Reply #10 on: January 11, 2011, 11:32:35 am »
Patch for IATS

Index: CRM/Core/Payment/IATS.php
===================================================================
--- CRM/Core/Payment/IATS.php   (revision 31681)
+++ CRM/Core/Payment/IATS.php   (working copy)
@@ -63,7 +63,13 @@
             return self::error('Invalid configuration:'.$currencyID.', you must use one of '.self::CURRENCIES.' with IATS');
         }
     }
-
+    static function &singleton( $mode, &$paymentProcessor ) {
+        $processorName = $paymentProcessor['name'];
+        if (self::$_singleton[$processorName] === null ) {
+            self::$_singleton[$processorName] = new CRM_Core_Payment_IATS( $mode, $paymentProcessor );
+        }
+        return self::$_singleton[$processorName];
+    }
     function doDirectPayment( &$params ) {
         // $result = '';
         //       foreach($params as $key => $value) {


Patch for Barclays

Index: civicrm/CRM/Core/Payment/Barclay.php
===================================================================
--- civicrm/CRM/Core/Payment/Barclay.php   (revision 157)
+++ civicrm/CRM/Core/Payment/Barclay.php   (working copy)
@@ -56,7 +56,14 @@
         $this->_paymentProcessor = $paymentProcessor;
         $this->_processorName    = ts('Barclay');
     }
-
+   
+    static function &singleton( $mode, &$paymentProcessor ) {
+        $processorName = $paymentProcessor['name'];
+        if (self::$_singleton[$processorName] === null ) {
+            self::$_singleton[$processorName] = new CRM_Core_Payment_Barclay( $mode, $paymentProcessor );
+        }
+        return self::$_singleton[$processorName];
+    }
     /**********************************************************
      * This function is set up and put here to make the mapping of fields
      * from the params object  as visually clear as possible for easy editing


Patch for ChasePaymentTech

Index: civicrm/CRM/Core/Payment/ChasePaymentTech.php
===================================================================
--- civicrm/CRM/Core/Payment/ChasePaymentTech.php   (revision 157)
+++ civicrm/CRM/Core/Payment/ChasePaymentTech.php   (working copy)
@@ -57,8 +57,15 @@
        $this->_mode = $mode;                         // live or test
        $this->_paymentProcessor = $paymentProcessor;
    }
+   
+    static function &singleton( $mode, &$paymentProcessor ) {
+        $processorName = $paymentProcessor['name'];
+        if (self::$_singleton[$processorName] === null ) {
+            self::$_singleton[$processorName] = new CRM_Core_Payment_ChasePaymentTech( $mode, $paymentProcessor );
+        }
+        return self::$_singleton[$processorName];
+    }
 
-
    /**********************************************************
     * This function sends request and receives response from
     * the processor
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Offline joshstuart

  • I post occasionally
  • **
  • Posts: 41
  • Karma: 2
    • ACORN Canada
  • CiviCRM version: 4.0
  • CMS version: Joomla 1.6
Re: Core/Payment/IATS.php code bugs/fixes
« Reply #11 on: January 11, 2011, 01:45:32 pm »
hmmm, I dropped that patch into the correct spot (cut/pasted below) but not I'm getting this error on my 'live' donation/paid events pages:

Fatal error: Access to undeclared static property: CRM_Core_Payment_IATS::$_singleton in /home/acorncanada/www/www/administrator/components/com_civicrm/civicrm/CRM/Core/Payment/IATS.php on line 68

Thanks for the help, I appreciate it.

Cut/paste from IATS.php below:
=========================================

            return self::error('Invalid configuration:'.$currencyID.', you must use one of '.self::CURRENCIES.' with IATS');
        }
    }
 static function &singleton( $mode, &$paymentProcessor ) {
        $processorName = $paymentProcessor['name'];
        if (self::$_singleton[$processorName] === null ) {
            self::$_singleton[$processorName] = new CRM_Core_Payment_IATS( $mode, $paymentProcessor );
        }
        return self::$_singleton[$processorName];
    }
    function doDirectPayment( &$params ) {
        // $result = '';
        //       foreach($params as $key => $value) {

Offline Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Core/Payment/IATS.php code bugs/fixes
« Reply #12 on: January 11, 2011, 01:59:57 pm »
Ah - it's missing this too

    /**
     * We only need one instance of this object. So we use the singleton
     * pattern and cache the instance in this variable
     *
     * @var object
     * @static
     */
    static private $_singleton = null;
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Offline joshstuart

  • I post occasionally
  • **
  • Posts: 41
  • Karma: 2
    • ACORN Canada
  • CiviCRM version: 4.0
  • CMS version: Joomla 1.6
Re: Core/Payment/IATS.php code bugs/fixes
« Reply #13 on: January 11, 2011, 02:44:05 pm »
Amazing!

Thanks so much for the help.  Next round of Make-it-happens I'll make a donation in your honor!   :D


Offline Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Core/Payment/IATS.php code bugs/fixes
« Reply #14 on: January 11, 2011, 02:44:51 pm »
Ah but there's still time .. we're about to push the deadlines back slightly :-)
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute