コード例 #1
0
 /**
  * (non-PHPdoc)
  * @see IActionController::executeAction()
  */
 public function executeAction($parameters)
 {
     $user = $this->_websoccer->getUser();
     // check if feature is enabled
     $exchangeRate = (int) $this->_websoccer->getConfig("premium_exchangerate_gamecurrency");
     if ($exchangeRate <= 0) {
         throw new Exception("featue is disabled!");
     }
     // check if user has a club.
     $clubId = $user->getClubId($this->_websoccer, $this->_db);
     if (!$clubId) {
         throw new Exception($this->_i18n->getMessage("feature_requires_team"));
     }
     // check if balance is enough
     $amount = $parameters["amount"];
     $balance = $user->premiumBalance;
     if ($balance < $amount) {
         throw new Exception($this->_i18n->getMessage("premium-exchange_err_balancenotenough"));
     }
     // validation only: redirect to confirmation page
     if ($parameters["validateonly"]) {
         return "premium-exchange-confirm";
     }
     // credit amount on team account
     BankAccountDataService::creditAmount($this->_websoccer, $this->_db, $clubId, $amount * $exchangeRate, "premium-exchange_team_subject", $user->username);
     // debit premium amount
     PremiumDataService::debitAmount($this->_websoccer, $this->_db, $user->id, $amount, "exchange-premium");
     // success message
     $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("premium-exchange_success"), ""));
     return "premiumaccount";
 }
 /**
  * (non-PHPdoc)
  * @see IActionController::executeAction()
  */
 public function executeAction($parameters)
 {
     // read the post from PayPal system and add 'cmd'
     $req = 'cmd=_notify-validate';
     foreach ($_POST as $key => $value) {
         $value = urlencode(stripslashes($value));
         $req .= "&{$key}={$value}";
     }
     // post back to PayPal system to validate
     $header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
     $header .= "Host: " . $this->_websoccer->getConfig("paypal_host") . "\r\n";
     $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
     $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
     $fp = fsockopen($this->_websoccer->getConfig("paypal_url"), 443, $errno, $errstr, 30);
     if (!$fp) {
         throw new Exception("Error on HTTP(S) request. Error: " . $errno . " " . $errstr);
     } else {
         fputs($fp, $header . $req);
         $response = "";
         while (!feof($fp)) {
             $res = fgets($fp, 1024);
             $response .= $res;
             if (strcmp($res, "VERIFIED") == 0) {
                 // PAYMENT VALIDATED & VERIFIED!
                 // check receiver e-mail
                 if (strtolower($parameters["receiver_email"]) != strtolower($this->_websoccer->getConfig("paypal_receiver_email"))) {
                     EmailHelper::sendSystemEmail($this->_websoccer, $this->_websoccer->getConfig("systememail"), "Failed PayPal confirmation: Invalid Receiver", "Invalid receiver: " . $parameters["receiver_email"]);
                     throw new Exception("Receiver E-Mail not correct.");
                 }
                 if ($parameters["payment_status"] != "Completed") {
                     EmailHelper::sendSystemEmail($this->_websoccer, $this->_websoccer->getConfig("systememail"), "Failed PayPal confirmation: Invalid Status", "A paypment notification has been sent, but has an invalid status: " . $parameters["payment_status"]);
                     throw new Exception("Payment status not correct.");
                 }
                 // credit amount to user
                 $amount = $parameters["mc_gross"];
                 $userId = $parameters["custom"];
                 PremiumDataService::createPaymentAndCreditPremium($this->_websoccer, $this->_db, $userId, $amount, "paypal-notify");
                 // we can exit script execution here, since action is called in background
                 die(200);
             } else {
                 if (strcmp($res, "INVALID") == 0) {
                     // PAYMENT INVALID & INVESTIGATE MANUALY!
                     throw new Exception("Payment is invalid");
                 }
             }
         }
         fclose($fp);
         header('X-Error-Message: invalid paypal response: ' . $response, true, 500);
         die('X-Error-Message: invalid paypal response: ' . $response);
     }
     return null;
 }
