diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index 7cfef28609..4ddf45cd63 100755 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -121,8 +121,6 @@ class AccountController extends \BaseController { 'data-newRow' => $newRow ); $recommendedGatewayArray[$recommendedGateway->name] = $arrayItem; - - } $data = [ @@ -138,14 +136,8 @@ class AccountController extends \BaseController { foreach ($data['gateways'] as $gateway) { $paymentLibrary = $gateway->paymentlibrary; - - if($paymentLibrary->name == 'Omnipay') - { - $gateway->fields = Omnipay::create($gateway->provider)->getDefaultParameters(); - } - else { - $gateway->fields = array(); - } + + $gateway->fields = $gateway->getFields(); if ($accountGateway && $accountGateway->gateway_id == $gateway->id) { @@ -471,7 +463,10 @@ class AccountController extends \BaseController { if ($gatewayId = Input::get('gateway_id')) { $gateway = Gateway::findOrFail($gatewayId); - $fields = Omnipay::create($gateway->provider)->getDefaultParameters(); + + $paymentLibrary = $gateway->paymentlibrary; + + $fields = $gateway->getFields(); foreach ($fields as $field => $details) { diff --git a/app/controllers/PaymentController.php b/app/controllers/PaymentController.php index ba8af464ba..b0724cd930 100755 --- a/app/controllers/PaymentController.php +++ b/app/controllers/PaymentController.php @@ -174,8 +174,8 @@ class PaymentController extends \BaseController 'ship_to_state' => $input['state'], 'ship_to_postal_code' => $input['postal_code'], 'currency_code' => $invoice->client->currency->code, - 'returnUrl' => URL::to('complete'), - 'cancelUrl' => URL::to('/') + 'returnUrl' => URL::to('complete'), + 'cancelUrl' => URL::to('/') ]; Session::put($key, $data); @@ -190,15 +190,22 @@ class PaymentController extends \BaseController $data = []; } - $card = new CreditCard($data); - - return [ - 'amount' => $invoice->amount, - 'card' => $card, - 'currency' => $invoice->client->currency->code, - 'returnUrl' => URL::to('complete'), - 'cancelUrl' => URL::to('/') - ]; + if($paymentLibrary->name == "Omnipay") + { + $card = new CreditCard($data); + + return [ + 'amount' => $invoice->amount, + 'card' => $card, + 'currency' => $invoice->client->currency->code, + 'returnUrl' => URL::to('complete'), + 'cancelUrl' => URL::to('/') + ]; + } + else + { + return $data; + } } public function show_payment($invitationKey) @@ -320,14 +327,13 @@ class PaymentController extends \BaseController } else if ($input && $paymentLibrary->name == "PHP-Payments") { + $provider = $accountGateway->gateway->provider; $p = new PHP_Payments; - $config = Payment_Utility::load('config', '/path/to/your/gateway/config'); + $config = Payment_Utility::load('config', 'drivers/'.$provider); $details = self::getPaymentDetails($invoice, Input::all()); - - -$response = $p->oneoff_payment('name_of_payment_driver', $details, $config); + $response = $p->oneoff_payment($provider, $details, $config); if ($response->status == 'Success') { @@ -341,17 +347,10 @@ $response = $p->oneoff_payment('name_of_payment_driver', $details, $config); Session::flash('message', 'Successfully applied payment'); return Redirect::to('view/' . $payment->invitation->invitation_key); } - else if ($response->isRedirect()) - { - $invitation->transaction_reference = $ref; - $invitation->save(); - - $response->redirect(); - } else { - Session::flash('error', $response->getMessage()); - return Utils::fatalError('Sorry, there was an error processing your payment. Please try again later.

', $response->getMessage()); + Session::flash('error', $response->details); + return Utils::fatalError('Sorry, there was an error processing your payment. Please try again later.

', $response->reason); } } } diff --git a/app/database/seeds/PaymentLibrariesSeeder.php b/app/database/seeds/PaymentLibrariesSeeder.php index 83c59e6eab..133cf1f5d3 100644 --- a/app/database/seeds/PaymentLibrariesSeeder.php +++ b/app/database/seeds/PaymentLibrariesSeeder.php @@ -7,11 +7,10 @@ class PaymentLibrariesSeeder extends Seeder { $gateways = [ array('name'=>'BeanStream', 'provider'=>'BeanStream', 'payment_library_id' => 2), - array('name'=>'iTransact', 'provider'=>'iTransact', 'payment_library_id' => 2), - array('name'=>'Amazon_Simplepay', 'provider'=>'Amazon Simplepay', 'payment_library_id' => 2), + array('name'=>'Amazon Simplepay', 'provider'=>'Amazon_Simplepay', 'payment_library_id' => 2), array('name'=>'Bluepay', 'provider'=>'Bluepay', 'payment_library_id' => 2), array('name'=>'Braintree', 'provider'=>'Braintree', 'payment_library_id' => 2), - array('name'=>'Google_Checkout', 'provider'=>'Google Checkout', 'payment_library_id' => 2), + array('name'=>'Google Checkout', 'provider'=>'Google_Checkout', 'payment_library_id' => 2), array('name'=>'Psigate', 'provider'=>'Psigate', 'payment_library_id' => 2), array('name'=>'Quickbooksms', 'provider'=>'Quickbooksms', 'payment_library_id' => 2) ]; @@ -34,7 +33,6 @@ class PaymentLibrariesSeeder extends Seeder Gateway::where('provider', '=', 'AuthorizeNet_AIM')->update(array('sort_order' => 5, 'site_url' => 'http://www.authorize.net/')); Gateway::where('provider', '=', 'BeanStream')->update(array('sort_order' => 10, 'site_url' => 'http://www.beanstream.com/')); - Gateway::where('provider', '=', 'iTransact')->update(array('sort_order' => 15, 'site_url' => 'http://itransact.com/')); Gateway::where('provider', '=', 'FirstData_Connect')->update(array('sort_order' => 20, 'site_url' => 'https://www.firstdata.com/')); Gateway::where('provider', '=', 'PayPal_Pro')->update(array('sort_order' => 25, 'site_url' => 'https://www.paypal.com/')); Gateway::where('provider', '=', 'TwoCheckout')->update(array('sort_order' => 30, 'site_url' => 'https://www.2checkout.com/')); diff --git a/app/models/Gateway.php b/app/models/Gateway.php index 2a06780630..3fdbe91696 100755 --- a/app/models/Gateway.php +++ b/app/models/Gateway.php @@ -14,4 +14,25 @@ class Gateway extends Eloquent { return '/images/gateways/logo_'.$this->provider.'.png'; } + + public function getFields() + { + $paymentLibrary = $this->paymentlibrary; + + if($paymentLibrary->name == 'Omnipay') + { + $fields = Omnipay::create($this->provider)->getDefaultParameters(); + } + else + { + $fields = Payment_Utility::load('config', 'drivers/'.$this->provider); + } + + if($fields == null) + { + $fields = array(); + } + + return $fields; + } } \ No newline at end of file diff --git a/app/views/accounts/payments.blade.php b/app/views/accounts/payments.blade.php index 17b4303065..0a4fb26026 100755 --- a/app/views/accounts/payments.blade.php +++ b/app/views/accounts/payments.blade.php @@ -12,12 +12,12 @@ {{ Former::legend('Payment Gateway') }} {{Former::label('Lorem Ipsum goes here.')}} - +

{{ Former::radios('recommendedGateway_id') ->label('Recommended Gateways') ->radios($recommendedGateways) ->class('recommended-gateway')}} - +
@if ($accountGateway) {{ Former::populateField('gateway_id', $accountGateway->gateway_id) }} @@ -63,8 +63,16 @@ function setFieldsShown() { var val = $('#gateway_id').val(); + var activeElement = $('.recommended-gateway[value=' + val + ']'); + var recommendedRadios = $('#recommendedGateway_id'); + $('.gateway-fields').hide(); $('#gateway_' + val + '_div').show(); + + if(activeElement && !activeElement.attr('checked')) + { + activeElement.attr('checked', true); + } } $(document).ready(function() {