Fixes for failed mollie payments

This commit is contained in:
David Bomba 2021-11-21 10:13:10 +11:00
parent ce3ea99f22
commit 3695042cc0

View File

@ -16,6 +16,7 @@ use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Http\Requests\Gateways\Mollie\Mollie3dsRequest; use App\Http\Requests\Gateways\Mollie\Mollie3dsRequest;
use App\Http\Requests\Payments\PaymentWebhookRequest; use App\Http\Requests\Payments\PaymentWebhookRequest;
use App\Jobs\Util\SystemLogger; use App\Jobs\Util\SystemLogger;
use App\Models\Client;
use App\Models\ClientGatewayToken; use App\Models\ClientGatewayToken;
use App\Models\GatewayType; use App\Models\GatewayType;
use App\Models\Invoice; use App\Models\Invoice;
@ -303,12 +304,39 @@ class MolliePaymentDriver extends BaseDriver
try { try {
$payment = $this->gateway->payments->get($request->id); $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(); if($record){
$record->status_id = $codes[$payment->status]; $client = $record->client;
$record->save(); }
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); return response()->json([], 200);
} catch (ApiException $e) { } catch (ApiException $e) {
return response()->json(['message' => $e->getMessage(), 'gatewayStatusCode' => $e->getCode()], 500); return response()->json(['message' => $e->getMessage(), 'gatewayStatusCode' => $e->getCode()], 500);
} }