From 3303c00067fb1d41c1160dcc5108760bf83da6ac Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 11 Apr 2016 22:09:05 +0300 Subject: [PATCH] Fix for Cybersource --- app/Http/Controllers/PaymentController.php | 14 +++++++++++--- app/Http/Middleware/VerifyCsrfToken.php | 1 + app/Http/routes.php | 3 ++- app/Services/PaymentService.php | 1 + 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index ebede5711bd5..2f2cdd92cc7e 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -460,6 +460,8 @@ class PaymentController extends BaseController $ref = $response->getData()['m_payment_id']; } elseif ($accountGateway->gateway_id == GATEWAY_GOCARDLESS) { $ref = $response->getData()['signature']; + } elseif ($accountGateway->gateway_id == GATEWAY_CYBERSOURCE) { + $ref = $response->getData()['transaction_uuid']; } else { $ref = $response->getTransactionReference(); } @@ -551,7 +553,15 @@ class PaymentController extends BaseController } try { - if (method_exists($gateway, 'completePurchase') + if ($accountGateway->isGateway(GATEWAY_CYBERSOURCE)) { + if (Input::get('decision') == 'ACCEPT') { + $payment = $this->paymentService->createPayment($invitation, $accountGateway, $token, $payerId); + Session::flash('message', trans('texts.applied_payment')); + } else { + Session::flash('error', Input::get('message')); + } + return Redirect::to($invitation->getLink()); + } elseif (method_exists($gateway, 'completePurchase') && !$accountGateway->isGateway(GATEWAY_TWO_CHECKOUT) && !$accountGateway->isGateway(GATEWAY_CHECKOUT_COM)) { $details = $this->paymentService->getPaymentDetails($invitation, $accountGateway); @@ -572,11 +582,9 @@ class PaymentController extends BaseController } else { $payment = $this->paymentService->createPayment($invitation, $accountGateway, $token, $payerId); Session::flash('message', trans('texts.applied_payment')); - return Redirect::to($invitation->getLink()); } } catch (\Exception $e) { - $this->error('Offsite-uncaught', false, $accountGateway, $e); return Redirect::to($invitation->getLink()); } diff --git a/app/Http/Middleware/VerifyCsrfToken.php b/app/Http/Middleware/VerifyCsrfToken.php index 15eeb65c7a8a..7766a0991337 100644 --- a/app/Http/Middleware/VerifyCsrfToken.php +++ b/app/Http/Middleware/VerifyCsrfToken.php @@ -6,6 +6,7 @@ use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier; class VerifyCsrfToken extends BaseVerifier { private $openRoutes = [ + 'complete', 'signup/register', 'api/v1/*', 'api/v1/login', diff --git a/app/Http/routes.php b/app/Http/routes.php index a2e3762f7970..a0260e4b6b4e 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -42,7 +42,7 @@ Route::group(['middleware' => 'auth:client'], function() { Route::get('approve/{invitation_key}', 'QuoteController@approve'); Route::get('payment/{invitation_key}/{payment_type?}', 'PaymentController@show_payment'); Route::post('payment/{invitation_key}', 'PaymentController@do_payment'); - Route::get('complete', 'PaymentController@offsite_payment'); + Route::match(['GET', 'POST'], 'complete', 'PaymentController@offsite_payment'); Route::get('client/quotes', 'PublicClientController@quoteIndex'); Route::get('client/invoices', 'PublicClientController@invoiceIndex'); Route::get('client/documents', 'PublicClientController@documentIndex'); @@ -535,6 +535,7 @@ if (!defined('CONTACT_EMAIL')) { define('GATEWAY_BITPAY', 42); define('GATEWAY_DWOLLA', 43); define('GATEWAY_CHECKOUT_COM', 47); + define('GATEWAY_CYBERSOURCE', 49); define('EVENT_CREATE_CLIENT', 1); define('EVENT_CREATE_INVOICE', 2); diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index 3bf26d8ba206..1669d94d88d4 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -74,6 +74,7 @@ class PaymentService extends BaseService if ($input) { $data = self::convertInputForOmnipay($input); + $data['email'] = $invitation->contact->email; Session::put($key, $data); } elseif (Session::get($key)) { $data = Session::get($key);