20-02-2026

This commit is contained in:
Kevin Adametz 2026-02-20 17:55:06 +01:00
parent a8b395e20d
commit a00c42e770
252 changed files with 28785 additions and 8907 deletions

View file

@ -2,27 +2,19 @@
namespace App\Http\Controllers\Api;
use App\Services\Shop;
use App\Services\Util;
use App\Models\UserAbo;
use App\Services\MyLog;
use App\Services\Payment;
use App\Services\AboHelper;
use App\Http\Controllers\Controller;
use App\Models\PaymentTransaction;
use App\Models\ShoppingOrder;
use App\Models\ShoppingPayment;
use App\Models\PaymentTransaction;
use App\Http\Controllers\Controller;
use App\Services\MyLog;
use App\Services\Payment;
use App\Services\ShoppingUserService;
use App\Services\Util;
class PayoneController extends Controller
{
public function __construct() {}
public function paymentStatus()
{
@ -42,14 +34,14 @@ class PayoneController extends Controller
*/
if (!isset($data['key']) || !isset($data['param']) || !isset($data['userid']) || !isset($data['txid']) || !isset($data['reference']) || !isset($data['price'])) {
if (! isset($data['key']) || ! isset($data['param']) || ! isset($data['userid']) || ! isset($data['txid']) || ! isset($data['reference']) || ! isset($data['price'])) {
MyLog::writeLog(
'payone',
'error',
'Error:2001 App\Http\Controllers\Api\PayoneController::paymentStatus parameter incomplete',
$data
);
print("TSOK");
echo 'TSOK';
exit;
}
@ -60,31 +52,31 @@ class PayoneController extends Controller
'Error:2002 App\Http\Controllers\Api\PayoneController::paymentStatus Key error',
$data
);
print("TSOK");
echo 'TSOK';
exit;
}
$shopping_order = ShoppingOrder::find($data['param']);
if (!$shopping_order) {
if (! $shopping_order) {
MyLog::writeLog(
'payone',
'error',
'Error:2003 App\Http\Controllers\Api\PayoneController::paymentStatus ShoppingOrder not found:',
$data
);
print("TSOK");
echo 'TSOK';
exit;
}
$shopping_payment = ShoppingPayment::where('reference', $data['reference'])->first();
if (!$shopping_payment) {
if (! $shopping_payment) {
MyLog::writeLog(
'payone',
'error',
'Error:2004 App\Http\Controllers\Api\PayoneController::paymentStatus ShoppingPayment not found',
$data
);
print("TSOK");
echo 'TSOK';
exit;
}
@ -95,11 +87,11 @@ class PayoneController extends Controller
'Error:2005 App\Http\Controllers\Api\PayoneController::paymentStatus ShoppingPayment no realation ShoppingOrder',
$data
);
print("TSOK");
echo 'TSOK';
exit;
}
$price = number_format((round($data['price'], 2) * 100), 0, '.', '');
$price = number_format((round($data['price'], 2) * 100), 0, '.', '');
$price_amount = number_format($shopping_payment->amount, 0, '.', '');
if ($price_amount != $price) {
$data['shopping_payment-amount'] = $price_amount;
@ -110,7 +102,7 @@ class PayoneController extends Controller
'Error:2006 App\Http\Controllers\Api\PayoneController::paymentStatus Price error',
$data
);
print("TSOK");
echo 'TSOK';
exit;
}
@ -125,8 +117,8 @@ class PayoneController extends Controller
$data,
false
);
//was already paid
print("TSOK");
// was already paid
echo 'TSOK';
exit;
} else {
MyLog::writeLog(
@ -139,7 +131,7 @@ class PayoneController extends Controller
}
}
//create transaction
// create transaction
PaymentTransaction::create([
'shopping_payment_id' => $shopping_payment->id,
'request' => 'transaction',
@ -152,10 +144,32 @@ class PayoneController extends Controller
'mode' => $data['mode'],
]);
$shopping_order->txaction = $data['txaction'];
$shopping_order->save();
$shopping_payment->txaction = $data['txaction'];
$shopping_payment->save();
// Define txaction priority (higher number = higher priority)
$txaction_priority = [
'appointed' => 1,
'pending' => 2,
'failed' => 3,
'paid' => 10, // highest priority - final state
];
$current_priority = isset($txaction_priority[$shopping_order->txaction]) ? $txaction_priority[$shopping_order->txaction] : 0;
$new_priority = isset($txaction_priority[$data['txaction']]) ? $txaction_priority[$data['txaction']] : 0;
// Only update txaction if new priority is higher than current
if ($new_priority > $current_priority) {
$shopping_order->txaction = $data['txaction'];
$shopping_order->save();
$shopping_payment->txaction = $data['txaction'];
$shopping_payment->save();
} else {
MyLog::writeLog(
'payone',
'info',
'App\Http\Controllers\Api\PayoneController::paymentStatus - txaction not updated (current: '.$shopping_order->txaction.' has higher/equal priority than new: '.$data['txaction'].')',
$data,
false
);
}
$send_link = false;
$send_mail = true;
@ -170,17 +184,38 @@ class PayoneController extends Controller
}
if ($data['txaction'] === 'paid') {
if (!$shopping_order->paid) {
$send_link = Payment::paymentStatusPaidAction($shopping_order, true, $shopping_payment);
} else {
$send_mail = false;
// Use DB transaction and row locking to prevent race conditions
\DB::beginTransaction();
try {
// Lock the shopping order row to prevent concurrent processing
$locked_order = ShoppingOrder::where('id', $shopping_order->id)
->lockForUpdate()
->first();
// Double-check if payment was already processed
if (! $locked_order->paid) {
$send_link = Payment::paymentStatusPaidAction($locked_order, true, $shopping_payment);
\DB::commit();
} else {
$send_mail = false;
\DB::commit();
}
} catch (\Exception $e) {
\DB::rollBack();
MyLog::writeLog(
'payone',
'error',
'Error:2008 App\Http\Controllers\Api\PayoneController::paymentStatus Transaction failed',
['error' => $e->getMessage(), 'data' => $data]
);
throw $e;
}
}
$data['send_link'] = $send_link;
if ($send_mail) {
Payment::paymentStatusSendMail($shopping_order, $shopping_payment, $data);
}
print("TSOK");
echo 'TSOK';
exit;
}
}