1

I am trying to call OmniPay from a ChronoForms v5 form in Joomla! 3 running PHP 5,6. I have made some progress but am hitting problems with paths and Name Spaces and could use some help.

After a struggle I have OmniPay installed from Composer in a folder /components/com_chronoforms5/extras/omnipay/ and I want to call the SecurePay path from a Custom Code action in a ChronoForm using code like this:

<?php
require (JPATH_SITE.'/components/com_chronoforms5/extras/omnipay/vendor/autoload.php');
use Omnipay\Omnipay;
$gateway = Omnipay::create('SecurePay');
?>

This works partially but gives me a Class not found error. I dug further and found that the Composer autoload_classmap.php file is generating an incorrect folder path which is missing the /vendor/ folder shown above.

Changing the autoload_classmap.php file to add this appears to create the correct paths in the returned array. (Though I suspect that the array is incomplete.) Here's the change I made:

$vendorDir = dirname(dirname(__FILE__));
// $baseDir = dirname($vendorDir); // << replace this line
$baseDir = $vendorDir; // << with this

With these changes the ClassLoader Object appears to have valid paths e.g.

[Omnipay\SecurePay\] => Array ( 
  [0] => /home/ . . ./components/com_chronoforms5/extras/omnipay/vendor/omnipay/securepay/src
) 

But my code to call the gateway still gives me a Fatal Error from the $gateway = line of the first code snippet above: Fatal error: Class 'Omnipay\Omnipay' not found

There is an added complication that the code is being executed in another NameSpace: 'GCore'. I have tried various combinations of prefix slashes, so far without success e.g. use \Omnipay\Omnipay

I am now at the point where my very limited knowledge of Composer and NameSpaces has run out. Any suggestions would be appreciated.

GreyHead
  • 230
  • 3
  • 23

0 Answers0