コード例 #3
0
 /**
  * (non-PHPdoc)
  * @see IModel::getTemplateParameters()
  */
 public function getTemplateParameters()
 {
     $userId = $this->_websoccer->getUser()->id;
     $count = PremiumDataService::countAccountStatementsOfUser($this->_websoccer, $this->_db, $userId);
     $eps = $this->_websoccer->getConfig("entries_per_page");
     $paginator = new Paginator($count, $eps, $this->_websoccer);
     if ($count > 0) {
         $statements = PremiumDataService::getAccountStatementsOfUser($this->_websoccer, $this->_db, $userId, $paginator->getFirstIndex(), $eps);
     } else {
         $statements = array();
     }
     return array("statements" => $statements, "paginator" => $paginator, "payments" => PremiumDataService::getPaymentsOfUser($this->_websoccer, $this->_db, $userId, 5));
 }
コード例 #4
0
 /**
  * (non-PHPdoc)
  * @see IActionController::executeAction()
  */
 public function executeAction($parameters)
 {
     $user = $this->_websoccer->getUser();
     $teamId = $user->getClubId($this->_websoccer, $this->_db);
     if ($teamId < 1) {
         throw new Exception($this->_i18n->getMessage("feature_requires_team"));
     }
     if (TrainingDataService::countRemainingTrainingUnits($this->_websoccer, $this->_db, $teamId)) {
         throw new Exception($this->_i18n->getMessage("training_choose_trainer_err_existing_units"));
     }
     // trainer info
     $trainer = TrainingDataService::getTrainerById($this->_websoccer, $this->_db, $parameters["id"]);
     if (!isset($trainer["id"])) {
         throw new Exception("invalid ID");
     }
     // can team afford it?
     $numberOfUnits = (int) $parameters["units"];
     $totalCosts = $numberOfUnits * $trainer["salary"];
     $teamInfo = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $teamId);
     if ($teamInfo["team_budget"] <= $totalCosts) {
         throw new Exception($this->_i18n->getMessage("training_choose_trainer_err_too_expensive"));
     }
     // try to debit premium fee
     if ($trainer['premiumfee']) {
         PremiumDataService::debitAmount($this->_websoccer, $this->_db, $user->id, $trainer['premiumfee'], "choose-trainer");
     }
     // debit money
     BankAccountDataService::debitAmount($this->_websoccer, $this->_db, $teamId, $totalCosts, "training_trainer_salary_subject", $trainer["name"]);
     // create new units
     $columns["team_id"] = $teamId;
     $columns["trainer_id"] = $trainer["id"];
     $fromTable = $this->_websoccer->getConfig("db_prefix") . "_training_unit";
     for ($unitNo = 1; $unitNo <= $numberOfUnits; $unitNo++) {
         $this->_db->queryInsert($columns, $fromTable);
     }
     // success message
     $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("saved_message_title"), ""));
     // redirect to training overview
     return "training";
 }
 /**
  * (non-PHPdoc)
  * @see IActionController::executeAction()
  */
 public function executeAction($parameters)
 {
     $configKey = trim($this->_websoccer->getConfig("sofortcom_configkey"));
     if (!strlen($configKey)) {
         throw new Exception("Sofort.com configuration key is not configured.");
     }
     // verify user
     $userId = $parameters['u'];
     $result = $this->_db->querySelect("id", $this->_websoccer->getConfig("db_prefix") . "_user", "id = %d", $userId);
     $user = $result->fetch_array();
     $result->free();
     if (!$user) {
         throw new Exception("illegal user id");
     }
     // read the notification from php://input  (http://php.net/manual/en/wrappers.php.php)
     $SofortLib_Notification = new SofortLibNotification();
     $TestNotification = $SofortLib_Notification->getNotification(file_get_contents('php://input'));
     // read data
     $SofortLibTransactionData = new SofortLibTransactionData($configKey);
     $SofortLibTransactionData->addTransaction($TestNotification);
     // verify transaction data
     $SofortLibTransactionData->sendRequest();
     if ($SofortLibTransactionData->isError()) {
         EmailHelper::sendSystemEmail($this->_websoccer, $this->_websoccer->getConfig("systememail"), "Failed Sofort.com payment notification", "Error: " . $SofortLibTransactionData->getError());
         throw new Exception($SofortLibTransactionData->getError());
     } else {
         // verify status
         if ($SofortLibTransactionData->getStatus() != 'received') {
             EmailHelper::sendSystemEmail($this->_websoccer, $this->_websoccer->getConfig("systememail"), "Failed Sofort.com payment notification: invalid status", "Status: " . $SofortLibTransactionData->getStatus());
             throw new Exception("illegal status");
         }
         // credit amount
         $amount = $SofortLibTransactionData->getAmount();
         PremiumDataService::createPaymentAndCreditPremium($this->_websoccer, $this->_db, $userId, $amount, "sofortcom-notify");
     }
     return null;
 }
