mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Refactor payment events
This commit is contained in:
parent
3900529e83
commit
a83099dad8
@ -46,12 +46,12 @@ class UpdateInvoicePayment implements ShouldQueue
|
||||
public function handle()
|
||||
{
|
||||
|
||||
$invoices = $this->payment->invoices();
|
||||
$invoices = $this->payment->invoices()->get();
|
||||
|
||||
$invoices_total = $invoices->sum('balance');
|
||||
|
||||
/* Simplest scenario*/
|
||||
if($invoices_total == $this->payment->amount)
|
||||
if(strval($invoices_total) === strval($this->payment->amount))
|
||||
{
|
||||
$invoices->each(function ($invoice){
|
||||
|
||||
@ -66,7 +66,8 @@ class UpdateInvoicePayment implements ShouldQueue
|
||||
|
||||
$total = 0;
|
||||
|
||||
foreach($invoice as $invoice)
|
||||
|
||||
foreach($invoices as $invoice)
|
||||
{
|
||||
|
||||
if($invoice->hasPartial())
|
||||
@ -74,7 +75,6 @@ class UpdateInvoicePayment implements ShouldQueue
|
||||
else
|
||||
$total += $invoice->balance;
|
||||
|
||||
Log::error("total = {$total}");
|
||||
}
|
||||
|
||||
/* test if there is a batch of partial invoices that have been paid */
|
||||
@ -103,15 +103,16 @@ class UpdateInvoicePayment implements ShouldQueue
|
||||
}
|
||||
else {
|
||||
|
||||
/*
|
||||
$this->sysLog([
|
||||
'payment' => $this->payment,
|
||||
'invoices' => $invoices,
|
||||
'invoices_total' => $invoices_total,
|
||||
'payment_amount' => $this->payment->amount,
|
||||
'partial_check_amount' => $total,
|
||||
], SystemLog::GATEWAY_RESPONSE, SystemLog::PAYMENT_RECONCILIATION_FAILURE);
|
||||
|
||||
throw new Exception('payment amount does not match invoice totals');
|
||||
], SystemLog::GATEWAY_RESPONSE, SystemLog::PAYMENT_RECONCILIATION_FAILURE, $this->payment->client);
|
||||
*/
|
||||
throw new \Exception("payment amount {$this->payment->amount} does not match invoice totals {$invoices_total}");
|
||||
}
|
||||
|
||||
|
||||
|
@ -110,7 +110,7 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
|
||||
'data' => $data
|
||||
]);
|
||||
|
||||
throw new Exception("Error Processing Payment", 1);
|
||||
throw new \Exception("Error Processing Payment", 1);
|
||||
|
||||
}
|
||||
}
|
||||
@ -132,7 +132,7 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
|
||||
'server_response' => $response->getData()
|
||||
]);
|
||||
|
||||
throw new Exception($response->getMessage());
|
||||
throw new \Exception($response->getMessage());
|
||||
}
|
||||
|
||||
$payment = $this->createPayment($response->getData());
|
||||
|
@ -377,7 +377,7 @@ class StripePaymentDriver extends BasePaymentDriver
|
||||
'invoices' => $invoices,
|
||||
]);
|
||||
|
||||
throw new Exception("Failed to process payment", 1);
|
||||
throw new \Exception("Failed to process payment", 1);
|
||||
|
||||
}
|
||||
|
||||
@ -484,7 +484,7 @@ class StripePaymentDriver extends BasePaymentDriver
|
||||
}
|
||||
|
||||
if(!$customer)
|
||||
throw new Exception('Unable to create gateway customer');
|
||||
throw new \Exception('Unable to create gateway customer');
|
||||
|
||||
return $customer;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Utils\Traits;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\SystemLog;
|
||||
|
||||
/**
|
||||
@ -20,9 +21,12 @@ use App\Models\SystemLog;
|
||||
trait SystemLogTrait
|
||||
{
|
||||
|
||||
public function sysLog($log, $category_id = SystemLog::GATEWAY_RESPONSE, $event_id = SystemLog::GATEWAY_FAILURE)
|
||||
public function sysLog($log, $category_id = SystemLog::GATEWAY_RESPONSE, $event_id = SystemLog::GATEWAY_FAILURE, Client $client = null)
|
||||
{
|
||||
|
||||
if($client != null)
|
||||
$this->client = $client;
|
||||
|
||||
$sl = [
|
||||
'client_id' => $this->client->id,
|
||||
'company_id' => $this->client->company->id,
|
||||
|
@ -5,8 +5,10 @@ use App\DataMapper\CompanySettings;
|
||||
use App\DataMapper\DefaultSettings;
|
||||
use App\Events\Invoice\InvoiceWasMarkedSent;
|
||||
use App\Events\Invoice\InvoiceWasUpdated;
|
||||
use App\Events\Payment\PaymentWasCreated;
|
||||
use App\Helpers\Invoice\InvoiceCalc;
|
||||
use App\Jobs\Company\UpdateCompanyLedgerWithInvoice;
|
||||
use App\Jobs\Invoice\UpdateInvoicePayment;
|
||||
use App\Listeners\Invoice\CreateInvoiceInvitation;
|
||||
use App\Models\Account;
|
||||
use App\Models\Client;
|
||||
@ -16,6 +18,7 @@ use App\Models\CompanyToken;
|
||||
use App\Models\GatewayType;
|
||||
use App\Models\GroupSetting;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\PaymentType;
|
||||
use App\Models\User;
|
||||
use App\Models\UserAccount;
|
||||
use App\Repositories\InvoiceRepository;
|
||||
@ -114,7 +117,7 @@ class RandomDataSeeder extends Seeder
|
||||
$invoices = Invoice::all();
|
||||
$invoice_repo = new InvoiceRepository();
|
||||
|
||||
$invoices->each(function ($invoice) use($invoice_repo){
|
||||
$invoices->each(function ($invoice) use($invoice_repo, $user, $company, $client){
|
||||
|
||||
$invoice_calc = new InvoiceCalc($invoice, $invoice->settings);
|
||||
|
||||
@ -129,6 +132,22 @@ class RandomDataSeeder extends Seeder
|
||||
$invoice_repo->markSent($invoice);
|
||||
|
||||
event(new InvoiceWasMarkedSent($invoice));
|
||||
|
||||
$payment = App\Models\Payment::create([
|
||||
'user_id' => $user->id,
|
||||
'company_id' => $company->id,
|
||||
'client_id' => $client->id,
|
||||
'amount' => $invoice->balance,
|
||||
'transaction_reference' => rand(0,500),
|
||||
'payment_type_id' => PaymentType::CREDIT_CARD_OTHER,
|
||||
]);
|
||||
|
||||
$payment->invoices()->save($invoice);
|
||||
|
||||
event(new PaymentWasCreated($payment));
|
||||
|
||||
UpdateInvoicePayment::dispatchNow($payment);
|
||||
|
||||
});
|
||||
|
||||
/** Recurring Invoice Factory */
|
||||
@ -136,7 +155,6 @@ class RandomDataSeeder extends Seeder
|
||||
|
||||
// factory(\App\Models\Payment::class,20)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id, 'settings' => ClientSettings::buildClientSettings($company->settings, $client->settings)]);
|
||||
|
||||
factory(\App\Models\Payment::class,20)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
|
||||
|
||||
|
||||
$clients = Client::all();
|
||||
|
Loading…
x
Reference in New Issue
Block a user