mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
Handling webhooks
This commit is contained in:
parent
42991e1813
commit
2d824e4d1e
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace App\PaymentDrivers;
|
namespace App\PaymentDrivers;
|
||||||
|
|
||||||
|
use App\Http\Requests\Payments\PaymentWebhookRequest;
|
||||||
use App\Jobs\Mail\PaymentFailureMailer;
|
use App\Jobs\Mail\PaymentFailureMailer;
|
||||||
use App\Jobs\Util\SystemLogger;
|
use App\Jobs\Util\SystemLogger;
|
||||||
use App\Models\ClientGatewayToken;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user