if (abs($cost) < 0.01) { // No cost, other enrolment methods (instances) should be used.
echo '<p>'.get_string('nocost', 'enrol_fee').'</p>';
} else {
- $localisedcost = format_float($cost, -1, true);
-
- if (isguestuser()) { // Force login only for guest user, not real users with guest role.
- $wwwroot = $CFG->wwwroot;
- echo '<div class="mdl-align"><p>'.get_string('paymentrequired').'</p>';
- echo '<p><b>'.get_string('cost').": $instance->currency $localisedcost".'</b></p>';
- echo '<p><a href="'.$wwwroot.'/login/">'.get_string('loginsite').'</a></p>';
- echo '</div>';
- } else {
- $coursefullname = format_string($course->fullname, true, ['context' => $context]);
- \core_payment\helper::gateways_modal_requirejs();
- $attributes = core_payment\helper::gateways_modal_link_params($cost, $instance->currency, 'enrol_fee',
- $instance->id, get_string('purchasedescription', 'enrol_fee', $coursefullname));
-
- echo '<div align="center">' .
- html_writer::tag('button', get_string("sendpaymentbutton", "enrol_paypal"), $attributes) .
- '</div>';
- }
+ $locale = get_string('localecldr', 'langconfig');
+ $fmt = NumberFormatter::create($locale, NumberFormatter::CURRENCY);
+ $localisedcost = numfmt_format_currency($fmt, $cost, $instance->currency);
+
+ $data = [
+ 'isguestuser' => isguestuser(),
+ 'cost' => $localisedcost,
+ 'currency' => $instance->currency,
+ 'amount' => $cost,
+ 'instanceid' => $instance->id,
+ 'description' => get_string('purchasedescription', 'enrol_fee',
+ format_string($course->fullname, true, ['context' => $context])),
+ ];
+ echo $OUTPUT->render_from_template('enrol_fee/payment_region', $data);
}
return $OUTPUT->box(ob_get_clean());
--- /dev/null
+{{!
+ 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/>.
+}}
+{{!
+ @template enrol_fee/payment_region
+
+ This template will render information about course fee along with a button for payment.
+
+ Classes required for JS:
+ * none
+
+ Data attributes required for JS:
+ * data-amount
+ * data-currency
+ * data-component
+ * data-componentid
+ * data-description
+
+ Context variables required for this template:
+ * cost - Human readable cost string including amount and currency
+ * amount - amount of the cost
+ * currency - currency of the cost
+ * instanceid - Id of the enrolment instance
+ * description - The description for this purchase
+
+ Example context (json):
+ {
+ "cost": "$108.50",
+ "amount": 108.50,
+ "currency": "AUD",
+ "instanceid": 11,
+ "description": "Enrolment in course Introduction to algorithms",
+ "isguestuser": false
+ }
+
+}}
+<div class="enrol_fee_payment_region text-center">
+ {{#isguestuser}}
+ <div class="mdl-align">
+ <p>{{# str }} paymentrequired {{/ str}}</p>
+ <p><b>{{cost}}</b></p>
+ <p><a href="{{config.wwwroot}}/login/">{{# str }} loginsite {{/ str }}</a></p>
+ </div>
+ {{/isguestuser}}
+ {{^isguestuser}}
+ <p>{{# str }} paymentrequired {{/ str}}</p>
+ <p><b>{{cost}}</b></p>
+ <button
+ class="btn btn-secondary"
+ type="button"
+ id="gateways-modal-trigger-{{ uniqid }}"
+ data-amount="{{amount}}"
+ data-currency="{{currency}}"
+ data-component="enrol_fee"
+ data-componentid="{{instanceid}}"
+ data-description={{# quote }}{{description}}{{/ quote }}
+ >
+ {{# str }} sendpaymentbutton, enrol_fee {{/ str }}
+ </button>
+ {{/isguestuser}}
+</div>
+{{#js}}
+ require(['core_payment/gateways_modal'], function(modal) {
+ modal.registerEventListeners(document.querySelector('#gateways-modal-trigger-{{ uniqid }}'));
+ });
+{{/js}}
$string['labelsep'] = ': ';
$string['listsep'] = ',';
$string['locale'] = 'en_AU.UTF-8';
+$string['localecldr'] = 'en-AU';
$string['localewin'] = 'English_Australia.1252';
$string['localewincharset'] = '';
$string['oldcharset'] = 'ISO-8859-1';
$string['jump'] = 'Jump';
$string['jumpto'] = 'Jump to...';
$string['keep'] = 'Keep';
+$string['labelvalue'] = '{$a->label}: {$a->value}';
$string['langltr'] = 'Language direction left-to-right';
$string['langrtl'] = 'Language direction right-to-left';
$string['language'] = 'Language';
*
* @param {string} nodeSelector The root to listen to.
*/
-export const registerEventListeners = (nodeSelector) => {
- const rootNode = document.querySelector(nodeSelector);
+export const registerEventListenersBySelector = (nodeSelector) => {
+ document.querySelectorAll(nodeSelector).forEach((element) => {
+ registerEventListeners(element);
+ });
+};
+/**
+ * Register event listeners for the module.
+ *
+ * @param {HTMLElement} rootNode The root to listen to.
+ */
+export const registerEventListeners = (rootNode) => {
rootNode.addEventListener('click', (e) => {
e.preventDefault();
show(rootNode, {focusOnClose: e.target});
return $gateways;
}
- /**
- * Requires the JS libraries for the pay button.
- */
- public static function gateways_modal_requirejs(): void {
- global $PAGE;
-
- static $done = false;
- if ($done) {
- return;
- }
-
- $PAGE->requires->js_call_amd('core_payment/gateways_modal', 'registerEventListeners', ['#gateways-modal-trigger']);
- $done = true;
- }
-
/**
* Returns the attributes to place on a pay button.
*