mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
Fixes for tests
This commit is contained in:
parent
3af84f7de7
commit
724cccacfc
@ -32,7 +32,9 @@ class StoreCompanyGatewayRequest extends Request
|
||||
{
|
||||
$this->sanitize();
|
||||
|
||||
$rules = [];
|
||||
$rules = [
|
||||
'gateway_key' => 'required'
|
||||
];
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ class UpdateCompanyGatewayRequest extends Request
|
||||
$this->sanitize();
|
||||
|
||||
$rules = [
|
||||
'gateway_key' => 'required',
|
||||
];
|
||||
|
||||
return $rules;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -1,139 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com)
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Listeners\Invoice;
|
||||
|
||||
use App\Jobs\Company\UpdateCompanyLedgerWithInvoice;
|
||||
use App\Jobs\Company\UpdateCompanyLedgerWithPayment;
|
||||
use App\Models\SystemLog;
|
||||
use App\Utils\Traits\SystemLogTrait;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
|
||||
class UpdateInvoicePayment implements ShouldQueue
|
||||
{
|
||||
use SystemLogTrait;
|
||||
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param object $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle($event)
|
||||
{
|
||||
$payment = $event->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);
|
||||
}
|
||||
*/
|
@ -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()
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class EventServiceProvider extends ServiceProvider
|
||||
],
|
||||
PaymentWasCreated::class => [
|
||||
PaymentCreatedActivity::class,
|
||||
UpdateInvoicePayment::class,
|
||||
//UpdateInvoicePayment::class,
|
||||
UpdateInvoiceInvitations::class,
|
||||
],
|
||||
'App\Events\ClientWasArchived' => [
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user