diff --git a/enrol/fee/classes/plugin.php b/enrol/fee/classes/plugin.php
index f2d4200a6dba9..b1c5220ce535b 100644
--- a/enrol/fee/classes/plugin.php
+++ b/enrol/fee/classes/plugin.php
@@ -207,7 +207,8 @@ public function enrol_page_hook(stdClass $instance) {
echo '';
} else {
\core_payment\helper::gateways_modal_requirejs();
- $attributes = core_payment\helper::gateways_modal_link_params($cost, $instance->currency);
+ $attributes = core_payment\helper::gateways_modal_link_params($cost, $instance->currency, 'enrol_fee',
+ $instance->id);
echo '
' .
html_writer::tag('button', get_string("sendpaymentbutton", "enrol_paypal"), $attributes) .
diff --git a/lang/en/payment.php b/lang/en/payment.php
index b9f6322e0f32b..9d0e615ab69e1 100644
--- a/lang/en/payment.php
+++ b/lang/en/payment.php
@@ -23,5 +23,6 @@
*/
$string['nogateway'] = 'There is no payment gateway that can be used.';
+$string['nogatewayselected'] = 'You first need to select a payment gateway.';
$string['selectpaymenttype'] = 'Select payment type';
$string['supportedcurrencies'] = 'Supported currencies';
diff --git a/payment/amd/build/gateways_modal.min.js b/payment/amd/build/gateways_modal.min.js
index f6c364ccbe3f7..3660ca750bd6b 100644
--- a/payment/amd/build/gateways_modal.min.js
+++ b/payment/amd/build/gateways_modal.min.js
@@ -1,2 +1,2 @@
-function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("core_payment/gateways_modal",["exports","core/modal_factory","core/templates","core/str","core_payment/repository","./selectors","core/modal_events"],function(a,b,c,d,e,f,g){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.registerEventListeners=void 0;b=j(b);c=j(c);f=j(f);g=i(g);function h(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;h=function(){return a};return a}function i(a){if(a&&a.__esModule){return a}if(null===a||"object"!==_typeof(a)&&"function"!=typeof a){return{default:a}}var b=h();if(b&&b.has(a)){return b.get(a)}var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a){if(Object.prototype.hasOwnProperty.call(a,e)){var f=d?Object.getOwnPropertyDescriptor(a,e):null;if(f&&(f.get||f.set)){Object.defineProperty(c,e,f)}else{c[e]=a[e]}}}c.default=a;if(b){b.set(a,c)}return c}function j(a){return a&&a.__esModule?a:{default:a}}function k(a){if("undefined"==typeof Symbol||null==a[Symbol.iterator]){if(Array.isArray(a)||(a=l(a))){var b=0,c=function(){};return{s:c,n:function n(){if(b>=a.length)return{done:!0};return{done:!1,value:a[b++]}},e:function e(a){throw a},f:c}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var d,e=!0,f=!1,g;return{s:function s(){d=a[Symbol.iterator]()},n:function n(){var a=d.next();e=a.done;return a},e:function e(a){f=!0;g=a},f:function f(){try{if(!e&&null!=d.return)d.return()}finally{if(f)throw g}}}}function l(a,b){if(!a)return;if("string"==typeof a)return m(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);if("Object"===c&&a.constructor)c=a.constructor.name;if("Map"===c||"Set"===c)return Array.from(c);if("Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c))return m(a,b)}function m(a,b){if(null==b||b>a.length)b=a.length;for(var c=0,d=Array(b);c=a.length)return{done:!0};return{done:!1,value:a[b++]}},e:function e(a){throw a},f:c}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var d,e=!0,f=!1,g;return{s:function s(){d=a[Symbol.iterator]()},n:function n(){var a=d.next();e=a.done;return a},e:function e(a){f=!0;g=a},f:function f(){try{if(!e&&null!=d.return)d.return()}finally{if(f)throw g}}}}function p(a,b){if(!a)return;if("string"==typeof a)return q(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);if("Object"===c&&a.constructor)c=a.constructor.name;if("Map"===c||"Set"===c)return Array.from(c);if("Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c))return q(a,b)}function q(a,b){if(null==b||b>a.length)b=a.length;for(var c=0,d=Array(b);c.\n\n/**\n * Contain the logic for the gateways modal.\n *\n * @module core_payment/gateways_modal\n * @package core_payment\n * @copyright 2019 Shamim Rezaie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport ModalFactory from 'core/modal_factory';\nimport Templates from 'core/templates';\nimport {get_string as getString} from 'core/str';\nimport {getGatewaysSupportingCurrency} from 'core_payment/repository';\nimport Selectors from './selectors';\nimport * as ModalEvents from 'core/modal_events';\n\n/**\n * Register event listeners for the module.\n *\n * @param {string} nodeSelector The root to listen to.\n */\nexport const registerEventListeners = (nodeSelector) => {\n const rootNode = document.querySelector(nodeSelector);\n\n rootNode.addEventListener('click', (e) => {\n e.preventDefault();\n show(rootNode, {focusOnClose: e.target});\n });\n};\n\n/**\n * Shows the gateway selector modal.\n *\n * @param {HTMLElement} rootNode\n * @param {Object} options - Additional options\n * @param {HTMLElement} options.focusOnClose The element to focus on when the modal is closed.\n */\nconst show = (rootNode, {\n focusOnClose = null,\n} = {}) => {\n Templates.render('core_payment/gateways_modal', {})\n .done(content => {\n ModalFactory.create({\n title: getString('selectpaymenttype', 'core_payment'),\n body: content,\n })\n .done(function(modal) {\n const currency = rootNode.dataset.currency;\n getGatewaysSupportingCurrency(currency)\n .done(gateways => {\n const context = {\n gateways: []\n };\n\n for (let gateway of gateways) {\n context.gateways.push(gateway);\n }\n\n Templates.render('core_payment/gateways', context)\n .done((html, js) => {\n Templates.replaceNodeContents(modal.getRoot().find(Selectors.regions.gatewaysContainer),\n html, js);\n });\n });\n\n modal.getRoot().on(ModalEvents.hidden, function() {\n // Destroy when hidden.\n modal.destroy();\n try {\n focusOnClose.focus();\n } catch (e) {\n // eslint-disable-line\n }\n });\n\n modal.show();\n });\n });\n};\n"],"file":"gateways_modal.min.js"}
\ No newline at end of file
+{"version":3,"sources":["../src/gateways_modal.js"],"names":["registerEventListeners","nodeSelector","rootNode","document","querySelector","addEventListener","e","preventDefault","show","focusOnClose","target","Templates","render","done","content","ModalFactory","create","type","types","SAVE_CANCEL","title","body","modal","getRoot","currency","dataset","gateways","context","gateway","push","html","js","replaceNodeContents","find","Selectors","regions","gatewaysContainer","on","ModalEvents","hidden","destroy","focus","save","root","values","value","processPayment","amount","component","componentid","then","message","rootElement","paymentMethod","process"],"mappings":"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","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Contain the logic for the gateways modal.\n *\n * @module core_payment/gateways_modal\n * @package core_payment\n * @copyright 2019 Shamim Rezaie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport ModalFactory from 'core/modal_factory';\nimport Templates from 'core/templates';\nimport {get_string as getString} from 'core/str';\nimport {getGatewaysSupportingCurrency} from 'core_payment/repository';\nimport Selectors from './selectors';\nimport * as ModalEvents from 'core/modal_events';\nimport {add as addToast, addToastRegion} from 'core/toast';\n\n/**\n * Register event listeners for the module.\n *\n * @param {string} nodeSelector The root to listen to.\n */\nexport const registerEventListeners = (nodeSelector) => {\n const rootNode = document.querySelector(nodeSelector);\n\n rootNode.addEventListener('click', (e) => {\n e.preventDefault();\n show(rootNode, {focusOnClose: e.target});\n });\n};\n\n/**\n * Shows the gateway selector modal.\n *\n * @param {HTMLElement} rootNode\n * @param {Object} options - Additional options\n * @param {HTMLElement} options.focusOnClose The element to focus on when the modal is closed.\n */\nconst show = (rootNode, {\n focusOnClose = null,\n} = {}) => {\n Templates.render('core_payment/gateways_modal', {})\n .done(content => {\n ModalFactory.create({\n type: ModalFactory.types.SAVE_CANCEL,\n title: getString('selectpaymenttype', 'core_payment'),\n body: content,\n })\n .done(function(modal) {\n addToastRegion(modal.getRoot()[0]);\n const currency = rootNode.dataset.currency;\n getGatewaysSupportingCurrency(currency)\n .done(gateways => {\n const context = {\n gateways: []\n };\n\n for (let gateway of gateways) {\n context.gateways.push(gateway);\n }\n\n Templates.render('core_payment/gateways', context)\n .done((html, js) => {\n Templates.replaceNodeContents(modal.getRoot().find(Selectors.regions.gatewaysContainer),\n html, js);\n });\n });\n\n modal.getRoot().on(ModalEvents.hidden, function() {\n // Destroy when hidden.\n modal.destroy();\n try {\n focusOnClose.focus();\n } catch (e) {\n // eslint-disable-line\n }\n });\n\n modal.getRoot().on(ModalEvents.save, function(e) {\n const root = modal.getRoot()[0];\n const gateway = (root.querySelector(Selectors.values.gateway) || {value: ''}).value;\n\n if (gateway) {\n processPayment(\n root,\n gateway,\n rootNode.dataset.amount,\n rootNode.dataset.currency,\n rootNode.dataset.component,\n rootNode.dataset.componentid\n );\n } else {\n getString('nogatewayselected', 'core_payment').then(message => {\n return addToast(message);\n });\n }\n\n e.preventDefault();\n });\n\n modal.show();\n });\n });\n};\n\n/**\n * Process payment using the selected gateway.\n *\n * @param {HTMLElement} rootElement The root element of the main modal\n * @param {string} gateway The gateway to be used for payment\n * @param {number} amount Amount of payment\n * @param {string} currency The currency in the three-character ISO-4217 format\n * @param {string} component Name of the component that the componentid belongs to\n * @param {number} componentid An internal identifier that is used by the component\n * @returns {Promise}\n */\nconst processPayment = async(rootElement, gateway, amount, currency, component, componentid) => {\n const paymentMethod = await import(`pg_${gateway}/gateways_modal`);\n\n paymentMethod.process(rootElement, amount, currency, component, componentid);\n};\n"],"file":"gateways_modal.min.js"}
\ No newline at end of file
diff --git a/payment/amd/build/selectors.min.js b/payment/amd/build/selectors.min.js
index de2f08e223cd9..480f147c2066f 100644
--- a/payment/amd/build/selectors.min.js
+++ b/payment/amd/build/selectors.min.js
@@ -1,2 +1,2 @@
-define ("core_payment/selectors",["exports"],function(a){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;a.default={regions:{gatewaysContainer:"[data-region=\"gateways-container\"]"}};return a.default});
+define ("core_payment/selectors",["exports"],function(a){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;a.default={regions:{gatewaysContainer:"[data-region=\"gateways-container\"]"},values:{gateway:"[data-region=\"gateways-container\"] input[type=\"radio\"]:checked"}};return a.default});
//# sourceMappingURL=selectors.min.js.map
diff --git a/payment/amd/build/selectors.min.js.map b/payment/amd/build/selectors.min.js.map
index f68775abafae2..fc5d505e55560 100644
--- a/payment/amd/build/selectors.min.js.map
+++ b/payment/amd/build/selectors.min.js.map
@@ -1 +1 @@
-{"version":3,"sources":["../src/selectors.js"],"names":["regions","gatewaysContainer"],"mappings":"kJAwBe,CACXA,OAAO,CAAE,CACLC,iBAAiB,CAAE,sCADd,CADE,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Define all of the selectors we will be using on the payment interface.\n *\n * @module core_payment/selectors\n * @package core_payment\n * @copyright 2019 Shamim Rezaie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nexport default {\n regions: {\n gatewaysContainer: '[data-region=\"gateways-container\"]',\n },\n};\n"],"file":"selectors.min.js"}
\ No newline at end of file
+{"version":3,"sources":["../src/selectors.js"],"names":["regions","gatewaysContainer","values","gateway"],"mappings":"kJAwBe,CACXA,OAAO,CAAE,CACLC,iBAAiB,CAAE,sCADd,CADE,CAIXC,MAAM,CAAE,CACJC,OAAO,CAAE,oEADL,CAJG,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Define all of the selectors we will be using on the payment interface.\n *\n * @module core_payment/selectors\n * @package core_payment\n * @copyright 2019 Shamim Rezaie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nexport default {\n regions: {\n gatewaysContainer: '[data-region=\"gateways-container\"]',\n },\n values: {\n gateway: '[data-region=\"gateways-container\"] input[type=\"radio\"]:checked',\n },\n};\n"],"file":"selectors.min.js"}
\ No newline at end of file
diff --git a/payment/amd/src/gateways_modal.js b/payment/amd/src/gateways_modal.js
index 85791583b12a0..a95c797a5992e 100644
--- a/payment/amd/src/gateways_modal.js
+++ b/payment/amd/src/gateways_modal.js
@@ -28,6 +28,7 @@ import {get_string as getString} from 'core/str';
import {getGatewaysSupportingCurrency} from 'core_payment/repository';
import Selectors from './selectors';
import * as ModalEvents from 'core/modal_events';
+import {add as addToast, addToastRegion} from 'core/toast';
/**
* Register event listeners for the module.
@@ -54,41 +55,82 @@ const show = (rootNode, {
focusOnClose = null,
} = {}) => {
Templates.render('core_payment/gateways_modal', {})
- .done(content => {
- ModalFactory.create({
- title: getString('selectpaymenttype', 'core_payment'),
- body: content,
- })
- .done(function(modal) {
- const currency = rootNode.dataset.currency;
- getGatewaysSupportingCurrency(currency)
- .done(gateways => {
- const context = {
- gateways: []
- };
+ .done(content => {
+ ModalFactory.create({
+ type: ModalFactory.types.SAVE_CANCEL,
+ title: getString('selectpaymenttype', 'core_payment'),
+ body: content,
+ })
+ .done(function(modal) {
+ addToastRegion(modal.getRoot()[0]);
+ const currency = rootNode.dataset.currency;
+ getGatewaysSupportingCurrency(currency)
+ .done(gateways => {
+ const context = {
+ gateways: []
+ };
- for (let gateway of gateways) {
- context.gateways.push(gateway);
- }
+ for (let gateway of gateways) {
+ context.gateways.push(gateway);
+ }
- Templates.render('core_payment/gateways', context)
- .done((html, js) => {
- Templates.replaceNodeContents(modal.getRoot().find(Selectors.regions.gatewaysContainer),
- html, js);
- });
+ Templates.render('core_payment/gateways', context)
+ .done((html, js) => {
+ Templates.replaceNodeContents(modal.getRoot().find(Selectors.regions.gatewaysContainer),
+ html, js);
});
+ });
+
+ modal.getRoot().on(ModalEvents.hidden, function() {
+ // Destroy when hidden.
+ modal.destroy();
+ try {
+ focusOnClose.focus();
+ } catch (e) {
+ // eslint-disable-line
+ }
+ });
- modal.getRoot().on(ModalEvents.hidden, function() {
- // Destroy when hidden.
- modal.destroy();
- try {
- focusOnClose.focus();
- } catch (e) {
- // eslint-disable-line
- }
- });
+ modal.getRoot().on(ModalEvents.save, function(e) {
+ const root = modal.getRoot()[0];
+ const gateway = (root.querySelector(Selectors.values.gateway) || {value: ''}).value;
- modal.show();
+ if (gateway) {
+ processPayment(
+ root,
+ gateway,
+ rootNode.dataset.amount,
+ rootNode.dataset.currency,
+ rootNode.dataset.component,
+ rootNode.dataset.componentid
+ );
+ } else {
+ getString('nogatewayselected', 'core_payment').then(message => {
+ return addToast(message);
+ });
+ }
+
+ e.preventDefault();
});
+
+ modal.show();
});
+ });
+};
+
+/**
+ * Process payment using the selected gateway.
+ *
+ * @param {HTMLElement} rootElement The root element of the main modal
+ * @param {string} gateway The gateway to be used for payment
+ * @param {number} amount Amount of payment
+ * @param {string} currency The currency in the three-character ISO-4217 format
+ * @param {string} component Name of the component that the componentid belongs to
+ * @param {number} componentid An internal identifier that is used by the component
+ * @returns {Promise}
+ */
+const processPayment = async(rootElement, gateway, amount, currency, component, componentid) => {
+ const paymentMethod = await import(`pg_${gateway}/gateways_modal`);
+
+ paymentMethod.process(rootElement, amount, currency, component, componentid);
};
diff --git a/payment/amd/src/selectors.js b/payment/amd/src/selectors.js
index 35be2db22651e..5bfc1af82b191 100644
--- a/payment/amd/src/selectors.js
+++ b/payment/amd/src/selectors.js
@@ -26,4 +26,7 @@ export default {
regions: {
gatewaysContainer: '[data-region="gateways-container"]',
},
+ values: {
+ gateway: '[data-region="gateways-container"] input[type="radio"]:checked',
+ },
};
diff --git a/payment/classes/helper.php b/payment/classes/helper.php
index 1fb92612a702f..ef9df49d81e70 100644
--- a/payment/classes/helper.php
+++ b/payment/classes/helper.php
@@ -98,12 +98,14 @@ public static function gateways_modal_requirejs(): void {
* @param string $currency Currency of payment
* @return array
*/
- public static function gateways_modal_link_params(float $amount, string $currency) : array {
+ public static function gateways_modal_link_params(float $amount, string $currency, string $component, int $componentid): array {
return [
'id' => 'gateways-modal-trigger',
'role' => 'button',
'data-amount' => $amount,
'data-currency' => $currency,
+ 'data-component' => $component,
+ 'data-componentid' => $componentid,
];
}
}