Skip to content

Commit

Permalink
Release 0.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
makasim committed Jan 1, 2015
1 parent c324588 commit a2290fa
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 7 deletions.
13 changes: 13 additions & 0 deletions config/module.config.routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@
),
),
),
'payum_refund_do' => array(
'type' => 'Segment',
'options' => array(
'route' => '/payment/refund[/:payum_token]',
'constraints' => array(
'payum_token' => '[a-zA-Z0-9]+'
),
'defaults' => array(
'controller' => 'PayumRefund',
'action' => 'do'
),
),
),
),
),
);
14 changes: 14 additions & 0 deletions config/service/controller.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use Payum\PayumModule\Controller\AuthorizeController;
use Payum\PayumModule\Controller\CaptureController;
use Payum\PayumModule\Controller\NotifyController;
use Payum\PayumModule\Controller\RefundController;

return array(
'factories' => array(
Expand All @@ -17,5 +19,17 @@
// Construct Authorize controller with required Payum Registry and HttpRequestVerifier dependencies.
return new AuthorizeController($sm->get('payum'), $sm->get('payum.security.http_request_verifier'));
},
'PayumNotify' => function ($cm) {
$sm = $cm->getServiceLocator();

// Construct Capture controller with required Payum Registry and HttpRequestVerifier dependencies.
return new NotifyController($sm->get('payum'), $sm->get('payum.security.http_request_verifier'));
},
'PayumRefund' => function ($cm) {
$sm = $cm->getServiceLocator();

// Construct Capture controller with required Payum Registry and HttpRequestVerifier dependencies.
return new RefundController($sm->get('payum'), $sm->get('payum.security.http_request_verifier'));
},
),
);
8 changes: 4 additions & 4 deletions docs/get-it-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ return array(
'hash'
),
'payments' => array(
'paypal_es' => PaymentFactory::create(new Api(new Curl(), array(
'paypal_ec' => PaymentFactory::create(new Api(new Curl(), array(
'username' => 'REPLACE WITH YOURS',
'password' => 'REPLACE WITH YOURS',
'signature' => 'REPLACE WITH YOURS',
Expand Down Expand Up @@ -112,16 +112,16 @@ class IndexController extends AbstractActionController
{
$storage = $this->getServiceLocator()->get('payum')->getStorage('Application\Model\PaymentDetails');

$details = $storage->createModel();
$details = $storage->create();
$details['PAYMENTREQUEST_0_CURRENCYCODE'] = 'EUR';
$details['PAYMENTREQUEST_0_AMT'] = 1.23;
$storage->updateModel($details);
$storage->update($details);

// FIXIT: I dont know how to inject controller plugin to the service.
$this->getServiceLocator()->get('payum.security.token_factory')->setUrlPlugin($this->url());

$captureToken = $this->getServiceLocator()->get('payum.security.token_factory')->createCaptureToken(
'paypal_es', $details, 'payment_done'
'paypal_ec', $details, 'payment_done'
);

$this->redirect()->toUrl($captureToken->getTargetUrl());
Expand Down
41 changes: 41 additions & 0 deletions src/Payum/PayumModule/Controller/RefundController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
namespace Payum\PayumModule\Controller;

use Payum\Core\Reply\HttpRedirect;
use Payum\Core\Reply\HttpResponse;
use Payum\Core\Reply\ReplyInterface;
use Payum\Core\Request\Refund;
use Zend\Http\Response;

class RefundController extends PayumController
{
public function doAction()
{
$token = $this->getHttpRequestVerifier()->verify($this->getRequest());
$this->getHttpRequestVerifier()->invalidate($token);

$payment = $this->getPayum()->getPayment($token->getPaymentName());

try {
$payment->execute(new Refund($token));
} catch (ReplyInterface $reply) {
if ($reply instanceof HttpRedirect) {
$this->redirect()->toUrl($reply->getUrl());
}

if ($reply instanceof HttpResponse) {
$this->getResponse()->setContent($reply->getContent());

$response = new Response();
$response->setStatusCode(200);
$response->setContent($reply->getContent());

return $response;
}

throw new \LogicException('Unsupported reply', null, $reply);
}

$this->redirect()->toUrl($token->getAfterUrl());
}
}
4 changes: 2 additions & 2 deletions src/Payum/PayumModule/Security/HttpRequestVerifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function verify($httpRequest)
if ($hash instanceof Token) {
$token = $hash;
} else {
if (false == $token = $this->tokenStorage->findModelById($hash)) {
if (false == $token = $this->tokenStorage->find($hash)) {
//TODO here again should be 404
throw new InvalidArgumentException(sprintf('A token with hash `%s` could not be found.', $hash));
}
Expand All @@ -68,6 +68,6 @@ public function verify($httpRequest)
*/
public function invalidate(TokenInterface $token)
{
$this->tokenStorage->deleteModel($token);
$this->tokenStorage->delete($token);
}
}
3 changes: 2 additions & 1 deletion src/Payum/PayumModule/Security/TokenFactoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public function createService(ServiceLocatorInterface $serviceLocator)
$serviceLocator->get('payum'),
'payum_capture_do',
'payum_notify_do',
'payum_authorize_do'
'payum_authorize_do',
'payum_refund_do'
);
}
}

0 comments on commit a2290fa

Please sign in to comment.