Merge pull request #1568 from jloguercio/1.11.x

WIP - Service buying process with paypal and qulqi - Refs BT#12077
pull/2487/head
José Loguercio 9 years ago committed by GitHub
commit bbb558bb37
  1. 2
      plugin/buycourses/lang/spanish.php
  2. 31
      plugin/buycourses/resources/css/style.css
  3. 19
      plugin/buycourses/src/buy_course_plugin.class.php
  4. 234
      plugin/buycourses/src/service_process.php
  5. 2
      plugin/buycourses/src/services_add.php
  6. 2
      plugin/buycourses/src/services_edit.php
  7. 6
      plugin/buycourses/view/catalog.tpl
  8. 94
      plugin/buycourses/view/process.tpl

@ -145,3 +145,5 @@ $strings['ServiceAdded'] = "Servicio agregado";
$strings['ServiceEdited'] = "Servicio editado";
$strings['ServiceSaleInfo'] = "Información del servicio";
$strings['ListOfServicesOnSale'] = "Lista de servicios a la venta";
$strings['AdditionalInfo'] = "Información adicional";
$strings['PleaseSelectTheCorrectInfoToApplyTheService'] = "Porfavor Seleccione la información correcta para aplicar el servicio";

@ -1,5 +1,34 @@
.buy-courses-tabs {
margin-bottom: 15px;
margin-bottom: 15px;
}
.buy-courses-page-header {
padding-bottom: 9px;
margin: 40px 0 20px;
border-bottom: 1px solid #eee;
}
.buy-courses-block-button {
display: block;
width: 100%;
height: 50px;
line-height: 35px;
font-size: 16px;
}
.buy-courses-cross-out {
text-decoration:line-through;
}
.buy-courses-title-color {
color: #5DC3E1;
padding-bottom: 10px;
}
.buy-courses-description-service {
text-align: justify;
font-size: 18px;
line-height: 1.42857;
}
@-moz-keyframes wobblebar-loader {

@ -2010,7 +2010,7 @@ class BuyCoursesPlugin extends Plugin
* @param string $name Optional. The name filter
* @param int $min Optional. The minimum price filter
* @param int $max Optional. The maximum price filter
* @param int $appliesTo Optional.
* @param mixed $appliesTo Optional.
* @return array
*/
public function getCatalogServiceList($name = null, $min = 0, $max = 0, $appliesTo = '')
@ -2069,4 +2069,21 @@ class BuyCoursesPlugin extends Plugin
}
/**
* Update the service sale status
* @param int $serviceSaleId The service sale ID
* @param int $newStatus The new status
* @return boolean
*/
private function updateServiceSaleStatus($serviceSaleId, $newStatus = self::SERVICE_STATUS_PENDING)
{
$serviceSaleTable = Database::get_main_table(self::TABLE_SERVICES_SALE);
return Database::update(
$serviceSaleTable,
['status' => intval($newStatus)],
['id = ?' => intval($serviceSaleId)]
);
}
}

