/**
 * Оплата через Плати потом.
 * 
 * @param type $type - тип оплаты
 * @param type $data - данные по параметрам покупаемой услуги
 *
 * @return \xajaxResponse
 */
function quickPaymentTservicebindPlatipotom($type, $data)
{
    $is_error = true;
    $uid = get_uid(false);
    $objResponse =& new xajaxResponse();
    $kind = (int) @$data['kind'];
    $tservice_id = (int) @$data['tservice_text_db_id'];
    $prof_id = (int) @$data['prof_id'];
    $is_prolong = (bool) @$data['is_prolong'];
    $promo_code = (string) @$data['promo'];
    $tservices_binds = new tservices_binds($kind);
    $tservices = new tservices($uid);
    $allow = $tservices_binds->isAllowBind($uid, $tservice_id, $kind, $prof_id);
    $valid = $tservices->isExists($tservice_id) && ($is_prolong ? !$allow : $allow);
    if ($valid) {
        $is_error = false;
        $bill = new billing($uid);
        //Допустимо использование промокодов
        $bill->setPromoCodes('SERVICE_TSERVICEBIND', $promo_code);
        $op_code = $tservices_binds->getOpCode();
        $option = array('weeks' => (int) @$data['weeks'], 'prof_id' => $prof_id, 'tservice_id' => $tservice_id, 'is_prolong' => $is_prolong);
        //Формируем заказ
        $billReserveId = $bill->addServiceAndCheckout($op_code, $option);
        $payed_sum = $bill->getRealPayedSum();
        $platipotom = new platipotom();
        $html_form = $platipotom->render($payed_sum, $bill->account->id, $billReserveId);
        if ($html_form) {
            $idx = quickPaymentPopupTservicebind::getPopupId($is_prolong ? $tservice_id : 0);
            $objResponse->script("\n                var qp_form_wrapper = \$\$('#" . $idx . " .__quick_payment_form');\n                if(qp_form_wrapper){    \n                    qp_form_wrapper.set('html','{$html_form}');\n                    qp_form_wrapper.getElement('form')[0].submit();\n                }\n            ");
            //сохранаем в сессию куда перейти при успешной покупке
            $redirect = (string) @$data['redirect'];
            $_SESSION[quickPaymentPopup::QPP_REDIRECT] = $redirect;
        }
    }
    // Показываем предупреждение в случае ошибки
    if ($is_error) {
        $idx = quickPaymentPopupTservicebind::getPopupId($is_prolong ? $tservice_id : 0);
        $action = $is_prolong ? 'продлении закрепления' : 'закреплении';
        $objResponse->script("\n            var qp = window.quick_payment_factory.getQuickPaymentById('tservicebind', '" . $idx . "');\n            if(qp) qp.show_error('Возникла ошибка при {$action} услуги!');\n        ");
    }
    return $objResponse;
}
Пример #2
0
 /**
  * Уведомление фрилансеру за 1 день до окончания 
  * размещения закрепления ТУ
  */
 public function remind24hEndBinds()
 {
     require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/tservices/tservices_binds.php";
     require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/quick_payment/quickPaymentPopupTservicebind.php";
     $tservices_categories = new tservices_categories();
     //Базовый шаблон письма
     $layout = Template::render(TSERVICES_BINDS_TPL_BASE_LAYOUT, array('params' => '', 'content' => '%CONTENT%'));
     $this->message = nl2br($layout);
     $count = 0;
     $page = 0;
     while ($binds = tservices_binds::getExpiring(++$page, 200)) {
         $bind_ids = array();
         foreach ($binds as $el) {
             $kind_txt = '';
             $link = '/?' . quickPaymentPopupTservicebind::getPopupId($el['tservice_id']) . '=1';
             switch ($el['kind']) {
                 case tservices_binds::KIND_LANDING:
                     $kind_txt = 'на главной странице сайта';
                     break;
                 case tservices_binds::KIND_ROOT:
                     $kind_txt = 'в общем разделе каталога услуг';
                     $link = '/tu' . $link;
                     break;
                 case tservices_binds::KIND_GROUP:
                     $category = $tservices_categories->getCategoryById($el['prof_id']);
                     $kind_txt = sprintf("в разделе %s каталога услуг", @$category['title']);
                     $link = sprintf("/tu/%s%s", @$category['link'], $link);
                     break;
                 case tservices_binds::KIND_SPEC:
                     $category = $tservices_categories->getCategoryById($el['prof_id']);
                     $kind_txt = sprintf("в подразделе %s каталога услуг", @$category['title']);
                     $link = sprintf("/tu/%s%s", @$category['link'], $link);
                     break;
             }
             //Шаблон уведомления
             $content = Template::render(TSERVICES_BINDS_TPL_MAIL_PATH . "remind_prolong.tpl.php", array('smail' => $this, 'time' => dateFormat('H:i', $el['date_stop']), 'kind' => $kind_txt, 'title' => $el['title'], 'link' => $link));
             $this->recipient[] = array('email' => $this->_formatFullname($el, true), 'extra' => array('CONTENT' => nl2br($content)));
             $bind_ids[] = $el['id'];
         }
         $count += count($bind_ids);
         $massId = $this->send('text/html');
         if ($massId) {
             tservices_binds::markSent('prolong', $bind_ids);
         }
     }
     return $count;
 }