<?php

// Include the database connection file
include "../../jwtconnect.php";
//ride/driverWallet/add.php
// Get the request parameters
$driverID = filterRequest("driverID");
$paymentID = filterRequest("paymentID");
$amount = filterRequest("amount");
$paymentMethod = filterRequest("paymentMethod");
$phone = filterRequest("phone");


    // Add payment to the driver's wallet table
    $sql = "INSERT INTO `driverWallet` (
        `driverID`,
        `paymentID`,
        `amount`,
        `paymentMethod`
    ) VALUES (
        :driverID,
        :paymentID,
        :amount,
        :paymentMethod
    );";

    $stmt = $con->prepare($sql);
    $stmt->execute(array(
        ':driverID' => $driverID,
        ':paymentID' => $paymentID,
        ':amount' => $amount,
        ':paymentMethod' => $paymentMethod
    ));

    if ($stmt->rowCount() > 0) {
        // Print a success message
        printSuccess("Record saved successfully");
       $messageBody = "تم إضافة رصيد بقيمة $amount إلى محفظتك بنجاح."; // "Balance of $amount added successfully."
       
      sendWhatsAppFromServer($phone, $messageBody);
        
        // Mark the token as used in the database
     /*   $stmt = $con->prepare("UPDATE payment_tokens SET isUsed = TRUE WHERE id = :tokenID");
        $stmt->execute(array(
            ':tokenID' => $tokenData['id']
        ));*/
    } else {
        // Print a failure message
        printFailure("Failed to save record");
    }

