diff --git a/config/module.config.routes.php b/config/module.config.routes.php index d3f42d0..de9a8fe 100644 --- a/config/module.config.routes.php +++ b/config/module.config.routes.php @@ -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' + ), + ), + ), ), ), ); diff --git a/config/service/controller.config.php b/config/service/controller.config.php index 25d20e0..5c9b4ad 100644 --- a/config/service/controller.config.php +++ b/config/service/controller.config.php @@ -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( @@ -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')); + }, ), ); \ No newline at end of file diff --git a/docs/get-it-started.md b/docs/get-it-started.md index a85447f..7b5ef72 100644 --- a/docs/get-it-started.md +++ b/docs/get-it-started.md @@ -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', @@ -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()); diff --git a/src/Payum/PayumModule/Controller/RefundController.php b/src/Payum/PayumModule/Controller/RefundController.php new file mode 100644 index 0000000..884bf9b --- /dev/null +++ b/src/Payum/PayumModule/Controller/RefundController.php @@ -0,0 +1,41 @@ +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()); + } +} \ No newline at end of file diff --git a/src/Payum/PayumModule/Security/HttpRequestVerifier.php b/src/Payum/PayumModule/Security/HttpRequestVerifier.php index ac92d12..8908ad4 100644 --- a/src/Payum/PayumModule/Security/HttpRequestVerifier.php +++ b/src/Payum/PayumModule/Security/HttpRequestVerifier.php @@ -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)); } @@ -68,6 +68,6 @@ public function verify($httpRequest) */ public function invalidate(TokenInterface $token) { - $this->tokenStorage->deleteModel($token); + $this->tokenStorage->delete($token); } } \ No newline at end of file diff --git a/src/Payum/PayumModule/Security/TokenFactoryFactory.php b/src/Payum/PayumModule/Security/TokenFactoryFactory.php index 0a86ba3..57d748e 100644 --- a/src/Payum/PayumModule/Security/TokenFactoryFactory.php +++ b/src/Payum/PayumModule/Security/TokenFactoryFactory.php @@ -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' ); } } \ No newline at end of file