/**
  * Execute the job.
  *
  * @return void
  */
 public function handle(UserRepositoryInterface $userRepo, BookingRepositoryInterface $bookingRepo, BillingGateway $gateway)
 {
     $user = $userRepo->find($this->user_id);
     $user->cardName = $this->cardName;
     $user->cardBrand = $this->cardBrand;
     $user->cardLastFour = $this->cardLastFour;
     $user->cardExpiryMonth = $this->cardExpiryMonth;
     $user->cardExpiryYear = $this->cardExpiryYear;
     $user->save();
     $booking = $bookingRepo->findByReference($this->booking_reference);
     $bookedPackages = $booking->packages;
     $total = calculateTotalAmount($bookedPackages);
     $transaction = $gateway->charge($user, $total, $this->token);
     if ($transaction) {
         $bookingRepo->update($booking->id, ['booking_reference' => bookingReference($transaction), 'paid' => $transaction->paid, 'status' => $transaction->status, 'comments' => '']);
         event(new UserPaidTheBooking($user, $this->booking_reference));
     } else {
         event(new UserPurchaseWasNotSuccessful($user));
         /**
          * If payment is not successful, delete the user to avoid duplicating his/her
          * record on the "users" table
          */
         //$userRepository->delete($user->id);
     }
 }
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle(UserRepositoryInterface $userRepo, BookingRepositoryInterface $bookingRepo, BillingGateway $gateway)
 {
     $user = $userRepo->find($this->user_id);
     $booking = $bookingRepo->findByReference($this->booking_reference);
     $bookedPackages = $booking->packages;
     $total = calculateTotalAmount($bookedPackages);
     $chargeWasSuccessful = $gateway->charge($user, $total, $this->token);
     if ($chargeWasSuccessful) {
         $bookingRepo->update($booking->id, ['status' => 1]);
         //event( new UserPaidTheBooking($user) );
     } else {
         //event( new UserPurchaseWasNotSuccessful($user) );
         /**
          * If payment is not successful, delete the user to avoid duplicating his/her
          * record on the "users" table
          */
         //$userRepository->delete($user->id);
     }
 }
<?php

# An array with products and their corresponding prices
$price = array("Black & Decker Accuboormachine" => 148.85, "Bosch Boorhamer" => 103.97, "Makita Accuschroefmachine" => 199.2, "Makita Klopboormachine" => 76.0, "Metabo Klopboor" => 119.0);
# Add an item to the price array
addItem($price, "Bosch GBH 18 V-LI", 412.37);
# Print the products with the corresponding prices to the screen
echo "<h1>Vandaag in het assortiment:</h1>";
foreach ($price as $price_key => $price_value) {
    echo "{$price_key} voor {$price_value} &euro;</br>";
}
echo "</br></br><h1>Totaalprijs van alle producten</h1>";
# Calculate the total amount
$total_amount = calculateTotalAmount($price);
echo "Totaalprijs = {$total_amount} &euro;";
echo "</br></br><h1>Producten gesorteerd op basis van prijs</h1>";
# Sort ascending based on price
asort($price);
foreach ($price as $key => $value) {
    echo "{$key} voor {$value} &euro;</br>";
}
/**
 * @param An array that contains a key(Productname) and a value(Price)
 * @return The total price of all the products in the array
 */
function calculateTotalAmount($array)
{
    $total_amount = 0;
    foreach ($array as $array_key => $array_value) {
        $total_amount += $array_value;
    }