From 0d41d8aeb6fe6b112a3f7cf7508fc196bebcde45 Mon Sep 17 00:00:00 2001 From: Joshua Dwire Date: Wed, 11 May 2016 12:53:43 -0400 Subject: [PATCH] Payments bug fixes - Part 2 --- app/Http/Controllers/AccountGatewayController.php | 1 + app/Http/Controllers/PaymentController.php | 13 ++++++------- app/Http/Controllers/PublicClientController.php | 5 ++--- app/Services/PaymentService.php | 8 ++++++-- .../2016_04_23_182223_payments_changes.php | 2 +- .../views/payments/paymentmethods_list.blade.php | 4 ++-- 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/app/Http/Controllers/AccountGatewayController.php b/app/Http/Controllers/AccountGatewayController.php index bd7cb2599b..a4fd57c7e5 100644 --- a/app/Http/Controllers/AccountGatewayController.php +++ b/app/Http/Controllers/AccountGatewayController.php @@ -87,6 +87,7 @@ class AccountGatewayController extends BaseController ->where('id', '!=', GATEWAY_GOCARDLESS) ->where('id', '!=', GATEWAY_DWOLLA) ->where('id', '!=', GATEWAY_STRIPE) + ->where('id', '!=', GATEWAY_WEPAY) ->orderBy('name')->get(); $data['hiddenFields'] = Gateway::$hiddenFields; diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index fead7b7b01..8f09c2980a 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -400,7 +400,7 @@ class PaymentController extends BaseController } public static function processPaymentClientDetails($client, $accountGateway, $paymentType, $onSite = true){ - $rules = [ + $rules = $paymentType == PAYMENT_TYPE_STRIPE_ACH ? [] : [ 'first_name' => 'required', 'last_name' => 'required', ]; @@ -433,9 +433,7 @@ class PaymentController extends BaseController $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { - return Redirect::to('payment/'.$invitationKey) - ->withErrors($validator) - ->withInput(Request::except('cvv')); + return false; } if ($requireAddress && $accountGateway->update_address) { @@ -475,9 +473,10 @@ class PaymentController extends BaseController } } - $result = static::processPaymentClientDetails($client, $accountGateway, $paymentType, $onSite); - if ($result !== true) { - return $result; + if (!static::processPaymentClientDetails($client, $accountGateway, $paymentType, $onSite)) { + return Redirect::to('payment/'.$invitationKey) + ->withErrors($validator) + ->withInput(Request::except('cvv')); } try { diff --git a/app/Http/Controllers/PublicClientController.php b/app/Http/Controllers/PublicClientController.php index b8c0893791..405de63493 100644 --- a/app/Http/Controllers/PublicClientController.php +++ b/app/Http/Controllers/PublicClientController.php @@ -884,9 +884,8 @@ class PublicClientController extends BaseController $accountGateway = $account->getGatewayByType($paymentType); $sourceToken = $accountGateway->gateway_id == GATEWAY_STRIPE ? Input::get('stripeToken'):Input::get('payment_method_nonce'); - $result = PaymentController::processPaymentClientDetails($client, $accountGateway, $paymentType); - if ($result !== true) { - return $result; + if (!PaymentController::processPaymentClientDetails($client, $accountGateway, $paymentType)) { + return Redirect::to('client/paymentmethods/add/' . $typeLink)->withInput(Request::except('cvv')); } if ($sourceToken) { diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index 21417437bf..7151777cbb 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -191,7 +191,8 @@ class PaymentService extends BaseService } $data = $response->getData(); - $sources = isset($data['sources']) ? $data['sources']['data'] : $data['cards']['data']; + $sources_list = isset($data['sources']) ? $data['sources'] : $data['cards']; + $sources = isset($sources_list['data'])?$sources_list['data']:$sources_list; // Load $accountGatewayToken->payment_methods(); @@ -459,8 +460,11 @@ class PaymentService extends BaseService public function createPaymentMethodFromGatewayResponse($gatewayResponse, $accountGateway, $accountGatewayToken = null, $contactId = null) { if ($accountGateway->gateway_id == GATEWAY_STRIPE) { $data = $gatewayResponse->getData(); - if(!empty($data['object']) && ($data['object'] == 'card' || $data['object'] == 'bank_account')) { + if (!empty($data['object']) && ($data['object'] == 'card' || $data['object'] == 'bank_account')) { $source = $data; + } elseif (!empty($data['object']) && $data['object'] == 'customer') { + $sources = !empty($data['sources']) ? $data['sources'] : $data['cards']; + $source = reset($sources); } else { $source = !empty($data['source']) ? $data['source'] : $data['card']; } diff --git a/database/migrations/2016_04_23_182223_payments_changes.php b/database/migrations/2016_04_23_182223_payments_changes.php index c250c89733..1c277d8da6 100644 --- a/database/migrations/2016_04_23_182223_payments_changes.php +++ b/database/migrations/2016_04_23_182223_payments_changes.php @@ -84,7 +84,7 @@ class PaymentsChanges extends Migration $table->unsignedInteger('default_payment_method_id')->nullable(); $table->foreign('default_payment_method_id')->references('id')->on('payment_methods'); - $table->boolean('uses_local_payment_methods')->defalut(true); + $table->boolean('uses_local_payment_methods')->default(true); }); \DB::table('account_gateway_tokens')->update(array('uses_local_payment_methods' => false)); diff --git a/resources/views/payments/paymentmethods_list.blade.php b/resources/views/payments/paymentmethods_list.blade.php index 8745cadcce..0dc04a988e 100644 --- a/resources/views/payments/paymentmethods_list.blade.php +++ b/resources/views/payments/paymentmethods_list.blade.php @@ -59,8 +59,8 @@ •••••{{$paymentMethod->last4}} @endif @if($paymentMethod->payment_type_id == PAYMENT_TYPE_ACH) - @if($paymentMethod->bank()) - {{ $paymentMethod->bank()->name }} + @if($paymentMethod->bank_data) + {{ $paymentMethod->bank_data }} @endif @if($paymentMethod->status == PAYMENT_METHOD_STATUS_NEW) ({{trans('texts.complete_verification')}})