PayPal Subscriptions issue?

davez

Member
I'm setting up a PayPal Subscription for the first time and am troubleshooting via the Fabrik Log. I end up getting a functional query that pulls the correct data from my subscriptions table. But when I debug editing the plugins/fabrik_form/paypal/scripts/paypal.php file, I'm finding that the query is still outputting null for the subscription object.
Code:
if ($this->isSubscription($params))
     {
       $subTable = JModelLegacy::getInstance('List', 'FabrikFEModel');
       $subTable->setId((int) $params->get('paypal_subs_table'));

       $idEl  = FabrikString::safeColName($params->get('paypal_subs_id', ''));
       $durationEl  = FabrikString::safeColName($params->get('paypal_subs_duration', ''));
       $durationPerEl = FabrikString::safeColName($params->get('paypal_subs_duration_period', ''));
       $name  = $params->get('paypal_subs_name', '');

       $subDb = $subTable->getDb();
       $query = $subDb->getQuery(true);
       $query->select('*, ' . $durationEl . ' AS p3, ' . $durationPerEl . ' AS t3, ' . $subDb->q($itemRaw) . ' AS item_number')
         ->from($subTable->getTable()->db_table_name)
         ->where($idEl . ' = ' . $subDb->quote($itemRaw));
       $subDb->setQuery($query);
       
       // Log the query
       $this->doLog('fabrik.paypal.onAfterProcess.debug', "Subscription query: " . (string) $query);
       $sub = $subDb->loadObject();
       
       if (is_object($sub))
So, even though I have a valid $query, I'm not getting an object out of $sub. I noticed the JModelLegacy at the top. Is this a legacy issue?
 
One more note. If I add the following code just before if (is_object($sub)) it works just fine:
Code:
       $db = JFactory::getDBO();
       $db->setQuery($query);
       $sub = $db->loadObject();
So, it just uses the JFactory to run the query instead of the other method.
 
I'll need to set up a test. No, the "legacy" part isn't an issue. We do the $subTable->getDb() so that we can allow having the subs table on a different database. The JFactory::getDbo() methods only returns the default J! database. But getDb() should return a valid dbo for whatever connection you've selected for the subs.

It might take a while to set up a test case here, as I just had to rebuild my main test server after an "accident", and lost my main PayPal / subs test setup.

-- hugh
 
If it helps, the functional query that I get is the following:

SELECT *, `fodm_subscriptions`.`duration` AS p3, `fodm_subscriptions`.`period` AS t3, '1' AS item_number
FROM fodm_subscriptions
WHERE `fodm_subscriptions`.`id` = '1'

This query works if I toss it into phpMyAdmin. And it works if I use JFactory. But no object is created when it flows normally through the getDb() that's in the paypal.php file.

fodm is not the joomla prefix. This subscriptions table is outside of the Joomla naming scheme. The subscriptions table is set up as a list in Fabrik. Could something be wrong with my table structure?

Sorry about the 'accident'.
 
I'm just surprised it's not erroring out with a meaningful error message.

I'll try and find time soon to test it here.

-- hugh
 
Oh, it is giving a message: "Could not determine subscription period, please check your settings." That's why I looked in the code, because I seemed to have set up everything properly and the Fabrik Log pumped out a query that I could run successfully on the database.

When I was first setting it up, the Log was giving me queries that would not run. But once I got the Purchase Item set up properly in the Item and Subscription configuration tabs, the query became valid. It just isn't working in the paypal.php code.
 
I found the issue.
Code:
$subTable = JModelLegacy::getInstance('List', 'FabrikFEModel');
       $subTable->setId((int) $params->get('paypal_subs_table'));

       $idEl  = FabrikString::safeColName($params->get('paypal_subs_id', ''));
       $durationEl  = FabrikString::safeColName($params->get('paypal_subs_duration', ''));
       $durationPerEl = FabrikString::safeColName($params->get('paypal_subs_duration_period', ''));
       $name  = $params->get('paypal_subs_name', '');

       $subDb = $subTable->getDb();
       $query = $subDb->getQuery(true);
       $query->select('*, ' . $durationEl . ' AS p3, ' . $durationPerEl . ' AS t3, ' . $subDb->q($itemRaw) . ' AS item_number')
         ->from($subTable->getTable()->db_table_name)
         ->where($idEl . ' = ' . $subDb->quote($itemRaw));
       $subDb->setQuery($query);
       // Log the query
       //$this->doLog('fabrik.paypal.onAfterProcess.debug', "Subscription query: " . (string) $query);
If I simply comment out the doLog line, it works just fine. Weird.
 
And the logging works if I put it after the object is created:
Code:
      $subDb->setQuery($query);
       $sub = $subDb->loadObject();
       // Log the query
       $this->doLog('fabrik.paypal.onAfterProcess.debug', "Subscription query: " . (string) $query);
 
Well that is truly weird. The doLoag() method does write to the database, through J!'s standard table API, but it should be on a different database instance.

Can you try moving the log line to before the setQuery()?

Code:
       // Log the query
       $this->doLog('fabrik.paypal.onAfterProcess.debug', "Subscription query: " . (string) $query);
       $subDb->setQuery($query);
       $sub = $subDb->loadObject();

We need to log the query before executing it, in case it blows up, to at least leave some spoor for subsequent forensics..

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top