Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 0.15 for Laravel 5.1 #22

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
],
"require": {
"php": ">=5.3.2",
"illuminate/container": "~4.0",
"illuminate/routing": "~4.0",
"illuminate/support": "~4.0",
"payum/core": "0.15.*"
"illuminate/container": "~5.1",
"illuminate/routing": "~5.1",
"illuminate/support": "~5.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see It is not working with Laravel4 any more. I dont know, How many people uses Laravel5 in compare with Laravel4.

"payum/core": "1.0.*@dev"
},
"suggest": {
"payum/paypal-express-checkout-nvp": "If you want to use paypal express checkout nvp gateway",
Expand All @@ -54,7 +54,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "0.15-dev"
"dev-master": "1.0-dev"
}
},
"config": {
Expand Down
5 changes: 4 additions & 1 deletion src/Payum/LaravelPackage/Controller/AuthorizeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ public function doAction($payum_token)

$gateway = $this->getPayum()->getGateway($token->getGatewayName());

$gateway->execute(new Authorize($token));
$response = $this->convertReply($gateway->execute(new Authorize($token), true));

if($response)
return $response;

$this->getHttpRequestVerifier()->invalidate($token);

Expand Down
6 changes: 5 additions & 1 deletion src/Payum/LaravelPackage/Controller/CaptureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ public function doAction($payum_token)

$gateway = $this->getPayum()->getGateway($token->getGatewayName());

$gateway->execute(new Capture($token));

$response = $this->convertReply($gateway->execute(new Capture($token), true));

if($response)
return $response;

$this->getHttpRequestVerifier()->invalidate($token);

Expand Down
10 changes: 8 additions & 2 deletions src/Payum/LaravelPackage/Controller/NotifyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ public function doUnsafeAction(Request $request)
{
$gateway = $this->getPayum()->getGateway($request->get('gateway_name'));

$gateway->execute(new Notify(null));
$response = $this->convertReply($gateway->execute(new Notify(null), true));

if($response)
return $response;

return \Response::make(null, 204);
}
Expand All @@ -21,7 +24,10 @@ public function doAction(Request $request)

$gateway = $this->getPayum()->getGateway($token->getGatewayName());

$gateway->execute(new Notify($token));
$response = $this->convertReply($gateway->execute(new Notify($token), true));

if($response)
return $response;

return \Response::make(null, 204);
}
Expand Down
37 changes: 35 additions & 2 deletions src/Payum/LaravelPackage/Controller/PayumController.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
<?php
namespace Payum\LaravelPackage\Controller;

use Illuminate\Routing\Controllers\Controller;
use Illuminate\Routing\Controller;
use Payum\Core\Registry\RegistryInterface;
use Payum\Core\Security\HttpRequestVerifierInterface;

abstract class PayumController extends \Controller
use Payum\Core\Exception\LogicException;
use Payum\Core\Reply\HttpRedirect;
use Payum\Core\Reply\HttpResponse;
use Payum\Core\Reply\ReplyInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;

abstract class PayumController extends Controller
{
/**
* @return RegistryInterface
Expand All @@ -22,4 +29,30 @@ protected function getHttpRequestVerifier()
{
return \App::make('payum.security.http_request_verifier');
}

public function convertReply($reply)
{
if(!$reply instanceof ReplyInterface)
return;

$response = null;

if ($reply instanceof SymfonyHttpResponse) {
$response = $reply->getResponse();
} elseif ($reply instanceof HttpRedirect) {
$response = new RedirectResponse($reply->getUrl());
} elseif ($reply instanceof HttpResponse) {
$response = new Response($reply->getContent());
}
if ($response) {
return $response;
}

$ro = new \ReflectionObject($reply);
throw new LogicException(
sprintf('Cannot convert reply %s to Laravel response.', $ro->getShortName()),
null,
$reply
);
}
}
5 changes: 4 additions & 1 deletion src/Payum/LaravelPackage/Controller/RefundController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ public function doAction($payum_token)

$gateway = $this->getPayum()->getGateway($token->getGatewayName());

$gateway->execute(new Refund($token));
$response = $this->convertReply($gateway->execute(new Refund($token), true));

if($response)
return $response;

$this->getHttpRequestVerifier()->invalidate($token);

Expand Down
40 changes: 11 additions & 29 deletions src/Payum/LaravelPackage/PayumServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,11 @@ class PayumServiceProvider extends ServiceProvider
*/
public function boot()
{
$this->package('payum/payum-laravel-package');
\View::addNamespace('payum/payum', __DIR__.'/../../views');

$this->app->error(function(ReplyInterface $reply)
{
$response = null;

if ($reply instanceof SymfonyHttpResponse) {
$response = $reply->getResponse();
} elseif ($reply instanceof HttpResponse) {
$response = new Response($reply->getContent());
} elseif ($reply instanceof HttpRedirect) {
$response = new RedirectResponse($reply->getUrl());
}

if ($response) {
return $response;
}

$ro = new \ReflectionObject($reply);
throw new LogicException(
sprintf('Cannot convert reply %s to Laravel response.', $ro->getShortName()),
null,
$reply
);
});
$this->publishes([
__DIR__.'/../../config/config.php' => config_path('payum-laravel-package.php'),
]);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't it work in Laravel5?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer this way, cuz you can easily customize response just by registering another listener

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never mind, I read you comments

$this->loadViewsFrom(__DIR__.'/../../views', 'payum/payum');

\Route::any('/payment/authorize/{payum_token}', array(
'as' => 'payum_authorize_do',
Expand Down Expand Up @@ -77,8 +56,8 @@ public function boot()
//TODO add exceptions if invalid gateways and storages options set.

$payum = new ContainerAwareRegistry(
\Config::get('payum-laravel-package::gateways'),
\Config::get('payum-laravel-package::storages')
\Config::get('payum-laravel-package.gateways'),
\Config::get('payum-laravel-package.storages')
);

$payum->setContainer($app);
Expand All @@ -89,7 +68,7 @@ public function boot()
$this->app['payum.security.token_storage'] = $this->app->share(function($app) {
//TODO add exceptions if invalid gateways and storages options set.

$tokenStorage = \Config::get('payum-laravel-package::token_storage');
$tokenStorage = \Config::get('payum-laravel-package.token_storage');

return is_object($tokenStorage) ? $tokenStorage : $app[$tokenStorage];
});
Expand All @@ -116,6 +95,9 @@ public function boot()
*/
public function register()
{
$this->mergeConfigFrom(
__DIR__.'/../../config/config.php', 'payum-laravel-package'
);
}

/**
Expand Down