From 8726d775178df043cd2fb44c4e61b0e3adc3687f Mon Sep 17 00:00:00 2001 From: Shamim Rezaie Date: Sat, 11 Jan 2020 05:34:47 +1100 Subject: [PATCH] MDL-69166 pg_paypal: Display PayPal buttons in a modal --- payment/amd/build/gateways_modal.min.js | 2 +- payment/amd/build/gateways_modal.min.js.map | 2 +- payment/amd/src/gateways_modal.js | 6 +- .../paypal/amd/build/gateways_modal.min.js | 2 +- .../amd/build/gateways_modal.min.js.map | 2 +- .../gateway/paypal/amd/build/selectors.min.js | 2 - .../paypal/amd/build/selectors.min.js.map | 1 - .../gateway/paypal/amd/src/gateways_modal.js | 61 +++++++++++++------ payment/gateway/paypal/amd/src/selectors.js | 32 ---------- 9 files changed, 49 insertions(+), 61 deletions(-) delete mode 100644 payment/gateway/paypal/amd/build/selectors.min.js delete mode 100644 payment/gateway/paypal/amd/build/selectors.min.js.map delete mode 100644 payment/gateway/paypal/amd/src/selectors.js diff --git a/payment/amd/build/gateways_modal.min.js b/payment/amd/build/gateways_modal.min.js index f69ff0440f4..0c03f7182fa 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 root,\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 {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 * @param {string} description Description of the payment\n * @returns {Promise}\n */\nconst processPayment = async(rootElement, gateway, amount, currency, component, componentid, description) => {\n const paymentMethod = await import(`pg_${gateway}/gateways_modal`);\n\n paymentMethod.process(rootElement, 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","then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C,CAAzD,oMACsBtB,CADtB,mOACsBA,CADtB,sDACsBA,CADtB,6BACbyB,CADa,QAGnBA,CAAa,CAACC,OAAd,CAAsBP,CAAtB,CAA8BvB,CAA9B,CAAwCwB,CAAxC,CAAmDC,CAAnD,CAAgEC,CAAhE,EAHmB,wCAAH,uD","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 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 diff --git a/payment/amd/src/gateways_modal.js b/payment/amd/src/gateways_modal.js index 0424017890f..39251ca6c52 100644 --- a/payment/amd/src/gateways_modal.js +++ b/payment/amd/src/gateways_modal.js @@ -97,7 +97,6 @@ const show = (rootNode, { if (gateway) { processPayment( - root, gateway, rootNode.dataset.amount, rootNode.dataset.currency, @@ -122,7 +121,6 @@ const show = (rootNode, { /** * 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 @@ -131,8 +129,8 @@ const show = (rootNode, { * @param {string} description Description of the payment * @returns {Promise} */ -const processPayment = async(rootElement, gateway, amount, currency, component, componentid, description) => { +const processPayment = async(gateway, amount, currency, component, componentid, description) => { const paymentMethod = await import(`pg_${gateway}/gateways_modal`); - paymentMethod.process(rootElement, amount, currency, component, componentid, description); + paymentMethod.process(amount, currency, component, componentid, description); }; diff --git a/payment/gateway/paypal/amd/build/gateways_modal.min.js b/payment/gateway/paypal/amd/build/gateways_modal.min.js index 8511ad8488c..b60eba14ebc 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","./selectors","core/truncate","core/ajax","core/notification"],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);ca.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=[]}); //# 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 4cba6e8b9d9..3d793bcb708 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","rootElement","Templates","renderForPromise","html","js","replaceNodeContents","querySelector","Selectors","regions","gatewaysContainer","process","amount","currency","component","componentid","description","Promise","all","Repository","getConfigForJs","paypalConfig","paypalScript","clientid","callExternalFunction","buttons","save","style","display","innerHTML","paypal","Buttons","createOrder","data","actions","order","create","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","type","success","render","jsFile","callback","currentlyloaded","includes","script","document","createElement","readyState","onreadystatechange","onload","setAttribute","head","appendChild","push"],"mappings":"uhBAuBA,OACA,OACA,OACA,OACA,OACA,O,u3DAQMA,CAAAA,CAAe,4CAAG,WAAMC,CAAN,4GACKC,WAAUC,gBAAV,CAA2B,qCAA3B,CAAkE,EAAlE,CADL,iBACbC,CADa,GACbA,IADa,CACPC,CADO,GACPA,EADO,CAEpBH,UAAUI,mBAAV,CAA8BL,CAAW,CAACM,aAAZ,CAA0BC,UAAUC,OAAV,CAAkBC,iBAA5C,CAA9B,CAA8FN,CAA9F,CAAoGC,CAApG,EAFoB,wCAAH,uD,CAKRM,CAAO,4CAAG,WAAMV,CAAN,CAAmBW,CAAnB,CAA2BC,CAA3B,CAAqCC,CAArC,CAAgDC,CAAhD,CAA6DC,CAA7D,8GAKTC,CAAAA,OAAO,CAACC,GAAR,CAAY,CAClBlB,CAAe,CAACC,CAAD,CADG,CAElBkB,CAAU,CAACC,cAAX,EAFkB,CAAZ,CALS,0BAIfC,CAJe,MAUbC,CAVa,mDAU6CD,CAAY,CAACE,QAV1D,sBAU+EV,CAV/E,sBAYnBW,CAAoB,CAACF,CAAD,CAAe,UAAM,CACrCrB,CAAW,CAACM,aAAZ,CAA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Q,CAAD,CAAV,EAQH,CARG,EASNF,IATM,CASD,SAASa,CAAT,CAAc,CAChBC,UAAaC,eAAb,CAA6B,CACzBC,OAAO,CAAEH,CAAG,CAACG,OADY,CAEzBC,IAAI,CAAEJ,CAAG,CAACK,OAAJ,CAAc,SAAd,CAA0B,OAFP,CAA7B,CAIH,CAdM,CAeV,CApBD,CAqBH,CAxCU,CAAf,EAyCGC,MAzCH,CAyCU7D,UAAUC,OAAV,CAAkBC,iBAzC5B,CA0CH,CA7CmB,CAApB,CAZmB,wCAAH,uD,aA4DpB,GAAMc,CAAAA,CAAoB,CAAG,SAAC8C,CAAD,CAASC,CAAT,CAAsB,CAE/C,GAAI/C,CAAoB,CAACgD,eAArB,CAAqCC,QAArC,CAA8CH,CAA9C,CAAJ,CAA2D,CACvDC,CAAQ,GACR,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,CAAQ,EACX,CACJ,CACJ,CAPD,IAOO,CACHG,CAAM,CAACK,MAAP,CAAgB,UAAW,CACvBR,CAAQ,EACX,CACJ,CAEDG,CAAM,CAACM,YAAP,CAAoB,KAApB,CAA2BV,CAA3B,EACAK,QAAQ,CAACM,IAAT,CAAcC,WAAd,CAA0BR,CAA1B,EAEAlD,CAAoB,CAACgD,eAArB,CAAqCW,IAArC,CAA0Cb,CAA1C,CACH,CA1BD,CA4BA9C,CAAoB,CAACgD,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 Selectors from './selectors';\nimport Truncate from 'core/truncate';\nimport Ajax from 'core/ajax';\nimport Notification from 'core/notification';\n\n/**\n * Renders a placeholder in the modal.\n *\n * @param rootElement\n * @returns {Promise}\n */\nconst showPlaceholder = async(rootElement) => {\n const {html, js} = await Templates.renderForPromise('pg_paypal/paypal_button_placeholder', {});\n Templates.replaceNodeContents(rootElement.querySelector(Selectors.regions.gatewaysContainer), html, js);\n};\n\nexport const process = async(rootElement, amount, currency, component, componentid, description) => {\n\n const [\n ,\n paypalConfig,\n ] = await Promise.all([\n showPlaceholder(rootElement),\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 rootElement.querySelector(Selectors.buttons.save).style.display = 'none';\n rootElement.querySelector(Selectors.regions.gatewaysContainer).innerHTML = '';\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(Selectors.regions.gatewaysContainer);\n });\n};\n\nconst callExternalFunction = (jsFile, callback) => {\n // Check to see if this file has already been loaded. If so just go straight to the callback.\n if (callExternalFunction.currentlyloaded.includes(jsFile)) {\n callback();\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 callback();\n }\n };\n } else {\n script.onload = function() {\n callback();\n };\n }\n\n script.setAttribute('src', jsFile);\n document.head.appendChild(script);\n\n callExternalFunction.currentlyloaded.push(jsFile);\n};\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","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,OACA,OACA,OACA,OACA,OACA,O,u3DAOMA,CAAAA,CAAe,4CAAG,yGACAC,SADA,MAEVA,UAAaC,K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AAW,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 diff --git a/payment/gateway/paypal/amd/build/selectors.min.js b/payment/gateway/paypal/amd/build/selectors.min.js deleted file mode 100644 index 4779204048a..00000000000 --- a/payment/gateway/paypal/amd/build/selectors.min.js +++ /dev/null @@ -1,2 +0,0 @@ -define ("pg_paypal/selectors",["exports"],function(a){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;a.default={regions:{gatewaysContainer:"[data-region=\"gateways-container\"]"},buttons:{save:"[data-action=\"save\"]"}};return a.default}); -//# sourceMappingURL=selectors.min.js.map diff --git a/payment/gateway/paypal/amd/build/selectors.min.js.map b/payment/gateway/paypal/amd/build/selectors.min.js.map deleted file mode 100644 index 41f80ebc7a4..00000000000 --- a/payment/gateway/paypal/amd/build/selectors.min.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["../src/selectors.js"],"names":["regions","gatewaysContainer","buttons","save"],"mappings":"+IAwBe,CACXA,OAAO,CAAE,CACLC,iBAAiB,CAAE,sCADd,CADE,CAIXC,OAAO,CAAE,CACLC,IAAI,CAAE,wBADD,CAJE,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 gateways modal.\n *\n * @module pg_paypal/selectors\n * @package pg_paypal\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 buttons: {\n save: '[data-action=\"save\"]',\n },\n};\n"],"file":"selectors.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 4878736d5cc..a86daf8699b 100644 --- a/payment/gateway/paypal/amd/src/gateways_modal.js +++ b/payment/gateway/paypal/amd/src/gateways_modal.js @@ -23,37 +23,50 @@ import * as Repository from './repository'; import Templates from 'core/templates'; -import Selectors from './selectors'; import Truncate from 'core/truncate'; import Ajax from 'core/ajax'; import Notification from 'core/notification'; +import ModalFactory from 'core/modal_factory'; /** - * Renders a placeholder in the modal. + * Creates and shows a modal that contains a placeholder. * - * @param rootElement - * @returns {Promise} + * @returns {Promise} */ -const showPlaceholder = async(rootElement) => { - const {html, js} = await Templates.renderForPromise('pg_paypal/paypal_button_placeholder', {}); - Templates.replaceNodeContents(rootElement.querySelector(Selectors.regions.gatewaysContainer), html, js); +const showPlaceholder = async() => { + const modal = await ModalFactory.create({ + type: ModalFactory.types.CANCEL, + body: await Templates.render('pg_paypal/paypal_button_placeholder', {}) + }); + modal.show(); + return modal; }; -export const process = async(rootElement, amount, currency, component, componentid, description) => { +/** + * Process the payment. + * + * @param {double} 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 + * @param {string} description Description of the payment + * @returns {Promise} + */ +export const process = async(amount, currency, component, componentid, description) => { const [ - , + modal, paypalConfig, ] = await Promise.all([ - showPlaceholder(rootElement), + showPlaceholder(), Repository.getConfigForJs(), ]); const paypalScript = `https://www.paypal.com/sdk/js?client-id=${paypalConfig.clientid}¤cy=${currency}&intent=authorize`; callExternalFunction(paypalScript, () => { - rootElement.querySelector(Selectors.buttons.save).style.display = 'none'; - rootElement.querySelector(Selectors.regions.gatewaysContainer).innerHTML = ''; + modal.setBody('
'); // This is a hack. Instead of emptying the body, we put an empty form there so the modal + // is not closed when user clicks outside of modal. paypal.Buttons({ // eslint-disable-line createOrder: function(data, actions) { // This function sets up the details of the transaction, including the amount and line item details. @@ -95,14 +108,20 @@ export const process = async(rootElement, amount, currency, component, component }); }); } - }).render(Selectors.regions.gatewaysContainer); + }).render(modal.getBody()[0]); }); }; -const callExternalFunction = (jsFile, callback) => { - // Check to see if this file has already been loaded. If so just go straight to the callback. +/** + * Calls a function from an external javascript file. + * + * @param {string} jsFile URL of the external JavaScript file + * @param {function} func The function to call + */ +const callExternalFunction = (jsFile, func) => { + // Check to see if this file has already been loaded. If so just go straight to the func. if (callExternalFunction.currentlyloaded.includes(jsFile)) { - callback(); + func(); return; } @@ -112,12 +131,12 @@ const callExternalFunction = (jsFile, callback) => { script.onreadystatechange = function() { if (this.readyState == 'complete' || this.readyState == 'loaded') { this.onreadystatechange = null; - callback(); + func(); } }; } else { script.onload = function() { - callback(); + func(); }; } @@ -127,4 +146,10 @@ const callExternalFunction = (jsFile, callback) => { callExternalFunction.currentlyloaded.push(jsFile); }; +/** + * Holds the list of external JavaScript files. + * + * @static + * @type {Array} + */ callExternalFunction.currentlyloaded = []; diff --git a/payment/gateway/paypal/amd/src/selectors.js b/payment/gateway/paypal/amd/src/selectors.js deleted file mode 100644 index 1515be7d740..00000000000 --- a/payment/gateway/paypal/amd/src/selectors.js +++ /dev/null @@ -1,32 +0,0 @@ -// 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 . - -/** - * Define all of the selectors we will be using on the gateways modal. - * - * @module pg_paypal/selectors - * @package pg_paypal - * @copyright 2019 Shamim Rezaie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -export default { - regions: { - gatewaysContainer: '[data-region="gateways-container"]', - }, - buttons: { - save: '[data-action="save"]', - }, -};