how to execute many query at same in my web.php route (Laravel)

Please, am new using laravel and firestore. i have users plans table(beta target, beta kopa, beta flex and users table), in the above table when a user makes a payment via card from the app, it first checks if the user paid into either any of the listed plan table and update the specific table as selected and also update the users table. Now, where am having issues is when a user withdraws, it sometimes debit the users plan table and wont debit the specific user main account, sometimes it will debit the users main account and wont debit the plan table account. please why is it not debiting both plan table and users table at same time. i will so much appreciate any help please. below is my web.php route

<?php

use IlluminateSupportFacadesRoute;
use AppHttpMiddlewareVerifyCsrfToken;
use IlluminateHttpRequest;
use CarbonCarbon;
use GoogleCloudFirestoreFirestoreClient;
use AppHttpControllersUserController;


/*paystack webhook below*/
Route:: post('/paystackz', function (){
    
     if ((strtoupper($_SERVER['REQUEST_METHOD']) != 'POST') || !array_key_exists('HTTP_X_PAYSTACK_SIGNATURE', $_SERVER))
        exit();
        
    
    $input = @file_get_contents("php://input");
    define('PAYSTACK_SECRET_KEY', 'sk_test_******************');
    
    if ($_SERVER['HTTP_X_PAYSTACK_SIGNATURE'] !== hash_hmac('sha512', $input, PAYSTACK_SECRET_KEY))
    exit();
    
 

// validate event do all at once to avoid timing attack
    $event = json_decode($input);  
$event = json_decode($input);    
$status = $event->data->status;
$eventz =  $event->event;

if($eventz == "charge.success"){
$status = $event->data->status;
$Cus_email = $mail = $event->data->customer->email; 
$Cus_auth = $event->data->authorization->authorization_code;
$Cus_amount = $amount = $event->data->amount/100;
$check = $event->data->status;
$Cus_date = $event->data->paid_at;
$Cus_method = $event->data->channel;

$Cus_paymentMethod = $event->data->metadata->custom_fields[0]->value;
$Cus_packageName = $event->data->metadata->custom_fields[1]->value;
$Cus_frequence = $event->data->metadata->custom_fields[2]->value;
$Cus_paymentType = $event->data->metadata->custom_fields[3]->value;
$Cus_deductionDate = $event->data->metadata->custom_fields[4]->value;
$Cus_withdrawalDate = $event->data->metadata->custom_fields[5]->value;

$Cus_targetAmount = $event->data->metadata->custom_fields[6]->value;
$Cus_targetTitle = $event->data->metadata->custom_fields[7]->value;
$Cus_userID = $event->data->metadata->custom_fields[8]->value;
$Cus_deductAmount = $event->data->metadata->custom_fields[9]->value;
$Cus_id = $event->data->id;
$Cus_status = $event->data->status;
$Cus_code = $event->data->customer->customer_code; 
$Cus_ref = $event->data->reference;


  //na here .. after transfer is made from the user it should debit the user account from the two tables but mostly it doesnt, it only debit from one table 

if  ($eventz == 'transfer.success') { 
    
    
$Cus_selectedClient = $event->data->recipient->metadata->custom_fields[0]->value;
$Cus_accountNO = $event->data->recipient->metadata->custom_fields[1]->value;
$Cus_accountName = $event->data->recipient->metadata->custom_fields[2]->value;
$Cus_bankName = $event->data->recipient->metadata->custom_fields[3]->value;
$Cus_emailz = $event->data->recipient->metadata->custom_fields[4]->value;
$Cus_uiDz = $event->data->recipient->metadata->custom_fields[5]->value;

$Cus_initialAmount = $event->data->recipient->metadata->custom_fields[6]->value;
$Cus_amountDebitedz = $event->data->recipient->metadata->custom_fields[7]->value;
$Cus_packageNamez = $event->data->recipient->metadata->custom_fields[8]->value;

$cus_amountSent = $event->data->amount/100;
$status = $event->data->status;
$Cus_date = $event->data->updatedAt;
$Cus_status = $event->data->status;
$Cus_ref = $event->data->reference;
$cus_total = $Cus_amountDebitedz/1;
$cus_totalAmount = $Cus_initialAmount-$Cus_amountDebitedz;
$cus_revz = $Cus_amountDebitedz - $cus_amountSent;
$forInterest = (int)$Cus_amountDebitedz;
// $forInterest2 = $Cus_amountDebitedz/1;

if ($eventz == 'transfer.success') {

    //inserting to history 
    
      $walletDb =  app('firebase.firestore')->database()->collection('transferInitiateProcess')->newDocument();
     
    $newDocument = $walletDb->set([
        
        'status' => $status,
        'amountSent' => $cus_amountSent,
        'createdAt' => $Cus_date,
        'balance' => $cus_totalAmount,
        'planTitle' => $Cus_selectedClient,
        'accountNo' => $Cus_accountNO,
        'accountName' => $Cus_accountName,
        'bankName' => $Cus_bankName,
        'email' => $Cus_emailz,
        'uID' => $Cus_uiDz,
        'initialAmount' => $Cus_initialAmount,
        'amountToDebit' => $Cus_amountDebitedz,
        'packageName' => $Cus_packageNamez,
        'ref' => $Cus_ref,
        'paymentMethod' => 'Bank Transfer/Debit'
       
    ]);
    //inserting to history 
    
            $lockPayment22 =  app('firebase.firestore')->database()->collection('AllPaymentHistory')->newDocument();
            
             $lockPayment22 -> set([
                    'active' => true, 
                    'paymentID' => $lockPayment22->id(), 
                    'status' => $status,
                    'targetTitle' => $Cus_selectedClient,
                    'targetAmount' => $cus_amountSent,
                    'packageName' => $Cus_packageNamez,
                    'amountDebited' => $cus_total,
                    'email' => $Cus_emailz,
                    'authenticate' => '-',
                    'uID' => $Cus_uiDz,
                    'withdrawalDate'=> '-',
                    'datePaid' => $Cus_date,
                    'totalTarget' => '-',
                    'paymentMethod' => 'Bank Transfer/Debit',
                    'frequence' =>  '-',
                    'paymentType' => 'Transfer/Debit',
                    'deductionDate' => $Cus_date,
                    'amountToCharge' => $cus_amountSent,
                    'ref' => $Cus_ref,
                    'credit' => 'Debit',
                    'modeofPayment' => 'Debit'
        ]);
              
          
    /*debit from Users specific table balance */
      $addAmountToUser1User =  app('firebase.firestore')->database()->collection('Users')->document($Cus_uiDz);
          if($Cus_packageNamez == 'Beta Flex') {
            $addAmountToUser1User -> update([
               [ 'path' => 'flexAmount', 'value' => GoogleCloudFirestoreFieldValue::increment(-$Cus_amountDebitedz)]
              
                ]);
          }
          
           if($Cus_packageNamez == 'Beta Flex Interest') {
            $addAmountToUser1User -> update([
               [ 'path' => 'flexInterest', 'value' => GoogleCloudFirestoreFieldValue::increment(-$Cus_amountDebitedz)]
              
                ]);
          }
          if ($Cus_packageNamez == 'Beta Kopa') {
            $addAmountToUser1User -> update([
               [ 'path' => 'kopaAmount', 'value' => GoogleCloudFirestoreFieldValue::increment(-$Cus_amountDebitedz)]
            
                ]);
          }
            if ($Cus_packageNamez == 'Beta Kopa Interest') {
            $addAmountToUser1User -> update([
               [ 'path' => 'kopaInterest', 'value' => GoogleCloudFirestoreFieldValue::increment(-$Cus_amountDebitedz)]
            
                ]);
          }
          if ($Cus_packageNamez == 'Beta Target') {
            $addAmountToUser1User -> update([
               [ 'path' => 'targetAmount', 'value' => GoogleCloudFirestoreFieldValue::increment(-$Cus_amountDebitedz)]
            
                ]);
          }
           if ($Cus_packageNamez == 'Beta Target Interest') {
            $addAmountToUser1User -> update([
               [ 'path' => 'targetInterest', 'value' => GoogleCloudFirestoreFieldValue::increment(-$Cus_amountDebitedz)]
            
                ]);
          }
          if ($Cus_packageNamez == 'Beta Lock - 30 Days') {
                 $addAmountToUser1User -> update([
               [ 'path' => 'lock3dAmount', 'value' => GoogleCloudFirestoreFieldValue::increment(-$Cus_amountDebitedz)]
                ]);
            }
            
            if ($Cus_packageNamez == 'Beta Lock - 30 Days') {
                 $addAmountToUser1User -> update([
               [ 'path' => 'lock3dAmount', 'value' => GoogleCloudFirestoreFieldValue::increment(-$Cus_amountDebitedz)]
                ]);
            }
            
            if
            ($Cus_packageNamez == 'Beta Lock Interest') {
                 $addAmountToUser1User -> update([
               [ 'path' => 'lock1yInterest', 'value' => GoogleCloudFirestoreFieldValue::increment(-$Cus_amountDebitedz)]
                ]);
            }if
            ($Cus_packageNamez == 'Beta Lock - 90 Days') {
                 $addAmountToUser1User -> update([
               [ 'path' => 'lock9dAmount', 'value' => GoogleCloudFirestoreFieldValue::increment(-$Cus_amountDebitedz)]
                ]);
            }if
            ($Cus_packageNamez == 'Beta Lock - 6 months') {
                 $addAmountToUser1User -> update([
               [ 'path' => 'lock6mAmount', 'value' => GoogleCloudFirestoreFieldValue::increment(-$Cus_amountDebitedz)]
                ]);
            }if
            ($Cus_packageNamez == 'Beta Lock 1-2 years') {
                 $addAmountToUser1User -> update([
               [ 'path' => 'lock1yAmount', 'value' => GoogleCloudFirestoreFieldValue::increment(-$Cus_amountDebitedz)]
                ]);
            }
          
          
           //debit from users plan table 
         
           if ($Cus_packageNamez == 'Beta Kopa'){
             $OnlykopaHistory1 = app('firebase.firestore')->database()->collection('OnlyKopaHistory');
$query = $OnlykopaHistory1
    ->where('uID', '==', $Cus_uiDz)
    ->where('packageName', '==', $Cus_packageNamez)
    ->where('targetTitle', '==', $Cus_selectedClient)
    ->where('email', '==', $Cus_emailz);
$documents = $query->documents();
foreach ($documents as $document) {
    $getID = $document->id();
    if ($document->exists()) {
        $OnlykopaHistory2Debit = app('firebase.firestore')->database()->collection('OnlyKopaHistory')->document($getID);
         $OnlykopaHistory2Debit -> update([
               [ 'path' => 'totalTarget', 'value' => GoogleCloudFirestoreFieldValue::increment(-$Cus_amountDebitedz)]
                ]);
    } else {
        printf('Document %s does not exist!' . PHP_EOL, $document->id());
    }
}
}          

 if
          ($Cus_packageNamez == 'Beta Target'){
             $OnlytargetHistoryTrans = app('firebase.firestore')->database()->collection('OnlyTargetHistory');
$query = $OnlytargetHistoryTrans
    ->where('uID', '==', $Cus_uiDz)
    ->where('packageName', '==', $Cus_packageNamez)
    ->where('targetTitle', '==', $Cus_selectedClient)
    ->where('email', '==', $Cus_emailz);
$documents = $query->documents();
foreach ($documents as $document) {
    $getID = $document->id();
    if ($document->exists()) {
        $OnlytargetHistory2Trans = app('firebase.firestore')->database()->collection('OnlyTargetHistory')->document($getID);
         $OnlytargetHistory2Trans -> update([
               [ 'path' => 'totalTarget', 'value' => GoogleCloudFirestoreFieldValue::increment(-$Cus_amountDebitedz)]
                ]);               
    } else {
        printf('Document %s does not exist!' . PHP_EOL, $document->id());
    }
}
}

 if (($Cus_packageNamez == 'Beta Lock - 30 Days') || ($Cus_packageNamez == 'Beta Lock - 60 Days') || ($Cus_packageNamez == 'Beta Lock - 90 Days') || ($Cus_packageNamez == '6 months') || ($Cus_packageNamez == 'Lock 1-2 years')) {
             $OnlylockHistoryTrans = app('firebase.firestore')->database()->collection('OnlyLockHistory');
$query = $OnlylockHistoryTrans
    ->where('uID', '==', $Cus_uiDz)
    ->where('packageName', '==', $Cus_packageNamez)
    ->where('LockTitle', '==', $Cus_selectedClient)
    ->where('email', '==', $Cus_emailz);
$documents = $query->documents();
foreach ($documents as $document) {
    $getID = $document->id();
    if ($document->exists()) {      
        $OnlyLockHistory2Trans = app('firebase.firestore')->database()->collection('OnlyLockHistory')->document($getID);
         $OnlyLockHistory2Trans -> update([
               [ 'path' => 'totalLock', 'value' => GoogleCloudFirestoreFieldValue::increment(-$Cus_amountDebitedz)]
                ]);
    } else {
        printf('Document %s does not exist!' . PHP_EOL, $document->id());
    }
}
}  
}
  else{
     die("Check Failed!");
     
 

     }

}
   http_response_code(200);
   exit();
}->withoutMiddleware(VerifyCsrfToken::class);

  



Auth::routes();

//Route::get('/logout', 'resourcesviewsLoginController');



New contributor

samuel Jen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật