$user_prof = get_object_vars($content);
//Check if user is logged
if ($user_logon_data == '') {
    $return_url = urlencode($_SERVER['SCRIPT_NAME'] . '?id=' . $campaign_id . '');
    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 {
}
foreach ($receiversArray as $i => $receiverData) {
    $receiverEmail = urlencode($receiverData['receiverEmail']);
    $amount = urlencode($receiverData['amount']);
    $amount_gross = $amount;
    $amount = round($amount * PAYPAL_FARE_PER, 2) + PAYPAL_FARE_FIX;
    $uniqueID = urlencode($receiverData['uniqueID']);
    $note = urlencode($receiverData['note']);
    $nvpStr .= "&L_EMAIL{$i}={$receiverEmail}&L_Amt{$i}={$amount_gross}&L_UNIQUEID{$i}={$uniqueID}&L_NOTE{$i}={$note}";
}
// Execute the API operation; see the PPHttpPost function above.
$httpParsedResponseAr = PPHttpPost('MassPay', $nvpStr);
//var_dump($nvpStr);
if ("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
    //Payment is ok, now record and substract the money
    $money_class->SubtractMoney($_SESSION['user_profile']['id'], $amount_gross);
    $user_class->Record_user_log($_SESSION['user_profile']['id'], "Refund " . $amount_gross . " " . $currency . " to paypal " . $paypal_to);
    $status = 'OK';
    $money_class->RecordPaypalRefund($_SESSION['user_profile']['id'], $amount_gross, $currency, $status, $httpParsedResponseAr['CORRELATIONID']);
    //print($httpParsedResponseAr['ACK']."<br>");
    //print("ok ".$amount." ".$currency." ".$paypal_to);
    //exit('MassPay Completed Successfully: '.print_r($httpParsedResponseAr, true));
    printf("<script>document.location.href='index.php?message=PAYPAL_REFUND_OK&hash=" . $hash . "'</script>;");
} else {
    $status = 'KO ' . $httpParsedResponseAr['L_SHORTMESSAGE0'];
    $money_class->SubtractMoney($_SESSION['user_profile']['id'], $amount_gross);
    $money_class->RecordPaypalRefund($_SESSION['user_profile']['id'], $amount_gross, $currency, $status, $httpParsedResponseAr['ACK']['CORRELATIONID']);
    //exit('MassPay failed: ' . print_r($httpParsedResponseAr, true));
    //print("ERR_PAYPAL_REFUND_CONTACT_SUPPORT");
    //If an error happens, send mail to info@tuitflow.com to make the payment.
    $cabeceras = 'From: info@tuitflow.com' . "\r\n" . 'Reply-To: info@tuitflow.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion();