diff --git a/payment/amd/build/gateways_modal.min.js b/payment/amd/build/gateways_modal.min.js index 0c03f7182fa..84578b72a1d 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","core/toast"],function(a,b,c,d,e,f,g,h){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.registerEventListeners=void 0;b=k(b);c=k(c);f=k(f);g=j(g);var r="undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:{};function i(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;i=function(){return a};return a}function j(a){if(a&&a.__esModule){return a}if(null===a||"object"!==_typeof(a)&&"function"!=typeof a){return{default:a}}var b=i();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 k(a){return a&&a.__esModule?a:{default:a}}function l(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){c(a);return}if(h.done){b(i)}else{Promise.resolve(i).then(d,e)}}function m(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){var h=a.apply(b,c);function f(a){l(h,d,e,f,g,"next",a)}function g(a){l(h,d,e,f,g,"throw",a)}f(void 0)})}}function n(a){if("undefined"==typeof Symbol||null==a[Symbol.iterator]){if(Array.isArray(a)||(a=p(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 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=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';\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 gateway,\n rootNode.dataset.amount,\n rootNode.dataset.currency,\n rootNode.dataset.component,\n rootNode.dataset.componentid,\n rootNode.dataset.description,\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 {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 * @param {string} description Description of the payment\n * @returns {Promise}\n */\nconst processPayment = async(gateway, amount, currency, component, componentid, description) => {\n const paymentMethod = await import(`pg_${gateway}/gateways_modal`);\n\n paymentMethod.process(amount, currency, component, componentid, description);\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","description","success","message","hide","Notification","addNotification","location","reload","alert","then","callback","paymentMethod","process"],"mappings":"6lBAwBA,OACA,OAGA,OACA,OAEA,O,khEAOsC,QAAzBA,CAAAA,sBAAyB,CAACC,CAAD,CAAkB,CACpD,GAAMC,CAAAA,CAAQ,CAAGC,QAAQ,CAACC,aAAT,CAAuBH,CAAvB,CAAjB,CAEAC,CAAQ,CAACG,gBAAT,CAA0B,OAA1B,CAAmC,SAACC,CAAD,CAAO,CACtCA,CAAC,CAACC,cAAF,GACAC,CAAI,CAACN,CAAD,CAAW,CAACO,YAAY,CAAEH,CAAC,CAACI,MAAjB,CAAX,CACP,CAHD,CAIH,C,IASKF,CAAAA,CAAI,CAAG,SAACN,CAAD,CAEF,8DAAP,EAAO,KADPO,YACO,CADPA,CACO,YADQ,IACR,GACPE,UAAUC,MAAV,CAAiB,6BAAjB,CAAgD,EAAhD,EACCC,IADD,CACM,SAAAC,CAAO,CAAI,CACbC,UAAaC,MAAb,CAAoB,CAChBC,IAAI,CAAEF,UAAa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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';\nimport Notification from 'core/notification';\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 gateway,\n rootNode.dataset.amount,\n rootNode.dataset.currency,\n rootNode.dataset.component,\n rootNode.dataset.componentid,\n rootNode.dataset.description,\n ({success, message = ''}) => {\n modal.hide();\n if (success) {\n Notification.addNotification({\n message: message,\n type: 'success',\n });\n location.reload();\n } else {\n Notification.alert('', message);\n }\n },\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 {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 * @param {string} description Description of the payment\n * @param {processPaymentCallback} callback The callback function to call when processing is finished\n * @returns {Promise}\n */\nconst processPayment = async(gateway, amount, currency, component, componentid, description, callback) => {\n const paymentMethod = await import(`pg_${gateway}/gateways_modal`);\n\n paymentMethod.process(amount, currency, component, componentid, description, callback);\n};\n\n/**\n * The callback definition for processPayment.\n *\n * @callback processPaymentCallback\n * @param {bool} success\n * @param {string} message\n */\n"],"file":"gateways_modal.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 39251ca6c52..b87a8bf4e13 100644 --- a/payment/amd/src/gateways_modal.js +++ b/payment/amd/src/gateways_modal.js @@ -29,6 +29,7 @@ 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'; +import Notification from 'core/notification'; /** * Register event listeners for the module. @@ -103,6 +104,18 @@ const show = (rootNode, { rootNode.dataset.component, rootNode.dataset.componentid, rootNode.dataset.description, + ({success, message = ''}) => { + modal.hide(); + if (success) { + Notification.addNotification({ + message: message, + type: 'success', + }); + location.reload(); + } else { + Notification.alert('', message); + } + }, ); } else { getString('nogatewayselected', 'core_payment').then(message => { @@ -127,10 +140,19 @@ const show = (rootNode, { * @param {string} component Name of the component that the componentid belongs to * @param {number} componentid An internal identifier that is used by the component * @param {string} description Description of the payment + * @param {processPaymentCallback} callback The callback function to call when processing is finished * @returns {Promise} */ -const processPayment = async(gateway, amount, currency, component, componentid, description) => { +const processPayment = async(gateway, amount, currency, component, componentid, description, callback) => { const paymentMethod = await import(`pg_${gateway}/gateways_modal`); - paymentMethod.process(amount, currency, component, componentid, description); + paymentMethod.process(amount, currency, component, componentid, description, callback); }; + +/** + * The callback definition for processPayment. + * + * @callback processPaymentCallback + * @param {bool} success + * @param {string} message + */ diff --git a/payment/gateway/paypal/amd/build/gateways_modal.min.js b/payment/gateway/paypal/amd/build/gateways_modal.min.js index b60eba14ebc..ddb38505e2b 100644 --- a/payment/gateway/paypal/amd/build/gateways_modal.min.js +++ b/payment/gateway/paypal/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 ("pg_paypal/gateways_modal",["exports","./repository","core/templates","core/truncate","core/ajax","core/notification","core/modal_factory"],function(a,b,c,d,e,f,g){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.process=void 0;b=j(b);c=h(c);d=h(d);e=h(e);f=h(f);g=h(g);function h(a){return a&&a.__esModule?a:{default:a}}function i(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;i=function(){return a};return a}function j(a){if(a&&a.__esModule){return a}if(null===a||"object"!==_typeof(a)&&"function"!=typeof a){return{default:a}}var b=i();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 k(a,b){return r(a)||q(a,b)||m(a,b)||l()}function l(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function m(a,b){if(!a)return;if("string"==typeof a)return p(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 p(a,b)}function p(a,b){if(null==b||b>a.length)b=a.length;for(var c=0,d=Array(b);c");paypal.Buttons({createOrder:function createOrder(a,b){return b.order.create({purchase_units:[{amount:{currency_code:g,value:c},description:d.default.truncate(j,{length:127,stripTags:!0})}],application_context:{shipping_preference:"NO_SHIPPING",brand_name:d.default.truncate(o.brandname,{length:127,stripTags:!0})}})},onApprove:function onApprove(a,b){b.order.authorize().then(function(b){var c=b.purchase_units[0].payments.authorizations[0].id;return e.default.call([{methodname:"pg_paypal_transaction_complete",args:{component:h,componentid:i,orderid:a.orderID,authorizationid:c}}])[0].then(function(a){f.default.addNotification({message:a.message,type:a.success?"success":"error"})})})}}).render(n.getBody()[0])});case 8:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}();a.process=v;var w=function(a,b){if(w.currentlyloaded.includes(a)){b();return}var c=document.createElement("script");if(c.readyState){c.onreadystatechange=function(){if("complete"==this.readyState||"loaded"==this.readyState){this.onreadystatechange=null;b()}}}else{c.onload=function(){b()}}c.setAttribute("src",a);document.head.appendChild(c);w.currentlyloaded.push(a)};w.currentlyloaded=[]}); +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 ("pg_paypal/gateways_modal",["exports","./repository","core/templates","core/truncate","core/ajax","core/modal_factory","core/modal_events"],function(a,b,c,d,e,f,g){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.process=void 0;b=j(b);c=h(c);d=h(d);e=h(e);f=h(f);g=h(g);function h(a){return a&&a.__esModule?a:{default:a}}function i(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;i=function(){return a};return a}function j(a){if(a&&a.__esModule){return a}if(null===a||"object"!==_typeof(a)&&"function"!=typeof a){return{default:a}}var b=i();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 k(a,b){return r(a)||q(a,b)||m(a,b)||l()}function l(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function m(a,b){if(!a)return;if("string"==typeof a)return p(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 p(a,b)}function p(a,b){if(null==b||b>a.length)b=a.length;for(var c=0,d=Array(b);c");paypal.Buttons({createOrder:function createOrder(a,b){return b.order.create({purchase_units:[{amount:{currency_code:f,value:c},description:d.default.truncate(j,{length:127,stripTags:!0})}],application_context:{shipping_preference:"NO_SHIPPING",brand_name:d.default.truncate(p.brandname,{length:127,stripTags:!0})}})},onApprove:function onApprove(a,b){b.order.authorize().then(function(b){var c=b.purchase_units[0].payments.authorizations[0].id;return e.default.call([{methodname:"pg_paypal_transaction_complete",args:{component:h,componentid:i,orderid:a.orderID,authorizationid:c}}])[0].then(function(a){o.hide();return l(a)})})}}).render(o.getBody()[0])});case 9:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}();a.process=v;var w=function(a,b){if(w.currentlyloaded.includes(a)){b();return}var c=document.createElement("script");if(c.readyState){c.onreadystatechange=function(){if("complete"==this.readyState||"loaded"==this.readyState){this.onreadystatechange=null;b()}}}else{c.onload=function(){b()}}c.setAttribute("src",a);document.head.appendChild(c);w.currentlyloaded.push(a)};w.currentlyloaded=[]}); //# sourceMappingURL=gateways_modal.min.js.map diff --git a/payment/gateway/paypal/amd/build/gateways_modal.min.js.map b/payment/gateway/paypal/amd/build/gateways_modal.min.js.map index 3d793bcb708..9c5b3a6bb04 100644 --- a/payment/gateway/paypal/amd/build/gateways_modal.min.js.map +++ b/payment/gateway/paypal/amd/build/gateways_modal.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/gateways_modal.js"],"names":["showPlaceholder","ModalFactory","types","CANCEL","Templates","render","type","body","create","modal","show","process","amount","currency","component","componentid","description","Promise","all","Repository","getConfigForJs","paypalConfig","paypalScript","clientid","callExternalFunction","setBody","paypal","Buttons","createOrder","data","actions","order","purchase_units","currency_code","value","Truncate","truncate","length","stripTags","application_context","shipping_preference","brand_name","brandname","onApprove","authorize","then","authorization","authorizationID","payments","authorizations","id","Ajax","call","methodname","args","orderid","orderID","authorizationid","res","Notification","addNotification","message","success","getBody","jsFile","func","currentlyloaded","includes","script","document","createElement","readyState","onreadystatechange","onload","setAttribute","head","appendChild","push"],"mappings":"8hBAuBA,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0B,IAA1B,CACAP,CAAI,EACP,CACJ,CACJ,CAPD,IAOO,CACHG,CAAM,CAACK,MAAP,CAAgB,UAAW,CACvBR,CAAI,EACP,CACJ,CAEDG,CAAM,CAACM,YAAP,CAAoB,KAApB,CAA2BV,CAA3B,EACAK,QAAQ,CAACM,IAAT,CAAcC,WAAd,CAA0BR,CAA1B,EAEA5C,CAAoB,CAAC0C,eAArB,CAAqCW,IAArC,CAA0Cb,CAA1C,CACH,CA1BD,CAkCAxC,CAAoB,CAAC0C,eAArB,CAAuC,E","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 * This module is responsible for PayPal content in the gateways modal.\n *\n * @module pg_paypal/gateway_modal\n * @copyright 2020 Shamim Rezaie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport * as Repository from './repository';\nimport Templates from 'core/templates';\nimport Truncate from 'core/truncate';\nimport Ajax from 'core/ajax';\nimport Notification from 'core/notification';\nimport ModalFactory from 'core/modal_factory';\n\n/**\n * Creates and shows a modal that contains a placeholder.\n *\n * @returns {Promise}\n */\nconst showPlaceholder = async() => {\n const modal = await ModalFactory.create({\n type: ModalFactory.types.CANCEL,\n body: await Templates.render('pg_paypal/paypal_button_placeholder', {})\n });\n modal.show();\n return modal;\n};\n\n/**\n * Process the payment.\n *\n * @param {double} 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 * @param {string} description Description of the payment\n * @returns {Promise}\n */\nexport const process = async(amount, currency, component, componentid, description) => {\n\n const [\n modal,\n paypalConfig,\n ] = await Promise.all([\n showPlaceholder(),\n Repository.getConfigForJs(),\n ]);\n\n const paypalScript = `https://www.paypal.com/sdk/js?client-id=${paypalConfig.clientid}¤cy=${currency}&intent=authorize`;\n\n callExternalFunction(paypalScript, () => {\n modal.setBody('
'); // This is a hack. Instead of emptying the body, we put an empty form there so the modal\n // is not closed when user clicks outside of modal.\n paypal.Buttons({ // eslint-disable-line\n createOrder: function(data, actions) {\n // This function sets up the details of the transaction, including the amount and line item details.\n return actions.order.create({\n purchase_units: [{ // eslint-disable-line\n amount: {\n currency_code: currency, // eslint-disable-line\n value: amount\n },\n description: Truncate.truncate(description, {length: 127, stripTags: true}),\n }],\n application_context: { // eslint-disable-line\n shipping_preference: 'NO_SHIPPING', // eslint-disable-line\n brand_name: Truncate.truncate(paypalConfig.brandname, {length: 127, stripTags: true}), // eslint-disable-line\n },\n });\n },\n onApprove: function(data, actions) {\n // Authorize the transaction.\n actions.order.authorize().then(function(authorization) {\n // Get the authorization id.\n const authorizationID = authorization.purchase_units[0].payments.authorizations[0].id;\n\n // Call your server to validate and capture the transaction.\n return Ajax.call([{\n methodname: 'pg_paypal_transaction_complete',\n args: {\n component,\n componentid,\n orderid: data.orderID,\n authorizationid: authorizationID,\n },\n }])[0]\n .then(function(res) {\n Notification.addNotification({\n message: res.message,\n type: res.success ? 'success' : 'error'\n });\n });\n });\n }\n }).render(modal.getBody()[0]);\n });\n};\n\n/**\n * Calls a function from an external javascript file.\n *\n * @param {string} jsFile URL of the external JavaScript file\n * @param {function} func The function to call\n */\nconst callExternalFunction = (jsFile, func) => {\n // Check to see if this file has already been loaded. If so just go straight to the func.\n if (callExternalFunction.currentlyloaded.includes(jsFile)) {\n func();\n return;\n }\n\n const script = document.createElement('script');\n\n if (script.readyState) {\n script.onreadystatechange = function() {\n if (this.readyState == 'complete' || this.readyState == 'loaded') {\n this.onreadystatechange = null;\n func();\n }\n };\n } else {\n script.onload = function() {\n func();\n };\n }\n\n script.setAttribute('src', jsFile);\n document.head.appendChild(script);\n\n callExternalFunction.currentlyloaded.push(jsFile);\n};\n\n/**\n * Holds the list of external JavaScript files.\n *\n * @static\n * @type {Array}\n */\ncallExternalFunction.currentlyloaded = [];\n"],"file":"gateways_modal.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/gateways_modal.js"],"names":["showPlaceholder","ModalFactory","types","CANCEL","Templates","render","type","body","create","modal","show","process","amount","currency","component","componentid","description","callback","Promise","all","Repository","getConfigForJs","paypalConfig","getRoot","on","ModalEvents","hidden","destroy","paypalScript","clientid","callExternalFunction","setBody","paypal","Buttons","createOrder","data","actions","order","purchase_units","currency_code","value","Truncate","truncate","length","stripTags","application_context","shipping_preference","brand_name","brandname","onApprove","authorize","then","authorization","authorizationID","payments","authorizations","id","Ajax","call","methodname","args","orderid","orderID","authorizationid","res","hide","getBody","jsFile","func","currentlyloaded","includes","script","document","createElement","readyState","onreadystatechange","onload","setAttribute","head","appendChild","push"],"mappings":"8hBAuBA,OACA,OACA,OACA,OACA,OACA,O,u3DAOMA,CAAAA,CAAe,4CAAG,yGACAC,SADA,MAEVA,UAAaC,KAAb,CAAmBC,MAFT,gBAGJC,WAAUC,MAAV,CAAiB,qCAAjB,CAAwD,EAAxD,CAHI,0BAEhBC,IAFgB,MAGhBC,IAHgB,4BACaC,MADb,wBACdC,CADc,QAKpBA,CAAK,CAACC,IAAN,GALoB,yBAMbD,CANa,2CAAH,uD,CAoBRE,CAAO,4CAAG,WAAMC,CAAN,CAAcC,CAAd,CAAwBC,CAAxB,CAAmCC,CAAnC,CAAgDC,CAAhD,CAA6DC,CAA7D,gHAKTC,CAAAA,OAAO,CAACC,GAAR,CAAY,CAClBnB,CAAe,EADG,CAElBoB,CAAU,CAACC,cAAX,EAFkB,CAAZ,CALS,0BAGfZ,CAHe,MAIfa,CAJe,MAUnBb,CAAK,CAACc,OAAN,GAAgBC,EAAhB,CAAmBC,UAAYC,MAA/B,CA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e,CAAEV,CAJf,CAFQ,CAAD,CAAV,EAQH,CARG,EASNF,IATM,CASD,SAASa,CAAT,CAAc,CAChBvD,CAAK,CAACwD,IAAN,GACA,MAAOhD,CAAAA,CAAQ,CAAC+C,CAAD,CAClB,CAZM,CAaV,CAlBD,CAmBH,CAtCU,CAAf,EAuCG3D,MAvCH,CAuCUI,CAAK,CAACyD,OAAN,GAAgB,CAAhB,CAvCV,CAwCH,CA3CmB,CAApB,CAjBmB,wCAAH,uD,aA6EpB,GAAMpC,CAAAA,CAAoB,CAAG,SAACqC,CAAD,CAASC,CAAT,CAAkB,CAE3C,GAAItC,CAAoB,CAACuC,eAArB,CAAqCC,QAArC,CAA8CH,CAA9C,CAAJ,CAA2D,CACvDC,CAAI,GACJ,MACH,CAED,GAAMG,CAAAA,CAAM,CAAGC,QAAQ,CAACC,aAAT,CAAuB,QAAvB,CAAf,CAEA,GAAIF,CAAM,CAACG,UAAX,CAAuB,CACnBH,CAAM,CAACI,kBAAP,CAA4B,UAAW,CACnC,GAAuB,UAAnB,OAAKD,UAAL,EAAoD,QAAnB,OAAKA,UAA1C,CAAkE,CAC9D,KAAKC,kBAAL,CAA0B,IAA1B,CACAP,CAAI,EACP,CACJ,CACJ,CAPD,IAOO,CACHG,CAAM,CAACK,MAAP,CAAgB,UAAW,CACvBR,CAAI,EACP,CACJ,CAEDG,CAAM,CAACM,YAAP,CAAoB,KAApB,CAA2BV,CAA3B,EACAK,QAAQ,CAACM,IAAT,CAAcC,WAAd,CAA0BR,CAA1B,EAEAzC,CAAoB,CAACuC,eAArB,CAAqCW,IAArC,CAA0Cb,CAA1C,CACH,CA1BD,CAkCArC,CAAoB,CAACuC,eAArB,CAAuC,E","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 * This module is responsible for PayPal content in the gateways modal.\n *\n * @module pg_paypal/gateway_modal\n * @copyright 2020 Shamim Rezaie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport * as Repository from './repository';\nimport Templates from 'core/templates';\nimport Truncate from 'core/truncate';\nimport Ajax from 'core/ajax';\nimport ModalFactory from 'core/modal_factory';\nimport ModalEvents from 'core/modal_events';\n\n/**\n * Creates and shows a modal that contains a placeholder.\n *\n * @returns {Promise}\n */\nconst showPlaceholder = async() => {\n const modal = await ModalFactory.create({\n type: ModalFactory.types.CANCEL,\n body: await Templates.render('pg_paypal/paypal_button_placeholder', {})\n });\n modal.show();\n return modal;\n};\n\n/**\n * Process the payment.\n *\n * @param {double} 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 * @param {string} description Description of the payment\n * @param {processCallback} callback The callback function to call when processing is finished\n * @returns {Promise}\n */\nexport const process = async(amount, currency, component, componentid, description, callback) => {\n\n const [\n modal,\n paypalConfig,\n ] = await Promise.all([\n showPlaceholder(),\n Repository.getConfigForJs(),\n ]);\n\n modal.getRoot().on(ModalEvents.hidden, () => {\n // Destroy when hidden.\n modal.destroy();\n });\n\n const paypalScript = `https://www.paypal.com/sdk/js?client-id=${paypalConfig.clientid}¤cy=${currency}&intent=authorize`;\n\n callExternalFunction(paypalScript, () => {\n modal.setBody('
'); // This is a hack. Instead of emptying the body, we put an empty form there so the modal\n // is not closed when user clicks outside of modal.\n paypal.Buttons({ // eslint-disable-line\n createOrder: function(data, actions) {\n // This function sets up the details of the transaction, including the amount and line item details.\n return actions.order.create({\n purchase_units: [{ // eslint-disable-line\n amount: {\n currency_code: currency, // eslint-disable-line\n value: amount\n },\n description: Truncate.truncate(description, {length: 127, stripTags: true}),\n }],\n application_context: { // eslint-disable-line\n shipping_preference: 'NO_SHIPPING', // eslint-disable-line\n brand_name: Truncate.truncate(paypalConfig.brandname, {length: 127, stripTags: true}), // eslint-disable-line\n },\n });\n },\n onApprove: function(data, actions) {\n // Authorize the transaction.\n actions.order.authorize().then(function(authorization) {\n // Get the authorization id.\n const authorizationID = authorization.purchase_units[0].payments.authorizations[0].id;\n\n // Call your server to validate and capture the transaction.\n return Ajax.call([{\n methodname: 'pg_paypal_transaction_complete',\n args: {\n component,\n componentid,\n orderid: data.orderID,\n authorizationid: authorizationID,\n },\n }])[0]\n .then(function(res) {\n modal.hide();\n return callback(res);\n });\n });\n }\n }).render(modal.getBody()[0]);\n });\n};\n\n/**\n * The callback definition for process.\n *\n * @callback processCallback\n * @param {bool} success\n * @param {string} message\n */\n\n/**\n * Calls a function from an external javascript file.\n *\n * @param {string} jsFile URL of the external JavaScript file\n * @param {function} func The function to call\n */\nconst callExternalFunction = (jsFile, func) => {\n // Check to see if this file has already been loaded. If so just go straight to the func.\n if (callExternalFunction.currentlyloaded.includes(jsFile)) {\n func();\n return;\n }\n\n const script = document.createElement('script');\n\n if (script.readyState) {\n script.onreadystatechange = function() {\n if (this.readyState == 'complete' || this.readyState == 'loaded') {\n this.onreadystatechange = null;\n func();\n }\n };\n } else {\n script.onload = function() {\n func();\n };\n }\n\n script.setAttribute('src', jsFile);\n document.head.appendChild(script);\n\n callExternalFunction.currentlyloaded.push(jsFile);\n};\n\n/**\n * Holds the list of external JavaScript files.\n *\n * @static\n * @type {Array}\n */\ncallExternalFunction.currentlyloaded = [];\n"],"file":"gateways_modal.min.js"} \ No newline at end of file diff --git a/payment/gateway/paypal/amd/src/gateways_modal.js b/payment/gateway/paypal/amd/src/gateways_modal.js index a86daf8699b..0266b8b4a42 100644 --- a/payment/gateway/paypal/amd/src/gateways_modal.js +++ b/payment/gateway/paypal/amd/src/gateways_modal.js @@ -25,8 +25,8 @@ import * as Repository from './repository'; import Templates from 'core/templates'; import Truncate from 'core/truncate'; import Ajax from 'core/ajax'; -import Notification from 'core/notification'; import ModalFactory from 'core/modal_factory'; +import ModalEvents from 'core/modal_events'; /** * Creates and shows a modal that contains a placeholder. @@ -50,9 +50,10 @@ const showPlaceholder = async() => { * @param {string} component Name of the component that the componentid belongs to * @param {number} componentid An internal identifier that is used by the component * @param {string} description Description of the payment + * @param {processCallback} callback The callback function to call when processing is finished * @returns {Promise} */ -export const process = async(amount, currency, component, componentid, description) => { +export const process = async(amount, currency, component, componentid, description, callback) => { const [ modal, @@ -62,6 +63,11 @@ export const process = async(amount, currency, component, componentid, descripti Repository.getConfigForJs(), ]); + modal.getRoot().on(ModalEvents.hidden, () => { + // Destroy when hidden. + modal.destroy(); + }); + const paypalScript = `https://www.paypal.com/sdk/js?client-id=${paypalConfig.clientid}¤cy=${currency}&intent=authorize`; callExternalFunction(paypalScript, () => { @@ -101,10 +107,8 @@ export const process = async(amount, currency, component, componentid, descripti }, }])[0] .then(function(res) { - Notification.addNotification({ - message: res.message, - type: res.success ? 'success' : 'error' - }); + modal.hide(); + return callback(res); }); }); } @@ -112,6 +116,14 @@ export const process = async(amount, currency, component, componentid, descripti }); }; +/** + * The callback definition for process. + * + * @callback processCallback + * @param {bool} success + * @param {string} message + */ + /** * Calls a function from an external javascript file. *