From b4437c645bb2975d7ca3c8acddb890cb629cf538 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 4 Jun 2017 21:55:39 +0300 Subject: [PATCH] Fix bug when using Braintree and terms checkbox --- resources/views/invoices/view.blade.php | 41 ++++++++++++++++--------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/resources/views/invoices/view.blade.php b/resources/views/invoices/view.blade.php index f5fedaf28218..e8bac6f604e8 100644 --- a/resources/views/invoices/view.blade.php +++ b/resources/views/invoices/view.blade.php @@ -67,7 +67,12 @@ }); paypalLink.click(function(e){ e.preventDefault(); - checkout.paypal.initAuthFlow(); + @if ($account->requiresAuthorization($invoice)) + window.pendingPaymentFunction = checkout.paypal.initAuthFlow; + showAuthorizationModal(); + @else + checkout.paypal.initAuthFlow(); + @endif }) }); @@ -212,19 +217,11 @@ $('#paymentButtons a').on('click', function(e) { e.preventDefault(); window.pendingPaymentHref = $(this).attr('href'); - @if ($account->showSignature($invoice)) - if (window.pendingPaymentInit) { - $("#signature").jSignature('reset'); - } - @endif - @if ($account->showAcceptTerms($invoice)) - $('#termsCheckbox').attr('checked', false); - @endif - $('#authenticationModal').modal('show'); + showAuthorizationModal(); }); @if ($account->showSignature($invoice)) - $('#authenticationModal').on('shown.bs.modal', function () { + $('#authorizationModal').on('shown.bs.modal', function () { if ( ! window.pendingPaymentInit) { window.pendingPaymentInit = true; $("#signature").jSignature().bind('change', function(e) { @@ -236,6 +233,18 @@ @endif }); + function showAuthorizationModal() { + @if ($account->showSignature($invoice)) + if (window.pendingPaymentInit) { + $("#signature").jSignature('reset'); + } + @endif + @if ($account->showAcceptTerms($invoice)) + $('#termsCheckbox').attr('checked', false); + @endif + $('#authorizationModal').modal('show'); + } + function onDownloadClick() { try { var doc = generatePDF(invoice, invoice.invoice_design.javascript, true); @@ -274,8 +283,12 @@ } function redirectToPayment() { - $('#authenticationModal').modal('hide'); - location.href = window.pendingPaymentHref; + $('#authorizationModal').modal('hide'); + if (window.pendingPaymentFunction) { + window.pendingPaymentFunction(); + } else { + location.href = window.pendingPaymentHref; + } } function setModalPayNowEnabled() { @@ -328,7 +341,7 @@ @endif @if ($account->requiresAuthorization($invoice)) -