Payments bug fixes

This commit is contained in:
Joshua Dwire 2016-05-15 16:27:56 -04:00
parent d99d81d655
commit a482c63ee3
9 changed files with 72 additions and 58 deletions

View File

@ -439,7 +439,7 @@ class PaymentController extends BaseController
$validator = Validator::make(Input::all(), $rules); $validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) { if ($validator->fails()) {
return false; return $validator;
} }
if ($requireAddress && $accountGateway->update_address) { if ($requireAddress && $accountGateway->update_address) {
@ -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) return Redirect::to('payment/'.$invitationKey)
->withErrors($validator) ->withErrors($validator)
->withInput(Request::except('cvv')); ->withInput(Request::except('cvv'));
} }
try { try {
// For offsite payments send the client's details on file // 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 // 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 // check if we're creating/using a billing token
$tokenBillingSupported = false; $tokenBillingSupported = false;
$sourceReferenceParam = 'token';
if ($accountGateway->gateway_id == GATEWAY_STRIPE) { if ($accountGateway->gateway_id == GATEWAY_STRIPE) {
$tokenBillingSupported = true; $tokenBillingSupported = true;
$customerReferenceParam = 'cardReference'; $customerReferenceParam = 'customerReference';
if ($paymentType == PAYMENT_TYPE_STRIPE_ACH && !Input::get('authorize_ach')) { if ($paymentType == PAYMENT_TYPE_STRIPE_ACH && !Input::get('authorize_ach')) {
Session::flash('error', trans('texts.ach_authorization_required')); Session::flash('error', trans('texts.ach_authorization_required'));
@ -507,7 +509,8 @@ class PaymentController extends BaseController
} }
} elseif ($accountGateway->gateway_id == GATEWAY_BRAINTREE) { } elseif ($accountGateway->gateway_id == GATEWAY_BRAINTREE) {
$tokenBillingSupported = true; $tokenBillingSupported = true;
$customerReferenceParam = 'paymentMethodToken'; $sourceReferenceParam = 'paymentMethodToken';
$customerReferenceParam = 'customerId';
$deviceData = Input::get('device_data'); $deviceData = Input::get('device_data');
if (!$deviceData) { if (!$deviceData) {
@ -527,12 +530,12 @@ class PaymentController extends BaseController
if ($customerReferenceParam) { if ($customerReferenceParam) {
$details[$customerReferenceParam] = $customerReference; $details[$customerReferenceParam] = $customerReference;
} }
$details['token'] = $sourceReference; $details[$sourceReferenceParam] = $sourceReference;
unset($details['card']); unset($details['card']);
} elseif ($account->token_billing_type_id == TOKEN_BILLING_ALWAYS || Input::get('token_billing') || $paymentType == PAYMENT_TYPE_STRIPE_ACH) { } 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 */); $token = $this->paymentService->createToken($gateway, $details, $accountGateway, $client, $invitation->contact_id, $customerReference/* return parameter */, $paymentMethod/* return parameter */);
if ($token) { if ($token) {
$details['token'] = $token; $details[$sourceReferenceParam] = $token;
if ($customerReferenceParam) { if ($customerReferenceParam) {
$details[$customerReferenceParam] = $customerReference; $details[$customerReferenceParam] = $customerReference;
} }
@ -568,7 +571,7 @@ class PaymentController extends BaseController
if (!$ref) { if (!$ref) {
$this->error('No-Ref', $response->getMessage(), $accountGateway); $this->error('No-Ref', $response->getMessage(), $accountGateway);
if ($onSite) { if ($onSite && $paymentType != PAYMENT_TYPE_BRAINTREE_PAYPAL) {
return Redirect::to('payment/'.$invitationKey) return Redirect::to('payment/'.$invitationKey)
->withInput(Request::except('cvv')); ->withInput(Request::except('cvv'));
} else { } else {
@ -596,7 +599,7 @@ class PaymentController extends BaseController
$response->redirect(); $response->redirect();
} else { } else {
$this->error('Unknown', $response->getMessage(), $accountGateway); $this->error('Unknown', $response->getMessage(), $accountGateway);
if ($onSite) { if ($onSite && $paymentType != PAYMENT_TYPE_BRAINTREE_PAYPAL) {
return Redirect::to('payment/'.$invitationKey)->withInput(Request::except('cvv')); return Redirect::to('payment/'.$invitationKey)->withInput(Request::except('cvv'));
} else { } else {
return Redirect::to('view/'.$invitationKey); return Redirect::to('view/'.$invitationKey);
@ -604,7 +607,7 @@ class PaymentController extends BaseController
} }
} catch (\Exception $e) { } catch (\Exception $e) {
$this->error('Uncaught', false, $accountGateway, $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')); return Redirect::to('payment/'.$invitationKey)->withInput(Request::except('cvv'));
} else { } else {
return Redirect::to('view/'.$invitationKey); return Redirect::to('view/'.$invitationKey);
@ -759,7 +762,7 @@ class PaymentController extends BaseController
'message' => $data, 'message' => $data,
], 500); ], 500);
} elseif (!empty($data)) { } elseif (!empty($data)) {
return $data; return response()->json($data);
} }
return response()->json([ return response()->json([

View File

@ -16,7 +16,7 @@ use Redirect;
use App\Models\Gateway; use App\Models\Gateway;
use App\Models\Invitation; use App\Models\Invitation;
use App\Models\Document; use App\Models\Document;
use App\ModelsPaymentMethod; use App\Models\PaymentMethod;
use App\Ninja\Repositories\InvoiceRepository; use App\Ninja\Repositories\InvoiceRepository;
use App\Ninja\Repositories\PaymentRepository; use App\Ninja\Repositories\PaymentRepository;
use App\Ninja\Repositories\ActivityRepository; use App\Ninja\Repositories\ActivityRepository;
@ -177,6 +177,8 @@ class PublicClientController extends BaseController
if ($paymentMethod->payment_type_id == PAYMENT_TYPE_ACH) { if ($paymentMethod->payment_type_id == PAYMENT_TYPE_ACH) {
if ($paymentMethod->bank_data) { if ($paymentMethod->bank_data) {
$html = '<div>' . htmlentities($paymentMethod->bank_data->name) . '</div>'; $html = '<div>' . htmlentities($paymentMethod->bank_data->name) . '</div>';
} else {
$html = '<img height="22" src="'.URL::to('/images/credit_cards/ach.png').'" style="float:left" alt="'.trans("texts.direct_debit").'">';
} }
} elseif ($paymentMethod->payment_type_id == PAYMENT_TYPE_ID_PAYPAL) { } elseif ($paymentMethod->payment_type_id == PAYMENT_TYPE_ID_PAYPAL) {
$html = '<img height="22" src="'.URL::to('/images/credit_cards/paypal.png').'" alt="'.trans("texts.card_".$code).'">'; $html = '<img height="22" src="'.URL::to('/images/credit_cards/paypal.png').'" alt="'.trans("texts.card_".$code).'">';
@ -887,8 +889,10 @@ class PublicClientController extends BaseController
$accountGateway = $account->getGatewayByType($paymentType); $accountGateway = $account->getGatewayByType($paymentType);
$sourceToken = Input::get('sourceToken'); $sourceToken = Input::get('sourceToken');
if (!PaymentController::processPaymentClientDetails($client, $accountGateway, $paymentType)) { if (($validator = PaymentController::processPaymentClientDetails($client, $accountGateway, $paymentType)) !== true) {
return Redirect::to('client/paymentmethods/add/' . $typeLink)->withInput(Request::except('cvv')); return Redirect::to('client/paymentmethods/add/' . $typeLink)
->withErrors($validator)
->withInput(Request::except('cvv'));
} }
if ($sourceToken) { if ($sourceToken) {

View File

@ -167,7 +167,7 @@ class Payment extends EntityModel
return ENTITY_PAYMENT; return ENTITY_PAYMENT;
} }
public function getBankData() public function getBankDataAttribute()
{ {
if (!$this->routing_number) { if (!$this->routing_number) {
return null; return null;

View File

@ -63,7 +63,7 @@ class PaymentMethod extends EntityModel
return $this->hasMany('App\Models\Payments'); return $this->hasMany('App\Models\Payments');
} }
public function getBankData() public function getBankDataAttribute()
{ {
if (!$this->routing_number) { if (!$this->routing_number) {
return null; return null;

View File

@ -131,7 +131,7 @@ class PaymentService extends BaseService
$data['cvv'] = $input['cvv']; $data['cvv'] = $input['cvv'];
} }
if (isset($input['country_id'])) { if (isset($input['address1'])) {
$country = Country::find($input['country_id']); $country = Country::find($input['country_id']);
$data = array_merge($data, [ $data = array_merge($data, [
@ -222,7 +222,7 @@ class PaymentService extends BaseService
public function verifyClientPaymentMethod($client, $publicId, $amount1, $amount2) 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) { if ($accountGateway->gateway_id != GATEWAY_STRIPE) {
return 'Unsupported gateway'; return 'Unsupported gateway';
} }
@ -238,7 +238,10 @@ class PaymentService extends BaseService
'amounts[]=' . intval($amount1) . '&amounts[]=' . intval($amount2) 'amounts[]=' . intval($amount1) . '&amounts[]=' . intval($amount2)
); );
if (!is_string($result)) { if (is_string($result)) {
return $result;
}
$paymentMethod->status = PAYMENT_METHOD_STATUS_VERIFIED; $paymentMethod->status = PAYMENT_METHOD_STATUS_VERIFIED;
$paymentMethod->save(); $paymentMethod->save();
@ -246,7 +249,7 @@ class PaymentService extends BaseService
$paymentMethod->account_gateway_token->default_payment_method_id = $paymentMethod->id; $paymentMethod->account_gateway_token->default_payment_method_id = $paymentMethod->id;
$paymentMethod->account_gateway_token->save(); $paymentMethod->account_gateway_token->save();
} }
}
return true; return true;
} }

View File

@ -49,7 +49,7 @@
->large() !!} ->large() !!}
@if(isset($gateways)) @if(isset($gateways))
<br><br> <br><br>
<a href="#" id="show-other-providers">{{ trans('texts.use_another_provider') }}</a> <a href="javascript::void" id="show-other-providers">{{ trans('texts.use_another_provider') }}</a>
@endif @endif
</center> </center>
</div> </div>

View File

@ -130,7 +130,6 @@
<div class="col-md-6"> <div class="col-md-6">
{!! Former::text('first_name') {!! Former::text('first_name')
->placeholder(trans('texts.first_name')) ->placeholder(trans('texts.first_name'))
->autocomplete('given-name')
->label('') !!} ->label('') !!}
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
@ -252,11 +251,10 @@
{!! Former::text('') {!! Former::text('')
->id('confirm_account_number') ->id('confirm_account_number')
->label(trans('texts.confirm_account_number')) !!} ->label(trans('texts.confirm_account_number')) !!}
</div>
{!! Former::checkbox('authorize_ach') {!! Former::checkbox('authorize_ach')
->text(trans('texts.ach_authorization', ['company'=>$account->getDisplayName()])) ->text(trans('texts.ach_authorization', ['company'=>$account->getDisplayName()]))
->label(' ') !!} ->label(' ') !!}
</div>
</div>
<div class="col-md-8 col-md-offset-4"> <div class="col-md-8 col-md-offset-4">
{!! Button::success(strtoupper(trans('texts.add_account'))) {!! Button::success(strtoupper(trans('texts.add_account')))
->submit() ->submit()
@ -441,7 +439,7 @@
$('#routing_number, #country').on('change keypress keyup keydown paste', function(){setTimeout(function () { $('#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, ''); 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(); $('#bank_name').hide();
} else if (routingNumberCache[routingNumber]) { } else if (routingNumberCache[routingNumber]) {
$('#bank_name').empty().append(routingNumberCache[routingNumber]).show(); $('#bank_name').empty().append(routingNumberCache[routingNumber]).show();

View File

@ -60,7 +60,7 @@
@endif @endif
@if($paymentMethod->payment_type_id == PAYMENT_TYPE_ACH) @if($paymentMethod->payment_type_id == PAYMENT_TYPE_ACH)
@if($paymentMethod->bank_data) @if($paymentMethod->bank_data)
{{ $paymentMethod->bank_data }} {{ $paymentMethod->bank_data->name }}
@endif @endif
@if($paymentMethod->status == PAYMENT_METHOD_STATUS_NEW) @if($paymentMethod->status == PAYMENT_METHOD_STATUS_NEW)
<a href="javasript::void" onclick="completeVerification('{{$paymentMethod->public_id}}','{{$paymentMethod->currency->symbol}}')">({{trans('texts.complete_verification')}})</a> <a href="javasript::void" onclick="completeVerification('{{$paymentMethod->public_id}}','{{$paymentMethod->currency->symbol}}')">({{trans('texts.complete_verification')}})</a>

View File

@ -1,6 +1,7 @@
<script type="text/javascript" src="https://js.braintreegateway.com/js/braintree-2.23.0.min.js"></script> <script type="text/javascript" src="https://js.braintreegateway.com/js/braintree-2.23.0.min.js"></script>
<script type="text/javascript" > <script type="text/javascript" >
$(function() { $(function() {
var $form = $('.payment-form');
braintree.setup("{{ $braintreeClientToken }}", "custom", { braintree.setup("{{ $braintreeClientToken }}", "custom", {
id: "payment-form", id: "payment-form",
hostedFields: { hostedFields: {
@ -29,7 +30,6 @@
} }
}, },
onError: function(e) { onError: function(e) {
var $form = $('.payment-form');
$form.find('button').prop('disabled', false); $form.find('button').prop('disabled', false);
// Show the errors on the form // Show the errors on the form
if (e.details && e.details.invalidFieldKeys.length) { if (e.details && e.details.invalidFieldKeys.length) {
@ -48,6 +48,12 @@
else { else {
$('#js-error-message').html(e.message).fadeIn(); $('#js-error-message').html(e.message).fadeIn();
} }
},
onPaymentMethodReceived: function(e) {
// Insert the token into the form so it gets submitted to the server
$form.append($('<input type="hidden" name="sourceToken"/>').val(e.nonce));
// and submit
$form.get(0).submit();
} }
}); });
$('.payment-form').submit(function(event) { $('.payment-form').submit(function(event) {