Samson Mutunga 1 kuukausi sitten
vanhempi
commit
e1fbed7a89

+ 31 - 0
app/Http/Controllers/InvoiceController.php

@@ -301,5 +301,36 @@ ORDER BY client.name_first, client.name_last",
             "data" => $invoices
         ]);
     }
+
+    public function customerInvoiceSavePayUrl(Request $request){
+        $invoiceUid = $request->get('invoiceUid');
+        $payUrl = $request->get('payUrl');
+
+        if(!$invoiceUid){
+            return json_encode([
+                "success" => false,
+                "message" => 'Invoice UID missing!'
+            ]);
+        }
+
+        $invoice = Invoice::where('uid', $invoiceUid)->first();
+        if(!$invoice){
+            return json_encode([
+                "success" => false,
+                "message" => 'Invalid invoice UID!'
+            ]);
+        }
+
+        $detailJson = json_decode($invoice->detail_json ?? '{}', true);
+        $detailJson['payUrl'] = $payUrl;
+        $invoice->detail_json = json_encode($detailJson);
+        $invoice->save();
+
+        return json_encode([
+            "success" => true,
+            "data" => $invoice->uid
+        ]);
+
+    }
    
 }

+ 3 - 0
app/Models/PaymentMethod.php

@@ -12,6 +12,9 @@ class PaymentMethod extends Model
 
     public function displayName(){
         $parsed = json_decode($this->detail_json);
+        if(!@$parsed->card){
+            return "Card ending in <b>{$this->card_last_four}</b>";
+        }
         return "<b>{$parsed->card->brand}</b> ending in <b>{$parsed->card->last4}</b>, expiring {$parsed->card->exp_month} / {$parsed->card->exp_year}";
     }
 }

+ 2 - 0
resources/views/app/invoice-center/ic-pay-invoice.blade.php

@@ -3,10 +3,12 @@
 <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>
+        @if($performer->session_type !== 'CUSTOMER')
         <a href="{{route('icCustomerPortal')}}" class="ml-auto">
             <i class="fa fa-chevron-left"></i>
             Back to Home
         </a>
+        @endif
     </div>
     <hr class="mt-0 mb-3">
     <div class="row">

+ 27 - 0
resources/views/app/patient/patient-requests.blade.php

@@ -30,6 +30,9 @@
                         <td>
                             @if ($patientRequest->invoice)
                                 <a href="#" data-invoice-uid="{{ $patientRequest->invoice->uid }}" data-uid="{{ $patientRequest->invoice->customer->uid }}"
+                        class="generate-and-store-ic-pay-url" native target="_blank">Request Pay</a>
+                        <small class="text-muted px-1">|</small>
+                        <a href="#" data-invoice-uid="{{ $patientRequest->invoice->uid }}" data-uid="{{ $patientRequest->invoice->customer->uid }}"
                         class="generate-and-copy-ic-pay-url" native target="_blank">Copy Pay Link</a>
                             @else
                                 <div moe>
@@ -72,6 +75,7 @@
     <script>
     (function($) {
         var patientRequestsComponent = {
+
             init: function() {
                 let parentSegment = $('body');
                 parentSegment.find('.copy-target')
@@ -96,6 +100,29 @@
                         });
                         return false;
                     });
+
+                //Save pay url to invoice detailJson
+                parentSegment.find('.generate-and-store-ic-pay-url')
+                    .off('click.generate-and-store-ic-pay-url')
+                    .on('click.generate-and-store-ic-pay-url', function() {
+                        $.post('/api/session/proLogInAsCustomer', {
+                            customerUid: $(this).attr('data-uid')
+                        }, _data => {
+                            if (!hasResponseError(_data)) {
+                                const invoiceUid = $(this).attr('data-invoice-uid');
+                                const payUrl = '{{ config('app.url') }}/ic/pay/' + invoiceUid + '/' + _data.data
+                                console.log({payUrl});
+                                $.post('/customer/invoice/save-pay-url', {invoiceUid: invoiceUid, payUrl: payUrl }, function(response){
+                                    if(response.success){
+                                        toastr.success('Inoice payment url generated!');
+                                    }else{
+                                        toastr.error(response.message);
+                                    }
+                                }, 'json');
+                            }
+                        });
+                        return false;
+                    });
             }
         };
         patientRequestsComponent.init();

+ 1 - 0
routes/web.php

@@ -765,6 +765,7 @@ Route::middleware('pro.auth')->group(function () {
     Route::get('/client-suggest', 'InvoiceController@clientSuggestJSON')->name('client-suggest-json');
     Route::get('/customer-suggest', 'InvoiceController@customerSuggestJSON')->name('customer-suggest-json');
     Route::get('/customer/invoicesJSON/{customer}', 'InvoiceController@customerInvoicesJSON')->name('customer-invoices-json');
+    Route::post('/customer/invoice/save-pay-url', 'InvoiceController@customerInvoiceSavePayUrl')->name('customer-invoice-save-pay-url');
 
     // Pro suggest
     Route::get('/pro-suggest', 'HomeController@proSuggest');