mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
fe5a97e174
* Fixes for Store Payment Validation * Tests for Payments * Use custom validator to ensure payments are made ONLY to payable invoices * Working on custom payment validators * Update Client balance * fixes for client balance * Fixes for activity API
56 lines
1.1 KiB
PHP
56 lines
1.1 KiB
PHP
<?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\Repositories;
|
|
|
|
use App\Events\Payment\PaymentWasCreated;
|
|
use App\Jobs\Company\UpdateCompanyLedgerWithPayment;
|
|
use App\Jobs\Invoice\UpdateInvoicePayment;
|
|
use App\Models\Invoice;
|
|
use App\Models\Payment;
|
|
use Illuminate\Http\Request;
|
|
|
|
/**
|
|
* PaymentRepository
|
|
*/
|
|
class PaymentRepository extends BaseRepository
|
|
{
|
|
|
|
public function getClassName()
|
|
{
|
|
return Payment::class;
|
|
}
|
|
|
|
public function save(Request $request, Payment $payment) : ?Payment
|
|
{
|
|
|
|
$payment->fill($request->input());
|
|
|
|
$payment->save();
|
|
|
|
if($request->input('invoices'))
|
|
{
|
|
|
|
$invoices = Invoice::whereIn('id', $request->input('invoices'))->get();
|
|
|
|
$payment->invoices()->saveMany($invoices);
|
|
|
|
}
|
|
|
|
event(new PaymentWasCreated($payment));
|
|
|
|
UpdateInvoicePayment::dispatchNow($payment);
|
|
|
|
return $payment;
|
|
|
|
}
|
|
|
|
} |