upgrade
This commit is contained in:
6146
plugin/buycourses/src/buy_course_plugin.class.php
Normal file
6146
plugin/buycourses/src/buy_course_plugin.class.php
Normal file
File diff suppressed because it is too large
Load Diff
612
plugin/buycourses/src/buycourses.ajax.php
Normal file
612
plugin/buycourses/src/buycourses.ajax.php
Normal file
@@ -0,0 +1,612 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CoreBundle\Entity\Course;
|
||||
use Chamilo\CoreBundle\Entity\Session;
|
||||
use Chamilo\CourseBundle\Entity\CLp;
|
||||
use Chamilo\UserBundle\Entity\User;
|
||||
|
||||
/**
|
||||
* Responses to AJAX calls.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
|
||||
if (api_is_anonymous()) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$culqiEnable = $plugin->get('culqi_enable');
|
||||
$action = isset($_GET['a']) ? $_GET['a'] : null;
|
||||
|
||||
$em = Database::getManager();
|
||||
|
||||
switch ($action) {
|
||||
case 'verifyPaypal':
|
||||
if (api_is_anonymous()) {
|
||||
break;
|
||||
}
|
||||
|
||||
$userId = isset($_POST['id']) ? (int) $_POST['id'] : '';
|
||||
$isUserHavePaypalAccount = $plugin->verifyPaypalAccountByBeneficiary($userId);
|
||||
if ($isUserHavePaypalAccount) {
|
||||
echo '';
|
||||
} else {
|
||||
echo '<b style="color: red; font-size: 70%;">* '.$plugin->get_lang('NoPayPalAccountDetected').'</b>';
|
||||
}
|
||||
break;
|
||||
case 'saleInfo':
|
||||
if (api_is_anonymous()) {
|
||||
break;
|
||||
}
|
||||
|
||||
$saleId = isset($_POST['id']) ? (int) $_POST['id'] : '';
|
||||
$sale = $plugin->getSale($saleId);
|
||||
$productType = $sale['product_type'] == 1 ? get_lang('Course') : get_lang('Session');
|
||||
$paymentType = $sale['payment_type'] == 1 ? 'Paypal' : $plugin->get_lang('BankTransfer');
|
||||
$productInfo = $sale['product_type'] == 1
|
||||
? api_get_course_info_by_id($sale['product_id'])
|
||||
: api_get_session_info($sale['product_id']);
|
||||
$currency = $plugin->getSelectedCurrency();
|
||||
if ($sale['product_type'] == 1) {
|
||||
$productImage = $productInfo['course_image_large'];
|
||||
} else {
|
||||
$productImage = ($productInfo['image'])
|
||||
? $productInfo['image']
|
||||
: Template::get_icon_path('session_default.png');
|
||||
}
|
||||
|
||||
$userInfo = api_get_user_info($sale['user_id']);
|
||||
|
||||
$html = '<h2>'.$sale['product_name'].'</h2>';
|
||||
$html .= '<div class="row">';
|
||||
$html .= '<div class="col-sm-6 col-md-6">';
|
||||
$html .= '<ul>';
|
||||
$html .= '<li><b>'.$plugin->get_lang('OrderPrice').':</b> '.$sale['total_price'].'</li>';
|
||||
$html .= '<li><b>'.$plugin->get_lang('CurrencyType').':</b> '.$currency['iso_code'].'</li>';
|
||||
$html .= '<li><b>'.$plugin->get_lang('ProductType').':</b> '.$productType.'</li>';
|
||||
$html .= '<li><b>'.$plugin->get_lang('OrderDate').':</b> '.
|
||||
api_format_date(
|
||||
$sale['date'],
|
||||
DATE_TIME_FORMAT_LONG_24H
|
||||
).'</li>';
|
||||
$html .= '<li><b>'.$plugin->get_lang('Buyer').':</b> '.$userInfo['complete_name'].'</li>';
|
||||
$html .= '<li><b>'.$plugin->get_lang('PaymentMethods').':</b> '.$paymentType.'</li>';
|
||||
$html .= '</ul>';
|
||||
$html .= '</div>';
|
||||
$html .= '<div class="col-sm-6 col-md-6">';
|
||||
$html .= '<img class="thumbnail" src="'.$productImage.'" >';
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
|
||||
echo $html;
|
||||
break;
|
||||
case 'stats':
|
||||
if (api_is_anonymous()) {
|
||||
break;
|
||||
}
|
||||
|
||||
$stats = [];
|
||||
$stats['completed_count'] = 0;
|
||||
$stats['completed_total_amount'] = 0;
|
||||
$stats['pending_count'] = 0;
|
||||
$stats['pending_total_amount'] = 0;
|
||||
$stats['canceled_count'] = 0;
|
||||
$stats['canceled_total_amount'] = 0;
|
||||
|
||||
$completedPayouts = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_COMPLETED);
|
||||
$pendingPayouts = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_PENDING);
|
||||
$canceledPayouts = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_CANCELED);
|
||||
$currency = $plugin->getSelectedCurrency();
|
||||
|
||||
foreach ($completedPayouts as $completed) {
|
||||
$stats['completed_count'] = count($completedPayouts);
|
||||
$stats['completed_total_amount'] += $completed['commission'];
|
||||
$stats['completed_total_amount'] = number_format($stats['completed_total_amount'], 2);
|
||||
}
|
||||
|
||||
foreach ($pendingPayouts as $pending) {
|
||||
$stats['pending_count'] = count($pendingPayouts);
|
||||
$stats['pending_total_amount'] += $pending['commission'];
|
||||
$stats['pending_total_amount'] = number_format($stats['pending_total_amount'], 2);
|
||||
}
|
||||
|
||||
foreach ($canceledPayouts as $canceled) {
|
||||
$stats['canceled_count'] = count($canceledPayouts);
|
||||
$stats['canceled_total_amount'] += $canceled['commission'];
|
||||
$stats['canceled_total_amount'] = number_format($stats['canceled_total_amount'], 2);
|
||||
}
|
||||
|
||||
$html = '<div class="row">'
|
||||
.'<p>'
|
||||
.'<ul>'
|
||||
.'<li>'.get_plugin_lang("PayoutsTotalCompleted", "BuyCoursesPlugin").' <b>'.$stats['completed_count']
|
||||
.'</b> - '.get_plugin_lang("TotalAmount", "BuyCoursesPlugin").' <b>'.$stats['completed_total_amount'].' '
|
||||
.$currency['iso_code'].'</b></li>'
|
||||
.'<li>'.get_plugin_lang("PayoutsTotalPending", "BuyCoursesPlugin").' <b>'.$stats['pending_count'].'</b> - '
|
||||
.get_plugin_lang("TotalAmount", "BuyCoursesPlugin").' <b>'.$stats['pending_total_amount'].' '
|
||||
.$currency['iso_code'].'</b></li>'
|
||||
.'<li>'.get_plugin_lang("PayoutsTotalCanceled", "BuyCoursesPlugin").' <b>'.$stats['canceled_count']
|
||||
.'</b> - '.get_plugin_lang("TotalAmount", "BuyCoursesPlugin").' <b>'.$stats['canceled_total_amount'].' '
|
||||
.$currency['iso_code'].'</b></li>'
|
||||
.'</ul>'
|
||||
.'</p>';
|
||||
$html .= '</div>';
|
||||
echo $html;
|
||||
break;
|
||||
case 'processPayout':
|
||||
if (api_is_anonymous()) {
|
||||
break;
|
||||
}
|
||||
|
||||
$html = '';
|
||||
$allPays = [];
|
||||
$totalAccounts = 0;
|
||||
$totalPayout = 0;
|
||||
|
||||
$payouts = isset($_POST['payouts']) ? $_POST['payouts'] : '';
|
||||
|
||||
if (!$payouts) {
|
||||
echo Display::return_message(
|
||||
get_plugin_lang("SelectOptionToProceed", "BuyCoursesPlugin"),
|
||||
'error',
|
||||
false
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ($payouts as $index => $id) {
|
||||
$allPays[] = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_PENDING, $id);
|
||||
}
|
||||
|
||||
foreach ($allPays as $payout) {
|
||||
$totalPayout += number_format($payout['commission'], 2);
|
||||
$totalAccounts++;
|
||||
}
|
||||
|
||||
$currentCurrency = $plugin->getSelectedCurrency();
|
||||
$isoCode = $currentCurrency['iso_code'];
|
||||
$html .= '<p>'.get_plugin_lang("VerifyTotalAmountToProceedPayout", "BuyCoursesPlugin").'</p>';
|
||||
$html .= ''
|
||||
.'<p>'
|
||||
.'<ul>'
|
||||
.'<li>'.get_plugin_lang("TotalAcounts", "BuyCoursesPlugin").' <b>'.$totalAccounts.'</b></li>'
|
||||
.'<li>'.get_plugin_lang("TotalPayout", "BuyCoursesPlugin").' <b>'.$isoCode.' '.$totalPayout.'</b></li>'
|
||||
.'</ul>'
|
||||
.'</p>';
|
||||
$html .= '<p>'.get_plugin_lang("CautionThisProcessCantBeCanceled", "BuyCoursesPlugin").'</p>';
|
||||
$html .= '<br /><br />';
|
||||
$html .= '<div id="spinner" class="text-center"></div>';
|
||||
|
||||
echo $html;
|
||||
break;
|
||||
case 'proceedPayout':
|
||||
if (api_is_anonymous()) {
|
||||
break;
|
||||
}
|
||||
|
||||
$paypalParams = $plugin->getPaypalParams();
|
||||
|
||||
$pruebas = $paypalParams['sandbox'] == 1;
|
||||
$paypalUsername = $paypalParams['username'];
|
||||
$paypalPassword = $paypalParams['password'];
|
||||
$paypalSignature = $paypalParams['signature'];
|
||||
|
||||
require_once "paypalfunctions.php";
|
||||
|
||||
$allPayouts = [];
|
||||
$totalAccounts = 0;
|
||||
$totalPayout = 0;
|
||||
|
||||
$payouts = isset($_POST['payouts']) ? $_POST['payouts'] : '';
|
||||
|
||||
if (!$payouts) {
|
||||
echo Display::return_message(
|
||||
get_plugin_lang("SelectOptionToProceed", "BuyCoursesPlugin"),
|
||||
'error',
|
||||
false
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ($payouts as $index => $id) {
|
||||
$allPayouts[] = $plugin->getPayouts(
|
||||
BuyCoursesPlugin::PAYOUT_STATUS_PENDING,
|
||||
$id
|
||||
);
|
||||
}
|
||||
|
||||
$currentCurrency = $plugin->getSelectedCurrency();
|
||||
$isoCode = $currentCurrency['iso_code'];
|
||||
$result = MassPayment($allPayouts, $isoCode);
|
||||
if ($result['ACK'] === 'Success') {
|
||||
foreach ($allPayouts as $payout) {
|
||||
$plugin->setStatusPayouts(
|
||||
$payout['id'],
|
||||
BuyCoursesPlugin::PAYOUT_STATUS_COMPLETED
|
||||
);
|
||||
if ($plugin->get('invoicing_enable') === 'true') {
|
||||
$plugin->setInvoice($payout['id']);
|
||||
}
|
||||
}
|
||||
|
||||
echo Display::return_message(
|
||||
get_plugin_lang("PayoutSuccess", "BuyCoursesPlugin"),
|
||||
'success',
|
||||
false
|
||||
);
|
||||
} else {
|
||||
echo Display::return_message(
|
||||
'<b>'.$result['L_SEVERITYCODE0'].' '.$result['L_ERRORCODE0'].'</b> - '.$result['L_SHORTMESSAGE0']
|
||||
.'<br /><ul><li>'.$result['L_LONGMESSAGE0'].'</li></ul>',
|
||||
'error',
|
||||
false
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'cancelPayout':
|
||||
if (api_is_anonymous()) {
|
||||
break;
|
||||
}
|
||||
|
||||
// $payoutId only gets used in setStatusPayout(), where it is filtered
|
||||
$payoutId = isset($_POST['id']) ? $_POST['id'] : '';
|
||||
$plugin->setStatusPayouts(
|
||||
$payoutId,
|
||||
BuyCoursesPlugin::PAYOUT_STATUS_CANCELED
|
||||
);
|
||||
|
||||
echo '';
|
||||
|
||||
break;
|
||||
case 'culqi_cargo':
|
||||
if (!$culqiEnable) {
|
||||
break;
|
||||
}
|
||||
|
||||
$tokenId = $_REQUEST['token_id'];
|
||||
$saleId = $_REQUEST['sale_id'];
|
||||
|
||||
if (!$tokenId || !$saleId) {
|
||||
break;
|
||||
}
|
||||
$sale = $plugin->getSale($saleId);
|
||||
if (!$sale) {
|
||||
break;
|
||||
}
|
||||
|
||||
require_once 'Requests.php';
|
||||
Requests::register_autoloader();
|
||||
require_once 'culqi.php';
|
||||
|
||||
$culqiParams = $plugin->getCulqiParams();
|
||||
|
||||
// API Key y autenticación
|
||||
$SECRET_API_KEY = $culqiParams['api_key'];
|
||||
$culqi = new Culqi\Culqi(['api_key' => $SECRET_API_KEY]);
|
||||
|
||||
$environment = $culqiParams['integration'];
|
||||
$environment = $environment
|
||||
? BuyCoursesPlugin::CULQI_INTEGRATION_TYPE
|
||||
: BuyCoursesPlugin::CULQI_PRODUCTION_TYPE;
|
||||
|
||||
$culqi->setEnv($environment);
|
||||
|
||||
$user = api_get_user_info();
|
||||
$currency = $plugin->getSelectedCurrency();
|
||||
|
||||
try {
|
||||
$cargo = $culqi->Cargos->create([
|
||||
"moneda" => $currency['iso_code'],
|
||||
"monto" => intval(floatval($sale['price']) * 100),
|
||||
"usuario" => $user['username'],
|
||||
"descripcion" => $sale['product_name'],
|
||||
"pedido" => $sale['reference'],
|
||||
"codigo_pais" => "PE",
|
||||
"direccion" => get_lang('None'),
|
||||
"ciudad" => get_lang('None'),
|
||||
"telefono" => 0,
|
||||
"nombres" => $user['firstname'],
|
||||
"apellidos" => $user['lastname'],
|
||||
"correo_electronico" => $user['email'],
|
||||
"token" => $tokenId,
|
||||
]);
|
||||
|
||||
if (is_object($cargo)) {
|
||||
$saleIsCompleted = $plugin->completeSale($sale['id']);
|
||||
|
||||
if ($saleIsCompleted) {
|
||||
Display::addFlash(
|
||||
$plugin->getSubscriptionSuccessMessage($sale)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($cargo);
|
||||
} catch (Exception $e) {
|
||||
$cargo = json_decode($e->getMessage(), true);
|
||||
$plugin->cancelSale($sale['id']);
|
||||
unset($_SESSION['bc_sale_id']);
|
||||
if (is_array($cargo)) {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf($plugin->get_lang('ErrorOccurred'), $cargo['codigo'], $cargo['mensaje']),
|
||||
'error',
|
||||
false
|
||||
)
|
||||
);
|
||||
} else {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
$plugin->get_lang('ErrorContactPlatformAdmin'),
|
||||
'error',
|
||||
false
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'culqi_cargo_service':
|
||||
if (!$culqiEnable) {
|
||||
break;
|
||||
}
|
||||
|
||||
$tokenId = $_REQUEST['token_id'];
|
||||
$serviceSaleId = $_REQUEST['service_sale_id'];
|
||||
|
||||
if (!$tokenId || !$serviceSaleId) {
|
||||
break;
|
||||
}
|
||||
|
||||
$serviceSale = $plugin->getServiceSale($serviceSaleId);
|
||||
|
||||
if (!$serviceSale) {
|
||||
break;
|
||||
}
|
||||
|
||||
require_once 'Requests.php';
|
||||
Requests::register_autoloader();
|
||||
require_once 'culqi.php';
|
||||
$culqiParams = $plugin->getCulqiParams();
|
||||
|
||||
// API Key y autenticación
|
||||
$SECRET_API_KEY = $culqiParams['api_key'];
|
||||
$culqi = new Culqi\Culqi(['api_key' => $SECRET_API_KEY]);
|
||||
|
||||
$environment = $culqiParams['integration'];
|
||||
$environment = $environment
|
||||
? BuyCoursesPlugin::CULQI_INTEGRATION_TYPE
|
||||
: BuyCoursesPlugin::CULQI_PRODUCTION_TYPE;
|
||||
|
||||
$culqi->setEnv($environment);
|
||||
$user = api_get_user_info();
|
||||
|
||||
try {
|
||||
$cargo = $culqi->Cargos->create([
|
||||
"moneda" => $serviceSale['currency'],
|
||||
"monto" => intval(floatval($serviceSale['price']) * 100),
|
||||
"usuario" => $user['username'],
|
||||
"descripcion" => $serviceSale['service']['name'],
|
||||
"pedido" => $serviceSale['reference'],
|
||||
"codigo_pais" => "PE",
|
||||
"direccion" => get_lang('None'),
|
||||
"ciudad" => get_lang('None'),
|
||||
"telefono" => 0,
|
||||
"nombres" => $user['firstname'],
|
||||
"apellidos" => $user['lastname'],
|
||||
"correo_electronico" => $user['email'],
|
||||
"token" => $tokenId,
|
||||
]);
|
||||
|
||||
if (is_object($cargo)) {
|
||||
$saleIsCompleted = $plugin->completeServiceSale($serviceSale['id']);
|
||||
if ($saleIsCompleted) {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf(
|
||||
$plugin->get_lang('SubscriptionToCourseXSuccessful'),
|
||||
$serviceSale['service']['name']
|
||||
),
|
||||
'success'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($cargo);
|
||||
} catch (Exception $e) {
|
||||
$cargo = json_decode($e->getMessage(), true);
|
||||
$plugin->cancelServiceSale($serviceSale['id']);
|
||||
|
||||
unset($_SESSION['bc_sale_id']);
|
||||
|
||||
if (is_array($cargo)) {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf($plugin->get_lang('ErrorOccurred'), $cargo['codigo'], $cargo['mensaje']),
|
||||
'error',
|
||||
false
|
||||
)
|
||||
);
|
||||
} else {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
$plugin->get_lang('ErrorContactPlatformAdmin'),
|
||||
'error',
|
||||
false
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'service_sale_info':
|
||||
$id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
|
||||
$serviceSale = $plugin->getServiceSale($id);
|
||||
$isAdmin = api_is_platform_admin();
|
||||
if (!$serviceSale) {
|
||||
break;
|
||||
}
|
||||
|
||||
$ajaxCallFile = $plugin->getPath('SRC').'buycourses.ajax.php';
|
||||
$serviceImg = $plugin->getPath('SERVICE_IMAGES').$serviceSale['service']['image'];
|
||||
$html = "<img class='img-responsive text-center' src='$serviceImg'>";
|
||||
$html .= "<br />";
|
||||
$html .= "<legend>{$plugin->get_lang('ServiceInformation')}</legend>";
|
||||
$html .= "<ul>";
|
||||
$html .= "<li><b>{$plugin->get_lang('ServiceName')}:</b> {$serviceSale['service']['name']}</li> ";
|
||||
$html .= "<li><b>{$plugin->get_lang('Description')}:</b> {$serviceSale['service']['description']}</li> ";
|
||||
$nodeType = $serviceSale['node_type'];
|
||||
$nodeName = '';
|
||||
if ($nodeType == BuyCoursesPlugin::SERVICE_TYPE_USER) {
|
||||
$nodeType = get_lang('User');
|
||||
/** @var User $user */
|
||||
$user = UserManager::getManager()->find($serviceSale['node_id']);
|
||||
$nodeName = $user ? $user->getCompleteNameWithUsername() : null;
|
||||
} else {
|
||||
if ($nodeType == BuyCoursesPlugin::SERVICE_TYPE_COURSE) {
|
||||
$nodeType = get_lang('Course');
|
||||
/** @var Course $course */
|
||||
$course = $em->find('ChamiloCoreBundle:Course', $serviceSale['node_id']);
|
||||
$nodeName = $course ? $course->getTitle() : null;
|
||||
} else {
|
||||
if ($nodeType == BuyCoursesPlugin::SERVICE_TYPE_SESSION) {
|
||||
$nodeType = get_lang('Session');
|
||||
/** @var Session $session */
|
||||
$session = $em->find('ChamiloCoreBundle:Session', $serviceSale['node_id']);
|
||||
$nodeName = $session ? $session->getName() : null;
|
||||
} else {
|
||||
if ($nodeType == BuyCoursesPlugin::SERVICE_TYPE_LP_FINAL_ITEM) {
|
||||
$nodeType = get_lang('TemplateTitleCertificate');
|
||||
/** @var CLp $lp */
|
||||
$lp = $em->find('ChamiloCourseBundle:CLp', $serviceSale['node_id']);
|
||||
$nodeName = $lp ? $lp->getName() : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$html .= "</ul>";
|
||||
$html .= "<legend>{$plugin->get_lang('SaleInfo')}</legend>";
|
||||
$html .= "<ul>";
|
||||
$html .= "<li><b>{$plugin->get_lang('BoughtBy')}:</b> {$serviceSale['buyer']['name']}</li> ";
|
||||
$html .= "<li><b>{$plugin->get_lang('PurchaserUser')}:</b> {$serviceSale['buyer']['username']}</li> ";
|
||||
$html .= "<li><b>{$plugin->get_lang('Total')}:</b> {$serviceSale['service']['total_price']}</li> ";
|
||||
$orderDate = api_format_date($serviceSale['buy_date'], DATE_FORMAT_LONG);
|
||||
$html .= "<li><b>{$plugin->get_lang('OrderDate')}:</b> $orderDate</li> ";
|
||||
$paymentType = $serviceSale['payment_type'];
|
||||
if ($paymentType == BuyCoursesPlugin::PAYMENT_TYPE_PAYPAL) {
|
||||
$paymentType = 'PayPal';
|
||||
} else {
|
||||
if ($paymentType == BuyCoursesPlugin::PAYMENT_TYPE_TRANSFER) {
|
||||
$paymentType = $plugin->get_lang('BankTransfer');
|
||||
} else {
|
||||
if ($paymentType == BuyCoursesPlugin::PAYMENT_TYPE_CULQI) {
|
||||
$paymentType = 'Culqi';
|
||||
}
|
||||
}
|
||||
}
|
||||
$html .= "<li><b>{$plugin->get_lang('PaymentMethod')}:</b> $paymentType</li> ";
|
||||
$status = $serviceSale['status'];
|
||||
$buttons = '';
|
||||
if ($status == BuyCoursesPlugin::SERVICE_STATUS_COMPLETED) {
|
||||
$status = $plugin->get_lang('Active');
|
||||
} else {
|
||||
if ($status == BuyCoursesPlugin::SERVICE_STATUS_PENDING) {
|
||||
$status = $plugin->get_lang('Pending');
|
||||
if ($isAdmin) {
|
||||
$buttons .= "<a id='{$serviceSale['id']}' tag='service_sale_confirm' class='btn btn-success pull-left'>{$plugin->get_lang('ConfirmOrder')}</a>";
|
||||
$buttons .= "<a id='{$serviceSale['id']}' tag='service_sale_cancel' class='btn btn-danger pull-right'>{$plugin->get_lang('CancelOrder')}</a>";
|
||||
}
|
||||
} else {
|
||||
if ($status == BuyCoursesPlugin::SERVICE_STATUS_CANCELLED) {
|
||||
$status = $plugin->get_lang('Cancelled');
|
||||
}
|
||||
}
|
||||
}
|
||||
$html .= "<li><b>{$plugin->get_lang('Status')}:</b> $status</li> ";
|
||||
$html .= "</ul>";
|
||||
$html .= "<br />";
|
||||
$html .= "<div class='row'>";
|
||||
$html .= "<div class='col-md-2'></div>";
|
||||
$html .= "<div class='col-md-8 text-center'>";
|
||||
$html .= "<div class='bc-action-buttons'>";
|
||||
$html .= $buttons;
|
||||
$html .= "</div>";
|
||||
$html .= "</div>";
|
||||
$html .= "<div class='col-md-2'></div>";
|
||||
$html .= "<script>";
|
||||
$html .= "$('.bc-action-buttons a').click(function() {";
|
||||
$html .= "var id = $(this).attr('id');";
|
||||
$html .= "var action = $(this).attr('tag');";
|
||||
$html .= "$.ajax({";
|
||||
$html .= "data: 'id='+id,";
|
||||
$html .= "url: '$ajaxCallFile?a='+action,";
|
||||
$html .= "type: 'POST',";
|
||||
$html .= "beforeSend: function() {";
|
||||
$processingLoaderText = $plugin->get_lang('ProcessingDontCloseThisWindow');
|
||||
$html .= "$('.bootbox-close-button').remove();";
|
||||
$html .= "$('.btn-default').attr('disabled', true);";
|
||||
$html .= "$('.bc-action-buttons').html('<div class=\"wobblebar-loader\"></div><p> $processingLoaderText</p>');";
|
||||
$html .= "},";
|
||||
$html .= "success: function(response) {";
|
||||
$html .= "$('.bc-action-buttons').html(response);";
|
||||
$html .= "},";
|
||||
$html .= "});";
|
||||
$html .= "});";
|
||||
$html .= "</script>";
|
||||
|
||||
echo $html;
|
||||
break;
|
||||
case 'service_sale_confirm':
|
||||
$id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
|
||||
$serviceSale = $plugin->getServiceSale($id);
|
||||
$response = $plugin->completeServiceSale($id);
|
||||
$html = "<div class='text-center'>";
|
||||
|
||||
if ($response) {
|
||||
$html .= Display::return_message(
|
||||
sprintf($plugin->get_lang('SubscriptionToServiceXSuccessful'), $serviceSale['service']['name']),
|
||||
'success'
|
||||
);
|
||||
} else {
|
||||
$html .= Display::return_message('Error - '.$plugin->get_lang('ErrorContactPlatformAdmin'), 'error');
|
||||
}
|
||||
|
||||
$html .= "<a id='finish-button' class='btn btn-primary'>".$plugin->get_lang('ClickHereToFinish')."</a>";
|
||||
$html .= "</div>";
|
||||
$html .= "<script>";
|
||||
$html .= "$('#finish-button').click(function() {";
|
||||
$html .= "location.reload();";
|
||||
$html .= "});";
|
||||
$html .= "</script>";
|
||||
echo $html;
|
||||
break;
|
||||
case 'service_sale_cancel':
|
||||
$id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
|
||||
$response = $plugin->cancelServiceSale($id);
|
||||
$html = '';
|
||||
$html .= "<div class='text-center'>";
|
||||
|
||||
if ($response) {
|
||||
$html .= Display::return_message(
|
||||
$plugin->get_lang('OrderCancelled'),
|
||||
'warning'
|
||||
);
|
||||
} else {
|
||||
$html .= Display::return_message('Error - '.$plugin->get_lang('ErrorContactPlatformAdmin'), 'error');
|
||||
}
|
||||
|
||||
$html .= "<a id='finish-button' class='btn btn-primary'>".$plugin->get_lang('ClickHereToFinish')."</a>";
|
||||
$html .= "</div>";
|
||||
$html .= "<script>";
|
||||
$html .= "$('#finish-button').click(function() {";
|
||||
$html .= "location.reload();";
|
||||
$html .= "});";
|
||||
$html .= "</script>";
|
||||
echo $html;
|
||||
break;
|
||||
}
|
||||
30
plugin/buycourses/src/cecabank_cancel.php
Normal file
30
plugin/buycourses/src/cecabank_cancel.php
Normal file
@@ -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();
|
||||
$cecabankEnabled = $plugin->get('cecabank_enable') === 'true';
|
||||
|
||||
if (!$cecabankEnabled) {
|
||||
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;
|
||||
53
plugin/buycourses/src/cecabank_response.php
Normal file
53
plugin/buycourses/src/cecabank_response.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?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();
|
||||
$cecabankEnabled = $plugin->get('cecabank_enable') === 'true';
|
||||
|
||||
if (!$cecabankEnabled) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$receivedAmount = (float) $_POST['Importe'];
|
||||
|
||||
if (empty($_POST['Num_operacion']) || empty($_POST['Firma']) || empty($receivedAmount)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$signature = $plugin->getCecabankSignature($_POST['Num_operacion'], $receivedAmount);
|
||||
|
||||
if ($signature != $_POST['Firma']) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$sale = $plugin->getSaleFromReference($_POST['Num_operacion']);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
$saleIsCompleted = $plugin->completeSale($sale['id']);
|
||||
if ($saleIsCompleted) {
|
||||
$plugin->storePayouts($sale['id']);
|
||||
}
|
||||
30
plugin/buycourses/src/cecabank_success.php
Normal file
30
plugin/buycourses/src/cecabank_success.php
Normal file
@@ -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();
|
||||
$cecabankEnabled = $plugin->get('cecabank_enable') === 'true';
|
||||
|
||||
if (!$cecabankEnabled) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$sale = $plugin->getSale($_SESSION['bc_sale_id']);
|
||||
|
||||
if (empty($sale)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
Display::addFlash(
|
||||
$plugin->getSubscriptionSuccessMessage($sale)
|
||||
);
|
||||
|
||||
unset($_SESSION['bc_sale_id']);
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/course_catalog.php');
|
||||
exit;
|
||||
204
plugin/buycourses/src/configure_coupon.php
Normal file
204
plugin/buycourses/src/configure_coupon.php
Normal file
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Configuration script for the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
require_once '../config.php';
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
$couponId = $_REQUEST['id'];
|
||||
|
||||
if (!isset($couponId)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
|
||||
$coupon = $plugin->getCouponInfo($couponId);
|
||||
|
||||
if (!isset($coupon)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
$couponDateRangeFrom = $coupon['valid_start'];
|
||||
$couponDateRangeTo = $coupon['valid_end'];
|
||||
|
||||
$includeSession = $plugin->get('include_sessions') === 'true';
|
||||
$includeServices = $plugin->get('include_services') === 'true';
|
||||
|
||||
$entityManager = Database::getManager();
|
||||
$userRepo = UserManager::getRepository();
|
||||
$currency = $plugin->getSelectedCurrency();
|
||||
|
||||
if (empty($currency)) {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('CurrencyIsNotConfigured'), 'error')
|
||||
);
|
||||
}
|
||||
|
||||
$currencyIso = null;
|
||||
|
||||
$coursesList = CourseManager::get_courses_list(
|
||||
0,
|
||||
0,
|
||||
'title',
|
||||
'asc',
|
||||
-1,
|
||||
null,
|
||||
api_get_current_access_url_id(),
|
||||
false,
|
||||
[],
|
||||
[]
|
||||
);
|
||||
|
||||
foreach ($coursesList as $course) {
|
||||
$courses[$course['id']] = $course['title'];
|
||||
}
|
||||
|
||||
$sessionsList = SessionManager::get_sessions_list(
|
||||
[],
|
||||
[],
|
||||
null,
|
||||
null,
|
||||
api_get_current_access_url_id(),
|
||||
[]
|
||||
);
|
||||
|
||||
foreach ($sessionsList as $session) {
|
||||
$sessions[$session['id']] = $session['name'];
|
||||
}
|
||||
|
||||
$servicesList = $plugin->getAllServices();
|
||||
|
||||
foreach ($servicesList as $service) {
|
||||
$services[$service['id']] = $service['name'];
|
||||
}
|
||||
|
||||
$discountTypes = $plugin->getCouponDiscountTypes();
|
||||
|
||||
// Build the form
|
||||
$form = new FormValidator('add_coupon');
|
||||
$form->addText('code', $plugin->get_lang('CouponCode'), false);
|
||||
$form->addText('discount_type', $plugin->get_lang('CouponDiscountType'), false);
|
||||
$form->addText('discount_amount', $plugin->get_lang('CouponDiscount'), false);
|
||||
$form->addDateRangePicker(
|
||||
'date',
|
||||
get_lang('Date'),
|
||||
true,
|
||||
[
|
||||
'value' => "$couponDateRangeFrom / $couponDateRangeTo",
|
||||
]
|
||||
);
|
||||
|
||||
$form->addCheckBox('active', $plugin->get_lang('CouponActive'));
|
||||
$form->addElement(
|
||||
'advmultiselect',
|
||||
'courses',
|
||||
get_lang('Courses'),
|
||||
$courses
|
||||
);
|
||||
|
||||
if ($includeSession) {
|
||||
$form->addElement(
|
||||
'advmultiselect',
|
||||
'sessions',
|
||||
get_lang('Sessions'),
|
||||
$sessions
|
||||
);
|
||||
}
|
||||
|
||||
if ($includeServices) {
|
||||
$form->addElement(
|
||||
'advmultiselect',
|
||||
'services',
|
||||
get_lang('Services'),
|
||||
$services
|
||||
);
|
||||
}
|
||||
|
||||
$form->addHidden('id', null);
|
||||
|
||||
$coursesAdded = $coupon["courses"];
|
||||
if (!empty($coursesAdded)) {
|
||||
$coursesAdded = array_column($coursesAdded, 'id');
|
||||
}
|
||||
|
||||
$sessionsAdded = $coupon["sessions"];
|
||||
if (!empty($sessionsAdded)) {
|
||||
$sessionsAdded = array_column($sessionsAdded, 'id');
|
||||
}
|
||||
|
||||
$servicesAdded = $coupon["services"];
|
||||
if (!empty($servicesAdded)) {
|
||||
$servicesAdded = array_column($servicesAdded, 'id');
|
||||
}
|
||||
|
||||
$formDefaults = [
|
||||
'id' => $coupon['id'],
|
||||
'code' => $coupon['code'],
|
||||
'discount_type' => $discountTypes[$coupon['discount_type']],
|
||||
'discount_amount' => $coupon['discount_amount'],
|
||||
'date' => "$couponDateRangeFrom / $couponDateRangeTo",
|
||||
'active' => $coupon['active'],
|
||||
'courses' => $coursesAdded,
|
||||
'sessions' => $sessionsAdded,
|
||||
'services' => $servicesAdded,
|
||||
];
|
||||
|
||||
$button = $form->addButtonSave(get_lang('Save'));
|
||||
if (empty($currency)) {
|
||||
$button->setAttribute('disabled');
|
||||
}
|
||||
|
||||
$form->freeze(['code', 'discount_type', 'discount_amount']);
|
||||
|
||||
if ($form->validate()) {
|
||||
$formValues = $form->exportValues();
|
||||
|
||||
$coupon['id'] = $formValues['id'];
|
||||
$coupon['valid_start'] = $formValues['date_start'];
|
||||
$coupon['valid_end'] = $formValues['date_end'];
|
||||
$coupon['active'] = $formValues['active'];
|
||||
$coupon['courses'] = isset($formValues['courses']) ? $formValues['courses'] : [];
|
||||
$coupon['sessions'] = isset($formValues['sessions']) ? $formValues['sessions'] : [];
|
||||
$coupon['services'] = isset($formValues['services']) ? $formValues['services'] : [];
|
||||
|
||||
$result = $plugin->updateCouponData($coupon);
|
||||
|
||||
if ($result) {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
$plugin->get_lang('CouponUpdate'),
|
||||
'success',
|
||||
false
|
||||
)
|
||||
);
|
||||
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/configure_coupon.php?id='.$coupon["id"]);
|
||||
} else {
|
||||
header('Location:'.api_get_self().'?'.$queryString);
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$form->setDefaults($formDefaults);
|
||||
|
||||
$templateName = $plugin->get_lang('ConfigureCoupon');
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'paymentsetup.php',
|
||||
'name' => get_lang('Configuration'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'coupons.php',
|
||||
'name' => $plugin->get_lang('CouponList'),
|
||||
];
|
||||
|
||||
$template = new Template($templateName);
|
||||
$template->assign('header', $templateName);
|
||||
$template->assign('content', $form->returnForm());
|
||||
$template->display_one_col_template();
|
||||
363
plugin/buycourses/src/configure_course.php
Normal file
363
plugin/buycourses/src/configure_course.php
Normal file
@@ -0,0 +1,363 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Configuration script for the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once '../config.php';
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
$id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
|
||||
$type = isset($_REQUEST['type']) ? (int) $_REQUEST['type'] : 0;
|
||||
|
||||
if (empty($id) || empty($type)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$commissionsEnable = $plugin->get('commissions_enable');
|
||||
|
||||
if ($commissionsEnable == 'true') {
|
||||
$htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_PLUGIN_PATH)
|
||||
.'buycourses/resources/js/commissions.js"></script>';
|
||||
$commissions = '';
|
||||
}
|
||||
|
||||
$includeSession = $plugin->get('include_sessions') === 'true';
|
||||
$editingCourse = $type === BuyCoursesPlugin::PRODUCT_TYPE_COURSE;
|
||||
$editingSession = $type === BuyCoursesPlugin::PRODUCT_TYPE_SESSION;
|
||||
|
||||
$entityManager = Database::getManager();
|
||||
$userRepo = UserManager::getRepository();
|
||||
$currency = $plugin->getSelectedCurrency();
|
||||
|
||||
if (empty($currency)) {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('CurrencyIsNotConfigured'), 'error')
|
||||
);
|
||||
$currency = null;
|
||||
}
|
||||
|
||||
$currencyIso = null;
|
||||
|
||||
if ($editingCourse) {
|
||||
$course = $entityManager->find('ChamiloCoreBundle:Course', $id);
|
||||
|
||||
if (!$course) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
/*if (!$plugin->isValidCourse($course)) {
|
||||
api_not_allowed(true);
|
||||
}*/
|
||||
|
||||
$courseItem = $plugin->getCourseForConfiguration($course, $currency);
|
||||
$defaultBeneficiaries = [];
|
||||
$teachers = $course->getTeachers();
|
||||
$teachersOptions = [];
|
||||
|
||||
foreach ($teachers as $courseTeacher) {
|
||||
$teacher = $courseTeacher->getUser();
|
||||
$teachersOptions[] = [
|
||||
'text' => $teacher->getCompleteName(),
|
||||
'value' => $teacher->getId(),
|
||||
];
|
||||
$defaultBeneficiaries[] = $teacher->getId();
|
||||
}
|
||||
|
||||
if (!empty($courseItem['item_id'])) {
|
||||
$currentBeneficiaries = $plugin->getItemBeneficiaries($courseItem['course_id']);
|
||||
if (!empty($currentBeneficiaries)) {
|
||||
$defaultBeneficiaries = array_column($currentBeneficiaries, 'user_id');
|
||||
if ($commissionsEnable === 'true') {
|
||||
$defaultCommissions = array_column($currentBeneficiaries, 'commissions');
|
||||
foreach ($defaultCommissions as $defaultCommission) {
|
||||
$commissions .= $defaultCommission.',';
|
||||
}
|
||||
$commissions = substr($commissions, 0, -1);
|
||||
}
|
||||
}
|
||||
|
||||
$currencyIso = $courseItem['currency'];
|
||||
$formDefaults = [
|
||||
'product_type' => get_lang('Course'),
|
||||
'id' => $courseItem['course_id'],
|
||||
'type' => BuyCoursesPlugin::PRODUCT_TYPE_COURSE,
|
||||
'name' => $courseItem['course_title'],
|
||||
'visible' => $courseItem['visible'],
|
||||
'price' => $courseItem['price'],
|
||||
'tax_perc' => $courseItem['tax_perc'],
|
||||
'beneficiaries' => $defaultBeneficiaries,
|
||||
$commissionsEnable == 'true' ? 'commissions' : '' => $commissionsEnable == 'true' ? $commissions : '',
|
||||
];
|
||||
} else {
|
||||
$formDefaults = [
|
||||
'product_type' => get_lang('Course'),
|
||||
'id' => $courseItem['course_id'],
|
||||
'type' => BuyCoursesPlugin::PRODUCT_TYPE_COURSE,
|
||||
'name' => $courseItem['course_title'],
|
||||
'visible' => false,
|
||||
'price' => 0,
|
||||
'tax_perc' => 0,
|
||||
'beneficiaries' => [],
|
||||
$commissionsEnable == 'true' ? 'commissions' : '' => $commissionsEnable == 'true' ? '' : '',
|
||||
];
|
||||
}
|
||||
} elseif ($editingSession) {
|
||||
if (!$includeSession) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$session = $entityManager->find('ChamiloCoreBundle:Session', $id);
|
||||
if (!$session) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$sessionItem = $plugin->getSessionForConfiguration($session, $currency);
|
||||
$generalCoach = $session->getGeneralCoach();
|
||||
$generalCoachOption = [
|
||||
'text' => $generalCoach->getCompleteName(),
|
||||
'value' => $generalCoach->getId(),
|
||||
];
|
||||
$defaultBeneficiaries = [
|
||||
$generalCoach->getId(),
|
||||
];
|
||||
$courseCoachesOptions = [];
|
||||
$sessionCourses = $session->getCourses();
|
||||
|
||||
foreach ($sessionCourses as $sessionCourse) {
|
||||
$courseCoaches = $userRepo->getCoachesForSessionCourse($session, $sessionCourse->getCourse());
|
||||
|
||||
foreach ($courseCoaches as $courseCoach) {
|
||||
if ($generalCoach->getId() === $courseCoach->getId()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$courseCoachesOptions[] = [
|
||||
'text' => $courseCoach->getCompleteName(),
|
||||
'value' => $courseCoach->getId(),
|
||||
];
|
||||
$defaultBeneficiaries[] = $courseCoach->getId();
|
||||
}
|
||||
}
|
||||
|
||||
if ($sessionItem['item_id']) {
|
||||
$currentBeneficiaries = $plugin->getItemBeneficiaries($sessionItem['item_id']);
|
||||
}
|
||||
|
||||
if (!empty($currentBeneficiaries)) {
|
||||
$defaultBeneficiaries = array_column($currentBeneficiaries, 'user_id');
|
||||
|
||||
if ($commissionsEnable == 'true') {
|
||||
$defaultCommissions = array_column($currentBeneficiaries, 'commissions');
|
||||
|
||||
foreach ($defaultCommissions as $defaultCommission) {
|
||||
$commissions .= $defaultCommission.',';
|
||||
}
|
||||
|
||||
$commissions = substr($commissions, 0, -1);
|
||||
}
|
||||
}
|
||||
|
||||
$currencyIso = $sessionItem['currency'];
|
||||
$formDefaults = [
|
||||
'product_type' => get_lang('Session'),
|
||||
'id' => $session->getId(),
|
||||
'type' => BuyCoursesPlugin::PRODUCT_TYPE_SESSION,
|
||||
'name' => $sessionItem['session_name'],
|
||||
'visible' => $sessionItem['visible'],
|
||||
'price' => $sessionItem['price'],
|
||||
'tax_perc' => $sessionItem['tax_perc'],
|
||||
'beneficiaries' => $defaultBeneficiaries,
|
||||
$commissionsEnable == 'true' ? 'commissions' : '' => $commissionsEnable == 'true' ? $commissions : '',
|
||||
];
|
||||
} else {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
if ($commissionsEnable === 'true') {
|
||||
$htmlHeadXtra[] = "
|
||||
<script>
|
||||
$(function() {
|
||||
if ($('[name=\"commissions\"]').val() === '') {
|
||||
$('#panelSliders').html(
|
||||
'<button id=\"setCommissionsButton\" class=\"btn btn-warning\">'
|
||||
+ '".get_plugin_lang('SetCommissions', 'BuyCoursesPlugin')."'
|
||||
);
|
||||
} else {
|
||||
showSliders(100, 'default', '".$commissions."');
|
||||
}
|
||||
|
||||
var maxPercentage = 100;
|
||||
$('#selectBox').on('change', function() {
|
||||
$('#panelSliders').html('');
|
||||
});
|
||||
|
||||
$('#setCommissionsButton').on('click', function() {
|
||||
$('#panelSliders').html('');
|
||||
showSliders(maxPercentage, 'renew');
|
||||
});
|
||||
});
|
||||
</script>
|
||||
";
|
||||
}
|
||||
|
||||
$globalSettingsParams = $plugin->getGlobalParameters();
|
||||
|
||||
$form = new FormValidator('beneficiaries');
|
||||
$form->addText('product_type', $plugin->get_lang('ProductType'), false);
|
||||
$form->addText('name', get_lang('Name'), false);
|
||||
$form->addCheckBox(
|
||||
'visible',
|
||||
$plugin->get_lang('VisibleInCatalog'),
|
||||
$plugin->get_lang('ShowOnCourseCatalog')
|
||||
);
|
||||
$form->addElement(
|
||||
'number',
|
||||
'price',
|
||||
[$plugin->get_lang('Price'), null, $currencyIso],
|
||||
['step' => 0.01]
|
||||
);
|
||||
$form->addElement(
|
||||
'number',
|
||||
'tax_perc',
|
||||
[$plugin->get_lang('TaxPerc'), $plugin->get_lang('TaxPercDescription'), '%'],
|
||||
['step' => 1, 'placeholder' => $globalSettingsParams['global_tax_perc'].'% '.$plugin->get_lang('ByDefault')]
|
||||
);
|
||||
$beneficiariesSelect = $form->addSelect(
|
||||
'beneficiaries',
|
||||
$plugin->get_lang('Beneficiaries'),
|
||||
null,
|
||||
['multiple' => 'multiple', 'id' => 'selectBox']
|
||||
);
|
||||
|
||||
if ($editingCourse) {
|
||||
$teachersOptions = api_unique_multidim_array($teachersOptions, 'value');
|
||||
$beneficiariesSelect->addOptGroup($teachersOptions, get_lang('Teachers'));
|
||||
} elseif ($editingSession) {
|
||||
$courseCoachesOptions = api_unique_multidim_array($courseCoachesOptions, 'value');
|
||||
$beneficiariesSelect->addOptGroup([$generalCoachOption], get_lang('SessionGeneralCoach'));
|
||||
$beneficiariesSelect->addOptGroup($courseCoachesOptions, get_lang('SessionCourseCoach'));
|
||||
}
|
||||
|
||||
if ($commissionsEnable === 'true') {
|
||||
$platformCommission = $plugin->getPlatformCommission();
|
||||
$form->addHtml(
|
||||
'
|
||||
<div class="form-group">
|
||||
<label for="sliders" class="col-sm-2 control-label">
|
||||
'.get_plugin_lang('Commissions', 'BuyCoursesPlugin').'
|
||||
</label>
|
||||
<div class="col-sm-8">
|
||||
'.Display::return_message(
|
||||
sprintf($plugin->get_lang('TheActualPlatformCommissionIsX'), $platformCommission['commission'].'%'),
|
||||
'info',
|
||||
false
|
||||
).'
|
||||
<div id="panelSliders"></div>
|
||||
</div>
|
||||
</div>'
|
||||
);
|
||||
$form->addHidden('commissions', '');
|
||||
}
|
||||
|
||||
$form->addHidden('type', null);
|
||||
$form->addHidden('id', null);
|
||||
$button = $form->addButtonSave(get_lang('Save'));
|
||||
|
||||
if (empty($currency)) {
|
||||
$button->setAttribute('disabled');
|
||||
}
|
||||
|
||||
$form->freeze(['product_type', 'name']);
|
||||
|
||||
if ($form->validate()) {
|
||||
$formValues = $form->exportValues();
|
||||
$id = $formValues['id'];
|
||||
$type = $formValues['type'];
|
||||
|
||||
$productItem = $plugin->getItemByProduct($id, $type);
|
||||
if (isset($formValues['visible'])) {
|
||||
$taxPerc = $formValues['tax_perc'] != '' ? (int) $formValues['tax_perc'] : null;
|
||||
if (!empty($productItem)) {
|
||||
$plugin->updateItem(
|
||||
[
|
||||
'price' => floatval($formValues['price']),
|
||||
'tax_perc' => $taxPerc,
|
||||
],
|
||||
$id,
|
||||
$type
|
||||
);
|
||||
} else {
|
||||
$itemId = $plugin->registerItem([
|
||||
'currency_id' => (int) $currency['id'],
|
||||
'product_type' => $type,
|
||||
'product_id' => $id,
|
||||
'price' => floatval($_POST['price']),
|
||||
'tax_perc' => $taxPerc,
|
||||
]);
|
||||
$productItem['id'] = $itemId;
|
||||
}
|
||||
|
||||
$plugin->deleteItemBeneficiaries($productItem['id']);
|
||||
|
||||
if (isset($formValues['beneficiaries'])) {
|
||||
if ($commissionsEnable === 'true') {
|
||||
$usersId = $formValues['beneficiaries'];
|
||||
$commissions = explode(',', $formValues['commissions']);
|
||||
$commissions = (count($usersId) != count($commissions))
|
||||
? array_fill(0, count($usersId), 0)
|
||||
: $commissions;
|
||||
$beneficiaries = array_combine($usersId, $commissions);
|
||||
} else {
|
||||
$usersId = $formValues['beneficiaries'];
|
||||
$commissions = array_fill(0, count($usersId), 0);
|
||||
$beneficiaries = array_combine($usersId, $commissions);
|
||||
}
|
||||
$plugin->registerItemBeneficiaries($productItem['id'], $beneficiaries);
|
||||
}
|
||||
} else {
|
||||
if (!empty($productItem['id'])) {
|
||||
$plugin->deleteItem($productItem['id']);
|
||||
}
|
||||
}
|
||||
$url = 'list.php';
|
||||
if ($type == 2) {
|
||||
$url = 'list_session.php';
|
||||
}
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/'.$url);
|
||||
exit;
|
||||
}
|
||||
|
||||
$form->setDefaults($formDefaults);
|
||||
|
||||
$templateName = '';
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'paymentsetup.php',
|
||||
'name' => get_lang('Configuration'),
|
||||
];
|
||||
switch ($type) {
|
||||
case 2:
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'list_session.php',
|
||||
'name' => $plugin->get_lang('Sessions'),
|
||||
];
|
||||
$templateName = $plugin->get_lang('Sessions');
|
||||
break;
|
||||
default:
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'list.php',
|
||||
'name' => $plugin->get_lang('AvailableCourses'),
|
||||
];
|
||||
$templateName = $plugin->get_lang('AvailableCourse');
|
||||
}
|
||||
|
||||
$template = new Template($templateName);
|
||||
$template->assign('header', $templateName);
|
||||
$template->assign('content', $form->returnForm());
|
||||
$template->display_one_col_template();
|
||||
119
plugin/buycourses/src/configure_frequency.php
Normal file
119
plugin/buycourses/src/configure_frequency.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Configuration page for subscriptions for the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
|
||||
api_protect_admin_script(true);
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
|
||||
if (isset($_GET['action'], $_GET['d'], $_GET['n'])) {
|
||||
if ($_GET['action'] == 'delete_frequency') {
|
||||
if (is_numeric($_GET['d'])) {
|
||||
$frequency = $plugin->selectFrequency($_GET['d']);
|
||||
|
||||
if (!empty($frequency)) {
|
||||
$subscriptionsItems = $plugin->getSubscriptionsItemsByDuration($_GET['d']);
|
||||
|
||||
if (empty($subscriptionsItems)) {
|
||||
$plugin->deleteFrequency($_GET['d']);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('FrequencyRemoved'), 'success')
|
||||
);
|
||||
} else {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('SubscriptionPeriodOnUse'), 'error')
|
||||
);
|
||||
}
|
||||
} else {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('FrequencyNotExits'), 'error')
|
||||
);
|
||||
}
|
||||
} else {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('FrequencyIncorrect'), 'error')
|
||||
);
|
||||
}
|
||||
|
||||
header('Location: '.api_get_self());
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$frequencies = $plugin->getFrequenciesList();
|
||||
|
||||
$globalSettingsParams = $plugin->getGlobalParameters();
|
||||
|
||||
$form = new FormValidator('add_frequency');
|
||||
|
||||
$form->addText('name', get_lang('Name'), false);
|
||||
|
||||
$form->addElement(
|
||||
'number',
|
||||
'duration',
|
||||
[$plugin->get_lang('Duration'), $plugin->get_lang('Days')],
|
||||
['step' => 1, 'placeholder' => $plugin->get_lang('SubscriptionFrequencyValueDays')]
|
||||
);
|
||||
|
||||
$button = $form->addButtonSave(get_lang('Save'));
|
||||
|
||||
if ($form->validate()) {
|
||||
$formValues = $form->getSubmitValues();
|
||||
$duration = $formValues['duration'];
|
||||
$name = $formValues['name'];
|
||||
|
||||
$frequency = $plugin->selectFrequency($duration);
|
||||
|
||||
if (!empty($frequency)) {
|
||||
$result = $plugin->updateFrequency($duration, $name);
|
||||
|
||||
if (!isset($result)) {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('FrequencyNotUpdated'), 'error')
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$result = $plugin->addFrequency($duration, $name);
|
||||
|
||||
if (!isset($result)) {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('FrequencyNotSaved'), 'error')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/configure_frequency.php');
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
//$form->setDefaults($formDefaults);
|
||||
|
||||
$templateName = $plugin->get_lang('FrequencyAdd');
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'subscriptions_courses.php',
|
||||
'name' => get_lang('Configuration'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'subscriptions_courses.php',
|
||||
'name' => $plugin->get_lang('SubscriptionList'),
|
||||
];
|
||||
|
||||
$template = new Template($templateName);
|
||||
$template->assign('header', $templateName);
|
||||
$template->assign('items_form', $form->returnForm());
|
||||
$template->assign('frequencies_list', $frequencies);
|
||||
|
||||
$content = $template->fetch('buycourses/view/configure_frequency.tpl');
|
||||
$template->assign('content', $content);
|
||||
|
||||
$template->display_one_col_template();
|
||||
246
plugin/buycourses/src/configure_subscription.php
Normal file
246
plugin/buycourses/src/configure_subscription.php
Normal file
@@ -0,0 +1,246 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Configuration page for subscriptions for the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
|
||||
api_protect_admin_script(true);
|
||||
|
||||
$id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
|
||||
$type = isset($_REQUEST['type']) ? (int) $_REQUEST['type'] : 0;
|
||||
|
||||
if (!isset($id) || !isset($type)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
$queryString = 'id='.intval($_REQUEST['id']).'&type='.intval($_REQUEST['type']);
|
||||
|
||||
$editingCourse = $type === BuyCoursesPlugin::PRODUCT_TYPE_COURSE;
|
||||
$editingSession = $type === BuyCoursesPlugin::PRODUCT_TYPE_SESSION;
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
|
||||
$includeSession = $plugin->get('include_sessions') === 'true';
|
||||
|
||||
if (isset($_GET['action'], $_GET['d'])) {
|
||||
if ($_GET['action'] == 'delete_frequency') {
|
||||
$plugin->deleteSubscription($type, $id, $_GET['d']);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('ItemRemoved'), 'success')
|
||||
);
|
||||
|
||||
header('Location: '.api_get_self().'?'.$queryString);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$entityManager = Database::getManager();
|
||||
$userRepo = UserManager::getRepository();
|
||||
$currency = $plugin->getSelectedCurrency();
|
||||
|
||||
if (empty($currency)) {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('CurrencyIsNotConfigured'), 'error')
|
||||
);
|
||||
}
|
||||
|
||||
$subscriptions = $plugin->getSubscriptions($type, $id);
|
||||
|
||||
$taxtPerc = 0;
|
||||
|
||||
if (isset($subscriptions) && !empty($subscriptions)) {
|
||||
$taxtPerc = $subscriptions[0]['tax_perc'];
|
||||
}
|
||||
|
||||
$currencyIso = null;
|
||||
|
||||
if ($editingCourse) {
|
||||
$course = $entityManager->find('ChamiloCoreBundle:Course', $id);
|
||||
if (!$course) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$courseItem = $plugin->getCourseForConfiguration($course, $currency);
|
||||
|
||||
$currencyIso = $courseItem['currency'];
|
||||
$formDefaults = [
|
||||
'product_type' => get_lang('Course'),
|
||||
'id' => $courseItem['course_id'],
|
||||
'type' => BuyCoursesPlugin::PRODUCT_TYPE_COURSE,
|
||||
'name' => $courseItem['course_title'],
|
||||
'visible' => $courseItem['visible'],
|
||||
'tax_perc' => $taxtPerc,
|
||||
];
|
||||
} elseif ($editingSession) {
|
||||
if (!$includeSession) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$session = $entityManager->find('ChamiloCoreBundle:Session', $id);
|
||||
if (!$session) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$sessionItem = $plugin->getSessionForConfiguration($session, $currency);
|
||||
|
||||
$currencyIso = $sessionItem['currency'];
|
||||
$formDefaults = [
|
||||
'product_type' => get_lang('Session'),
|
||||
'id' => $session->getId(),
|
||||
'type' => BuyCoursesPlugin::PRODUCT_TYPE_SESSION,
|
||||
'name' => $sessionItem['session_name'],
|
||||
'visible' => $sessionItem['visible'],
|
||||
'tax_perc' => $taxtPerc,
|
||||
];
|
||||
} else {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$globalSettingsParams = $plugin->getGlobalParameters();
|
||||
|
||||
$form = new FormValidator('add_subscription');
|
||||
|
||||
$form->addText('product_type', $plugin->get_lang('ProductType'), false);
|
||||
$form->addText('name', get_lang('Name'), false);
|
||||
|
||||
$form->freeze(['product_type', 'name']);
|
||||
|
||||
$form->addElement(
|
||||
'number',
|
||||
'tax_perc',
|
||||
[$plugin->get_lang('TaxPerc'), $plugin->get_lang('TaxPercDescription'), '%'],
|
||||
['step' => 1, 'placeholder' => $globalSettingsParams['global_tax_perc'].'% '.$plugin->get_lang('ByDefault')]
|
||||
);
|
||||
|
||||
$frequenciesOptions = $plugin->getFrequencies();
|
||||
|
||||
$frequencyForm = new FormValidator('frequency_config', 'post', api_get_self().'?'.$queryString);
|
||||
|
||||
$frequencyFormDefaults = [
|
||||
'id' => $id,
|
||||
'type' => $type,
|
||||
'tax_perc' => $taxtPerc,
|
||||
'currency_id' => $currency['id'],
|
||||
];
|
||||
|
||||
$frequencyForm->setDefaults($frequencyFormDefaults);
|
||||
|
||||
if ($frequencyForm->validate()) {
|
||||
$frequencyFormValues = $frequencyForm->getSubmitValues();
|
||||
|
||||
$subscription['product_id'] = $frequencyFormValues['id'];
|
||||
$subscription['product_type'] = $frequencyFormValues['type'];
|
||||
$subscription['tax_perc'] = $frequencyFormValues['tax_perc'] != '' ? (int) $frequencyFormValues['tax_perc'] : null;
|
||||
$subscription['currency_id'] = $currency['id'];
|
||||
$duration = $frequencyFormValues['duration'];
|
||||
$price = $frequencyFormValues['price'];
|
||||
|
||||
for ($i = 0; $i <= count($subscriptions); $i++) {
|
||||
if ($subscriptions[$i]['duration'] == $duration) {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('SubscriptionAlreadyExists'), 'error')
|
||||
);
|
||||
|
||||
header('Location:'.api_get_self().'?'.$queryString);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$subscription['frequencies'] = [['duration' => $duration, 'price' => $price]];
|
||||
|
||||
$result = $plugin->addNewSubscription($subscription);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('Saved'), 'success')
|
||||
);
|
||||
|
||||
header('Location:'.api_get_self().'?'.$queryString);
|
||||
exit;
|
||||
}
|
||||
|
||||
$frequencyForm->addElement(
|
||||
'select',
|
||||
'duration',
|
||||
$plugin->get_lang('Duration'),
|
||||
$frequenciesOptions,
|
||||
['cols-size' => [2, 8, 2]]
|
||||
);
|
||||
|
||||
$frequencyForm->addElement(
|
||||
'number',
|
||||
'price',
|
||||
[$plugin->get_lang('Price'), null, $currencyIso],
|
||||
false,
|
||||
[
|
||||
'step' => 1,
|
||||
'cols-size' => [3, 8, 1],
|
||||
]
|
||||
);
|
||||
|
||||
$frequencyForm->addHidden('type', $type);
|
||||
$frequencyForm->addHidden('id', $id);
|
||||
$frequencyForm->addHidden('tax_perc', $taxtPerc);
|
||||
$frequencyForm->addHidden('currency_id', $currency['id']);
|
||||
$frequencyForm->addButtonCreate('Add');
|
||||
|
||||
for ($i = 0; $i < count($subscriptions); $i++) {
|
||||
if ($subscriptions[$i]['duration'] > 0) {
|
||||
$subscriptions[$i]['durationName'] = $frequenciesOptions[$subscriptions[$i]['duration']];
|
||||
}
|
||||
}
|
||||
|
||||
$form->addHidden('type', $type);
|
||||
$form->addHidden('id', $id);
|
||||
$button = $form->addButtonSave(get_lang('Save'));
|
||||
|
||||
if (empty($currency)) {
|
||||
$button->setAttribute('disabled');
|
||||
}
|
||||
|
||||
if ($form->validate()) {
|
||||
$formValues = $form->getSubmitValues();
|
||||
$id = $formValues['id'];
|
||||
$type = $formValues['type'];
|
||||
$taxPerc = $formValues['tax_perc'] != '' ? (int) $formValues['tax_perc'] : null;
|
||||
|
||||
$result = $plugin->updateSubscriptions($type, $id, $taxPerc);
|
||||
|
||||
if ($result) {
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/subscriptions_courses.php');
|
||||
} else {
|
||||
header('Location:'.api_get_self().'?'.$queryString);
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$form->setDefaults($formDefaults);
|
||||
|
||||
$templateName = $plugin->get_lang('SubscriptionAdd');
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'subscriptions_courses.php',
|
||||
'name' => get_lang('Configuration'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'subscriptions_courses.php',
|
||||
'name' => $plugin->get_lang('SubscriptionList'),
|
||||
];
|
||||
|
||||
$template = new Template($templateName);
|
||||
$template->assign('header', $templateName);
|
||||
$template->assign('items_form', $form->returnForm());
|
||||
$template->assign('frequency_form', $frequencyForm->returnForm());
|
||||
$template->assign('subscriptions', $subscriptions);
|
||||
$template->assign('currencyIso', $currencyIso);
|
||||
|
||||
$content = $template->fetch('buycourses/view/configure_subscription.tpl');
|
||||
$template->assign('content', $content);
|
||||
|
||||
$template->display_one_col_template();
|
||||
167
plugin/buycourses/src/coupon_add.php
Normal file
167
plugin/buycourses/src/coupon_add.php
Normal file
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Configuration script for the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
require_once '../config.php';
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
|
||||
$includeSession = $plugin->get('include_sessions') === 'true';
|
||||
$includeServices = $plugin->get('include_services') === 'true';
|
||||
|
||||
$entityManager = Database::getManager();
|
||||
$userRepo = UserManager::getRepository();
|
||||
$currency = $plugin->getSelectedCurrency();
|
||||
|
||||
if (empty($currency)) {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('CurrencyIsNotConfigured'), 'error')
|
||||
);
|
||||
}
|
||||
|
||||
$currencyIso = null;
|
||||
|
||||
$coursesList = CourseManager::get_courses_list(
|
||||
0,
|
||||
0,
|
||||
'title',
|
||||
'asc',
|
||||
-1,
|
||||
null,
|
||||
api_get_current_access_url_id(),
|
||||
false,
|
||||
[],
|
||||
[]
|
||||
);
|
||||
|
||||
foreach ($coursesList as $course) {
|
||||
$courses[$course['id']] = $course['title'];
|
||||
}
|
||||
|
||||
$sessionsList = SessionManager::get_sessions_list(
|
||||
[],
|
||||
[],
|
||||
null,
|
||||
null,
|
||||
api_get_current_access_url_id(),
|
||||
[]
|
||||
);
|
||||
|
||||
foreach ($sessionsList as $session) {
|
||||
$sessions[$session['id']] = $session['name'];
|
||||
}
|
||||
|
||||
$servicesList = $plugin->getAllServices();
|
||||
|
||||
foreach ($servicesList as $service) {
|
||||
$services[$service['id']] = $service['name'];
|
||||
}
|
||||
|
||||
$discountTypes = $plugin->getCouponDiscountTypes();
|
||||
|
||||
// Build the form
|
||||
$form = new FormValidator('add_coupon');
|
||||
$form->addText('code', $plugin->get_lang('CouponCode'), true);
|
||||
$form->addRadio('discount_type', $plugin->get_lang('CouponDiscountType'), $discountTypes);
|
||||
$form->addElement(
|
||||
'number',
|
||||
'discount_amount',
|
||||
[$plugin->get_lang('CouponDiscount'), null, $currencyIso],
|
||||
['step' => 1]
|
||||
);
|
||||
$form->addDateRangePicker('date', get_lang('Date'), true);
|
||||
$form->addCheckBox('active', get_lang('Active'));
|
||||
$form->addElement(
|
||||
'advmultiselect',
|
||||
'courses',
|
||||
get_lang('Courses'),
|
||||
$courses
|
||||
);
|
||||
|
||||
if ($includeSession) {
|
||||
$form->addElement(
|
||||
'advmultiselect',
|
||||
'sessions',
|
||||
get_lang('Sessions'),
|
||||
$sessions
|
||||
);
|
||||
}
|
||||
|
||||
if ($includeServices) {
|
||||
$form->addElement(
|
||||
'advmultiselect',
|
||||
'services',
|
||||
get_lang('Services'),
|
||||
$services
|
||||
);
|
||||
}
|
||||
|
||||
$button = $form->addButtonSave(get_lang('Save'));
|
||||
|
||||
if (empty($currency)) {
|
||||
$button->setAttribute('disabled');
|
||||
}
|
||||
|
||||
if ($form->validate()) {
|
||||
$formValues = $form->exportValues();
|
||||
|
||||
$coupon['code'] = $formValues['code'];
|
||||
$coupon['discount_type'] = $formValues['discount_type'];
|
||||
$coupon['discount_amount'] = $formValues['discount_amount'];
|
||||
$coupon['valid_start'] = $formValues['date_start'];
|
||||
$coupon['valid_end'] = $formValues['date_end'];
|
||||
$coupon['active'] = $formValues['active'];
|
||||
|
||||
if ($coupon['discount_type'] == BuyCoursesPlugin::COUPON_DISCOUNT_TYPE_PERCENTAGE && $coupon['discount_amount'] > 100) {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('CouponDiscountExceed100'), 'error', false)
|
||||
);
|
||||
}
|
||||
|
||||
$coupon['courses'] = isset($formValues['courses']) ? $formValues['courses'] : [];
|
||||
$coupon['sessions'] = isset($formValues['sessions']) ? $formValues['sessions'] : [];
|
||||
$coupon['services'] = isset($formValues['services']) ? $formValues['services'] : [];
|
||||
|
||||
$result = $plugin->addNewCoupon($coupon);
|
||||
|
||||
if ($result) {
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/coupons.php');
|
||||
} else {
|
||||
header('Location:'.api_get_self().'?'.$queryString);
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$formDefaults = [
|
||||
'code' => '',
|
||||
'discount_type' => null,
|
||||
'discount_amount' => 0,
|
||||
'active' => 0,
|
||||
'courses' => [],
|
||||
'sessions' => [],
|
||||
'services' => [],
|
||||
];
|
||||
|
||||
$form->setDefaults($formDefaults);
|
||||
|
||||
$templateName = $plugin->get_lang('CouponAdd');
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'paymentsetup.php',
|
||||
'name' => get_lang('Configuration'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'coupons.php',
|
||||
'name' => $plugin->get_lang('CouponList'),
|
||||
];
|
||||
|
||||
$template = new Template($templateName);
|
||||
$template->assign('header', $templateName);
|
||||
$template->assign('content', $form->returnForm());
|
||||
$template->display_one_col_template();
|
||||
109
plugin/buycourses/src/coupons.php
Normal file
109
plugin/buycourses/src/coupons.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* List of couponsof the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once '../config.php';
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
|
||||
if (isset($_GET['coupon_id'])) {
|
||||
$coupon = $plugin->getCouponInfo($_GET['coupon_id']);
|
||||
|
||||
if (empty($coupon)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$urlToRedirect = api_get_self().'?';
|
||||
|
||||
switch ($_GET['action']) {
|
||||
case 'deactivate':
|
||||
//activate coupon
|
||||
break;
|
||||
case 'activate':
|
||||
//deactivate coupon
|
||||
break;
|
||||
}
|
||||
|
||||
header("Location: $urlToRedirect");
|
||||
exit;
|
||||
}
|
||||
|
||||
$discountTypes = $plugin->getCouponDiscountTypes();
|
||||
$couponStatuses = $plugin->getCouponStatuses();
|
||||
|
||||
$selectedFilterType = '0';
|
||||
$selectedStatus = isset($_GET['status']) ? $_GET['status'] : BuyCoursesPlugin::COUPON_STATUS_ACTIVE;
|
||||
|
||||
$form = new FormValidator('search', 'get');
|
||||
|
||||
if ($form->validate()) {
|
||||
$selectedStatus = $form->getSubmitValue('status');
|
||||
|
||||
if ($selectedStatus === false) {
|
||||
$selectedStatus = BuyCoursesPlugin::COUPON_STATUS_ACTIVE;
|
||||
}
|
||||
|
||||
if ($selectedFilterType === false) {
|
||||
$selectedFilterType = '0';
|
||||
}
|
||||
}
|
||||
|
||||
$form->addHtml('<div id="report-by-status" '.($selectedFilterType !== '0' ? 'style="display:none"' : '').'>');
|
||||
$form->addSelect('status', $plugin->get_lang('CouponStatus'), $couponStatuses);
|
||||
$form->addHtml('</div>');
|
||||
$form->addButtonFilter(get_lang('Search'));
|
||||
$form->setDefaults([
|
||||
'filter_type' => $selectedFilterType,
|
||||
'status' => $selectedStatus,
|
||||
]);
|
||||
|
||||
$coupons = $plugin->getCouponsListByStatus($selectedStatus);
|
||||
$currency = $plugin->getSelectedCurrency();
|
||||
|
||||
foreach ($coupons as &$coupon) {
|
||||
if ($coupon['discount_type'] == BuyCoursesPlugin::COUPON_DISCOUNT_TYPE_PERCENTAGE) {
|
||||
$coupon['discount_value'] = $coupon['discount_amount']." %";
|
||||
} elseif ($coupon['discount_type'] == BuyCoursesPlugin::COUPON_DISCOUNT_TYPE_AMOUNT) {
|
||||
$coupon['discount_value'] = $plugin->getPriceWithCurrencyFromIsoCode($coupon['discount_amount'], $currency['iso_code']);
|
||||
}
|
||||
$coupon['discount_type'] = $discountTypes[$coupon['discount_type']];
|
||||
}
|
||||
|
||||
$interbreadcrumb[] = ['url' => '../index.php', 'name' => $plugin->get_lang('plugin_title')];
|
||||
|
||||
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_PLUGIN_PATH).'buycourses/resources/css/style.css');
|
||||
|
||||
$templateName = $plugin->get_lang('CouponList');
|
||||
$template = new Template($templateName);
|
||||
|
||||
$toolbar = Display::url(
|
||||
Display::returnFontAwesomeIcon('fas fa-plus').
|
||||
$plugin->get_lang('CouponAdd'),
|
||||
api_get_path(WEB_PLUGIN_PATH).'buycourses/src/coupon_add.php',
|
||||
['class' => 'btn btn-primary']
|
||||
);
|
||||
|
||||
$template->assign(
|
||||
'actions',
|
||||
Display::toolbarAction('toolbar', [$toolbar])
|
||||
);
|
||||
|
||||
$template->assign('form', $form->returnForm());
|
||||
$template->assign('selected_status', $selectedStatus);
|
||||
$template->assign('coupon_list', $coupons);
|
||||
$template->assign('coupon_status_active', BuyCoursesPlugin::COUPON_STATUS_ACTIVE);
|
||||
$template->assign('coupon_status_disable', BuyCoursesPlugin::COUPON_STATUS_DISABLE);
|
||||
|
||||
$content = $template->fetch('buycourses/view/coupons.tpl');
|
||||
|
||||
$template->assign('header', $templateName);
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
100
plugin/buycourses/src/course_catalog.php
Normal file
100
plugin/buycourses/src/course_catalog.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* List of courses.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$includeSessions = $plugin->get('include_sessions') === 'true';
|
||||
$includeServices = $plugin->get('include_services') === 'true';
|
||||
|
||||
$nameFilter = '';
|
||||
$minFilter = 0;
|
||||
$maxFilter = 0;
|
||||
|
||||
$form = new FormValidator(
|
||||
'search_filter_form',
|
||||
'get',
|
||||
null,
|
||||
null,
|
||||
[],
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
|
||||
if ($form->validate()) {
|
||||
$formValues = $form->getSubmitValues();
|
||||
$nameFilter = isset($formValues['name']) ? $formValues['name'] : null;
|
||||
$minFilter = isset($formValues['min']) ? $formValues['min'] : 0;
|
||||
$maxFilter = isset($formValues['max']) ? $formValues['max'] : 0;
|
||||
}
|
||||
|
||||
$form->addHeader($plugin->get_lang('SearchFilter'));
|
||||
$form->addText('name', get_lang('CourseName'), false);
|
||||
$form->addElement(
|
||||
'number',
|
||||
'min',
|
||||
$plugin->get_lang('MinimumPrice'),
|
||||
['step' => '0.01', 'min' => '0']
|
||||
);
|
||||
$form->addElement(
|
||||
'number',
|
||||
'max',
|
||||
$plugin->get_lang('MaximumPrice'),
|
||||
['step' => '0.01', 'min' => '0']
|
||||
);
|
||||
$form->addHtml('<hr>');
|
||||
$form->addButtonFilter(get_lang('Search'));
|
||||
|
||||
$pageSize = BuyCoursesPlugin::PAGINATION_PAGE_SIZE;
|
||||
$currentPage = isset($_GET['page']) ? (int) $_GET['page'] : 1;
|
||||
$first = $pageSize * ($currentPage - 1);
|
||||
$courseList = $plugin->getCatalogCourseList($first, $pageSize, $nameFilter, $minFilter, $maxFilter);
|
||||
$totalItems = $plugin->getCatalogCourseList($first, $pageSize, $nameFilter, $minFilter, $maxFilter, 'count');
|
||||
$pagesCount = ceil($totalItems / $pageSize);
|
||||
|
||||
$pagination = BuyCoursesPlugin::returnPagination(api_get_self(), $currentPage, $pagesCount, $totalItems);
|
||||
|
||||
// View
|
||||
if (api_is_platform_admin()) {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'list.php',
|
||||
'name' => $plugin->get_lang('AvailableCoursesConfiguration'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'paymentsetup.php',
|
||||
'name' => $plugin->get_lang('PaymentsConfiguration'),
|
||||
];
|
||||
} else {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'course_panel.php',
|
||||
'name' => get_lang('TabsDashboard'),
|
||||
];
|
||||
}
|
||||
|
||||
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_PLUGIN_PATH).'buycourses/resources/css/style.css');
|
||||
|
||||
$templateName = $plugin->get_lang('CourseListOnSale');
|
||||
$tpl = new Template($templateName);
|
||||
$tpl->assign('search_filter_form', $form->returnForm());
|
||||
$tpl->assign('showing_courses', true);
|
||||
$tpl->assign('courses', $courseList);
|
||||
$tpl->assign('sessions_are_included', $includeSessions);
|
||||
$tpl->assign('services_are_included', $includeServices);
|
||||
$tpl->assign('pagination', $pagination);
|
||||
|
||||
$countSessions = $plugin->getCatalogSessionList($first, $pageSize, $nameFilter, $minFilter, $maxFilter, 'count');
|
||||
|
||||
$tpl->assign('coursesExist', true);
|
||||
$tpl->assign('sessionExist', $countSessions > 0);
|
||||
|
||||
$content = $tpl->fetch('buycourses/view/catalog.tpl');
|
||||
|
||||
$tpl->assign('header', $templateName);
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template();
|
||||
67
plugin/buycourses/src/course_panel.php
Normal file
67
plugin/buycourses/src/course_panel.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* User Panel.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$includeSessions = $plugin->get('include_sessions') === 'true';
|
||||
$includeServices = $plugin->get('include_services') === 'true';
|
||||
|
||||
$userInfo = api_get_user_info();
|
||||
|
||||
$productTypes = $plugin->getProductTypes();
|
||||
$saleStatuses = $plugin->getSaleStatuses();
|
||||
$paymentTypes = $plugin->getPaymentTypes();
|
||||
|
||||
$sales = $plugin->getSaleListByUserId($userInfo['id']);
|
||||
|
||||
$saleList = [];
|
||||
|
||||
foreach ($sales as $sale) {
|
||||
if ($sale['product_type'] == 1) {
|
||||
$saleList[] = [
|
||||
'id' => $sale['id'],
|
||||
'reference' => $sale['reference'],
|
||||
'date' => api_format_date($sale['date'], DATE_TIME_FORMAT_LONG_24H),
|
||||
'currency' => $sale['iso_code'],
|
||||
'price' => $sale['price'],
|
||||
'product_name' => $sale['product_name'],
|
||||
'product_type' => $productTypes[$sale['product_type']],
|
||||
'payment_type' => $paymentTypes[$sale['payment_type']],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$toolbar = Display::toolbarButton(
|
||||
$plugin->get_lang('CourseListOnSale'),
|
||||
'course_catalog.php',
|
||||
'search-plus',
|
||||
'primary',
|
||||
['title' => $plugin->get_lang('CourseListOnSale')]
|
||||
);
|
||||
|
||||
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_PLUGIN_PATH).'buycourses/resources/css/style.css');
|
||||
|
||||
$templateName = get_lang('TabsDashboard');
|
||||
$tpl = new Template($templateName);
|
||||
$tpl->assign('showing_courses', true);
|
||||
$tpl->assign('sessions_are_included', $includeSessions);
|
||||
$tpl->assign('services_are_included', $includeServices);
|
||||
$tpl->assign('sale_list', $saleList);
|
||||
|
||||
$content = $tpl->fetch('buycourses/view/course_panel.tpl');
|
||||
|
||||
$tpl->assign(
|
||||
'actions',
|
||||
Display::toolbarAction('toolbar', [$toolbar])
|
||||
);
|
||||
$tpl->assign('header', $templateName);
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template();
|
||||
14
plugin/buycourses/src/error.php
Normal file
14
plugin/buycourses/src/error.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
/**
|
||||
* Errors management for the Buy Courses plugin - Redirects to course_catalog.php.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
/**
|
||||
* Config.
|
||||
*/
|
||||
unset($_SESSION['bc_sale_id']);
|
||||
|
||||
header('Location: course_catalog.php');
|
||||
exit;
|
||||
63
plugin/buycourses/src/export_report.php
Normal file
63
plugin/buycourses/src/export_report.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
//Initialization
|
||||
$cidReset = true;
|
||||
|
||||
require_once '../config.php';
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$form = new FormValidator('export_validate');
|
||||
|
||||
$form->addDatePicker('date_start', get_lang('DateStart'), false);
|
||||
$form->addDatePicker('date_end', get_lang('DateEnd'), false);
|
||||
$form->addButton('export_sales', get_lang('ExportExcel'), 'check', 'primary');
|
||||
$salesStatus = [];
|
||||
|
||||
if ($form->validate()) {
|
||||
$reportValues = $form->getSubmitValues();
|
||||
|
||||
$dateStart = $reportValues['date_start'];
|
||||
$dateEnd = $reportValues['date_end'];
|
||||
|
||||
if ($dateStart == null || $dateEnd == null) {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('SelectDateRange'), 'error', false)
|
||||
);
|
||||
} elseif ($dateStart > $dateEnd) {
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('EndDateCannotBeBeforeTheStartDate'), 'error', false)
|
||||
);
|
||||
} else {
|
||||
$salesStatus = $plugin->getSaleListReport($dateStart, $dateEnd);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($salesStatus)) {
|
||||
$archiveFile = 'export_report_sales_'.api_get_local_time();
|
||||
Export::arrayToXls($salesStatus, $archiveFile);
|
||||
}
|
||||
$interbreadcrumb[] = [
|
||||
'url' => '../index.php', 'name' => $plugin->get_lang('plugin_title'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_PLUGIN_PATH).'buycourses/src/sales_report.php',
|
||||
'name' => $plugin->get_lang('SalesReport'),
|
||||
];
|
||||
|
||||
$templateName = $plugin->get_lang('ExportReport');
|
||||
$toolbar = Display::url(
|
||||
Display::return_icon('back.png', get_lang('GoBack'), [], ICON_SIZE_MEDIUM),
|
||||
api_get_path(WEB_PLUGIN_PATH).'buycourses/src/sales_report.php'
|
||||
);
|
||||
$template = new Template($templateName);
|
||||
$template->assign(
|
||||
'actions',
|
||||
Display::toolbarAction('toolbar', [$toolbar])
|
||||
);
|
||||
$template->assign('form', $form->returnForm());
|
||||
$content = $template->fetch('buycourses/view/export_report.tpl');
|
||||
$template->assign('header', $templateName);
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
63
plugin/buycourses/src/export_subscription_report.php
Normal file
63
plugin/buycourses/src/export_subscription_report.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
//Initialization
|
||||
$cidReset = true;
|
||||
|
||||
require_once '../config.php';
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$form = new FormValidator('export_validate');
|
||||
|
||||
$form->addDatePicker('date_start', get_lang('DateStart'), false);
|
||||
$form->addDatePicker('date_end', get_lang('DateEnd'), false);
|
||||
$form->addButton('export_sales', get_lang('ExportExcel'), 'check', 'primary');
|
||||
$salesStatus = [];
|
||||
|
||||
if ($form->validate()) {
|
||||
$reportValues = $form->getSubmitValues();
|
||||
|
||||
$dateStart = $reportValues['date_start'];
|
||||
$dateEnd = $reportValues['date_end'];
|
||||
|
||||
if ($dateStart == null || $dateEnd == null) {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('SelectDateRange'), 'error', false)
|
||||
);
|
||||
} elseif ($dateStart > $dateEnd) {
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('EndDateCannotBeBeforeTheStartDate'), 'error', false)
|
||||
);
|
||||
} else {
|
||||
$salesStatus = $plugin->getSubscriptionSaleListReport($dateStart, $dateEnd);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($salesStatus)) {
|
||||
$archiveFile = 'export_report_sales_'.api_get_local_time();
|
||||
Export::arrayToXls($salesStatus, $archiveFile);
|
||||
}
|
||||
$interbreadcrumb[] = [
|
||||
'url' => '../index.php', 'name' => $plugin->get_lang('plugin_title'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_PLUGIN_PATH).'buycourses/src/subscription_sales_report.php',
|
||||
'name' => $plugin->get_lang('SubscriptionSalesReport'),
|
||||
];
|
||||
|
||||
$templateName = $plugin->get_lang('ExportReport');
|
||||
$toolbar = Display::url(
|
||||
Display::return_icon('back.png', get_lang('GoBack'), [], ICON_SIZE_MEDIUM),
|
||||
api_get_path(WEB_PLUGIN_PATH).'buycourses/src/subscription_sales_report.php'
|
||||
);
|
||||
$template = new Template($templateName);
|
||||
$template->assign(
|
||||
'actions',
|
||||
Display::toolbarAction('toolbar', [$toolbar])
|
||||
);
|
||||
$template->assign('form', $form->returnForm());
|
||||
$content = $template->fetch('buycourses/view/export_report.tpl');
|
||||
$template->assign('header', $templateName);
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
47
plugin/buycourses/src/expresscheckout.php
Normal file
47
plugin/buycourses/src/expresscheckout.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
/**
|
||||
* PayPal Express Checkout Module.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
/**
|
||||
* Init.
|
||||
*/
|
||||
require_once 'paypalfunctions.php';
|
||||
/**
|
||||
* The paymentAmount is the total value of
|
||||
* the shopping cart, that was set
|
||||
* earlier in a session variable
|
||||
* by the shopping cart page.
|
||||
*/
|
||||
$paymentAmount = $_SESSION["Payment_Amount"];
|
||||
|
||||
/**
|
||||
* The currencyCodeType and paymentType
|
||||
* are set to the selections made on the Integration Assistant.
|
||||
*/
|
||||
$paymentType = "Sale";
|
||||
|
||||
/**
|
||||
* Calls the SetExpressCheckout API call
|
||||
* The CallShortcutExpressCheckout function is defined in the file PayPalFunctions.php,
|
||||
* it is included at the top of this file.
|
||||
*/
|
||||
$resArray = CallShortcutExpressCheckout($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL);
|
||||
$ack = strtoupper($resArray["ACK"]);
|
||||
if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") {
|
||||
RedirectToPayPal($resArray["TOKEN"]);
|
||||
} else {
|
||||
//Display a user friendly Error on the page using any of the following error information returned by PayPal
|
||||
$ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
|
||||
$ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
|
||||
$ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
|
||||
$ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
|
||||
|
||||
echo "SetExpressCheckout API call failed. ";
|
||||
echo "Detailed Error Message: ".$ErrorLongMsg;
|
||||
echo "Short Error Message: ".$ErrorShortMsg;
|
||||
echo "Error Code: ".$ErrorCode;
|
||||
echo "Error Severity Code: ".$ErrorSeverityCode;
|
||||
}
|
||||
48
plugin/buycourses/src/index.buycourses.php
Normal file
48
plugin/buycourses/src/index.buycourses.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Index of the Buy Courses plugin courses list.
|
||||
*/
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$allow = $plugin->get('unregistered_users_enable');
|
||||
|
||||
$userIsAdmin = api_is_platform_admin();
|
||||
|
||||
if (($allow === 'true' && api_is_anonymous()) || !api_is_anonymous()) {
|
||||
$webPluginPath = api_get_path(WEB_PLUGIN_PATH).'buycourses/';
|
||||
|
||||
$countCourses = $plugin->getCatalogCourseList(
|
||||
0,
|
||||
BuyCoursesPlugin::PAGINATION_PAGE_SIZE,
|
||||
null,
|
||||
0,
|
||||
0,
|
||||
'count'
|
||||
);
|
||||
|
||||
if ($countCourses > 0 && !$userIsAdmin) {
|
||||
api_location($webPluginPath.'src/course_catalog.php');
|
||||
}
|
||||
|
||||
$countSessions = $plugin->getCatalogSessionList(
|
||||
0,
|
||||
BuyCoursesPlugin::PAGINATION_PAGE_SIZE,
|
||||
null,
|
||||
0,
|
||||
0,
|
||||
'count'
|
||||
);
|
||||
|
||||
if ($countSessions > 0 && !$userIsAdmin) {
|
||||
api_location($webPluginPath.'src/session_catalog.php');
|
||||
}
|
||||
|
||||
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_PLUGIN_PATH).'buycourses/resources/css/style.css');
|
||||
|
||||
$tpl = new Template();
|
||||
$content = $tpl->fetch('buycourses/view/index.tpl');
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template(false);
|
||||
}
|
||||
1
plugin/buycourses/src/index.php
Normal file
1
plugin/buycourses/src/index.php
Normal file
@@ -0,0 +1 @@
|
||||
<?php
|
||||
155
plugin/buycourses/src/invoice.php
Normal file
155
plugin/buycourses/src/invoice.php
Normal file
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
|
||||
|
||||
/**
|
||||
* Print invoice of the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once '../config.php';
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
|
||||
$invoicingEnable = $plugin->get('invoicing_enable') === 'true';
|
||||
if (!$invoicingEnable) {
|
||||
api_not_allowed(true, $plugin->get_lang('NoInvoiceEnable'));
|
||||
}
|
||||
|
||||
$saleId = isset($_GET['invoice']) ? (int) $_GET['invoice'] : 0;
|
||||
$isService = isset($_GET['is_service']) ? (int) $_GET['is_service'] : 0;
|
||||
|
||||
$globalParameters = $plugin->getGlobalParameters();
|
||||
$infoSale = $plugin->getDataSaleInvoice($saleId, $isService);
|
||||
$buyer = api_get_user_info($infoSale['user_id']);
|
||||
$extraUserInfoData = UserManager::get_extra_user_data($infoSale['user_id']);
|
||||
$infoInvoice = $plugin->getDataInvoice($saleId, $isService);
|
||||
|
||||
$taxAppliesTo = $globalParameters['tax_applies_to'];
|
||||
$taxEnable = $plugin->get('tax_enable') === 'true' &&
|
||||
($taxAppliesTo == BuyCoursesPlugin::TAX_APPLIES_TO_ALL ||
|
||||
($taxAppliesTo == BuyCoursesPlugin::TAX_APPLIES_TO_ONLY_COURSE && !$isService) ||
|
||||
($taxAppliesTo == BuyCoursesPlugin::TAX_APPLIES_TO_ONLY_SESSION && $isService));
|
||||
|
||||
$htmlText = '<html>';
|
||||
$htmlText .= '<link rel="stylesheet" type="text/css" href="plugin.css">';
|
||||
$htmlText .= '<link rel="stylesheet" type="text/css" href="'.api_get_path(WEB_CSS_PATH).'base.css">';
|
||||
$htmlText .= '<body>';
|
||||
|
||||
$organization = ChamiloApi::getPlatformLogo('', [], true);
|
||||
// Use custom logo image.
|
||||
$pdfLogo = api_get_setting('pdf_logo_header');
|
||||
if ($pdfLogo === 'true') {
|
||||
$visualTheme = api_get_visual_theme();
|
||||
$img = api_get_path(SYS_CSS_PATH).'themes/'.$visualTheme.'/images/pdf_logo_header.png';
|
||||
if (file_exists($img)) {
|
||||
$organization = "<img src='$img'>";
|
||||
}
|
||||
}
|
||||
$htmlText .= $organization;
|
||||
|
||||
// Seller and customer info
|
||||
$htmlText .= '<table width="100%">';
|
||||
$htmlText .= '<tr>';
|
||||
$htmlText .= '<td>';
|
||||
$htmlText .= '<b>'.$globalParameters['seller_name'].'</b><br/>';
|
||||
$htmlText .= $globalParameters['seller_id'].'<br/>';
|
||||
$htmlText .= $globalParameters['seller_address'].'<br/>';
|
||||
$htmlText .= $globalParameters['seller_email'].'<br/>';
|
||||
$htmlText .= '</td>';
|
||||
$htmlText .= '<td style="text-align:right;">';
|
||||
$htmlText .= '<b>'.$buyer['complete_name'].'</b><br/>';
|
||||
$htmlText .= ($extraUserInfoData['buycourses_company'] ? $extraUserInfoData['buycourses_company'].'<br>' : '');
|
||||
$htmlText .= ($extraUserInfoData['buycourses_vat'] ? $extraUserInfoData['buycourses_vat'].'<br>' : '');
|
||||
$htmlText .= ($extraUserInfoData['buycourses_address'] ? $extraUserInfoData['buycourses_address'].'<br/>' : '');
|
||||
$htmlText .= ($buyer['phone'] ? $buyer['phone'].'<br/>' : '');
|
||||
$htmlText .= ($buyer['email'] ? $buyer['email'].'<br>' : '');
|
||||
$htmlText .= '</td>';
|
||||
$htmlText .= '</tr>';
|
||||
$htmlText .= '</table>';
|
||||
|
||||
$htmlText .= '<br><br>';
|
||||
$htmlText .= '<p>';
|
||||
$htmlText .= $plugin->get_lang('InvoiceDate').': <span style="font-weight:bold;">'
|
||||
.api_convert_and_format_date($infoInvoice['date_invoice'], DATE_TIME_FORMAT_LONG_24H).'</span><br>';
|
||||
$htmlText .= $plugin->get_lang('InvoiceNumber').': <span style="font-weight:bold;">'
|
||||
.$infoInvoice['serie'].$infoInvoice['year'].'/'.$infoInvoice['num_invoice'].'</span><br>';
|
||||
$htmlText .= '</p><br><br>';
|
||||
|
||||
$header = [
|
||||
$plugin->get_lang('OrderReference'),
|
||||
$plugin->get_lang('ProductType'),
|
||||
$plugin->get_lang('Price'),
|
||||
];
|
||||
|
||||
if ($taxEnable) {
|
||||
$header[] = $globalParameters['tax_name'];
|
||||
$header[] = $plugin->get_lang('Total');
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$row = [
|
||||
$infoSale['reference'],
|
||||
$infoSale['product_name'],
|
||||
];
|
||||
|
||||
//var_dump($infoSale);exit;
|
||||
$isoCode = $plugin->getCurrency($infoSale['currency_id'])['iso_code'];
|
||||
|
||||
if ($taxEnable) {
|
||||
$row[] = $plugin->getPriceWithCurrencyFromIsoCode($infoSale['price_without_tax'], $isoCode);
|
||||
$row[] = $plugin->getPriceWithCurrencyFromIsoCode($infoSale['tax_amount'], $isoCode).' ('.(int) $infoSale['tax_perc'].'%)';
|
||||
}
|
||||
|
||||
$totalPrice = $plugin->getPriceWithCurrencyFromIsoCode(
|
||||
$infoSale['price'],
|
||||
$plugin->getCurrency($infoSale['currency_id'])['iso_code']
|
||||
);
|
||||
|
||||
$row[] = $totalPrice;
|
||||
$data[] = $row;
|
||||
|
||||
$totalPrice = $plugin->getPriceWithCurrencyFromIsoCode(
|
||||
$infoSale['price'],
|
||||
$plugin->getCurrency($infoSale['currency_id'])['iso_code']
|
||||
);
|
||||
|
||||
if ($taxEnable) {
|
||||
$row = [
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
$plugin->get_lang('TotalPayout'),
|
||||
$totalPrice,
|
||||
];
|
||||
} else {
|
||||
$row = [
|
||||
'',
|
||||
$plugin->get_lang('TotalPayout'),
|
||||
$totalPrice,
|
||||
];
|
||||
}
|
||||
$data[] = $row;
|
||||
$attr = [];
|
||||
$attr['class'] = 'table table-hover table-striped data_table';
|
||||
$attr['width'] = '100%';
|
||||
$htmlText .= Display::table($header, $data, $attr);
|
||||
$htmlText .= '</body></html>';
|
||||
|
||||
$fileName = $infoInvoice['serie'].$infoInvoice['year'].'-'.$infoInvoice['num_invoice'];
|
||||
$fileName = api_replace_dangerous_char($fileName);
|
||||
$params = [
|
||||
'filename' => $fileName,
|
||||
'pdf_title' => $plugin->get_lang('Invoice'),
|
||||
'pdf_description' => '',
|
||||
'format' => 'A4',
|
||||
'orientation' => 'P',
|
||||
];
|
||||
$pdf = new PDF($params['format'], $params['orientation'], $params);
|
||||
@$pdf->content_to_pdf($htmlText, '', $fileName, null, 'D', false, null, false, false, false);
|
||||
exit;
|
||||
87
plugin/buycourses/src/list.php
Normal file
87
plugin/buycourses/src/list.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
/**
|
||||
* Configuration script for the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
|
||||
use Doctrine\ORM\Tools\Pagination\Paginator;
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$includeSession = $plugin->get('include_sessions') === 'true';
|
||||
$includeServices = $plugin->get('include_services') === 'true';
|
||||
$taxEnable = $plugin->get('tax_enable') === 'true';
|
||||
|
||||
api_protect_admin_script(true);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
get_lang('Info').' - '.$plugin->get_lang('CoursesInSessionsDoesntDisplayHere'),
|
||||
'info'
|
||||
)
|
||||
);
|
||||
|
||||
$pageSize = BuyCoursesPlugin::PAGINATION_PAGE_SIZE;
|
||||
$type = isset($_GET['type']) ? (int) $_GET['type'] : BuyCoursesPlugin::PRODUCT_TYPE_COURSE;
|
||||
$currentPage = isset($_GET['page']) ? (int) $_GET['page'] : 1;
|
||||
$first = $pageSize * ($currentPage - 1);
|
||||
|
||||
$qb = $plugin->getCourseList($first, $pageSize);
|
||||
$query = $qb->getQuery();
|
||||
$courses = new Paginator($query, $fetchJoinCollection = true);
|
||||
foreach ($courses as $course) {
|
||||
$item = $plugin->getItemByProduct($course->getId(), BuyCoursesPlugin::PRODUCT_TYPE_COURSE);
|
||||
$course->buyCourseData = [];
|
||||
if ($item !== false) {
|
||||
$course->buyCourseData = $item;
|
||||
}
|
||||
}
|
||||
|
||||
$totalItems = count($courses);
|
||||
$pagesCount = ceil($totalItems / $pageSize);
|
||||
|
||||
$pagination = BuyCoursesPlugin::returnPagination(
|
||||
api_get_self(),
|
||||
$currentPage,
|
||||
$pagesCount,
|
||||
$totalItems,
|
||||
['type' => $type]
|
||||
);
|
||||
|
||||
// breadcrumbs
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_PLUGIN_PATH).'buycourses/index.php',
|
||||
'name' => $plugin->get_lang('plugin_title'),
|
||||
];
|
||||
|
||||
$templateName = $plugin->get_lang('AvailableCourses');
|
||||
|
||||
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_PLUGIN_PATH).'buycourses/resources/css/style.css');
|
||||
|
||||
$tpl = new Template($templateName);
|
||||
|
||||
$tpl->assign('product_type_course', BuyCoursesPlugin::PRODUCT_TYPE_COURSE);
|
||||
$tpl->assign('product_type_session', BuyCoursesPlugin::PRODUCT_TYPE_SESSION);
|
||||
$tpl->assign('courses', $courses);
|
||||
$tpl->assign('course_pagination', $pagination);
|
||||
$tpl->assign('sessions_are_included', $includeSession);
|
||||
$tpl->assign('services_are_included', $includeServices);
|
||||
$tpl->assign('tax_enable', $taxEnable);
|
||||
|
||||
if ($taxEnable) {
|
||||
$globalParameters = $plugin->getGlobalParameters();
|
||||
$tpl->assign('global_tax_perc', $globalParameters['global_tax_perc']);
|
||||
$tpl->assign('tax_applies_to', $globalParameters['tax_applies_to']);
|
||||
$tpl->assign('tax_name', $globalParameters['tax_name']);
|
||||
}
|
||||
|
||||
$content = $tpl->fetch('buycourses/view/list.tpl');
|
||||
|
||||
$tpl->assign('header', $templateName);
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template();
|
||||
96
plugin/buycourses/src/list_coupon.php
Normal file
96
plugin/buycourses/src/list_coupon.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* List of couponsof the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once '../config.php';
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
|
||||
if (isset($_GET['coupon_id'])) {
|
||||
$coupon = $plugin->getCouponInfo($_GET['coupon_id']);
|
||||
|
||||
if (empty($coupon)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$urlToRedirect = api_get_self().'?';
|
||||
|
||||
switch ($_GET['action']) {
|
||||
case 'deactivate':
|
||||
//activate coupon
|
||||
break;
|
||||
case 'activate':
|
||||
//deactivate coupon
|
||||
break;
|
||||
}
|
||||
|
||||
header("Location: $urlToRedirect");
|
||||
exit;
|
||||
}
|
||||
|
||||
$discountTypes = $plugin->getCouponDiscountTypes();
|
||||
$couponStatuses = $plugin->getCouponStatuses();
|
||||
|
||||
$selectedFilterType = '0';
|
||||
$selectedStatus = isset($_GET['status']) ? $_GET['status'] : BuyCoursesPlugin::COUPON_STATUS_ACTIVE;
|
||||
|
||||
$form = new FormValidator('search', 'get');
|
||||
|
||||
if ($form->validate()) {
|
||||
$selectedStatus = $form->getSubmitValue('status');
|
||||
|
||||
if ($selectedStatus === false) {
|
||||
$selectedStatus = BuyCoursesPlugin::COUPON_STATUS_ACTIVE;
|
||||
}
|
||||
|
||||
if ($selectedFilterType === false) {
|
||||
$selectedFilterType = '0';
|
||||
}
|
||||
}
|
||||
|
||||
$form->addHtml('<div id="report-by-status" '.($selectedFilterType !== '0' ? 'style="display:none"' : '').'>');
|
||||
$form->addSelect('status', $plugin->get_lang('CouponStatus'), $couponStatuses);
|
||||
$form->addHtml('</div>');
|
||||
$form->addButtonFilter(get_lang('Search'));
|
||||
$form->setDefaults([
|
||||
'filter_type' => $selectedFilterType,
|
||||
'status' => $selectedStatus,
|
||||
]);
|
||||
|
||||
$coupons = $plugin->getCouponsListByStatus($selectedStatus);
|
||||
|
||||
foreach ($coupons as &$coupon) {
|
||||
if ($coupon['discount_type'] == BuyCoursesPlugin::COUPON_DISCOUNT_TYPE_PERCENTAGE) {
|
||||
$coupon['discount_value'] = $coupon['discount_amount']." %";
|
||||
} elseif ($coupon['discount_type'] == BuyCoursesPlugin::COUPON_DISCOUNT_TYPE_AMOUNT) {
|
||||
$coupon['discount_value'] = $plugin->getPriceWithCurrencyFromIsoCode($coupon['discount_amount'], $coupon['iso_code']);
|
||||
}
|
||||
$coupon['discount_type'] = $discountTypes[$coupon['discount_type']];
|
||||
}
|
||||
|
||||
$interbreadcrumb[] = ['url' => '../index.php', 'name' => $plugin->get_lang('plugin_title')];
|
||||
|
||||
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_PLUGIN_PATH).'buycourses/resources/css/style.css');
|
||||
|
||||
$templateName = $plugin->get_lang('CouponList');
|
||||
$template = new Template($templateName);
|
||||
|
||||
$template->assign('form', $form->returnForm());
|
||||
$template->assign('selected_status', $selectedStatus);
|
||||
$template->assign('coupon_list', $coupons);
|
||||
$template->assign('coupon_status_active', BuyCoursesPlugin::COUPON_STATUS_ACTIVE);
|
||||
$template->assign('coupon_status_disable', BuyCoursesPlugin::COUPON_STATUS_DISABLE);
|
||||
|
||||
$content = $template->fetch('buycourses/view/list_coupon.tpl');
|
||||
|
||||
$template->assign('header', $templateName);
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
71
plugin/buycourses/src/list_service.php
Normal file
71
plugin/buycourses/src/list_service.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
/**
|
||||
* Configuration script for the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$includeSession = $plugin->get('include_sessions') === 'true';
|
||||
$includeServices = $plugin->get('include_services') === 'true';
|
||||
if (!$includeServices) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$taxEnable = $plugin->get('tax_enable') === 'true';
|
||||
|
||||
api_protect_admin_script(true);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
get_lang('Info').' - '.$plugin->get_lang('CoursesInSessionsDoesntDisplayHere'),
|
||||
'info'
|
||||
)
|
||||
);
|
||||
|
||||
$pageSize = BuyCoursesPlugin::PAGINATION_PAGE_SIZE;
|
||||
$currentPage = isset($_GET['page']) ? (int) $_GET['page'] : 1;
|
||||
$first = $pageSize * ($currentPage - 1);
|
||||
|
||||
$services = $plugin->getServices($first, $pageSize);
|
||||
$totalItems = $plugin->getServices(0, 1000000000, 'count');
|
||||
$pagesCount = ceil($totalItems / $pageSize);
|
||||
|
||||
$pagination = BuyCoursesPlugin::returnPagination(api_get_self(), $currentPage, $pagesCount, $totalItems);
|
||||
|
||||
// breadcrumbs
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_PLUGIN_PATH).'buycourses/index.php',
|
||||
'name' => $plugin->get_lang('plugin_title'),
|
||||
];
|
||||
|
||||
$templateName = $plugin->get_lang('Services');
|
||||
|
||||
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_PLUGIN_PATH).'buycourses/resources/css/style.css');
|
||||
|
||||
$tpl = new Template($templateName);
|
||||
|
||||
$tpl->assign('product_type_course', BuyCoursesPlugin::PRODUCT_TYPE_COURSE);
|
||||
$tpl->assign('product_type_session', BuyCoursesPlugin::PRODUCT_TYPE_SESSION);
|
||||
$tpl->assign('sessions_are_included', $includeSession);
|
||||
$tpl->assign('services_are_included', $includeServices);
|
||||
$tpl->assign('tax_enable', $taxEnable);
|
||||
$tpl->assign('services', $services);
|
||||
$tpl->assign('service_pagination', $pagination);
|
||||
|
||||
if ($taxEnable) {
|
||||
$globalParameters = $plugin->getGlobalParameters();
|
||||
$tpl->assign('global_tax_perc', $globalParameters['global_tax_perc']);
|
||||
$tpl->assign('tax_applies_to', $globalParameters['tax_applies_to']);
|
||||
$tpl->assign('tax_name', $globalParameters['tax_name']);
|
||||
}
|
||||
|
||||
$content = $tpl->fetch('buycourses/view/list.tpl');
|
||||
|
||||
$tpl->assign('header', $templateName);
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template();
|
||||
89
plugin/buycourses/src/list_session.php
Normal file
89
plugin/buycourses/src/list_session.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
/**
|
||||
* Configuration script for the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
use Doctrine\ORM\Tools\Pagination\Paginator;
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$includeSession = $plugin->get('include_sessions') === 'true';
|
||||
|
||||
if (!$includeSession) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
$includeServices = $plugin->get('include_services') === 'true';
|
||||
$taxEnable = $plugin->get('tax_enable') === 'true';
|
||||
|
||||
api_protect_admin_script(true);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
get_lang('Info').' - '.$plugin->get_lang('CoursesInSessionsDoesntDisplayHere'),
|
||||
'info'
|
||||
)
|
||||
);
|
||||
|
||||
$pageSize = BuyCoursesPlugin::PAGINATION_PAGE_SIZE;
|
||||
$currentPage = isset($_GET['page']) ? (int) $_GET['page'] : 1;
|
||||
$first = $pageSize * ($currentPage - 1);
|
||||
|
||||
// breadcrumbs
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_PLUGIN_PATH).'buycourses/index.php',
|
||||
'name' => $plugin->get_lang('plugin_title'),
|
||||
];
|
||||
|
||||
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_PLUGIN_PATH).'buycourses/resources/css/style.css');
|
||||
|
||||
$templateName = $plugin->get_lang('Sessions');
|
||||
|
||||
$tpl = new Template($templateName);
|
||||
|
||||
$tpl->assign('product_type_course', BuyCoursesPlugin::PRODUCT_TYPE_COURSE);
|
||||
$tpl->assign('product_type_session', BuyCoursesPlugin::PRODUCT_TYPE_SESSION);
|
||||
$tpl->assign('sessions_are_included', $includeSession);
|
||||
$tpl->assign('services_are_included', $includeServices);
|
||||
$tpl->assign('tax_enable', $taxEnable);
|
||||
|
||||
$query = CoursesAndSessionsCatalog::browseSessions(null, ['start' => $first, 'length' => $pageSize], true);
|
||||
$sessions = new Paginator($query, $fetchJoinCollection = true);
|
||||
foreach ($sessions as $session) {
|
||||
$item = $plugin->getItemByProduct($session->getId(), BuyCoursesPlugin::PRODUCT_TYPE_SESSION);
|
||||
$session->buyCourseData = [];
|
||||
if ($item !== false) {
|
||||
$session->buyCourseData = $item;
|
||||
}
|
||||
}
|
||||
|
||||
$totalItems = count($sessions);
|
||||
$pagesCount = ceil($totalItems / $pageSize);
|
||||
|
||||
$pagination = BuyCoursesPlugin::returnPagination(
|
||||
api_get_self(),
|
||||
$currentPage,
|
||||
$pagesCount,
|
||||
$totalItems,
|
||||
['type' => BuyCoursesPlugin::PRODUCT_TYPE_SESSION]
|
||||
);
|
||||
|
||||
$tpl->assign('sessions', $sessions);
|
||||
$tpl->assign('session_pagination', $pagination);
|
||||
|
||||
if ($taxEnable) {
|
||||
$globalParameters = $plugin->getGlobalParameters();
|
||||
$tpl->assign('global_tax_perc', $globalParameters['global_tax_perc']);
|
||||
$tpl->assign('tax_applies_to', $globalParameters['tax_applies_to']);
|
||||
$tpl->assign('tax_name', $globalParameters['tax_name']);
|
||||
}
|
||||
|
||||
$content = $tpl->fetch('buycourses/view/list.tpl');
|
||||
|
||||
$tpl->assign('header', $templateName);
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template();
|
||||
221
plugin/buycourses/src/panel.ajax.php
Normal file
221
plugin/buycourses/src/panel.ajax.php
Normal file
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Responses to AJAX calls.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
|
||||
api_protect_admin_script(true);
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
|
||||
$paypalEnable = $plugin->get('paypal_enable');
|
||||
$commissionsEnable = $plugin->get('commissions_enable');
|
||||
|
||||
$action = isset($_GET['a']) ? $_GET['a'] : null;
|
||||
|
||||
switch ($action) {
|
||||
case 'saleInfo':
|
||||
//$saleId is only used in getSale() and is always filtered there
|
||||
$saleId = isset($_POST['id']) ? $_POST['id'] : '';
|
||||
$sale = $plugin->getSale($saleId);
|
||||
$productType = ($sale['product_type'] == 1) ? get_lang('Course') : get_lang('Session');
|
||||
$paymentType = ($sale['payment_type'] == 1) ? 'Paypal' : $plugin->get_lang('BankTransfer');
|
||||
$productInfo = ($sale['product_type'] == 1)
|
||||
? api_get_course_info_by_id($sale['product_id'])
|
||||
: api_get_session_info($sale['product_id']);
|
||||
$currency = $plugin->getSelectedCurrency();
|
||||
if ($sale['product_type'] == 1) {
|
||||
$productImage = $productInfo['course_image_large'];
|
||||
} else {
|
||||
$productImage = ($productInfo['image'])
|
||||
? $productInfo['image']
|
||||
: Template::get_icon_path('session_default.png');
|
||||
}
|
||||
|
||||
$userInfo = api_get_user_info($sale['user_id']);
|
||||
|
||||
$html = '<h2>'.$sale['product_name'].'</h2>';
|
||||
$html .= '<div class="row">';
|
||||
$html .= '<div class="col-sm-6 col-md-6">';
|
||||
$html .= '<ul>';
|
||||
$html .= '<li><b>'.$plugin->get_lang('OrderPrice').':</b> '.$sale['price'].'</li>';
|
||||
$html .= '<li><b>'.$plugin->get_lang('CurrencyType').':</b> '.$currency['iso_code'].'</li>';
|
||||
$html .= '<li><b>'.$plugin->get_lang('ProductType').':</b> '.$productType.'</li>';
|
||||
$html .= '<li><b>'.$plugin->get_lang('OrderDate').':</b> '
|
||||
.api_format_date($sale['date'], DATE_TIME_FORMAT_LONG_24H).'</li>';
|
||||
$html .= '<li><b>'.$plugin->get_lang('Buyer').':</b> '.$userInfo['complete_name'].'</li>';
|
||||
$html .= '<li><b>'.$plugin->get_lang('PaymentMethods').':</b> '.$paymentType.'</li>';
|
||||
$html .= '</ul>';
|
||||
$html .= '</div>';
|
||||
$html .= '<div class="col-sm-6 col-md-6">';
|
||||
$html .= '<img class="thumbnail" src="'.$productImage.'" >';
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
echo $html;
|
||||
break;
|
||||
case 'stats':
|
||||
$stats = [];
|
||||
$stats['completed_count'] = 0;
|
||||
$stats['completed_total_amount'] = 0;
|
||||
$stats['pending_count'] = 0;
|
||||
$stats['pending_total_amount'] = 0;
|
||||
$stats['canceled_count'] = 0;
|
||||
$stats['canceled_total_amount'] = 0;
|
||||
|
||||
$completedPayouts = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_COMPLETED);
|
||||
$pendingPayouts = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_PENDING);
|
||||
$canceledPayouts = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_CANCELED);
|
||||
$currency = $plugin->getSelectedCurrency();
|
||||
|
||||
foreach ($completedPayouts as $completed) {
|
||||
$stats['completed_count'] = count($completedPayouts);
|
||||
$stats['completed_total_amount'] += $completed['commission'];
|
||||
$stats['completed_total_amount'] = number_format($stats['completed_total_amount'], 2);
|
||||
}
|
||||
|
||||
foreach ($pendingPayouts as $pending) {
|
||||
$stats['pending_count'] = count($pendingPayouts);
|
||||
$stats['pending_total_amount'] += $pending['commission'];
|
||||
$stats['pending_total_amount'] = number_format($stats['pending_total_amount'], 2);
|
||||
}
|
||||
|
||||
foreach ($canceledPayouts as $canceled) {
|
||||
$stats['canceled_count'] = count($canceledPayouts);
|
||||
$stats['canceled_total_amount'] += $canceled['commission'];
|
||||
$stats['canceled_total_amount'] = number_format($stats['canceled_total_amount'], 2);
|
||||
}
|
||||
|
||||
$html = '
|
||||
<div class="row">
|
||||
<p>
|
||||
<ul>
|
||||
<li>
|
||||
'.get_plugin_lang("PayoutsTotalCompleted", "BuyCoursesPlugin").'
|
||||
<b>'.$stats['completed_count'].'</b> - '.get_plugin_lang("TotalAmount", "BuyCoursesPlugin").'
|
||||
<b>'.$stats['completed_total_amount'].' '.$currency['iso_code'].'</b>
|
||||
</li>
|
||||
<li>'.get_plugin_lang("PayoutsTotalPending", "BuyCoursesPlugin").'
|
||||
<b>'.$stats['pending_count'].'</b> - '.get_plugin_lang("TotalAmount", "BuyCoursesPlugin").'
|
||||
<b>'.$stats['pending_total_amount'].' '.$currency['iso_code'].'</b>
|
||||
</li>
|
||||
<li>'.get_plugin_lang("PayoutsTotalCanceled", "BuyCoursesPlugin").'
|
||||
<b>'.$stats['canceled_count'].'</b> - '.get_plugin_lang("TotalAmount", "BuyCoursesPlugin").'
|
||||
<b>'.$stats['canceled_total_amount'].' '.$currency['iso_code'].'</b>
|
||||
</li>
|
||||
</ul>
|
||||
</p>
|
||||
</div>
|
||||
';
|
||||
echo $html;
|
||||
break;
|
||||
case 'processPayout':
|
||||
if (api_is_anonymous()) {
|
||||
break;
|
||||
}
|
||||
|
||||
$html = '';
|
||||
$allPays = [];
|
||||
$totalAccounts = 0;
|
||||
$totalPayout = 0;
|
||||
$payouts = isset($_POST['payouts']) ? $_POST['payouts'] : '';
|
||||
|
||||
if (!$payouts) {
|
||||
echo Display::return_message(get_plugin_lang("SelectOptionToProceed", "BuyCoursesPlugin"), 'error', false);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ($payouts as $index => $id) {
|
||||
$allPays[] = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_PENDING, $id);
|
||||
}
|
||||
|
||||
foreach ($allPays as $payout) {
|
||||
$totalPayout += number_format($payout['commission'], 2);
|
||||
$totalAccounts++;
|
||||
}
|
||||
|
||||
$currentCurrency = $plugin->getSelectedCurrency();
|
||||
|
||||
$isoCode = $currentCurrency['iso_code'];
|
||||
|
||||
$html .= '<p>'.get_plugin_lang("VerifyTotalAmountToProceedPayout", "BuyCoursesPlugin").'</p>';
|
||||
$html .= '
|
||||
<p>
|
||||
<ul>
|
||||
<li>'.get_plugin_lang("TotalAcounts", "BuyCoursesPlugin").' <b>'.$totalAccounts.'</b></li>
|
||||
<li>'.get_plugin_lang("TotalPayout", "BuyCoursesPlugin").' <b>'.$isoCode.' '.$totalPayout.'</b></li>
|
||||
</ul>
|
||||
</p>
|
||||
<p>'.get_plugin_lang("CautionThisProcessCantBeCanceled", "BuyCoursesPlugin").'</p>
|
||||
<br /><br />
|
||||
<div id="spinner" class="text-center"></div>
|
||||
';
|
||||
|
||||
echo $html;
|
||||
break;
|
||||
|
||||
case 'proceedPayout':
|
||||
if (api_is_anonymous()) {
|
||||
break;
|
||||
}
|
||||
|
||||
$paypalParams = $plugin->getPaypalParams();
|
||||
$pruebas = $paypalParams['sandbox'] == 1;
|
||||
$paypalUsername = $paypalParams['username'];
|
||||
$paypalPassword = $paypalParams['password'];
|
||||
$paypalSignature = $paypalParams['signature'];
|
||||
require_once "paypalfunctions.php";
|
||||
$allPayouts = [];
|
||||
$totalAccounts = 0;
|
||||
$totalPayout = 0;
|
||||
|
||||
$payouts = isset($_POST['payouts']) ? $_POST['payouts'] : '';
|
||||
|
||||
if (!$payouts) {
|
||||
echo Display::return_message(get_plugin_lang("SelectOptionToProceed", "BuyCoursesPlugin"), 'error', false);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ($payouts as $index => $id) {
|
||||
$allPayouts[] = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_PENDING, $id);
|
||||
}
|
||||
|
||||
$currentCurrency = $plugin->getSelectedCurrency();
|
||||
|
||||
$isoCode = $currentCurrency['iso_code'];
|
||||
|
||||
$result = MassPayment($allPayouts, $isoCode);
|
||||
|
||||
if ($result['ACK'] === 'Success') {
|
||||
foreach ($allPayouts as $payout) {
|
||||
$plugin->setStatusPayouts($payout['id'], BuyCoursesPlugin::PAYOUT_STATUS_COMPLETED);
|
||||
}
|
||||
echo Display::return_message(get_plugin_lang("PayoutSuccess", "BuyCoursesPlugin"), 'success', false);
|
||||
} else {
|
||||
echo Display::return_message(
|
||||
'<b>'.$result['L_SEVERITYCODE0'].' '.$result['L_ERRORCODE0'].'</b> - '
|
||||
.$result['L_SHORTMESSAGE0'].'<br /><ul><li>'.$result['L_LONGMESSAGE0'].'</li></ul>',
|
||||
'error',
|
||||
false
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'cancelPayout':
|
||||
if (api_is_anonymous()) {
|
||||
break;
|
||||
}
|
||||
|
||||
$payoutId = isset($_POST['id']) ? $_POST['id'] : '';
|
||||
$plugin->setStatusPayouts($payoutId, BuyCoursesPlugin::PAYOUT_STATUS_CANCELED);
|
||||
echo '';
|
||||
break;
|
||||
}
|
||||
exit;
|
||||
538
plugin/buycourses/src/paymentsetup.php
Normal file
538
plugin/buycourses/src/paymentsetup.php
Normal file
@@ -0,0 +1,538 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Configuration page for payment methods for the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
|
||||
api_protect_admin_script(true);
|
||||
|
||||
$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');
|
||||
$stripeEnable = $plugin->get('stripe_enable') === 'true';
|
||||
$cecabankEnable = $plugin->get('cecabank_enable') === 'true';
|
||||
|
||||
if (isset($_GET['action'], $_GET['id'])) {
|
||||
if ($_GET['action'] == 'delete_taccount') {
|
||||
$plugin->deleteTransferAccount($_GET['id']);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('ItemRemoved'), 'success')
|
||||
);
|
||||
|
||||
header('Location: '.api_get_self());
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$globalSettingForm = new FormValidator('currency');
|
||||
|
||||
if ($globalSettingForm->validate()) {
|
||||
$globalSettingFormValues = $globalSettingForm->getSubmitValues();
|
||||
|
||||
$plugin->saveCurrency($globalSettingFormValues['currency']);
|
||||
unset($globalSettingFormValues['currency']);
|
||||
$plugin->saveGlobalParameters($globalSettingFormValues);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('Saved'), 'success')
|
||||
);
|
||||
|
||||
header('Location:'.api_get_self());
|
||||
exit;
|
||||
}
|
||||
|
||||
$currencies = $plugin->getCurrencies();
|
||||
|
||||
$currencySelect = $globalSettingForm->addSelect(
|
||||
'currency',
|
||||
[
|
||||
$plugin->get_lang('CurrencyType'),
|
||||
$plugin->get_lang('InfoCurrency'),
|
||||
],
|
||||
[get_lang('Select')]
|
||||
);
|
||||
|
||||
foreach ($currencies as $currency) {
|
||||
$currencyText = implode(
|
||||
' => ',
|
||||
[
|
||||
$currency['country_name'],
|
||||
$currency['iso_code'],
|
||||
]
|
||||
);
|
||||
$currencyValue = $currency['id'];
|
||||
$currencySelect->addOption($currencyText, $currencyValue);
|
||||
|
||||
if ($currency['status']) {
|
||||
$currencySelect->setSelected($currencyValue);
|
||||
}
|
||||
}
|
||||
|
||||
$globalSettingForm->addTextarea(
|
||||
'terms_and_conditions',
|
||||
[
|
||||
get_lang('TermsAndConditions'),
|
||||
$plugin->get_lang('WriteHereTheTermsAndConditionsOfYourECommerce'),
|
||||
]
|
||||
);
|
||||
|
||||
$globalSettingForm->addElement(
|
||||
'text',
|
||||
'sale_email',
|
||||
$plugin->get_lang('SaleEmail')
|
||||
);
|
||||
|
||||
$taxEnable = $plugin->get('tax_enable') === 'true';
|
||||
$invoicingEnable = $plugin->get('invoicing_enable') === 'true';
|
||||
|
||||
if ($taxEnable) {
|
||||
$globalSettingForm->addHtml('<hr/>');
|
||||
|
||||
$globalSettingForm->addElement(
|
||||
'number',
|
||||
'global_tax_perc',
|
||||
[$plugin->get_lang('GlobalTaxPerc'), $plugin->get_lang('GlobalTaxPercDescription'), '%'],
|
||||
['step' => 1]
|
||||
);
|
||||
|
||||
$taxAppliesTo = $plugin->getTaxAppliesTo();
|
||||
|
||||
$taxTypeSelect = $globalSettingForm->addSelect(
|
||||
'tax_applies_to',
|
||||
$plugin->get_lang('TaxAppliesTo'),
|
||||
[get_lang('Select')]
|
||||
);
|
||||
|
||||
foreach ($taxAppliesTo as $key => $value) {
|
||||
$optionText = $value;
|
||||
$optionyValue = $key;
|
||||
|
||||
$taxTypeSelect->addOption($optionText, $optionyValue);
|
||||
}
|
||||
|
||||
$globalSettingForm->addElement(
|
||||
'text',
|
||||
'tax_name',
|
||||
$plugin->get_lang('TaxNameCustom'),
|
||||
['placeholder' => $plugin->get_lang('TaxNameExamples')]
|
||||
);
|
||||
}
|
||||
|
||||
if ($invoicingEnable) {
|
||||
$globalSettingForm->addHtml('<hr/>');
|
||||
|
||||
$globalSettingForm->addElement(
|
||||
'text',
|
||||
'seller_name',
|
||||
$plugin->get_lang('SellerName')
|
||||
);
|
||||
|
||||
$globalSettingForm->addElement(
|
||||
'text',
|
||||
'seller_id',
|
||||
$plugin->get_lang('SellerId')
|
||||
);
|
||||
|
||||
$globalSettingForm->addElement(
|
||||
'text',
|
||||
'seller_address',
|
||||
$plugin->get_lang('SellerAddress')
|
||||
);
|
||||
|
||||
$globalSettingForm->addElement(
|
||||
'text',
|
||||
'seller_email',
|
||||
$plugin->get_lang('SellerEmail')
|
||||
);
|
||||
|
||||
$globalSettingForm->addElement(
|
||||
'number',
|
||||
'next_number_invoice',
|
||||
[$plugin->get_lang('NextNumberInvoice'), $plugin->get_lang('NextNumberInvoiceDescription')],
|
||||
['step' => 1]
|
||||
);
|
||||
|
||||
$globalSettingForm->addElement(
|
||||
'text',
|
||||
'invoice_series',
|
||||
[$plugin->get_lang('InvoiceSeries'), $plugin->get_lang('InvoiceSeriesDescription')]
|
||||
);
|
||||
}
|
||||
|
||||
$globalSettingForm->addButtonSave(get_lang('Save'));
|
||||
$globalSettingForm->setDefaults($plugin->getGlobalParameters());
|
||||
|
||||
$termsAndConditionsForm = new FormValidator('termsconditions');
|
||||
|
||||
$paypalForm = new FormValidator('paypal');
|
||||
|
||||
if ($paypalForm->validate()) {
|
||||
$paypalFormValues = $paypalForm->getSubmitValues();
|
||||
|
||||
$plugin->savePaypalParams($paypalFormValues);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('Saved'), 'success')
|
||||
);
|
||||
|
||||
header('Location:'.api_get_self());
|
||||
exit;
|
||||
}
|
||||
|
||||
$paypalForm->addText(
|
||||
'username',
|
||||
$plugin->get_lang('ApiUsername'),
|
||||
false,
|
||||
['cols-size' => [3, 8, 1]]
|
||||
);
|
||||
$paypalForm->addText(
|
||||
'password',
|
||||
$plugin->get_lang('ApiPassword'),
|
||||
false,
|
||||
['cols-size' => [3, 8, 1]]
|
||||
);
|
||||
$paypalForm->addText(
|
||||
'signature',
|
||||
$plugin->get_lang('ApiSignature'),
|
||||
false,
|
||||
['cols-size' => [3, 8, 1]]
|
||||
);
|
||||
$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');
|
||||
|
||||
if ($commissionForm->validate()) {
|
||||
$commissionFormValues = $commissionForm->getSubmitValues();
|
||||
|
||||
$plugin->updateCommission($commissionFormValues);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('Saved'), 'success')
|
||||
);
|
||||
|
||||
header('Location:'.api_get_self());
|
||||
exit;
|
||||
}
|
||||
|
||||
$commissionForm->addElement(
|
||||
'number',
|
||||
'commission',
|
||||
[$plugin->get_lang('Commission'), null, '%'],
|
||||
['step' => 1, 'cols-size' => [3, 7, 1], 'min' => 0, 'max' => 100]
|
||||
);
|
||||
|
||||
$commissionForm->addButtonSave(get_lang('Save'));
|
||||
$commissionForm->setDefaults($plugin->getPlatformCommission());
|
||||
|
||||
$transferForm = new FormValidator('transfer_account');
|
||||
|
||||
if ($transferForm->validate()) {
|
||||
$transferFormValues = $transferForm->getSubmitValues();
|
||||
|
||||
$plugin->saveTransferAccount($transferFormValues);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('Saved'), 'success')
|
||||
);
|
||||
|
||||
header('Location:'.api_get_self());
|
||||
exit;
|
||||
}
|
||||
|
||||
$transferForm->addText(
|
||||
'tname',
|
||||
get_lang('Name'),
|
||||
false,
|
||||
['cols-size' => [3, 8, 1]]
|
||||
);
|
||||
$transferForm->addText(
|
||||
'taccount',
|
||||
$plugin->get_lang('BankAccount'),
|
||||
false,
|
||||
['cols-size' => [3, 8, 1]]
|
||||
);
|
||||
$transferForm->addText(
|
||||
'tswift',
|
||||
[$plugin->get_lang('SWIFT'), $plugin->get_lang('SWIFT_help')],
|
||||
false,
|
||||
['cols-size' => [3, 8, 1]]
|
||||
);
|
||||
$transferForm->addButtonCreate(get_lang('Add'));
|
||||
|
||||
$transferAccounts = $plugin->getTransferAccounts();
|
||||
|
||||
$transferInfoForm = new FormValidator('transfer_info');
|
||||
|
||||
if ($transferInfoForm->validate()) {
|
||||
$transferInfoFormValues = $transferInfoForm->getSubmitValues();
|
||||
|
||||
$plugin->saveTransferInfoEmail($transferInfoFormValues);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('Saved'), 'success')
|
||||
);
|
||||
|
||||
header('Location:'.api_get_self());
|
||||
exit;
|
||||
}
|
||||
$transferInfoForm->addHtmlEditor(
|
||||
'tinfo_email_extra',
|
||||
$plugin->get_lang('InfoEmailExtra'),
|
||||
false,
|
||||
false,
|
||||
['ToolbarSet' => 'Minimal']
|
||||
);
|
||||
$transferInfoForm->addButtonCreate(get_lang('Save'));
|
||||
$transferInfoForm->setDefaults($plugin->getTransferInfoExtra());
|
||||
|
||||
// Culqi main configuration
|
||||
|
||||
$culqiForm = new FormValidator('culqi_config');
|
||||
|
||||
if ($culqiForm->validate()) {
|
||||
$culqiFormValues = $culqiForm->getSubmitValues();
|
||||
|
||||
$plugin->saveCulqiParameters($culqiFormValues);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('Saved'), 'success')
|
||||
);
|
||||
|
||||
header('Location:'.api_get_self());
|
||||
exit;
|
||||
}
|
||||
|
||||
$culqiForm->addText(
|
||||
'commerce_code',
|
||||
$plugin->get_lang('CommerceCode'),
|
||||
false,
|
||||
['cols-size' => [3, 8, 1]]
|
||||
);
|
||||
$culqiForm->addText(
|
||||
'api_key',
|
||||
$plugin->get_lang('ApiPassword'),
|
||||
false,
|
||||
['cols-size' => [3, 8, 1]]
|
||||
);
|
||||
$culqiForm->addCheckBox('integration', null, $plugin->get_lang('Sandbox'));
|
||||
$culqiForm->addButtonSave(get_lang('Save'));
|
||||
$culqiForm->setDefaults($plugin->getCulqiParams());
|
||||
|
||||
// Stripe main configuration
|
||||
|
||||
$stripeForm = new FormValidator('stripe_config');
|
||||
|
||||
if ($stripeForm->validate()) {
|
||||
$stripeFormValues = $stripeForm->getSubmitValues();
|
||||
|
||||
$plugin->saveStripeParameters($stripeFormValues);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('Saved'), 'success')
|
||||
);
|
||||
|
||||
header('Location:'.api_get_self());
|
||||
exit;
|
||||
}
|
||||
|
||||
$stripeForm->addText(
|
||||
'account_id',
|
||||
$plugin->get_lang('StripeAccountId'),
|
||||
false,
|
||||
['cols-size' => [3, 8, 1]]
|
||||
);
|
||||
$stripeForm->addText(
|
||||
'secret_key',
|
||||
$plugin->get_lang('StripeSecret'),
|
||||
false,
|
||||
['cols-size' => [3, 8, 1]]
|
||||
);
|
||||
$stripeForm->addText(
|
||||
'endpoint_secret',
|
||||
$plugin->get_lang('StripeEndpointSecret'),
|
||||
false,
|
||||
['cols-size' => [3, 8, 1]]
|
||||
);
|
||||
$stripeForm->addButtonSave(get_lang('Save'));
|
||||
$stripeForm->setDefaults($plugin->getStripeParams());
|
||||
|
||||
// Cecabank main configuration
|
||||
|
||||
$cecabankForm = new FormValidator('cecabank_config');
|
||||
|
||||
if ($cecabankForm->validate()) {
|
||||
$cecabankFormValues = $cecabankForm->getSubmitValues();
|
||||
|
||||
$plugin->saveCecabankParameters($cecabankFormValues);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('Saved'), 'success')
|
||||
);
|
||||
|
||||
header('Location:'.api_get_self());
|
||||
exit;
|
||||
}
|
||||
|
||||
$cecabankForm->addText(
|
||||
'crypto_key',
|
||||
$plugin->get_lang('CecaSecret'),
|
||||
false,
|
||||
['cols-size' => [3, 8, 1]]
|
||||
);
|
||||
$cecabankForm->addText(
|
||||
'url',
|
||||
$plugin->get_lang('CecaUrl'),
|
||||
false,
|
||||
['cols-size' => [3, 8, 1]]
|
||||
);
|
||||
$cecabankForm->addText(
|
||||
'merchant_id',
|
||||
$plugin->get_lang('CecaMerchanId'),
|
||||
false,
|
||||
['cols-size' => [3, 8, 1]]
|
||||
);
|
||||
$cecabankForm->addText(
|
||||
'acquirer_bin',
|
||||
$plugin->get_lang('CecaAcquirerId'),
|
||||
false,
|
||||
['cols-size' => [3, 8, 1]]
|
||||
);
|
||||
$cecabankForm->addText(
|
||||
'terminal_id',
|
||||
$plugin->get_lang('CecaTerminalId'),
|
||||
false,
|
||||
['cols-size' => [3, 8, 1]]
|
||||
);
|
||||
$cecabankForm->addText(
|
||||
'cypher',
|
||||
$plugin->get_lang('CecaCypher'),
|
||||
false,
|
||||
['cols-size' => [3, 8, 1]]
|
||||
);
|
||||
$cecabankForm->addText(
|
||||
'exponent',
|
||||
$plugin->get_lang('CecaExponent'),
|
||||
false,
|
||||
['cols-size' => [3, 8, 1]]
|
||||
);
|
||||
$cecabankForm->addText(
|
||||
'supported_payment',
|
||||
$plugin->get_lang('CecaSupportedPayment'),
|
||||
false,
|
||||
['cols-size' => [3, 8, 1]]
|
||||
);
|
||||
$cecabankForm->addButtonSave(get_lang('Save'));
|
||||
$cecabankForm->setDefaults($plugin->getCecabankParams());
|
||||
|
||||
// breadcrumbs
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_PLUGIN_PATH).'buycourses/index.php',
|
||||
'name' => $plugin->get_lang('plugin_title'),
|
||||
];
|
||||
|
||||
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_PLUGIN_PATH).'buycourses/resources/css/style.css');
|
||||
|
||||
$templateName = $plugin->get_lang('PaymentsConfiguration');
|
||||
$tpl = new Template($templateName);
|
||||
$tpl->assign('header', $templateName);
|
||||
$tpl->assign('global_config_form', $globalSettingForm->returnForm());
|
||||
$tpl->assign('paypal_form', $paypalForm->returnForm());
|
||||
$tpl->assign('commission_form', $commissionForm->returnForm());
|
||||
$tpl->assign('transfer_form', $transferForm->returnForm());
|
||||
$tpl->assign('transfer_info_form', $transferInfoForm->returnForm());
|
||||
$tpl->assign('culqi_form', $culqiForm->returnForm());
|
||||
$tpl->assign('transfer_accounts', $transferAccounts);
|
||||
$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);
|
||||
$tpl->assign('stripe_enable', $stripeEnable);
|
||||
$tpl->assign('stripe_form', $stripeForm->returnForm());
|
||||
$tpl->assign('cecabank_enable', $cecabankEnable);
|
||||
$tpl->assign('cecabank_form', $cecabankForm->returnForm());
|
||||
|
||||
$content = $tpl->fetch('buycourses/view/paymentsetup.tpl');
|
||||
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template();
|
||||
65
plugin/buycourses/src/payout_panel.php
Normal file
65
plugin/buycourses/src/payout_panel.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* User Panel.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
/**
|
||||
* Initialization.
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$includeSessions = $plugin->get('include_sessions') === 'true';
|
||||
|
||||
$userInfo = api_get_user_info();
|
||||
|
||||
$payouts = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_COMPLETED, 0, $userInfo['id']);
|
||||
|
||||
$payoutList = [];
|
||||
|
||||
foreach ($payouts as $payout) {
|
||||
$payoutList[] = [
|
||||
'id' => $payout['id'],
|
||||
'sale_id' => $payout['sale_id'],
|
||||
'reference' => $payout['sale_reference'],
|
||||
'date' => api_format_date($payout['date'], DATE_TIME_FORMAT_LONG_24H),
|
||||
'payout_date' => ($payout['payout_date'] === '0000-00-00 00:00:00')
|
||||
? '-'
|
||||
: api_format_date($payout['payout_date'], DATE_TIME_FORMAT_LONG_24H),
|
||||
'currency' => $payout['iso_code'],
|
||||
'price' => $payout['item_price'],
|
||||
'commission' => $payout['commission'],
|
||||
'paypal_account' => $payout['paypal_account'],
|
||||
'status' => $payout['status'],
|
||||
];
|
||||
}
|
||||
|
||||
$toolbar = Display::toolbarButton(
|
||||
$plugin->get_lang('CourseListOnSale'),
|
||||
'course_catalog.php',
|
||||
'search-plus',
|
||||
'primary',
|
||||
['title' => $plugin->get_lang('CourseListOnSale')]
|
||||
);
|
||||
|
||||
$templateName = get_lang('TabsDashboard');
|
||||
|
||||
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_PLUGIN_PATH).'buycourses/resources/css/style.css');
|
||||
|
||||
$tpl = new Template($templateName);
|
||||
$tpl->assign('showing_courses', true);
|
||||
$tpl->assign('sessions_are_included', $includeSessions);
|
||||
$tpl->assign('payout_list', $payoutList);
|
||||
|
||||
$content = $tpl->fetch('buycourses/view/payout_panel.tpl');
|
||||
|
||||
$tpl->assign(
|
||||
'actions',
|
||||
Display::toolbarAction('toolbar', [$toolbar])
|
||||
);
|
||||
$tpl->assign('header', $templateName);
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template();
|
||||
94
plugin/buycourses/src/payout_report.php
Normal file
94
plugin/buycourses/src/payout_report.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
/* For license terms, see /license.txt */
|
||||
/**
|
||||
* List of pending payments of the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
//Initialization
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
|
||||
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_PLUGIN_PATH).'buycourses/resources/css/style.css');
|
||||
$htmlHeadXtra[] =
|
||||
'<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js"></script>';
|
||||
|
||||
api_protect_admin_script(true);
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
|
||||
$commissionsEnable = $plugin->get('commissions_enable');
|
||||
$payoutStatuses = $plugin->getPayoutStatuses();
|
||||
$selectedStatus = isset($_GET['status']) ? $_GET['status'] : BuyCoursesPlugin::SALE_STATUS_COMPLETED;
|
||||
|
||||
if ($commissionsEnable !== "true") {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$form = new FormValidator('search', 'get');
|
||||
|
||||
if ($form->validate()) {
|
||||
$selectedStatus = $form->getSubmitValue('status');
|
||||
|
||||
if ($selectedStatus === false) {
|
||||
$selectedStatus = BuyCoursesPlugin::PAYOUT_STATUS_PENDING;
|
||||
}
|
||||
}
|
||||
|
||||
$form->addSelect('status', $plugin->get_lang('PayoutStatus'), $payoutStatuses);
|
||||
$form->addButtonFilter(get_lang('Search'));
|
||||
$form->setDefaults([
|
||||
'status' => $selectedStatus,
|
||||
]);
|
||||
|
||||
switch ($selectedStatus) {
|
||||
case '2':
|
||||
$payouts = $plugin->getPayouts($selectedStatus);
|
||||
|
||||
break;
|
||||
case '1':
|
||||
$payouts = $plugin->getPayouts($selectedStatus);
|
||||
|
||||
break;
|
||||
case '0':
|
||||
default:
|
||||
$payouts = $plugin->getPayouts();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$payoutList = [];
|
||||
|
||||
foreach ($payouts as $payout) {
|
||||
$payoutList[] = [
|
||||
'id' => $payout['id'],
|
||||
'sale_id' => $payout['sale_id'],
|
||||
'reference' => $payout['sale_reference'],
|
||||
'date' => api_format_date($payout['date'], DATE_TIME_FORMAT_LONG_24H),
|
||||
'payout_date' => ($payout['payout_date'] === '0000-00-00 00:00:00')
|
||||
? '-'
|
||||
: api_format_date($payout['payout_date'], DATE_TIME_FORMAT_LONG_24H),
|
||||
'currency' => $payout['iso_code'],
|
||||
'price' => $payout['item_price'],
|
||||
'commission' => $payout['commission'],
|
||||
'beneficiary' => api_get_person_name($payout['firstname'], $payout['lastname']),
|
||||
'paypal_account' => $payout['paypal_account'],
|
||||
'status' => $payout['status'],
|
||||
];
|
||||
}
|
||||
|
||||
$templateName = $plugin->get_lang('PayoutReport');
|
||||
|
||||
$template = new Template($templateName);
|
||||
|
||||
$template->assign('form', $form->returnForm());
|
||||
$template->assign('payout_list', $payoutList);
|
||||
$template->assign('selected_status', $selectedStatus);
|
||||
|
||||
$content = $template->fetch('buycourses/view/payout_report.tpl');
|
||||
|
||||
$template->assign('header', $templateName);
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
55
plugin/buycourses/src/paypal_payout.php
Normal file
55
plugin/buycourses/src/paypal_payout.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* List page for Paypal Payout for the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
/**
|
||||
* Initialization.
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
|
||||
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_PLUGIN_PATH).'buycourses/resources/css/style.css');
|
||||
|
||||
api_protect_admin_script(true);
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
|
||||
$paypalEnable = $plugin->get('paypal_enable');
|
||||
$commissionsEnable = $plugin->get('commissions_enable');
|
||||
|
||||
if ($paypalEnable !== "true" && $commissionsEnable !== "true") {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$payouts = $plugin->getPayouts();
|
||||
|
||||
$payoutList = [];
|
||||
|
||||
foreach ($payouts as $payout) {
|
||||
$payoutList[] = [
|
||||
'id' => $payout['id'],
|
||||
'reference' => $payout['sale_reference'],
|
||||
'date' => api_format_date($payout['date'], DATE_TIME_FORMAT_LONG_24H),
|
||||
'currency' => $payout['iso_code'],
|
||||
'price' => $payout['item_price'],
|
||||
'commission' => $payout['commission'],
|
||||
'paypal_account' => $payout['paypal_account'],
|
||||
];
|
||||
}
|
||||
|
||||
$templateName = $plugin->get_lang('PaypalPayoutCommissions');
|
||||
|
||||
$template = new Template($templateName);
|
||||
|
||||
$template->assign('payout_list', $payoutList);
|
||||
|
||||
$content = $template->fetch('buycourses/view/paypal_payout.tpl');
|
||||
|
||||
$template->assign('header', $templateName);
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
432
plugin/buycourses/src/paypalfunctions.php
Normal file
432
plugin/buycourses/src/paypalfunctions.php
Normal file
@@ -0,0 +1,432 @@
|
||||
<?php
|
||||
/*
|
||||
* PayPal API Module
|
||||
*
|
||||
* Defines all the global variables and the wrapper functions
|
||||
*/
|
||||
$PROXY_HOST = '127.0.0.1';
|
||||
$PROXY_PORT = '808';
|
||||
|
||||
$SandboxFlag = $pruebas;
|
||||
|
||||
/**
|
||||
* PayPal API Credentials
|
||||
* Replace <API_USERNAME> with your API Username
|
||||
* Replace <API_PASSWORD> with your API Password
|
||||
* Replace <API_SIGNATURE> with your Signature.
|
||||
*/
|
||||
$API_UserName = $paypalUsername;
|
||||
$API_Password = $paypalPassword;
|
||||
$API_Signature = $paypalSignature;
|
||||
|
||||
// BN Code is only applicable for partners
|
||||
$sBNCode = "PP-ECWizard";
|
||||
|
||||
/**
|
||||
* Define the PayPal Redirect URLs.
|
||||
* This is the URL that the buyer is first sent to do authorize payment with their paypal account
|
||||
* change the URL depending if you are testing on the sandbox or the live PayPal site.
|
||||
*
|
||||
* For the sandbox, the URL is https://www.sandbox.paypal.com/webscr&cmd=_express-checkout&token=
|
||||
* For the live site, the URL is https://www.paypal.com/webscr&cmd=_express-checkout&token=
|
||||
*/
|
||||
if ($SandboxFlag == true) {
|
||||
$API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
|
||||
$PAYPAL_URL = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
|
||||
} else {
|
||||
$API_Endpoint = "https://api-3t.paypal.com/nvp";
|
||||
$PAYPAL_URL = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
|
||||
}
|
||||
|
||||
$USE_PROXY = false;
|
||||
$version = "93";
|
||||
|
||||
if (session_id() == "") {
|
||||
session_start();
|
||||
}
|
||||
|
||||
/**
|
||||
* An express checkout transaction starts with a token, that
|
||||
* identifies to PayPal your transaction
|
||||
* In this example, when the script sees a token, the script
|
||||
* knows that the buyer has already authorized payment through
|
||||
* paypal. If no token was found, the action is to send the buyer
|
||||
* to PayPal to first authorize payment.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Purpose: Prepares the parameters for the SetExpressCheckout API Call.
|
||||
* Inputs:
|
||||
* paymentAmount: Total value of the shopping cart
|
||||
* currencyCodeType: Currency code value the PayPal API
|
||||
* paymentType: paymentType has to be one of the following values: Sale or Order or Authorization
|
||||
* returnURL: the page where buyers return to after they are done with the payment review on PayPal
|
||||
* cancelURL: the page where buyers return to when they cancel the payment review on PayPal.
|
||||
*/
|
||||
function CallShortcutExpressCheckout($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $extra)
|
||||
{
|
||||
// Construct the parameter string that describes the SetExpressCheckout API call in the shortcut implementation
|
||||
$nvpstr = "&PAYMENTREQUEST_0_AMT=".$paymentAmount;
|
||||
$nvpstr .= "&PAYMENTREQUEST_0_ITEMAMT=".$paymentAmount;
|
||||
$nvpstr .= "&PAYMENTREQUEST_0_PAYMENTACTION=".$paymentType;
|
||||
$nvpstr .= "&RETURNURL=".$returnURL;
|
||||
$nvpstr .= "&CANCELURL=".$cancelURL;
|
||||
$nvpstr .= "&PAYMENTREQUEST_0_CURRENCYCODE=".$currencyCodeType;
|
||||
$nvpstr .= $extra;
|
||||
|
||||
$_SESSION["currencyCodeType"] = $currencyCodeType;
|
||||
$_SESSION["PaymentType"] = $paymentType;
|
||||
|
||||
/**
|
||||
* Make the API call to PayPal
|
||||
* If the API call succeded, then redirect the buyer to PayPal to begin to authorize payment.
|
||||
* If an error occured, show the resulting errors.
|
||||
*/
|
||||
$resArray = hash_call("SetExpressCheckout", $nvpstr);
|
||||
$ack = strtoupper($resArray["ACK"]);
|
||||
if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") {
|
||||
$token = urldecode($resArray["TOKEN"]);
|
||||
$_SESSION['TOKEN'] = $token;
|
||||
}
|
||||
|
||||
return $resArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: Prepares the parameters for the SetExpressCheckout API Call.
|
||||
* Inputs:
|
||||
* paymentAmount: Total value of the shopping cart
|
||||
* currencyCodeType: Currency code value the PayPal API
|
||||
* paymentType: paymentType has to be one of the following values: Sale or Order or Authorization
|
||||
* returnURL: the page where buyers return to after they are done with the payment review on PayPal
|
||||
* cancelURL: the page where buyers return to when they cancel the payment review on PayPal
|
||||
* shipToName: the Ship to name entered on the merchant's site
|
||||
* shipToStreet: the Ship to Street entered on the merchant's site
|
||||
* shipToCity: the Ship to City entered on the merchant's site
|
||||
* shipToState: the Ship to State entered on the merchant's site
|
||||
* shipToCountryCode: the Code for Ship to Country entered on the merchant's site
|
||||
* shipToZip: the Ship to ZipCode entered on the merchant's site
|
||||
* shipToStreet2: the Ship to Street2 entered on the merchant's site
|
||||
* phoneNum: the phoneNum entered on the merchant's site.
|
||||
*/
|
||||
function CallMarkExpressCheckout(
|
||||
$paymentAmount,
|
||||
$currencyCodeType,
|
||||
$paymentType,
|
||||
$returnURL,
|
||||
$cancelURL,
|
||||
$shipToName,
|
||||
$shipToStreet,
|
||||
$shipToCity,
|
||||
$shipToState,
|
||||
$shipToCountryCode,
|
||||
$shipToZip,
|
||||
$shipToStreet2,
|
||||
$phoneNum
|
||||
) {
|
||||
// Construct the parameter string that describes the SetExpressCheckout API call in the shortcut implementation
|
||||
$nvpstr = "&PAYMENTREQUEST_0_AMT=".$paymentAmount;
|
||||
$nvpstr = $nvpstr."&PAYMENTREQUEST_0_PAYMENTACTION=".$paymentType;
|
||||
$nvpstr = $nvpstr."&RETURNURL=".$returnURL;
|
||||
$nvpstr = $nvpstr."&CANCELURL=".$cancelURL;
|
||||
$nvpstr = $nvpstr."&PAYMENTREQUEST_0_CURRENCYCODE=".$currencyCodeType;
|
||||
$nvpstr = $nvpstr."&ADDROVERRIDE=1";
|
||||
$nvpstr = $nvpstr."&PAYMENTREQUEST_0_SHIPTONAME=".$shipToName;
|
||||
$nvpstr = $nvpstr."&PAYMENTREQUEST_0_SHIPTOSTREET=".$shipToStreet;
|
||||
$nvpstr = $nvpstr."&PAYMENTREQUEST_0_SHIPTOSTREET2=".$shipToStreet2;
|
||||
$nvpstr = $nvpstr."&PAYMENTREQUEST_0_SHIPTOCITY=".$shipToCity;
|
||||
$nvpstr = $nvpstr."&PAYMENTREQUEST_0_SHIPTOSTATE=".$shipToState;
|
||||
$nvpstr = $nvpstr."&PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE=".$shipToCountryCode;
|
||||
$nvpstr = $nvpstr."&PAYMENTREQUEST_0_SHIPTOZIP=".$shipToZip;
|
||||
$nvpstr = $nvpstr."&PAYMENTREQUEST_0_SHIPTOPHONENUM=".$phoneNum;
|
||||
|
||||
$_SESSION["currencyCodeType"] = $currencyCodeType;
|
||||
$_SESSION["PaymentType"] = $paymentType;
|
||||
|
||||
/**
|
||||
* Make the API call to PayPal
|
||||
* If the API call succeded, then redirect the buyer to PayPal to begin to authorize payment.
|
||||
* If an error occured, show the resulting errors.
|
||||
*/
|
||||
$resArray = hash_call("SetExpressCheckout", $nvpstr);
|
||||
$ack = strtoupper($resArray["ACK"]);
|
||||
if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") {
|
||||
$token = urldecode($resArray["TOKEN"]);
|
||||
$_SESSION['TOKEN'] = $token;
|
||||
}
|
||||
|
||||
return $resArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: Prepares the parameters for the GetExpressCheckoutDetails API Call.
|
||||
*
|
||||
* Inputs:
|
||||
* None
|
||||
* Returns:
|
||||
* The NVP Collection object of the GetExpressCheckoutDetails Call Response.
|
||||
*/
|
||||
function GetShippingDetails($token)
|
||||
{
|
||||
/**
|
||||
* At this point, the buyer has completed authorizing the payment
|
||||
* at PayPal. The function will call PayPal to obtain the details
|
||||
* of the authorization, including any shipping information of the
|
||||
* buyer. Remember, the authorization is not a completed transaction
|
||||
* at this state - the buyer still needs an additional step to finalize
|
||||
* the transaction.
|
||||
*
|
||||
* Build a second API request to PayPal, using the token as the
|
||||
* ID to get the details on the payment authorization
|
||||
*/
|
||||
$nvpstr = "&TOKEN=".$token;
|
||||
|
||||
/**
|
||||
* Make the API call and store the results in an array.
|
||||
* If the call was a success, show the authorization details, and provide
|
||||
* an action to complete the payment.
|
||||
* If failed, show the error.
|
||||
*/
|
||||
$resArray = hash_call("GetExpressCheckoutDetails", $nvpstr);
|
||||
$ack = strtoupper($resArray["ACK"]);
|
||||
if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") {
|
||||
$_SESSION['payer_id'] = $resArray['PAYERID'];
|
||||
}
|
||||
|
||||
return $resArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: Prepares the parameters for the GetExpressCheckoutDetails API Call.
|
||||
* Inputs:
|
||||
* sBNCode: The BN code used by PayPal to track the transactions from a given shopping cart.
|
||||
* Returns:
|
||||
* The NVP Collection object of the GetExpressCheckoutDetails Call Response.
|
||||
*/
|
||||
function ConfirmPayment($FinalPaymentAmt)
|
||||
{
|
||||
/**
|
||||
* Gather the information to make the final call to
|
||||
* finalize the PayPal payment. The variable nvpstr
|
||||
* holds the name value pairs.
|
||||
*/
|
||||
|
||||
//Format the other parameters that were stored in the session from the previous calls
|
||||
|
||||
$token = urlencode($_SESSION['TOKEN']);
|
||||
$paymentType = urlencode($_SESSION['PaymentType']);
|
||||
$currencyCodeType = urlencode($_SESSION['currencyCodeType']);
|
||||
$payerID = urlencode($_SESSION['payer_id']);
|
||||
$serverName = urlencode($_SERVER['SERVER_NAME']);
|
||||
|
||||
$nvpstr =
|
||||
'&TOKEN='.$token.'&PAYERID='.$payerID.'&PAYMENTREQUEST_0_PAYMENTACTION='.$paymentType.'&PAYMENTREQUEST_0_AMT='
|
||||
.$FinalPaymentAmt;
|
||||
$nvpstr .= '&PAYMENTREQUEST_0_CURRENCYCODE='.$currencyCodeType.'&IPADDRESS='.$serverName;
|
||||
$nvpstr = '&'.http_build_query([
|
||||
'TOKEN' => $token,
|
||||
'PAYERID' => $payerID,
|
||||
'PAYMENTACTION' => $paymentType,
|
||||
'PAYMENTREQUEST_0_AMT' => $FinalPaymentAmt,
|
||||
'PAYMENTREQUEST_0_CURRENCYCODE' => $currencyCodeType,
|
||||
'IPADDRESS' => $serverName,
|
||||
'paymentactionspecified' => 'true',
|
||||
]);
|
||||
|
||||
/**
|
||||
* Make the call to PayPal to finalize payment
|
||||
* If an error occured, show the resulting errors.
|
||||
*/
|
||||
$resArray = hash_call("DoExpressCheckoutPayment", $nvpstr);
|
||||
|
||||
/**
|
||||
* Display the API response back to the browser.
|
||||
* If the response from PayPal was a success, display the response parameters
|
||||
* If the response was an error, display the errors received using APIError.php.
|
||||
*/
|
||||
$ack = strtoupper($resArray["ACK"]);
|
||||
|
||||
return $resArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: This function makes a DoDirectPayment API call
|
||||
* Inputs:
|
||||
* paymentType: paymentType has to be one of the following values: Sale or Order or Authorization
|
||||
* paymentAmount: total value of the shopping cart
|
||||
* currencyCode: currency code value the PayPal API
|
||||
* firstName: first name as it appears on credit card
|
||||
* lastName: last name as it appears on credit card
|
||||
* street: buyer's street address line as it appears on credit card
|
||||
* city: buyer's city
|
||||
* state: buyer's state
|
||||
* countryCode: buyer's country code
|
||||
* zip: buyer's zip
|
||||
* creditCardType: buyer's credit card type (i.e. Visa, MasterCard ... )
|
||||
* creditCardNumber: buyers credit card number without any spaces, dashes or any other characters
|
||||
* expDate: credit card expiration date
|
||||
* cvv2: Card Verification Value
|
||||
* Returns:
|
||||
* The NVP Collection object of the DoDirectPayment Call Response.
|
||||
*/
|
||||
function DirectPayment(
|
||||
$paymentType,
|
||||
$paymentAmount,
|
||||
$creditCardType,
|
||||
$creditCardNumber,
|
||||
$expDate,
|
||||
$cvv2,
|
||||
$firstName,
|
||||
$lastName,
|
||||
$street,
|
||||
$city,
|
||||
$state,
|
||||
$zip,
|
||||
$countryCode,
|
||||
$currencyCode
|
||||
) {
|
||||
//Construct the parameter string that describes DoDirectPayment
|
||||
$nvpstr = "&AMT=".$paymentAmount;
|
||||
$nvpstr = $nvpstr."&CURRENCYCODE=".$currencyCode;
|
||||
$nvpstr = $nvpstr."&PAYMENTACTION=".$paymentType;
|
||||
$nvpstr = $nvpstr."&CREDITCARDTYPE=".$creditCardType;
|
||||
$nvpstr = $nvpstr."&ACCT=".$creditCardNumber;
|
||||
$nvpstr = $nvpstr."&EXPDATE=".$expDate;
|
||||
$nvpstr = $nvpstr."&CVV2=".$cvv2;
|
||||
$nvpstr = $nvpstr."&FIRSTNAME=".$firstName;
|
||||
$nvpstr = $nvpstr."&LASTNAME=".$lastName;
|
||||
$nvpstr = $nvpstr."&STREET=".$street;
|
||||
$nvpstr = $nvpstr."&CITY=".$city;
|
||||
$nvpstr = $nvpstr."&STATE=".$state;
|
||||
$nvpstr = $nvpstr."&COUNTRYCODE=".$countryCode;
|
||||
$nvpstr = $nvpstr."&IPADDRESS=".$_SERVER['REMOTE_ADDR'];
|
||||
|
||||
$resArray = hash_call("DoDirectPayment", $nvpstr);
|
||||
|
||||
return $resArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: This function makes a MassPay API call
|
||||
* Inputs:
|
||||
* Beneficiarie: Array that contains the Beneficiearie paypal account and the payout amount
|
||||
* Currency Code: The currency Iso code
|
||||
* Returns:
|
||||
* The NVP Collection object of the MassPay Call Response.
|
||||
*/
|
||||
function MassPayment(array $beneficiaries, $currencyCode)
|
||||
{
|
||||
$nvpstr = "&RECEIVERTYPE=EmailAddress";
|
||||
$nvpstr .= "&CURRENCYCODE=".$currencyCode;
|
||||
|
||||
$index = 0;
|
||||
|
||||
foreach ($beneficiaries as $beneficiary) {
|
||||
$nvpstr .= "&L_EMAIL".$index."=".$beneficiary['paypal_account'];
|
||||
$nvpstr .= "&L_AMT".$index."=".$beneficiary['commission'];
|
||||
$index++;
|
||||
}
|
||||
|
||||
$resArray = hash_call("MassPay", $nvpstr);
|
||||
|
||||
return $resArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* hash_call: Function to perform the API call to PayPal using API signature.
|
||||
*
|
||||
* @methodName is name of API method.
|
||||
* @nvpStr is nvp string.
|
||||
* returns an associtive array containing the response from the server.
|
||||
*/
|
||||
function hash_call($methodName, $nvpStr)
|
||||
{
|
||||
//declaring of global variables
|
||||
global $API_Endpoint, $version, $API_UserName, $API_Password, $API_Signature;
|
||||
global $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
|
||||
global $sBNCode;
|
||||
|
||||
//setting the curl parameters.
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
|
||||
curl_setopt($ch, CURLOPT_VERBOSE, 1);
|
||||
//turning off the server and peer verification(TrustManager Concept).
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
|
||||
//if USE_PROXY constant set to TRUE in Constants.php, then only proxy will be enabled.
|
||||
//Set proxy name to PROXY_HOST and port number to PROXY_PORT in constants.php
|
||||
if ($USE_PROXY) {
|
||||
curl_setopt($ch, CURLOPT_PROXY, $PROXY_HOST.":".$PROXY_PORT);
|
||||
}
|
||||
|
||||
//NVPRequest for submitting to server
|
||||
$nvpreq = "METHOD=".urlencode($methodName)."&VERSION=".urlencode($version).
|
||||
"&PWD=".urlencode($API_Password)."&USER=".urlencode($API_UserName).
|
||||
"&SIGNATURE=".urlencode($API_Signature).$nvpStr."&BUTTONSOURCE=".urlencode($sBNCode);
|
||||
|
||||
//setting the nvpreq as POST FIELD to curl
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
|
||||
//getting response from server
|
||||
$response = curl_exec($ch);
|
||||
//converting NVPResponse to an Associative Array
|
||||
$nvpResArray = deformatNVP($response);
|
||||
$nvpReqArray = deformatNVP($nvpreq);
|
||||
|
||||
$_SESSION['nvpReqArray'] = $nvpReqArray;
|
||||
|
||||
if (curl_errno($ch)) {
|
||||
// moving to display page to display curl errors
|
||||
$_SESSION['curl_error_no'] = curl_errno($ch);
|
||||
$_SESSION['curl_error_msg'] = curl_error($ch);
|
||||
//Execute the Error handling module to display errors.
|
||||
} else {
|
||||
//closing the curl
|
||||
curl_close($ch);
|
||||
}
|
||||
|
||||
return $nvpResArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: Redirects to PayPal.com site.
|
||||
* Inputs: NVP string.
|
||||
*/
|
||||
function RedirectToPayPal($token)
|
||||
{
|
||||
global $PAYPAL_URL;
|
||||
// Redirect to paypal.com here
|
||||
$payPalURL = $PAYPAL_URL.$token;
|
||||
header("Location: ".$payPalURL);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will take NVPString and convert it to an Associative Array and it will decode the response.
|
||||
* It is usefull to search for a particular key and displaying arrays.
|
||||
*
|
||||
* @nvpstr is NVPString.
|
||||
* @nvpArray is Associative Array.
|
||||
*/
|
||||
function deformatNVP($nvpstr)
|
||||
{
|
||||
$intial = 0;
|
||||
$nvpArray = [];
|
||||
|
||||
while (strlen($nvpstr)) {
|
||||
//postion of Key
|
||||
$keypos = strpos($nvpstr, '=');
|
||||
//position of value
|
||||
$valuepos = strpos($nvpstr, '&') ? strpos($nvpstr, '&') : strlen($nvpstr);
|
||||
/*getting the Key and Value values and storing in a Associative Array*/
|
||||
$keyval = substr($nvpstr, $intial, $keypos);
|
||||
$valval = substr($nvpstr, $keypos + 1, $valuepos - $keypos - 1);
|
||||
//decoding the respose
|
||||
$nvpArray[urldecode($keyval)] = urldecode($valval);
|
||||
$nvpstr = substr($nvpstr, $valuepos + 1, strlen($nvpstr));
|
||||
}
|
||||
|
||||
return $nvpArray;
|
||||
}
|
||||
188
plugin/buycourses/src/process.php
Normal file
188
plugin/buycourses/src/process.php
Normal file
@@ -0,0 +1,188 @@
|
||||
<?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();
|
||||
|
||||
$htmlHeadXtra[] = '<link rel="stylesheet" type="text/css" href="'.api_get_path(
|
||||
WEB_PLUGIN_PATH
|
||||
).'buycourses/resources/css/style.css"/>';
|
||||
$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';
|
||||
$tpvRedsysEnable = $plugin->get('tpv_redsys_enable') === 'true';
|
||||
$stripeEnable = $plugin->get('stripe_enable') === 'true';
|
||||
$tpvCecabankEnable = $plugin->get('cecabank_enable') === 'true';
|
||||
|
||||
if (!$paypalEnabled && !$transferEnabled && !$culqiEnabled && !$tpvRedsysEnable && !$stripeEnable && !$tpvCecabankEnable) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
if (!isset($_REQUEST['t'], $_REQUEST['i'])) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$currency = $plugin->getSelectedCurrency();
|
||||
$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']);
|
||||
|
||||
$coupon = null;
|
||||
|
||||
if (isset($_REQUEST['c'])) {
|
||||
$couponId = (int) $_REQUEST['c'];
|
||||
if ($buyingCourse) {
|
||||
$coupon = $plugin->getCoupon($couponId, BuyCoursesPlugin::PRODUCT_TYPE_COURSE, $_REQUEST['i']);
|
||||
} else {
|
||||
$coupon = $plugin->getCoupon($couponId, BuyCoursesPlugin::PRODUCT_TYPE_SESSION, $_REQUEST['i']);
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($currentUserId)) {
|
||||
Session::write('buy_course_redirect', api_get_self().'?'.$queryString);
|
||||
header('Location: '.api_get_path(WEB_CODE_PATH).'auth/inscription.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($buyingCourse) {
|
||||
$courseInfo = $plugin->getCourseInfo($_REQUEST['i'], $coupon);
|
||||
$item = $plugin->getItemByProduct($_REQUEST['i'], BuyCoursesPlugin::PRODUCT_TYPE_COURSE);
|
||||
} elseif ($buyingSession) {
|
||||
$sessionInfo = $plugin->getSessionInfo($_REQUEST['i'], $coupon);
|
||||
$item = $plugin->getItemByProduct($_REQUEST['i'], BuyCoursesPlugin::PRODUCT_TYPE_SESSION);
|
||||
}
|
||||
|
||||
$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'], $formValues['c']);
|
||||
|
||||
if ($saleId !== false) {
|
||||
$_SESSION['bc_sale_id'] = $saleId;
|
||||
|
||||
if (isset($formValues['c'])) {
|
||||
$couponSaleId = $plugin->registerCouponSale($saleId, $formValues['c']);
|
||||
if ($couponSaleId !== false) {
|
||||
$plugin->updateCouponDelivered($formValues['c']);
|
||||
$_SESSION['bc_coupon_id'] = $formValues['c'];
|
||||
}
|
||||
}
|
||||
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/process_confirm.php');
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$paymentTypesOptions = $plugin->getPaymentTypes(true);
|
||||
|
||||
$count = count($paymentTypesOptions);
|
||||
if ($count === 0) {
|
||||
$form->addHtml($plugin->get_lang('NoPaymentOptionAvailable'));
|
||||
$form->addHtml('<br />');
|
||||
$form->addHtml('<br />');
|
||||
} elseif ($count === 1) {
|
||||
// get the only array item
|
||||
foreach ($paymentTypesOptions as $type => $value) {
|
||||
$form->addHtml(sprintf($plugin->get_lang('XIsOnlyPaymentMethodAvailable'), $value));
|
||||
$form->addHtml('<br />');
|
||||
$form->addHtml('<br />');
|
||||
$form->addHidden('payment_type', $type);
|
||||
}
|
||||
} else {
|
||||
$form->addHtml(
|
||||
Display::return_message(
|
||||
$plugin->get_lang('PleaseSelectThePaymentMethodBeforeConfirmYourOrder'),
|
||||
'info'
|
||||
)
|
||||
);
|
||||
$form->addRadio('payment_type', null, $paymentTypesOptions);
|
||||
}
|
||||
|
||||
$form->addHidden('t', intval($_REQUEST['t']));
|
||||
$form->addHidden('i', intval($_REQUEST['i']));
|
||||
if ($coupon != null) {
|
||||
$form->addHidden('c', intval($coupon['id']));
|
||||
}
|
||||
$form->addButton('submit', $plugin->get_lang('ConfirmOrder'), 'check', 'success', 'btn-lg pull-right');
|
||||
|
||||
$formCoupon = new FormValidator('confirm_coupon');
|
||||
if ($formCoupon->validate()) {
|
||||
$formCouponValues = $formCoupon->getSubmitValues();
|
||||
|
||||
if (!$formCouponValues['coupon_code']) {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('NeedToAddCouponCode'), 'error', false)
|
||||
);
|
||||
header('Location:'.api_get_self().'?'.$queryString);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($buyingCourse) {
|
||||
$coupon = $plugin->getCouponByCode($formCouponValues['coupon_code'], BuyCoursesPlugin::PRODUCT_TYPE_COURSE, $_REQUEST['i']);
|
||||
} else {
|
||||
$coupon = $plugin->getCouponByCode($formCouponValues['coupon_code'], BuyCoursesPlugin::PRODUCT_TYPE_SESSION, $_REQUEST['i']);
|
||||
}
|
||||
|
||||
if ($coupon == null) {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('CouponNotValid'), 'error', false)
|
||||
);
|
||||
header('Location:'.api_get_self().'?'.$queryString);
|
||||
exit;
|
||||
}
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('CouponRedeemed'), 'success', false)
|
||||
);
|
||||
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/process.php?i='.$_REQUEST['i'].'&t='.$_REQUEST['t'].'&c='.$coupon['id']);
|
||||
|
||||
exit;
|
||||
}
|
||||
$formCoupon->addText('coupon_code', $plugin->get_lang('CouponsCode'), true);
|
||||
$formCoupon->addHidden('t', intval($_GET['t']));
|
||||
$formCoupon->addHidden('i', intval($_GET['i']));
|
||||
$formCoupon->addButton('submit', $plugin->get_lang('RedeemCoupon'), 'check', 'success', 'btn-lg pull-right');
|
||||
|
||||
// View
|
||||
$templateName = $plugin->get_lang('PaymentMethods');
|
||||
$interbreadcrumb[] = ['url' => 'course_catalog.php', 'name' => $plugin->get_lang('CourseListOnSale')];
|
||||
|
||||
$tpl = new Template($templateName);
|
||||
$tpl->assign('item_type', (int) $_GET['t']);
|
||||
$tpl->assign('buying_course', $buyingCourse);
|
||||
$tpl->assign('buying_session', $buyingSession);
|
||||
$tpl->assign('user', api_get_user_info());
|
||||
$tpl->assign('form_coupon', $formCoupon->returnForm());
|
||||
$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();
|
||||
597
plugin/buycourses/src/process_confirm.php
Normal file
597
plugin/buycourses/src/process_confirm.php
Normal file
@@ -0,0 +1,597 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Process purchase confirmation script for the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
require_once '../config.php';
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
|
||||
$saleId = $_SESSION['bc_sale_id'];
|
||||
$couponId = (!empty($_SESSION['bc_coupon_id']) ?? '');
|
||||
|
||||
if (empty($saleId)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$sale = $plugin->getSale($saleId);
|
||||
|
||||
$coupon = [];
|
||||
if (!empty($couponId)) {
|
||||
$coupon = $plugin->getCoupon($couponId, $sale['product_type'], $sale['product_id']);
|
||||
}
|
||||
|
||||
$userInfo = api_get_user_info($sale['user_id']);
|
||||
|
||||
if (empty($sale)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$currency = $plugin->getCurrency($sale['currency_id']);
|
||||
$globalParameters = $plugin->getGlobalParameters();
|
||||
|
||||
switch ($sale['payment_type']) {
|
||||
case BuyCoursesPlugin::PAYMENT_TYPE_PAYPAL:
|
||||
$paypalParams = $plugin->getPaypalParams();
|
||||
|
||||
$pruebas = $paypalParams['sandbox'] == 1;
|
||||
$paypalUsername = $paypalParams['username'];
|
||||
$paypalPassword = $paypalParams['password'];
|
||||
$paypalSignature = $paypalParams['signature'];
|
||||
|
||||
require_once "paypalfunctions.php";
|
||||
|
||||
$i = 0;
|
||||
$extra = "&L_PAYMENTREQUEST_0_NAME0={$sale['product_name']}";
|
||||
$extra .= "&L_PAYMENTREQUEST_0_AMT0={$sale['price']}";
|
||||
$extra .= "&L_PAYMENTREQUEST_0_QTY0=1";
|
||||
|
||||
$expressCheckout = CallShortcutExpressCheckout(
|
||||
$sale['price'],
|
||||
$currency['iso_code'],
|
||||
'paypal',
|
||||
api_get_path(WEB_PLUGIN_PATH).'buycourses/src/success.php',
|
||||
api_get_path(WEB_PLUGIN_PATH).'buycourses/src/error.php',
|
||||
$extra
|
||||
);
|
||||
|
||||
if ($expressCheckout["ACK"] !== 'Success') {
|
||||
$erroMessage = vsprintf(
|
||||
$plugin->get_lang('ErrorOccurred'),
|
||||
[$expressCheckout['L_ERRORCODE0'], $expressCheckout['L_LONGMESSAGE0']]
|
||||
);
|
||||
Display::addFlash(
|
||||
Display::return_message($erroMessage, 'error', false)
|
||||
);
|
||||
header('Location: ../index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!empty($globalParameters['sale_email'])) {
|
||||
$messageConfirmTemplate = new Template();
|
||||
$messageConfirmTemplate->assign('user', $userInfo);
|
||||
$messageConfirmTemplate->assign(
|
||||
'sale',
|
||||
[
|
||||
'date' => $sale['date'],
|
||||
'product' => $sale['product_name'],
|
||||
'currency' => $currency['iso_code'],
|
||||
'price' => $sale['price'],
|
||||
'reference' => $sale['reference'],
|
||||
]
|
||||
);
|
||||
|
||||
api_mail_html(
|
||||
'',
|
||||
$globalParameters['sale_email'],
|
||||
$plugin->get_lang('bc_subject'),
|
||||
$messageConfirmTemplate->fetch('buycourses/view/message_confirm.tpl')
|
||||
);
|
||||
}
|
||||
|
||||
RedirectToPayPal($expressCheckout["TOKEN"]);
|
||||
break;
|
||||
case BuyCoursesPlugin::PAYMENT_TYPE_TRANSFER:
|
||||
$buyingCourse = false;
|
||||
$buyingSession = false;
|
||||
|
||||
switch ($sale['product_type']) {
|
||||
case BuyCoursesPlugin::PRODUCT_TYPE_COURSE:
|
||||
$buyingCourse = true;
|
||||
$course = $plugin->getCourseInfo($sale['product_id'], $coupon);
|
||||
break;
|
||||
case BuyCoursesPlugin::PRODUCT_TYPE_SESSION:
|
||||
$buyingSession = true;
|
||||
$session = $plugin->getSessionInfo($sale['product_id'], $coupon);
|
||||
break;
|
||||
}
|
||||
|
||||
$transferAccounts = $plugin->getTransferAccounts();
|
||||
$infoEmailExtra = $plugin->getTransferInfoExtra()['tinfo_email_extra'];
|
||||
|
||||
$form = new FormValidator(
|
||||
'success',
|
||||
'POST',
|
||||
api_get_self(),
|
||||
null,
|
||||
null,
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
|
||||
if ($form->validate()) {
|
||||
$formValues = $form->getSubmitValues();
|
||||
|
||||
if (isset($formValues['cancel'])) {
|
||||
$plugin->cancelSale($sale['id']);
|
||||
|
||||
unset($_SESSION['bc_sale_id']);
|
||||
unset($_SESSION['bc_coupon_id']);
|
||||
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$messageTemplate = new Template();
|
||||
$messageTemplate->assign('user', $userInfo);
|
||||
$messageTemplate->assign(
|
||||
'sale',
|
||||
[
|
||||
'date' => $sale['date'],
|
||||
'product' => $sale['product_name'],
|
||||
'currency' => $currency['iso_code'],
|
||||
'price' => $sale['price'],
|
||||
'reference' => $sale['reference'],
|
||||
]
|
||||
);
|
||||
$messageTemplate->assign('transfer_accounts', $transferAccounts);
|
||||
$messageTemplate->assign('info_email_extra', $infoEmailExtra);
|
||||
|
||||
MessageManager::send_message_simple(
|
||||
$userInfo['user_id'],
|
||||
$plugin->get_lang('bc_subject'),
|
||||
$messageTemplate->fetch('buycourses/view/message_transfer.tpl')
|
||||
);
|
||||
|
||||
if (!empty($globalParameters['sale_email'])) {
|
||||
$messageConfirmTemplate = new Template();
|
||||
$messageConfirmTemplate->assign('user', $userInfo);
|
||||
$messageConfirmTemplate->assign(
|
||||
'sale',
|
||||
[
|
||||
'date' => $sale['date'],
|
||||
'product' => $sale['product_name'],
|
||||
'currency' => $currency['iso_code'],
|
||||
'price' => $sale['price'],
|
||||
'reference' => $sale['reference'],
|
||||
]
|
||||
);
|
||||
|
||||
api_mail_html(
|
||||
'',
|
||||
$globalParameters['sale_email'],
|
||||
$plugin->get_lang('bc_subject'),
|
||||
$messageConfirmTemplate->fetch('buycourses/view/message_confirm.tpl')
|
||||
);
|
||||
}
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf(
|
||||
$plugin->get_lang('PurchaseStatusX'),
|
||||
$plugin->get_lang('PendingReasonByTransfer')
|
||||
),
|
||||
'success',
|
||||
false
|
||||
)
|
||||
);
|
||||
|
||||
unset($_SESSION['bc_sale_id']);
|
||||
unset($_SESSION['bc_coupon_id']);
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/course_catalog.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$form->addButton(
|
||||
'confirm',
|
||||
$plugin->get_lang('ConfirmOrder'),
|
||||
'check',
|
||||
'success',
|
||||
'default',
|
||||
null,
|
||||
['id' => 'confirm']
|
||||
);
|
||||
$form->addButtonCancel($plugin->get_lang('CancelOrder'), 'cancel');
|
||||
|
||||
$template = new Template();
|
||||
|
||||
if ($buyingCourse) {
|
||||
$template->assign('course', $course);
|
||||
} elseif ($buyingSession) {
|
||||
$template->assign('session', $session);
|
||||
}
|
||||
|
||||
$template->assign('buying_course', $buyingCourse);
|
||||
$template->assign('buying_session', $buyingSession);
|
||||
$template->assign('terms', $globalParameters['terms_and_conditions']);
|
||||
$template->assign('title', $sale['product_name']);
|
||||
$template->assign('price', $sale['price']);
|
||||
$template->assign('currency', $sale['currency_id']);
|
||||
$template->assign('user', $userInfo);
|
||||
$template->assign('transfer_accounts', $transferAccounts);
|
||||
$template->assign('form', $form->returnForm());
|
||||
$template->assign('is_bank_transfer', true);
|
||||
|
||||
$content = $template->fetch('buycourses/view/process_confirm.tpl');
|
||||
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
break;
|
||||
case BuyCoursesPlugin::PAYMENT_TYPE_CULQI:
|
||||
// We need to include the main online script, acording to the Culqi documentation the JS needs to be loeaded
|
||||
// directly from the main url "https://integ-pago.culqi.com" because a local copy of this JS is not supported
|
||||
$htmlHeadXtra[] = '<script src="//integ-pago.culqi.com/js/v1"></script>';
|
||||
|
||||
$buyingCourse = false;
|
||||
$buyingSession = false;
|
||||
|
||||
switch ($sale['product_type']) {
|
||||
case BuyCoursesPlugin::PRODUCT_TYPE_COURSE:
|
||||
$buyingCourse = true;
|
||||
$course = $plugin->getCourseInfo($sale['product_id'], $coupon);
|
||||
break;
|
||||
case BuyCoursesPlugin::PRODUCT_TYPE_SESSION:
|
||||
$buyingSession = true;
|
||||
$session = $plugin->getSessionInfo($sale['product_id'], $coupon);
|
||||
break;
|
||||
}
|
||||
|
||||
$form = new FormValidator(
|
||||
'success',
|
||||
'POST',
|
||||
api_get_self(),
|
||||
null,
|
||||
null,
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
|
||||
if ($form->validate()) {
|
||||
$formValues = $form->getSubmitValues();
|
||||
|
||||
if (isset($formValues['cancel'])) {
|
||||
$plugin->cancelSale($sale['id']);
|
||||
|
||||
unset($_SESSION['bc_sale_id']);
|
||||
unset($_SESSION['bc_coupon_id']);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
$plugin->get_lang('OrderCanceled'),
|
||||
'warning',
|
||||
false
|
||||
)
|
||||
);
|
||||
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/index.php');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$form->addButton(
|
||||
'confirm',
|
||||
$plugin->get_lang('ConfirmOrder'),
|
||||
'check',
|
||||
'success',
|
||||
'default',
|
||||
null,
|
||||
['id' => 'confirm']
|
||||
);
|
||||
$form->addButton(
|
||||
'cancel',
|
||||
$plugin->get_lang('CancelOrder'),
|
||||
'times',
|
||||
'danger',
|
||||
'default',
|
||||
null,
|
||||
['id' => 'cancel']
|
||||
);
|
||||
|
||||
$template = new Template();
|
||||
|
||||
if ($buyingCourse) {
|
||||
$template->assign('course', $course);
|
||||
} elseif ($buyingSession) {
|
||||
$template->assign('session', $session);
|
||||
}
|
||||
|
||||
$template->assign('buying_course', $buyingCourse);
|
||||
$template->assign('buying_session', $buyingSession);
|
||||
$template->assign('terms', $globalParameters['terms_and_conditions']);
|
||||
$template->assign('title', $sale['product_name']);
|
||||
$template->assign('price', floatval($sale['price']));
|
||||
$template->assign('currency', $plugin->getSelectedCurrency());
|
||||
$template->assign('user', $userInfo);
|
||||
$template->assign('sale', $sale);
|
||||
$template->assign('form', $form->returnForm());
|
||||
$template->assign('is_culqi_payment', true);
|
||||
$template->assign('culqi_params', $culqiParams = $plugin->getCulqiParams());
|
||||
|
||||
$content = $template->fetch('buycourses/view/process_confirm.tpl');
|
||||
|
||||
$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;
|
||||
case BuyCoursesPlugin::PAYMENT_TYPE_STRIPE:
|
||||
$buyingCourse = false;
|
||||
$buyingSession = false;
|
||||
|
||||
switch ($sale['product_type']) {
|
||||
case BuyCoursesPlugin::PRODUCT_TYPE_COURSE:
|
||||
$buyingCourse = true;
|
||||
$course = $plugin->getCourseInfo($sale['product_id'], $coupon);
|
||||
break;
|
||||
case BuyCoursesPlugin::PRODUCT_TYPE_SESSION:
|
||||
$buyingSession = true;
|
||||
$session = $plugin->getSessionInfo($sale['product_id'], $coupon);
|
||||
break;
|
||||
}
|
||||
|
||||
$form = new FormValidator(
|
||||
'success',
|
||||
'POST',
|
||||
api_get_self(),
|
||||
null,
|
||||
null,
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
|
||||
if ($form->validate()) {
|
||||
$formValues = $form->getSubmitValues();
|
||||
|
||||
if (isset($formValues['cancel'])) {
|
||||
$plugin->cancelSale($sale['id']);
|
||||
|
||||
unset($_SESSION['bc_sale_id']);
|
||||
unset($_SESSION['bc_coupon_id']);
|
||||
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$stripeParams = $plugin->getStripeParams();
|
||||
$currency = $plugin->getCurrency($sale['currency_id']);
|
||||
|
||||
\Stripe\Stripe::setApiKey($stripeParams['secret_key']);
|
||||
\Stripe\Stripe::setAppInfo("ChamiloBuyCoursesPlugin");
|
||||
|
||||
$session = \Stripe\Checkout\Session::create([
|
||||
'payment_method_types' => ['card'],
|
||||
'line_items' => [[
|
||||
'price_data' => [
|
||||
'unit_amount_decimal' => $sale['price'] * 100,
|
||||
'currency' => $currency['iso_code'],
|
||||
'product_data' => [
|
||||
'name' => $sale['product_name'],
|
||||
],
|
||||
],
|
||||
'quantity' => 1,
|
||||
]],
|
||||
'customer_email' => $_SESSION['_user']['email'],
|
||||
'mode' => 'payment',
|
||||
'success_url' => api_get_path(WEB_PLUGIN_PATH).'buycourses/src/stripe_success.php',
|
||||
'cancel_url' => api_get_path(WEB_PLUGIN_PATH).'buycourses/src/stripe_cancel.php',
|
||||
]);
|
||||
|
||||
if (!empty($session)) {
|
||||
$plugin->updateSaleReference($saleId, $session->id);
|
||||
|
||||
unset($_SESSION['bc_coupon_id']);
|
||||
|
||||
header('HTTP/1.1 301 Moved Permanently');
|
||||
header('Location: '.$session->url);
|
||||
} else {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
$plugin->get_lang('ErrorOccurred'),
|
||||
'error',
|
||||
false
|
||||
)
|
||||
);
|
||||
header('Location: ../index.php');
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$form->addButton(
|
||||
'confirm',
|
||||
$plugin->get_lang('ConfirmOrder'),
|
||||
'check',
|
||||
'success',
|
||||
'default',
|
||||
null,
|
||||
['id' => 'confirm']
|
||||
);
|
||||
$form->addButtonCancel($plugin->get_lang('CancelOrder'), 'cancel');
|
||||
|
||||
$template = new Template();
|
||||
|
||||
if ($buyingCourse) {
|
||||
$template->assign('course', $course);
|
||||
} elseif ($buyingSession) {
|
||||
$template->assign('session', $session);
|
||||
}
|
||||
|
||||
$template->assign('buying_course', $buyingCourse);
|
||||
$template->assign('buying_session', $buyingSession);
|
||||
$template->assign('terms', $globalParameters['terms_and_conditions']);
|
||||
$template->assign('title', $sale['product_name']);
|
||||
$template->assign('price', $sale['price']);
|
||||
$template->assign('currency', $sale['currency_id']);
|
||||
$template->assign('user', $userInfo);
|
||||
$template->assign('transfer_accounts', $transferAccounts);
|
||||
$template->assign('form', $form->returnForm());
|
||||
$template->assign('is_bank_transfer', false);
|
||||
|
||||
$content = $template->fetch('buycourses/view/process_confirm.tpl');
|
||||
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
|
||||
break;
|
||||
|
||||
case BuyCoursesPlugin::PAYMENT_TYPE_TPV_CECABANK:
|
||||
$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;
|
||||
}
|
||||
|
||||
$cecabankParams = $plugin->getcecabankParams();
|
||||
$currency = $plugin->getCurrency($sale['currency_id']);
|
||||
|
||||
$form = new FormValidator(
|
||||
'success',
|
||||
'POST',
|
||||
api_get_self(),
|
||||
null,
|
||||
null,
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
|
||||
if ($form->validate()) {
|
||||
$formValues = $form->getSubmitValues();
|
||||
|
||||
if (isset($formValues['cancel'])) {
|
||||
$plugin->cancelSale($sale['id']);
|
||||
|
||||
unset($_SESSION['bc_sale_id']);
|
||||
unset($_SESSION['bc_coupon_id']);
|
||||
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$urlTpv = $cecabankParams['url'];
|
||||
$currency = $plugin->getCurrency($sale['currency_id']);
|
||||
$signature = $plugin->getCecabankSignature($sale['reference'], $sale['price']);
|
||||
|
||||
echo '<form name="tpv_chamilo" action="'.$urlTpv.'" method="POST">';
|
||||
echo '<input type="hidden" name="MerchantID" value="'.$cecabankParams['merchant_id'].'" />';
|
||||
echo '<input type="hidden" name="AcquirerBIN" value="'.$cecabankParams['acquirer_bin'].'" />';
|
||||
echo '<input type="hidden" name="TerminalID" value="'.$cecabankParams['terminal_id'].'" />';
|
||||
echo '<input type="hidden" name="URL_OK" value="'.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/cecabank_success.php'.'" />';
|
||||
echo '<input type="hidden" name="URL_NOK" value="'.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/cecabank_cancel.php'.'" />';
|
||||
echo '<input type="hidden" name="Firma" value="'.$signature.'" />';
|
||||
echo '<input type="hidden" name="Cifrado" value="'.$cecabankParams['cypher'].'" />';
|
||||
echo '<input type="hidden" name="Num_operacion" value="'.$sale['reference'].'" />';
|
||||
echo '<input type="hidden" name="Importe" value="'.($sale['price'] * 100).'" />';
|
||||
echo '<input type="hidden" name="TipoMoneda" value="978" />';
|
||||
echo '<input type="hidden" name="Exponente" value="'.$cecabankParams['exponent'].'" />';
|
||||
echo '<input type="hidden" name="Pago_soportado" value="'.$cecabankParams['supported_payment'].'" />';
|
||||
echo '</form>';
|
||||
|
||||
echo '<SCRIPT language=javascript>';
|
||||
echo 'document.tpv_chamilo.submit();';
|
||||
echo '</script>';
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$form->addButton(
|
||||
'confirm',
|
||||
$plugin->get_lang('ConfirmOrder'),
|
||||
'check',
|
||||
'success',
|
||||
'default',
|
||||
null,
|
||||
['id' => 'confirm']
|
||||
);
|
||||
$form->addButtonCancel($plugin->get_lang('CancelOrder'), 'cancel');
|
||||
|
||||
$template = new Template();
|
||||
|
||||
if ($buyingCourse) {
|
||||
$template->assign('course', $course);
|
||||
} elseif ($buyingSession) {
|
||||
$template->assign('session', $session);
|
||||
}
|
||||
|
||||
$template->assign('buying_course', $buyingCourse);
|
||||
$template->assign('buying_session', $buyingSession);
|
||||
$template->assign('terms', $globalParameters['terms_and_conditions']);
|
||||
$template->assign('title', $sale['product_name']);
|
||||
$template->assign('price', $sale['price']);
|
||||
$template->assign('currency', $sale['currency_id']);
|
||||
$template->assign('user', $userInfo);
|
||||
$template->assign('transfer_accounts', $transferAccounts);
|
||||
$template->assign('form', $form->returnForm());
|
||||
$template->assign('is_bank_transfer', false);
|
||||
|
||||
$content = $template->fetch('buycourses/view/process_confirm.tpl');
|
||||
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
|
||||
break;
|
||||
}
|
||||
375
plugin/buycourses/src/process_subscription_confirm.php
Normal file
375
plugin/buycourses/src/process_subscription_confirm.php
Normal file
@@ -0,0 +1,375 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Process purchase confirmation script for the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
require_once '../config.php';
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
|
||||
$saleId = $_SESSION['bc_sale_id'];
|
||||
$couponId = $_SESSION['bc_coupon_id'];
|
||||
|
||||
if (empty($saleId)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$sale = $plugin->getSubscriptionSale($saleId);
|
||||
|
||||
if (!empty($couponId)) {
|
||||
$coupon = $plugin->getCoupon($couponId, $sale['product_type'], $sale['product_id']);
|
||||
}
|
||||
|
||||
$userInfo = api_get_user_info($sale['user_id']);
|
||||
|
||||
if (empty($sale)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$currency = $plugin->getCurrency($sale['currency_id']);
|
||||
$globalParameters = $plugin->getGlobalParameters();
|
||||
|
||||
switch ($sale['payment_type']) {
|
||||
case BuyCoursesPlugin::PAYMENT_TYPE_PAYPAL:
|
||||
$paypalParams = $plugin->getPaypalParams();
|
||||
|
||||
$pruebas = $paypalParams['sandbox'] == 1;
|
||||
$paypalUsername = $paypalParams['username'];
|
||||
$paypalPassword = $paypalParams['password'];
|
||||
$paypalSignature = $paypalParams['signature'];
|
||||
|
||||
require_once "paypalfunctions.php";
|
||||
|
||||
$i = 0;
|
||||
$extra = "&L_PAYMENTREQUEST_0_NAME0={$sale['product_name']}";
|
||||
$extra .= "&L_PAYMENTREQUEST_0_AMT0={$sale['price']}";
|
||||
$extra .= "&L_PAYMENTREQUEST_0_QTY0=1";
|
||||
|
||||
$expressCheckout = CallShortcutExpressCheckout(
|
||||
$sale['price'],
|
||||
$currency['iso_code'],
|
||||
'paypal',
|
||||
api_get_path(WEB_PLUGIN_PATH).'buycourses/src/success.php',
|
||||
api_get_path(WEB_PLUGIN_PATH).'buycourses/src/error.php',
|
||||
$extra
|
||||
);
|
||||
|
||||
if ($expressCheckout["ACK"] !== 'Success') {
|
||||
$erroMessage = vsprintf(
|
||||
$plugin->get_lang('ErrorOccurred'),
|
||||
[$expressCheckout['L_ERRORCODE0'], $expressCheckout['L_LONGMESSAGE0']]
|
||||
);
|
||||
Display::addFlash(
|
||||
Display::return_message($erroMessage, 'error', false)
|
||||
);
|
||||
header('Location: ../index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!empty($globalParameters['sale_email'])) {
|
||||
$messageConfirmTemplate = new Template();
|
||||
$messageConfirmTemplate->assign('user', $userInfo);
|
||||
$messageConfirmTemplate->assign(
|
||||
'sale',
|
||||
[
|
||||
'date' => $sale['date'],
|
||||
'product' => $sale['product_name'],
|
||||
'currency' => $currency['iso_code'],
|
||||
'price' => $sale['price'],
|
||||
'reference' => $sale['reference'],
|
||||
]
|
||||
);
|
||||
|
||||
api_mail_html(
|
||||
'',
|
||||
$globalParameters['sale_email'],
|
||||
$plugin->get_lang('bc_subject'),
|
||||
$messageConfirmTemplate->fetch('buycourses/view/message_confirm.tpl')
|
||||
);
|
||||
}
|
||||
|
||||
RedirectToPayPal($expressCheckout["TOKEN"]);
|
||||
break;
|
||||
case BuyCoursesPlugin::PAYMENT_TYPE_TRANSFER:
|
||||
$buyingCourse = false;
|
||||
$buyingSession = false;
|
||||
|
||||
switch ($sale['product_type']) {
|
||||
case BuyCoursesPlugin::PRODUCT_TYPE_COURSE:
|
||||
$buyingCourse = true;
|
||||
$course = $plugin->getSubscriptionCourseInfo($sale['product_id'], $coupon);
|
||||
break;
|
||||
case BuyCoursesPlugin::PRODUCT_TYPE_SESSION:
|
||||
$buyingSession = true;
|
||||
$session = $plugin->getSubscriptionSessionInfo($sale['product_id'], $coupon);
|
||||
break;
|
||||
}
|
||||
|
||||
$transferAccounts = $plugin->getTransferAccounts();
|
||||
$infoEmailExtra = $plugin->getTransferInfoExtra()['tinfo_email_extra'];
|
||||
|
||||
$form = new FormValidator(
|
||||
'success',
|
||||
'POST',
|
||||
api_get_self(),
|
||||
null,
|
||||
null,
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
|
||||
if ($form->validate()) {
|
||||
$formValues = $form->getSubmitValues();
|
||||
|
||||
if (isset($formValues['cancel'])) {
|
||||
$plugin->cancelSubscriptionSale($sale['id']);
|
||||
|
||||
unset($_SESSION['bc_sale_id']);
|
||||
unset($_SESSION['bc_coupon_id']);
|
||||
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$messageTemplate = new Template();
|
||||
$messageTemplate->assign('user', $userInfo);
|
||||
$messageTemplate->assign(
|
||||
'sale',
|
||||
[
|
||||
'date' => $sale['date'],
|
||||
'product' => $sale['product_name'],
|
||||
'currency' => $currency['iso_code'],
|
||||
'price' => $sale['price'],
|
||||
'reference' => $sale['reference'],
|
||||
]
|
||||
);
|
||||
$messageTemplate->assign('transfer_accounts', $transferAccounts);
|
||||
$messageTemplate->assign('info_email_extra', $infoEmailExtra);
|
||||
|
||||
MessageManager::send_message_simple(
|
||||
$userInfo['user_id'],
|
||||
$plugin->get_lang('bc_subject'),
|
||||
$messageTemplate->fetch('buycourses/view/message_transfer.tpl')
|
||||
);
|
||||
|
||||
if (!empty($globalParameters['sale_email'])) {
|
||||
$messageConfirmTemplate = new Template();
|
||||
$messageConfirmTemplate->assign('user', $userInfo);
|
||||
$messageConfirmTemplate->assign(
|
||||
'sale',
|
||||
[
|
||||
'date' => $sale['date'],
|
||||
'product' => $sale['product_name'],
|
||||
'currency' => $currency['iso_code'],
|
||||
'price' => $sale['price'],
|
||||
'reference' => $sale['reference'],
|
||||
]
|
||||
);
|
||||
|
||||
api_mail_html(
|
||||
'',
|
||||
$globalParameters['sale_email'],
|
||||
$plugin->get_lang('bc_subject'),
|
||||
$messageConfirmTemplate->fetch('buycourses/view/message_confirm.tpl')
|
||||
);
|
||||
}
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf(
|
||||
$plugin->get_lang('PurchaseStatusX'),
|
||||
$plugin->get_lang('PendingReasonByTransfer')
|
||||
),
|
||||
'success',
|
||||
false
|
||||
)
|
||||
);
|
||||
|
||||
unset($_SESSION['bc_sale_id']);
|
||||
unset($_SESSION['bc_coupon_id']);
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/course_catalog.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$form->addButton(
|
||||
'confirm',
|
||||
$plugin->get_lang('ConfirmOrder'),
|
||||
'check',
|
||||
'success',
|
||||
'default',
|
||||
null,
|
||||
['id' => 'confirm']
|
||||
);
|
||||
$form->addButtonCancel($plugin->get_lang('CancelOrder'), 'cancel');
|
||||
|
||||
$template = new Template();
|
||||
|
||||
if ($buyingCourse) {
|
||||
$template->assign('course', $course);
|
||||
} elseif ($buyingSession) {
|
||||
$template->assign('session', $session);
|
||||
}
|
||||
|
||||
$template->assign('buying_course', $buyingCourse);
|
||||
$template->assign('buying_session', $buyingSession);
|
||||
$template->assign('terms', $globalParameters['terms_and_conditions']);
|
||||
$template->assign('title', $sale['product_name']);
|
||||
$template->assign('price', $sale['price']);
|
||||
$template->assign('currency', $sale['currency_id']);
|
||||
$template->assign('user', $userInfo);
|
||||
$template->assign('transfer_accounts', $transferAccounts);
|
||||
$template->assign('form', $form->returnForm());
|
||||
$template->assign('is_bank_transfer', true);
|
||||
|
||||
$content = $template->fetch('buycourses/view/subscription_process_confirm.tpl');
|
||||
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
break;
|
||||
case BuyCoursesPlugin::PAYMENT_TYPE_CULQI:
|
||||
// We need to include the main online script, acording to the Culqi documentation the JS needs to be loeaded
|
||||
// directly from the main url "https://integ-pago.culqi.com" because a local copy of this JS is not supported
|
||||
$htmlHeadXtra[] = '<script src="//integ-pago.culqi.com/js/v1"></script>';
|
||||
|
||||
$buyingCourse = false;
|
||||
$buyingSession = false;
|
||||
|
||||
switch ($sale['product_type']) {
|
||||
case BuyCoursesPlugin::PRODUCT_TYPE_COURSE:
|
||||
$buyingCourse = true;
|
||||
$course = $plugin->getSubscriptionCourseInfo($sale['product_id'], $coupon);
|
||||
break;
|
||||
case BuyCoursesPlugin::PRODUCT_TYPE_SESSION:
|
||||
$buyingSession = true;
|
||||
$session = $plugin->getSubscriptionSessionInfo($sale['product_id'], $coupon);
|
||||
break;
|
||||
}
|
||||
|
||||
$form = new FormValidator(
|
||||
'success',
|
||||
'POST',
|
||||
api_get_self(),
|
||||
null,
|
||||
null,
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
|
||||
if ($form->validate()) {
|
||||
$formValues = $form->getSubmitValues();
|
||||
|
||||
if (isset($formValues['cancel'])) {
|
||||
$plugin->cancelSubscriptionSale($sale['id']);
|
||||
|
||||
unset($_SESSION['bc_sale_id']);
|
||||
unset($_SESSION['bc_coupon_id']);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
$plugin->get_lang('OrderCanceled'),
|
||||
'warning',
|
||||
false
|
||||
)
|
||||
);
|
||||
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/index.php');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$form->addButton(
|
||||
'confirm',
|
||||
$plugin->get_lang('ConfirmOrder'),
|
||||
'check',
|
||||
'success',
|
||||
'default',
|
||||
null,
|
||||
['id' => 'confirm']
|
||||
);
|
||||
$form->addButton(
|
||||
'cancel',
|
||||
$plugin->get_lang('CancelOrder'),
|
||||
'times',
|
||||
'danger',
|
||||
'default',
|
||||
null,
|
||||
['id' => 'cancel']
|
||||
);
|
||||
|
||||
$template = new Template();
|
||||
|
||||
if ($buyingCourse) {
|
||||
$template->assign('course', $course);
|
||||
} elseif ($buyingSession) {
|
||||
$template->assign('session', $session);
|
||||
}
|
||||
|
||||
$template->assign('buying_course', $buyingCourse);
|
||||
$template->assign('buying_session', $buyingSession);
|
||||
$template->assign('terms', $globalParameters['terms_and_conditions']);
|
||||
$template->assign('title', $sale['product_name']);
|
||||
$template->assign('price', floatval($sale['price']));
|
||||
$template->assign('currency', $plugin->getSelectedCurrency());
|
||||
$template->assign('user', $userInfo);
|
||||
$template->assign('sale', $sale);
|
||||
$template->assign('form', $form->returnForm());
|
||||
$template->assign('is_culqi_payment', true);
|
||||
$template->assign('culqi_params', $culqiParams = $plugin->getCulqiParams());
|
||||
|
||||
$content = $template->fetch('buycourses/view/subscription_process_confirm.tpl');
|
||||
|
||||
$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;
|
||||
}
|
||||
216
plugin/buycourses/src/sales_report.php
Normal file
216
plugin/buycourses/src/sales_report.php
Normal file
@@ -0,0 +1,216 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* List of pending payments of the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once '../config.php';
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
|
||||
$paypalEnable = $plugin->get('paypal_enable');
|
||||
$commissionsEnable = $plugin->get('commissions_enable');
|
||||
$includeServices = $plugin->get('include_services');
|
||||
$invoicingEnable = $plugin->get('invoicing_enable') === 'true';
|
||||
|
||||
if (isset($_GET['order'])) {
|
||||
$sale = $plugin->getSale($_GET['order']);
|
||||
if (empty($sale)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$urlToRedirect = api_get_self().'?';
|
||||
|
||||
switch ($_GET['action']) {
|
||||
case 'confirm':
|
||||
$plugin->completeSale($sale['id']);
|
||||
$plugin->storePayouts($sale['id']);
|
||||
Display::addFlash(
|
||||
$plugin->getSubscriptionSuccessMessage($sale)
|
||||
);
|
||||
|
||||
$urlToRedirect .= http_build_query([
|
||||
'status' => BuyCoursesPlugin::SALE_STATUS_COMPLETED,
|
||||
'sale' => $sale['id'],
|
||||
]);
|
||||
break;
|
||||
case 'cancel':
|
||||
$plugin->cancelSale($sale['id']);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
$plugin->get_lang('OrderCanceled'),
|
||||
'warning'
|
||||
)
|
||||
);
|
||||
|
||||
$urlToRedirect .= http_build_query([
|
||||
'status' => BuyCoursesPlugin::SALE_STATUS_CANCELED,
|
||||
'sale' => $sale['id'],
|
||||
]);
|
||||
break;
|
||||
}
|
||||
|
||||
header("Location: $urlToRedirect");
|
||||
exit;
|
||||
}
|
||||
|
||||
$productTypes = $plugin->getProductTypes();
|
||||
$saleStatuses = $plugin->getSaleStatuses();
|
||||
$paymentTypes = $plugin->getPaymentTypes();
|
||||
|
||||
$selectedFilterType = '0';
|
||||
$selectedStatus = isset($_GET['status']) ? $_GET['status'] : BuyCoursesPlugin::SALE_STATUS_PENDING;
|
||||
$selectedSale = isset($_GET['sale']) ? intval($_GET['sale']) : 0;
|
||||
$dateStart = isset($_GET['date_start']) ? $_GET['date_start'] : date('Y-m-d H:i', mktime(0, 0, 0));
|
||||
$dateEnd = isset($_GET['date_end']) ? $_GET['date_end'] : date('Y-m-d H:i', mktime(23, 59, 59));
|
||||
$searchTerm = '';
|
||||
$email = '';
|
||||
|
||||
$form = new FormValidator('search', 'get');
|
||||
|
||||
if ($form->validate()) {
|
||||
$selectedFilterType = $form->getSubmitValue('filter_type');
|
||||
$selectedStatus = $form->getSubmitValue('status');
|
||||
$searchTerm = $form->getSubmitValue('user');
|
||||
$dateStart = $form->getSubmitValue('date_start');
|
||||
$dateEnd = $form->getSubmitValue('date_end');
|
||||
$email = $form->getSubmitValue('email');
|
||||
|
||||
if ($selectedStatus === false) {
|
||||
$selectedStatus = BuyCoursesPlugin::SALE_STATUS_PENDING;
|
||||
}
|
||||
|
||||
if ($selectedFilterType === false) {
|
||||
$selectedFilterType = '0';
|
||||
}
|
||||
}
|
||||
|
||||
$form->addRadio(
|
||||
'filter_type',
|
||||
get_lang('Filter'),
|
||||
[
|
||||
$plugin->get_lang('ByStatus'),
|
||||
$plugin->get_lang('ByUser'),
|
||||
$plugin->get_lang('ByDate'),
|
||||
$plugin->get_lang('ByEmail'),
|
||||
]
|
||||
);
|
||||
$form->addHtml('<div id="report-by-status" '.($selectedFilterType !== '0' ? 'style="display:none"' : '').'>');
|
||||
$form->addSelect('status', $plugin->get_lang('OrderStatus'), $saleStatuses);
|
||||
$form->addHtml('</div>');
|
||||
$form->addHtml('<div id="report-by-user" '.($selectedFilterType !== '1' ? 'style="display:none"' : '').'>');
|
||||
$form->addText('user', get_lang('UserName'), false);
|
||||
$form->addHtml('</div>');
|
||||
$form->addHtml('<div id="report-by-date" '.($selectedFilterType !== '2' ? 'style="display:none"' : '').'>');
|
||||
$form->addDateRangePicker('date', get_lang('Date'), false);
|
||||
$form->addHtml('</div>');
|
||||
$form->addHtml('<div id="report-by-email" '.($selectedFilterType !== '3' ? 'style="display:none"' : '').'>');
|
||||
$form->addText('email', get_lang('Email'), false);
|
||||
$form->addHtml('</div>');
|
||||
$form->addButtonFilter(get_lang('Search'));
|
||||
$form->setDefaults([
|
||||
'filter_type' => $selectedFilterType,
|
||||
'status' => $selectedStatus,
|
||||
'date_start' => $dateStart,
|
||||
'date_end' => $dateEnd,
|
||||
'email' => $email,
|
||||
]);
|
||||
|
||||
switch ($selectedFilterType) {
|
||||
case '0':
|
||||
$sales = $plugin->getSaleListByStatus($selectedStatus);
|
||||
break;
|
||||
case '1':
|
||||
$sales = $plugin->getSaleListByUser($searchTerm);
|
||||
break;
|
||||
case '2':
|
||||
$sales = $plugin->getSaleListByDate($dateStart, $dateEnd);
|
||||
break;
|
||||
case '3':
|
||||
$sales = $plugin->getSaleListByEmail($email);
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ($sales as &$sale) {
|
||||
$sale['product_type'] = $productTypes[$sale['product_type']];
|
||||
$sale['payment_type'] = $paymentTypes[$sale['payment_type']];
|
||||
$sale['complete_user_name'] = api_get_person_name($sale['firstname'], $sale['lastname']);
|
||||
$sale['num_invoice'] = $plugin->getNumInvoice($sale['id'], 0);
|
||||
$sale['total_price'] = $plugin->getPriceWithCurrencyFromIsoCode($sale['price'], $sale['iso_code']);
|
||||
if (isset($sale['discount_amount']) && $sale['discount_amount'] != 0) {
|
||||
$sale['total_discount'] = $plugin->getPriceWithCurrencyFromIsoCode($sale['discount_amount'], $sale['iso_code']);
|
||||
$sale['coupon_code'] = $plugin->getSaleCouponCode($sale['id']);
|
||||
}
|
||||
}
|
||||
|
||||
$interbreadcrumb[] = ['url' => '../index.php', 'name' => $plugin->get_lang('plugin_title')];
|
||||
|
||||
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_PLUGIN_PATH).'buycourses/resources/css/style.css');
|
||||
$htmlHeadXtra[] = api_get_jqgrid_js();
|
||||
$htmlHeadXtra[] = BuyCoursesPlugin::getSalesReportScript($sales, $invoicingEnable);
|
||||
|
||||
$templateName = $plugin->get_lang('SalesReport');
|
||||
$template = new Template($templateName);
|
||||
|
||||
$toolbar = Display::url(
|
||||
Display::returnFontAwesomeIcon('file-excel-o').
|
||||
get_lang('GenerateReport'),
|
||||
api_get_path(WEB_PLUGIN_PATH).'buycourses/src/export_report.php',
|
||||
['class' => 'btn btn-primary']
|
||||
);
|
||||
|
||||
if ($paypalEnable === 'true' && $commissionsEnable === 'true') {
|
||||
$toolbar .= Display::toolbarButton(
|
||||
$plugin->get_lang('PaypalPayoutCommissions'),
|
||||
api_get_path(WEB_PLUGIN_PATH).'buycourses/src/paypal_payout.php',
|
||||
'paypal',
|
||||
'primary',
|
||||
['title' => $plugin->get_lang('PaypalPayoutCommissions')]
|
||||
);
|
||||
|
||||
$template->assign(
|
||||
'actions',
|
||||
Display::toolbarAction('toolbar', [$toolbar])
|
||||
);
|
||||
}
|
||||
|
||||
if ($commissionsEnable === 'true') {
|
||||
$toolbar .= Display::toolbarButton(
|
||||
$plugin->get_lang('PayoutReport'),
|
||||
api_get_path(WEB_PLUGIN_PATH).'buycourses/src/payout_report.php',
|
||||
'money',
|
||||
'info',
|
||||
['title' => $plugin->get_lang('PayoutReport')]
|
||||
);
|
||||
|
||||
$template->assign(
|
||||
'actions',
|
||||
Display::toolbarAction('toolbar', [$toolbar])
|
||||
);
|
||||
}
|
||||
$template->assign(
|
||||
'actions',
|
||||
Display::toolbarAction('toolbar', [$toolbar])
|
||||
);
|
||||
$template->assign('form', $form->returnForm());
|
||||
$template->assign('selected_sale', $selectedSale);
|
||||
$template->assign('selected_status', $selectedStatus);
|
||||
$template->assign('services_are_included', $includeServices);
|
||||
$template->assign('sale_list', $sales);
|
||||
$template->assign('sale_status_canceled', BuyCoursesPlugin::SALE_STATUS_CANCELED);
|
||||
$template->assign('sale_status_pending', BuyCoursesPlugin::SALE_STATUS_PENDING);
|
||||
$template->assign('sale_status_completed', BuyCoursesPlugin::SALE_STATUS_COMPLETED);
|
||||
$template->assign('invoicing_enable', $invoicingEnable);
|
||||
|
||||
$content = $template->fetch('buycourses/view/sales_report.tpl');
|
||||
|
||||
$template->assign('header', $templateName);
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
101
plugin/buycourses/src/service_catalog.php
Normal file
101
plugin/buycourses/src/service_catalog.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* List of services.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once '../../../main/inc/global.inc.php';
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$includeSessions = $plugin->get('include_sessions') === 'true';
|
||||
$includeServices = $plugin->get('include_services') === 'true';
|
||||
|
||||
$nameFilter = null;
|
||||
$minFilter = 0;
|
||||
$maxFilter = 0;
|
||||
$appliesToFilter = '';
|
||||
|
||||
$form = new FormValidator(
|
||||
'search_filter_form',
|
||||
'get',
|
||||
null,
|
||||
null,
|
||||
[],
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
|
||||
if ($form->validate()) {
|
||||
$formValues = $form->getSubmitValues();
|
||||
$nameFilter = isset($formValues['name']) ? $formValues['name'] : null;
|
||||
$minFilter = isset($formValues['min']) ? $formValues['min'] : 0;
|
||||
$maxFilter = isset($formValues['max']) ? $formValues['max'] : 0;
|
||||
$appliesToFilter = isset($formValues['applies_to']) ? $formValues['applies_to'] : '';
|
||||
}
|
||||
|
||||
$form->addHeader($plugin->get_lang('SearchFilter'));
|
||||
$form->addText('name', $plugin->get_lang('ServiceName'), false);
|
||||
$form->addElement(
|
||||
'number',
|
||||
'min',
|
||||
$plugin->get_lang('MinimumPrice'),
|
||||
['step' => '0.01', 'min' => '0']
|
||||
);
|
||||
$form->addElement(
|
||||
'number',
|
||||
'max',
|
||||
$plugin->get_lang('MaximumPrice'),
|
||||
['step' => '0.01', 'min' => '0']
|
||||
);
|
||||
$appliesToOptions = [
|
||||
'' => get_lang('Any'),
|
||||
0 => get_lang('None'),
|
||||
1 => get_lang('User'),
|
||||
2 => get_lang('Course'),
|
||||
3 => get_lang('Session'),
|
||||
4 => get_lang('TemplateTitleCertificate'),
|
||||
];
|
||||
$form->addSelect('applies_to', $plugin->get_lang('AppliesTo'), $appliesToOptions);
|
||||
$form->addHtml('<hr>');
|
||||
$form->addButtonFilter(get_lang('Search'));
|
||||
|
||||
$pageSize = BuyCoursesPlugin::PAGINATION_PAGE_SIZE;
|
||||
$currentPage = isset($_GET['page']) ? (int) $_GET['page'] : 1;
|
||||
$first = $pageSize * ($currentPage - 1);
|
||||
$serviceList = $plugin->getCatalogServiceList($first, $pageSize, $nameFilter, $minFilter, $maxFilter, $appliesToFilter);
|
||||
$totalItems = $plugin->getCatalogServiceList($first, $pageSize, $nameFilter, $minFilter, $maxFilter, $appliesToFilter, 'count');
|
||||
$pagesCount = ceil($totalItems / $pageSize);
|
||||
$pagination = BuyCoursesPlugin::returnPagination(api_get_self(), $currentPage, $pagesCount, $totalItems);
|
||||
|
||||
// View
|
||||
if (api_is_platform_admin()) {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'list.php',
|
||||
'name' => $plugin->get_lang('AvailableCoursesConfiguration'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'paymentsetup.php',
|
||||
'name' => $plugin->get_lang('PaymentsConfiguration'),
|
||||
];
|
||||
} else {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => '../index.php',
|
||||
'name' => $plugin->get_lang('UserPanel'),
|
||||
];
|
||||
}
|
||||
|
||||
$templateName = $plugin->get_lang('ListOfServicesOnSale');
|
||||
$tpl = new Template($templateName);
|
||||
$tpl->assign('search_filter_form', $form->returnForm());
|
||||
$tpl->assign('showing_services', true);
|
||||
$tpl->assign('services', $serviceList);
|
||||
$tpl->assign('sessions_are_included', $includeSessions);
|
||||
$tpl->assign('services_are_included', $includeServices);
|
||||
$tpl->assign('pagination', $pagination);
|
||||
|
||||
$content = $tpl->fetch('buycourses/view/catalog.tpl');
|
||||
|
||||
$tpl->assign('header', $templateName);
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template();
|
||||
35
plugin/buycourses/src/service_error.php
Normal file
35
plugin/buycourses/src/service_error.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
/**
|
||||
* Errors management for the Buy Courses plugin - Redirects to service_catalog.php with a error msg.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
require_once '../config.php';
|
||||
|
||||
if (isset($_SESSION['bc_service_sale_id'])) {
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$serviceSaleId = $_SESSION['bc_service_sale_id'];
|
||||
unset($_SESSION['bc_service_sale_id']);
|
||||
$serviceSale = $plugin->getServiceSale($serviceSaleId);
|
||||
|
||||
$plugin->cancelServiceSale(intval($serviceSaleId));
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
$plugin->get_lang('OrderCancelled'),
|
||||
'error',
|
||||
false
|
||||
)
|
||||
);
|
||||
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/service_catalog.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('ErrorOccurred'), 'error', false)
|
||||
);
|
||||
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/service_catalog.php');
|
||||
|
||||
exit;
|
||||
42
plugin/buycourses/src/service_information.php
Normal file
42
plugin/buycourses/src/service_information.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Service information page
|
||||
* Show information about a service (for custom purposes).
|
||||
*
|
||||
* @author José Loguercio Silva <jose.loguercio@beeznest.com>
|
||||
*
|
||||
* @package chamilo.buycourses_plugin
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once '../../../main/inc/global.inc.php';
|
||||
|
||||
$serviceId = isset($_GET['service_id']) ? intval($_GET['service_id']) : false;
|
||||
$htmlHeadXtra[] = '<link rel="stylesheet" type="text/css" href="'.api_get_path(
|
||||
WEB_PLUGIN_PATH
|
||||
).'buycourses/resources/css/style.css"/>';
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
|
||||
$includeServices = $plugin->get('include_services') === 'true';
|
||||
|
||||
if (!$includeServices) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$service = $plugin->getService($serviceId);
|
||||
|
||||
if (!$service['id']) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$template = new Template(false);
|
||||
$template->assign('pageUrl', api_get_path(WEB_PATH)."service/{$serviceId}/information/");
|
||||
$template->assign('service', $service);
|
||||
$template->assign('essence', Essence\Essence::instance());
|
||||
|
||||
$content = $template->fetch('buycourses/view/service_information.tpl');
|
||||
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
74
plugin/buycourses/src/service_panel.php
Normal file
74
plugin/buycourses/src/service_panel.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* User Panel.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once '../../../main/inc/global.inc.php';
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$includeServices = $plugin->get('include_services') === 'true';
|
||||
$includeSessions = $plugin->get('include_sessions') === 'true';
|
||||
$servicesOnly = $plugin->get('show_services_only') === 'true';
|
||||
|
||||
$userInfo = api_get_user_info();
|
||||
|
||||
if (!$userInfo) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
$serviceTypes = $plugin->getServiceTypes();
|
||||
$serviceSaleStatuses['status_cancelled'] = BuyCoursesPlugin::SERVICE_STATUS_CANCELLED;
|
||||
$serviceSaleStatuses['status_pending'] = BuyCoursesPlugin::SERVICE_STATUS_PENDING;
|
||||
$serviceSaleStatuses['status_completed'] = BuyCoursesPlugin::SERVICE_STATUS_COMPLETED;
|
||||
|
||||
$serviceSales = $plugin->getServiceSales($userInfo['user_id']);
|
||||
$saleList = [];
|
||||
|
||||
foreach ($serviceSales as $sale) {
|
||||
$saleList[] = [
|
||||
'id' => $sale['id'],
|
||||
'name' => $sale['service']['name'],
|
||||
'service_type' => $serviceTypes[$sale['service']['applies_to']],
|
||||
'applies_to' => $sale['service']['applies_to'],
|
||||
'reference' => $sale['reference'],
|
||||
'date' => api_format_date(api_get_local_time($sale['buy_date']), DATE_TIME_FORMAT_LONG_24H),
|
||||
'date_end' => api_format_date(api_get_local_time($sale['date_end']), DATE_TIME_FORMAT_LONG_24H),
|
||||
'currency' => $sale['currency'],
|
||||
'price' => $sale['price'],
|
||||
'status' => $sale['status'],
|
||||
];
|
||||
}
|
||||
|
||||
$toolbar = Display::toolbarButton(
|
||||
$plugin->get_lang('CourseListOnSale'),
|
||||
'course_catalog.php',
|
||||
'search-plus',
|
||||
'primary',
|
||||
['title' => $plugin->get_lang('CourseListOnSale')]
|
||||
);
|
||||
|
||||
$webPluginPath = api_get_path(WEB_PLUGIN_PATH);
|
||||
$htmlHeadXtra[] = api_get_css($webPluginPath.'buycourses/resources/css/style.css');
|
||||
$htmlHeadXtra[] = api_get_js_simple($webPluginPath.'buycourses/resources/js/modals.js');
|
||||
|
||||
$templateName = $plugin->get_lang('TabsDashboard');
|
||||
$tpl = new Template($templateName);
|
||||
$tpl->assign('showing_courses', true);
|
||||
$tpl->assign('services_are_included', $includeServices);
|
||||
$tpl->assign('sessions_are_included', $includeSessions);
|
||||
$tpl->assign('service_sale_statuses', $serviceSaleStatuses);
|
||||
$tpl->assign('sale_list', $saleList);
|
||||
if ($servicesOnly) {
|
||||
$tpl->assign('show_services_only', true);
|
||||
}
|
||||
|
||||
$content = $tpl->fetch('buycourses/view/service_panel.tpl');
|
||||
|
||||
$tpl->assign(
|
||||
'actions',
|
||||
Display::toolbarAction('toolbar', [$toolbar])
|
||||
);
|
||||
$tpl->assign('header', $templateName);
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template();
|
||||
304
plugin/buycourses/src/service_process.php
Normal file
304
plugin/buycourses/src/service_process.php
Normal file
@@ -0,0 +1,304 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
use Chamilo\CoreBundle\Entity\Session;
|
||||
use Chamilo\CoreBundle\Entity\SessionRelCourseRelUser;
|
||||
use Chamilo\UserBundle\Entity\User;
|
||||
|
||||
/**
|
||||
* Process payments for the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once '../config.php';
|
||||
|
||||
if (!isset($_REQUEST['t'], $_REQUEST['i'])) {
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/service_catalog.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$currentUserId = api_get_user_id();
|
||||
$serviceId = (int) $_REQUEST['i'];
|
||||
$type = (int) $_REQUEST['t'];
|
||||
|
||||
if (empty($currentUserId)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
$htmlHeadXtra[] = '<link rel="stylesheet" type="text/css" href="'.api_get_path(
|
||||
WEB_PLUGIN_PATH
|
||||
).'buycourses/resources/css/style.css"/>';
|
||||
$em = Database::getManager();
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$includeServices = $plugin->get('include_services');
|
||||
$additionalQueryString = '';
|
||||
if ($includeServices !== 'true') {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$typeUser = $type === BuyCoursesPlugin::SERVICE_TYPE_USER;
|
||||
$typeCourse = $type === BuyCoursesPlugin::SERVICE_TYPE_COURSE;
|
||||
$typeSession = $type === BuyCoursesPlugin::SERVICE_TYPE_SESSION;
|
||||
$typeFinalLp = $type === BuyCoursesPlugin::SERVICE_TYPE_LP_FINAL_ITEM;
|
||||
$queryString = 'i='.$serviceId.'&t='.$type.$additionalQueryString;
|
||||
|
||||
if (isset($_REQUEST['c'])) {
|
||||
$couponCode = $_REQUEST['c'];
|
||||
$coupon = $plugin->getCouponServiceByCode($couponCode, $_REQUEST['i']);
|
||||
}
|
||||
|
||||
$serviceInfo = $plugin->getService($serviceId, $coupon);
|
||||
$userInfo = api_get_user_info($currentUserId);
|
||||
|
||||
$form = new FormValidator('confirm_sale');
|
||||
$paymentTypesOptions = $plugin->getPaymentTypes(true);
|
||||
|
||||
$form->addHtml(
|
||||
Display::return_message(
|
||||
$plugin->get_lang('PleaseSelectThePaymentMethodBeforeConfirmYourOrder'),
|
||||
'info'
|
||||
)
|
||||
);
|
||||
$form->addRadio('payment_type', null, $paymentTypesOptions);
|
||||
|
||||
$infoRequired = false;
|
||||
if ($typeUser || $typeCourse || $typeSession || $typeFinalLp) {
|
||||
$infoRequired = true;
|
||||
$form->addHtml(
|
||||
Display::return_message(
|
||||
$plugin->get_lang('PleaseSelectTheCorrectInfoToApplyTheService'),
|
||||
'info'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$selectOptions = [
|
||||
0 => get_lang('None'),
|
||||
];
|
||||
|
||||
if ($typeUser) {
|
||||
$users = UserManager::getRepository()->findAll();
|
||||
$selectOptions[$userInfo['user_id']] = api_get_person_name(
|
||||
$userInfo['firstname'],
|
||||
$userInfo['lastname']
|
||||
).' ('.get_lang('Myself').')';
|
||||
|
||||
if (!empty($users)) {
|
||||
/** @var User $user */
|
||||
foreach ($users as $user) {
|
||||
if (intval($userInfo['user_id']) !== intval($user->getId())) {
|
||||
$selectOptions[$user->getId()] = $user->getCompleteNameWithUsername();
|
||||
}
|
||||
}
|
||||
}
|
||||
$form->addSelect('info_select', get_lang('User'), $selectOptions);
|
||||
} elseif ($typeCourse) {
|
||||
/** @var User $user */
|
||||
$user = UserManager::getRepository()->find($currentUserId);
|
||||
$courses = $user->getCourses();
|
||||
$checker = false;
|
||||
foreach ($courses as $course) {
|
||||
$checker = true;
|
||||
$selectOptions[$course->getCourse()->getId()] = $course->getCourse()->getTitle();
|
||||
}
|
||||
if (!$checker) {
|
||||
$form->addHtml(
|
||||
Display::return_message(
|
||||
$plugin->get_lang('YouNeedToBeRegisteredInAtLeastOneCourse'),
|
||||
'error'
|
||||
)
|
||||
);
|
||||
}
|
||||
$form->addSelect('info_select', get_lang('Course'), $selectOptions);
|
||||
} elseif ($typeSession) {
|
||||
$sessions = [];
|
||||
/** @var User $user */
|
||||
$user = UserManager::getRepository()->find($currentUserId);
|
||||
$userSubscriptions = $user->getSessionCourseSubscriptions();
|
||||
|
||||
/** @var SessionRelCourseRelUser $userSubscription */
|
||||
foreach ($userSubscriptions as $userSubscription) {
|
||||
$sessions[$userSubscription->getSession()->getId()] = $userSubscription->getSession()->getName();
|
||||
}
|
||||
|
||||
$sessionsAsGeneralCoach = $user->getSessionAsGeneralCoach();
|
||||
/** @var Session $sessionAsGeneralCoach */
|
||||
foreach ($sessionsAsGeneralCoach as $sessionAsGeneralCoach) {
|
||||
$sessions[$sessionAsGeneralCoach->getId()] = $sessionAsGeneralCoach->getName();
|
||||
}
|
||||
|
||||
if (!$sessions) {
|
||||
$form->addHtml(Display::return_message($plugin->get_lang('YouNeedToBeRegisteredInAtLeastOneSession'), 'error'));
|
||||
} else {
|
||||
$selectOptions = $sessions;
|
||||
$form->addSelect('info_select', get_lang('Session'), $selectOptions);
|
||||
}
|
||||
} elseif ($typeFinalLp) {
|
||||
// We need here to check the current user courses first
|
||||
/** @var User $user */
|
||||
$user = UserManager::getRepository()->find($currentUserId);
|
||||
$courses = $user->getCourses();
|
||||
$courseLpList = [];
|
||||
$sessionLpList = [];
|
||||
$checker = false;
|
||||
foreach ($courses as $course) {
|
||||
// Now get all the courses lp's
|
||||
$thisLpList = $em->getRepository('ChamiloCourseBundle:CLp')->findBy(['cId' => $course->getCourse()->getId()]);
|
||||
foreach ($thisLpList as $lp) {
|
||||
$courseLpList[$lp->getCId()] = $lp->getName().' ('.$course->getCourse()->getTitle().')';
|
||||
}
|
||||
}
|
||||
|
||||
// Here now checking the current user sessions
|
||||
$sessions = $user->getSessionCourseSubscriptions();
|
||||
foreach ($sessions as $session) {
|
||||
$thisLpList = $em
|
||||
->getRepository('ChamiloCourseBundle:CLp')
|
||||
->findBy(['sessionId' => $session->getSession()->getId()]);
|
||||
|
||||
// Here check all the lpItems
|
||||
foreach ($thisLpList as $lp) {
|
||||
$thisLpItems = $em->getRepository('ChamiloCourseBundle:CLpItem')->findBy(['lpId' => $lp->getId()]);
|
||||
|
||||
foreach ($thisLpItems as $item) {
|
||||
//Now only we need the final item and return the current LP
|
||||
if ($item->getItemType() == TOOL_LP_FINAL_ITEM) {
|
||||
$checker = true;
|
||||
$sessionLpList[$lp->getCId()] = $lp->getName().' ('.$session->getSession()->getName().')';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$thisLpList = $em->getRepository('ChamiloCourseBundle:CLp')->findBy(['cId' => $session->getCourse()->getId()]);
|
||||
|
||||
// Here check all the lpItems
|
||||
foreach ($thisLpList as $lp) {
|
||||
$thisLpItems = $em->getRepository('ChamiloCourseBundle:CLpItem')->findBy(['lpId' => $lp->getId()]);
|
||||
foreach ($thisLpItems as $item) {
|
||||
//Now only we need the final item and return the current LP
|
||||
if ($item->getItemType() == TOOL_LP_FINAL_ITEM) {
|
||||
$checker = true;
|
||||
$sessionLpList[$lp->getCId()] = $lp->getName().' ('.$session->getSession()->getName().')';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$selectOptions = $selectOptions + $courseLpList + $sessionLpList;
|
||||
if (!$checker) {
|
||||
$form->addHtml(
|
||||
Display::return_message(
|
||||
$plugin->get_lang('YourCoursesNeedAtLeastOneLearningPath'),
|
||||
'error'
|
||||
)
|
||||
);
|
||||
}
|
||||
$form->addSelect('info_select', get_lang('LearningPath'), $selectOptions);
|
||||
}
|
||||
|
||||
$form->addHidden('t', intval($_GET['t']));
|
||||
$form->addHidden('i', intval($_GET['i']));
|
||||
$form->addButton('submit', $plugin->get_lang('ConfirmOrder'), 'check', 'success');
|
||||
|
||||
if ($form->validate()) {
|
||||
$formValues = $form->getSubmitValues();
|
||||
|
||||
if (!isset($formValues['payment_type'])) {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('NeedToSelectPaymentType'), 'error', false)
|
||||
);
|
||||
header('Location:'.api_get_self().'?'.$queryString);
|
||||
exit;
|
||||
}
|
||||
|
||||
$infoSelected = [];
|
||||
if ($infoRequired) {
|
||||
if (isset($formValues['info_select'])) {
|
||||
$infoSelected = $formValues['info_select'];
|
||||
} else {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('AdditionalInfoRequired'), 'error', false)
|
||||
);
|
||||
header('Location:'.api_get_self().'?'.$queryString);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$serviceSaleId = $plugin->registerServiceSale(
|
||||
$serviceId,
|
||||
$formValues['payment_type'],
|
||||
$infoSelected,
|
||||
$formValues['c']
|
||||
);
|
||||
|
||||
if ($serviceSaleId !== false) {
|
||||
$_SESSION['bc_service_sale_id'] = $serviceSaleId;
|
||||
|
||||
if (isset($formValues['c'])) {
|
||||
$couponSaleId = $plugin->registerCouponServiceSale($serviceSaleId, $formValues['c']);
|
||||
if ($couponSaleId !== false) {
|
||||
$plugin->updateCouponDelivered($formValues['c']);
|
||||
$_SESSION['bc_coupon_id'] = $formValues['c'];
|
||||
}
|
||||
}
|
||||
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/service_process_confirm.php');
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
$formCoupon = new FormValidator('confirm_coupon');
|
||||
if ($formCoupon->validate()) {
|
||||
$formCouponValues = $formCoupon->getSubmitValues();
|
||||
|
||||
if (!$formCouponValues['coupon_code']) {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('NeedToAddCouponCode'), 'error', false)
|
||||
);
|
||||
header('Location:'.api_get_self().'?'.$queryString);
|
||||
exit;
|
||||
}
|
||||
|
||||
$coupon = $plugin->getCouponServiceByCode($formCouponValues['coupon_code'], $formCouponValues['i']);
|
||||
|
||||
if ($coupon == null) {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('CouponNotValid'), 'error', false)
|
||||
);
|
||||
header('Location:'.api_get_self().'?'.$queryString);
|
||||
exit;
|
||||
}
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('CouponRedeemed'), 'success', false)
|
||||
);
|
||||
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/service_process.php?i='.$_REQUEST['i'].'&t='.$_REQUEST['t'].'&c='.$formCouponValues['coupon_code']);
|
||||
|
||||
exit;
|
||||
}
|
||||
$formCoupon->addText('coupon_code', $plugin->get_lang('CouponsCode'), true);
|
||||
$formCoupon->addHidden('t', intval($_GET['t']));
|
||||
$formCoupon->addHidden('i', intval($_GET['i']));
|
||||
if ($coupon != null) {
|
||||
$form->addHidden('c', intval($coupon['id']));
|
||||
}
|
||||
$formCoupon->addButton('submit', $plugin->get_lang('RedeemCoupon'), 'check', 'success', 'btn-lg pull-right');
|
||||
|
||||
// View
|
||||
$templateName = $plugin->get_lang('PaymentMethods');
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'service_catalog.php',
|
||||
'name' => $plugin->get_lang('ListOfServicesOnSale'),
|
||||
];
|
||||
|
||||
$tpl = new Template($templateName);
|
||||
$tpl->assign('buying_service', true);
|
||||
$tpl->assign('service', $serviceInfo);
|
||||
$tpl->assign('user', api_get_user_info());
|
||||
$tpl->assign('form_coupon', $formCoupon->returnForm());
|
||||
$tpl->assign('form', $form->returnForm());
|
||||
$content = $tpl->fetch('buycourses/view/service_process.tpl');
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template();
|
||||
385
plugin/buycourses/src/service_process_confirm.php
Normal file
385
plugin/buycourses/src/service_process_confirm.php
Normal file
@@ -0,0 +1,385 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
use ChamiloSession as Session;
|
||||
|
||||
/**
|
||||
* Process purchase confirmation script for the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
require_once '../config.php';
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$serviceSaleId = Session::read('bc_service_sale_id');
|
||||
$couponId = Session::read('bc_coupon_id');
|
||||
|
||||
if (empty($serviceSaleId)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$serviceSale = $plugin->getServiceSale($serviceSaleId, $coupon);
|
||||
$userInfo = api_get_user_info($serviceSale['buyer']['id']);
|
||||
|
||||
if (!empty($couponId)) {
|
||||
$coupon = $plugin->getCouponService($couponId, $serviceSale['service_id']);
|
||||
$serviceSale['item'] = $plugin->getService($serviceSale['service_id'], $coupon);
|
||||
}
|
||||
|
||||
if (empty($serviceSale)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$currency = $plugin->getCurrency($serviceSale['currency_id']);
|
||||
$globalParameters = $plugin->getGlobalParameters();
|
||||
|
||||
switch ($serviceSale['payment_type']) {
|
||||
case BuyCoursesPlugin::PAYMENT_TYPE_PAYPAL:
|
||||
$paypalParams = $plugin->getPaypalParams();
|
||||
|
||||
$pruebas = $paypalParams['sandbox'] == 1;
|
||||
$paypalUsername = $paypalParams['username'];
|
||||
$paypalPassword = $paypalParams['password'];
|
||||
$paypalSignature = $paypalParams['signature'];
|
||||
|
||||
// This var $itemPrice may be "0" if the transaction does not include a one-time purchase such as when you set up
|
||||
// a billing agreement for a recurring payment that is not immediately charged. When the field is set to 0,
|
||||
// purchase-specific fields are ignored. This little condition handle this fact.
|
||||
$itemPrice = $serviceSale['price'];
|
||||
|
||||
$returnUrl = api_get_path(WEB_PLUGIN_PATH).'buycourses/src/service_success.php';
|
||||
$cancelUrl = api_get_path(WEB_PLUGIN_PATH).'buycourses/src/service_error.php';
|
||||
|
||||
// The extra params for handle the hard job, this var is VERY IMPORTANT !!
|
||||
$extra = '';
|
||||
require_once 'paypalfunctions.php';
|
||||
|
||||
$extra .= "&L_PAYMENTREQUEST_0_NAME0={$serviceSale['service']['name']}";
|
||||
$extra .= "&L_PAYMENTREQUEST_0_QTY0=1";
|
||||
$extra .= "&L_PAYMENTREQUEST_0_AMT0=$itemPrice";
|
||||
|
||||
// Full Checkout express
|
||||
$expressCheckout = CallShortcutExpressCheckout(
|
||||
$itemPrice,
|
||||
$currency['iso_code'],
|
||||
'paypal',
|
||||
$returnUrl,
|
||||
$cancelUrl,
|
||||
$extra
|
||||
);
|
||||
|
||||
if ($expressCheckout['ACK'] !== 'Success') {
|
||||
$erroMessage = vsprintf(
|
||||
$plugin->get_lang('ErrorOccurred'),
|
||||
[$expressCheckout['L_ERRORCODE0'], $expressCheckout['L_LONGMESSAGE0']]
|
||||
);
|
||||
Display::addFlash(
|
||||
Display::return_message($erroMessage, 'error', false)
|
||||
);
|
||||
|
||||
$plugin->cancelServiceSale($serviceSale['id']);
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/service_catalog.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!empty($globalParameters['sale_email'])) {
|
||||
$messageConfirmTemplate = new Template();
|
||||
$messageConfirmTemplate->assign('user', $userInfo);
|
||||
$messageConfirmTemplate->assign(
|
||||
'sale',
|
||||
[
|
||||
'date' => $serviceSale['buy_date'],
|
||||
'product' => $serviceSale['service']['name'],
|
||||
'currency' => $currency['iso_code'],
|
||||
'price' => $serviceSale['price'],
|
||||
'reference' => $serviceSale['reference'],
|
||||
]
|
||||
);
|
||||
|
||||
api_mail_html(
|
||||
'',
|
||||
$globalParameters['sale_email'],
|
||||
$plugin->get_lang('bc_subject'),
|
||||
$messageConfirmTemplate->fetch('buycourses/view/message_confirm.tpl')
|
||||
);
|
||||
}
|
||||
|
||||
RedirectToPayPal($expressCheckout['TOKEN']);
|
||||
break;
|
||||
case BuyCoursesPlugin::PAYMENT_TYPE_TRANSFER:
|
||||
$transferAccounts = $plugin->getTransferAccounts();
|
||||
|
||||
$form = new FormValidator(
|
||||
'success',
|
||||
'POST',
|
||||
api_get_self(),
|
||||
null,
|
||||
null,
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
|
||||
if ($form->validate()) {
|
||||
$formValues = $form->getSubmitValues();
|
||||
|
||||
if (isset($formValues['cancel'])) {
|
||||
$plugin->cancelServiceSale($serviceSale['id']);
|
||||
|
||||
unset($_SESSION['bc_service_sale_id']);
|
||||
unset($_SESSION['bc_coupon_id']);
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('OrderCancelled'), 'error', false)
|
||||
);
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/service_catalog.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$messageTemplate = new Template();
|
||||
$messageTemplate->assign(
|
||||
'service_sale',
|
||||
[
|
||||
'name' => $serviceSale['service']['name'],
|
||||
'buyer' => $serviceSale['buyer']['name'],
|
||||
'buy_date' => $serviceSale['buy_date'],
|
||||
'start_date' => $serviceSale['start_date'],
|
||||
'end_date' => $serviceSale['end_date'],
|
||||
'currency' => $currency['iso_code'],
|
||||
'price' => $serviceSale['price'],
|
||||
'reference' => $serviceSale['reference'],
|
||||
]
|
||||
);
|
||||
$messageTemplate->assign('transfer_accounts', $transferAccounts);
|
||||
$buyer = api_get_user_info($serviceSale['buyer']['id']);
|
||||
|
||||
MessageManager::send_message_simple(
|
||||
$buyer['user_id'],
|
||||
$plugin->get_lang('bc_subject'),
|
||||
$messageTemplate->fetch('buycourses/view/service_message_transfer.tpl')
|
||||
);
|
||||
|
||||
if (!empty($globalParameters['sale_email'])) {
|
||||
$messageConfirmTemplate = new Template();
|
||||
$messageConfirmTemplate->assign('user', $userInfo);
|
||||
$messageConfirmTemplate->assign(
|
||||
'sale',
|
||||
[
|
||||
'date' => $serviceSale['buy_date'],
|
||||
'product' => $serviceSale['service']['name'],
|
||||
'currency' => $currency['iso_code'],
|
||||
'price' => $serviceSale['price'],
|
||||
'reference' => $serviceSale['reference'],
|
||||
]
|
||||
);
|
||||
|
||||
api_mail_html(
|
||||
'',
|
||||
$globalParameters['sale_email'],
|
||||
$plugin->get_lang('bc_subject'),
|
||||
$messageConfirmTemplate->fetch('buycourses/view/message_confirm.tpl')
|
||||
);
|
||||
}
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf(
|
||||
$plugin->get_lang('PurchaseStatusX'),
|
||||
$plugin->get_lang('PendingReasonByTransfer')
|
||||
),
|
||||
'success',
|
||||
false
|
||||
)
|
||||
);
|
||||
|
||||
unset($_SESSION['bc_service_sale_id']);
|
||||
unset($_SESSION['bc_coupon_id']);
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/service_catalog.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$form->addButton(
|
||||
'confirm',
|
||||
$plugin->get_lang('ConfirmOrder'),
|
||||
'check',
|
||||
'success',
|
||||
'default',
|
||||
null,
|
||||
['id' => 'confirm']
|
||||
);
|
||||
$form->addButton(
|
||||
'cancel',
|
||||
$plugin->get_lang('CancelOrder'),
|
||||
'times',
|
||||
'danger',
|
||||
'default',
|
||||
null,
|
||||
['id' => 'cancel']
|
||||
);
|
||||
|
||||
$template = new Template();
|
||||
$template->assign('terms', $globalParameters['terms_and_conditions']);
|
||||
$template->assign('title', $serviceSale['service']['name']);
|
||||
$template->assign('price', $serviceSale['price']);
|
||||
$template->assign('currency', $serviceSale['currency_id']);
|
||||
$template->assign('buying_service', $serviceSale);
|
||||
$template->assign('user', $userInfo);
|
||||
$template->assign('service', $serviceSale['service']);
|
||||
$template->assign('service_item', $serviceSale['item']);
|
||||
$template->assign('transfer_accounts', $transferAccounts);
|
||||
$template->assign('form', $form->returnForm());
|
||||
|
||||
$content = $template->fetch('buycourses/view/process_confirm.tpl');
|
||||
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
break;
|
||||
case BuyCoursesPlugin::PAYMENT_TYPE_CULQI:
|
||||
// We need to include the main online script, acording to the Culqi documentation the JS needs to be loeaded
|
||||
// directly from the main url "https://integ-pago.culqi.com" because a local copy of this JS is not supported
|
||||
$htmlHeadXtra[] = '<script src="//integ-pago.culqi.com/js/v1"></script>';
|
||||
|
||||
$form = new FormValidator(
|
||||
'success',
|
||||
'POST',
|
||||
api_get_self(),
|
||||
null,
|
||||
null,
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
|
||||
if ($form->validate()) {
|
||||
$formValues = $form->getSubmitValues();
|
||||
if (isset($formValues['cancel'])) {
|
||||
$plugin->cancelServiceSale($serviceSale['id']);
|
||||
|
||||
unset($_SESSION['bc_service_sale_id']);
|
||||
unset($_SESSION['bc_coupon_id']);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
$plugin->get_lang('OrderCanceled'),
|
||||
'warning',
|
||||
false
|
||||
)
|
||||
);
|
||||
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/index.php');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$form->addButton(
|
||||
'confirm',
|
||||
$plugin->get_lang('ConfirmOrder'),
|
||||
'check',
|
||||
'success',
|
||||
'default',
|
||||
null,
|
||||
['id' => 'confirm']
|
||||
);
|
||||
$form->addButton(
|
||||
'cancel',
|
||||
$plugin->get_lang('CancelOrder'),
|
||||
'times',
|
||||
'danger',
|
||||
'default',
|
||||
null,
|
||||
['id' => 'cancel']
|
||||
);
|
||||
|
||||
$template = new Template();
|
||||
$template->assign('terms', $globalParameters['terms_and_conditions']);
|
||||
$template->assign('title', $serviceSale['service']['name']);
|
||||
$template->assign('price', floatval($serviceSale['price']));
|
||||
$template->assign('currency', $plugin->getSelectedCurrency());
|
||||
$template->assign('buying_service', $serviceSale);
|
||||
$template->assign('user', $userInfo);
|
||||
$template->assign('service', $serviceSale['service']);
|
||||
$template->assign('service_item', $serviceSale['item']);
|
||||
$template->assign('form', $form->returnForm());
|
||||
$template->assign('is_culqi_payment', true);
|
||||
$template->assign('culqi_params', $culqiParams = $plugin->getCulqiParams());
|
||||
$content = $template->fetch('buycourses/view/process_confirm.tpl');
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
break;
|
||||
|
||||
case BuyCoursesPlugin::PAYMENT_TYPE_TPV_CECABANK:
|
||||
$cecabankParams = $plugin->getcecabankParams();
|
||||
$currency = $plugin->getCurrency($sale['currency_id']);
|
||||
|
||||
$form = new FormValidator(
|
||||
'success',
|
||||
'POST',
|
||||
api_get_self(),
|
||||
null,
|
||||
null,
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
|
||||
if ($form->validate()) {
|
||||
$formValues = $form->getSubmitValues();
|
||||
|
||||
if (isset($formValues['cancel'])) {
|
||||
$plugin->cancelServiceSale($sale['id']);
|
||||
|
||||
unset($_SESSION['bc_sale_id']);
|
||||
unset($_SESSION['bc_coupon_id']);
|
||||
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$urlTpv = $cecabankParams['merchart_id'];
|
||||
$currency = $plugin->getCurrency($sale['currency_id']);
|
||||
$signature = $plugin->getCecabankSignature($sale['reference'], $sale['price']);
|
||||
|
||||
echo '<form name="tpv_chamilo" action="'.$urlTpv.'" method="POST">';
|
||||
echo '<input type="hidden" name="MerchantID" value="'.$cecabankParams['merchant_id'].'" />';
|
||||
echo '<input type="hidden" name="AcquirerBIN" value="'.$cecabankParams['acquirer_bin'].'" />';
|
||||
echo '<input type="hidden" name="TerminalID" value="'.$cecabankParams['terminal_id'].'" />';
|
||||
echo '<input type="hidden" name="URL_OK" value="'.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/cecabank_success.php'.'" />';
|
||||
echo '<input type="hidden" name="URL_NOK" value="'.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/cecabank_cancel.php'.'" />';
|
||||
echo '<input type="hidden" name="Firma" value="'.$signature.'" />';
|
||||
echo '<input type="hidden" name="Cifrado" value="'.$cecabankParams['cypher'].'" />';
|
||||
echo '<input type="hidden" name="Num_operacion" value="'.$sale['reference'].'" />';
|
||||
echo '<input type="hidden" name="Importe" value="'.($sale['price'] * 100).'" />';
|
||||
echo '<input type="hidden" name="TipoMoneda" value="'.$cecabankParams['currency'].'" />';
|
||||
echo '<input type="hidden" name="Exponente" value="'.$cecabankParams['exponent'].'" />';
|
||||
echo '<input type="hidden" name="Pago_soportado" value="'.$cecabankParams['supported_payment'].'" />';
|
||||
echo '</form>';
|
||||
|
||||
echo '<SCRIPT language=javascript>';
|
||||
echo 'document.tpv_chamilo.submit();';
|
||||
echo '</script>';
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$form->addButton(
|
||||
'confirm',
|
||||
$plugin->get_lang('ConfirmOrder'),
|
||||
'check',
|
||||
'success',
|
||||
'default',
|
||||
null,
|
||||
['id' => 'confirm']
|
||||
);
|
||||
$form->addButtonCancel($plugin->get_lang('CancelOrder'), 'cancel');
|
||||
|
||||
$template = new Template();
|
||||
$template->assign('terms', $globalParameters['terms_and_conditions']);
|
||||
$template->assign('title', $serviceSale['service']['name']);
|
||||
$template->assign('price', $serviceSale['price']);
|
||||
$template->assign('currency', $serviceSale['currency_id']);
|
||||
$template->assign('buying_service', $serviceSale);
|
||||
$template->assign('user', $userInfo);
|
||||
$template->assign('service', $serviceSale['service']);
|
||||
$template->assign('service_item', $serviceSale['item']);
|
||||
$template->assign('transfer_accounts', $transferAccounts);
|
||||
$template->assign('form', $form->returnForm());
|
||||
|
||||
$content = $template->fetch('buycourses/view/process_confirm.tpl');
|
||||
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
|
||||
break;
|
||||
}
|
||||
103
plugin/buycourses/src/service_sales_report.php
Normal file
103
plugin/buycourses/src/service_sales_report.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* List of pending payments of the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once '../config.php';
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
|
||||
$paypalEnable = $plugin->get('paypal_enable');
|
||||
$commissionsEnable = $plugin->get('commissions_enable');
|
||||
$includeServices = $plugin->get('include_services');
|
||||
$invoicingEnable = $plugin->get('invoicing_enable') === 'true';
|
||||
|
||||
$saleStatuses = $plugin->getServiceSaleStatuses();
|
||||
$selectedStatus = isset($_GET['status']) ? $_GET['status'] : BuyCoursesPlugin::SALE_STATUS_PENDING;
|
||||
$form = new FormValidator('search', 'get');
|
||||
|
||||
if ($form->validate()) {
|
||||
$selectedStatus = $form->getSubmitValue('status');
|
||||
if ($selectedStatus === false) {
|
||||
$selectedStatus = BuyCoursesPlugin::SALE_STATUS_PENDING;
|
||||
}
|
||||
}
|
||||
|
||||
$form->addSelect('status', $plugin->get_lang('OrderStatus'), $saleStatuses, ['cols-size' => [0, 0, 0]]);
|
||||
$form->addText('user', get_lang('User'), false, ['cols-size' => [0, 0, 0]]);
|
||||
$form->addButtonSearch(get_lang('Search'), 'search');
|
||||
|
||||
$servicesSales = $plugin->getServiceSales(0, $selectedStatus);
|
||||
|
||||
foreach ($servicesSales as &$sale) {
|
||||
if (isset($sale['discount_amount']) && $sale['discount_amount'] != 0) {
|
||||
$sale['total_discount'] = $plugin->getPriceWithCurrencyFromIsoCode($sale['discount_amount'], $sale['iso_code']);
|
||||
$sale['coupon_code'] = $plugin->getServiceSaleCouponCode($sale['id']);
|
||||
}
|
||||
}
|
||||
|
||||
$interbreadcrumb[] = ['url' => '../index.php', 'name' => $plugin->get_lang('plugin_title')];
|
||||
|
||||
$webPluginPath = api_get_path(WEB_PLUGIN_PATH);
|
||||
$htmlHeadXtra[] = api_get_css($webPluginPath.'buycourses/resources/css/style.css');
|
||||
$htmlHeadXtra[] = api_get_css($webPluginPath.'buycourses/resources/js/modals.js');
|
||||
|
||||
$templateName = $plugin->get_lang('SalesReport');
|
||||
|
||||
$template = new Template($templateName);
|
||||
|
||||
$toolbar = Display::url(
|
||||
Display::returnFontAwesomeIcon('file-excel-o').
|
||||
get_lang('GenerateReport'),
|
||||
api_get_path(WEB_PLUGIN_PATH).'buycourses/src/export_report.php',
|
||||
['class' => 'btn btn-primary']
|
||||
);
|
||||
|
||||
if ($paypalEnable == 'true' && $commissionsEnable == 'true') {
|
||||
$toolbar .= Display::toolbarButton(
|
||||
$plugin->get_lang('PaypalPayoutCommissions'),
|
||||
api_get_path(WEB_PLUGIN_PATH).'buycourses/src/paypal_payout.php',
|
||||
'paypal',
|
||||
'primary',
|
||||
['title' => $plugin->get_lang('PaypalPayoutCommissions')]
|
||||
);
|
||||
}
|
||||
|
||||
$template->assign(
|
||||
'actions',
|
||||
Display::toolbarAction('toolbar', [$toolbar])
|
||||
);
|
||||
|
||||
if ($commissionsEnable == 'true') {
|
||||
$toolbar = Display::toolbarButton(
|
||||
$plugin->get_lang('PayoutReport'),
|
||||
api_get_path(WEB_PLUGIN_PATH).'buycourses/src/payout_report.php',
|
||||
'money',
|
||||
'info',
|
||||
['title' => $plugin->get_lang('PayoutReport')]
|
||||
);
|
||||
|
||||
$template->assign(
|
||||
'actions',
|
||||
Display::toolbarAction('toolbar', [$toolbar])
|
||||
);
|
||||
}
|
||||
$template->assign('form', $form->returnForm());
|
||||
$template->assign('showing_services', true);
|
||||
$template->assign('services_are_included', $includeServices);
|
||||
$template->assign('sale_list', $servicesSales);
|
||||
$template->assign('sale_status_cancelled', BuyCoursesPlugin::SERVICE_STATUS_CANCELLED);
|
||||
$template->assign('sale_status_pending', BuyCoursesPlugin::SERVICE_STATUS_PENDING);
|
||||
$template->assign('sale_status_completed', BuyCoursesPlugin::SERVICE_STATUS_COMPLETED);
|
||||
$template->assign('invoicing_enable', $invoicingEnable);
|
||||
$content = $template->fetch('buycourses/view/service_sales_report.tpl');
|
||||
$template->assign('content', $content);
|
||||
$template->assign('header', $templateName);
|
||||
$template->display_one_col_template();
|
||||
186
plugin/buycourses/src/service_success.php
Normal file
186
plugin/buycourses/src/service_success.php
Normal file
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Success page for the purchase of a service in the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
require_once '../config.php';
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$paypalEnabled = $plugin->get('paypal_enable') === 'true';
|
||||
|
||||
if (!$paypalEnabled) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$serviceSaleId = $_SESSION['bc_service_sale_id'];
|
||||
$serviceSale = $plugin->getServiceSale($serviceSaleId);
|
||||
$itemPrice = $serviceSale['price'];
|
||||
|
||||
if (empty($serviceSale)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$paypalParams = $plugin->getPaypalParams();
|
||||
|
||||
$pruebas = $paypalParams['sandbox'] == 1;
|
||||
$paypalUsername = $paypalParams['username'];
|
||||
$paypalPassword = $paypalParams['password'];
|
||||
$paypalSignature = $paypalParams['signature'];
|
||||
|
||||
require_once "paypalfunctions.php";
|
||||
|
||||
$buyerInformation = GetShippingDetails(urlencode($_SESSION['TOKEN']));
|
||||
|
||||
$form = new FormValidator(
|
||||
'success',
|
||||
'POST',
|
||||
api_get_self(),
|
||||
null,
|
||||
null,
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
$form->addButton(
|
||||
'confirm',
|
||||
$plugin->get_lang('ConfirmOrder'),
|
||||
'check',
|
||||
'success'
|
||||
);
|
||||
$form->addButtonCancel($plugin->get_lang('CancelOrder'), 'cancel');
|
||||
|
||||
if ($form->validate()) {
|
||||
$formValues = $form->getSubmitValues();
|
||||
if (isset($formValues['cancel'])) {
|
||||
$plugin->cancelServiceSale($serviceSale['id']);
|
||||
|
||||
unset($_SESSION['bc_service_sale_id']);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('OrderCancelled'), 'error', false)
|
||||
);
|
||||
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/service_catalog.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$confirmPayments = ConfirmPayment($itemPrice);
|
||||
if ($confirmPayments['ACK'] !== 'Success') {
|
||||
$erroMessage = vsprintf(
|
||||
$plugin->get_lang('ErrorOccurred'),
|
||||
[$expressCheckout['L_ERRORCODE0'], $confirmPayments['L_LONGMESSAGE0']]
|
||||
);
|
||||
Display::addFlash(
|
||||
Display::return_message($erroMessage, 'error', false)
|
||||
);
|
||||
unset($_SESSION['wizard']);
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/service_catalog.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
switch ($confirmPayments["PAYMENTINFO_0_PAYMENTSTATUS"]) {
|
||||
case 'Completed':
|
||||
$serviceSaleIsCompleted = $plugin->completeServiceSale($serviceSale['id']);
|
||||
|
||||
if ($serviceSaleIsCompleted) {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf($plugin->get_lang('SubscriptionToServiceXSuccessful'), $serviceSale['service']['name']),
|
||||
'success'
|
||||
)
|
||||
);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('ErrorContactPlatformAdmin'), 'error')
|
||||
);
|
||||
break;
|
||||
case 'Pending':
|
||||
switch ($confirmPayments["PAYMENTINFO_0_PENDINGREASON"]) {
|
||||
case 'address':
|
||||
$purchaseStatus = $plugin->get_lang('PendingReasonByAddress');
|
||||
break;
|
||||
case 'authorization':
|
||||
$purchaseStatus = $plugin->get_lang('PendingReasonByAuthorization');
|
||||
break;
|
||||
case 'echeck':
|
||||
$purchaseStatus = $plugin->get_lang('PendingReasonByEcheck');
|
||||
break;
|
||||
case 'intl':
|
||||
$purchaseStatus = $plugin->get_lang('PendingReasonByIntl');
|
||||
break;
|
||||
case 'multicurrency':
|
||||
$purchaseStatus = $plugin->get_lang('PendingReasonByMulticurrency');
|
||||
break;
|
||||
case 'order':
|
||||
$purchaseStatus = $plugin->get_lang('PendingReasonByOrder');
|
||||
break;
|
||||
case 'paymentreview':
|
||||
$purchaseStatus = $plugin->get_lang('PendingReasonByPaymentReview');
|
||||
break;
|
||||
case 'regulatoryreview':
|
||||
$purchaseStatus = $plugin->get_lang('PendingReasonByRegulatoryReview');
|
||||
break;
|
||||
case 'unilateral':
|
||||
$purchaseStatus = $plugin->get_lang('PendingReasonByUnilateral');
|
||||
break;
|
||||
case 'upgrade':
|
||||
$purchaseStatus = $plugin->get_lang('PendingReasonByUpgrade');
|
||||
break;
|
||||
case 'verify':
|
||||
$purchaseStatus = $plugin->get_lang('PendingReasonByVerify');
|
||||
break;
|
||||
case 'other':
|
||||
default:
|
||||
$purchaseStatus = $plugin->get_lang('PendingReasonByOther');
|
||||
break;
|
||||
}
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf($plugin->get_lang('PurchaseStatusX'), $purchaseStatus),
|
||||
'warning',
|
||||
false
|
||||
)
|
||||
);
|
||||
break;
|
||||
default:
|
||||
$plugin->cancelServiceSale(intval($serviceSale['id']));
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('ErrorContactPlatformAdmin'), 'error')
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
unset($_SESSION['bc_service_sale_id']);
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/service_catalog.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$token = isset($_GET['token']) ? Security::remove_XSS($_GET['token']) : null;
|
||||
if (empty($token)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$interbreadcrumb[] = [
|
||||
"url" => "service_catalog.php",
|
||||
"name" => $plugin->get_lang('ListOfServicesOnSale'),
|
||||
];
|
||||
|
||||
$templateName = $plugin->get_lang('PaymentMethods');
|
||||
$tpl = new Template($templateName);
|
||||
$tpl->assign('title', $serviceSale['service']['name']);
|
||||
$tpl->assign('price', $serviceSale['price']);
|
||||
$tpl->assign('currency', $serviceSale['currency_id']);
|
||||
$tpl->assign('service', $serviceSale);
|
||||
$tpl->assign('buying_service', true);
|
||||
$tpl->assign('user', api_get_user_info($serviceSale['buyer']['id']));
|
||||
$tpl->assign('form', $form->returnForm());
|
||||
|
||||
$content = $tpl->fetch('buycourses/view/success.tpl');
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template();
|
||||
141
plugin/buycourses/src/services_add.php
Normal file
141
plugin/buycourses/src/services_add.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Create new Services for the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once '../../../main/inc/global.inc.php';
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$currency = $plugin->getSelectedCurrency();
|
||||
$em = Database::getManager();
|
||||
$users = UserManager::getRepository()->findAll();
|
||||
$userOptions = [];
|
||||
if (!empty($users)) {
|
||||
foreach ($users as $user) {
|
||||
$userOptions[$user->getId()] = $user->getCompleteNameWithUsername();
|
||||
}
|
||||
}
|
||||
|
||||
api_protect_admin_script(true);
|
||||
|
||||
$htmlHeadXtra[] = api_get_css_asset('cropper/dist/cropper.min.css');
|
||||
$htmlHeadXtra[] = api_get_asset('cropper/dist/cropper.min.js');
|
||||
|
||||
//view
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_PLUGIN_PATH).'buycourses/index.php',
|
||||
'name' => $plugin->get_lang('plugin_title'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'list_service.php',
|
||||
'name' => $plugin->get_lang('Services'),
|
||||
];
|
||||
|
||||
$globalSettingsParams = $plugin->getGlobalParameters();
|
||||
|
||||
$formDefaultValues = [
|
||||
'price' => 0,
|
||||
'tax_perc' => $globalSettingsParams['global_tax_perc'],
|
||||
'duration_days' => 0,
|
||||
'applies_to' => 0,
|
||||
'visibility' => true,
|
||||
];
|
||||
|
||||
$form = new FormValidator('Services');
|
||||
$form->addText('name', $plugin->get_lang('ServiceName'));
|
||||
$form->addHtmlEditor('description', $plugin->get_lang('Description'));
|
||||
$form->addElement(
|
||||
'number',
|
||||
'price',
|
||||
[$plugin->get_lang('Price'), null, $currency['iso_code']],
|
||||
['step' => 0.01]
|
||||
);
|
||||
$form->addElement(
|
||||
'number',
|
||||
'tax_perc',
|
||||
[$plugin->get_lang('TaxPerc'), $plugin->get_lang('TaxPercDescription'), '%'],
|
||||
['step' => 1, 'placeholder' => $globalSettingsParams['global_tax_perc'].'% '.$plugin->get_lang('ByDefault')]
|
||||
);
|
||||
$form->addElement(
|
||||
'number',
|
||||
'duration_days',
|
||||
[$plugin->get_lang('Duration'), null, get_lang('Days')],
|
||||
['step' => 1]
|
||||
);
|
||||
$form->addElement(
|
||||
'radio',
|
||||
'applies_to',
|
||||
$plugin->get_lang('AppliesTo'),
|
||||
get_lang('None'),
|
||||
0
|
||||
);
|
||||
$form->addElement(
|
||||
'radio',
|
||||
'applies_to',
|
||||
null,
|
||||
get_lang('User'),
|
||||
1
|
||||
);
|
||||
$form->addElement(
|
||||
'radio',
|
||||
'applies_to',
|
||||
null,
|
||||
get_lang('Course'),
|
||||
2
|
||||
);
|
||||
$form->addElement(
|
||||
'radio',
|
||||
'applies_to',
|
||||
null,
|
||||
get_lang('Session'),
|
||||
3
|
||||
);
|
||||
$form->addElement(
|
||||
'radio',
|
||||
'applies_to',
|
||||
null,
|
||||
get_lang('TemplateTitleCertificate'),
|
||||
4
|
||||
);
|
||||
$form->addSelect(
|
||||
'owner_id',
|
||||
get_lang('Owner'),
|
||||
$userOptions
|
||||
);
|
||||
$form->addCheckBox('visibility', $plugin->get_lang('VisibleInCatalog'));
|
||||
$form->addFile(
|
||||
'picture',
|
||||
(get_lang(
|
||||
'AddImage'
|
||||
)),
|
||||
['id' => 'picture', 'class' => 'picture-form', 'crop_image' => true, 'crop_ratio' => '16 / 9']
|
||||
);
|
||||
$form->addText('video_url', get_lang('VideoUrl'), false);
|
||||
$form->addHtmlEditor('service_information', $plugin->get_lang('ServiceInformation'), false);
|
||||
$form->addButtonSave(get_lang('Add'));
|
||||
$form->setDefaults($formDefaultValues);
|
||||
|
||||
if ($form->validate()) {
|
||||
$values = $form->getSubmitValues();
|
||||
|
||||
$plugin->storeService($values);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('ServiceAdded'), 'success')
|
||||
);
|
||||
|
||||
header('Location: list_service.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$templateName = $plugin->get_lang('NewService');
|
||||
$tpl = new Template($templateName);
|
||||
|
||||
$tpl->assign('header', $templateName);
|
||||
$tpl->assign('content', $form->returnForm());
|
||||
$tpl->display_one_col_template();
|
||||
161
plugin/buycourses/src/services_edit.php
Normal file
161
plugin/buycourses/src/services_edit.php
Normal file
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Create new Services for the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once '../../../main/inc/global.inc.php';
|
||||
|
||||
$serviceId = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : null;
|
||||
|
||||
if (!$serviceId) {
|
||||
header('Location: list.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$currency = $plugin->getSelectedCurrency();
|
||||
$users = UserManager::getRepository()->findAll();
|
||||
$userOptions = [];
|
||||
if (!empty($users)) {
|
||||
foreach ($users as $user) {
|
||||
$userOptions[$user->getId()] = $user->getCompleteNameWithUsername();
|
||||
}
|
||||
}
|
||||
|
||||
api_protect_admin_script(true);
|
||||
$htmlHeadXtra[] = api_get_css_asset('cropper/dist/cropper.min.css');
|
||||
$htmlHeadXtra[] = api_get_asset('cropper/dist/cropper.min.js');
|
||||
|
||||
//view
|
||||
// breadcrumbs
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_PLUGIN_PATH).'buycourses/index.php',
|
||||
'name' => $plugin->get_lang('plugin_title'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'list_service.php',
|
||||
'name' => $plugin->get_lang('Services'),
|
||||
];
|
||||
|
||||
$globalSettingsParams = $plugin->getGlobalParameters();
|
||||
$service = $plugin->getService($serviceId);
|
||||
|
||||
$formDefaultValues = [
|
||||
'name' => $service['name'],
|
||||
'description' => $service['description'],
|
||||
'price' => $service['price'],
|
||||
'tax_perc' => $service['tax_perc'],
|
||||
'duration_days' => $service['duration_days'],
|
||||
'owner_id' => intval($service['owner_id']),
|
||||
'applies_to' => intval($service['applies_to']),
|
||||
'visibility' => ($service['visibility'] == 1) ? true : false,
|
||||
'image' => is_file(api_get_path(SYS_PLUGIN_PATH).'buycourses/uploads/services/images/simg-'.$serviceId.'.png')
|
||||
? api_get_path(WEB_PLUGIN_PATH).'buycourses/uploads/services/images/simg-'.$serviceId.'.png'
|
||||
: api_get_path(WEB_CODE_PATH).'img/session_default.png',
|
||||
'video_url' => $service['video_url'],
|
||||
'service_information' => $service['service_information'],
|
||||
];
|
||||
|
||||
$form = new FormValidator('Services');
|
||||
$form->addText('name', $plugin->get_lang('ServiceName'));
|
||||
$form->addHtmlEditor('description', $plugin->get_lang('Description'));
|
||||
$form->addElement(
|
||||
'number',
|
||||
'price',
|
||||
[$plugin->get_lang('Price'), null, $currency['iso_code']],
|
||||
['step' => 0.01]
|
||||
);
|
||||
$form->addElement(
|
||||
'number',
|
||||
'tax_perc',
|
||||
[$plugin->get_lang('TaxPerc'), $plugin->get_lang('TaxPercDescription'), '%'],
|
||||
['step' => 1, 'placeholder' => $globalSettingsParams['global_tax_perc'].'% '.$plugin->get_lang('ByDefault')]
|
||||
);
|
||||
$form->addElement(
|
||||
'number',
|
||||
'duration_days',
|
||||
[$plugin->get_lang('Duration'), null, get_lang('Days')],
|
||||
['step' => 1]
|
||||
);
|
||||
$form->addElement(
|
||||
'radio',
|
||||
'applies_to',
|
||||
$plugin->get_lang('AppliesTo'),
|
||||
get_lang('None'),
|
||||
0
|
||||
);
|
||||
$form->addElement(
|
||||
'radio',
|
||||
'applies_to',
|
||||
null,
|
||||
get_lang('User'),
|
||||
1
|
||||
);
|
||||
$form->addElement(
|
||||
'radio',
|
||||
'applies_to',
|
||||
null,
|
||||
get_lang('Course'),
|
||||
2
|
||||
);
|
||||
$form->addElement(
|
||||
'radio',
|
||||
'applies_to',
|
||||
null,
|
||||
get_lang('Session'),
|
||||
3
|
||||
);
|
||||
$form->addElement(
|
||||
'radio',
|
||||
'applies_to',
|
||||
null,
|
||||
get_lang('TemplateTitleCertificate'),
|
||||
4
|
||||
);
|
||||
$form->addSelect(
|
||||
'owner_id',
|
||||
get_lang('Owner'),
|
||||
$userOptions
|
||||
);
|
||||
$form->addCheckBox('visibility', $plugin->get_lang('VisibleInCatalog'));
|
||||
$form->addFile(
|
||||
'picture',
|
||||
$formDefaultValues['image'] != '' ? get_lang('UpdateImage') : get_lang('AddImage'),
|
||||
['id' => 'picture', 'class' => 'picture-form', 'crop_image' => true, 'crop_ratio' => '16 / 9']
|
||||
);
|
||||
$form->addText('video_url', get_lang('VideoUrl'), false);
|
||||
$form->addHtmlEditor('service_information', $plugin->get_lang('ServiceInformation'), false);
|
||||
$form->addHidden('id', $serviceId);
|
||||
$form->addButtonSave(get_lang('Edit'));
|
||||
$form->addHtml('<br /><br /><br /><br />');
|
||||
$form->addButtonDelete($plugin->get_lang('DeleteThisService'), 'delete_service');
|
||||
$form->setDefaults($formDefaultValues);
|
||||
if ($form->validate()) {
|
||||
$values = $form->getSubmitValues();
|
||||
|
||||
if (isset($values['delete_service'])) {
|
||||
$plugin->deleteService($serviceId);
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('ServiceDeleted'), 'error')
|
||||
);
|
||||
} else {
|
||||
$plugin->updateService($values, $serviceId);
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('ServiceEdited'), 'success')
|
||||
);
|
||||
}
|
||||
header('Location: list_service.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$templateName = $plugin->get_lang('EditService');
|
||||
$tpl = new Template($templateName);
|
||||
|
||||
$tpl->assign('header', $templateName);
|
||||
$tpl->assign('content', $form->returnForm());
|
||||
$tpl->display_one_col_template();
|
||||
127
plugin/buycourses/src/session_catalog.php
Normal file
127
plugin/buycourses/src/session_catalog.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* List of courses.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$includeSessions = $plugin->get('include_sessions') === 'true';
|
||||
$includeServices = $plugin->get('include_services') === 'true';
|
||||
|
||||
if (!$includeSessions) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$nameFilter = null;
|
||||
$minFilter = 0;
|
||||
$maxFilter = 0;
|
||||
$sessionCategory = isset($_GET['session_category']) ? (int) $_GET['session_category'] : 0;
|
||||
$form = new FormValidator(
|
||||
'search_filter_form',
|
||||
'get',
|
||||
null,
|
||||
null,
|
||||
[],
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
|
||||
$form->removeAttribute('class');
|
||||
|
||||
if ($form->validate()) {
|
||||
$formValues = $form->getSubmitValues();
|
||||
$nameFilter = isset($formValues['name']) ? $formValues['name'] : null;
|
||||
$minFilter = isset($formValues['min']) ? $formValues['min'] : 0;
|
||||
$maxFilter = isset($formValues['max']) ? $formValues['max'] : 0;
|
||||
$sessionCategory = isset($formValues['session_category']) ? $formValues['session_category'] : $sessionCategory;
|
||||
}
|
||||
|
||||
$form->addHeader($plugin->get_lang('SearchFilter'));
|
||||
|
||||
$categoriesOptions = [
|
||||
'0' => get_lang('AllCategories'),
|
||||
];
|
||||
$categoriesList = SessionManager::get_all_session_category();
|
||||
if ($categoriesList != false) {
|
||||
foreach ($categoriesList as $categoryItem) {
|
||||
$categoriesOptions[$categoryItem['id']] = $categoryItem['name'];
|
||||
}
|
||||
}
|
||||
$form->addSelect(
|
||||
'session_category',
|
||||
get_lang('SessionCategory'),
|
||||
$categoriesOptions,
|
||||
[
|
||||
'id' => 'session_category',
|
||||
]
|
||||
);
|
||||
|
||||
$form->addText('name', get_lang('SessionName'), false);
|
||||
|
||||
$form->addElement(
|
||||
'number',
|
||||
'min',
|
||||
$plugin->get_lang('MinimumPrice'),
|
||||
['step' => '0.01', 'min' => '0']
|
||||
);
|
||||
$form->addElement(
|
||||
'number',
|
||||
'max',
|
||||
$plugin->get_lang('MaximumPrice'),
|
||||
['step' => '0.01', 'min' => '0']
|
||||
);
|
||||
$form->addHtml('<hr>');
|
||||
$form->addButtonFilter(get_lang('Search'));
|
||||
|
||||
$form->setDefaults(
|
||||
[
|
||||
'session_category' => $sessionCategory,
|
||||
]
|
||||
);
|
||||
$pageSize = BuyCoursesPlugin::PAGINATION_PAGE_SIZE;
|
||||
$currentPage = isset($_GET['page']) ? (int) $_GET['page'] : 1;
|
||||
$first = $pageSize * ($currentPage - 1);
|
||||
$sessionList = $plugin->getCatalogSessionList($first, $pageSize, $nameFilter, $minFilter, $maxFilter, 'all', $sessionCategory);
|
||||
$totalItems = $plugin->getCatalogSessionList($first, $pageSize, $nameFilter, $minFilter, $maxFilter, 'count', $sessionCategory);
|
||||
$pagesCount = ceil($totalItems / $pageSize);
|
||||
$pagination = BuyCoursesPlugin::returnPagination(api_get_self(), $currentPage, $pagesCount, $totalItems);
|
||||
|
||||
// View
|
||||
if (api_is_platform_admin()) {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'list.php',
|
||||
'name' => $plugin->get_lang('AvailableCoursesConfiguration'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'paymentsetup.php',
|
||||
'name' => $plugin->get_lang('PaymentsConfiguration'),
|
||||
];
|
||||
}
|
||||
|
||||
$templateName = $plugin->get_lang('CourseListOnSale');
|
||||
|
||||
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_PLUGIN_PATH).'buycourses/resources/css/style.css');
|
||||
|
||||
$template = new Template($templateName);
|
||||
$template->assign('search_filter_form', $form->returnForm());
|
||||
$template->assign('sessions_are_included', $includeSessions);
|
||||
$template->assign('services_are_included', $includeServices);
|
||||
$template->assign('showing_sessions', true);
|
||||
$template->assign('sessions', $sessionList);
|
||||
$template->assign('pagination', $pagination);
|
||||
|
||||
$countCourses = $plugin->getCatalogCourseList($first, $pageSize, $nameFilter, $minFilter, $maxFilter, 'count');
|
||||
|
||||
$template->assign('coursesExist', $countCourses > 0);
|
||||
$template->assign('sessionExist', true);
|
||||
|
||||
$content = $template->fetch('buycourses/view/catalog.tpl');
|
||||
|
||||
$template->assign('header', $templateName);
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
67
plugin/buycourses/src/session_panel.php
Normal file
67
plugin/buycourses/src/session_panel.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* User Panel.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$includeSessions = $plugin->get('include_sessions') === 'true';
|
||||
$includeServices = $plugin->get('include_services') === 'true';
|
||||
|
||||
$userInfo = api_get_user_info();
|
||||
|
||||
$productTypes = $plugin->getProductTypes();
|
||||
$saleStatuses = $plugin->getSaleStatuses();
|
||||
$paymentTypes = $plugin->getPaymentTypes();
|
||||
|
||||
$sales = $plugin->getSaleListByUserId($userInfo['id']);
|
||||
|
||||
$saleList = [];
|
||||
|
||||
foreach ($sales as $sale) {
|
||||
if ($sale['product_type'] == 2) {
|
||||
$saleList[] = [
|
||||
'id' => $sale['id'],
|
||||
'reference' => $sale['reference'],
|
||||
'date' => api_format_date($sale['date'], DATE_TIME_FORMAT_LONG_24H),
|
||||
'currency' => $sale['iso_code'],
|
||||
'price' => $sale['price'],
|
||||
'product_name' => $sale['product_name'],
|
||||
'product_type' => $productTypes[$sale['product_type']],
|
||||
'payment_type' => $paymentTypes[$sale['payment_type']],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$toolbar = Display::toolbarButton(
|
||||
$plugin->get_lang('CourseListOnSale'),
|
||||
'course_catalog.php',
|
||||
'search-plus',
|
||||
'primary',
|
||||
['title' => $plugin->get_lang('CourseListOnSale')]
|
||||
);
|
||||
|
||||
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_PLUGIN_PATH).'buycourses/resources/css/style.css');
|
||||
|
||||
$templateName = get_lang('TabsDashboard');
|
||||
$tpl = new Template($templateName);
|
||||
$tpl->assign('showing_courses', true);
|
||||
$tpl->assign('sessions_are_included', $includeSessions);
|
||||
$tpl->assign('services_are_included', $includeServices);
|
||||
$tpl->assign('sale_list', $saleList);
|
||||
|
||||
$content = $tpl->fetch('buycourses/view/session_panel.tpl');
|
||||
|
||||
$tpl->assign(
|
||||
'actions',
|
||||
Display::toolbarAction('toolbar', [$toolbar])
|
||||
);
|
||||
$tpl->assign('header', $templateName);
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template();
|
||||
30
plugin/buycourses/src/stripe_cancel.php
Normal file
30
plugin/buycourses/src/stripe_cancel.php
Normal file
@@ -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();
|
||||
$stripeEnabled = $plugin->get('stripe_enable') === 'true';
|
||||
|
||||
if (!$stripeEnabled) {
|
||||
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;
|
||||
65
plugin/buycourses/src/stripe_response.php
Normal file
65
plugin/buycourses/src/stripe_response.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
require_once '../config.php';
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$stripeEnabled = $plugin->get('stripe_enable') === 'true';
|
||||
|
||||
if (!$stripeEnabled) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$stripeParams = $plugin->getStripeParams();
|
||||
|
||||
$payload = @file_get_contents('php://input');
|
||||
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
|
||||
$event = null;
|
||||
|
||||
try {
|
||||
$event = \Stripe\Webhook::constructEvent(
|
||||
$payload, $sig_header, $stripeParams['endpoint_secret']
|
||||
);
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
http_response_code(400);
|
||||
exit();
|
||||
} catch (\Stripe\Exception\SignatureVerificationException $e) {
|
||||
http_response_code(400);
|
||||
exit();
|
||||
}
|
||||
|
||||
switch ($event->type) {
|
||||
case 'checkout.session.completed':
|
||||
$checkoutSession = $event->data->object;
|
||||
|
||||
$sale = $plugin->getSaleFromReference($checkoutSession->id);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
$saleIsCompleted = $plugin->completeSale($sale['id']);
|
||||
|
||||
if ($saleIsCompleted) {
|
||||
$plugin->storePayouts($sale['id']);
|
||||
}
|
||||
|
||||
// no break
|
||||
default:
|
||||
echo 'Received unknown event type '.$event->type;
|
||||
}
|
||||
|
||||
http_response_code(200);
|
||||
78
plugin/buycourses/src/stripe_success.php
Normal file
78
plugin/buycourses/src/stripe_success.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?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();
|
||||
$stripeEnabled = $plugin->get('stripe_enable') === 'true';
|
||||
|
||||
if (!$stripeEnabled) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$sale = $plugin->getSale($_SESSION['bc_sale_id']);
|
||||
|
||||
if (empty($sale)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$userInfo = api_get_user_info($sale['user_id']);
|
||||
$currency = $plugin->getCurrency($sale['currency_id']);
|
||||
$globalParameters = $plugin->getGlobalParameters();
|
||||
|
||||
if (!empty($globalParameters['sale_email'])) {
|
||||
$messageConfirmBuyerTemplate = new Template();
|
||||
$messageConfirmBuyerTemplate->assign('user', $userInfo);
|
||||
$messageConfirmBuyerTemplate->assign(
|
||||
'sale',
|
||||
[
|
||||
'date' => $sale['date'],
|
||||
'product' => $sale['product_name'],
|
||||
'currency' => $currency['iso_code'],
|
||||
'price' => $sale['price'],
|
||||
'reference' => $sale['reference'],
|
||||
]
|
||||
);
|
||||
|
||||
api_mail_html(
|
||||
$userInfo['complete_name'],
|
||||
$userInfo['email'],
|
||||
$plugin->get_lang('bc_subject'),
|
||||
$messageConfirmBuyerTemplate->fetch('buycourses/view/message_confirm_buyer.tpl'),
|
||||
'',
|
||||
$globalParameters['sale_email']
|
||||
);
|
||||
|
||||
$messageConfirmTemplate = new Template();
|
||||
$messageConfirmTemplate->assign('user', $userInfo);
|
||||
$messageConfirmTemplate->assign(
|
||||
'sale',
|
||||
[
|
||||
'date' => $sale['date'],
|
||||
'product' => $sale['product_name'],
|
||||
'currency' => $currency['iso_code'],
|
||||
'price' => $sale['price'],
|
||||
'reference' => $sale['reference'],
|
||||
]
|
||||
);
|
||||
|
||||
api_mail_html(
|
||||
'',
|
||||
$globalParameters['sale_email'],
|
||||
$plugin->get_lang('bc_subject'),
|
||||
$messageConfirmTemplate->fetch('buycourses/view/message_confirm.tpl')
|
||||
);
|
||||
}
|
||||
|
||||
Display::addFlash(
|
||||
$plugin->getSubscriptionSuccessMessage($sale)
|
||||
);
|
||||
|
||||
unset($_SESSION['bc_sale_id']);
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/course_catalog.php');
|
||||
exit;
|
||||
234
plugin/buycourses/src/subscription_add.php
Normal file
234
plugin/buycourses/src/subscription_add.php
Normal file
@@ -0,0 +1,234 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Configuration page for subscriptions for the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
|
||||
api_protect_admin_script(true);
|
||||
|
||||
$id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
|
||||
$type = isset($_REQUEST['type']) ? (int) $_REQUEST['type'] : 0;
|
||||
|
||||
if (empty($id) || empty($type)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
$queryString = 'id='.intval($_REQUEST['id']).'&type='.intval($_REQUEST['type']);
|
||||
|
||||
$editingCourse = $type === BuyCoursesPlugin::PRODUCT_TYPE_COURSE;
|
||||
$editingSession = $type === BuyCoursesPlugin::PRODUCT_TYPE_SESSION;
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
|
||||
$includeSession = $plugin->get('include_sessions') === 'true';
|
||||
|
||||
$entityManager = Database::getManager();
|
||||
$userRepo = UserManager::getRepository();
|
||||
$currency = $plugin->getSelectedCurrency();
|
||||
|
||||
if (empty($currency)) {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('CurrencyIsNotConfigured'), 'error')
|
||||
);
|
||||
}
|
||||
|
||||
$currencyIso = null;
|
||||
|
||||
if ($editingCourse) {
|
||||
$course = $entityManager->find('ChamiloCoreBundle:Course', $id);
|
||||
if (!$course) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$courseItem = $plugin->getCourseForConfiguration($course, $currency);
|
||||
|
||||
$currencyIso = $courseItem['currency'];
|
||||
$formDefaults = [
|
||||
'product_type' => get_lang('Course'),
|
||||
'id' => $courseItem['course_id'],
|
||||
'type' => BuyCoursesPlugin::PRODUCT_TYPE_COURSE,
|
||||
'name' => $courseItem['course_title'],
|
||||
'visible' => $courseItem['visible'],
|
||||
'price' => $courseItem['price'],
|
||||
'tax_perc' => $courseItem['tax_perc'],
|
||||
'currency_id' => $currency['id'],
|
||||
];
|
||||
} elseif ($editingSession) {
|
||||
if (!$includeSession) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$session = $entityManager->find('ChamiloCoreBundle:Session', $id);
|
||||
if (!$session) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$sessionItem = $plugin->getSessionForConfiguration($session, $currency);
|
||||
|
||||
$currencyIso = $sessionItem['currency'];
|
||||
$formDefaults = [
|
||||
'product_type' => get_lang('Session'),
|
||||
'id' => $session->getId(),
|
||||
'type' => BuyCoursesPlugin::PRODUCT_TYPE_SESSION,
|
||||
'name' => $sessionItem['session_name'],
|
||||
'visible' => $sessionItem['visible'],
|
||||
'price' => $sessionItem['price'],
|
||||
'tax_perc' => $sessionItem['tax_perc'],
|
||||
'currency_id' => $currency['id'],
|
||||
];
|
||||
} else {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$globalSettingsParams = $plugin->getGlobalParameters();
|
||||
|
||||
$form = new FormValidator('add_subscription');
|
||||
|
||||
$form->addText('product_type', $plugin->get_lang('ProductType'), false);
|
||||
$form->addText('name', get_lang('Name'), false);
|
||||
|
||||
$form->freeze(['product_type', 'name']);
|
||||
|
||||
$form->addElement(
|
||||
'number',
|
||||
'tax_perc',
|
||||
[$plugin->get_lang('TaxPerc'), $plugin->get_lang('TaxPercDescription'), '%'],
|
||||
['step' => 1, 'placeholder' => $globalSettingsParams['global_tax_perc'].'% '.$plugin->get_lang('ByDefault')]
|
||||
);
|
||||
|
||||
$frequencies = $plugin->getFrequencies();
|
||||
|
||||
$selectOptions = '';
|
||||
foreach ($frequencies as $key => $frequency) {
|
||||
$selectOptions .= '<option value="'.$key.'">'.$frequency.'</option>';
|
||||
}
|
||||
|
||||
if (empty($frequencies)) {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('FrequencyIsNotConfigured'), 'error')
|
||||
);
|
||||
}
|
||||
|
||||
$platformCommission = $plugin->getPlatformCommission();
|
||||
$form->addHtml(
|
||||
'
|
||||
<div class="form-group">
|
||||
<div class="col-sm-11">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">'.$plugin->get_lang('FrequencyConfig').'</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="form-group">
|
||||
<div class="col-sm-5">
|
||||
<div class="form-group ">
|
||||
<label for="duration" class="col-sm-3 control-label">
|
||||
'.$plugin->get_lang('Duration').'
|
||||
</label>
|
||||
<div class="col-sm-8">
|
||||
<div class="dropdown bootstrap-select form-control bs3 dropup">
|
||||
<select class="selectpicker form-control"
|
||||
data-live-search="true" name="duration" id="duration" tabindex="null">
|
||||
'.$selectOptions.'
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-1"></div>
|
||||
</div>
|
||||
<div class="form-group ">
|
||||
<label for="price" class="col-sm-3 control-label">
|
||||
'.$plugin->get_lang('Price').'
|
||||
</label>
|
||||
<div class="col-sm-8">
|
||||
<input class="form-control" name="price" type="number" step="0.01" id="price">
|
||||
</div>
|
||||
<div class="col-sm-1">
|
||||
'.$currencyIso.'
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-12">
|
||||
<a class=" btn btn-primary " name="add" type="submit"><em class="fa fa-plus"></em> Add</a>
|
||||
</div>
|
||||
<div class="col-sm-2"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-7">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>'.$plugin->get_lang('Duration').'</th>
|
||||
<th>'.$plugin->get_lang('Price').'</th>
|
||||
<th>'.$plugin->get_lang('Actions').'</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
</div>
|
||||
</div>
|
||||
'
|
||||
);
|
||||
|
||||
$form->addHidden('type', null);
|
||||
$form->addHidden('id', null);
|
||||
$button = $form->addButtonSave(get_lang('Save'));
|
||||
|
||||
if (empty($currency) || empty($frequencies)) {
|
||||
$button->setAttribute('disabled');
|
||||
}
|
||||
|
||||
if ($form->validate()) {
|
||||
$formValues = $form->getSubmitValues();
|
||||
$subscription['product_id'] = $formValues['id'];
|
||||
$subscription['product_type'] = $formValues['type'];
|
||||
$subscription['currency_id'] = $currency['id'];
|
||||
$subscription['tax_perc'] = $formValues['tax_perc'] != '' ? (int) $formValues['tax_perc'] : null;
|
||||
$subscription['frequencies'] = isset($formValues['frequencies']) ? $formValues['frequencies'] : [];
|
||||
|
||||
$result = $plugin->addNewSubscription($subscription);
|
||||
|
||||
if ($result) {
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/subscriptions_courses.php');
|
||||
} else {
|
||||
header('Location:'.api_get_self().'?'.$queryString);
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$form->setDefaults($formDefaults);
|
||||
|
||||
$templateName = $plugin->get_lang('SubscriptionAdd');
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'subscriptions_courses.php',
|
||||
'name' => get_lang('Configuration'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'subscriptions_courses.php',
|
||||
'name' => $plugin->get_lang('SubscriptionList'),
|
||||
];
|
||||
|
||||
$template = new Template($templateName);
|
||||
$template->assign('header', $templateName);
|
||||
$template->assign('items_form', $form->returnForm());
|
||||
$template->assign('currencyIso', $currencyIso);
|
||||
|
||||
$content = $template->fetch('buycourses/view/subscription_add.tpl');
|
||||
$template->assign('content', $content);
|
||||
|
||||
$template->display_one_col_template();
|
||||
88
plugin/buycourses/src/subscription_course_catalog.php
Normal file
88
plugin/buycourses/src/subscription_course_catalog.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* List of subscriptions.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$includeSessions = $plugin->get('include_sessions') === 'true';
|
||||
$includeServices = $plugin->get('include_services') === 'true';
|
||||
|
||||
$nameFilter = '';
|
||||
|
||||
$form = new FormValidator(
|
||||
'search_filter_form',
|
||||
'get',
|
||||
null,
|
||||
null,
|
||||
[],
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
|
||||
if ($form->validate()) {
|
||||
$formValues = $form->getSubmitValues();
|
||||
$nameFilter = isset($formValues['name']) ? $formValues['name'] : null;
|
||||
}
|
||||
|
||||
$form->addHeader($plugin->get_lang('SearchFilter'));
|
||||
$form->addText('name', get_lang('CourseName'), false);
|
||||
$form->addHtml('<hr>');
|
||||
$form->addButtonFilter(get_lang('Search'));
|
||||
|
||||
$pageSize = BuyCoursesPlugin::PAGINATION_PAGE_SIZE;
|
||||
$currentPage = isset($_GET['page']) ? (int) $_GET['page'] : 1;
|
||||
$first = $pageSize * ($currentPage - 1);
|
||||
$courseList = $plugin->getCatalogSubscriptionCourseList($first, $pageSize, $nameFilter);
|
||||
$totalItems = $plugin->getCatalogSubscriptionCourseList($first, $pageSize, $nameFilter, 'count');
|
||||
$pagesCount = ceil($totalItems / $pageSize);
|
||||
|
||||
$pagination = BuyCoursesPlugin::returnPagination(api_get_self(), $currentPage, $pagesCount, $totalItems);
|
||||
|
||||
// View
|
||||
if (api_is_platform_admin()) {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'subscriptions_courses.php',
|
||||
'name' => $plugin->get_lang('AvailableCoursesConfiguration'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'paymentsetup.php',
|
||||
'name' => $plugin->get_lang('PaymentsConfiguration'),
|
||||
];
|
||||
} else {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'course_panel.php',
|
||||
'name' => get_lang('TabsDashboard'),
|
||||
];
|
||||
}
|
||||
|
||||
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_PLUGIN_PATH).'buycourses/resources/css/style.css');
|
||||
|
||||
$templateName = $plugin->get_lang('SubscriptionListOnSale');
|
||||
$tpl = new Template($templateName);
|
||||
$tpl->assign('search_filter_form', $form->returnForm());
|
||||
$tpl->assign('showing_courses', true);
|
||||
$tpl->assign('courses', $courseList);
|
||||
$tpl->assign('sessions_are_included', $includeSessions);
|
||||
$tpl->assign('pagination', $pagination);
|
||||
|
||||
$sessionList = $plugin->getCatalogSubscriptionSessionList($first, $pageSize, $nameFilter, 'first', 0);
|
||||
$coursesExist = true;
|
||||
$sessionExist = true;
|
||||
if (count($sessionList) <= 0) {
|
||||
$sessionExist = false;
|
||||
}
|
||||
|
||||
$tpl->assign('coursesExist', $coursesExist);
|
||||
$tpl->assign('sessionExist', $sessionExist);
|
||||
|
||||
$content = $tpl->fetch('buycourses/view/subscription_catalog.tpl');
|
||||
|
||||
$tpl->assign('header', $templateName);
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template();
|
||||
266
plugin/buycourses/src/subscription_process.php
Normal file
266
plugin/buycourses/src/subscription_process.php
Normal file
@@ -0,0 +1,266 @@
|
||||
<?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();
|
||||
|
||||
$htmlHeadXtra[] = '<link rel="stylesheet" type="text/css" href="'.api_get_path(
|
||||
WEB_PLUGIN_PATH
|
||||
).'buycourses/resources/css/style.css"/>';
|
||||
$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';
|
||||
$tpvRedsysEnable = $plugin->get('tpv_redsys_enable') === 'true';
|
||||
|
||||
if (!$paypalEnabled && !$transferEnabled && !$culqiEnabled && !$tpvRedsysEnable) {
|
||||
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 (isset($_REQUEST['c'])) {
|
||||
$couponCode = $_REQUEST['c'];
|
||||
if ($buyingCourse) {
|
||||
$coupon = $plugin->getCouponByCode($couponCode, BuyCoursesPlugin::PRODUCT_TYPE_COURSE, $_REQUEST['i']);
|
||||
} else {
|
||||
$coupon = $plugin->getCouponByCode($couponCode, BuyCoursesPlugin::PRODUCT_TYPE_SESSION, $_REQUEST['i']);
|
||||
}
|
||||
|
||||
$queryString .= 'c='.$coupon['code'];
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['d'])) {
|
||||
$duration = $_REQUEST['d'];
|
||||
if ($buyingCourse) {
|
||||
$subscriptionItem = $plugin->getSubscription(BuyCoursesPlugin::PRODUCT_TYPE_COURSE, $_REQUEST['i'], $duration, $coupon);
|
||||
} else {
|
||||
$subscriptionItem = $plugin->getSubscription(BuyCoursesPlugin::PRODUCT_TYPE_SESSION, $_REQUEST['i'], $duration, $coupon);
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($currentUserId)) {
|
||||
Session::write('buy_course_redirect', api_get_self().'?'.$queryString);
|
||||
header('Location: '.api_get_path(WEB_CODE_PATH).'auth/inscription.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$subscriptionItems = $plugin->getSubscriptionsItemsByProduct($_REQUEST['i'], $_REQUEST['t']);
|
||||
|
||||
if (!isset($subscriptionItems) || empty($subscriptionItems)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
if (!isset($subscriptionItem) || empty($subscriptionItem)) {
|
||||
$subscriptionItem = $plugin->getSubscription($subscriptionItems[0]['product_type'], $subscriptionItems[0]['product_id'], $subscriptionItems[0]['duration'], $coupon);
|
||||
}
|
||||
|
||||
$queryString .= 'd='.intval($subscriptionItem['duration']);
|
||||
|
||||
if ($buyingCourse) {
|
||||
$courseInfo = $plugin->getSubscriptionCourseInfo($_REQUEST['i'], $coupon);
|
||||
$item = $plugin->getSubscriptionItemByProduct($_REQUEST['i'], BuyCoursesPlugin::PRODUCT_TYPE_COURSE);
|
||||
} elseif ($buyingSession) {
|
||||
$sessionInfo = $plugin->getSubscriptionSessionInfo($_REQUEST['i'], $coupon);
|
||||
$item = $plugin->getSubscriptionItemByProduct($_REQUEST['i'], BuyCoursesPlugin::PRODUCT_TYPE_SESSION);
|
||||
}
|
||||
|
||||
$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->registerSubscriptionSale($item['product_id'], $item['product_type'], $formValues['payment_type'], $formValues['d'], $formValues['c']);
|
||||
|
||||
if ($saleId !== false) {
|
||||
$_SESSION['bc_sale_id'] = $saleId;
|
||||
|
||||
if (isset($formValues['c'])) {
|
||||
$couponSaleId = $plugin->registerCouponSubscriptionSale($saleId, $formValues['c']);
|
||||
if ($couponSaleId !== false) {
|
||||
$plugin->updateCouponDelivered($formValues['c']);
|
||||
$_SESSION['bc_coupon_id'] = $formValues['c'];
|
||||
}
|
||||
}
|
||||
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/process_subscription_confirm.php');
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$paymentTypesOptions = $plugin->getPaymentTypes(true);
|
||||
|
||||
$count = count($paymentTypesOptions);
|
||||
if ($count === 0) {
|
||||
$form->addHtml($plugin->get_lang('NoPaymentOptionAvailable'));
|
||||
$form->addHtml('<br />');
|
||||
$form->addHtml('<br />');
|
||||
} elseif ($count === 1) {
|
||||
// get the only array item
|
||||
foreach ($paymentTypesOptions as $type => $value) {
|
||||
$form->addHtml(sprintf($plugin->get_lang('XIsOnlyPaymentMethodAvailable'), $value));
|
||||
$form->addHtml('<br />');
|
||||
$form->addHtml('<br />');
|
||||
$form->addHidden('payment_type', $type);
|
||||
}
|
||||
} else {
|
||||
$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']));
|
||||
if ($coupon != null) {
|
||||
$form->addHidden('c', intval($coupon['id']));
|
||||
}
|
||||
$form->addButton('submit', $plugin->get_lang('ConfirmOrder'), 'check', 'success', 'btn-lg pull-right');
|
||||
|
||||
$formSubscription = new FormValidator('confirm_subscription');
|
||||
if ($formSubscription->validate()) {
|
||||
$formSubscriptionValues = $formSubscription->getSubmitValues();
|
||||
|
||||
if (!$formSubscriptionValues['duration']) {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('NeedToAddDuration'), 'error', false)
|
||||
);
|
||||
header('Location:'.api_get_self().'?'.$queryString);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($buyingCourse) {
|
||||
$subscription = $plugin->getSubscription(BuyCoursesPlugin::PRODUCT_TYPE_COURSE, $_REQUEST['i'], $formSubscriptionValues['duration']);
|
||||
} else {
|
||||
$subscription = $plugin->getSubscription(BuyCoursesPlugin::PRODUCT_TYPE_SESSION, $_REQUEST['i'], $formSubscriptionValues['duration']);
|
||||
}
|
||||
|
||||
if ($subscription == null) {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('SubscriptionNotValid'), 'error', false)
|
||||
);
|
||||
header('Location:'.api_get_self().'?'.$queryString);
|
||||
exit;
|
||||
}
|
||||
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/subscription_process.php?i='.$_REQUEST['i'].'&t='.$_REQUEST['t'].'&d='.$formSubscriptionValues['duration']);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$frequencies = $plugin->getFrequencies();
|
||||
$selectedFrequencies = [];
|
||||
|
||||
foreach ($subscriptionItems as $si) {
|
||||
if (isset($frequencies[$si['duration']])) {
|
||||
$selectedFrequencies[$si['duration']] = $frequencies[$si['duration']].' - '.$si['price_formatted'].' '.$si['iso_code'];
|
||||
}
|
||||
}
|
||||
|
||||
$formSubscription->addRadio('duration', null, $selectedFrequencies);
|
||||
|
||||
if (!empty($selectedFrequencies)) {
|
||||
$formSubscriptionDefaults['duration'] = $subscriptionItem['duration'];
|
||||
$formSubscription->setDefaults($formSubscriptionDefaults);
|
||||
}
|
||||
|
||||
$selectedDurationName = $frequencies[$subscriptionItem['duration']];
|
||||
|
||||
$formSubscription->addHidden('t', intval($_GET['t']));
|
||||
$formSubscription->addHidden('i', intval($_GET['i']));
|
||||
|
||||
$form->addHidden('d', $subscriptionItem['duration']);
|
||||
|
||||
$formCoupon = new FormValidator('confirm_coupon');
|
||||
if ($formCoupon->validate()) {
|
||||
$formCouponValues = $formCoupon->getSubmitValues();
|
||||
|
||||
if (!$formCouponValues['coupon_code']) {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('NeedToAddCouponCode'), 'error', false)
|
||||
);
|
||||
header('Location:'.api_get_self().'?'.$queryString);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($buyingCourse) {
|
||||
$coupon = $plugin->getCouponByCode($formCouponValues['coupon_code'], BuyCoursesPlugin::PRODUCT_TYPE_COURSE, $_REQUEST['i']);
|
||||
} else {
|
||||
$coupon = $plugin->getCouponByCode($formCouponValues['coupon_code'], BuyCoursesPlugin::PRODUCT_TYPE_SESSION, $_REQUEST['i']);
|
||||
}
|
||||
|
||||
if ($coupon == null) {
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('CouponNotValid'), 'error', false)
|
||||
);
|
||||
header('Location:'.api_get_self().'?'.$queryString);
|
||||
exit;
|
||||
}
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('CouponRedeemed'), 'success', false)
|
||||
);
|
||||
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/subscription_process.php?i='.$_REQUEST['i'].'&t='.$_REQUEST['t'].'&d='.$_REQUEST['d'].'&c='.$formCouponValues['coupon_code']);
|
||||
|
||||
exit;
|
||||
}
|
||||
$formCoupon->addText('coupon_code', $plugin->get_lang('CouponsCode'), true);
|
||||
$formCoupon->addHidden('t', intval($_GET['t']));
|
||||
$formCoupon->addHidden('i', intval($_GET['i']));
|
||||
$formCoupon->addHidden('d', $subscriptionItem['duration']);
|
||||
$formCoupon->addButton('submit', $plugin->get_lang('RedeemCoupon'), 'check', 'success', 'btn-lg pull-right');
|
||||
|
||||
// View
|
||||
$templateName = $plugin->get_lang('PaymentMethods');
|
||||
$interbreadcrumb[] = ['url' => 'subscription_course_catalog.php', 'name' => $plugin->get_lang('CourseListOnSale')];
|
||||
|
||||
$tpl = new Template($templateName);
|
||||
$tpl->assign('item_type', (int) $_GET['t']);
|
||||
$tpl->assign('buying_course', $buyingCourse);
|
||||
$tpl->assign('buying_session', $buyingSession);
|
||||
$tpl->assign('user', api_get_user_info());
|
||||
$tpl->assign('form_coupon', $formCoupon->returnForm());
|
||||
$tpl->assign('message_payment', $messagePayment);
|
||||
$tpl->assign('selected_duration_name', $selectedDurationName);
|
||||
$tpl->assign('form', $form->returnForm());
|
||||
$tpl->assign('form_subscription', $formSubscription->returnForm());
|
||||
|
||||
if ($buyingCourse) {
|
||||
$tpl->assign('course', $courseInfo);
|
||||
} elseif ($buyingSession) {
|
||||
$tpl->assign('session', $sessionInfo);
|
||||
}
|
||||
|
||||
$tpl->assign('subscription', $subscriptionItem);
|
||||
|
||||
$content = $tpl->fetch('buycourses/view/subscription_process.tpl');
|
||||
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template();
|
||||
201
plugin/buycourses/src/subscription_sales_report.php
Normal file
201
plugin/buycourses/src/subscription_sales_report.php
Normal file
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* List of pending subscriptions payments of the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once '../config.php';
|
||||
|
||||
api_protect_admin_script();
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
|
||||
$paypalEnable = $plugin->get('paypal_enable');
|
||||
$commissionsEnable = $plugin->get('commissions_enable');
|
||||
$includeServices = $plugin->get('include_services');
|
||||
$invoicingEnable = $plugin->get('invoicing_enable') === 'true';
|
||||
|
||||
if (isset($_GET['order'])) {
|
||||
$sale = $plugin->getSubscriptionSale($_GET['order']);
|
||||
|
||||
if (empty($sale)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$urlToRedirect = api_get_self().'?';
|
||||
|
||||
switch ($_GET['action']) {
|
||||
case 'confirm':
|
||||
$plugin->completeSubscriptionSale($sale['id']);
|
||||
$plugin->storeSubscriptionPayouts($sale['id']);
|
||||
Display::addFlash(
|
||||
$plugin->getSubscriptionSuccessMessage($sale)
|
||||
);
|
||||
|
||||
$urlToRedirect .= http_build_query([
|
||||
'status' => BuyCoursesPlugin::SALE_STATUS_COMPLETED,
|
||||
'sale' => $sale['id'],
|
||||
]);
|
||||
break;
|
||||
case 'cancel':
|
||||
$plugin->cancelSubscriptionSale($sale['id']);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
$plugin->get_lang('OrderCanceled'),
|
||||
'warning'
|
||||
)
|
||||
);
|
||||
|
||||
$urlToRedirect .= http_build_query([
|
||||
'status' => BuyCoursesPlugin::SALE_STATUS_CANCELED,
|
||||
'sale' => $sale['id'],
|
||||
]);
|
||||
break;
|
||||
}
|
||||
|
||||
header("Location: $urlToRedirect");
|
||||
exit;
|
||||
}
|
||||
|
||||
$productTypes = $plugin->getProductTypes();
|
||||
$saleStatuses = $plugin->getSaleStatuses();
|
||||
$paymentTypes = $plugin->getPaymentTypes();
|
||||
|
||||
$selectedFilterType = '0';
|
||||
$selectedStatus = isset($_GET['status']) ? $_GET['status'] : BuyCoursesPlugin::SALE_STATUS_PENDING;
|
||||
$selectedSale = isset($_GET['sale']) ? intval($_GET['sale']) : 0;
|
||||
$dateStart = isset($_GET['date_start']) ? $_GET['date_start'] : date('Y-m-d H:i', mktime(0, 0, 0));
|
||||
$dateEnd = isset($_GET['date_end']) ? $_GET['date_end'] : date('Y-m-d H:i', mktime(23, 59, 59));
|
||||
$searchTerm = '';
|
||||
$email = '';
|
||||
|
||||
$form = new FormValidator('search', 'get');
|
||||
|
||||
if ($form->validate()) {
|
||||
$selectedFilterType = $form->getSubmitValue('filter_type');
|
||||
$selectedStatus = $form->getSubmitValue('status');
|
||||
$searchTerm = $form->getSubmitValue('user');
|
||||
$dateStart = $form->getSubmitValue('date_start');
|
||||
$dateEnd = $form->getSubmitValue('date_end');
|
||||
$email = $form->getSubmitValue('email');
|
||||
|
||||
if ($selectedStatus === false) {
|
||||
$selectedStatus = BuyCoursesPlugin::SALE_STATUS_PENDING;
|
||||
}
|
||||
|
||||
if ($selectedFilterType === false) {
|
||||
$selectedFilterType = '0';
|
||||
}
|
||||
}
|
||||
|
||||
$form->addRadio(
|
||||
'filter_type',
|
||||
get_lang('Filter'),
|
||||
[
|
||||
$plugin->get_lang('ByStatus'),
|
||||
$plugin->get_lang('ByUser'),
|
||||
$plugin->get_lang('ByDate'),
|
||||
$plugin->get_lang('ByEmail'),
|
||||
]
|
||||
);
|
||||
$form->addHtml('<div id="report-by-status" '.($selectedFilterType !== '0' ? 'style="display:none"' : '').'>');
|
||||
$form->addSelect('status', $plugin->get_lang('OrderStatus'), $saleStatuses);
|
||||
$form->addHtml('</div>');
|
||||
$form->addHtml('<div id="report-by-user" '.($selectedFilterType !== '1' ? 'style="display:none"' : '').'>');
|
||||
$form->addText('user', get_lang('UserName'), false);
|
||||
$form->addHtml('</div>');
|
||||
$form->addHtml('<div id="report-by-date" '.($selectedFilterType !== '2' ? 'style="display:none"' : '').'>');
|
||||
$form->addDateRangePicker('date', get_lang('Date'), false);
|
||||
$form->addHtml('</div>');
|
||||
$form->addHtml('<div id="report-by-email" '.($selectedFilterType !== '3' ? 'style="display:none"' : '').'>');
|
||||
$form->addText('email', get_lang('Email'), false);
|
||||
$form->addHtml('</div>');
|
||||
$form->addButtonFilter(get_lang('Search'));
|
||||
$form->setDefaults([
|
||||
'filter_type' => $selectedFilterType,
|
||||
'status' => $selectedStatus,
|
||||
'date_start' => $dateStart,
|
||||
'date_end' => $dateEnd,
|
||||
'email' => $email,
|
||||
]);
|
||||
|
||||
switch ($selectedFilterType) {
|
||||
case '0':
|
||||
$sales = $plugin->getSubscriptionSaleListByStatus($selectedStatus);
|
||||
break;
|
||||
case '1':
|
||||
$sales = $plugin->getSubscriptionSaleListByUser($searchTerm);
|
||||
break;
|
||||
case '2':
|
||||
$sales = $plugin->getSubscriptionSaleListByDate($dateStart, $dateEnd);
|
||||
break;
|
||||
case '3':
|
||||
$sales = $plugin->getSubscriptionSaleListByEmail($email);
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ($sales as &$sale) {
|
||||
$sale['product_type'] = $productTypes[$sale['product_type']];
|
||||
$sale['payment_type'] = $paymentTypes[$sale['payment_type']];
|
||||
$sale['complete_user_name'] = api_get_person_name($sale['firstname'], $sale['lastname']);
|
||||
$sale['num_invoice'] = $plugin->getNumInvoice($sale['id'], 0);
|
||||
$sale['total_price'] = $plugin->getPriceWithCurrencyFromIsoCode($sale['price'], $sale['iso_code']);
|
||||
if (isset($sale['discount_amount']) && $sale['discount_amount'] != 0) {
|
||||
$sale['total_discount'] = $plugin->getPriceWithCurrencyFromIsoCode($sale['discount_amount'], $sale['iso_code']);
|
||||
$sale['coupon_code'] = $plugin->getSaleCouponCode($sale['id']);
|
||||
}
|
||||
}
|
||||
|
||||
$interbreadcrumb[] = ['url' => '../index.php', 'name' => $plugin->get_lang('plugin_title')];
|
||||
|
||||
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_PLUGIN_PATH).'buycourses/resources/css/style.css');
|
||||
|
||||
$templateName = $plugin->get_lang('SalesReport');
|
||||
$template = new Template($templateName);
|
||||
|
||||
$toolbar = Display::url(
|
||||
Display::returnFontAwesomeIcon('file-excel-o').
|
||||
get_lang('GenerateReport'),
|
||||
api_get_path(WEB_PLUGIN_PATH).'buycourses/src/export_subscription_report.php',
|
||||
['class' => 'btn btn-primary']
|
||||
);
|
||||
|
||||
if ($paypalEnable === 'true' && $commissionsEnable === 'true') {
|
||||
$toolbar .= Display::toolbarButton(
|
||||
$plugin->get_lang('PaypalPayoutCommissions'),
|
||||
api_get_path(WEB_PLUGIN_PATH).'buycourses/src/paypal_payout.php',
|
||||
'paypal',
|
||||
'primary',
|
||||
['title' => $plugin->get_lang('PaypalPayoutCommissions')]
|
||||
);
|
||||
|
||||
$template->assign(
|
||||
'actions',
|
||||
Display::toolbarAction('toolbar', [$toolbar])
|
||||
);
|
||||
}
|
||||
|
||||
$template->assign(
|
||||
'actions',
|
||||
Display::toolbarAction('toolbar', [$toolbar])
|
||||
);
|
||||
$template->assign('form', $form->returnForm());
|
||||
$template->assign('selected_sale', $selectedSale);
|
||||
$template->assign('selected_status', $selectedStatus);
|
||||
$template->assign('services_are_included', $includeServices);
|
||||
$template->assign('sale_list', $sales);
|
||||
$template->assign('sale_status_canceled', BuyCoursesPlugin::SALE_STATUS_CANCELED);
|
||||
$template->assign('sale_status_pending', BuyCoursesPlugin::SALE_STATUS_PENDING);
|
||||
$template->assign('sale_status_completed', BuyCoursesPlugin::SALE_STATUS_COMPLETED);
|
||||
$template->assign('invoicing_enable', $invoicingEnable);
|
||||
|
||||
$content = $template->fetch('buycourses/view/subscription_sales_report.tpl');
|
||||
|
||||
$template->assign('header', $templateName);
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
114
plugin/buycourses/src/subscription_session_catalog.php
Normal file
114
plugin/buycourses/src/subscription_session_catalog.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* List of sessions.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$includeSessions = $plugin->get('include_sessions') === 'true';
|
||||
$includeServices = $plugin->get('include_services') === 'true';
|
||||
|
||||
if (!$includeSessions) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$nameFilter = null;
|
||||
$sessionCategory = isset($_GET['session_category']) ? (int) $_GET['session_category'] : 0;
|
||||
$form = new FormValidator(
|
||||
'search_filter_form',
|
||||
'get',
|
||||
null,
|
||||
null,
|
||||
[],
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
|
||||
$form->removeAttribute('class');
|
||||
|
||||
if ($form->validate()) {
|
||||
$formValues = $form->getSubmitValues();
|
||||
$nameFilter = isset($formValues['name']) ? $formValues['name'] : null;
|
||||
$sessionCategory = isset($formValues['session_category']) ? $formValues['session_category'] : $sessionCategory;
|
||||
}
|
||||
|
||||
$form->addHeader($plugin->get_lang('SearchFilter'));
|
||||
|
||||
$categoriesOptions = [
|
||||
'0' => get_lang('AllCategories'),
|
||||
];
|
||||
$categoriesList = SessionManager::get_all_session_category();
|
||||
if ($categoriesList != false) {
|
||||
foreach ($categoriesList as $categoryItem) {
|
||||
$categoriesOptions[$categoryItem['id']] = $categoryItem['name'];
|
||||
}
|
||||
}
|
||||
$form->addSelect(
|
||||
'session_category',
|
||||
get_lang('SessionCategory'),
|
||||
$categoriesOptions,
|
||||
[
|
||||
'id' => 'session_category',
|
||||
]
|
||||
);
|
||||
|
||||
$form->addText('name', get_lang('SessionName'), false);
|
||||
|
||||
$form->addHtml('<hr>');
|
||||
$form->addButtonFilter(get_lang('Search'));
|
||||
|
||||
$form->setDefaults(
|
||||
[
|
||||
'session_category' => $sessionCategory,
|
||||
]
|
||||
);
|
||||
$pageSize = BuyCoursesPlugin::PAGINATION_PAGE_SIZE;
|
||||
$currentPage = isset($_GET['page']) ? (int) $_GET['page'] : 1;
|
||||
$first = $pageSize * ($currentPage - 1);
|
||||
$sessionList = $plugin->getCatalogSubscriptionSessionList($first, $pageSize, $nameFilter, 'all', $sessionCategory);
|
||||
$totalItems = $plugin->getCatalogSubscriptionSessionList($first, $pageSize, $nameFilter, 'count', $sessionCategory);
|
||||
$pagesCount = ceil($totalItems / $pageSize);
|
||||
$pagination = BuyCoursesPlugin::returnPagination(api_get_self(), $currentPage, $pagesCount, $totalItems);
|
||||
|
||||
// View
|
||||
if (api_is_platform_admin()) {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'subscriptions_sessions.php',
|
||||
'name' => $plugin->get_lang('AvailableCoursesConfiguration'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => 'paymentsetup.php',
|
||||
'name' => $plugin->get_lang('PaymentsConfiguration'),
|
||||
];
|
||||
}
|
||||
|
||||
$templateName = $plugin->get_lang('CourseListOnSale');
|
||||
|
||||
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_PLUGIN_PATH).'buycourses/resources/css/style.css');
|
||||
|
||||
$template = new Template($templateName);
|
||||
$template->assign('search_filter_form', $form->returnForm());
|
||||
$template->assign('sessions_are_included', $includeSessions);
|
||||
$template->assign('showing_sessions', true);
|
||||
$template->assign('sessions', $sessionList);
|
||||
$template->assign('pagination', $pagination);
|
||||
|
||||
$courseList = $plugin->getCatalogSubscriptionCourseList($first, $pageSize, $nameFilter);
|
||||
$coursesExist = true;
|
||||
$sessionExist = true;
|
||||
if (count($courseList) <= 0) {
|
||||
$coursesExist = false;
|
||||
}
|
||||
$template->assign('coursesExist', $coursesExist);
|
||||
$template->assign('sessionExist', $sessionExist);
|
||||
|
||||
$content = $template->fetch('buycourses/view/subscription_catalog.tpl');
|
||||
|
||||
$template->assign('header', $templateName);
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
97
plugin/buycourses/src/subscriptions_courses.php
Normal file
97
plugin/buycourses/src/subscriptions_courses.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
/**
|
||||
* Configuration script for the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
|
||||
use Doctrine\ORM\Tools\Pagination\Paginator;
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$includeSession = $plugin->get('include_sessions') === 'true';
|
||||
$taxEnable = $plugin->get('tax_enable') === 'true';
|
||||
|
||||
api_protect_admin_script(true);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
get_lang('Info').' - '.$plugin->get_lang('CoursesInSessionsDoesntDisplayHere'),
|
||||
'info'
|
||||
)
|
||||
);
|
||||
|
||||
$pageSize = BuyCoursesPlugin::PAGINATION_PAGE_SIZE;
|
||||
$type = isset($_GET['type']) ? (int) $_GET['type'] : BuyCoursesPlugin::PRODUCT_TYPE_COURSE;
|
||||
$currentPage = isset($_GET['page']) ? (int) $_GET['page'] : 1;
|
||||
$first = $pageSize * ($currentPage - 1);
|
||||
|
||||
$qb = $plugin->getCourseList($first, $pageSize);
|
||||
$query = $qb->getQuery();
|
||||
$courses = new Paginator($query, $fetchJoinCollection = true);
|
||||
foreach ($courses as $course) {
|
||||
$item = $plugin->getSubscriptionItemByProduct($course->getId(), BuyCoursesPlugin::PRODUCT_TYPE_COURSE);
|
||||
$course->buyCourseData = [];
|
||||
if ($item !== false) {
|
||||
$course->buyCourseData = $item;
|
||||
}
|
||||
}
|
||||
|
||||
$totalItems = count($courses);
|
||||
$pagesCount = ceil($totalItems / $pageSize);
|
||||
|
||||
$pagination = BuyCoursesPlugin::returnPagination(
|
||||
api_get_self(),
|
||||
$currentPage,
|
||||
$pagesCount,
|
||||
$totalItems,
|
||||
['type' => $type]
|
||||
);
|
||||
|
||||
// breadcrumbs
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_PLUGIN_PATH).'buycourses/index.php',
|
||||
'name' => $plugin->get_lang('plugin_title'),
|
||||
];
|
||||
|
||||
$templateName = $plugin->get_lang('AvailableCourses');
|
||||
|
||||
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_PLUGIN_PATH).'buycourses/resources/css/style.css');
|
||||
|
||||
$tpl = new Template($templateName);
|
||||
|
||||
$toolbar = Display::url(
|
||||
Display::returnFontAwesomeIcon('fa-calendar-alt').
|
||||
$plugin->get_lang('ConfigureSubscriptionsFrequencies'),
|
||||
api_get_path(WEB_PLUGIN_PATH).'buycourses/src/configure_frequency.php',
|
||||
['class' => 'btn btn-primary']
|
||||
);
|
||||
|
||||
$tpl->assign(
|
||||
'actions',
|
||||
Display::toolbarAction('toolbar', [$toolbar])
|
||||
);
|
||||
|
||||
$tpl->assign('product_type_course', BuyCoursesPlugin::PRODUCT_TYPE_COURSE);
|
||||
$tpl->assign('product_type_session', BuyCoursesPlugin::PRODUCT_TYPE_SESSION);
|
||||
$tpl->assign('courses', $courses);
|
||||
$tpl->assign('course_pagination', $pagination);
|
||||
$tpl->assign('sessions_are_included', $includeSession);
|
||||
$tpl->assign('tax_enable', $taxEnable);
|
||||
|
||||
if ($taxEnable) {
|
||||
$globalParameters = $plugin->getGlobalParameters();
|
||||
$tpl->assign('global_tax_perc', $globalParameters['global_tax_perc']);
|
||||
$tpl->assign('tax_applies_to', $globalParameters['tax_applies_to']);
|
||||
$tpl->assign('tax_name', $globalParameters['tax_name']);
|
||||
}
|
||||
|
||||
$content = $tpl->fetch('buycourses/view/subscriptions.tpl');
|
||||
|
||||
$tpl->assign('header', $templateName);
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template();
|
||||
101
plugin/buycourses/src/subscriptions_sessions.php
Normal file
101
plugin/buycourses/src/subscriptions_sessions.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
/**
|
||||
* Configuration script for the Buy Courses plugin.
|
||||
*
|
||||
* @package chamilo.plugin.buycourses
|
||||
*/
|
||||
use Doctrine\ORM\Tools\Pagination\Paginator;
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
|
||||
$plugin = BuyCoursesPlugin::create();
|
||||
$includeSession = $plugin->get('include_sessions') === 'true';
|
||||
|
||||
if (!$includeSession) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
$includeServices = $plugin->get('include_services') === 'true';
|
||||
$taxEnable = $plugin->get('tax_enable') === 'true';
|
||||
|
||||
api_protect_admin_script(true);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
get_lang('Info').' - '.$plugin->get_lang('CoursesInSessionsDoesntDisplayHere'),
|
||||
'info'
|
||||
)
|
||||
);
|
||||
|
||||
$pageSize = BuyCoursesPlugin::PAGINATION_PAGE_SIZE;
|
||||
$currentPage = isset($_GET['page']) ? (int) $_GET['page'] : 1;
|
||||
$first = $pageSize * ($currentPage - 1);
|
||||
|
||||
// breadcrumbs
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_PLUGIN_PATH).'buycourses/index.php',
|
||||
'name' => $plugin->get_lang('plugin_title'),
|
||||
];
|
||||
|
||||
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_PLUGIN_PATH).'buycourses/resources/css/style.css');
|
||||
|
||||
$templateName = $plugin->get_lang('AvailableCourses');
|
||||
|
||||
$tpl = new Template($templateName);
|
||||
|
||||
$toolbar = Display::url(
|
||||
Display::returnFontAwesomeIcon('fa-calendar-alt').
|
||||
$plugin->get_lang('ConfigureSubscriptionsFrequencies'),
|
||||
api_get_path(WEB_PLUGIN_PATH).'buycourses/src/configure_frequency.php',
|
||||
['class' => 'btn btn-primary']
|
||||
);
|
||||
|
||||
$tpl->assign(
|
||||
'actions',
|
||||
Display::toolbarAction('toolbar', [$toolbar])
|
||||
);
|
||||
|
||||
$tpl->assign('product_type_course', BuyCoursesPlugin::PRODUCT_TYPE_COURSE);
|
||||
$tpl->assign('product_type_session', BuyCoursesPlugin::PRODUCT_TYPE_SESSION);
|
||||
$tpl->assign('sessions_are_included', $includeSession);
|
||||
$tpl->assign('services_are_included', $includeServices);
|
||||
$tpl->assign('tax_enable', $taxEnable);
|
||||
|
||||
$query = CoursesAndSessionsCatalog::browseSessions(null, ['start' => $first, 'length' => $pageSize], true);
|
||||
$sessions = new Paginator($query, $fetchJoinCollection = true);
|
||||
foreach ($sessions as $session) {
|
||||
$item = $plugin->getSubscriptionItemByProduct($session->getId(), BuyCoursesPlugin::PRODUCT_TYPE_SESSION);
|
||||
$session->buyCourseData = [];
|
||||
if ($item !== false) {
|
||||
$session->buyCourseData = $item;
|
||||
}
|
||||
}
|
||||
|
||||
$totalItems = count($sessions);
|
||||
$pagesCount = ceil($totalItems / $pageSize);
|
||||
|
||||
$pagination = BuyCoursesPlugin::returnPagination(
|
||||
api_get_self(),
|
||||
$currentPage,
|
||||
$pagesCount,
|
||||
$totalItems,
|
||||
['type' => BuyCoursesPlugin::PRODUCT_TYPE_SESSION]
|
||||
);
|
||||
|
||||
$tpl->assign('sessions', $sessions);
|
||||
$tpl->assign('session_pagination', $pagination);
|
||||
|
||||
if ($taxEnable) {
|
||||
$globalParameters = $plugin->getGlobalParameters();
|
||||
$tpl->assign('global_tax_perc', $globalParameters['global_tax_perc']);
|
||||
$tpl->assign('tax_applies_to', $globalParameters['tax_applies_to']);
|
||||
$tpl->assign('tax_name', $globalParameters['tax_name']);
|
||||
}
|
||||
|
||||
$content = $tpl->fetch('buycourses/view/subscriptions.tpl');
|
||||
|
||||
$tpl->assign('header', $templateName);
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template();
|
||||
200
plugin/buycourses/src/success.php
Normal file
200
plugin/buycourses/src/success.php
Normal file
@@ -0,0 +1,200 @@
|
||||
<?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();
|
||||
$paypalEnabled = $plugin->get('paypal_enable') === 'true';
|
||||
|
||||
if (!$paypalEnabled) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$sale = $plugin->getSale($_SESSION['bc_sale_id']);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
$paypalParams = $plugin->getPaypalParams();
|
||||
$pruebas = $paypalParams['sandbox'] == 1;
|
||||
$paypalUsername = $paypalParams['username'];
|
||||
$paypalPassword = $paypalParams['password'];
|
||||
$paypalSignature = $paypalParams['signature'];
|
||||
|
||||
require_once "paypalfunctions.php";
|
||||
|
||||
$form = new FormValidator(
|
||||
'success',
|
||||
'POST',
|
||||
api_get_self(),
|
||||
null,
|
||||
null,
|
||||
FormValidator::LAYOUT_INLINE
|
||||
);
|
||||
$form->addButton('confirm', $plugin->get_lang('ConfirmOrder'), 'check', 'success');
|
||||
$form->addButtonCancel($plugin->get_lang('CancelOrder'), 'cancel');
|
||||
|
||||
if ($form->validate()) {
|
||||
$formValues = $form->getSubmitValues();
|
||||
if (isset($formValues['cancel'])) {
|
||||
$plugin->cancelSale($sale['id']);
|
||||
unset($_SESSION['bc_sale_id']);
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$confirmPayments = ConfirmPayment($sale['price']);
|
||||
|
||||
if ($confirmPayments['ACK'] !== 'Success') {
|
||||
$erroMessage = vsprintf(
|
||||
$plugin->get_lang('ErrorOccurred'),
|
||||
[$expressCheckout['L_ERRORCODE0'], $confirmPayments['L_LONGMESSAGE0']]
|
||||
);
|
||||
Display::addFlash(
|
||||
Display::return_message($erroMessage, 'error', false)
|
||||
);
|
||||
header('Location: ../index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$transactionId = $confirmPayments['PAYMENTINFO_0_TRANSACTIONID'];
|
||||
$transactionType = $confirmPayments['PAYMENTINFO_0_TRANSACTIONTYPE'];
|
||||
|
||||
switch ($confirmPayments['PAYMENTINFO_0_PAYMENTSTATUS']) {
|
||||
case 'Completed':
|
||||
$saleIsCompleted = $plugin->completeSale($sale['id']);
|
||||
if ($saleIsCompleted) {
|
||||
Display::addFlash(
|
||||
$plugin->getSubscriptionSuccessMessage($sale)
|
||||
);
|
||||
$plugin->storePayouts($sale['id']);
|
||||
break;
|
||||
}
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('ErrorContactPlatformAdmin'), 'error')
|
||||
);
|
||||
break;
|
||||
case 'Pending':
|
||||
switch ($confirmPayments["PAYMENTINFO_0_PENDINGREASON"]) {
|
||||
case 'address':
|
||||
$purchaseStatus = $plugin->get_lang('PendingReasonByAddress');
|
||||
break;
|
||||
case 'authorization':
|
||||
$purchaseStatus = $plugin->get_lang('PendingReasonByAuthorization');
|
||||
break;
|
||||
case 'echeck':
|
||||
$purchaseStatus = $plugin->get_lang('PendingReasonByEcheck');
|
||||
break;
|
||||
case 'intl':
|
||||
$purchaseStatus = $plugin->get_lang('PendingReasonByIntl');
|
||||
break;
|
||||
case 'multicurrency':
|
||||
$purchaseStatus = $plugin->get_lang('PendingReasonByMulticurrency');
|
||||
break;
|
||||
case 'order':
|
||||
$purchaseStatus = $plugin->get_lang('PendingReasonByOrder');
|
||||
break;
|
||||
case 'paymentreview':
|
||||
$purchaseStatus = $plugin->get_lang('PendingReasonByPaymentReview');
|
||||
break;
|
||||
case 'regulatoryreview':
|
||||
$purchaseStatus = $plugin->get_lang('PendingReasonByRegulatoryReview');
|
||||
break;
|
||||
case 'unilateral':
|
||||
$purchaseStatus = $plugin->get_lang('PendingReasonByUnilateral');
|
||||
break;
|
||||
case 'upgrade':
|
||||
$purchaseStatus = $plugin->get_lang('PendingReasonByUpgrade');
|
||||
break;
|
||||
case 'verify':
|
||||
$purchaseStatus = $plugin->get_lang('PendingReasonByVerify');
|
||||
break;
|
||||
case 'other':
|
||||
default:
|
||||
$purchaseStatus = $plugin->get_lang('PendingReasonByOther');
|
||||
break;
|
||||
}
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf($plugin->get_lang('PurchaseStatusX'), $purchaseStatus),
|
||||
'warning',
|
||||
false
|
||||
)
|
||||
);
|
||||
break;
|
||||
default:
|
||||
Display::addFlash(
|
||||
Display::return_message($plugin->get_lang('ErrorContactPlatformAdmin'), 'error')
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
unset($_SESSION['bc_sale_id']);
|
||||
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/course_catalog.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$token = isset($_GET['token']) ? $_GET['token'] : null;
|
||||
|
||||
if (empty($token)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$shippingDetails = GetShippingDetails($token);
|
||||
|
||||
if ($shippingDetails['ACK'] !== 'Success') {
|
||||
$erroMessage = vsprintf(
|
||||
$plugin->get_lang('ErrorOccurred'),
|
||||
[$expressCheckout['L_ERRORCODE0'], $shippingDetails['L_LONGMESSAGE0']]
|
||||
);
|
||||
Display::addFlash(
|
||||
Display::return_message($erroMessage, 'error', false)
|
||||
);
|
||||
header('Location: ../index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$interbreadcrumb[] = ["url" => "course_catalog.php", "name" => $plugin->get_lang('CourseListOnSale')];
|
||||
|
||||
$templateName = $plugin->get_lang('PaymentMethods');
|
||||
$tpl = new Template($templateName);
|
||||
|
||||
if ($buyingCourse) {
|
||||
$tpl->assign('course', $course);
|
||||
} elseif ($buyingSession) {
|
||||
$tpl->assign('session', $session);
|
||||
}
|
||||
|
||||
$tpl->assign('buying_course', $buyingCourse);
|
||||
$tpl->assign('buying_session', $buyingSession);
|
||||
$tpl->assign('title', $sale['product_name']);
|
||||
$tpl->assign('price', $sale['price']);
|
||||
$tpl->assign('currency', $sale['currency_id']);
|
||||
$tpl->assign('user', api_get_user_info($sale['user_id']));
|
||||
$tpl->assign('form', $form->returnForm());
|
||||
|
||||
$content = $tpl->fetch('buycourses/view/success.tpl');
|
||||
$tpl->assign('content', $content);
|
||||
$tpl->display_one_col_template();
|
||||
30
plugin/buycourses/src/tpv_error.php
Normal file
30
plugin/buycourses/src/tpv_error.php
Normal file
@@ -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;
|
||||
68
plugin/buycourses/src/tpv_response.php
Normal file
68
plugin/buycourses/src/tpv_response.php
Normal file
@@ -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']);
|
||||
}
|
||||
}
|
||||
}
|
||||
31
plugin/buycourses/src/tpv_success.php
Normal file
31
plugin/buycourses/src/tpv_success.php
Normal file
@@ -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;
|
||||
Reference in New Issue
Block a user