/** * Get all available payment types */ private function PaymentTypes() { $gateways = Omnipay\Common\GatewayFactory::find(); $gateways = array_map(function ($name) { $factory = new Omnipay\Common\GatewayFactory(); return $factory->create($name); }, $gateways); return $gateways; }
/** * Get all available payment types */ private function PaymentTypes() { $factory = new \Omnipay\Common\GatewayFactory(); // since the omnipay gateway factory only returns gateways from the composer.json extra data, // we should merge it with user-defined gateways from Payment.allowed_gateways $gateways = array_unique(array_merge($factory->find(), array_keys(GatewayInfo::getSupportedGateways(false)))); $supportedGateways = array(); array_walk($gateways, function ($name, $index) use(&$supportedGateways, &$factory) { try { $instance = $factory->create($name); $supportedGateways[$name] = $instance; } catch (\Exception $e) { } }); return $supportedGateways; }
<?php require __DIR__ . '/../vendor/autoload.php'; // create basic Silex application $app = new Silex\Application(); $app->register(new Silex\Provider\SessionServiceProvider()); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/views')); // enable Silex debugging $app['debug'] = true; // root route $app->get('/', function () use($app) { $gateways = array_map(function ($name) { return Omnipay\Common\GatewayFactory::create($name); }, Omnipay\Common\GatewayFactory::find()); return $app['twig']->render('index.twig', array('gateways' => $gateways)); }); // gateway settings $app->get('/gateways/{name}', function ($name) use($app) { $gateway = Omnipay\Common\GatewayFactory::create($name); $sessionVar = 'omnipay.' . $gateway->getShortName(); $gateway->initialize((array) $app['session']->get($sessionVar)); return $app['twig']->render('gateway.twig', array('gateway' => $gateway, 'settings' => $gateway->getParameters())); }); // save gateway settings $app->post('/gateways/{name}', function ($name) use($app) { $gateway = Omnipay\Common\GatewayFactory::create($name); $sessionVar = 'omnipay.' . $gateway->getShortName(); $gateway->initialize((array) $app['request']->get('gateway')); // save gateway settings in session $app['session']->set($sessionVar, $gateway->getParameters()); // redirect back to gateway settings page