From d5a9d6e5207b5e59abbb1385fcf61498111c960e Mon Sep 17 00:00:00 2001 From: Shamim Rezaie Date: Sat, 17 Oct 2020 05:05:54 +1100 Subject: [PATCH] MDL-69166 core_payment: Rename componentid to itemid --- enrol/fee/templates/payment_region.mustache | 4 +- lib/db/install.xml | 4 +- lib/db/upgrade.php | 4 +- payment/amd/build/gateways_modal.min.js | 2 +- payment/amd/build/gateways_modal.min.js.map | 2 +- payment/amd/build/repository.min.js | 2 +- payment/amd/build/repository.min.js.map | 2 +- payment/amd/src/gateways_modal.js | 15 +++--- payment/amd/src/repository.js | 6 +-- .../external/get_available_gateways.php | 12 ++--- payment/classes/helper.php | 46 +++++++++---------- payment/classes/local/callback/provider.php | 8 ++-- .../paypal/amd/build/gateways_modal.min.js | 2 +- .../amd/build/gateways_modal.min.js.map | 2 +- .../paypal/amd/build/repository.min.js | 2 +- .../paypal/amd/build/repository.min.js.map | 2 +- .../gateway/paypal/amd/src/gateways_modal.js | 12 ++--- payment/gateway/paypal/amd/src/repository.js | 10 ++-- .../classes/external/get_config_for_js.php | 12 ++--- .../classes/external/transaction_complete.php | 18 ++++---- payment/tests/generator/lib.php | 2 +- payment/tests/helper_test.php | 2 +- 22 files changed, 85 insertions(+), 86 deletions(-) diff --git a/enrol/fee/templates/payment_region.mustache b/enrol/fee/templates/payment_region.mustache index f39babe421a4f..6fb27c3c38390 100644 --- a/enrol/fee/templates/payment_region.mustache +++ b/enrol/fee/templates/payment_region.mustache @@ -25,7 +25,7 @@ Data attributes required for JS: * data-component * data-paymentarea - * data-componentid + * data-itemid * data-cost * data-description @@ -60,7 +60,7 @@ id="gateways-modal-trigger-{{ uniqid }}" data-component="enrol_fee" data-paymentarea="fee" - data-componentid="{{instanceid}}" + data-itemid="{{instanceid}}" data-cost="{{cost}}" data-description={{# quote }}{{description}}{{/ quote }} > diff --git a/lib/db/install.xml b/lib/db/install.xml index 5fbfe08dfe8b3..5974516647c93 100755 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -4323,7 +4323,7 @@ - + @@ -4339,7 +4339,7 @@ - + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 064a390c42a29..9803aedaf6159 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2925,7 +2925,7 @@ function xmldb_main_upgrade($oldversion) { $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null); $table->add_field('paymentarea', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null); - $table->add_field('componentid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); + $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); $table->add_field('amount', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null); $table->add_field('currency', XMLDB_TYPE_CHAR, '3', null, XMLDB_NOTNULL, null, null); @@ -2941,7 +2941,7 @@ function xmldb_main_upgrade($oldversion) { // Adding indexes to table payments. $table->add_index('gateway', XMLDB_INDEX_NOTUNIQUE, ['gateway']); - $table->add_index('component-paymentarea-componentid', XMLDB_INDEX_NOTUNIQUE, ['component', 'paymentarea', 'componentid']); + $table->add_index('component-paymentarea-itemid', XMLDB_INDEX_NOTUNIQUE, ['component', 'paymentarea', 'itemid']); // Conditionally launch create table for payments. if (!$dbman->table_exists($table)) { diff --git a/payment/amd/build/gateways_modal.min.js b/payment/amd/build/gateways_modal.min.js index 32d97f4155c17..fabf9e580c256 100644 --- a/payment/amd/build/gateways_modal.min.js +++ b/payment/amd/build/gateways_modal.min.js @@ -1,2 +1,2 @@ -define ("core_payment/gateways_modal",["exports","core/modal_factory","core/templates","core/str","./repository","./selectors","core/modal_events","core_payment/events","core/toast","core/notification","./modal_gateways"],function(a,b,c,d,e,f,g,h,i,j,k){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.registerEventListeners=a.registerEventListenersBySelector=void 0;b=l(b);c=l(c);f=l(f);g=l(g);h=l(h);j=l(j);k=l(k);var o="undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:{};function l(a){return a&&a.__esModule?a:{default:a}}function m(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 n(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){var h=a.apply(b,c);function f(a){m(h,d,e,f,g,"next",a)}function g(a){m(h,d,e,f,g,"throw",a)}f(void 0)})}}a.registerEventListenersBySelector=function registerEventListenersBySelector(a){document.querySelectorAll(a).forEach(function(a){p(a)})};var p=function(a){a.addEventListener("click",function(b){b.preventDefault();q(a,{focusOnClose:b.target})})};a.registerEventListeners=p;var q=function(){var a=n(regeneratorRuntime.mark(function a(l){var m,n,o,p,q,u,v,w,x,y,z=arguments;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:m=1.\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 {getAvailableGateways} from './repository';\nimport Selectors from './selectors';\nimport ModalEvents from 'core/modal_events';\nimport PaymentEvents from 'core_payment/events';\nimport {add as addToast, addToastRegion} from 'core/toast';\nimport Notification from 'core/notification';\nimport ModalGateways from './modal_gateways';\n\n/**\n * Register event listeners for the module.\n *\n * @param {string} nodeSelector The root to listen to.\n */\nexport const registerEventListenersBySelector = (nodeSelector) => {\n document.querySelectorAll(nodeSelector).forEach((element) => {\n registerEventListeners(element);\n });\n};\n\n/**\n * Register event listeners for the module.\n *\n * @param {HTMLElement} rootNode The root to listen to.\n */\nexport const registerEventListeners = (rootNode) => {\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 = async(rootNode, {\n focusOnClose = null,\n} = {}) => {\n const modal = await ModalFactory.create({\n type: ModalGateways.TYPE,\n title: await getString('selectpaymenttype', 'core_payment'),\n body: await Templates.render('core_payment/gateways_modal', {}),\n });\n\n const rootElement = modal.getRoot()[0];\n addToastRegion(rootElement);\n\n modal.show();\n\n modal.getRoot().on(ModalEvents.hidden, () => {\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(PaymentEvents.proceed, (e) => {\n const gateway = (rootElement.querySelector(Selectors.values.gateway) || {value: ''}).value;\n\n if (gateway) {\n processPayment(\n gateway,\n rootNode.dataset.component,\n rootNode.dataset.paymentarea,\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 // We cannot use await in the following line.\n // The reason is that we are preventing the default action of the save event being triggered,\n // therefore we cannot define the event handler function asynchronous.\n getString('nogatewayselected', 'core_payment').then(message => addToast(message));\n }\n\n e.preventDefault();\n });\n\n // Re-calculate the cost when gateway is changed.\n rootElement.addEventListener('change', e => {\n if (e.target.matches(Selectors.elements.gateways)) {\n updateCostRegion(rootElement, rootNode.dataset.cost);\n }\n });\n\n const gateways = await getAvailableGateways(rootNode.dataset.component, rootNode.dataset.paymentarea,\n rootNode.dataset.componentid);\n const context = {\n gateways\n };\n\n const {html, js} = await Templates.renderForPromise('core_payment/gateways', context);\n Templates.replaceNodeContents(rootElement.querySelector(Selectors.regions.gatewaysContainer), html, js);\n selectSingleGateway(rootElement);\n await updateCostRegion(rootElement, rootNode.dataset.cost);\n};\n\n/**\n * Auto-select the gateway if there is only one gateway.\n *\n * @param {HTMLElement} root An HTMLElement that contains the cost region\n */\nconst selectSingleGateway = root => {\n const gateways = root.querySelectorAll(Selectors.elements.gateways);\n\n if (gateways.length == 1) {\n gateways[0].checked = true;\n }\n};\n\n/**\n * Shows the cost of the item the user is purchasing in the cost region.\n *\n * @param {HTMLElement} root An HTMLElement that contains the cost region\n * @param {string} defaultCost The default cost that is going to be displayed if no gateway is selected\n * @returns {Promise}\n */\nconst updateCostRegion = async(root, defaultCost = '') => {\n const gatewayElement = root.querySelector(Selectors.values.gateway);\n const surcharge = parseInt((gatewayElement || {dataset: {surcharge: 0}}).dataset.surcharge);\n const cost = (gatewayElement || {dataset: {cost: defaultCost}}).dataset.cost;\n\n const {html, js} = await Templates.renderForPromise('core_payment/fee_breakdown', {fee: cost, surcharge});\n Templates.replaceNodeContents(root.querySelector(Selectors.regions.costContainer), html, js);\n};\n\n/**\n * Process payment using the selected gateway.\n *\n * @param {string} gateway The gateway to be used for payment\n * @param {string} component Name of the component that the componentId belongs to\n * @param {string} paymentArea Name of the area in 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, component, paymentArea, componentId, description, callback) => {\n const paymentMethod = await import(`paygw_${gateway}/gateways_modal`);\n paymentMethod.process(component, paymentArea, 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 +{"version":3,"sources":["../src/gateways_modal.js"],"names":["registerEventListenersBySelector","nodeSelector","document","querySelectorAll","forEach","element","registerEventListeners","rootNode","addEventListener","e","preventDefault","show","focusOnClose","target","ModalFactory","ModalGateways","TYPE","Templates","render","type","title","body","create","modal","rootElement","getRoot","on","ModalEvents","hidden","destroy","focus","PaymentEvents","proceed","gateway","querySelector","Selectors","values","value","processPayment","dataset","component","paymentarea","itemid","description","success","message","hide","Notification","addNotification","location","reload","alert","then","matches","elements","gateways","updateCostRegion","cost","context","renderForPromise","html","js","replaceNodeContents","regions","gatewaysContainer","selectSingleGateway","root","length","checked","defaultCost","gatewayElement","surcharge","parseInt","fee","costContainer","paymentArea","itemId","callback","paymentMethod","process"],"mappings":"+XAwBA,OACA,OAGA,OACA,OACA,OAEA,OACA,O,ggBAOgD,QAAnCA,CAAAA,gCAAmC,CAACC,CAAD,CAAkB,CAC9DC,QAAQ,CAACC,gBAAT,CAA0BF,CAA1B,EAAwCG,OAAxC,CAAgD,SAACC,CAAD,CAAa,CACzDC,CAAsB,CAACD,CAAD,CACzB,CAFD,CAGH,C,CAOM,GAAMC,CAAAA,CAAsB,CAAG,SAACC,CAAD,CAAc,CAChDA,CAAQ,CAACC,gBAAT,CAA0B,OAA1B,CAAmC,SAACC,CAAD,CAAO,CACtCA,CAAC,CAACC,cAAF,GACAC,CAAI,CAACJ,CAAD,CAAW,CAACK,YAAY,CAAEH,CAAC,CAACI,MAAjB,CAAX,CACP,CAHD,CAIH,CALM,C,8BAcDF,CAAAA,CAAI,4CAAG,WAAMJ,CAAN,wJAET,EAFS,KACTK,YADS,CACTA,CADS,YACM,IADN,QAGWE,SAHX,MAICC,UAAcC,IAJf,gBAKQ,iBAAU,mBAAV,CAA+B,cAA/B,CALR,mCAMOC,WAAUC,MAAV,CAAiB,6BAAjB,CAAgD,EAAhD,CANP,0BAILC,IAJK,MAKLC,KALK,MAMLC,IANK,6BAGwBC,MAHxB,yBAGHC,CAHG,QASHC,CATG,CASWD,CAAK,CAACE,OAAN,GAAgB,CAAhB,CATX,CAUT,qBAAeD,CAAf,EAEAD,CAAK,CAACZ,IAAN,GAEAY,CAAK,CAACE,OAAN,GAAgBC,EAAhB,CAAmBC,UAAY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,CAAC/B,OAAO,CAAE,CAACgC,SAAS,CAAE,CAAZ,CAAV,CAAnB,EAA8ChC,OAA9C,CAAsDgC,SAAvD,CAFL,CAGfd,CAHe,CAGR,CAACa,CAAc,EAAI,CAAC/B,OAAO,CAAE,CAACkB,IAAI,CAAEY,CAAP,CAAV,CAAnB,EAAmD9B,OAAnD,CAA2DkB,IAHnD,gBAKIxC,WAAU0C,gBAAV,CAA2B,4BAA3B,CAAyD,CAACc,GAAG,CAAEhB,CAAN,CAAYc,SAAS,CAATA,CAAZ,CAAzD,CALJ,iBAKdX,CALc,GAKdA,IALc,CAKRC,CALQ,GAKRA,EALQ,CAMrB5C,UAAU6C,mBAAV,CAA8BI,CAAI,CAAChC,aAAL,CAAmBC,UAAU4B,OAAV,CAAkBW,aAArC,CAA9B,CAAmFd,CAAnF,CAAyFC,CAAzF,EANqB,yCAAH,uD,CAoBhBvB,CAAc,4CAAG,WAAML,CAAN,CAAeO,CAAf,CAA0BmC,CAA1B,CAAuCC,CAAvC,CAA+CjC,CAA/C,CAA4DkC,CAA5D,uMACyB5C,CADzB,sOACyBA,CADzB,yDACyBA,CADzB,6BACb6C,CADa,QAEnBA,CAAa,CAACC,OAAd,CAAsBvC,CAAtB,CAAiCmC,CAAjC,CAA8CC,CAA9C,CAAsDjC,CAAtD,CAAmEkC,CAAnE,EAFmB,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 {getAvailableGateways} from './repository';\nimport Selectors from './selectors';\nimport ModalEvents from 'core/modal_events';\nimport PaymentEvents from 'core_payment/events';\nimport {add as addToast, addToastRegion} from 'core/toast';\nimport Notification from 'core/notification';\nimport ModalGateways from './modal_gateways';\n\n/**\n * Register event listeners for the module.\n *\n * @param {string} nodeSelector The root to listen to.\n */\nexport const registerEventListenersBySelector = (nodeSelector) => {\n document.querySelectorAll(nodeSelector).forEach((element) => {\n registerEventListeners(element);\n });\n};\n\n/**\n * Register event listeners for the module.\n *\n * @param {HTMLElement} rootNode The root to listen to.\n */\nexport const registerEventListeners = (rootNode) => {\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 = async(rootNode, {\n focusOnClose = null,\n} = {}) => {\n const modal = await ModalFactory.create({\n type: ModalGateways.TYPE,\n title: await getString('selectpaymenttype', 'core_payment'),\n body: await Templates.render('core_payment/gateways_modal', {}),\n });\n\n const rootElement = modal.getRoot()[0];\n addToastRegion(rootElement);\n\n modal.show();\n\n modal.getRoot().on(ModalEvents.hidden, () => {\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(PaymentEvents.proceed, (e) => {\n const gateway = (rootElement.querySelector(Selectors.values.gateway) || {value: ''}).value;\n\n if (gateway) {\n processPayment(\n gateway,\n rootNode.dataset.component,\n rootNode.dataset.paymentarea,\n rootNode.dataset.itemid,\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 // We cannot use await in the following line.\n // The reason is that we are preventing the default action of the save event being triggered,\n // therefore we cannot define the event handler function asynchronous.\n getString('nogatewayselected', 'core_payment').then(message => addToast(message));\n }\n\n e.preventDefault();\n });\n\n // Re-calculate the cost when gateway is changed.\n rootElement.addEventListener('change', e => {\n if (e.target.matches(Selectors.elements.gateways)) {\n updateCostRegion(rootElement, rootNode.dataset.cost);\n }\n });\n\n const gateways = await getAvailableGateways(rootNode.dataset.component, rootNode.dataset.paymentarea, rootNode.dataset.itemid);\n const context = {\n gateways\n };\n\n const {html, js} = await Templates.renderForPromise('core_payment/gateways', context);\n Templates.replaceNodeContents(rootElement.querySelector(Selectors.regions.gatewaysContainer), html, js);\n selectSingleGateway(rootElement);\n await updateCostRegion(rootElement, rootNode.dataset.cost);\n};\n\n/**\n * Auto-select the gateway if there is only one gateway.\n *\n * @param {HTMLElement} root An HTMLElement that contains the cost region\n */\nconst selectSingleGateway = root => {\n const gateways = root.querySelectorAll(Selectors.elements.gateways);\n\n if (gateways.length == 1) {\n gateways[0].checked = true;\n }\n};\n\n/**\n * Shows the cost of the item the user is purchasing in the cost region.\n *\n * @param {HTMLElement} root An HTMLElement that contains the cost region\n * @param {string} defaultCost The default cost that is going to be displayed if no gateway is selected\n * @returns {Promise}\n */\nconst updateCostRegion = async(root, defaultCost = '') => {\n const gatewayElement = root.querySelector(Selectors.values.gateway);\n const surcharge = parseInt((gatewayElement || {dataset: {surcharge: 0}}).dataset.surcharge);\n const cost = (gatewayElement || {dataset: {cost: defaultCost}}).dataset.cost;\n\n const {html, js} = await Templates.renderForPromise('core_payment/fee_breakdown', {fee: cost, surcharge});\n Templates.replaceNodeContents(root.querySelector(Selectors.regions.costContainer), html, js);\n};\n\n/**\n * Process payment using the selected gateway.\n *\n * @param {string} gateway The gateway to be used for payment\n * @param {string} component Name of the component that the itemId belongs to\n * @param {string} paymentArea Name of the area in the component that the itemId belongs to\n * @param {number} itemId 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, component, paymentArea, itemId, description, callback) => {\n const paymentMethod = await import(`paygw_${gateway}/gateways_modal`);\n paymentMethod.process(component, paymentArea, itemId, 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/build/repository.min.js b/payment/amd/build/repository.min.js index 750638661afa3..9a31003276c55 100644 --- a/payment/amd/build/repository.min.js +++ b/payment/amd/build/repository.min.js @@ -1,2 +1,2 @@ -define ("core_payment/repository",["exports","core/ajax"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.getAvailableGateways=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);var c=function(a,c,d){return b.default.call([{methodname:"core_payment_get_available_gateways",args:{component:a,paymentarea:c,componentid:d}}])[0]};a.getAvailableGateways=c}); +define ("core_payment/repository",["exports","core/ajax"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.getAvailableGateways=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);var c=function(a,c,d){return b.default.call([{methodname:"core_payment_get_available_gateways",args:{component:a,paymentarea:c,itemid:d}}])[0]};a.getAvailableGateways=c}); //# sourceMappingURL=repository.min.js.map diff --git a/payment/amd/build/repository.min.js.map b/payment/amd/build/repository.min.js.map index e36de5baa336e..47d3a2a89fe25 100644 --- a/payment/amd/build/repository.min.js.map +++ b/payment/amd/build/repository.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/repository.js"],"names":["getAvailableGateways","component","paymentArea","componentId","Ajax","call","methodname","args","paymentarea","componentid"],"mappings":"oKAwBA,uDAUO,GAAMA,CAAAA,CAAoB,CAAG,SAACC,CAAD,CAAYC,CAAZ,CAAyBC,CAAzB,CAAyC,CASzE,MAAOC,WAAKC,IAAL,CAAU,CARD,CACZC,UAAU,CAAE,qCADA,CAEZC,IAAI,CAAE,CACFN,SAAS,CAATA,CADE,CAEFO,WAAW,CAAEN,CAFX,CAGFO,WAAW,CAAEN,CAHX,CAFM,CAQC,CAAV,EAAqB,CAArB,CACV,CAVM,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 * Repository for payment subsystem.\n *\n * @module core_payment/repository\n * @package core_payment\n * @copyright 2020 Shamim Rezaie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\n\n/**\n * Returns the list of gateways that can process payments in the given currency.\n *\n * @param {string} component\n * @param {string} paymentArea\n * @param {number} componentId\n * @returns {Promise<{shortname: string, name: string, description: String}[]>}\n */\nexport const getAvailableGateways = (component, paymentArea, componentId) => {\n const request = {\n methodname: 'core_payment_get_available_gateways',\n args: {\n component,\n paymentarea: paymentArea,\n componentid: componentId,\n }\n };\n return Ajax.call([request])[0];\n};\n"],"file":"repository.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/repository.js"],"names":["getAvailableGateways","component","paymentArea","itemId","Ajax","call","methodname","args","paymentarea","itemid"],"mappings":"oKAwBA,uDAUO,GAAMA,CAAAA,CAAoB,CAAG,SAACC,CAAD,CAAYC,CAAZ,CAAyBC,CAAzB,CAAoC,CASpE,MAAOC,WAAKC,IAAL,CAAU,CARD,CACZC,UAAU,CAAE,qCADA,CAEZC,IAAI,CAAE,CACFN,SAAS,CAATA,CADE,CAEFO,WAAW,CAAEN,CAFX,CAGFO,MAAM,CAAEN,CAHN,CAFM,CAQC,CAAV,EAAqB,CAArB,CACV,CAVM,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 * Repository for payment subsystem.\n *\n * @module core_payment/repository\n * @package core_payment\n * @copyright 2020 Shamim Rezaie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\n\n/**\n * Returns the list of gateways that can process payments in the given currency.\n *\n * @param {string} component\n * @param {string} paymentArea\n * @param {number} itemId\n * @returns {Promise<{shortname: string, name: string, description: String}[]>}\n */\nexport const getAvailableGateways = (component, paymentArea, itemId) => {\n const request = {\n methodname: 'core_payment_get_available_gateways',\n args: {\n component,\n paymentarea: paymentArea,\n itemid: itemId,\n }\n };\n return Ajax.call([request])[0];\n};\n"],"file":"repository.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 cf748516495d5..afeeb1b9424ee 100644 --- a/payment/amd/src/gateways_modal.js +++ b/payment/amd/src/gateways_modal.js @@ -95,7 +95,7 @@ const show = async(rootNode, { gateway, rootNode.dataset.component, rootNode.dataset.paymentarea, - rootNode.dataset.componentid, + rootNode.dataset.itemid, rootNode.dataset.description, ({success, message = ''}) => { modal.hide(); @@ -127,8 +127,7 @@ const show = async(rootNode, { } }); - const gateways = await getAvailableGateways(rootNode.dataset.component, rootNode.dataset.paymentarea, - rootNode.dataset.componentid); + const gateways = await getAvailableGateways(rootNode.dataset.component, rootNode.dataset.paymentarea, rootNode.dataset.itemid); const context = { gateways }; @@ -172,16 +171,16 @@ const updateCostRegion = async(root, defaultCost = '') => { * Process payment using the selected gateway. * * @param {string} gateway The gateway to be used for payment - * @param {string} component Name of the component that the componentId belongs to - * @param {string} paymentArea Name of the area in the component that the componentId belongs to - * @param {number} componentId An internal identifier that is used by the component + * @param {string} component Name of the component that the itemId belongs to + * @param {string} paymentArea Name of the area in the component that the itemId belongs to + * @param {number} itemId 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, component, paymentArea, componentId, description, callback) => { +const processPayment = async(gateway, component, paymentArea, itemId, description, callback) => { const paymentMethod = await import(`paygw_${gateway}/gateways_modal`); - paymentMethod.process(component, paymentArea, componentId, description, callback); + paymentMethod.process(component, paymentArea, itemId, description, callback); }; /** diff --git a/payment/amd/src/repository.js b/payment/amd/src/repository.js index 7b4ccbbff4e52..c3e71b28cb63b 100644 --- a/payment/amd/src/repository.js +++ b/payment/amd/src/repository.js @@ -29,16 +29,16 @@ import Ajax from 'core/ajax'; * * @param {string} component * @param {string} paymentArea - * @param {number} componentId + * @param {number} itemId * @returns {Promise<{shortname: string, name: string, description: String}[]>} */ -export const getAvailableGateways = (component, paymentArea, componentId) => { +export const getAvailableGateways = (component, paymentArea, itemId) => { const request = { methodname: 'core_payment_get_available_gateways', args: { component, paymentarea: paymentArea, - componentid: componentId, + itemid: itemId, } }; return Ajax.call([request])[0]; diff --git a/payment/classes/external/get_available_gateways.php b/payment/classes/external/get_available_gateways.php index 3eba964295355..09fa896f7ef23 100644 --- a/payment/classes/external/get_available_gateways.php +++ b/payment/classes/external/get_available_gateways.php @@ -46,7 +46,7 @@ public static function execute_parameters(): external_function_parameters { return new external_function_parameters([ 'component' => new external_value(PARAM_COMPONENT, 'Component'), 'paymentarea' => new external_value(PARAM_AREA, 'Payment area in the component'), - 'componentid' => new external_value(PARAM_INT, 'An identifier for payment area in the component') + 'itemid' => new external_value(PARAM_INT, 'An identifier for payment area in the component') ]); } @@ -55,23 +55,23 @@ public static function execute_parameters(): external_function_parameters { * * @param string $component * @param string $paymentarea - * @param int $componentid + * @param int $itemid * @return \stdClass[] */ - public static function execute(string $component, string $paymentarea, int $componentid): array { + public static function execute(string $component, string $paymentarea, int $itemid): array { $params = external_api::validate_parameters(self::execute_parameters(), [ 'component' => $component, 'paymentarea' => $paymentarea, - 'componentid' => $componentid, + 'itemid' => $itemid, ]); $list = []; - $gateways = helper::get_available_gateways($params['component'], $params['paymentarea'], $params['componentid']); + $gateways = helper::get_available_gateways($params['component'], $params['paymentarea'], $params['itemid']); [ 'amount' => $amount, 'currency' => $currency - ] = helper::get_cost($params['component'], $params['paymentarea'], $params['componentid']); + ] = helper::get_cost($params['component'], $params['paymentarea'], $params['itemid']); foreach ($gateways as $gateway) { $surcharge = helper::get_gateway_surcharge($gateway); diff --git a/payment/classes/helper.php b/payment/classes/helper.php index 4dd64e9127e04..0148a5782c524 100644 --- a/payment/classes/helper.php +++ b/payment/classes/helper.php @@ -62,17 +62,17 @@ public static function get_supported_currencies(): array { * * @param string $component * @param string $paymentarea - * @param int $componentid + * @param int $itemid * @return string[] */ - public static function get_available_gateways(string $component, string $paymentarea, int $componentid): array { + public static function get_available_gateways(string $component, string $paymentarea, int $itemid): array { $gateways = []; [ 'amount' => $amount, 'currency' => $currency, 'accountid' => $accountid, - ] = self::get_cost($component, $paymentarea, $componentid); + ] = self::get_cost($component, $paymentarea, $itemid); $account = new account($accountid); if (!$account->get('id') || !$account->get('enabled')) { return $gateways; @@ -143,24 +143,24 @@ public static function get_gateway_surcharge(string $gateway): float { /** * Returns the attributes to place on a pay button. * - * @param string $component Name of the component that the componentid belongs to + * @param string $component Name of the component that the itemid belongs to * @param string $paymentarea - * @param int $componentid An internal identifier that is used by the component + * @param int $itemid An internal identifier that is used by the component * @param string $description Description of the payment * @return array */ - public static function gateways_modal_link_params(string $component, string $paymentarea, int $componentid, string $description): array { + public static function gateways_modal_link_params(string $component, string $paymentarea, int $itemid, string $description): array { [ 'amount' => $amount, 'currency' => $currency - ] = self::get_cost($component, $paymentarea, $componentid); + ] = self::get_cost($component, $paymentarea, $itemid); return [ 'id' => 'gateways-modal-trigger', 'role' => 'button', 'data-component' => $component, 'data-paymentarea' => $paymentarea, - 'data-componentid' => $componentid, + 'data-itemid' => $itemid, 'data-cost' => self::get_cost_as_string($amount, $currency), 'data-description' => $description, ]; @@ -169,14 +169,14 @@ public static function gateways_modal_link_params(string $component, string $pay /** * Asks the cost from the related component. * - * @param string $component Name of the component that the componentid belongs to + * @param string $component Name of the component that the itemid belongs to * @param string $paymentarea - * @param int $componentid An internal identifier that is used by the component + * @param int $itemid An internal identifier that is used by the component * @return array['amount' => float, 'currency' => string, 'accountid' => int] * @throws \moodle_exception */ - public static function get_cost(string $component, string $paymentarea, int $componentid): array { - $cost = component_class_callback("$component\\payment\\provider", 'get_cost', [$paymentarea, $componentid]); + public static function get_cost(string $component, string $paymentarea, int $itemid): array { + $cost = component_class_callback("$component\\payment\\provider", 'get_cost', [$paymentarea, $itemid]); if ($cost === null || !is_array($cost) || !array_key_exists('amount', $cost) || !array_key_exists('currency', $cost) || !array_key_exists('accountid', $cost) ) { @@ -191,14 +191,14 @@ public static function get_cost(string $component, string $paymentarea, int $com * * @param string $component * @param string $paymentarea - * @param int $componentid + * @param int $itemid * @param string $gatewayname * @return array * @throws \moodle_exception */ - public static function get_gateway_configuration(string $component, string $paymentarea, int $componentid, + public static function get_gateway_configuration(string $component, string $paymentarea, int $itemid, string $gatewayname): array { - $x = self::get_cost($component, $paymentarea, $componentid); + $x = self::get_cost($component, $paymentarea, $itemid); $gateway = null; $account = new account($x['accountid']); if ($account && $account->get('enabled')) { @@ -215,15 +215,15 @@ public static function get_gateway_configuration(string $component, string $paym * * @uses \core_payment\local\callback\provider::deliver_order() * - * @param string $component Name of the component that the componentid belongs to + * @param string $component Name of the component that the itemid belongs to * @param string $paymentarea - * @param int $componentid An internal identifier that is used by the component + * @param int $itemid An internal identifier that is used by the component * @param int $paymentid payment id as inserted into the 'payments' table, if needed for reference * @return bool Whether successful or not */ - public static function deliver_order(string $component, string $paymentarea, int $componentid, int $paymentid): bool { + public static function deliver_order(string $component, string $paymentarea, int $itemid, int $paymentid): bool { $result = component_class_callback("$component\\payment\\provider", 'deliver_order', - [$paymentarea, $componentid, $paymentid]); + [$paymentarea, $itemid, $paymentid]); if ($result === null) { throw new \moodle_exception('callbacknotimplemented', 'core_payment', '', $component); @@ -237,23 +237,23 @@ public static function deliver_order(string $component, string $paymentarea, int * Each payment gateway may then store the additional information their way. * * @param int $accountid Account id - * @param string $component Name of the component that the componentid belongs to + * @param string $component Name of the component that the itemid belongs to * @param string $paymentarea - * @param int $componentid An internal identifier that is used by the component + * @param int $itemid An internal identifier that is used by the component * @param int $userid Id of the user who is paying * @param float $amount Amount of payment * @param string $currency Currency of payment * @param string $gateway The gateway that is used for the payment * @return int */ - public static function save_payment(int $accountid, string $component, string $paymentarea, int $componentid, int $userid, + public static function save_payment(int $accountid, string $component, string $paymentarea, int $itemid, int $userid, float $amount, string $currency, string $gateway): int { global $DB; $record = new \stdClass(); $record->component = $component; $record->paymentarea = $paymentarea; - $record->componentid = $componentid; + $record->itemid = $itemid; $record->userid = $userid; $record->amount = $amount; $record->currency = $currency; diff --git a/payment/classes/local/callback/provider.php b/payment/classes/local/callback/provider.php index e4c3b5a01d58e..8b6fa60464ea2 100644 --- a/payment/classes/local/callback/provider.php +++ b/payment/classes/local/callback/provider.php @@ -38,16 +38,16 @@ interface provider { /** * @param string $paymentarea - * @param int $componentid An identifier that is known to the plugin + * @param int $itemid An identifier that is known to the plugin * @return array['amount' => float, 'currency' => string, 'accountid' => int] */ - public static function get_cost(string $paymentarea, int $componentid): array; + public static function get_cost(string $paymentarea, int $itemid): array; /** * @param string $paymentarea - * @param int $componentid An identifier that is known to the plugin + * @param int $itemid An identifier that is known to the plugin * @param int $paymentid payment id as inserted into the 'payments' table, if needed for reference * @return bool Whether successful or not */ - public static function deliver_order(string $paymentarea, int $componentid, int $paymentid): bool; + public static function deliver_order(string $paymentarea, int $itemid, int $paymentid): bool; } diff --git a/payment/gateway/paypal/amd/build/gateways_modal.min.js b/payment/gateway/paypal/amd/build/gateways_modal.min.js index 08f064c9b7905..8faa42b473c7d 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 ("paygw_paypal/gateways_modal",["exports","./repository","core/templates","core/truncate","core/ajax","core/modal_factory","core/modal_events","core/str"],function(a,b,c,d,e,f,g,h){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.process=void 0;b=k(b);c=i(c);d=i(d);e=i(e);f=i(f);g=i(g);function i(a){return a&&a.__esModule?a:{default:a}}function j(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;j=function(){return a};return a}function k(a){if(a&&a.__esModule){return a}if(null===a||"object"!==_typeof(a)&&"function"!=typeof a){return{default:a}}var b=j();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 l(a,b){return r(a)||q(a,b)||n(a,b)||m()}function m(){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 n(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.\n\n/**\n * This module is responsible for PayPal content in the gateways modal.\n *\n * @module paygw_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';\nimport {get_string as getString} from 'core/str';\n\n/**\n * Creates and shows a modal that contains a placeholder.\n *\n * @returns {Promise}\n */\nconst showModalWithPlaceholder = async() => {\n const modal = await ModalFactory.create({\n body: await Templates.render('paygw_paypal/paypal_button_placeholder', {})\n });\n modal.show();\n return modal;\n};\n\n/**\n * Process the payment.\n *\n * @param {string} component Name of the component that the componentId belongs to\n * @param {string} paymentArea The area 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(component, paymentArea, componentId, description, callback) => {\n\n const [\n modal,\n paypalConfig,\n ] = await Promise.all([\n showModalWithPlaceholder(),\n Repository.getConfigForJs(component, paymentArea, componentId),\n ]);\n const currency = paypalConfig.currency;\n const amount = paypalConfig.cost; // Cost with surcharge.\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}`;\n\n callExternalFunction(paypalScript, () => {\n modal.setBody(''); // We have to clear the body. The render method in paypal.Buttons will render everything.\n\n paypal.Buttons({ // eslint-disable-line\n // Set up the transaction.\n createOrder: function(data, actions) {\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 // Finalise the transaction.\n onApprove: function(data) {\n modal.getRoot().on(ModalEvents.outsideClick, (e) => {\n // Prevent closing the modal when clicking outside of it.\n e.preventDefault();\n });\n\n modal.setBody(getString('authorising', 'paygw_paypal'));\n\n // Call server to validate and capture payment for order.\n return Ajax.call([{\n methodname: 'paygw_paypal_create_transaction_complete',\n args: {\n component,\n paymentarea: paymentArea,\n componentid: componentId,\n orderid: data.orderID,\n },\n }])[0]\n .then(function(res) {\n modal.hide();\n return callback(res);\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 == jsFile) {\n func();\n return;\n }\n\n // PayPal can only work with one currency at the same time. We have to unload the previously loaded script\n // if it was loaded for a different currency. Weird way indeed, but the only way.\n // See: https://github.com/paypal/paypal-checkout-components/issues/1180\n if (callExternalFunction.currentlyloaded) {\n const suspectedScript = document.querySelector(`script[src=\"${callExternalFunction.currentlyloaded}\"]`);\n if (suspectedScript) {\n suspectedScript.parentNode.removeChild(suspectedScript);\n }\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 = jsFile;\n};\n\n/**\n * Holds the full url of loaded external JavaScript file.\n *\n * @static\n * @type {string}\n */\ncallExternalFunction.currentlyloaded = '';\n"],"file":"gateways_modal.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/gateways_modal.js"],"names":["showModalWithPlaceholder","ModalFactory","Templates","render","body","create","modal","show","process","component","paymentArea","itemId","description","callback","Promise","all","Repository","getConfigForJs","paypalConfig","currency","amount","cost","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","outsideClick","e","preventDefault","Ajax","call","methodname","args","paymentarea","itemid","orderid","orderID","then","res","hide","getBody","jsFile","func","currentlyloaded","suspectedScript","document","querySelector","parentNode","removeChild","script","createElement","readyState","onreadystatechange","onload","setAttribute","head","appendChild"],"mappings":"8iBAuBA,OACA,OACA,OACA,OACA,OACA,O,u3DAQMA,CAAAA,CAAwB,4CAAG,yGACTC,SADS,gBAEbC,WAAUC,MAAV,CAAiB,wCAAjB,CAA2D,EAA3D,CAFa,0BAEzBC,IAFyB,4BACIC,MADJ,wBACvBC,CADuB,QAI7BA,CAAK,CAACC,IAAN,GAJ6B,yBAKtBD,CALsB,2CAAH,uD,CAkBjBE,CAAO,4CAAG,WAAMC,CAAN,CAAiBC,CAAjB,CAA8BC,CAA9B,CAAsCC,CAAtC,CAAmDC,CAAnD,oHAKTC,CAAAA,OAAO,CAACC,GAAR,CAAY,CAClBf,CAAwB,EADN,CAElBgB,CAAU,CAACC,cAAX,CAA0BR,CAA1B,CAAqCC,CAArC,CAAkDC,CAAlD,CAFkB,CAAZ,CALS,0BAGfL,CAHe,MAIfY,CAJe,MASbC,CATa,CASFD,CAAY,CAACC,QATX,CAUbC,CAVa,CAUJF,CAAY,CAACG,IAVT,CAYnBf,CAAK,CAACgB,OA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C,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 paygw_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';\nimport {get_string as getString} from 'core/str';\n\n/**\n * Creates and shows a modal that contains a placeholder.\n *\n * @returns {Promise}\n */\nconst showModalWithPlaceholder = async() => {\n const modal = await ModalFactory.create({\n body: await Templates.render('paygw_paypal/paypal_button_placeholder', {})\n });\n modal.show();\n return modal;\n};\n\n/**\n * Process the payment.\n *\n * @param {string} component Name of the component that the itemId belongs to\n * @param {string} paymentArea The area of the component that the itemId belongs to\n * @param {number} itemId 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(component, paymentArea, itemId, description, callback) => {\n\n const [\n modal,\n paypalConfig,\n ] = await Promise.all([\n showModalWithPlaceholder(),\n Repository.getConfigForJs(component, paymentArea, itemId),\n ]);\n const currency = paypalConfig.currency;\n const amount = paypalConfig.cost; // Cost with surcharge.\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}`;\n\n callExternalFunction(paypalScript, () => {\n modal.setBody(''); // We have to clear the body. The render method in paypal.Buttons will render everything.\n\n paypal.Buttons({ // eslint-disable-line\n // Set up the transaction.\n createOrder: function(data, actions) {\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 // Finalise the transaction.\n onApprove: function(data) {\n modal.getRoot().on(ModalEvents.outsideClick, (e) => {\n // Prevent closing the modal when clicking outside of it.\n e.preventDefault();\n });\n\n modal.setBody(getString('authorising', 'paygw_paypal'));\n\n // Call server to validate and capture payment for order.\n return Ajax.call([{\n methodname: 'paygw_paypal_create_transaction_complete',\n args: {\n component,\n paymentarea: paymentArea,\n itemid: itemId,\n orderid: data.orderID,\n },\n }])[0]\n .then(function(res) {\n modal.hide();\n return callback(res);\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 == jsFile) {\n func();\n return;\n }\n\n // PayPal can only work with one currency at the same time. We have to unload the previously loaded script\n // if it was loaded for a different currency. Weird way indeed, but the only way.\n // See: https://github.com/paypal/paypal-checkout-components/issues/1180\n if (callExternalFunction.currentlyloaded) {\n const suspectedScript = document.querySelector(`script[src=\"${callExternalFunction.currentlyloaded}\"]`);\n if (suspectedScript) {\n suspectedScript.parentNode.removeChild(suspectedScript);\n }\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 = jsFile;\n};\n\n/**\n * Holds the full url of loaded external JavaScript file.\n *\n * @static\n * @type {string}\n */\ncallExternalFunction.currentlyloaded = '';\n"],"file":"gateways_modal.min.js"} \ No newline at end of file diff --git a/payment/gateway/paypal/amd/build/repository.min.js b/payment/gateway/paypal/amd/build/repository.min.js index af79a9eafb1c3..83d0ead347940 100644 --- a/payment/gateway/paypal/amd/build/repository.min.js +++ b/payment/gateway/paypal/amd/build/repository.min.js @@ -1,2 +1,2 @@ -define ("paygw_paypal/repository",["exports","core/ajax"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.getConfigForJs=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);var c=function(a,c,d){return b.default.call([{methodname:"paygw_paypal_get_config_for_js",args:{component:a,paymentarea:c,componentid:d}}])[0]};a.getConfigForJs=c}); +define ("paygw_paypal/repository",["exports","core/ajax"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.getConfigForJs=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);var c=function(a,c,d){return b.default.call([{methodname:"paygw_paypal_get_config_for_js",args:{component:a,paymentarea:c,itemid:d}}])[0]};a.getConfigForJs=c}); //# sourceMappingURL=repository.min.js.map diff --git a/payment/gateway/paypal/amd/build/repository.min.js.map b/payment/gateway/paypal/amd/build/repository.min.js.map index af94441f3819b..9f0f3835069f7 100644 --- a/payment/gateway/paypal/amd/build/repository.min.js.map +++ b/payment/gateway/paypal/amd/build/repository.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/repository.js"],"names":["getConfigForJs","component","paymentArea","componentId","Ajax","call","methodname","args","paymentarea","componentid"],"mappings":"8JAwBA,uDAUO,GAAMA,CAAAA,CAAc,CAAG,SAACC,CAAD,CAAYC,CAAZ,CAAyBC,CAAzB,CAAyC,CAUnE,MAAOC,WAAKC,IAAL,CAAU,CATD,CACZC,UAAU,CAAE,gCADA,CAEZC,IAAI,CAAE,CACFN,SAAS,CAATA,CADE,CAEFO,WAAW,CAAEN,CAFX,CAGFO,WAAW,CAAEN,CAHX,CAFM,CASC,CAAV,EAAqB,CAArB,CACV,CAXM,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 * PayPal repository module to encapsulate all of the AJAX requests that can be sent for PayPal.\n *\n * @module paygw_paypal/repository\n * @package paygw_paypal\n * @copyright 2020 Shamim Rezaie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\n\n/**\n * Return the PayPal JavaScript SDK URL.\n *\n * @param {string} component Name of the component that the componentid belongs to\n * @param {string} paymentArea The area of the component that the componentid belongs to\n * @param {number} componentId An internal identifier that is used by the component\n * @returns {Promise<{clientid: string, brandname: string}>}\n */\nexport const getConfigForJs = (component, paymentArea, componentId) => {\n const request = {\n methodname: 'paygw_paypal_get_config_for_js',\n args: {\n component,\n paymentarea: paymentArea,\n componentid: componentId,\n },\n };\n\n return Ajax.call([request])[0];\n};\n"],"file":"repository.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/repository.js"],"names":["getConfigForJs","component","paymentArea","itemId","Ajax","call","methodname","args","paymentarea","itemid"],"mappings":"8JAwBA,uDAUO,GAAMA,CAAAA,CAAc,CAAG,SAACC,CAAD,CAAYC,CAAZ,CAAyBC,CAAzB,CAAoC,CAU9D,MAAOC,WAAKC,IAAL,CAAU,CATD,CACZC,UAAU,CAAE,gCADA,CAEZC,IAAI,CAAE,CACFN,SAAS,CAATA,CADE,CAEFO,WAAW,CAAEN,CAFX,CAGFO,MAAM,CAAEN,CAHN,CAFM,CASC,CAAV,EAAqB,CAArB,CACV,CAXM,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 * PayPal repository module to encapsulate all of the AJAX requests that can be sent for PayPal.\n *\n * @module paygw_paypal/repository\n * @package paygw_paypal\n * @copyright 2020 Shamim Rezaie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\n\n/**\n * Return the PayPal JavaScript SDK URL.\n *\n * @param {string} component Name of the component that the itemId belongs to\n * @param {string} paymentArea The area of the component that the itemId belongs to\n * @param {number} itemId An internal identifier that is used by the component\n * @returns {Promise<{clientid: string, brandname: string}>}\n */\nexport const getConfigForJs = (component, paymentArea, itemId) => {\n const request = {\n methodname: 'paygw_paypal_get_config_for_js',\n args: {\n component,\n paymentarea: paymentArea,\n itemid: itemId,\n },\n };\n\n return Ajax.call([request])[0];\n};\n"],"file":"repository.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 59f4bb1e231bd..4d68227e4b505 100644 --- a/payment/gateway/paypal/amd/src/gateways_modal.js +++ b/payment/gateway/paypal/amd/src/gateways_modal.js @@ -45,21 +45,21 @@ const showModalWithPlaceholder = async() => { /** * Process the payment. * - * @param {string} component Name of the component that the componentId belongs to - * @param {string} paymentArea The area of the component that the componentId belongs to - * @param {number} componentId An internal identifier that is used by the component + * @param {string} component Name of the component that the itemId belongs to + * @param {string} paymentArea The area of the component that the itemId belongs to + * @param {number} itemId 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(component, paymentArea, componentId, description, callback) => { +export const process = async(component, paymentArea, itemId, description, callback) => { const [ modal, paypalConfig, ] = await Promise.all([ showModalWithPlaceholder(), - Repository.getConfigForJs(component, paymentArea, componentId), + Repository.getConfigForJs(component, paymentArea, itemId), ]); const currency = paypalConfig.currency; const amount = paypalConfig.cost; // Cost with surcharge. @@ -106,7 +106,7 @@ export const process = async(component, paymentArea, componentId, description, c args: { component, paymentarea: paymentArea, - componentid: componentId, + itemid: itemId, orderid: data.orderID, }, }])[0] diff --git a/payment/gateway/paypal/amd/src/repository.js b/payment/gateway/paypal/amd/src/repository.js index 627c95d419a49..627753e695638 100644 --- a/payment/gateway/paypal/amd/src/repository.js +++ b/payment/gateway/paypal/amd/src/repository.js @@ -27,18 +27,18 @@ import Ajax from 'core/ajax'; /** * Return the PayPal JavaScript SDK URL. * - * @param {string} component Name of the component that the componentid belongs to - * @param {string} paymentArea The area of the component that the componentid belongs to - * @param {number} componentId An internal identifier that is used by the component + * @param {string} component Name of the component that the itemId belongs to + * @param {string} paymentArea The area of the component that the itemId belongs to + * @param {number} itemId An internal identifier that is used by the component * @returns {Promise<{clientid: string, brandname: string}>} */ -export const getConfigForJs = (component, paymentArea, componentId) => { +export const getConfigForJs = (component, paymentArea, itemId) => { const request = { methodname: 'paygw_paypal_get_config_for_js', args: { component, paymentarea: paymentArea, - componentid: componentId, + itemid: itemId, }, }; diff --git a/payment/gateway/paypal/classes/external/get_config_for_js.php b/payment/gateway/paypal/classes/external/get_config_for_js.php index 0cd110f99772c..5850dcb9c1cf9 100644 --- a/payment/gateway/paypal/classes/external/get_config_for_js.php +++ b/payment/gateway/paypal/classes/external/get_config_for_js.php @@ -47,7 +47,7 @@ public static function execute_parameters(): external_function_parameters { return new external_function_parameters([ 'component' => new external_value(PARAM_COMPONENT, 'Component'), 'paymentarea' => new external_value(PARAM_AREA, 'Payment area in the component'), - 'componentid' => new external_value(PARAM_INT, 'An identifier for payment area in the component'), + 'itemid' => new external_value(PARAM_INT, 'An identifier for payment area in the component'), ]); } @@ -56,18 +56,18 @@ public static function execute_parameters(): external_function_parameters { * * @param string $component * @param string $paymentarea - * @param int $componentid + * @param int $itemid * @return string[] */ - public static function execute(string $component, string $paymentarea, int $componentid): array { + public static function execute(string $component, string $paymentarea, int $itemid): array { self::validate_parameters(self::execute_parameters(), [ 'component' => $component, 'paymentarea' => $paymentarea, - 'componentid' => $componentid, + 'itemid' => $itemid, ]); - $config = helper::get_gateway_configuration($component, $paymentarea, $componentid, 'paypal'); - $cost = helper::get_cost($component, $paymentarea, $componentid); + $config = helper::get_gateway_configuration($component, $paymentarea, $itemid, 'paypal'); + $cost = helper::get_cost($component, $paymentarea, $itemid); $surcharge = helper::get_gateway_surcharge('paypal'); return [ diff --git a/payment/gateway/paypal/classes/external/transaction_complete.php b/payment/gateway/paypal/classes/external/transaction_complete.php index 251272d290b6e..dba305ea545f0 100644 --- a/payment/gateway/paypal/classes/external/transaction_complete.php +++ b/payment/gateway/paypal/classes/external/transaction_complete.php @@ -48,7 +48,7 @@ public static function execute_parameters() { return new external_function_parameters([ 'component' => new external_value(PARAM_COMPONENT, 'The component name'), 'paymentarea' => new external_value(PARAM_AREA, 'Payment area in the component'), - 'componentid' => new external_value(PARAM_INT, 'The item id in the context of the component area'), + 'itemid' => new external_value(PARAM_INT, 'The item id in the context of the component area'), 'orderid' => new external_value(PARAM_TEXT, 'The order id coming back from PayPal'), ]); } @@ -57,30 +57,30 @@ public static function execute_parameters() { * Perform what needs to be done when a transaction is reported to be complete. * This function does not take cost as a parameter as we cannot rely on any provided value. * - * @param string $component Name of the component that the componentid belongs to + * @param string $component Name of the component that the itemid belongs to * @param string $paymentarea - * @param int $componentid An internal identifier that is used by the component + * @param int $itemid An internal identifier that is used by the component * @param string $orderid PayPal order ID * @return array */ - public static function execute(string $component, string $paymentarea, int $componentid, string $orderid): array { + public static function execute(string $component, string $paymentarea, int $itemid, string $orderid): array { global $USER, $DB; self::validate_parameters(self::execute_parameters(), [ 'component' => $component, 'paymentarea' => $paymentarea, - 'componentid' => $componentid, + 'itemid' => $itemid, 'orderid' => $orderid, ]); - $config = (object)helper::get_gateway_configuration($component, $paymentarea, $componentid, 'paypal'); + $config = (object)helper::get_gateway_configuration($component, $paymentarea, $itemid, 'paypal'); $sandbox = $config->environment == 'sandbox'; [ 'amount' => $amount, 'currency' => $currency, 'accountid' => $accountid, - ] = payment_helper::get_cost($component, $paymentarea, $componentid); + ] = payment_helper::get_cost($component, $paymentarea, $itemid); // Add surcharge if there is any. $surcharge = helper::get_gateway_surcharge('paypal'); @@ -102,7 +102,7 @@ public static function execute(string $component, string $paymentarea, int $comp $success = true; // Everything is correct. Let's give them what they paid for. try { - $paymentid = payment_helper::save_payment((int) $accountid, $component, $paymentarea, $componentid, + $paymentid = payment_helper::save_payment((int) $accountid, $component, $paymentarea, $itemid, (int) $USER->id, $amount, $currency, 'paypal'); // Store PayPal extra information. @@ -112,7 +112,7 @@ public static function execute(string $component, string $paymentarea, int $comp $DB->insert_record('paygw_paypal', $record); - payment_helper::deliver_order($component, $paymentarea, $componentid, $paymentid); + payment_helper::deliver_order($component, $paymentarea, $itemid, $paymentid); } catch (\Exception $e) { debugging('Exception while trying to process payment: ' . $e->getMessage(), DEBUG_DEVELOPER); $success = false; diff --git a/payment/tests/generator/lib.php b/payment/tests/generator/lib.php index 48f46490b40d2..8dd67e4205273 100644 --- a/payment/tests/generator/lib.php +++ b/payment/tests/generator/lib.php @@ -73,7 +73,7 @@ public function create_payment(array $data): int { [ 'component' => 'testcomponent', 'paymentarea' => 'teatarea', - 'componentid' => 0, + 'itemid' => 0, 'currency' => 'AUD', ]); return $id; diff --git a/payment/tests/helper_test.php b/payment/tests/helper_test.php index 417765033146d..e1c5e296ecdb5 100644 --- a/payment/tests/helper_test.php +++ b/payment/tests/helper_test.php @@ -121,7 +121,7 @@ public function test_archive_restore_account() { 'accountid' => $account->get('id'), 'component' => 'test', 'paymentarea' => 'test', - 'componentid' => 1, + 'itemid' => 1, 'userid' => $USER->id, ]); helper::delete_payment_account(account::get_record(['id' => $account->get('id')]));