Example #1
0
 /**
  * Get a list of supported gateways, in friendly format (e.g. PayPal_Express)
  */
 public static function find($directory = null)
 {
     $result = array();
     // find all gateways in the Billing directory
     $directory = dirname(__DIR__);
     $it = new RecursiveDirectoryIterator($directory);
     foreach (new RecursiveIteratorIterator($it) as $file) {
         $filepath = $file->getPathName();
         if ('Gateway.php' === substr($filepath, -11)) {
             // determine class name
             $type = substr($filepath, 0, -11);
             $type = str_replace(array($directory, DIRECTORY_SEPARATOR), array('', '_'), $type);
             $type = trim($type, '_');
             $class = Helper::getGatewayClassName($type);
             // ensure class exists and is not abstract
             if (class_exists($class)) {
                 $reflection = new ReflectionClass($class);
                 if (!$reflection->isAbstract() and $reflection->implementsInterface('\\Omnipay\\Common\\GatewayInterface')) {
                     $result[] = $type;
                 }
             }
         }
     }
     return $result;
 }
Example #2
0
 /**
  * Create a new gateway instance
  *
  * @param string               $class       Gateway name
  * @param ClientInterface|null $httpClient  A Guzzle HTTP Client implementation
  * @param HttpRequest|null     $httpRequest A Symfony HTTP Request implementation
  */
 public function create($class, ClientInterface $httpClient = null, HttpRequest $httpRequest = null)
 {
     $class = Helper::getGatewayClassName($class);
     if (!class_exists($class)) {
         throw new RuntimeException("Class '{$class}' not found");
     }
     return new $class($httpClient, $httpRequest);
 }
 /**
  * Create gateway service.
  *
  * @param ContainerBuilder $container
  * @param string           $name
  * @param array            $parameters
  */
 public function createGatewayService(ContainerBuilder $container, $name, array $parameters)
 {
     $type = $parameters['type'];
     $class = trim(Helper::getGatewayClassName($type), "\\");
     $definition = new Definition($class);
     $definition->setFactoryService('sylius.omnipay.gateway_factory')->setFactoryMethod('create')->setArguments(array($type));
     $reflection = new \ReflectionClass($class);
     foreach ($parameters['options'] as $optionName => $value) {
         $method = 'set' . ucfirst($optionName);
         if ($reflection->hasMethod($method)) {
             $definition->addMethodCall($method, array($value));
         }
     }
     $container->setDefinition(sprintf('sylius.omnipay.gateway.%s', $name), $definition);
     $this->gateways[$name] = isset($parameters['label']) ? $parameters['label'] : $name;
 }
 protected function resolve($name)
 {
     $config = $this->getConfig($name);
     if (is_null($config)) {
         throw new \UnexpectedValueException("Gateway [{$name}] is not defined.");
     }
     $gateway = $this->factory->create($config['driver']);
     $class = trim(Helper::getGatewayClassName($config['driver']), "\\");
     $reflection = new \ReflectionClass($class);
     foreach ($config['options'] as $optionName => $value) {
         $method = 'set' . ucfirst($optionName);
         if ($reflection->hasMethod($method)) {
             $gateway->{$method}($value);
         }
     }
     return $gateway;
 }
Example #5
0
 public function getProvidersAction()
 {
     $gateways = \Omnipay\Tool::getSupportedGateways();
     $available = [];
     $activeProviders = Model\Configuration::get("OMNIPAY.ACTIVEPROVIDERS");
     if (!is_array($activeProviders)) {
         $activeProviders = [];
     }
     foreach ($gateways as $gateway) {
         $class = \Omnipay\Common\Helper::getGatewayClassName($gateway);
         if (\Pimcore\Tool::classExists($class)) {
             if (!in_array($gateway, $activeProviders)) {
                 $available[] = ["name" => $gateway];
             }
         }
     }
     $this->_helper->json(array("data" => $available));
 }
Example #6
0
 /**
  * Underscored types should be resolved in a PSR-0 fashion.
  */
 public function testGetGatewayClassNameUnderscoreNamespace()
 {
     $class = Helper::getGatewayClassName('PayPal_Express');
     $this->assertEquals('\\Omnipay\\PayPal\\ExpressGateway', $class);
 }
 /**
  * Create a new gateway instance
  *
  * @param string                        $class           Gateway name
  * @param ClientInterface|null          $httpClient      A Guzzle HTTP Client implementation
  * @param HttpRequest|null              $httpRequest     A Symfony HTTP Request implementation
  * @param EventDispatcherInterface|null $eventDispatcher A Symfony event dispatcher implementation
  * @throws RuntimeException                              If no such gateway is found
  * @return GatewayInterface                              An object of class $class is created and returned
  */
 public function create($class, ClientInterface $httpClient = null, HttpRequest $httpRequest = null, EventDispatcherInterface $eventDispatcher = null)
 {
     $class = Helper::getGatewayClassName($class);
     if (!class_exists($class)) {
         throw new RuntimeException("Class '{$class}' not found");
     }
     if ($eventDispatcher === null) {
         $eventDispatcher = $this->getDefaultEventDispatcher();
     }
     return new $class($httpClient, $httpRequest, $eventDispatcher);
 }