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

Handling webhooks

This commit is contained in:
Benjamin Beganović 2021-09-30 15:55:34 +02:00
parent 42991e1813
commit 2d824e4d1e

View File

@ -11,6 +11,7 @@
namespace App\PaymentDrivers;
use App\Http\Requests\Payments\PaymentWebhookRequest;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken;
@ -211,4 +212,42 @@ class GoCardlessPaymentDriver extends BaseDriver
);
}
}
public function processWebhookRequest(PaymentWebhookRequest $request)
{
// Allow app to catch up with webhook request.
sleep(2);
$this->init();
foreach ($request->events as $event) {
if ($event['action'] === 'confirmed') {
$payment = Payment::query()
->where('transaction_reference', $event['links']['payment'])
->where('company_id', $request->getCompany()->id)
->first();
if ($payment) {
$payment->status_id = Payment::STATUS_COMPLETED;
$payment->save();
}
}
if ($event['action'] === 'failed') {
// Update invoices, etc?
$payment = Payment::query()
->where('transaction_reference', $event['links']['payment'])
->where('company_id', $request->getCompany()->id)
->first();
if ($payment) {
$payment->status_id = Payment::STATUS_FAILED;
$payment->save();
}
}
}
return response()->json([], 200);
}
}