コード例 #6
0
 /**
  * (non-PHPdoc)
  * @see IActionController::executeAction()
  */
 public function executeAction($parameters)
 {
     $user = $this->_websoccer->getUser();
     $teamId = $user->getClubId($this->_websoccer, $this->_db);
     if ($teamId < 1) {
         return null;
     }
     // any number entered?
     if (!$parameters["side_standing"] && !$parameters["side_seats"] && !$parameters["grand_standing"] && !$parameters["grand_seats"] && !$parameters["vip"]) {
         return null;
     }
     $stadium = StadiumsDataService::getStadiumByTeamId($this->_websoccer, $this->_db, $teamId);
     if (!$stadium) {
         return null;
     }
     // max limit exceeded?
     $seatsSide = $stadium["places_stands"] + $stadium["places_seats"] + $parameters["side_standing"] + $parameters["side_seats"];
     if ($seatsSide > $this->_websoccer->getConfig("stadium_max_side")) {
         throw new Exception($this->_i18n->getMessage("stadium_extend_err_exceed_max_side", $this->_websoccer->getConfig("stadium_max_side")));
     }
     $seatsGrand = $stadium["places_stands_grand"] + $stadium["places_seats_grand"] + $parameters["grand_standing"] + $parameters["grand_seats"];
     if ($seatsGrand > $this->_websoccer->getConfig("stadium_max_grand")) {
         throw new Exception($this->_i18n->getMessage("stadium_extend_err_exceed_max_grand", $this->_websoccer->getConfig("stadium_max_grand")));
     }
     $seatsVip = $stadium["places_vip"] + $parameters["vip"];
     if ($seatsVip > $this->_websoccer->getConfig("stadium_max_vip")) {
         throw new Exception($this->_i18n->getMessage("stadium_extend_err_exceed_max_vip", $this->_websoccer->getConfig("stadium_max_vip")));
     }
     // is construction already on-going?
     if (StadiumsDataService::getCurrentConstructionOrderOfTeam($this->_websoccer, $this->_db, $teamId) != NULL) {
         throw new Exception($this->_i18n->getMessage("stadium_extend_err_constructionongoing"));
     }
     if (isset($parameters["validate-only"]) && $parameters["validate-only"]) {
         return "stadium-extend-confirm";
     }
     // builder got selected? Illegal builder ID can only happen due to a bug or user input manipulation.
     $builderId = $this->_websoccer->getRequestParameter("offerid");
     $offers = StadiumsDataService::getBuilderOffersForExtension($this->_websoccer, $this->_db, $teamId, (int) $this->_websoccer->getRequestParameter("side_standing"), (int) $this->_websoccer->getRequestParameter("side_seats"), (int) $this->_websoccer->getRequestParameter("grand_standing"), (int) $this->_websoccer->getRequestParameter("grand_seats"), (int) $this->_websoccer->getRequestParameter("vip"));
     if ($builderId == NULL || !isset($offers[$builderId])) {
         throw new Exception("Illegal offer ID.");
     }
     // can user afford it?
     $offer = $offers[$builderId];
     $team = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $teamId);
     $totalCosts = $offer["totalCosts"];
     if ($team["team_budget"] <= $totalCosts) {
         throw new Exception($this->_i18n->getMessage("stadium_extend_err_too_expensive"));
     }
     // try to debit premium fee
     if ($offer["builder_premiumfee"]) {
         PremiumDataService::debitAmount($this->_websoccer, $this->_db, $user->id, $offer["builder_premiumfee"], "extend-stadium");
     }
     // debit money
     BankAccountDataService::debitAmount($this->_websoccer, $this->_db, $teamId, $totalCosts, "stadium_extend_transaction_subject", $offer["builder_name"]);
     // create construction order
     $this->_db->queryInsert(array("team_id" => $teamId, "builder_id" => $builderId, "started" => $this->_websoccer->getNowAsTimestamp(), "deadline" => $offer["deadline"], "p_steh" => $parameters["side_standing"] ? $parameters["side_standing"] : 0, "p_sitz" => $parameters["side_seats"] ? $parameters["side_seats"] : 0, "p_haupt_steh" => $parameters["grand_standing"] ? $parameters["grand_standing"] : 0, "p_haupt_sitz" => $parameters["grand_seats"] ? $parameters["grand_seats"] : 0, "p_vip" => $parameters["vip"] ? $parameters["vip"] : 0), $this->_websoccer->getConfig("db_prefix") . "_stadium_construction");
     // success message
     $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("stadium_extend_success"), ""));
     // create action log manually here, ceause of this great "validate-only" idea...
     ActionLogDataService::createOrUpdateActionLog($this->_websoccer, $this->_db, $user->id, "extend-stadium");
     $seats = $parameters["side_standing"] + $parameters["side_seats"] + $parameters["grand_standing"] + $parameters["grand_seats"] + $parameters["vip"];
     BadgesDataService::awardBadgeIfApplicable($this->_websoccer, $this->_db, $user->id, 'stadium_construction_by_x', $seats);
     return "stadium";
 }