@ -0,0 +1,234 @@
<?php
/* For license terms, see /license.txt */
/**
* Process payments for the Buy Courses plugin
* @package chamilo.plugin.buycourses
*/
/**
* Initialization
*/
$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');
}
$currentUserId = api_get_user_id();
$serviceId = intval($_REQUEST['i']);
if (empty($currentUserId)) {
api_not_allowed(true);
}
$em = Database::getManager();
$plugin = BuyCoursesPlugin::create();
$includeServices = $plugin->get('include_services');
$paypalEnabled = $plugin->get('paypal_enable') === 'true';
$transferEnabled = $plugin->get('transfer_enable') === 'true';
$wizard = true;
$additionalQueryString = '';
if ($includeServices !== 'true') {
api_not_allowed(true);
}
$typeUser = intval($_REQUEST['t']) === BuyCoursesPlugin::SERVICE_TYPE_USER;
$typeCourse = intval($_REQUEST['t']) === BuyCoursesPlugin::SERVICE_TYPE_COURSE;
$typeSession = intval($_REQUEST['t']) === BuyCoursesPlugin::SERVICE_TYPE_SESSION;
$queryString = 'i=' . intval($_REQUEST['i']) . '&t=' . intval($_REQUEST['t']).$additionalQueryString;
$serviceInfo = $plugin->getServices(intval($_REQUEST['i']));
$userInfo = api_get_user_info($currentUserId);
$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;
}
if (!$formValues['info_select']) {
Display::addFlash(
Display::return_message($plugin->get_lang('AdditionalInfoRequired'), 'error', false)
);
header('Location:' . api_get_self() . '?' . $queryString);
exit;
}
$userGroup = $em->getRepository('ChamiloCoreBundle:Usergroup')->findBy(['name' => $formValues['info_select']]);
if ($userGroup) {
Display::addFlash(
Display::return_message($plugin->get_lang('StoreNameAlreadyExist'), 'error', false)
);
header('Location:' . api_get_self() . '?' . $queryString);
exit;
}
$serviceSaleId = $plugin->registerServiceSale($serviceId, $formValues['payment_type'], $formValues['info_select'], $formValues['enable_trial']);
if (!empty($formValues['store_code'])) {
$data = [
'store_code' => Security::remove_XSS($formValues['store_code']),
'store_name' => Security::remove_XSS($formValues['info_select']),
'parent_id' => 0,
'description' => 'Registered by User in buying process',
'type' => 1,
'discount' => 0
];
$verification = $plugin->getDiscountByCode($data['store_code']);
if (!$verification) {
$plugin->addDiscountCode($data);
}
}
if ($serviceSaleId !== false) {
$_SESSION['bc_service_sale_id'] = $serviceSaleId;
if ($verification['discount'] == 100) {
$serviceSale = $plugin->getServiceSale($serviceSaleId);
$serviceSaleIsCompleted = $plugin->completeServiceSale($serviceSale['id']);
if ($serviceSaleIsCompleted) {
Display::addFlash(Display::return_message(sprintf($plugin->get_lang('SubscriptionToServiceXSuccessful'), $serviceSale['service']['name']), 'success'));
$plugin->SendSubscriptionMail(intval($serviceSale['id']));
unset($_SESSION['bc_service_sale_id']);
header('Location: ' . api_get_path(WEB_PLUGIN_PATH) . 'buycourses/src/package_panel.php?id='.$serviceSale['id']);
exit;
}
}
if ($wizard) {
header('Location: ' . api_get_path(WEB_PLUGIN_PATH) . 'buycourses/src/service_process_confirm.php?from=register');
} else {
header('Location: ' . api_get_path(WEB_PLUGIN_PATH) . 'buycourses/src/service_process_confirm.php');
}
}
exit;
}
// Reset discount code
unset($_SESSION['s_discount']);
$paymentTypesOptions = $plugin->getPaymentTypes(true);
$form->addHeader('');
$form->addRadio('payment_type', null, $paymentTypesOptions);
$form->addHtml('<h3 class="panel-heading">'.$plugin->get_lang('AdditionalInfo').'</h3>');
$form->addHeader('');
$form->addHtml(Display::return_message($plugin->get_lang('PleaseSelectTheCorrectInfoToApplyTheService'), 'info'));
$selectOptions = [];
if ($typeUser) {
$users = $em->getRepository('ChamiloUserBundle:User')->findAll();
$selectOptions[$userInfo['user_id']] = api_get_person_name($userInfo['firstname'], $userInfo['lastname']) . ' (' . get_lang('Myself') . ')';
if (!empty($users)) {
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) {
$user = $em->getRepository('ChamiloUserBundle:User')->find($currentUserId);
$courses = $user->getCourses();
if (!empty($courses)) {
foreach ($courses as $course) {
$selectOptions[$course->getCourse()->getId()] = $course->getCourse()->getTitle();
}
}
$form->addSelect('info_select', get_lang('Course'), $selectOptions);
} elseif ($typeSession) {
$user = $em->getRepository('ChamiloUserBundle:User')->find($currentUserId);
$sessions = $user->getSessionCourseSubscriptions();
if (!empty($sessions)) {
foreach ($sessions as $session) {
$selectOptions[$session->getSession()->getId()] = $session->getSession()->getName();
}
}
$form->addSelect('info_select', get_lang('Session'), $selectOptions);
} elseif ($typeSubscriptionPackage) {
$trial = intval($serviceInfo['allow_trial']);
if ($trial) {
$trialTime = $serviceInfo['trial_period'] == 'Month' ? get_lang($serviceInfo['trial_period']) . '(es)' : get_lang($serviceInfo['trial_period']) . '(s)';
$form->addHtml('
<div class="form-group ">
<label for="qf_373cc5" class="col-sm-6">
' . sprintf($plugin->get_lang('EnableTrialSubscription'), $serviceInfo['trial_frequency'] . ' ' . $trialTime) . '
</label>
<div class="col-sm-6">
<input cols-size="" name="enable_trial" value="1" id="qf_373cc5" type="checkbox"></div>
<div class="col-sm-0"></div>
</div>
<div class="form-group ">
<div class="col-sm-12">
<p class="help-block">' . sprintf($plugin->get_lang('EnableTrialSubscriptionHelpText'), $serviceInfo['trial_frequency'] . ' ' . $trialTime) . '</p>
</div>
</div>
');
}
$form->addText('store_code', $plugin->get_lang('DiscountCodeProcess'), true, ['cols-size' => [6, 6, 0], 'id' => 'store_code']);
$form->addText('info_select_trick', $plugin->get_lang('StoreName'), true, ['cols-size' => [6, 6, 0], 'id' => 'info_select_trick']);
$form->addHidden('info_select', '');
$form->addHtml('
<div class="form-group">
<div class="col-sm-2 pull-right">
<a id="code-checker" class="btn btn-xs btn-warning">' . $plugin->get_lang('Check') . '</a>
</div>
<div id="code-verificator-text" class="col-sm-4 pull-right">
</div>
</div>
<div id="code-verificator-info">
</div>
<div class="form-group">
<div class="col-sm-12">
<p class="help-block">' . $plugin->get_lang('DiscountCodeInfoText') . '</p>
</div>
</div>
');
}
$form->addHidden('t', intval($_GET['t']));
$form->addHidden('i', intval($_GET['i']));
$form->addButton('submit', $plugin->get_lang('ConfirmOrder'), 'check', 'success');
// View
$templateName = $plugin->get_lang('PaymentMethods');
$interbreadcrumb[] = array("url" => "service_catalog.php", "name" => $plugin->get_lang('ListOfServicesOnSale'));
$tpl = new Template($templateName);
if (isset($_GET['from'])) {
if($_GET['from'] == 'register') {
$tpl->assign('wizard', true);
}
}
$tpl->assign('buying_service', true);
$tpl->assign('service', $serviceInfo);
$tpl->assign('user', api_get_user_info());
$tpl->assign('form', $form->returnForm());
$content = $tpl->fetch('buycourses/view/process.tpl');
$tpl->assign('content', $content);
$tpl->display_one_col_template();

@ -95,7 +95,7 @@ $form->addFile(
(get_lang(
'AddImage'
)),
array('id' => 'picture', 'class' => 'picture-form', 'crop_image' => true, 'crop_ratio' => '4 / 3')
array('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);

@ -113,7 +113,7 @@ $form->addFile(
($formDefaultValues['image'] != '' ? get_lang('UpdateImage') : get_lang(
'AddImage'
)),
array('id' => 'picture', 'class' => 'picture-form', 'crop_image' => true, 'crop_ratio' => '4 / 3')
array('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);

@ -148,11 +148,7 @@
<em class="fa fa-info-circle"></em> {{ 'ServiceInformation'|get_plugin_lang('BuyCoursesPlugin') }}
</a>
<a class="btn btn-success btn-block btn-sm" title="" href="{{ _p.web_plugin ~ 'buycourses/src/service_process.php?' ~ {'i': service.id, 't': service.applies_to}|url_encode() }}">
{% if service.allow_trial %}
<em class="fa fa-shopping-cart"></em> {{ 'TryItNowFree'|get_plugin_lang('BuyCoursesPlugin') }}
{% else %}
<em class="fa fa-shopping-cart"></em> {{ 'Buy'|get_plugin_lang('BuyCoursesPlugin') }}
{% endif %}
<em class="fa fa-shopping-cart"></em> {{ 'Buy'|get_plugin_lang('BuyCoursesPlugin') }}
</a>
</div>
</div>

@ -1,8 +1,9 @@
<script type='text/javascript' src="../js/buycourses.js"></script>
<div class="row">
<div class="col-md-7">
<h3 class="page-header">{{ 'PurchaseData'|get_plugin_lang('BuyCoursesPlugin') }}</h3>
<div class="col-md-5 panel panel-default buycourse-panel-default">
<h3 class="panel-heading">{{ 'PurchaseData'|get_plugin_lang('BuyCoursesPlugin') }}</h3>
<legend></legend>
<div class="row">
{% if buying_course %}
<div class="col-sm-6 col-md-5">
@ -43,10 +44,97 @@
{% endfor %}
</dl>
</div>
{% elseif buying_service %}
<div class="col-sm-12 col-md-12 col-xs-12">
<a href='{{ _p.web }}service/{{ service.id }}'>
<img alt="{{ service.name }}" class="img-responsive" src="{{ _p.web }}plugin/buycourses/uploads/services/images/{{ service.image }}">
</a>
</div>
<div class="col-sm-12 col-md-12 col-xs-12">
<h3>
<a href='{{ _p.web }}service/{{ service.id }}'>{{ service.name }}</a>
</h3>
<ul class="list-unstyled">
{% if service.applies_to == 0 %}
<li><em class="fa fa-hand-o-right"></em> {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'None' | get_lang }}</li>
{% elseif service.applies_to == 1 %}
<li><em class="fa fa-hand-o-right"></em> {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'User' | get_lang }}</li>
{% elseif service.applies_to == 2 %}
<li><em class="fa fa-hand-o-right"></em> {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'Course' | get_lang }}</li>
{% elseif service.applies_to == 3 %}
<li><em class="fa fa-hand-o-right"></em> {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'Session' | get_lang }}</li>
{% endif %}
<li><em class="fa fa-money"></em> {{ 'Price'|get_plugin_lang('BuyCoursesPlugin') }} : {{ service.currency == 'BRL' ? 'R$' : service.currency }} {{ service.price }} / {{ service.duration_days == 0 ? 'NoLimit' | get_lang : service.duration_days ~ ' ' ~ 'Days' | get_lang }} </li>
<li><em class="fa fa-user"></em> {{ service.owner_name }}</li>
<li><em class="fa fa-align-justify"></em> {{ service.description }}</li>
</ul>
<p id="n-price" class="lead text-right" style="color: white;"><span class="label label-primary">{{ service.currency == 'BRL' ? 'R$' : service.currency }} {{ service.price }}</span></p>
<p id="s-price" class="lead text-right"></p>
</div>
<script>
$(document).ready(function() {
$("input[name=info_select_trick]").prop('disabled', true);
$("input[name=payment_type]").attr('hidden', true);
$("input[name=payment_type]").attr('checked', true);
$("#paypal-icon").html(' <em class="fa fa-check text-success fa-2x" aria-hidden="true"></em>');
$("input[name=payment_type]").click(function () {
$("#paypal-icon").html(' <em class="fa fa-check text-success fa-2x" aria-hidden="true"></em>');
})
$("label").removeClass('control-label');
$('.form_required').remove();
$("small").remove();
$("label[for=submit]").remove();
$("input[name=enable_trial]").attr('checked', true);
$("#code-checker").click(function () {
var code = $("#store_code").val();
$.ajax({
beforeSend: function() {
$("#code-checker").html('<em class="fa fa-refresh fa-spin"></em> {{ 'Loading' | get_lang }}');
},
type: "POST",
url: "{{ _p.web_plugin ~ 'buycourses/src/buycourses.ajax.php?a=verify_discount_code' }}",
data : { store_code: code},
success: function(response) {
$("#code-checker").html('{{ 'Check' | get_plugin_lang('BuyCoursesPlugin') }}');
if (response.msg == 'true') {
var store_name = response.store_name;
var description = response.description;
var type = response.type;
var parent = '';
if (response.parent) {
parent = '<div class="form-group"><label for="code_parent" class="col-sm-6">{{ 'Parent' | get_plugin_lang('BuyCoursesPlugin') }}</label><div class="col-sm-6">' + response.parent + '</div></div>'
}
$("input[name=info_select]").val(store_name);
$("#info_select_trick").val(store_name);
$("#code-verificator-text").html('<p style="color: green">{{ 'ValidCode' | get_plugin_lang('BuyCoursesPlugin') }}</p>');
$("#code-verificator-info").html('' +
'<div class="form-group"><label for="code_description" class="col-sm-6">{{ 'Description' | get_plugin_lang('BuyCoursesPlugin') }}</label><div class="col-sm-6">' + description + '</div></div>' +
'<div class="form-group"><label for="code_type" class="col-sm-6">{{ 'Type' | get_plugin_lang('BuyCoursesPlugin') }}</label><div class="col-sm-6">' + type + '</div></div>' + parent +
'');
var price = {{ service.price }};
var show = response.discount;
var discount = price * (response.discount / 100);
var total = price - discount;
$("#n-price").css('text-decoration', 'line-through');
$("#s-price").html('<b>Desconto especial de ' + show + '%</b> <span class="label label-success">{{ service.currency == 'BRL' ? 'R$' : service.currency }} ' + total.toFixed(2) + '</span>');
} else if (response.msg == 'false') {
$("#code-verificator-text").html('<p style="color: red">{{ 'CodeDoesntExist' | get_plugin_lang('BuyCoursesPlugin') }}</p>');
$("input[name=info_select]").val($("#store_code").val());
$("#info_select_trick").val($("#store_code").val());
}
}
});
});
});
</script>
{% endif %}
</div>
</div>
<div class="col-md-5">
<div class="col-md-1">
</div>
<div class="col-md-6 panel panel-default buycourse-panel-default">
<h3 class="panel-heading">{{ 'PaymentMethods' | get_plugin_lang('BuyCoursesPlugin') }}</h3>
{{ form }}
</div>
</div>

Loading…
Cancel
Save