Merge branch '1.11.x' of github.com:chamilo/chamilo-lms into 1.11.x

pull/3565/head^2
Julio Montoya 5 years ago
commit 06cbcc6fdf
  1. 17
      main/exercise/TestCategory.php
  2. 14
      main/inc/lib/extra_field.lib.php
  3. 11
      main/inc/lib/social.lib.php
  4. 3
      main/install/configuration.dist.php
  5. 29
      main/lp/learnpath.class.php
  6. 53
      main/lp/lp_add_author.php
  7. 26
      plugin/buycourses/database.php
  8. 12
      plugin/buycourses/lang/english.php
  9. 12
      plugin/buycourses/lang/spanish.php
  10. 79
      plugin/buycourses/src/buy_course_plugin.class.php
  11. 67
      plugin/buycourses/src/paymentsetup.php
  12. 7
      plugin/buycourses/src/process.php
  13. 50
      plugin/buycourses/src/process_confirm.php
  14. 30
      plugin/buycourses/src/tpv_error.php
  15. 68
      plugin/buycourses/src/tpv_response.php
  16. 31
      plugin/buycourses/src/tpv_success.php
  17. 15
      plugin/buycourses/view/paymentsetup.tpl

@ -333,7 +333,7 @@ class TestCategory
*/
public static function getListOfCategoriesIDForTest($exerciseId, $courseId = 0)
{
// parcourir les questions d'un test, recup les categories uniques dans un tableau
// Check test questions, obtaining unique categories in a table
$exercise = new Exercise($courseId);
$exercise->read($exerciseId, false);
$categoriesInExercise = $exercise->getQuestionWithCategories();
@ -353,7 +353,7 @@ class TestCategory
*/
public static function getListOfCategoriesIDForTestObject(Exercise $exercise)
{
// parcourir les questions d'un test, recup les categories uniques dans un tableau
// Check the categories of a test, obtaining unique categories in table
$categories_in_exercise = [];
$question_list = $exercise->getQuestionOrderedListByName();
@ -1014,10 +1014,15 @@ class TestCategory
public function returnCategoryForm(Exercise $exercise)
{
$categories = $this->getListOfCategoriesForTest($exercise);
$sortedCategories = [];
foreach ($categories as $catId => $cat) {
$sortedCategories[$cat['title']] = $cat;
}
ksort($sortedCategories);
$saved_categories = $exercise->getCategoriesInExercise();
$return = null;
if (!empty($categories)) {
if (!empty($sortedCategories)) {
$nbQuestionsTotal = $exercise->getNumberQuestionExerciseCategory();
$exercise->setCategoriesGrouping(true);
$real_question_count = count($exercise->getQuestionList());
@ -1044,9 +1049,9 @@ class TestCategory
'title' => get_lang('NoCategory'),
];
$categories[] = $emptyCategory;
$sortedCategories[] = $emptyCategory;
foreach ($categories as $category) {
foreach ($sortedCategories as $category) {
$cat_id = $category['iid'];
$return .= '<tr>';
$return .= '<td>';
@ -1187,7 +1192,7 @@ class TestCategory
c.c_id = $courseId AND
i.tool = '".TOOL_TEST_CATEGORY."'
$sessionCondition
ORDER BY title";
ORDER BY title ASC";
$result = Database::query($sql);
return Database::store_result($result, 'ASSOC');

@ -994,6 +994,20 @@ class ExtraField extends Model
continue;
}
}
// see BT#17943
$authors = false;
if (
$field_details['variable'] == 'authors'
|| $field_details['variable'] == 'authorlp'
|| $field_details['variable'] == 'authorlpitem'
|| $field_details['variable'] == 'price'
) {
$authors = true;
}
if (!api_is_platform_admin() && $authors == true) {
continue;
}
// Getting default value id if is set
$defaultValueId = null;

@ -2467,8 +2467,15 @@ class SocialManager extends UserManager
$userId = $userId !== 0 ? $userId : api_get_user_id();
$user_info = api_get_user_info($userId);
$friend = true;
if ($userId != api_get_user_id()){
$editPorfolioLink = '';
if ($userId != api_get_user_id()) {
$friend = self::get_relation_between_contacts(api_get_user_id(), $userId);
} else {
$editPorfolioLink .= "<div class=\"pull-right\" style='margin-top: -5px'>".
'<a href="/main/auth/profile.php?type=extended#openarea" class="btn btn-default btn-sm btn-social-edit">'.
"<i class=\"fa fa-pencil\" aria-hidden=\"true\"></i>".
'</a>'.
"</div>";
}
if ($friend == 0) {
/* if has not relation, get current user */
@ -2556,7 +2563,7 @@ class SocialManager extends UserManager
$form->addHtml('</div>');
$form->addHidden('url_content', '');
return Display::panel($more_info, get_lang('Portfolio'));
return Display::panel($more_info, get_lang('Portfolio') . $editPorfolioLink);
}
/**

@ -1766,6 +1766,9 @@ $_configuration['auth_password_links'] = [
// Allow all office suite documents to be uploaded in the "My files" section of the social network
//$_configuration['social_myfiles_office_files_upload_allowed'] = false;
// Enable a "Previous question" button in surveys
// $_configuration['survey_backwards_enable'] = false;
// KEEP THIS AT THE END
// -------- Custom DB changes
// Add user activation by confirmation email

@ -6779,19 +6779,22 @@ class learnpath
);
}
if (isset($extraField['authorlp'])) {
$actionsLeft .= Display::url(
Display::return_icon(
'add-groups.png',
get_lang('Author'),
'',
ICON_SIZE_MEDIUM
),
'lp_controller.php?'.api_get_cidreq().'&'.http_build_query([
'action' => 'author_view',
'lp_id' => $lpId,
])
);
// see BT#17943
if (api_is_platform_admin()) {
if (isset($extraField['authorlp'])) {
$actionsLeft .= Display::url(
Display::return_icon(
'add-groups.png',
get_lang('Author'),
'',
ICON_SIZE_MEDIUM
),
'lp_controller.php?'.api_get_cidreq().'&'.http_build_query([
'action' => 'author_view',
'lp_id' => $lpId,
])
);
}
}
$toolbar = Display::toolbarAction(

@ -15,6 +15,7 @@ use ChamiloSession as Session;
$this_section = SECTION_COURSES;
api_protect_course_script();
api_protect_admin_script(true);
$isStudentView = isset($_REQUEST['isStudentView']) ? $_REQUEST['isStudentView'] : null;
$lpId = isset($_REQUEST['lp_id']) ? (int) $_REQUEST['lp_id'] : 0;
@ -32,11 +33,6 @@ if (!$is_allowed_to_edit) {
/** @var learnpath $learnPath */
$learnPath = Session::read('oLP');
/*
echo "<pre>".var_export($learnPath->authorsAvaible,true)."</pre>";
exit();
*/
if (empty($learnPath)) {
api_not_allowed();
}
@ -247,6 +243,10 @@ foreach ($_SESSION['oLP']->items as $item) {
$itemId,
strtolower('AuthorLPItem')
);
$priceItem = $extraFieldValue->get_values_by_handler_and_field_variable(
$itemId,
strtolower('price')
);
$authorName = [];
if (!empty($extraFieldValues)) {
if ($extraFieldValues != false) {
@ -268,6 +268,9 @@ foreach ($_SESSION['oLP']->items as $item) {
} else {
$authorName = '';
}
if (isset($priceItem['value']) && !empty($priceItem['value'])) {
$authorName .= "<br><small>".get_lang('Price')." (".$priceItem['value'].")</small>";
}
$form->addCheckBox("itemSelected[$itemId]", null, Display::return_icon('lp_document.png', $itemName).$itemName.$authorName);
$default["itemSelected"][$itemId] = false;
}
@ -310,6 +313,7 @@ foreach ($teachers as $key => $value) {
$form->addSelect('authorItemSelect', get_lang('Authors'), $options, [
'multiple' => 'multiple',
]);
$form->addNumeric('price', get_lang('Price'));
$form->addHtml('</div>');
$form->addButtonCreate(get_lang('Send'));
$form->setDefaults($default);
@ -320,6 +324,7 @@ if ($form->validate()) {
if (isset($_GET['sub_action']) && ($_GET['sub_action'] === 'author_view')) {
$authors = $_POST['authorItemSelect'];
$items = $_POST['itemSelected'];
$price = api_float_val($_POST['price']);
unset($author);
$saveExtraFieldItem = [];
$saveAuthor = [];
@ -339,6 +344,17 @@ if ($form->validate()) {
$saveExtraFieldItem[$itemId][$author] = $author;
}
}
if ($price > 0) {
$extraFieldValues = $extraFieldValue->get_values_by_handler_and_field_variable(
$itemId,
'price'
);
$extraFieldValue->save([
'variable' => 'price',
'value' => $price,
'item_id' => $itemId,
]);
}
}
}
@ -360,17 +376,24 @@ if ($form->validate()) {
}
$saveAuthor = array_unique($saveAuthor);
$messages .= implode(' / ', $saveAuthor);
$currentUrl = api_get_self();
if (!empty($messages)) {
if ($removeExist) {
Session::write('messageError', get_lang('DeletedAuthors'));
//header("Location: $currentUrl");
echo "<script>window.location.replace(\"$currentUrl\");</script>";
die();
}
$currentUrl = api_request_uri();
$redirect = false;
$sms = [];
if ($removeExist) {
Session::write('messageError', get_lang('DeletedAuthors'));
$redirect = true;
} elseif ($price > 0) {
$sms[] = get_lang('PriceUpdated');
$redirect = true;
} elseif (!empty($messages)) {
$sms[] = get_lang(get_lang('RegisteredAuthors')." ".$messages);
$redirect = true;
}
Session::write('message', get_lang('RegisteredAuthors')." ".$messages);
//header("Location: $currentUrl");
if ($redirect == true) {
if (count($sms) > 0) {
Session::write('message', implode(' / ', $sms));
}
echo "<script>window.location.replace(\"$currentUrl\");</script>";
die();
}

@ -48,6 +48,23 @@ if (false === $sm->tablesExist(BuyCoursesPlugin::TABLE_TRANSFER)) {
$transferTable->setPrimaryKey(['id']);
}
if (false === $sm->tablesExist(BuyCoursesPlugin::TABLE_TPV_REDSYS)) {
$tpvRedsysTable = $pluginSchema->createTable(BuyCoursesPlugin::TABLE_TPV_REDSYS);
$tpvRedsysTable->addColumn(
'id',
\Doctrine\DBAL\Types\Type::INTEGER,
['autoincrement' => true, 'unsigned' => true]
);
$tpvRedsysTable->addColumn('merchantcode', \Doctrine\DBAL\Types\Type::STRING);
$tpvRedsysTable->addColumn('terminal', \Doctrine\DBAL\Types\Type::STRING);
$tpvRedsysTable->addColumn('currency', \Doctrine\DBAL\Types\Type::STRING);
$tpvRedsysTable->addColumn('kc', \Doctrine\DBAL\Types\Type::STRING);
$tpvRedsysTable->addColumn('url_redsys', \Doctrine\DBAL\Types\Type::STRING);
$tpvRedsysTable->addColumn('url_redsys_sandbox', \Doctrine\DBAL\Types\Type::STRING);
$tpvRedsysTable->addColumn('sandbox', \Doctrine\DBAL\Types\Type::BOOLEAN);
$tpvRedsysTable->setPrimaryKey(['id']);
}
if (false === $sm->tablesExist(BuyCoursesPlugin::TABLE_CURRENCY)) {
$currencyTable = $pluginSchema->createTable(BuyCoursesPlugin::TABLE_CURRENCY);
$currencyTable->addColumn(
@ -404,6 +421,7 @@ $commissionTable = Database::get_main_table(BuyCoursesPlugin::TABLE_COMMISSION);
$extraFieldTable = Database::get_main_table(TABLE_EXTRA_FIELD);
$culqiTable = Database::get_main_table(BuyCoursesPlugin::TABLE_CULQI);
$globalTable = Database::get_main_table(BuyCoursesPlugin::TABLE_GLOBAL_CONFIG);
$tpvRedsysTable = Database::get_main_table(BuyCoursesPlugin::TABLE_TPV_REDSYS);
$paypalExtraField = Database::select(
"*",
@ -442,6 +460,14 @@ Database::insert(
]
);
Database::insert(
$tpvRedsysTable,
[
'url_redsys' => 'https://sis.redsys.es/sis/realizarPago',
'url_redsys_sandbox' => 'https://sis-t.redsys.es:25443/sis/realizarPago',
]
);
Database::insert(
$culqiTable,
[

@ -193,3 +193,15 @@ $strings['use_currency_symbol'] = "Use currency symbol";
$strings['ExportReport'] = "Export Sales Report";
$strings['OrderTime'] = "Order time";
$strings['SelectDateRange'] = "Select a <strong>start date</strong> and <strong>end date</strong> for the report";
$strings['tpv_redsys_enable'] = "Enable RedSys POS";
$strings['tpv_redsys_enable_help'] = "In order to use the RedSys POS payment method, it is necessary to download the \"REST INTEGRATION - PHP API \" files at the following link <a href='https://pagosonline.redsys.es/descargas.html'>web de RedSys</a> and locate the file <strong>apiRedSys.php</strong> in the <em>plugin/buycourses/resources</em> directory.";
$strings['NotFindRedsysFile'] = "The <strong>apiRedsys.php</strong> file cannot be found in <em>plugin/buycourses/resources</em> directory";
$strings['TpvPayment'] = "POS payment";
$strings['TpvRedsysConfig'] = "Redsys POS configuration";
$strings['DS_MERCHANT_MERCHANTCODE'] = "Trade number (FUC)";
$strings['DS_MERCHANT_TERMINAL'] = "Terminal number";
$strings['DS_MERCHANT_CURRENCY'] = "Terminal currency";
$strings['kc'] = "Secret encryption key";
$strings['url_redsys'] = "Redsys connection URL";
$strings['url_redsys_sandbox'] = "Redsys connection URL (Sandbox)";
$strings['InfoTpvRedsysApiCredentials'] = "You must complete the following fields of the form with the information provided by the Redsys POS Technical Support:";

@ -214,3 +214,15 @@ $strings['CurrencyIsNotConfigured'] = "Por favor, configure una moneda antes de
$strings['ExportReport'] = "Exportar reporte de ventas";
$strings['OrderTime'] = "Hora de pedido";
$strings['SelectDateRange'] = "Seleccione una <strong>fecha de inicio</strong> y <strong>fecha de fin</strong> para el reporte";
$strings['tpv_redsys_enable'] = "Habilitar TPV RedSys";
$strings['tpv_redsys_enable_help'] = "Para poder utilizar la modalidad de pago del TPV de RedSys es necesario descargar los ficheros de \"INTEGRACIÓN REST - API PHP\" en el siguiente enlace <a href='https://pagosonline.redsys.es/descargas.html'>web de RedSys</a> y ubicar el fichero el fichero <strong>apiRedSys.php</strong> en el directorio <em>plugin/buycourses/resources</em>.";
$strings['NotFindRedsysFile'] = "No se encuentra en el directorio <em>plugin/buycourses/resources</em> el fichero <strong>apiRedsys.php</strong>";
$strings['TpvPayment'] = "Pago con tarjeta";
$strings['TpvRedsysConfig'] = "Configuración TPV Redsys";
$strings['DS_MERCHANT_MERCHANTCODE'] = "Número de comercio (FUC)";
$strings['DS_MERCHANT_TERMINAL'] = "Número de terminal";
$strings['DS_MERCHANT_CURRENCY'] = "Moneda del terminal";
$strings['kc'] = "Clave secreta de encriptación";
$strings['url_redsys'] = "URL conexión Redsys";
$strings['url_redsys_sandbox'] = "URL conexión Redsys (Pruebas)";
$strings['InfoTpvRedsysApiCredentials'] = "Deberá completar los siguientes campos del formulario con la información que les facilite el Soporte Técnico del TPV Redsys:";

@ -32,11 +32,13 @@ class BuyCoursesPlugin extends Plugin
const TABLE_CULQI = 'plugin_buycourses_culqi';
const TABLE_GLOBAL_CONFIG = 'plugin_buycourses_global_config';
const TABLE_INVOICE = 'plugin_buycourses_invoices';
const TABLE_TPV_REDSYS = 'plugin_buycourses_tpvredsys_account';
const PRODUCT_TYPE_COURSE = 1;
const PRODUCT_TYPE_SESSION = 2;
const PAYMENT_TYPE_PAYPAL = 1;
const PAYMENT_TYPE_TRANSFER = 2;
const PAYMENT_TYPE_CULQI = 3;
const PAYMENT_TYPE_TPV_REDSYS = 4;
const PAYOUT_STATUS_CANCELED = 2;
const PAYOUT_STATUS_PENDING = 0;
const PAYOUT_STATUS_COMPLETED = 1;
@ -90,6 +92,7 @@ class BuyCoursesPlugin extends Plugin
'invoicing_enable' => 'boolean',
'tax_enable' => 'boolean',
'use_currency_symbol' => 'boolean',
'tpv_redsys_enable' => 'boolean',
]
);
}
@ -135,6 +138,7 @@ class BuyCoursesPlugin extends Plugin
self::TABLE_SERVICES_SALE,
self::TABLE_GLOBAL_CONFIG,
self::TABLE_INVOICE,
self::TABLE_TPV_REDSYS,
];
$em = Database::getManager();
$cn = $em->getConnection();
@ -167,6 +171,7 @@ class BuyCoursesPlugin extends Plugin
self::TABLE_SERVICES,
self::TABLE_GLOBAL_CONFIG,
self::TABLE_INVOICE,
self::TABLE_TPV_REDSYS,
];
foreach ($tablesToBeDeleted as $tableToBeDeleted) {
@ -273,6 +278,29 @@ class BuyCoursesPlugin extends Plugin
)";
Database::query($sql);
$table = self::TABLE_TPV_REDSYS;
$sql = "CREATE TABLE IF NOT EXISTS $table (
id int unsigned NOT NULL AUTO_INCREMENT,
merchantcode varchar(255) NOT NULL,
terminal varchar(255) NOT NULL,
currency varchar(255) NOT NULL,
kc varchar(255) NOT NULL,
url_redsys varchar(255) NOT NULL,
url_redsys_sandbox varchar(255) NOT NULL,
sandbox int unsigned NULL,
PRIMARY KEY (id)
)";
Database::query($sql);
$sql = "SELECT * FROM $table";
$res = Database::query($sql);
if (Database::num_rows($res) == 0) {
Database::insert($table, [
'url_redsys' => 'https://sis.redsys.es/sis/realizarPago',
'url_redsys_sandbox' => 'https://sis-t.redsys.es:25443/sis/realizarPago',
]);
}
Display::addFlash(
Display::return_message(
$this->get_lang('Updated'),
@ -452,6 +480,45 @@ class BuyCoursesPlugin extends Plugin
);
}
/**
* Gets the stored TPV Redsys params.
*
* @return array
*/
public function getTpvRedsysParams()
{
return Database::select(
'*',
Database::get_main_table(self::TABLE_TPV_REDSYS),
['id = ?' => 1],
'first'
);
}
/**
* Save the tpv Redsys configuration params.
*
* @param array $params
*
* @return int Rows affected. Otherwise return false
*/
public function saveTpvRedsysParams($params)
{
return Database::update(
Database::get_main_table(self::TABLE_TPV_REDSYS),
[
'merchantcode' => $params['merchantcode'],
'terminal' => $params['terminal'],
'currency' => $params['currency'],
'kc' => $params['kc'],
'url_redsys' => $params['url_redsys'],
'url_redsys_sandbox' => $params['url_redsys_sandbox'],
'sandbox' => isset($params['sandbox']),
],
['id = ?' => 1]
);
}
/**
* Save a transfer account information.
*
@ -896,9 +963,14 @@ class BuyCoursesPlugin extends Plugin
public function registerSale($itemId, $paymentType)
{
if (!in_array(
$paymentType,
[self::PAYMENT_TYPE_PAYPAL, self::PAYMENT_TYPE_TRANSFER, self::PAYMENT_TYPE_CULQI]
)
$paymentType,
[
self::PAYMENT_TYPE_PAYPAL,
self::PAYMENT_TYPE_TRANSFER,
self::PAYMENT_TYPE_CULQI,
self::PAYMENT_TYPE_TPV_REDSYS,
]
)
) {
return false;
}
@ -1175,6 +1247,7 @@ class BuyCoursesPlugin extends Plugin
self::PAYMENT_TYPE_PAYPAL => 'PayPal',
self::PAYMENT_TYPE_TRANSFER => $this->get_lang('BankTransfer'),
self::PAYMENT_TYPE_CULQI => 'Culqi',
self::PAYMENT_TYPE_TPV_REDSYS => $this->get_lang('TpvPayment'),
];
}

@ -16,6 +16,7 @@ $plugin = BuyCoursesPlugin::create();
$paypalEnable = $plugin->get('paypal_enable');
$transferEnable = $plugin->get('transfer_enable');
$tpvRedsysEnable = $plugin->get('tpv_redsys_enable');
$commissionsEnable = $plugin->get('commissions_enable');
$culqiEnable = $plugin->get('culqi_enable');
@ -209,6 +210,70 @@ $paypalForm->addCheckBox('sandbox', null, $plugin->get_lang('Sandbox'));
$paypalForm->addButtonSave(get_lang('Save'));
$paypalForm->setDefaults($plugin->getPaypalParams());
// TPV Redsys
$htmlTpvRedsys = Display::return_message($plugin->get_lang('NotFindRedsysFile'), 'warning', false);
if (file_exists(api_get_path(SYS_PLUGIN_PATH).'buycourses/resources/apiRedsys.php')) {
$tpvRedsysForm = new FormValidator('tpv_redsys');
$tpvRedsysForm->addHtml(
Display::return_message($plugin->get_lang('InfoTpvRedsysApiCredentials'), 'info', false)
);
if ($tpvRedsysForm->validate()) {
$tpvRedsysFormValues = $tpvRedsysForm->getSubmitValues();
$plugin->saveTpvRedsysParams($tpvRedsysFormValues);
Display::addFlash(
Display::return_message(get_lang('Saved'), 'success')
);
header('Location:'.api_get_self());
exit;
}
$tpvRedsysForm->addText(
'merchantcode',
[$plugin->get_lang('DS_MERCHANT_MERCHANTCODE'), 'DS_MERCHANT_MERCHANTCODE'],
false,
['cols-size' => [3, 8, 1]]
);
$tpvRedsysForm->addText(
'terminal',
[$plugin->get_lang('DS_MERCHANT_TERMINAL'), 'DS_MERCHANT_TERMINAL'],
false,
['cols-size' => [3, 8, 1]]
);
$tpvRedsysForm->addText(
'currency',
[$plugin->get_lang('DS_MERCHANT_CURRENCY'), 'DS_MERCHANT_CURRENCY'],
false,
['cols-size' => [3, 8, 1]]
);
$tpvRedsysForm->addText(
'kc',
$plugin->get_lang('kc'),
false,
['cols-size' => [3, 8, 1]]
);
$tpvRedsysForm->addText(
'url_redsys',
$plugin->get_lang('url_redsys'),
false,
['cols-size' => [3, 8, 1]]
);
$tpvRedsysForm->addText(
'url_redsys_sandbox',
$plugin->get_lang('url_redsys_sandbox'),
false,
['cols-size' => [3, 8, 1]]
);
$tpvRedsysForm->addCheckBox('sandbox', null, $plugin->get_lang('Sandbox'));
$tpvRedsysForm->addButtonSave(get_lang('Save'));
$tpvRedsysForm->setDefaults($plugin->getTpvRedsysParams());
$htmlTpvRedsys = $tpvRedsysForm->returnForm();
}
// Platform Commissions
$commissionForm = new FormValidator('commissions');
@ -325,6 +390,8 @@ $tpl->assign('paypal_enable', $paypalEnable);
$tpl->assign('commissions_enable', $commissionsEnable);
$tpl->assign('transfer_enable', $transferEnable);
$tpl->assign('culqi_enable', $culqiEnable);
$tpl->assign('tpv_redsys_enable', $tpvRedsysEnable);
$tpl->assign('tpv_redsys_form', $htmlTpvRedsys);
$content = $tpl->fetch('buycourses/view/paymentsetup.tpl');

@ -20,8 +20,9 @@ $includeSession = $plugin->get('include_sessions') === 'true';
$paypalEnabled = $plugin->get('paypal_enable') === 'true';
$transferEnabled = $plugin->get('transfer_enable') === 'true';
$culqiEnabled = $plugin->get('culqi_enable') === 'true';
$tpvRedsysEnable = $plugin->get('tpv_redsys_enable') === 'true';
if (!$paypalEnabled && !$transferEnabled && !$culqiEnabled) {
if (!$paypalEnabled && !$transferEnabled && !$culqiEnabled && !$tpvRedsysEnable) {
api_not_allowed(true);
}
@ -83,6 +84,10 @@ if (!$culqiEnabled) {
unset($paymentTypesOptions[BuyCoursesPlugin::PAYMENT_TYPE_CULQI]);
}
if (!$tpvRedsysEnable || !file_exists(api_get_path(SYS_PLUGIN_PATH).'buycourses/resources/apiRedsys.php')) {
unset($paymentTypesOptions[BuyCoursesPlugin::PAYMENT_TYPE_TPV_REDSYS]);
}
$count = count($paymentTypesOptions);
if ($count === 0) {
$form->addHtml($plugin->get_lang('NoPaymentOptionAvailable'));

@ -311,5 +311,55 @@ switch ($sale['payment_type']) {
$template->assign('content', $content);
$template->display_one_col_template();
break;
case BuyCoursesPlugin::PAYMENT_TYPE_TPV_REDSYS:
$tpvRedsysParams = $plugin->getTpvRedsysParams();
require_once '../resources/apiRedsys.php';
$tpv = new RedsysAPI();
$merchantcode = $tpvRedsysParams['merchantcode'];
$terminal = $tpvRedsysParams['terminal'];
$currency = $tpvRedsysParams['currency'];
$transactionType = "0";
$urlMerchant = api_get_path(WEB_PLUGIN_PATH).'buycourses/src/tpv_response.php';
$urlSuccess = api_get_path(WEB_PLUGIN_PATH).'buycourses/src/tpv_success.php';
$urlFailed = api_get_path(WEB_PLUGIN_PATH).'buycourses/src/tpv_error.php';
$order = str_pad(strval($saleId), 4, "0", STR_PAD_LEFT);
$amount = $sale['price'] * 100;
$description = $plugin->get_lang('OrderReference').": ".$sale['reference'];
$tpv->setParameter("DS_MERCHANT_AMOUNT", $amount);
$tpv->setParameter("DS_MERCHANT_ORDER", $order);
$tpv->setParameter("DS_MERCHANT_MERCHANTCODE", $merchantcode);
$tpv->setParameter("DS_MERCHANT_CURRENCY", $currency);
$tpv->setParameter("DS_MERCHANT_TRANSACTIONTYPE", $transactionType);
$tpv->setParameter("DS_MERCHANT_TERMINAL", $terminal);
$tpv->setParameter("DS_MERCHANT_MERCHANTURL", $urlMerchant);
$tpv->setParameter("DS_MERCHANT_URLOK", $urlSuccess);
$tpv->setParameter("DS_MERCHANT_URLKO", $urlFailed);
$tpv->setParameter("DS_MERCHANT_PRODUCTDESCRIPTION", $description);
$version = "HMAC_SHA256_V1";
$kc = $tpvRedsysParams['kc'];
$urlTpv = $tpvRedsysParams['url_redsys'];
$sandboxFlag = $tpvRedsysParams['sandbox'] == 1;
if ($sandboxFlag === true) {
$urlTpv = $tpvRedsysParams['url_redsys_sandbox'];
}
$params = $tpv->createMerchantParameters();
$signature = $tpv->createMerchantSignature($kc);
echo '<form name="tpv_chamilo" action="'.$urlTpv.'" method="POST">';
echo '<input type="hidden" name="Ds_SignatureVersion" value="'.$version.'" />';
echo '<input type="hidden" name="Ds_MerchantParameters" value="'.$params.'" />';
echo '<input type="hidden" name="Ds_Signature" value="'.$signature.'" />';
echo '</form>';
echo '<SCRIPT language=javascript>';
echo 'document.tpv_chamilo.submit();';
echo '</script>';
break;
}

@ -0,0 +1,30 @@
<?php
/* For license terms, see /license.txt */
/**
* Success page for the purchase of a course in the Buy Courses plugin.
*
* @package chamilo.plugin.buycourses
*/
require_once '../config.php';
$plugin = BuyCoursesPlugin::create();
$tpvRedsysEnabled = $plugin->get('tpv_redsys_enable') === 'true';
if (!$tpvRedsysEnabled) {
api_not_allowed(true);
}
$sale = $plugin->getSale($_SESSION['bc_sale_id']);
if (empty($sale)) {
api_not_allowed(true);
}
Display::addFlash(
Display::return_message($plugin->get_lang('ErrorContactPlatformAdmin'), 'error')
);
unset($_SESSION['bc_sale_id']);
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/course_catalog.php');
exit;

@ -0,0 +1,68 @@
<?php
/* For license terms, see /license.txt */
/**
* Success page for the purchase of a course in the Buy Courses plugin.
*
* @package chamilo.plugin.buycourses
*/
require_once '../config.php';
$plugin = BuyCoursesPlugin::create();
$tpvRedsysEnabled = $plugin->get('tpv_redsys_enable') === 'true';
if (!$tpvRedsysEnabled) {
api_not_allowed(true);
}
$tpvRedsysParams = $plugin->getTpvRedsysParams();
$version = $_POST['Ds_SignatureVersion'];
$params = $_POST["Ds_MerchantParameters"];
$signatureReceived = $_POST['Ds_Signature'];
require_once '../resources/apiRedsys.php';
$tpv = new RedsysAPI();
$decodec = $tpv->decodeMerchantParameters($params);
$kc = $tpvRedsysParams['kc'];
$signature = $tpv->createMerchantSignatureNotif($kc, $params);
if ($signature === $signatureReceived) {
$saleId = (int) $tpv->getParameter("Ds_Order");
$response = $tpv->getParameter("Ds_Response");
// other fields available
// $Ds_Amount=$miObj->getParameter("Ds_Amount");
// $Ds_MerchantCode=$miObj->getParameter("Ds_MerchantCode");
// $Ds_TransactionType=$miObj->getParameter("Ds_TransactionType");
// $Ds_MerchantData=$miObj->getParameter("Ds_MerchantData");
// $Ds_Date=$miObj->getParameter("Ds_Date");
// $Ds_Hour=$miObj->getParameter("Ds_Hour");
$sale = $plugin->getSale($saleId);
if (empty($sale)) {
api_not_allowed(true);
}
$buyingCourse = false;
$buyingSession = false;
switch ($sale['product_type']) {
case BuyCoursesPlugin::PRODUCT_TYPE_COURSE:
$buyingCourse = true;
$course = $plugin->getCourseInfo($sale['product_id']);
break;
case BuyCoursesPlugin::PRODUCT_TYPE_SESSION:
$buyingSession = true;
$session = $plugin->getSessionInfo($sale['product_id']);
break;
}
if ($response == "0000") {
$saleIsCompleted = $plugin->completeSale($sale['id']);
if ($saleIsCompleted) {
$plugin->storePayouts($sale['id']);
}
}
}

@ -0,0 +1,31 @@
<?php
/* For license terms, see /license.txt */
/**
* Success page for the purchase of a course in the Buy Courses plugin.
*
* @package chamilo.plugin.buycourses
*/
require_once '../config.php';
$plugin = BuyCoursesPlugin::create();
$tpvRedsysEnabled = $plugin->get('tpv_redsys_enable') === 'true';
if (!$tpvRedsysEnabled) {
api_not_allowed(true);
}
$sale = $plugin->getSale($_SESSION['bc_sale_id']);
if (empty($sale)) {
api_not_allowed(true);
}
Display::addFlash(
$plugin->getSubscriptionSuccessMessage($sale)
);
//$plugin->storePayouts($sale['id']);
unset($_SESSION['bc_sale_id']);
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/course_catalog.php');
exit;

@ -41,6 +41,21 @@
</div>
{% endif %}
{% if tpv_redsys_enable == "true" %}
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">{{ 'TpvRedsysConfig'|get_plugin_lang('BuyCoursesPlugin') }}</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-12">
{{ tpv_redsys_form }}
</div>
</div>
</div>
</div>
{% endif %}
{% if commissions_enable == "true" %}
<div class="panel panel-default">
<div class="panel-heading">

Loading…
Cancel
Save