From a482c63ee3f9737c77e7dee33659a3fc3672806d Mon Sep 17 00:00:00 2001 From: Joshua Dwire Date: Sun, 15 May 2016 16:27:56 -0400 Subject: [PATCH] Payments bug fixes --- app/Http/Controllers/PaymentController.php | 27 +++++----- .../Controllers/PublicClientController.php | 12 +++-- app/Models/Payment.php | 2 +- app/Models/PaymentMethod.php | 2 +- app/Services/PaymentService.php | 23 ++++---- .../partials/account_gateway_wepay.blade.php | 2 +- .../payments/add_paymentmethod.blade.php | 52 +++++++++---------- .../payments/paymentmethods_list.blade.php | 2 +- .../payments/tokenization_braintree.blade.php | 8 ++- 9 files changed, 72 insertions(+), 58 deletions(-) diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index c30436cd3a..69553f58d5 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -411,7 +411,7 @@ class PaymentController extends BaseController 'last_name' => 'required', ]; - if ( ! Input::get('sourceToken') && !(Input::get('plaidPublicToken') && Input::get('plaidAccountId'))) { + if ( !Input::get('sourceToken') && !(Input::get('plaidPublicToken') && Input::get('plaidAccountId'))) { $rules = array_merge( $rules, [ @@ -439,7 +439,7 @@ class PaymentController extends BaseController $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { - return false; + return $validator; } if ($requireAddress && $accountGateway->update_address) { @@ -465,7 +465,7 @@ class PaymentController extends BaseController $paymentType = Session::get($invitation->id . 'payment_type'); $accountGateway = $account->getGatewayByType($paymentType); $paymentMethod = null; - + if ($useToken) { if(!$sourceId) { Session::flash('error', trans('texts.no_payment_method_specified')); @@ -477,12 +477,13 @@ class PaymentController extends BaseController } } - if (!static::processPaymentClientDetails($client, $accountGateway, $paymentType, $onSite)) { + if (($validator = static::processPaymentClientDetails($client, $accountGateway, $paymentType, $onSite)) !== true) { return Redirect::to('payment/'.$invitationKey) ->withErrors($validator) ->withInput(Request::except('cvv')); } + try { // For offsite payments send the client's details on file // If we're using a token then we don't need to send any other data @@ -497,9 +498,10 @@ class PaymentController extends BaseController // check if we're creating/using a billing token $tokenBillingSupported = false; + $sourceReferenceParam = 'token'; if ($accountGateway->gateway_id == GATEWAY_STRIPE) { $tokenBillingSupported = true; - $customerReferenceParam = 'cardReference'; + $customerReferenceParam = 'customerReference'; if ($paymentType == PAYMENT_TYPE_STRIPE_ACH && !Input::get('authorize_ach')) { Session::flash('error', trans('texts.ach_authorization_required')); @@ -507,7 +509,8 @@ class PaymentController extends BaseController } } elseif ($accountGateway->gateway_id == GATEWAY_BRAINTREE) { $tokenBillingSupported = true; - $customerReferenceParam = 'paymentMethodToken'; + $sourceReferenceParam = 'paymentMethodToken'; + $customerReferenceParam = 'customerId'; $deviceData = Input::get('device_data'); if (!$deviceData) { @@ -527,12 +530,12 @@ class PaymentController extends BaseController if ($customerReferenceParam) { $details[$customerReferenceParam] = $customerReference; } - $details['token'] = $sourceReference; + $details[$sourceReferenceParam] = $sourceReference; unset($details['card']); } elseif ($account->token_billing_type_id == TOKEN_BILLING_ALWAYS || Input::get('token_billing') || $paymentType == PAYMENT_TYPE_STRIPE_ACH) { $token = $this->paymentService->createToken($gateway, $details, $accountGateway, $client, $invitation->contact_id, $customerReference/* return parameter */, $paymentMethod/* return parameter */); if ($token) { - $details['token'] = $token; + $details[$sourceReferenceParam] = $token; if ($customerReferenceParam) { $details[$customerReferenceParam] = $customerReference; } @@ -568,7 +571,7 @@ class PaymentController extends BaseController if (!$ref) { $this->error('No-Ref', $response->getMessage(), $accountGateway); - if ($onSite) { + if ($onSite && $paymentType != PAYMENT_TYPE_BRAINTREE_PAYPAL) { return Redirect::to('payment/'.$invitationKey) ->withInput(Request::except('cvv')); } else { @@ -596,7 +599,7 @@ class PaymentController extends BaseController $response->redirect(); } else { $this->error('Unknown', $response->getMessage(), $accountGateway); - if ($onSite) { + if ($onSite && $paymentType != PAYMENT_TYPE_BRAINTREE_PAYPAL) { return Redirect::to('payment/'.$invitationKey)->withInput(Request::except('cvv')); } else { return Redirect::to('view/'.$invitationKey); @@ -604,7 +607,7 @@ class PaymentController extends BaseController } } catch (\Exception $e) { $this->error('Uncaught', false, $accountGateway, $e); - if ($onSite) { + if ($onSite && $paymentType != PAYMENT_TYPE_BRAINTREE_PAYPAL) { return Redirect::to('payment/'.$invitationKey)->withInput(Request::except('cvv')); } else { return Redirect::to('view/'.$invitationKey); @@ -759,7 +762,7 @@ class PaymentController extends BaseController 'message' => $data, ], 500); } elseif (!empty($data)) { - return $data; + return response()->json($data); } return response()->json([ diff --git a/app/Http/Controllers/PublicClientController.php b/app/Http/Controllers/PublicClientController.php index 360f71e90f..bf12d808fa 100644 --- a/app/Http/Controllers/PublicClientController.php +++ b/app/Http/Controllers/PublicClientController.php @@ -16,7 +16,7 @@ use Redirect; use App\Models\Gateway; use App\Models\Invitation; use App\Models\Document; -use App\ModelsPaymentMethod; +use App\Models\PaymentMethod; use App\Ninja\Repositories\InvoiceRepository; use App\Ninja\Repositories\PaymentRepository; use App\Ninja\Repositories\ActivityRepository; @@ -175,8 +175,10 @@ class PublicClientController extends BaseController $code = htmlentities(str_replace(' ', '', strtolower($paymentMethod->payment_type->name))); if ($paymentMethod->payment_type_id == PAYMENT_TYPE_ACH) { - if($paymentMethod->bank_data) { + if ($paymentMethod->bank_data) { $html = '
' . htmlentities($paymentMethod->bank_data->name) . '
'; + } else { + $html = ''.trans('; } } elseif ($paymentMethod->payment_type_id == PAYMENT_TYPE_ID_PAYPAL) { $html = ''.trans('; @@ -887,8 +889,10 @@ class PublicClientController extends BaseController $accountGateway = $account->getGatewayByType($paymentType); $sourceToken = Input::get('sourceToken'); - if (!PaymentController::processPaymentClientDetails($client, $accountGateway, $paymentType)) { - return Redirect::to('client/paymentmethods/add/' . $typeLink)->withInput(Request::except('cvv')); + if (($validator = PaymentController::processPaymentClientDetails($client, $accountGateway, $paymentType)) !== true) { + return Redirect::to('client/paymentmethods/add/' . $typeLink) + ->withErrors($validator) + ->withInput(Request::except('cvv')); } if ($sourceToken) { diff --git a/app/Models/Payment.php b/app/Models/Payment.php index 9171c9d22c..85a10acafb 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -167,7 +167,7 @@ class Payment extends EntityModel return ENTITY_PAYMENT; } - public function getBankData() + public function getBankDataAttribute() { if (!$this->routing_number) { return null; diff --git a/app/Models/PaymentMethod.php b/app/Models/PaymentMethod.php index 07c6d2e19e..a2f17b722a 100644 --- a/app/Models/PaymentMethod.php +++ b/app/Models/PaymentMethod.php @@ -63,7 +63,7 @@ class PaymentMethod extends EntityModel return $this->hasMany('App\Models\Payments'); } - public function getBankData() + public function getBankDataAttribute() { if (!$this->routing_number) { return null; diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index 32fafc045c..d1a0a29a71 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -131,7 +131,7 @@ class PaymentService extends BaseService $data['cvv'] = $input['cvv']; } - if (isset($input['country_id'])) { + if (isset($input['address1'])) { $country = Country::find($input['country_id']); $data = array_merge($data, [ @@ -222,7 +222,7 @@ class PaymentService extends BaseService public function verifyClientPaymentMethod($client, $publicId, $amount1, $amount2) { - $token = $client->getGatewayToken($accountGateway); + $token = $client->getGatewayToken($accountGateway/* return parameter */, $accountGatewayToken/* return parameter */); if ($accountGateway->gateway_id != GATEWAY_STRIPE) { return 'Unsupported gateway'; } @@ -238,15 +238,18 @@ class PaymentService extends BaseService 'amounts[]=' . intval($amount1) . '&amounts[]=' . intval($amount2) ); - if (!is_string($result)) { - $paymentMethod->status = PAYMENT_METHOD_STATUS_VERIFIED; - $paymentMethod->save(); - - if (!$paymentMethod->account_gateway_token->default_payment_method_id) { - $paymentMethod->account_gateway_token->default_payment_method_id = $paymentMethod->id; - $paymentMethod->account_gateway_token->save(); - } + if (is_string($result)) { + return $result; } + + $paymentMethod->status = PAYMENT_METHOD_STATUS_VERIFIED; + $paymentMethod->save(); + + if (!$paymentMethod->account_gateway_token->default_payment_method_id) { + $paymentMethod->account_gateway_token->default_payment_method_id = $paymentMethod->id; + $paymentMethod->account_gateway_token->save(); + } + return true; } diff --git a/resources/views/accounts/partials/account_gateway_wepay.blade.php b/resources/views/accounts/partials/account_gateway_wepay.blade.php index 4d6832a8c1..803fc37ed1 100644 --- a/resources/views/accounts/partials/account_gateway_wepay.blade.php +++ b/resources/views/accounts/partials/account_gateway_wepay.blade.php @@ -49,7 +49,7 @@ ->large() !!} @if(isset($gateways))

- {{ trans('texts.use_another_provider') }} + {{ trans('texts.use_another_provider') }} @endif diff --git a/resources/views/payments/add_paymentmethod.blade.php b/resources/views/payments/add_paymentmethod.blade.php index e4d5d3c0a5..c5a5b1eab3 100644 --- a/resources/views/payments/add_paymentmethod.blade.php +++ b/resources/views/payments/add_paymentmethod.blade.php @@ -130,7 +130,6 @@
{!! Former::text('first_name') ->placeholder(trans('texts.first_name')) - ->autocomplete('given-name') ->label('') !!}
@@ -230,33 +229,32 @@ ))->inline()->label(trans('texts.account_holder_type')); !!} {!! Former::text('account_holder_name') ->label(trans('texts.account_holder_name')) !!} - {!! Former::select('country_id') - ->label(trans('texts.country_id')) - ->fromQuery($countries, 'name', 'id') - ->addGroupClass('country-select') !!} - {!! Former::select('currency') - ->label(trans('texts.currency_id')) - ->fromQuery($currencies, 'name', 'code') - ->addGroupClass('currency-select') !!} - {!! Former::text('') - ->id('routing_number') - ->label(trans('texts.routing_number')) !!} -
-
-
-
-
- {!! Former::text('') - ->id('account_number') - ->label(trans('texts.account_number')) !!} - {!! Former::text('') - ->id('confirm_account_number') - ->label(trans('texts.confirm_account_number')) !!} - {!! Former::checkbox('authorize_ach') - ->text(trans('texts.ach_authorization', ['company'=>$account->getDisplayName()])) - ->label(' ') !!} + {!! Former::select('country_id') + ->label(trans('texts.country_id')) + ->fromQuery($countries, 'name', 'id') + ->addGroupClass('country-select') !!} + {!! Former::select('currency') + ->label(trans('texts.currency_id')) + ->fromQuery($currencies, 'name', 'code') + ->addGroupClass('currency-select') !!} + {!! Former::text('') + ->id('routing_number') + ->label(trans('texts.routing_number')) !!} +
+
+
+
+ {!! Former::text('') + ->id('account_number') + ->label(trans('texts.account_number')) !!} + {!! Former::text('') + ->id('confirm_account_number') + ->label(trans('texts.confirm_account_number')) !!}
+ {!! Former::checkbox('authorize_ach') + ->text(trans('texts.ach_authorization', ['company'=>$account->getDisplayName()])) + ->label(' ') !!}
{!! Button::success(strtoupper(trans('texts.add_account'))) ->submit() @@ -441,7 +439,7 @@ $('#routing_number, #country').on('change keypress keyup keydown paste', function(){setTimeout(function () { var routingNumber = $('#routing_number').val().replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); - if (routingNumber.length != 9 || $("#country").val() != 'US' || routingNumberCache[routingNumber] === false) { + if (routingNumber.length != 9 || $("#country_id").val() != 840 || routingNumberCache[routingNumber] === false) { $('#bank_name').hide(); } else if (routingNumberCache[routingNumber]) { $('#bank_name').empty().append(routingNumberCache[routingNumber]).show(); diff --git a/resources/views/payments/paymentmethods_list.blade.php b/resources/views/payments/paymentmethods_list.blade.php index 79e8faae5b..3b0d7745d6 100644 --- a/resources/views/payments/paymentmethods_list.blade.php +++ b/resources/views/payments/paymentmethods_list.blade.php @@ -60,7 +60,7 @@ @endif @if($paymentMethod->payment_type_id == PAYMENT_TYPE_ACH) @if($paymentMethod->bank_data) - {{ $paymentMethod->bank_data }} + {{ $paymentMethod->bank_data->name }} @endif @if($paymentMethod->status == PAYMENT_METHOD_STATUS_NEW) ({{trans('texts.complete_verification')}}) diff --git a/resources/views/payments/tokenization_braintree.blade.php b/resources/views/payments/tokenization_braintree.blade.php index f6f6e59217..3588ff9a67 100644 --- a/resources/views/payments/tokenization_braintree.blade.php +++ b/resources/views/payments/tokenization_braintree.blade.php @@ -1,6 +1,7 @@