diff --git a/app/Http/Requests/CompanyGateway/StoreCompanyGatewayRequest.php b/app/Http/Requests/CompanyGateway/StoreCompanyGatewayRequest.php index e440f2cb894b..5cb2484a2a5a 100644 --- a/app/Http/Requests/CompanyGateway/StoreCompanyGatewayRequest.php +++ b/app/Http/Requests/CompanyGateway/StoreCompanyGatewayRequest.php @@ -32,7 +32,9 @@ class StoreCompanyGatewayRequest extends Request { $this->sanitize(); - $rules = []; + $rules = [ + 'gateway_key' => 'required' + ]; return $rules; } diff --git a/app/Http/Requests/CompanyGateway/UpdateCompanyGatewayRequest.php b/app/Http/Requests/CompanyGateway/UpdateCompanyGatewayRequest.php index 21841c7694ef..df88e5a3b5aa 100644 --- a/app/Http/Requests/CompanyGateway/UpdateCompanyGatewayRequest.php +++ b/app/Http/Requests/CompanyGateway/UpdateCompanyGatewayRequest.php @@ -32,7 +32,6 @@ class UpdateCompanyGatewayRequest extends Request $this->sanitize(); $rules = [ - 'gateway_key' => 'required', ]; return $rules; diff --git a/app/Jobs/Invoice/MarkInvoicePaid.php b/app/Jobs/Invoice/MarkInvoicePaid.php index c24fbb40ab23..e49541258b4f 100644 --- a/app/Jobs/Invoice/MarkInvoicePaid.php +++ b/app/Jobs/Invoice/MarkInvoicePaid.php @@ -56,6 +56,7 @@ class MarkInvoicePaid implements ShouldQueue $payment->amount = $this->invoice->balance; $payment->status_id = Payment::STATUS_COMPLETED; $payment->client_id = $this->invoice->client_id; + $payment->transaction_reference = ctrans('texts.manual_entry'); /* Create a payment relationship to the invoice entity */ $payment->save(); $payment->invoices()->save($this->invoice); @@ -65,8 +66,9 @@ class MarkInvoicePaid implements ShouldQueue //$invoice = ApplyPaymentToInvoice::dispatchNow($payment, $this->invoice); event(new PaymentWasCreated($payment)); - UpdateCompanyLedgerWithPayment::dispatchNow($payment, $payment->amount); - + UpdateCompanyLedgerWithPayment::dispatchNow($payment, ($payment->amount*-1)); + $this->invoice->updateBalance(($payment->amount*-1)); + return $this->invoice; } } diff --git a/app/Listeners/Invoice/UpdateInvoicePayment.php b/app/Listeners/Invoice/UpdateInvoicePayment.php deleted file mode 100644 index 9f0ea3a7ecca..000000000000 --- a/app/Listeners/Invoice/UpdateInvoicePayment.php +++ /dev/null @@ -1,139 +0,0 @@ -payment; - $invoices = $payment->invoices(); - - $invoices_total = $invoices->sum('balance'); - - /* Simplest scenario*/ - if($invoices_total == $payment->amount) - { - $invoices->each(function ($invoice) use($payment){ - - UpdateCompanyLedgerWithPayment::dispatchNow($payment, ($invoice->balance*-1)); - $invoice->clearPartial(); - $invoice->updateBalance($invoice->balance*-1); - - }); - - } - else { - - $total = 0; - - foreach($invoice as $invoice) - { - - if($invoice->hasPartial()) - $total += $invoice->partial; - else - $total += $invoice->balance; - - Log::error("total = {$total}"); - } - - /* test if there is a batch of partial invoices that have been paid */ - if($payment->amount == $total) - { - - $invoices->each(function ($invoice) use($payment){ - - if($invoice->hasPartial()) { - - UpdateCompanyLedgerWithPayment::dispatchNow($payment, ($invoice->partial*-1)); - $invoice->updateBalance($invoice->partial*-1); - $invoice->clearPartial(); - $invoice->setDueDate(); - //todo do we need to mark it as a partial? - } - else - { - UpdateCompanyLedgerWithPayment::dispatchNow($payment, ($invoice->balance*-1)); - $invoice->clearPartial(); - $invoice->updateBalance($invoice->balance*-1); - } - - }); - - } - else { - - $data = [ - 'payment' => $payment, - 'invoices' => $invoices, - 'invoices_total' => $invoices_total, - 'payment_amount' => $payment->amount, - 'partial_check_amount' => $total, - ]; - - - $this->sysLog($data, SystemLog::GATEWAY_RESPONSE, SystemLog::PAYMENT_RECONCILIATION_FAILURE); - - throw new Exception('payment amount does not match invoice totals'); - } - - - } - } -} - -/* - $payment = $event->payment; - $invoice = $payment->invoice; - $adjustment = $payment->amount * -1; - $partial = max(0, $invoice->partial - $payment->amount); - - $invoice->updateBalances($adjustment, $partial); - $invoice->updatePaidStatus(true); - - // store a backup of the invoice - $activity = Activity::wherePaymentId($payment->id) - ->whereActivityTypeId(ACTIVITY_TYPE_CREATE_PAYMENT) - ->first(); - $activity->json_backup = $invoice->hidePrivateFields()->toJSON(); - $activity->save(); - - if ($invoice->balance == 0 && $payment->account->auto_archive_invoice) { - $invoiceRepo = app('App\Ninja\Repositories\InvoiceRepository'); - $invoiceRepo->archive($invoice); - } -*/ \ No newline at end of file diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 5fbdf24660b8..166c569ce795 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -326,7 +326,6 @@ class Invoice extends BaseModel */ public function updateBalance($balance_adjustment) { - \Log::error('updating invoice balance'); if ($this->is_deleted) return; @@ -339,7 +338,6 @@ class Invoice extends BaseModel $this->status_id = self::STATUS_PAID; $this->save(); - \Log::error('finished updatingoice balance'); } public function setDueDate() diff --git a/app/PaymentDrivers/PayPalExpressPaymentDriver.php b/app/PaymentDrivers/PayPalExpressPaymentDriver.php index 4a2dcba4241b..176aedc82724 100644 --- a/app/PaymentDrivers/PayPalExpressPaymentDriver.php +++ b/app/PaymentDrivers/PayPalExpressPaymentDriver.php @@ -103,12 +103,10 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver } else { // payment failed: display message to customer - $log = [ + $this->sysLog([ 'server_response' => $response->getData(), 'data' => $data - ]; - - $this->sysLog($log); + ]); throw new Exception("Error Processing Payment", 1); @@ -126,12 +124,11 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver return redirect()->route('client.invoices.index')->with('warning',ctrans('texts.status_voided')); } elseif (! $response->isSuccessful()) { - $data = [ + + $this->sysLog([ 'request' => $request->all(), 'server_response' => $response->getData() - ]; - - $this->sysLog($data); + ]); throw new Exception($response->getMessage()); } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 4660214e0ac9..57e84d7079ce 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -56,7 +56,7 @@ class EventServiceProvider extends ServiceProvider ], PaymentWasCreated::class => [ PaymentCreatedActivity::class, - UpdateInvoicePayment::class, + //UpdateInvoicePayment::class, UpdateInvoiceInvitations::class, ], 'App\Events\ClientWasArchived' => [ diff --git a/tests/Feature/CompanyGatewayApiTest.php b/tests/Feature/CompanyGatewayApiTest.php index 1303608b4907..832c0c2eac8b 100644 --- a/tests/Feature/CompanyGatewayApiTest.php +++ b/tests/Feature/CompanyGatewayApiTest.php @@ -92,19 +92,12 @@ class CompanyGatewayApiTest extends TestCase 'config' => 'changed', ]; - \Log::error('the id = '.$cg_id); + $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token - ])->put("/api/v1/company_gateways/{$cg_id}", $data); - - $response->assertStatus(200); - - $response = $this->withHeaders([ - 'X-API-SECRET' => config('ninja.api_secret'), - 'X-API-TOKEN' => $this->token - ])->put("/api/v1/company_gateways/{$cg_id}", $data); + ])->put("/api/v1/company_gateways/".$cg_id, $data); $response->assertStatus(200);