diff --git a/app/Http/Controllers/ClientPortalController.php b/app/Http/Controllers/ClientPortalController.php index c2d850f0a1c5..9ee46c7b9ec4 100644 --- a/app/Http/Controllers/ClientPortalController.php +++ b/app/Http/Controllers/ClientPortalController.php @@ -203,7 +203,7 @@ class ClientPortalController extends BaseController if (!$invitation = $this->invoiceRepo->findInvoiceByInvitation($invitationKey)) { return RESULT_FAILURE; } - + $invitation->signature_base64 = Input::get('signature'); $invitation->signature_date = date_create(); $invitation->save(); diff --git a/app/Http/Controllers/OnlinePaymentController.php b/app/Http/Controllers/OnlinePaymentController.php index e7d709096e37..f30c47b87090 100644 --- a/app/Http/Controllers/OnlinePaymentController.php +++ b/app/Http/Controllers/OnlinePaymentController.php @@ -117,7 +117,8 @@ class OnlinePaymentController extends BaseController } else { Session::flash('message', trans('texts.applied_payment')); } - return redirect()->to('view/' . $invitation->invitation_key); + + return $this->completePurchase($invitation); } catch (Exception $exception) { return $this->error($paymentDriver, $exception, true); } @@ -152,12 +153,22 @@ class OnlinePaymentController extends BaseController if ($paymentDriver->completeOffsitePurchase(Input::all())) { Session::flash('message', trans('texts.applied_payment')); } - return redirect()->to($invitation->getLink()); + return $this->completePurchase($invitation, true); } catch (Exception $exception) { return $this->error($paymentDriver, $exception); } } + private function completePurchase($invitation, $isOffsite = false) + { + if ($redirectUrl = session('redirect_url:' . $invitation->invitation_key)) { + return redirect()->to($redirectUrl . '?invoice_id=' . $invitation->invoice->public_id); + } else { + // Allow redirecting to iFrame for offsite payments + return redirect()->to($invitation->getLink('view', ! $isOffsite)); + } + } + /** * @param $paymentDriver * @param $exception @@ -253,17 +264,18 @@ class OnlinePaymentController extends BaseController } $account = Account::whereAccountKey(Input::get('account_key'))->first(); - $redirectUrl = Input::get('redirect_url', URL::previous()); + $redirectUrl = Input::get('redirect_url'); + $failureUrl = URL::previous(); if ( ! $account || ! $account->enable_buy_now_buttons || ! $account->hasFeature(FEATURE_BUY_NOW_BUTTONS)) { - return redirect()->to("{$redirectUrl}/?error=invalid account"); + return redirect()->to("{$failureUrl}/?error=invalid account"); } Auth::onceUsingId($account->users[0]->id); $product = Product::scope(Input::get('product_id'))->first(); if ( ! $product) { - return redirect()->to("{$redirectUrl}/?error=invalid product"); + return redirect()->to("{$failureUrl}/?error=invalid product"); } $rules = [ @@ -274,7 +286,7 @@ class OnlinePaymentController extends BaseController $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { - return redirect()->to("{$redirectUrl}/?error=" . $validator->errors()->first()); + return redirect()->to("{$failureUrl}/?error=" . $validator->errors()->first()); } $data = [ @@ -300,6 +312,10 @@ class OnlinePaymentController extends BaseController $invitation = $invoice->invitations[0]; $link = $invitation->getLink(); + if ($redirectUrl) { + session(['redirect_url:' . $invitation->invitation_key => $redirectUrl]); + } + if ($gatewayTypeAlias) { return redirect()->to($invitation->getLink('payment') . "/{$gatewayTypeAlias}"); } else { diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 636e9ac987db..850cd8d4062c 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2255,6 +2255,8 @@ $LANG = array( 'live_preview_help' => 'Display a live PDF preview on the invoice page.
Disable this to improve performance when editing invoices.', 'force_pdfjs_help' => 'Replace the built-in PDF viewer in :chrome_link and :firefox_link.
Enable this if your browser is automatically downloading the PDF.', 'force_pdfjs' => 'PDF Viewer', + 'redirect_url' => 'Redirect URL', + 'redirect_url_help' => 'Optionally specify a URL to redirect to after a payment is made.', ); diff --git a/resources/views/accounts/client_portal.blade.php b/resources/views/accounts/client_portal.blade.php index 715268095239..efb309a9bcb4 100644 --- a/resources/views/accounts/client_portal.blade.php +++ b/resources/views/accounts/client_portal.blade.php @@ -155,6 +155,11 @@ ->inlineHelp('buy_now_buttons_warning') ->addGroupClass('product-select') !!} + {!! Former::text('redirect_url') + ->onchange('updateBuyNowButtons()') + ->placeholder('https://www.example.com') + ->help('redirect_url_help') !!} + {!! Former::checkboxes('client_fields') ->onchange('updateBuyNowButtons()') ->checkboxes([ @@ -274,6 +279,7 @@ var productId = $('#product').val(); var landingPage = $('input[name=landing_page_type]:checked').val() var paymentType = landingPage == 'payment' ? '/' + $('#payment_type').val() : ''; + var redirectUrl = $('#redirect_url').val(); var form = ''; var link = ''; @@ -294,6 +300,11 @@ } @endforeach + if (redirectUrl) { + link += '&redirect_url=' + encodeURIComponent(redirectUrl); + form += '' + "\n"; + } + form += '' + "\n" + ''; }