diff --git a/app/PaymentDrivers/MolliePaymentDriver.php b/app/PaymentDrivers/MolliePaymentDriver.php index 4b991a057a86..5064ddbb22b1 100644 --- a/app/PaymentDrivers/MolliePaymentDriver.php +++ b/app/PaymentDrivers/MolliePaymentDriver.php @@ -16,6 +16,7 @@ use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; use App\Http\Requests\Gateways\Mollie\Mollie3dsRequest; use App\Http\Requests\Payments\PaymentWebhookRequest; use App\Jobs\Util\SystemLogger; +use App\Models\Client; use App\Models\ClientGatewayToken; use App\Models\GatewayType; use App\Models\Invoice; @@ -303,12 +304,39 @@ class MolliePaymentDriver extends BaseDriver try { $payment = $this->gateway->payments->get($request->id); + $record = Payment::withTrashed()->where('transaction_reference', $request->id)->first(); - $record = Payment::withTrashed()->where('transaction_reference', $request->id)->firstOrFail(); - $record->status_id = $codes[$payment->status]; - $record->save(); + if($record){ + $client = $record->client; + } + else{ + $input = $request->all(); + $client = Client::withTrashed()->find($this->decodePrimaryKey($input['metadata']->client_id)); + } + + $message = [ + 'server_response' => $payment, + 'data' => $request->all(), + ]; + + $response = SystemLog::EVENT_GATEWAY_FAILURE; + + if($record){ + $record->status_id = $codes[$payment->status]; + $record->save(); + $response = SystemLog::EVENT_GATEWAY_SUCCESS; + } + + SystemLogger::dispatch( + $message, + SystemLog::CATEGORY_GATEWAY_RESPONSE, + $response, + SystemLog::TYPE_MOLLIE, + $client + ); return response()->json([], 200); + } catch (ApiException $e) { return response()->json(['message' => $e->getMessage(), 'gatewayStatusCode' => $e->getCode()], 500); }