diff --git a/app/Http/Controllers/CreditController.php b/app/Http/Controllers/CreditController.php index 871034337f9f..88a48009878a 100644 --- a/app/Http/Controllers/CreditController.php +++ b/app/Http/Controllers/CreditController.php @@ -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))); diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index aa37045de57f..78fd9019fee2 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -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(); diff --git a/app/Services/Credit/CreditService.php b/app/Services/Credit/CreditService.php index acac1ff28ede..c6b41fb3eef3 100644 --- a/app/Services/Credit/CreditService.php +++ b/app/Services/Credit/CreditService.php @@ -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