|
241 | 241 | ));
|
242 | 242 | });
|
243 | 243 |
|
| 244 | +// create gateway update |
| 245 | +$app->get('/gateways/{name}/update', function($name) use ($app) { |
| 246 | + $gateway = Omnipay\Common\GatewayFactory::create($name); |
| 247 | + $sessionVar = 'omnipay.'.$gateway->getShortName(); |
| 248 | + $gateway->initialize((array) $app['session']->get($sessionVar)); |
| 249 | + |
| 250 | + $params = $app['session']->get($sessionVar.'.update', array()); |
| 251 | + $card = new Omnipay\Common\CreditCard($app['session']->get($sessionVar.'.card')); |
| 252 | + |
| 253 | + return $app['twig']->render('request.twig', array( |
| 254 | + 'gateway' => $gateway, |
| 255 | + 'method' => 'update', |
| 256 | + 'params' => $params, |
| 257 | + 'card' => $card->getParameters(), |
| 258 | + )); |
| 259 | +}); |
| 260 | + |
| 261 | +// submit gateway update |
| 262 | +$app->post('/gateways/{name}/update', function($name) use ($app) { |
| 263 | + $gateway = Omnipay\Common\GatewayFactory::create($name); |
| 264 | + $sessionVar = 'omnipay.'.$gateway->getShortName(); |
| 265 | + $gateway->initialize((array) $app['session']->get($sessionVar)); |
| 266 | + |
| 267 | + // load POST data |
| 268 | + $params = $app['request']->get('params'); |
| 269 | + $card = $app['request']->get('card'); |
| 270 | + |
| 271 | + // save POST data into session |
| 272 | + $app['session']->set($sessionVar.'.update', $params); |
| 273 | + $app['session']->set($sessionVar.'.card', $card); |
| 274 | + |
| 275 | + $params['card'] = $card; |
| 276 | + $params['clientIp'] = $app['request']->getClientIp(); |
| 277 | + $response = $gateway->update($params)->send(); |
| 278 | + |
| 279 | + return $app['twig']->render('response.twig', array( |
| 280 | + 'gateway' => $gateway, |
| 281 | + 'response' => $response, |
| 282 | + )); |
| 283 | +}); |
| 284 | + |
244 | 285 | // create gateway unstore
|
245 | 286 | $app->get('/gateways/{name}/unstore', function($name) use ($app) {
|
246 | 287 | $gateway = Omnipay\Common\GatewayFactory::create($name);
|
|
0 commit comments