Update: 2026-06-15 01:37:40
This commit is contained in:
@@ -28,28 +28,50 @@ if ($referral['is_reward_claimed'] == 1) {
|
||||
jsonError("Reward already claimed");
|
||||
}
|
||||
|
||||
// Logic:
|
||||
// Driver -> Driver: 50 trips = 500 SYP (example)
|
||||
// Driver -> Passenger: 10 trips = 30 SYP per trip. This could be progressive, but for manual claim we assume completed
|
||||
$amountSyp = 0;
|
||||
// 2. Get local currency dynamically
|
||||
$stmtKazan = $con->prepare("SELECT country, currency FROM kazan LIMIT 1");
|
||||
$stmtKazan->execute();
|
||||
$kazanData = $stmtKazan->fetch(PDO::FETCH_ASSOC);
|
||||
$country = $kazanData['country'] ?? 'Syria';
|
||||
$currency = $kazanData['currency'] ?? 'SYP';
|
||||
|
||||
$driverRewardBase = 0;
|
||||
$passengerRewardPerTrip = 0;
|
||||
|
||||
switch ($currency) {
|
||||
case 'SYP':
|
||||
$driverRewardBase = 50000;
|
||||
$passengerRewardPerTrip = 2000;
|
||||
break;
|
||||
case 'EGP':
|
||||
$driverRewardBase = 300;
|
||||
$passengerRewardPerTrip = 15;
|
||||
break;
|
||||
case 'JOD':
|
||||
default:
|
||||
$driverRewardBase = 10;
|
||||
$passengerRewardPerTrip = 0.5;
|
||||
break;
|
||||
}
|
||||
|
||||
$rewardAmount = 0;
|
||||
|
||||
if ($referral['invited_user_type'] == 'driver') {
|
||||
if ($referral['trip_count'] >= 50) {
|
||||
$amountSyp = 500;
|
||||
$rewardAmount = $driverRewardBase;
|
||||
} else {
|
||||
jsonError("Requirement not met (50 trips required)");
|
||||
}
|
||||
} else if ($referral['invited_user_type'] == 'passenger') {
|
||||
if ($referral['trip_count'] >= 1) {
|
||||
// Here, user gets 30 SYP per trip, max 10. Let's assume claim all at once up to 10.
|
||||
$tripsToClaim = min($referral['trip_count'], 10);
|
||||
$amountSyp = $tripsToClaim * 30;
|
||||
$rewardAmount = $tripsToClaim * $passengerRewardPerTrip;
|
||||
} else {
|
||||
jsonError("Requirement not met (At least 1 trip required)");
|
||||
}
|
||||
}
|
||||
|
||||
if ($amountSyp <= 0) {
|
||||
if ($rewardAmount <= 0) {
|
||||
jsonError("No reward available to claim");
|
||||
}
|
||||
|
||||
@@ -61,20 +83,68 @@ try {
|
||||
$updateStmt->execute([$referralId]);
|
||||
|
||||
if ($claimType == 'wallet') {
|
||||
// Add to driver wallet
|
||||
$walletStmt = $con->prepare("UPDATE driver SET wallet = wallet + ? WHERE id = ?");
|
||||
$walletStmt->execute([$amountSyp, $user_id]);
|
||||
// Add to driver wallet via Payment Server S2S API
|
||||
$walletServer = "https://walletintaleq.intaleq.xyz";
|
||||
if (strtolower($country) == 'jordan') {
|
||||
$walletServer = getenv('WALLET_SERVER_JORDAN') ?: "https://walletintaleq.intaleq.xyz";
|
||||
} elseif (strtolower($country) == 'egypt') {
|
||||
$walletServer = getenv('WALLET_SERVER_EGYPT') ?: "https://walletintaleq.intaleq.xyz";
|
||||
} else {
|
||||
$walletServer = getenv('WALLET_SERVER_SYRIA') ?: "https://walletintaleq.intaleq.xyz";
|
||||
}
|
||||
|
||||
$paymentID = "REF_" . time();
|
||||
$walletUrl = "$walletServer/v2/main/ride/driverWallet/add_s2s_reward.php";
|
||||
|
||||
$payload = [
|
||||
"driverID" => $user_id,
|
||||
"paymentID" => $paymentID,
|
||||
"amount" => $rewardAmount,
|
||||
"paymentMethod" => "referral_reward"
|
||||
];
|
||||
|
||||
$ch = curl_init($walletUrl);
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => http_build_query($payload),
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_TIMEOUT => 15,
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Content-Type: application/x-www-form-urlencoded',
|
||||
'X-S2S-Api-Key: ' . getenv('S2S_SHARED_KEY')
|
||||
]
|
||||
]);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$curlErr = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
$s2sSuccess = false;
|
||||
if (!$curlErr && $httpCode === 200) {
|
||||
$resDecoded = json_decode($response, true);
|
||||
if ($resDecoded && isset($resDecoded['status']) && $resDecoded['status'] === 'success') {
|
||||
$s2sSuccess = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$s2sSuccess) {
|
||||
throw new Exception("S2S Wallet credit failed: " . ($curlErr ?: "HTTP $httpCode - Response: $response"));
|
||||
}
|
||||
|
||||
} else if ($claimType == 'cash') {
|
||||
// Request manual cash out
|
||||
$cashStmt = $con->prepare("INSERT INTO driver_cash_claims (driver_id, referral_id, amount_syp, status) VALUES (?, ?, ?, 'pending')");
|
||||
$cashStmt->execute([$user_id, $referralId, $amountSyp]);
|
||||
$cashStmt->execute([$user_id, $referralId, $rewardAmount]);
|
||||
}
|
||||
|
||||
$con->commit();
|
||||
printSuccess(["message" => "Reward claimed successfully as $claimType"]);
|
||||
printSuccess(["message" => "Reward claimed successfully as " . $rewardAmount . " " . $currency]);
|
||||
|
||||
} catch (PDOException $e) {
|
||||
$con->rollBack();
|
||||
jsonError("Database error: " . $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
if ($con->inTransaction()) {
|
||||
$con->rollBack();
|
||||
}
|
||||
jsonError("Failed to claim reward: " . $e->getMessage());
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user