コード例 #7
0
ファイル: index.php プロジェクト: astroChasqui/open-websoccer
    die('micropayments.de is not enabled');
}
// 1. validate parameters --------------------------------------------------
// amount is passed in eurocents
$amount = $_GET['amount'] / 100;
// user id as free parameter
$userId = (int) $_GET['free'];
if (!$userId) {
    die('status=error');
}
// function must be 'billing' for crediting money
if ($_GET['function'] != 'billing') {
    die('invalid function');
}
// credit amount
PremiumDataService::createPaymentAndCreditPremium($website, $db, $userId, $amount, 'micropayment-notify');
// 2. Prepare response ------------------------------------------------------------------
$trenner = "\n";
$status = 'ok';
$url = $website->getInternalUrl('premiumaccount', null, TRUE);
$target = '_top';
$forward = 1;
$response = 'status=' . $status;
$response .= $trenner;
$response .= 'url=' . $url;
$response .= $trenner;
$response .= 'target=' . $target;
$response .= $trenner;
$response .= 'forward=' . $forward;
// send response
echo $response;
コード例 #8
0
 /**
  * (non-PHPdoc)
  * @see IActionController::executeAction()
  */
 public function executeAction($parameters)
 {
     $buildingId = $parameters['id'];
     $user = $this->_websoccer->getUser();
     $teamId = $user->getClubId($this->_websoccer, $this->_db);
     if (!$teamId) {
         throw new Exception($this->_i18n->getMessage("feature_requires_team"));
     }
     $dbPrefix = $this->_websoccer->getConfig('db_prefix');
     $result = $this->_db->querySelect('*', $dbPrefix . '_stadiumbuilding', 'id = %d', $buildingId);
     $building = $result->fetch_array();
     $result->free();
     if (!$building) {
         // no i18n required since this should actually not happen if used properly.
         throw new Exception('illegal building.');
     }
     // check budget
     $team = TeamsDataService::getTeamSummaryById($this->_websoccer, $this->_db, $teamId);
     if ($team['team_budget'] <= $building['costs']) {
         throw new Exception($this->_i18n->getMessage('stadiumenvironment_build_err_too_expensive'));
     }
     // check if already exists in team
     $result = $this->_db->querySelect('*', $dbPrefix . '_buildings_of_team', 'team_id = %d AND building_id = %d', array($teamId, $buildingId));
     $buildingExists = $result->fetch_array();
     $result->free();
     if ($buildingExists) {
         throw new Exception($this->_i18n->getMessage('stadiumenvironment_build_err_already_exists'));
     }
     // check required building
     if ($building['required_building_id']) {
         $result = $this->_db->querySelect('*', $dbPrefix . '_buildings_of_team', 'team_id = %d AND building_id = %d', array($teamId, $building['required_building_id']));
         $requiredBuildingExists = $result->fetch_array();
         $result->free();
         if (!$requiredBuildingExists) {
             throw new Exception($this->_i18n->getMessage('stadiumenvironment_build_err_requires_building'));
         }
     }
     // check premium costs
     if ($building['premiumfee'] > $user->premiumBalance) {
         throw new Exception($this->_i18n->getMessage('stadiumenvironment_build_err_premium_balance'));
     }
     // withdraw costs
     BankAccountDataService::debitAmount($this->_websoccer, $this->_db, $teamId, $building['costs'], 'building_construction_fee_subject', $building['name']);
     // place order
     $constructionDeadline = $this->_websoccer->getNowAsTimestamp() + $building['construction_time_days'] * 24 * 3600;
     $this->_db->queryInsert(array('building_id' => $buildingId, 'team_id' => $teamId, 'construction_deadline' => $constructionDeadline), $dbPrefix . '_buildings_of_team');
     // withdraw premium fee
     if ($building['premiumfee']) {
         PremiumDataService::debitAmount($this->_websoccer, $this->_db, $user->id, $building['premiumfee'], "order-building");
     }
     // credit fan popularity change
     if ($building['effect_fanpopularity'] != 0) {
         $result = $this->_db->querySelect('fanbeliebtheit', $dbPrefix . '_user', 'id = %d', $user->id, 1);
         $userinfo = $result->fetch_array();
         $result->free();
         $popularity = min(100, max(1, $building['effect_fanpopularity'] + $userinfo['fanbeliebtheit']));
         $this->_db->queryUpdate(array('fanbeliebtheit' => $popularity), $dbPrefix . '_user', 'id = %d', $user->id);
     }
     // success message
     $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("stadiumenvironment_build_success"), ""));
     return null;
 }
コード例 #9
0
 private static function _handlePremiumAction(WebSoccer $website, DbConnection $db, I18n $i18n, $actionId, $creditsRequired, $validatedParams, $controllerName)
 {
     // check if user has enough credit
     if ($creditsRequired > $website->getUser()->premiumBalance) {
         $targetPage = $website->getConfig('premium_infopage');
         // redirect to external info page
         if (filter_var($targetPage, FILTER_VALIDATE_URL)) {
             header('location: ' . $targetPage);
             exit;
             // render info page
         } else {
             $website->addContextParameter('premium_balance_required', $creditsRequired);
             return $targetPage;
         }
     }
     // debit amount and execute action
     if ($website->getRequestParameter('premiumconfirmed')) {
         PremiumDataService::debitAmount($website, $db, $website->getUser()->id, $creditsRequired, $actionId);
         return self::_executeAction($website, $db, $i18n, $actionId, $controllerName, $validatedParams);
     }
     // redirect to confirmation page
     $website->addContextParameter('premium_balance_required', $creditsRequired);
     $website->addContextParameter('actionparameters', $validatedParams);
     $website->addContextParameter('actionid', $actionId);
     $website->addContextParameter('srcpage', $website->getPageId());
     return 'premium-confirm-action';
 }