Skip to content

Commit 2442acc

Browse files
committed
Merge pull request #19 from alexandernst/token-factory
Token factory
2 parents ecca8c1 + fa3269a commit 2442acc

File tree

4 files changed

+57
-31
lines changed

4 files changed

+57
-31
lines changed

docs/get-it-started.md

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -85,37 +85,21 @@ class PaypalController extends CController
8585

8686
$payum = $this->getPayum();
8787

88-
$tokenStorage = $payum->getTokenStorage();
8988
$storage = $payum->getRegistry()->getStorage(
9089
'PaymentDetails',
9190
$paymentName
9291
);
9392

94-
$paymentDetails = $storage->createModel();
95-
$paymentDetails['PAYMENTREQUEST_0_CURRENCYCODE'] = 'USD';
96-
$paymentDetails['PAYMENTREQUEST_0_AMT'] = 1.23;
97-
$storage->updateModel($paymentDetails);
93+
$details = $storage->createModel();
94+
$details['PAYMENTREQUEST_0_CURRENCYCODE'] = 'USD';
95+
$details['PAYMENTREQUEST_0_AMT'] = 1.23;
96+
$storage->updateModel($details);
97+
98+
$captureToken = $payum->getTokenFactory()->createCaptureToken($paymentName, $details, 'paypal/done');
9899

99-
$doneToken = $tokenStorage->createModel();
100-
$doneToken->setPaymentName($paymentName);
101-
$doneToken->setDetails($storage->getIdentificator($paymentDetails));
102-
$doneToken->setTargetUrl(
103-
$this->createAbsoluteUrl('paypal/done', array('payum_token' => $doneToken->getHash()))
104-
);
105-
$tokenStorage->updateModel($doneToken);
106-
107-
$captureToken = $tokenStorage->createModel();
108-
$captureToken->setPaymentName('paypal');
109-
$captureToken->setDetails($storage->getIdentificator($paymentDetails));
110-
$captureToken->setTargetUrl(
111-
$this->createAbsoluteUrl('payment/capture', array('payum_token' => $captureToken->getHash()))
112-
);
113-
$captureToken->setAfterUrl($doneToken->getTargetUrl());
114-
$tokenStorage->updateModel($captureToken);
115-
116-
$paymentDetails['RETURNURL'] = $captureToken->getTargetUrl();
117-
$paymentDetails['CANCELURL'] = $captureToken->getTargetUrl();
118-
$storage->updateModel($paymentDetails);
100+
$details['RETURNURL'] = $captureToken->getTargetUrl();
101+
$details['CANCELURL'] = $captureToken->getTargetUrl();
102+
$storage->updateModel($details);
119103

120104
$this->redirect($captureToken->getTargetUrl());
121105
}

src/Payum/YiiExtension/PaymentController.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22
namespace Payum\YiiExtension;
33

4-
use Payum\Core\Request\BinaryMaskStatusRequest;
54
use Payum\Core\Request\InteractiveRequestInterface;
65
use Payum\Core\Request\RedirectUrlInteractiveRequest;
76
//use Payum\Core\Request\Http\RedirectUrlInteractiveRequest; // see issue #17
@@ -22,17 +21,18 @@ public function actionCapture()
2221
$token = $this->getPayum()->getHttpRequestVerifier()->verify($_REQUEST);
2322
$payment = $this->getPayum()->getRegistry()->getPayment($token->getPaymentName());
2423

25-
$status = new BinaryMaskStatusRequest($token);
26-
$payment->execute($status);
27-
28-
$capture = new SecuredCaptureRequest($token);
29-
$payment->execute($capture);
24+
$payment->execute($capture = new SecuredCaptureRequest($token));
3025

3126
$this->getPayum()->getHttpRequestVerifier()->invalidate($token);
3227

3328
$this->redirect($token->getAfterUrl());
3429
}
3530

31+
public function actionNotify()
32+
{
33+
throw new \LogicException('Not Implemented');
34+
}
35+
3636
public function handleException(\CExceptionEvent $event)
3737
{
3838
if (false == $event->exception instanceof InteractiveRequestInterface) {

src/Payum/YiiExtension/PayumComponent.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<?php
22
namespace Payum\YiiExtension;
33

4+
\Yii::import('Payum\YiiExtension\TokenFactory', true);
5+
46
use Payum\Core\PaymentInterface;
57
use Payum\Core\Registry\RegistryInterface;
68
use Payum\Core\Registry\SimpleRegistry;
9+
use Payum\Core\Security\GenericTokenFactoryInterface;
710
use Payum\Core\Security\HttpRequestVerifierInterface;
811
use Payum\Core\Security\PlainHttpRequestVerifier;
912
use Payum\Core\Storage\StorageInterface;
@@ -25,6 +28,11 @@ class PayumComponent extends \CApplicationComponent
2528
*/
2629
public $tokenStorage;
2730

31+
/**
32+
* @var GenericTokenFactoryInterface
33+
*/
34+
public $tokenFactory;
35+
2836
/**
2937
* @var HttpRequestVerifierInterface
3038
*/
@@ -40,6 +48,7 @@ public function init()
4048
$this->registry = new SimpleRegistry($this->payments, $this->storages, null);
4149

4250
$this->httpRequestVerifier = new PlainHttpRequestVerifier($this->tokenStorage);
51+
$this->tokenFactory = new TokenFactory($this->tokenStorage, $this->registry, 'payment/capture', 'payment/notify');
4352
}
4453

4554
/**
@@ -50,6 +59,14 @@ public function getTokenStorage()
5059
return $this->tokenStorage;
5160
}
5261

62+
/**
63+
* @return GenericTokenFactoryInterface
64+
*/
65+
public function getTokenFactory()
66+
{
67+
return $this->tokenFactory;
68+
}
69+
5370
/**
5471
* @return HttpRequestVerifierInterface
5572
*/
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
namespace Payum\YiiExtension;
3+
4+
use Payum\Core\Security\AbstractGenericTokenFactory;
5+
6+
class TokenFactory extends AbstractGenericTokenFactory
7+
{
8+
9+
/**
10+
* @param string $path
11+
* @param array $parameters
12+
*
13+
* @return string
14+
*/
15+
protected function generateUrl($path, array $parameters = array())
16+
{
17+
$ampersand = '&';
18+
$schema = '';
19+
20+
return
21+
\Yii::app()->getRequest()->getHostInfo($schema).
22+
\Yii::app()->createUrl(trim($path,'/'),$parameters, $ampersand)
23+
;
24+
}
25+
}

0 commit comments

Comments
 (0)