Prechádzať zdrojové kódy

IC portal link and logic updates

Vijayakrishnan 3 rokov pred
rodič
commit
3ea56c40ac

+ 39 - 9
app/Http/Controllers/InvoiceController.php

@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers;
 
+use App\Lib\Backend;
 use App\Models\AppSession;
 use App\Models\BillingReport;
 use App\Models\CareMonth;
@@ -45,8 +46,10 @@ use App\Models\ClientMemo;
 use Carbon\Carbon;
 use Cassandra\Custom;
 use Illuminate\Pagination\LengthAwarePaginator;
+use Illuminate\Support\Facades\Cookie;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Http;
+use MongoDB\Driver\Session;
 use PDF;
 use DateTime;
 use DateTimeZone;
@@ -131,25 +134,52 @@ class InvoiceController extends Controller
         return view ('app.invoice-center.invoice-transactions', compact('records', 'invoice'));
     }
 
-    public function icPayInvoice(Request $request, $invoiceSlug) {
-        $invoice = Invoice::where('payment_link_slug', $invoiceSlug)->where('is_active', true)->first();
+    private function getICCustomer($sessionKey) {
+        $customer = false;
+        if($sessionKey) {
+            Cookie::queue('sessionKey', $sessionKey);
+        }
+        else {
+            $session = get_current_session();
+            if(!$session) {
+                abort(403);
+            }
+            else {
+                $customer = Customer::where('id', $session->customer_id)->first();
+                if(!$customer) {
+                    abort(403);
+                }
+            }
+        }
+        return $customer;
+    }
+
+    public function icPayInvoice(Request $request, $invoiceUid, $sessionKey = '') {
+        $customer = $this->getICCustomer($sessionKey);
+        if(!$customer) {
+            return redirect(route('icPayInvoice', ['invoiceUid' => $invoiceUid]));
+        }
+        $invoice = Invoice::where('uid', $invoiceUid)->where('is_active', true)->first();
         if (!$invoice) abort(404);
-        $customer = $invoice->customer;
         $company = $customer->company;
         return view('app.invoice-center.ic-pay-invoice', compact('invoice', 'customer', 'company'));
     }
 
-    public function icCustomerPortal(Request $request, $customerSlug) {
-        $customer = Customer::where('slug', $customerSlug)->where('is_active', true)->first();
-        if (!$customer) abort(404);
+    public function icCustomerPortal(Request $request, $sessionKey = '') {
+        $customer = $this->getICCustomer($sessionKey);
+        if(!$customer) {
+            return redirect(route('icCustomerPortal'));
+        }
         $client = $customer->client;
         $company = $customer->company;
         return view('app.invoice-center.ic-customer-portal', compact('customer', 'company'));
     }
 
-    public function icManageAccount(Request $request, $customerSlug) {
-        $customer = Customer::where('slug', $customerSlug)->where('is_active', true)->first();
-        if (!$customer) abort(404);
+    public function icManageAccount(Request $request, $sessionKey = '') {
+        $customer = $this->getICCustomer($sessionKey);
+        if(!$customer) {
+            return redirect(route('icManageAccount'));
+        }
         $client = $customer->client;
         $company = $customer->company;
         return view('app.invoice-center.ic-manage-account', compact('customer', 'company', 'client'));

+ 51 - 0
resources/views/app/invoice-center/_ic-add-payment-method-moe.blade.php

@@ -0,0 +1,51 @@
+<div moe relative>
+    <a start show href="#" class="text-nowrap">{{@$label ?: 'Add Payment Method'}}</a>
+    <form url="/api/paymentMethod/createCard">
+        <input type="hidden" name="customerUid" value="{{$customer->uid}}">
+        <p class="text-secondary font-weight-bold mb-1 text-nowrap">Add Payment Method</p>
+        <div class="mb-2">
+            <lable class="mb-1 text-secondary text-sm">Card Number</lable>
+            <input type="text" name="cardNumber" value="" class="form-control form-control-sm min-width-200px" required>
+        </div>
+        <div class="mb-2">
+            <lable class="mb-1 text-secondary text-sm">Expiry Date</lable>
+            <div class="d-flex align-items-start">
+                <select class="form-control form-control-sm" name="expirationMonth" required>
+                    <option value="">-- select --</option>
+                    <option value="1">January</option>
+                    <option value="2">February</option>
+                    <option value="3">March</option>
+                    <option value="4">April</option>
+                    <option value="5">May</option>
+                    <option value="6">June</option>
+                    <option value="7">July</option>
+                    <option value="8">August</option>
+                    <option value="9">September</option>
+                    <option value="10">October</option>
+                    <option value="11">November</option>
+                    <option value="12">December</option>
+                </select>
+                <select class="form-control form-control-sm ml-2" name="expirationYear" required>
+                    <option value="">-- select --</option>
+                    <option value="2022">2022</option>
+                    <option value="2023">2023</option>
+                    <option value="2024">2024</option>
+                    <option value="2025">2025</option>
+                    <option value="2026">2026</option>
+                </select>
+            </div>
+        </div>
+        <div class="mb-2">
+            <lable class="mb-1 text-secondary text-sm">CVV/CCV Number</lable>
+            <input type="text" name="ccv" value="" class="form-control form-control-sm min-width-200px" required>
+        </div>
+        <div class="mb-2">
+            <lable class="mb-1 text-secondary text-sm">Billing Zip</lable>
+            <input type="text" name="billingZip" value="" class="form-control form-control-sm min-width-200px">
+        </div>
+        <div class="d-flex align-items-center">
+            <button submit class="btn btn-sm btn-primary me-2">Submit</button>
+            <button cancel class="btn btn-sm btn-default">Cancel</button>
+        </div>
+    </form>
+</div>

+ 1 - 1
resources/views/app/invoice-center/ic-customer-portal.blade.php

@@ -32,7 +32,7 @@
                     @foreach($customer->invoices as $invoice)
                         <tr>
                             <td>{{friendly_date($invoice->created_at)}}</td>
-                            <td><a href="{{route('icPayInvoice', ['invoiceSlug' => $invoice->payment_link_slug])}}">{{$invoice->description}}</a></td>
+                            <td><a href="{{route('icPayInvoice', ['invoiceUid' => $invoice->uid])}}">{{$invoice->description}}</a></td>
                             <td class="text-dark">${{!is_null($invoice->amount) ? $invoice->amount : 0}}</td>
                             <td class="text-success">${{!is_null($invoice->paid) ? $invoice->paid : 0}}</td>
                             <td class="font-weight-bold text-warning-dark">${{!is_null($invoice->balance) ? $invoice->balance : 0}}</td>

+ 3 - 56
resources/views/app/invoice-center/ic-manage-account.blade.php

@@ -3,7 +3,7 @@
     <div class="container mcp-theme-1">
         <div class="d-flex align-items-baseline mt-3 mb-2">
             <h3 class="font-size-16 font-weight-bold text-dark">Manage Account</h3>
-            <a href="{{route('icCustomerPortal', ['customerSlug' => $customer->slug])}}" class="ml-auto">
+            <a href="{{route('icCustomerPortal')}}" class="ml-auto">
                 <i class="fa fa-chevron-left"></i>
                 Back to Home
             </a>
@@ -13,61 +13,8 @@
             <div class="col-md-8">
                 <div class="d-flex align-items-baseline mt-4">
                     <h4 class="title-sm m-0">Payment Methods</h4>
-                    <div moe class="ml-3">
-                        <a start show href="#" class="text-nowrap">Add Payment Method</a>
-                        <form url="/api/paymentMethod/create">
-                            <input type="hidden" name="customerUid" value="{{$customer->uid}}">
-                            <input type="hidden" name="customerSlug" value="{{$customer->slug}}">
-                            <p class="text-secondary font-weight-bold mb-1 text-nowrap">Add Payment Method</p>
-                            <div class="mb-2">
-                                <lable class="mb-1 text-secondary text-sm">Card Number</lable>
-                                <input type="text" name="cardNumber" value="" class="form-control form-control-sm min-width-200px" required>
-                            </div>
-                            <div class="mb-2">
-                                <lable class="mb-1 text-secondary text-sm">Name nn Card</lable>
-                                <input type="text" name="nameOnCard" value="" class="form-control form-control-sm min-width-200px" required>
-                            </div>
-                            <div class="mb-2">
-                                <lable class="mb-1 text-secondary text-sm">Expiry Date</lable>
-                                <div class="d-flex align-items-start">
-                                    <select class="form-control form-control-sm" name="expirationMonth" required>
-                                        <option value="">-- select --</option>
-                                        <option value="1">January</option>
-                                        <option value="2">February</option>
-                                        <option value="3">March</option>
-                                        <option value="4">April</option>
-                                        <option value="5">May</option>
-                                        <option value="6">June</option>
-                                        <option value="7">July</option>
-                                        <option value="8">August</option>
-                                        <option value="9">September</option>
-                                        <option value="10">October</option>
-                                        <option value="11">November</option>
-                                        <option value="12">December</option>
-                                    </select>
-                                    <select class="form-control form-control-sm ml-2" name="expirationYear" required>
-                                        <option value="">-- select --</option>
-                                        <option value="2022">2022</option>
-                                        <option value="2023">2023</option>
-                                        <option value="2024">2024</option>
-                                        <option value="2025">2025</option>
-                                        <option value="2026">2026</option>
-                                    </select>
-                                </div>
-                            </div>
-                            <div class="mb-2">
-                                <lable class="mb-1 text-secondary text-sm">CVV/CCV Number</lable>
-                                <input type="text" name="ccv" value="" class="form-control form-control-sm min-width-200px" required>
-                            </div>
-                            <div class="mb-2">
-                                <lable class="mb-1 text-secondary text-sm">Billing Zip</lable>
-                                <input type="text" name="billingZip" value="" class="form-control form-control-sm min-width-200px">
-                            </div>
-                            <div class="d-flex align-items-center">
-                                <button submit class="btn btn-sm btn-primary me-2">Submit</button>
-                                <button cancel class="btn btn-sm btn-default">Cancel</button>
-                            </div>
-                        </form>
+                    <div class="ml-3">
+                        @include('app.invoice-center._ic-add-payment-method-moe')
                     </div>
                 </div>
                 <hr class="red-underline">

+ 6 - 3
resources/views/app/invoice-center/ic-pay-invoice.blade.php

@@ -3,7 +3,7 @@
 <div class="container mcp-theme-1">
     <div class="d-flex align-items-baseline mt-3 mb-2">
         <h3 class="font-size-16 font-weight-bold text-dark">Invoice</h3>
-        <a href="{{route('icCustomerPortal', ['customerSlug' => $customer->slug])}}" class="ml-auto">
+        <a href="{{route('icCustomerPortal')}}" class="ml-auto">
             <i class="fa fa-chevron-left"></i>
             Back to Home
         </a>
@@ -79,7 +79,6 @@
                                             <p class="mb-2 text-left">Pay Invoice</p>
                                             <input type="hidden" name="invoiceUid" value="{{$invoice->uid}}">
                                             <input type="hidden" name="amount" value="{{$invoice->balance}}">
-                                            <input type="hidden" name="paymentLinkSlug" value="{{$invoice->payment_link_slug}}">
                                             <div class="mb-2">
                                                 <label class="text-sm text-secondary mb-1">Payment Method</label>
                                                 <select name="paymentMethodUid" class="form-control form-control-sm" required>
@@ -97,7 +96,11 @@
                                     </div>
                                 @else
                                     <div class="mt-3 border rounded border-secondary p-2 text-left text-warning-dark w-100">
-                                        You have not setup any payment methods yet. <a href="/ic/manageAccount/{{$customer->slug}}">Click here</a> to set one up.
+                                        You have not setup any payment methods yet.
+                                        <div class="d-inline-block">
+                                            @include('app.invoice-center._ic-add-payment-method-moe', ['label' => 'Click here'])
+                                        </div>
+                                        to set one up.
                                     </div>
                                 @endif
                             </div>

+ 1 - 1
resources/views/app/invoice-center/ic-rhs.blade.php

@@ -4,7 +4,7 @@
         <span class="font-weight-bold text-dark">${{!is_null($customer->customer_balance) ? $customer->customer_balance : 0}}</span>
     </div>
     @if(request()->route()->getName() !== 'icManageAccount')
-        <a href="/ic/manageAccount/{{$customer->slug}}" class="font-weight-bold mb-3 d-block">Manage Payment Methods</a>
+        <a href="/ic/manageAccount" class="font-weight-bold mb-3 d-block">Manage Payment Methods</a>
     @endif
     <h3 class="font-weight-bold mb-2 text-secondary">Redeem Gift Card</h3>
     <div moe>

+ 3 - 3
routes/web.php

@@ -782,6 +782,6 @@ Route::any("/nop", 'HomeController@nop')->name('nop');
 Route::get('/document-pdf/{uid}', 'DocumentsController@generateDocumentPDF')->name('generateDocumentPDF');
 
 // ic pages - client facing
-Route::get('/ic/home/{customerSlug}', 'InvoiceController@icCustomerPortal')->name('icCustomerPortal');
-Route::get('/ic/pay/{invoiceSlug}', 'InvoiceController@icPayInvoice')->name('icPayInvoice');
-Route::get('/ic/manageAccount/{customerSlug}', 'InvoiceController@icManageAccount')->name('icManageAccount');
+Route::get('/ic/home/{sessionKey?}', 'InvoiceController@icCustomerPortal')->name('icCustomerPortal');
+Route::get('/ic/pay/{invoiceUid}/{sessionKey?}', 'InvoiceController@icPayInvoice')->name('icPayInvoice');
+Route::get('/ic/manageAccount/{sessionKey?}', 'InvoiceController@icManageAccount')->name('icManageAccount');