Support updating card on file

This commit is contained in:
Hillel Coren 2017-06-21 23:36:59 +03:00
parent 1616746267
commit b2f0012aae
10 changed files with 84 additions and 51 deletions

View File

@ -75,7 +75,7 @@ class OnlinePaymentController extends BaseController
]); ]);
} }
if (! $invitation->invoice->canBePaid()) { if (! $invitation->invoice->canBePaid() && ! request()->update) {
return redirect()->to('view/' . $invitation->invitation_key); return redirect()->to('view/' . $invitation->invitation_key);
} }
@ -120,14 +120,16 @@ class OnlinePaymentController extends BaseController
$gatewayTypeId = Session::get($invitation->id . 'gateway_type'); $gatewayTypeId = Session::get($invitation->id . 'gateway_type');
$paymentDriver = $invitation->account->paymentDriver($invitation, $gatewayTypeId); $paymentDriver = $invitation->account->paymentDriver($invitation, $gatewayTypeId);
if (! $invitation->invoice->canBePaid()) { if (! $invitation->invoice->canBePaid() && ! request()->update) {
return redirect()->to('view/' . $invitation->invitation_key); return redirect()->to('view/' . $invitation->invitation_key);
} }
try { try {
$paymentDriver->completeOnsitePurchase($request->all()); $paymentDriver->completeOnsitePurchase($request->all());
if ($paymentDriver->isTwoStep()) { if (request()->update) {
return redirect('/client/dashboard')->withMessage(trans('texts.updated_payment_details'));
} elseif ($paymentDriver->isTwoStep()) {
Session::flash('warning', trans('texts.bank_account_verification_next_steps')); Session::flash('warning', trans('texts.bank_account_verification_next_steps'));
} else { } else {
Session::flash('message', trans('texts.applied_payment')); Session::flash('message', trans('texts.applied_payment'));

View File

@ -559,6 +559,15 @@ class Client extends EntityModel
{ {
return $this->payment_terms == -1 ? 0 : $this->payment_terms; return $this->payment_terms == -1 ? 0 : $this->payment_terms;
} }
public function firstInvitationKey()
{
if ($invoice = $this->invoices->first()) {
if ($invitation = $invoice->invitations->first()) {
return $invitation->invitation_key;
}
}
}
} }
Client::creating(function ($client) { Client::creating(function ($client) {

View File

@ -157,6 +157,11 @@ class BasePaymentDriver
return redirect()->to('view/' . $this->invitation->invitation_key); return redirect()->to('view/' . $this->invitation->invitation_key);
} }
$url = 'payment/' . $this->invitation->invitation_key;
if (request()->update) {
$url .= '?update=true';
}
$data = [ $data = [
'details' => ! empty($input['details']) ? json_decode($input['details']) : false, 'details' => ! empty($input['details']) ? json_decode($input['details']) : false,
'accountGateway' => $this->accountGateway, 'accountGateway' => $this->accountGateway,
@ -164,7 +169,7 @@ class BasePaymentDriver
'gateway' => $gateway, 'gateway' => $gateway,
'showAddress' => $this->accountGateway->show_address, 'showAddress' => $this->accountGateway->show_address,
'showBreadcrumbs' => false, 'showBreadcrumbs' => false,
'url' => 'payment/' . $this->invitation->invitation_key, 'url' => $url,
'amount' => $this->invoice()->getRequestedAmount(), 'amount' => $this->invoice()->getRequestedAmount(),
'invoiceNumber' => $this->invoice()->invoice_number, 'invoiceNumber' => $this->invoice()->invoice_number,
'client' => $this->client(), 'client' => $this->client(),
@ -293,7 +298,7 @@ class BasePaymentDriver
} }
} }
if ($this->isTwoStep()) { if ($this->isTwoStep() || request()->update) {
return; return;
} }

View File

@ -2269,6 +2269,9 @@ $LANG = array(
'select_label' => 'Select Label', 'select_label' => 'Select Label',
'label' => 'Label', 'label' => 'Label',
'service' => 'Service', 'service' => 'Service',
'update_payment_details' => 'Update payment details',
'updated_payment_details' => 'Successfully updated payment details',
'update_credit_card' => 'Update Credit Card',
); );

View File

@ -29,7 +29,7 @@
<center> <center>
@if(isset($amount)) @if(isset($amount))
{!! Button::success(strtoupper(trans('texts.pay_now') . ' - ' . $account->formatMoney($amount, $client, CURRENCY_DECORATOR_CODE) )) {!! Button::success(request()->update ? strtoupper(trans('texts.submit')) : strtoupper(trans('texts.pay_now') . ' - ' . $account->formatMoney($amount, $client, CURRENCY_DECORATOR_CODE) ))
->submit() ->submit()
->large() !!} ->large() !!}
@else @else

View File

@ -316,11 +316,12 @@
<p>&nbsp;</p> <p>&nbsp;</p>
<center> <center>
@if (isset($invitation)) @if (isset($invitation))
{!! Button::normal(strtoupper(trans('texts.cancel')))->large()->asLinkTo($invitation->getLink()) !!} {!! Button::normal(strtoupper(trans('texts.cancel')))->large()->asLinkTo(HTMLUtils::previousUrl('/credits')) !!}
&nbsp;&nbsp; &nbsp;&nbsp;
@endif @endif
@if (isset($amount)) @if (isset($amount))
{!! Button::success(strtoupper(trans('texts.pay_now') . ' - ' . $account->formatMoney($amount, $client, CURRENCY_DECORATOR_CODE) )) {!! Button::success(request()->update ? strtoupper(trans('texts.submit')) : strtoupper(trans('texts.pay_now') . ' - ' . $account->formatMoney($amount, $client, CURRENCY_DECORATOR_CODE) ))
->submit() ->submit()
->large() !!} ->large() !!}
@else @else

View File

@ -15,7 +15,11 @@
<header> <header>
@if ($client && isset($invoiceNumber)) @if ($client && isset($invoiceNumber))
<h2>{{ $client->getDisplayName() }}</h2> <h2>{{ $client->getDisplayName() }}</h2>
@if (request()->update)
<h3>{{ trans('texts.update_payment_details') }}</h3>
@else
<h3>{{ trans('texts.invoice') . ' ' . $invoiceNumber }}<span>|&nbsp; {{ trans('texts.amount_due') }}: <em>{{ $account->formatMoney($amount, $client, CURRENCY_DECORATOR_CODE) }}</em></span></h3> <h3>{{ trans('texts.invoice') . ' ' . $invoiceNumber }}<span>|&nbsp; {{ trans('texts.amount_due') }}: <em>{{ $account->formatMoney($amount, $client, CURRENCY_DECORATOR_CODE) }}</em></span></h3>
@endif
@elseif ($paymentTitle) @elseif ($paymentTitle)
<h2>{{ $paymentTitle }} <h2>{{ $paymentTitle }}
@if(isset($paymentSubtitle)) @if(isset($paymentSubtitle))

View File

@ -77,9 +77,18 @@
</script> </script>
@endif @endif
@if(!empty($paymentMethods) && count($paymentMethods)) @if ($invitationKey = $client->firstInvitationKey())
<h3>{{ trans('texts.payment_methods') }}</h3> <h3>
{{ trans('texts.payment_methods') }}
@if ($account->getGatewayByType(GATEWAY_TYPE_CREDIT_CARD)
&& $account->getGatewayByType(GATEWAY_TYPE_TOKEN)
&& $account->token_billing_type_id != TOKEN_BILLING_DISABLED)
&nbsp;&nbsp;
{!! Button::success(strtoupper(trans('texts.update_credit_card')))->asLinkTo(URL::to("/payment/$invitationKey/credit_card?update=true")) !!}
@endif
</h3>
@if(!empty($paymentMethods) && count($paymentMethods))
@foreach ($paymentMethods as $paymentMethod) @foreach ($paymentMethods as $paymentMethod)
<div class="payment_method"> <div class="payment_method">
<span class="payment_method_img_container"> <span class="payment_method_img_container">
@ -123,7 +132,7 @@
</div> </div>
@endforeach @endforeach
@endif @endif
@endif
<center> <center>
@if (false && $account->getGatewayByType(GATEWAY_TYPE_CREDIT_CARD) && $account->getGatewayByType(GATEWAY_TYPE_TOKEN)) @if (false && $account->getGatewayByType(GATEWAY_TYPE_CREDIT_CARD) && $account->getGatewayByType(GATEWAY_TYPE_TOKEN))

View File

@ -240,7 +240,7 @@
->large() !!} ->large() !!}
@if ($accountGateway->getPlaidEnabled() && !empty($amount)) @if ($accountGateway->getPlaidEnabled() && !empty($amount))
{!! Button::success(strtoupper(trans('texts.pay_now') . ' - ' . $account->formatMoney($amount, $client, CURRENCY_DECORATOR_CODE) )) {!! Button::success(request()->update ? strtoupper(trans('texts.submit')) : strtoupper(trans('texts.pay_now') . ' - ' . $account->formatMoney($amount, $client, CURRENCY_DECORATOR_CODE) ))
->submit() ->submit()
->withAttributes(['style'=>'display:none', 'id'=>'pay_now_button']) ->withAttributes(['style'=>'display:none', 'id'=>'pay_now_button'])
->large() !!} ->large() !!}

View File

@ -33,7 +33,7 @@
{!! Button::normal(strtoupper(trans('texts.cancel')))->large()->asLinkTo($invitation->getLink()) !!} {!! Button::normal(strtoupper(trans('texts.cancel')))->large()->asLinkTo($invitation->getLink()) !!}
&nbsp;&nbsp; &nbsp;&nbsp;
@if(isset($amount) && empty($paymentMethodPending)) @if(isset($amount) && empty($paymentMethodPending))
{!! Button::success(strtoupper(trans('texts.pay_now') . ' - ' . $account->formatMoney($amount, $client, CURRENCY_DECORATOR_CODE) )) {!! Button::success(request()->update ? strtoupper(trans('texts.submit')) : strtoupper(trans('texts.pay_now') . ' - ' . $account->formatMoney($amount, $client, CURRENCY_DECORATOR_CODE) ))
->submit() ->submit()
->large() !!} ->large() !!}
@else @else