PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / controllers / subscriptions.php
vikappointments / site / controllers Last commit date
calendarweek.php 3 years ago cart.php 1 month ago confirmapp.php 2 years ago empattachser.php 4 years ago empeditcoupon.php 4 years ago empeditcustfield.php 4 years ago empeditlocation.php 4 years ago empeditpay.php 4 years ago empeditprofile.php 4 months ago empeditservice.php 4 years ago empeditwdays.php 4 years ago emplocwdays.php 4 years ago emplogin.php 2 years ago employeesearch.php 2 years ago employeeslist.php 4 years ago empmakerecur.php 1 month ago empmanres.php 1 month ago empsettings.php 2 years ago empsubscr.php 4 years ago empsubscrorder.php 1 year ago index.html 6 years ago modules.php 1 year ago order.php 4 months ago packages.php 4 years ago packagesconfirm.php 4 years ago packagesorder.php 1 year ago servicesearch.php 2 years ago subscriptions.php 4 years ago subscrpayment.php 1 year ago userprofile.php 4 months ago waitinglist.php 4 years ago
subscriptions.php
87 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 VAPLoader::import('libraries.mvc.controllers.admin');
15
16 /**
17 * VikAppointments user subscriptions controller.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsControllerSubscriptions extends VAPControllerAdmin
22 {
23 /**
24 * End-point used to redeem the coupon code.
25 *
26 * @return boolean
27 */
28 public function redeemcoupon()
29 {
30 $app = JFactory::getApplication();
31 $input = $app->input;
32
33 $itemid = $input->getUint('Itemid');
34
35 // prepare redirect URL
36 $this->setRedirect(JRoute::rewrite('index.php?option=com_vikappointments&view=subscriptions' . ($itemid ? '&Itemid=' . $itemid : ''), false));
37
38 // validate form token to prevent brute force attacks
39 if (!JSession::checkToken())
40 {
41 // direct access attempt
42 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
43 return false;
44 }
45
46 // get coupon key from POST
47 $coupon = $input->post->getString('couponkey', '');
48
49 // get cart model
50 $model = $this->getModel('subscrcart');
51
52 // try to redeem the coupon code
53 $res = $model->redeemCoupon($coupon);
54
55 if (!$res)
56 {
57 // get last error registered by the model
58 $error = $model->getError($index = null, $string = true);
59 // propagate error or use the default one
60 $app->enqueueMessage($error ? $error : JText::translate('VAPCOUPONNOTVALID'), 'error');
61 return false;
62 }
63
64 // coupon applied successfully
65 $app->enqueueMessage(JText::translate('VAPCOUPONFOUND'));
66 return true;
67 }
68
69 /**
70 * AJAX end-point used to obtain the updated totals based on the
71 * selected subscription plan and payment method.
72 *
73 * @return void
74 */
75 public function refreshtotalsajax()
76 {
77 // get subscriptions model
78 $model = $this->getModel('subscrcart');
79
80 // refresh totals based on updated subscription plan and payment
81 $totals = $model->getTotals();
82
83 // send totals to caller
84 $this->sendJSON($totals);
85 }
86 }
87