<?php session_start(); require_once 'config.php'; require_once 'classes.php'; $m = new MoneyStuff(); $promo_code = $_GET['promo_code']; //Validate promo code and user session $validate = $m->ValidateVoucher($promo_code); if ($validate == false) { printf("<script>document.location.href='index.php?error=ERR_CODE_NOT_VALID'</script>;"); die("ERR_CODE_NOT_VALID"); } $user_logon_data = $_SESSION['user_profile']; if ($user_logon_data['id'] == '') { printf("<script>document.location.href='index.php?error=ERR_NO_SESSION'</script>;"); die("ERR_NO_SESSION"); } if ($user_logon_data['currency'] != $validate['currency']) { $amount = round($validate['amount'] * $m->CurrencyExchange($user_logon_data['currency'], $validate['currency']), 2); } else { $amount = $validate['amount']; } $m->SumMoney($user_logon_data['id'], $amount); $m->InsertPaymentVoucher($user_logon_data['id'], $validate['currency'], $validate['amount']); $m->RedeemCode($promo_code); printf("<script>document.location.href='index.php?message=VOUCHER_OK'</script>;");
print "<script>document.location.href='connect.php?message=INIT_SESSION&return=" . $return_url . "'</script>;"; die; } //Get to user id $campaign_owner = $money_class->GetCampaignOwner($campaign_id); //Check if user has balance $account_balance = $user_class->GetBalance($user_logon_data['id']); if ($account_balance >= $amount && $amount != '') { $from_user_currency = $user_logon_data['currency']; $to_user_currency = $user_class->GetUSerCurrency($campaign_owner['user_id']); //Substract money to user $substract = $money_class->SubtractMoney($user_logon_data['id'], $amount); if ($from_user_currency == $to_user_currency) { $amount = $amount; } else { $exchange = $money_class->CurrencyExchange($to_user_currency, $from_user_currency); $amount = round($amount * $exchange, 2); //var_dump($amount);die(); } $add_money = $money_class->SumMoney($campaign_owner['user_id'], $amount); $redeemed = '1'; $anonymous = '0'; $trans_hash = md5($campaign_owner['user_id'] . $user_logon_data['id'] . time()); $to_user_twitter_id = $user_class->GetTwitterIdFromUserId($campaign_owner['user_id']); $save_trans = mysql_query("INSERT INTO `transactions` (`id` ,`from_user_id` ,`to_twitter_user_id` ,`date` ,`redeemed` ,`amount` ,`anonymous` , `hash`)VALUES (\nNULL , '" . $user_logon_data['id'] . "', '" . $to_user_twitter_id . "', CURRENT_TIMESTAMP , '" . $redeemed . "', '" . $amount . "', '" . $anonymous . "' , '" . $trans_hash . "');"); $save_trans_campaign = mysql_query("INSERT INTO `campaign_transactions` (`id` ,`campaign_id` ,`amount` ,`currency` , `from_user_id`, `sent_time`)VALUES (\nNULL , '" . $campaign_id . "', '" . $amount . "','" . $to_user_currency . "' , '" . $user_logon_data['id'] . "' , CURRENT_TIMESTAMP);"); } else { //Oops, no money, redirect to payment platform printf("<script>document.location.href='sum_balance.php?message=NO_MONEY&return='</script>;"); } printf("<script>document.location.href='campaign.php?id=" . $campaign_id . "&INFO=THANKS_DONATE'</script>;");
break; case 'success': //Pago correcto //Fin //Comprobar que no sea la ultima participacion // $hash = $_GET['hash']; $secure = md5($hash . PAYPAL_SECRET_HASH); if ($secure != $_GET['secure']) { die('ERR_HASH_CHECK_FAILED'); } $get_amount = mysql_query("SELECT amount,user_id FROM `paypal_payments` WHERE `hash` = '" . $hash . "' AND `status` = '0';"); $get_am = mysql_fetch_array($get_amount); $amount = $get_am['amount']; $user_id_sum = $get_am['user_id']; $sum = $m->SumMoney($user_id_sum, $amount); $save_trans = mysql_query("UPDATE `paypal_payments` SET `status` = '1' WHERE `hash` = '" . $hash . "';"); $to_user_id = $_GET['to_user_id']; //Sum money to user account balance echo "<html><head></head><body><h3>processing...</h3>"; if ($to_user_id == '') { printf("<script>document.location.href='index.php?message=PAYPAL_REFILL_OK'</script>;"); } else { printf("<script>document.location.href='send_money.php?from_user_id=" . $user_id_sum . "&to_user_id=" . $to_user_id . "'</script>;"); } // foreach ($_POST as $key => $value) { echo "$key: $value<br>"; } echo "</body></html>"; break; case 'cancel': // Order was canceled... $hash = $_GET['hash'];
//echo("enough money!!"); //deduct money from user profile $substract = $money_class->SubtractMoney($user_logon_data['id'], $amount); //if user is in DB, sum money to destination user and if ($user_exists == true) { $from_user_currency = $user_logon_data['currency']; $to_user_currency = $user_exists['currency']; if ($from_user_currency == $to_user_currency) { $amount = $amount; } else { $exchange = $money_class->CurrencyExchange($to_user_currency, $from_user_currency); $amount = round($amount * $exchange, 2); //var_dump($amount);die(); } //Do the adition to the user destination account_balance $add_money = $money_class->SumMoney($user_exists['id'], $amount); $redeemed = '1'; //Redeem is true because we add money to user profile } else { $redeemed = '0'; } //save transaction log $trans_hash = md5($user_data['screen_name'] . $user_data['id'] . $user_logon_data['id'] . time()); $save_trans = mysql_query("INSERT INTO `transactions` (`id` ,`from_user_id` ,`to_twitter_user_id` ,`date` ,`redeemed` ,`amount` ,`anonymous` , `hash`)VALUES (\nNULL , '" . $user_logon_data['id'] . "', '" . $user_data['id'] . "', CURRENT_TIMESTAMP , '" . $redeemed . "', '" . $amount . "', '" . $anonymous . "' , '" . $trans_hash . "');"); //notify to destination user $link = "https://" . TUITFLOW_URL . "redeem.php?id=" . $trans_hash; //Get random value from $notificator array $k = array_rand($notificator); $notificator_data = $notificator[$k]; $connection_own = new TwitterOAuth($notificator_data['consumer_key'], $notificator_data['consumer_secret'], $notificator_data['own_key'], $notificator_data['own_secret']); if ($anonymous == 0) {