From 5853dd34de117040d6afe6ca31b4af3683ec8f77 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 4 Mar 2015 01:23:02 +0200 Subject: [PATCH] Added support for an additional payment gateway (paypal + credit card) --- app/controllers/PaymentController.php | 54 ++++++--------------------- app/models/AccountGateway.php | 4 +- 2 files changed, 15 insertions(+), 43 deletions(-) diff --git a/app/controllers/PaymentController.php b/app/controllers/PaymentController.php index 196a81052563..71ce186bac8f 100755 --- a/app/controllers/PaymentController.php +++ b/app/controllers/PaymentController.php @@ -316,7 +316,7 @@ class PaymentController extends \BaseController } else { $invitation = Invitation::with('invoice.client.account', 'invoice.client.account.account_gateways.gateway')->where('invitation_key', '=', $invitationKey)->firstOrFail(); $account = $invitation->invoice->client->account; - if ($account->isGatewayConfigured(GATEWAY_PAYPAL_EXPRESS)) { + if ($account->getGatewayByType(PAYMENT_TYPE_PAYPAL)) { $usePayPal = true; } } @@ -588,10 +588,14 @@ class PaymentController extends \BaseController $ref = $response->getTransactionReference(); if (!$ref) { + Session::flash('error', $response->getMessage()); - return Redirect::to('payment/'.$invitationKey) - ->withInput(); + if ($onSite) { + return Redirect::to('payment/'.$invitationKey)->withInput(); + } else { + return Redirect::to('view/'.$invitationKey); + } } if ($response->isSuccessful()) { @@ -609,51 +613,17 @@ class PaymentController extends \BaseController return Utils::fatalError('Sorry, there was an error processing your payment. Please try again later.

', $response->getMessage()); } - } elseif ($paymentLibrary->id == PAYMENT_LIBRARY_PHP_PAYMENTS) { - $gateway = $accountGateway->gateway; - $provider = $gateway->provider; - $p = new PHP_Payments(array('mode' => 'test')); - - $config = Payment_Utility::load('config', 'drivers/'.$provider); - - switch ($gateway->id) { - case GATEWAY_BEANSTREAM: - $config['delay_charge'] = false; - $config['bill_outstanding'] = true; - break; - case GATEWAY_AMAZON: - $config['return_url'] = URL::to('complete'); - $config['abandon_url'] = URL::to('/'); - $config['immediate_return'] = 0; - $config['process_immediate'] = 1; - $config['ipn_url'] = URL::to('ipn'); - $config['collect_shipping_address'] = false; - break; - } - - $details = self::getPaymentDetails($invoice, Input::all()); - - $response = $p->oneoff_payment($provider, $details, $config); - - if (strtolower($response->status) == 'success') { - $payment = self::createPayment($invitation, $response->response_message); - - Session::flash('message', trans('texts.applied_payment')); - - return Redirect::to('view/'.$payment->invitation->invitation_key); - } else { - Session::flash('error', $response->response_message); - - return Utils::fatalError('Sorry, there was an error processing your payment. Please try again later.

', $response->response_message); - } } } catch (\Exception $e) { $errorMessage = trans('texts.payment_error'); Session::flash('error', $errorMessage."

".$e->getMessage()); Utils::logError(Utils::getErrorString($e)); - return Redirect::to('payment/'.$invitationKey) - ->withInput(); + if ($onSite) { + return Redirect::to('payment/'.$invitationKey)->withInput(); + } else { + return Redirect::to('view/'.$invitationKey); + } } } diff --git a/app/models/AccountGateway.php b/app/models/AccountGateway.php index e66a599cba97..f2f09548958a 100755 --- a/app/models/AccountGateway.php +++ b/app/models/AccountGateway.php @@ -22,6 +22,8 @@ class AccountGateway extends EntityModel } public function isPayPal() { - return $this->gateway_id == GATEWAY_PAYPAL_EXPRESS || $this->gateway_id == GATEWAY_PAYPAL_PRO; + //return $this->gateway_id == GATEWAY_PAYPAL_EXPRESS || $this->gateway_id == GATEWAY_PAYPAL_PRO; + return $this->gateway_id == GATEWAY_PAYPAL_EXPRESS; } } +