public function confirmed($project = null, $id = null, $reward = null) { if (empty($id)) { Message::Error(Text::get('invest-data-error')); throw new Redirection('/', Redirection::TEMPORARY); } // el aporte $invest = Model\Invest::get($id); $projectData = Model\Project::getMedium($invest->project); // para evitar las duplicaciones de feed y email if (isset($_SESSION['invest_' . $invest->id . '_completed'])) { Message::Info(Text::get('invest-process-completed')); throw new Redirection($retUrl); } // segun método if ($invest->method == 'tpv') { // si el aporte no está en estado "cobrado por goteo" (1) if ($invest->status != '1') { @mail('*****@*****.**', 'Aporte tpv no pagado ' . $invest->id, 'Ha llegado a invest/confirm el aporte ' . $invest->id . ' mediante tpv sin estado cobrado (llega con estado ' . $invest->status . ')'); // mandarlo a la pagina de aportar para que lo intente de nuevo // si es de Bazar, a la del producto del catálogo if ($project == 'bazargoteo') { throw new Redirection("/bazaar/{$reward}/fail"); } else { throw new Redirection("/project/{$invest->project}/invest/?confirm=fail"); } } } // Paypal solo disponible si activado if ($invest->method == 'paypal') { // hay que cambiarle el status a 0 $invest->setStatus('0'); // Evento Feed $log = new Feed(); $log->setTarget($projectData->id); $log->populate('Aporte PayPal', '/admin/invests', \vsprintf("%s ha aportado %s al proyecto %s mediante PayPal", array(Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('money', $invest->amount . ' €'), Feed::item('project', $projectData->name, $projectData->id)))); $log->doAdmin('money'); // evento público $log_html = Text::html('feed-invest', Feed::item('money', $invest->amount . ' €'), Feed::item('project', $projectData->name, $projectData->id)); if ($invest->anonymous) { $log->populate(Text::get('regular-anonymous'), '/user/profile/anonymous', $log_html, 1); } else { $log->populate($_SESSION['user']->name, '/user/profile/' . $_SESSION['user']->id, $log_html, $_SESSION['user']->avatar->id); } $log->doPublic('community'); unset($log); } // fin segun metodo // Feed del aporte de la campaña if (!empty($invest->droped) && $drop instanceof Model\Invest && is_object($callData)) { // Evento Feed $log = new Feed(); $log->setTarget($projectData->id); $log->populate('Aporte riego ' . $drop->method, '/admin/invests', \vsprintf("%s ha aportado %s de %s al proyecto %s a través de la campaña %s", array(Feed::item('user', $callData->user->name, $callData->user->id), Feed::item('money', $drop->amount . ' €'), Feed::item('drop', 'Capital Riego', '/service/resources'), Feed::item('project', $projectData->name, $projectData->id), Feed::item('call', $callData->name, $callData->id)))); $log->doAdmin('money'); // evento público $log->populate($callData->user->name, '/user/profile/' . $callData->user->id, Text::html('feed-invest', Feed::item('money', $drop->amount . ' €') . ' de ' . Feed::item('drop', 'Capital Riego', '/service/resources'), Feed::item('project', $projectData->name, $projectData->id) . ' a través de la campaña ' . Feed::item('call', $callData->name, $callData->id)), $callData->user->avatar->id); $log->doPublic('community'); unset($log); } // texto recompensa // @TODO quitar esta lacra de N recompensas porque ya es solo una recompensa siempre $rewards = $invest->rewards; array_walk($rewards, function (&$reward) { $reward = $reward->reward; }); $txt_rewards = implode(', ', $rewards); // recaudado y porcentaje $amount = $projectData->invested; $percent = floor($projectData->invested / $projectData->mincost * 100); // email de agradecimiento al cofinanciador // primero monto el texto de recompensas //@TODO el concepto principal sería 'renuncia' (porque todos los aportes son donativos) if ($invest->resign) { // Plantilla de donativo segun la ronda if ($projectData->round == 2) { $template = Template::get(36); // en segunda ronda } else { $template = Template::get(28); // en primera ronda } } else { // plantilla de agradecimiento segun la ronda if ($projectData->round == 2) { $template = Template::get(34); // en segunda ronda } else { $template = Template::get(10); // en primera ronda } } // Dirección en el mail (y version para regalo) $txt_address = Text::get('invest-address-address-field') . ' ' . $invest->address->address; $txt_address .= '<br> ' . Text::get('invest-address-zipcode-field') . ' ' . $invest->address->zipcode; $txt_address .= '<br> ' . Text::get('invest-address-location-field') . ' ' . $invest->address->location; $txt_address .= '<br> ' . Text::get('invest-address-country-field') . ' ' . $invest->address->country; $txt_destaddr = $txt_address; $txt_address = Text::get('invest-mail_info-address') . '<br>' . $txt_address; // Agradecimiento al cofinanciador // Sustituimos los datos $subject = str_replace('%PROJECTNAME%', $projectData->name, $template->title); // En el contenido: $search = array('%USERNAME%', '%PROJECTNAME%', '%PROJECTURL%', '%AMOUNT%', '%REWARDS%'); $replace = array($_SESSION['user']->name, $projectData->name, SITE_URL . '/project/' . $projectData->id, $confirm->amount, $txt_rewards); $content = \str_replace($search, $replace, $template->text); $mailHandler = new Mail(); $mailHandler->reply = GOTEO_CONTACT_MAIL; $mailHandler->replyName = GOTEO_MAIL_NAME; $mailHandler->to = $_SESSION['user']->email; $mailHandler->toName = $_SESSION['user']->name; $mailHandler->subject = $subject; $mailHandler->content = $content; $mailHandler->html = true; $mailHandler->template = $template->id; if ($mailHandler->send($errors)) { Message::Info(Text::get('project-invest-thanks_mail-success')); } else { Message::Error(Text::get('project-invest-thanks_mail-fail')); Message::Error(implode('<br />', $errors)); } unset($mailHandler); // Notificación al autor $template = Template::get(29); // Sustituimos los datos $subject = str_replace('%PROJECTNAME%', $projectData->name, $template->title); // En el contenido: $search = array('%OWNERNAME%', '%USERNAME%', '%PROJECTNAME%', '%SITEURL%', '%AMOUNT%', '%MESSAGEURL%'); $replace = array($projectData->user->name, $_SESSION['user']->name, $projectData->name, SITE_URL, $invest->amount, SITE_URL . '/user/profile/' . $_SESSION['user']->id . '/message'); $content = \str_replace($search, $replace, $template->text); $mailHandler = new Mail(); $mailHandler->to = $projectData->user->email; $mailHandler->toName = $projectData->user->name; $mailHandler->subject = $subject; $mailHandler->content = $content; $mailHandler->html = true; $mailHandler->template = $template->id; $mailHandler->send(); unset($mailHandler); // marcar que ya se ha completado el proceso de aportar $_SESSION['invest_' . $invest->id . '_completed'] = true; // log Model\Invest::setDetail($invest->id, 'confirmed', 'El usuario regresó a /invest/confirmed'); if ($confirm->method == 'paypal') { // hay que cambiarle el status a 0 $confirm->setStatus('0'); /* * Evento Feed */ $log = new Feed(); $log->title = 'Aporte PayPal'; $log->url = '/admin/invests'; $log->type = 'money'; $log_text = "%s ha aportado %s al proyecto %s mediante PayPal"; $items = array(Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('money', $confirm->amount . ' €'), Feed::item('project', $projectData->name, $projectData->id)); $log->html = \vsprintf($log_text, $items); $log->add($errors); // evento público if ($confirm->anonymous) { $log->title = Text::get('regular-anonymous'); $log->url = '/user/profile/anonymous'; $log->image = 1; } else { $log->title = $_SESSION['user']->name; $log->url = '/user/profile/' . $_SESSION['user']->id; $log->image = $_SESSION['user']->avatar->id; } $log->scope = 'public'; $log->type = 'community'; $log->html = Text::html('feed-invest', Feed::item('money', $confirm->amount . ' €'), Feed::item('project', $projectData->name, $projectData->id)); $log->add($errors); unset($log); } // mandarlo a la pagina de gracias throw new Redirection("/project/{$project}/invest/?confirm=ok", Redirection::TEMPORARY); }