You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
3.4 KiB
110 lines
3.4 KiB
<?php
|
|
/* For license terms, see /license.txt */
|
|
|
|
use ChamiloSession as Session;
|
|
|
|
/**
|
|
* Process payments for the Buy Courses plugin
|
|
* @package chamilo.plugin.buycourses
|
|
*/
|
|
require_once '../config.php';
|
|
|
|
$currentUserId = api_get_user_id();
|
|
|
|
if (empty($currentUserId)) {
|
|
Session::write('buy_course_redirect', Security::remove_XSS($_SERVER['REQUEST_URI']));
|
|
header('Location: '.api_get_path(WEB_CODE_PATH).'auth/inscription.php');
|
|
exit;
|
|
}
|
|
|
|
$plugin = BuyCoursesPlugin::create();
|
|
$includeSession = $plugin->get('include_sessions') === 'true';
|
|
$paypalEnabled = $plugin->get('paypal_enable') === 'true';
|
|
$transferEnabled = $plugin->get('transfer_enable') === 'true';
|
|
$culqiEnabled = $plugin->get('culqi_enable') === 'true';
|
|
|
|
if (!$paypalEnabled && !$transferEnabled && !$culqiEnabled) {
|
|
api_not_allowed(true);
|
|
}
|
|
|
|
if (!isset($_REQUEST['t'], $_REQUEST['i'])) {
|
|
api_not_allowed(true);
|
|
}
|
|
|
|
$buyingCourse = intval($_REQUEST['t']) === BuyCoursesPlugin::PRODUCT_TYPE_COURSE;
|
|
$buyingSession = intval($_REQUEST['t']) === BuyCoursesPlugin::PRODUCT_TYPE_SESSION;
|
|
$queryString = 'i='.intval($_REQUEST['i']).'&t='.intval($_REQUEST['t']);
|
|
|
|
if ($buyingCourse) {
|
|
$courseInfo = $plugin->getCourseInfo($_REQUEST['i']);
|
|
$item = $plugin->getItemByProduct($_REQUEST['i'], BuyCoursesPlugin::PRODUCT_TYPE_COURSE);
|
|
} elseif ($buyingSession) {
|
|
$sessionInfo = $plugin->getSessionInfo($_REQUEST['i']);
|
|
$item = $plugin->getItemByProduct($_REQUEST['i'], BuyCoursesPlugin::PRODUCT_TYPE_SESSION);
|
|
}
|
|
|
|
$userInfo = api_get_user_info();
|
|
|
|
$form = new FormValidator('confirm_sale');
|
|
|
|
if ($form->validate()) {
|
|
$formValues = $form->getSubmitValues();
|
|
|
|
if (!$formValues['payment_type']) {
|
|
Display::addFlash(
|
|
Display::return_message($plugin->get_lang('NeedToSelectPaymentType'), 'error', false)
|
|
);
|
|
header('Location:'.api_get_self().'?'.$queryString);
|
|
exit;
|
|
}
|
|
|
|
$saleId = $plugin->registerSale($item['id'], $formValues['payment_type']);
|
|
|
|
if ($saleId !== false) {
|
|
$_SESSION['bc_sale_id'] = $saleId;
|
|
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/process_confirm.php');
|
|
}
|
|
|
|
exit;
|
|
}
|
|
|
|
$paymentTypesOptions = $plugin->getPaymentTypes();
|
|
|
|
if (!$paypalEnabled) {
|
|
unset($paymentTypesOptions[BuyCoursesPlugin::PAYMENT_TYPE_PAYPAL]);
|
|
}
|
|
|
|
if (!$transferEnabled) {
|
|
unset($paymentTypesOptions[BuyCoursesPlugin::PAYMENT_TYPE_TRANSFER]);
|
|
}
|
|
|
|
if (!$culqiEnabled) {
|
|
unset($paymentTypesOptions[BuyCoursesPlugin::PAYMENT_TYPE_CULQI]);
|
|
}
|
|
|
|
$form->addHtml(Display::return_message($plugin->get_lang('PleaseSelectThePaymentMethodBeforeConfirmYourOrder'), 'info'));
|
|
$form->addRadio('payment_type', null, $paymentTypesOptions);
|
|
$form->addHidden('t', intval($_GET['t']));
|
|
$form->addHidden('i', intval($_GET['i']));
|
|
$form->addButton('submit', $plugin->get_lang('ConfirmOrder'), 'check', 'success');
|
|
|
|
// View
|
|
$templateName = $plugin->get_lang('PaymentMethods');
|
|
$interbreadcrumb[] = array("url" => "course_catalog.php", "name" => $plugin->get_lang('CourseListOnSale'));
|
|
|
|
$tpl = new Template($templateName);
|
|
$tpl->assign('buying_course', $buyingCourse);
|
|
$tpl->assign('buying_session', $buyingSession);
|
|
$tpl->assign('user', api_get_user_info());
|
|
$tpl->assign('form', $form->returnForm());
|
|
|
|
if ($buyingCourse) {
|
|
$tpl->assign('course', $courseInfo);
|
|
} elseif ($buyingSession) {
|
|
$tpl->assign('session', $sessionInfo);
|
|
}
|
|
|
|
$content = $tpl->fetch('buycourses/view/process.tpl');
|
|
|
|
$tpl->assign('content', $content);
|
|
$tpl->display_one_col_template();
|
|
|