Skip to content

Commit 1ba32aa

Browse files
committed
Add example how to use Stripe update request
1 parent 97c9510 commit 1ba32aa

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

example/index.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,47 @@
241241
));
242242
});
243243

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+
244285
// create gateway unstore
245286
$app->get('/gateways/{name}/unstore', function($name) use ($app) {
246287
$gateway = Omnipay\Common\GatewayFactory::create($name);

example/views/gateway.twig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ $response = $gateway->initialize($params);</pre>
4545
{% if gateway.supportsStore() %}
4646
<li><a href="/gateways/{{gateway.shortName}}/store">store()</a></li>
4747
{% endif %}
48+
{% if gateway.supportsUpdate() %}
49+
<li><a href="/gateways/{{gateway.shortName}}/update">update()</a></li>
50+
{% endif %}
4851
{% if gateway.supportsUnstore() %}
4952
<li><a href="/gateways/{{gateway.shortName}}/unstore">unstore()</a></li>
5053
{% endif %}

0 commit comments

Comments
 (0)