-
Notifications
You must be signed in to change notification settings - Fork 0
/
payment.php
163 lines (141 loc) · 6.16 KB
/
payment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Payment page for an activity
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* @package availability_coursepayment
* @copyright 2016 Mfreak.nl
* @author Luuk Verhoeven
**/
require('../../../config.php');
defined('MOODLE_INTERNAL') || die;
$cmid = optional_param('cmid', false, PARAM_INT);
$section = optional_param('section', false, PARAM_INT);
$contextlevel = required_param('contextlevel', PARAM_INT);
$courseid = required_param('courseid', PARAM_INT);
$method = optional_param('method', false, PARAM_ALPHA);
$course = $DB->get_record('course', ['id' => $courseid], '*', MUST_EXIST);
require_login($course);
$PAGE->set_url('/availability/condition/coursepayment/payment.php', [
'courseid' => $course->id,
'cmid' => $cmid,
'method' => $method,
'section' => $section,
]);
if (enrol_coursepayment_helper::requires_mollie_connect()) {
throw new moodle_exception('error:mollie_connect_requires', 'enrol_coursepayment');
}
/* @var enrol_coursepayment_gateway $gateway */
$gateway = new enrol_coursepayment_mollie();
// Check if we support the standalone page mode.
if ($gateway->is_standalone_purchase_page()) {
// Standalone.
$PAGE->requires->js_init_call('M.enrol_coursepayment_mollie_standalone.init', [
$CFG->wwwroot . '/enrol/coursepayment/ajax.php',
sesskey(),
$course->id,
], false, [
'name' => 'enrol_coursepayment_mollie_standalone',
'fullpath' => '/enrol/coursepayment/js/mollie_standalone.js',
'requires' => ['node', 'io'],
]);
$PAGE->requires->css('/enrol/coursepayment/gateway_mollie.css');
$PAGE->set_pagelayout('popup');
} else {
// Old payment page.
$jsmodule = [
'name' => 'enrol_coursepayment_gateway',
'fullpath' => '/enrol/coursepayment/js/gateway.js',
'requires' => ['node', 'io'],
];
$PAGE->requires->js_init_call('M.enrol_coursepayment_gateway.init', [
$CFG->wwwroot . '/enrol/coursepayment/ajax.php',
sesskey(),
$course->id,
], false, $jsmodule);
}
$additionaloutput = '';
switch ($contextlevel) {
case CONTEXT_MODULE:
// Check if user already can access the content.
if (\availability_coursepayment\helper::user_can_access_cmid($USER->id, $cmid)) {
redirect(new moodle_url('/course/view.php', ['id' => $course->id, 'status' => 'user_can_access_cmid']));
}
// Get more info.
$module = \availability_coursepayment\helper::get_cmid_info($cmid, $course->id);
$pricing = \availability_coursepayment\helper::pricing_from_cmid($cmid);
// Check if we are redirecting.
if (!$method) {
if (!$gateway->is_standalone_purchase_page()) {
$additionaloutput .= $OUTPUT->heading(get_string('pluginname', 'enrol_coursepayment'));
$additionaloutput .= '<div align="center">
<h3 class="coursepayment_instancename">' . $module->name . " - " . $COURSE->fullname . '</h3>
<p><b>' . get_string("cost") . ':
<span id="coursepayment_cost">' . \availability_coursepayment\helper::price($pricing->cost) . '</span> ' .
get_string('currency:' . strtolower($pricing->currency), 'availability_coursepayment') . ' </b></p>
</div>';
}
}
break;
case CONTEXT_COURSE:
// Check if user already can access the content.
if (\availability_coursepayment\helper::user_can_access_section($section, $USER->id, $course->id)) {
redirect(new moodle_url('/course/view.php', ['id' => $course->id, 'status' => 'user_can_access_section']));
}
// Get more info.
$module = \availability_coursepayment\helper::get_section_info($section, $course->id);
$pricing = \availability_coursepayment\helper::pricing_from_section($section, $course->id);
// Check if we are redirecting.
if (!$method) {
if (!$gateway->is_standalone_purchase_page()) {
$additionaloutput .= $OUTPUT->heading(get_string('pluginname', 'enrol_coursepayment'));
$additionaloutput .= '<div align="center">
<h3 class="coursepayment_instancename">' . $module->name . " - " . $COURSE->fullname . '</h3>
<p><b>' . get_string("cost") . ':
<span id="coursepayment_cost">' . \availability_coursepayment\helper::price($pricing->cost) . '</span> ' .
get_string('currency:' . strtolower($pricing->currency), 'availability_coursepayment') . ' </b></p>
</div>';
}
}
break;
}
$gateway->set_instanceconfig((object) [
'is_activity' => true,
'instancename' => $module->name . " - " . $COURSE->fullname,
'localisedcost' => format_float($pricing->cost, 2, true),
'userid' => $USER->id,
'userfullname' => fullname($USER),
'coursename' => $module->name . " - " . $COURSE->fullname, // Module can also be a section.
'locale' => $USER->lang,
'currency' => $pricing->currency,
'cost' => $pricing->cost,
'courseid' => $course->id,
'vatpercentage' => $pricing->vat,
'customint1' => $pricing->vat,
'instanceid' => 0,
'cmid' => $cmid,
'section' => $section,
'contextlevel' => $contextlevel,
]);
// Payment form.
// Load before echoing to prevent errors on redirect.
$form = $gateway->order_form($gateway->is_standalone_purchase_page());
echo $OUTPUT->header();
echo $additionaloutput;
echo $form;
echo $OUTPUT->footer();