Advertisement
Guest User

Untitled

a guest
Jul 21st, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1.     /**
  2.      * This routine will pay for any advert placements with available credit.
  3.      * You are redirected here after payments with paypal or if you already have enough credit
  4.      */
  5.     private function pay_for_adverts_with_credit()
  6.     {
  7.         $errors = array();
  8.         // Ok lets get all the unpaid ad placements for the given user
  9.         $ad_placements = $this->advert_model->getUnpaidAdPlacementsForUser($user->user_id);
  10.         $user_id = $this->user_model->getLoggedInUser()->user_id;
  11.         foreach($ad_placements as $ad_placement)
  12.         {
  13.             // Let's try to purchase them with credit
  14.             if (!$this->user_model->deductCredit($user_id, $ad_placement->cost))
  15.             {
  16.                 $errors[] = 'Failed to pay for ad placement scheduled at: ' . $ad_placement->scheduled . ' as you do not have enough credit';
  17.                 break;
  18.             }
  19.  
  20.             $this->advert_model->markAdvertPlacementActive($ad_placement->advert_placement_id);
  21.         }
  22.  
  23.         if (count($errors) > 0)
  24.         {
  25.             print_r($errors);
  26.         }
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement