I'm trying to use the Omnipay API with the Pin gateway but having issues.
I've run composer.phar locally with this in the composer.json file:
{
"require": {
"omnipay/omnipay": "~2.0"
}
}
The composer "vendor" folder now resides at "classes/libs/vendor" on my site.
I have this payment class:
class Payment extends BasicClass {
public function charge() {
require "libs/vendor/autoload.php";
use Omnipay\Omnipay;
$gateway = GatewayFactory::create('Pin');
$gateway->setSecretKey($this->config->secretKey);
}
}
When calling:
$topup = new Payment();
$topup->charge();
I get a parse error, PHP takes issue with my use Omnipay\Omnipay
line.
Very confused as all Omnipay documentation seems to use this syntax.
I've tried the require and use lines outside the class, but that did not help.
Thanks for everyone's help.
You have to use the use
operator outside the class definition.
From PHP documentation :
Scoping rules for importing
The use keyword must be declared in the outermost scope of a file (the global scope) or inside namespace declarations. This is because the importing is done at compile time and not runtime, so it cannot be block scoped.
http://php.net/manual/en/language.namespaces.importing.php#language.namespaces.importing.scope