Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This routine will pay for any advert placements with available credit.
- * You are redirected here after payments with paypal or if you already have enough credit
- */
- private function pay_for_adverts_with_credit()
- {
- $errors = array();
- // Ok lets get all the unpaid ad placements for the given user
- $ad_placements = $this->advert_model->getUnpaidAdPlacementsForUser($user->user_id);
- $user_id = $this->user_model->getLoggedInUser()->user_id;
- foreach($ad_placements as $ad_placement)
- {
- // Let's try to purchase them with credit
- if (!$this->user_model->deductCredit($user_id, $ad_placement->cost))
- {
- $errors[] = 'Failed to pay for ad placement scheduled at: ' . $ad_placement->scheduled . ' as you do not have enough credit';
- break;
- }
- $this->advert_model->markAdvertPlacementActive($ad_placement->advert_placement_id);
- }
- if (count($errors) > 0)
- {
- print_r($errors);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement