1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 22:22:32 +01:00

Triggered actions for credits

This commit is contained in:
David Bomba 2021-11-15 14:14:58 +11:00
parent 293367cd16
commit 4deb820346
3 changed files with 25 additions and 3 deletions

View File

@ -200,6 +200,7 @@ class CreditController extends BaseController
$credit = $credit->service()
->fillDefaults()
->triggeredActions($request)
->save();
event(new CreditWasCreated($credit, $credit->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
@ -377,7 +378,9 @@ class CreditController extends BaseController
$credit = $this->credit_repository->save($request->all(), $credit);
$credit->service()->deletePdf();
$credit->service()
->triggeredActions($request)
->deletePdf();
event(new CreditWasUpdated($credit, $credit->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));

View File

@ -524,14 +524,25 @@ class StripePaymentDriver extends BaseDriver
if ($request->type === 'charge.succeeded' || $request->type === 'payment_intent.succeeded') {
foreach ($request->data as $transaction) {
$payment = Payment::query()
->where('transaction_reference', $transaction['payment_intent'])
if(array_key_exists('payment_intent', $transaction))
{
$payment = Payment::query()
->where('company_id', $request->getCompany()->id)
->where(function ($query) use ($transaction) {
$query->where('transaction_reference', $transaction['payment_intent'])
->orWhere('transaction_reference', $transaction['id']);
})
->first();
}
else
{
$payment = Payment::query()
->where('company_id', $request->getCompany()->id)
->where('transaction_reference', $transaction['id'])
->first();
}
if ($payment) {
$payment->status_id = Payment::STATUS_COMPLETED;
$payment->save();

View File

@ -14,6 +14,7 @@ namespace App\Services\Credit;
use App\Jobs\Util\UnlinkFile;
use App\Models\Credit;
use App\Services\Credit\CreateInvitations;
use App\Services\Credit\TriggeredActions;
use App\Utils\Traits\MakesHash;
class CreditService
@ -150,6 +151,13 @@ class CreditService
return $this;
}
public function triggeredActions($request)
{
$this->invoice = (new TriggeredActions($this->credit, $request))->run();
return $this;
}
/**
* Saves the credit.
* @return Credit object