mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 12:12:48 +01:00
Payments bug fixes
This commit is contained in:
parent
d99d81d655
commit
a482c63ee3
@ -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([
|
||||
|
@ -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 = '<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) {
|
||||
$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);
|
||||
$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) {
|
||||
|
@ -167,7 +167,7 @@ class Payment extends EntityModel
|
||||
return ENTITY_PAYMENT;
|
||||
}
|
||||
|
||||
public function getBankData()
|
||||
public function getBankDataAttribute()
|
||||
{
|
||||
if (!$this->routing_number) {
|
||||
return null;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@
|
||||
->large() !!}
|
||||
@if(isset($gateways))
|
||||
<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
|
||||
</center>
|
||||
</div>
|
||||
|
@ -130,7 +130,6 @@
|
||||
<div class="col-md-6">
|
||||
{!! Former::text('first_name')
|
||||
->placeholder(trans('texts.first_name'))
|
||||
->autocomplete('given-name')
|
||||
->label('') !!}
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
@ -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')) !!}
|
||||
<div class="form-group" style="margin-top:-15px">
|
||||
<div class="col-md-8 col-md-offset-4">
|
||||
<div id="bank_name"></div>
|
||||
</div>
|
||||
</div>
|
||||
{!! 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')) !!}
|
||||
<div class="form-group" style="margin-top:-15px">
|
||||
<div class="col-md-8 col-md-offset-4">
|
||||
<div id="bank_name"></div>
|
||||
</div>
|
||||
</div>
|
||||
{!! Former::text('')
|
||||
->id('account_number')
|
||||
->label(trans('texts.account_number')) !!}
|
||||
{!! Former::text('')
|
||||
->id('confirm_account_number')
|
||||
->label(trans('texts.confirm_account_number')) !!}
|
||||
</div>
|
||||
{!! Former::checkbox('authorize_ach')
|
||||
->text(trans('texts.ach_authorization', ['company'=>$account->getDisplayName()]))
|
||||
->label(' ') !!}
|
||||
<div class="col-md-8 col-md-offset-4">
|
||||
{!! 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();
|
||||
|
@ -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)
|
||||
<a href="javasript::void" onclick="completeVerification('{{$paymentMethod->public_id}}','{{$paymentMethod->currency->symbol}}')">({{trans('texts.complete_verification')}})</a>
|
||||
|
@ -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" >
|
||||
$(function() {
|
||||
var $form = $('.payment-form');
|
||||
braintree.setup("{{ $braintreeClientToken }}", "custom", {
|
||||
id: "payment-form",
|
||||
hostedFields: {
|
||||
@ -29,7 +30,6 @@
|
||||
}
|
||||
},
|
||||
onError: function(e) {
|
||||
var $form = $('.payment-form');
|
||||
$form.find('button').prop('disabled', false);
|
||||
// Show the errors on the form
|
||||
if (e.details && e.details.invalidFieldKeys.length) {
|
||||
@ -48,6 +48,12 @@
|
||||
else {
|
||||
$('#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) {
|
||||
|
Loading…
Reference in New Issue
Block a user