mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 13:38:32 +01:00
MDL-69166 core_payment: Rename componentid to itemid
This commit is contained in:
parent
2d7feb7583
commit
d5a9d6e520
@ -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 }}
|
||||
>
|
||||
|
@ -4323,7 +4323,7 @@
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="component" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" COMMENT="The plugin this payment belongs to."/>
|
||||
<FIELD NAME="paymentarea" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false" COMMENT="The name of payable area"/>
|
||||
<FIELD NAME="componentid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="itemid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="amount" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="currency" TYPE="char" LENGTH="3" NOTNULL="true" SEQUENCE="false"/>
|
||||
@ -4339,7 +4339,7 @@
|
||||
</KEYS>
|
||||
<INDEXES>
|
||||
<INDEX NAME="gateway" UNIQUE="false" FIELDS="gateway"/>
|
||||
<INDEX NAME="component-paymentarea-componentid" UNIQUE="false" FIELDS="component, paymentarea, componentid"/>
|
||||
<INDEX NAME="component-paymentarea-itemid" UNIQUE="false" FIELDS="component, paymentarea, itemid"/>
|
||||
</INDEXES>
|
||||
</TABLE>
|
||||
<TABLE NAME="infected_files" COMMENT="Table to store infected file details.">
|
||||
|
@ -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)) {
|
||||
|
2
payment/amd/build/gateways_modal.min.js
vendored
2
payment/amd/build/gateways_modal.min.js
vendored
@ -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<z.length&&z[1]!==void 0?z[1]:{},n=m.focusOnClose,o=void 0===n?null:n;a.t0=b.default;a.t1=k.default.TYPE;a.next=5;return(0,d.get_string)("selectpaymenttype","core_payment");case 5:a.t2=a.sent;a.next=8;return c.default.render("core_payment/gateways_modal",{});case 8:a.t3=a.sent;a.t4={type:a.t1,title:a.t2,body:a.t3};a.next=12;return a.t0.create.call(a.t0,a.t4);case 12:p=a.sent;q=p.getRoot()[0];(0,i.addToastRegion)(q);p.show();p.getRoot().on(g.default.hidden,function(){p.destroy();try{o.focus()}catch(a){}});p.getRoot().on(h.default.proceed,function(a){var b=(q.querySelector(f.default.values.gateway)||{value:""}).value;if(b){t(b,l.dataset.component,l.dataset.paymentarea,l.dataset.componentid,l.dataset.description,function(a){var b=a.success,c=a.message,d=void 0===c?"":c;p.hide();if(b){j.default.addNotification({message:d,type:"success"});location.reload()}else{j.default.alert("",d)}})}else{(0,d.get_string)("nogatewayselected","core_payment").then(function(a){return(0,i.add)(a)})}a.preventDefault()});q.addEventListener("change",function(a){if(a.target.matches(f.default.elements.gateways)){s(q,l.dataset.cost)}});a.next=21;return(0,e.getAvailableGateways)(l.dataset.component,l.dataset.paymentarea,l.dataset.componentid);case 21:u=a.sent;v={gateways:u};a.next=25;return c.default.renderForPromise("core_payment/gateways",v);case 25:w=a.sent;x=w.html;y=w.js;c.default.replaceNodeContents(q.querySelector(f.default.regions.gatewaysContainer),x,y);r(q);a.next=32;return s(q,l.dataset.cost);case 32:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}(),r=function(a){var b=a.querySelectorAll(f.default.elements.gateways);if(1==b.length){b[0].checked=!0}},s=function(){var a=n(regeneratorRuntime.mark(function a(b){var d,e,g,h,i,j,k,l=arguments;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:d=1<l.length&&l[1]!==void 0?l[1]:"";e=b.querySelector(f.default.values.gateway);g=parseInt((e||{dataset:{surcharge:0}}).dataset.surcharge);h=(e||{dataset:{cost:d}}).dataset.cost;a.next=6;return c.default.renderForPromise("core_payment/fee_breakdown",{fee:h,surcharge:g});case 6:i=a.sent;j=i.html;k=i.js;c.default.replaceNodeContents(b.querySelector(f.default.regions.costContainer),j,k);case 10:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}(),t=function(){var a=n(regeneratorRuntime.mark(function a(b,c,d,e,f,g){var h;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:a.next=2;return"function"==typeof o.define&&o.define.amd?new Promise(function(a,c){o.require(["paygw_".concat(b,"/gateways_modal")],a,c)}):"undefined"!=typeof module&&module.exports&&"undefined"!=typeof require||"undefined"!=typeof module&&module.component&&o.require&&"component"===o.require.loader?Promise.resolve(require(("paygw_".concat(b,"/gateways_modal")))):Promise.resolve(o["paygw_".concat(b,"/gateways_modal")]);case 2:h=a.sent;h.process(c,d,e,f,g);case 4:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}()});
|
||||
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<z.length&&z[1]!==void 0?z[1]:{},n=m.focusOnClose,o=void 0===n?null:n;a.t0=b.default;a.t1=k.default.TYPE;a.next=5;return(0,d.get_string)("selectpaymenttype","core_payment");case 5:a.t2=a.sent;a.next=8;return c.default.render("core_payment/gateways_modal",{});case 8:a.t3=a.sent;a.t4={type:a.t1,title:a.t2,body:a.t3};a.next=12;return a.t0.create.call(a.t0,a.t4);case 12:p=a.sent;q=p.getRoot()[0];(0,i.addToastRegion)(q);p.show();p.getRoot().on(g.default.hidden,function(){p.destroy();try{o.focus()}catch(a){}});p.getRoot().on(h.default.proceed,function(a){var b=(q.querySelector(f.default.values.gateway)||{value:""}).value;if(b){t(b,l.dataset.component,l.dataset.paymentarea,l.dataset.itemid,l.dataset.description,function(a){var b=a.success,c=a.message,d=void 0===c?"":c;p.hide();if(b){j.default.addNotification({message:d,type:"success"});location.reload()}else{j.default.alert("",d)}})}else{(0,d.get_string)("nogatewayselected","core_payment").then(function(a){return(0,i.add)(a)})}a.preventDefault()});q.addEventListener("change",function(a){if(a.target.matches(f.default.elements.gateways)){s(q,l.dataset.cost)}});a.next=21;return(0,e.getAvailableGateways)(l.dataset.component,l.dataset.paymentarea,l.dataset.itemid);case 21:u=a.sent;v={gateways:u};a.next=25;return c.default.renderForPromise("core_payment/gateways",v);case 25:w=a.sent;x=w.html;y=w.js;c.default.replaceNodeContents(q.querySelector(f.default.regions.gatewaysContainer),x,y);r(q);a.next=32;return s(q,l.dataset.cost);case 32:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}(),r=function(a){var b=a.querySelectorAll(f.default.elements.gateways);if(1==b.length){b[0].checked=!0}},s=function(){var a=n(regeneratorRuntime.mark(function a(b){var d,e,g,h,i,j,k,l=arguments;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:d=1<l.length&&l[1]!==void 0?l[1]:"";e=b.querySelector(f.default.values.gateway);g=parseInt((e||{dataset:{surcharge:0}}).dataset.surcharge);h=(e||{dataset:{cost:d}}).dataset.cost;a.next=6;return c.default.renderForPromise("core_payment/fee_breakdown",{fee:h,surcharge:g});case 6:i=a.sent;j=i.html;k=i.js;c.default.replaceNodeContents(b.querySelector(f.default.regions.costContainer),j,k);case 10:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}(),t=function(){var a=n(regeneratorRuntime.mark(function a(b,c,d,e,f,g){var h;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:a.next=2;return"function"==typeof o.define&&o.define.amd?new Promise(function(a,c){o.require(["paygw_".concat(b,"/gateways_modal")],a,c)}):"undefined"!=typeof module&&module.exports&&"undefined"!=typeof require||"undefined"!=typeof module&&module.component&&o.require&&"component"===o.require.loader?Promise.resolve(require(("paygw_".concat(b,"/gateways_modal")))):Promise.resolve(o["paygw_".concat(b,"/gateways_modal")]);case 2:h=a.sent;h.process(c,d,e,f,g);case 4:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}()});
|
||||
//# sourceMappingURL=gateways_modal.min.js.map
|
||||
|
File diff suppressed because one or more lines are too long
2
payment/amd/build/repository.min.js
vendored
2
payment/amd/build/repository.min.js
vendored
@ -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
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.\n\n/**\n * Repository for payment subsystem.\n *\n * @module core_payment/repository\n * @package core_payment\n * @copyright 2020 Shamim Rezaie <shamim@moodle.com>\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"}
|
||||
{"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 <http://www.gnu.org/licenses/>.\n\n/**\n * Repository for payment subsystem.\n *\n * @module core_payment/repository\n * @package core_payment\n * @copyright 2020 Shamim Rezaie <shamim@moodle.com>\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"}
|
@ -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<void>}
|
||||
*/
|
||||
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);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -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];
|
||||
|
@ -46,7 +46,7 @@ class get_available_gateways extends external_api {
|
||||
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 @@ class get_available_gateways extends external_api {
|
||||
*
|
||||
* @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);
|
||||
|
@ -62,17 +62,17 @@ class helper {
|
||||
*
|
||||
* @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 @@ class helper {
|
||||
/**
|
||||
* 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 @@ class helper {
|
||||
/**
|
||||
* 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 @@ class helper {
|
||||
*
|
||||
* @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 @@ class helper {
|
||||
*
|
||||
* @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 @@ class helper {
|
||||
* 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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);c<b;c++){d[c]=a[c]}return d}function q(a,b){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(a)))return;var c=[],d=!0,e=!1,f=void 0;try{for(var g=a[Symbol.iterator](),h;!(d=(h=g.next()).done);d=!0){c.push(h.value);if(b&&c.length===b)break}}catch(a){e=!0;f=a}finally{try{if(!d&&null!=g["return"])g["return"]()}finally{if(e)throw f}}return c}function r(a){if(Array.isArray(a))return a}function s(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 t(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){var h=a.apply(b,c);function f(a){s(h,d,e,f,g,"next",a)}function g(a){s(h,d,e,f,g,"throw",a)}f(void 0)})}}var u=function(){var a=t(regeneratorRuntime.mark(function a(){var b;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:a.t0=f.default;a.next=3;return c.default.render("paygw_paypal/paypal_button_placeholder",{});case 3:a.t1=a.sent;a.t2={body:a.t1};a.next=7;return a.t0.create.call(a.t0,a.t2);case 7:b=a.sent;b.show();return a.abrupt("return",b);case 10:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}(),v=function(){var a=t(regeneratorRuntime.mark(function a(c,f,i,j,k){var m,n,o,p,q,r,s;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:a.next=2;return Promise.all([u(),b.getConfigForJs(c,f,i)]);case 2:m=a.sent;n=l(m,2);o=n[0];p=n[1];q=p.currency;r=p.cost;o.getRoot().on(g.default.hidden,function(){o.destroy()});s="https://www.paypal.com/sdk/js?client-id=".concat(p.clientid,"¤cy=").concat(q);w(s,function(){o.setBody("");paypal.Buttons({createOrder:function createOrder(a,b){return b.order.create({purchase_units:[{amount:{currency_code:q,value:r},description:d.default.truncate(j,{length:127,stripTags:!0})}],application_context:{shipping_preference:"NO_SHIPPING",brand_name:d.default.truncate(p.brandname,{length:127,stripTags:!0})}})},onApprove:function onApprove(a){o.getRoot().on(g.default.outsideClick,function(a){a.preventDefault()});o.setBody((0,h.get_string)("authorising","paygw_paypal"));return e.default.call([{methodname:"paygw_paypal_create_transaction_complete",args:{component:c,paymentarea:f,componentid:i,orderid:a.orderID}}])[0].then(function(a){o.hide();return k(a)})}}).render(o.getBody()[0])});case 11:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}();a.process=v;var w=function(a,b){if(w.currentlyloaded==a){b();return}if(w.currentlyloaded){var d=document.querySelector("script[src=\"".concat(w.currentlyloaded,"\"]"));if(d){d.parentNode.removeChild(d)}}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=a};w.currentlyloaded=""});
|
||||
function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("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);c<b;c++){d[c]=a[c]}return d}function q(a,b){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(a)))return;var c=[],d=!0,e=!1,f=void 0;try{for(var g=a[Symbol.iterator](),h;!(d=(h=g.next()).done);d=!0){c.push(h.value);if(b&&c.length===b)break}}catch(a){e=!0;f=a}finally{try{if(!d&&null!=g["return"])g["return"]()}finally{if(e)throw f}}return c}function r(a){if(Array.isArray(a))return a}function s(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 t(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){var h=a.apply(b,c);function f(a){s(h,d,e,f,g,"next",a)}function g(a){s(h,d,e,f,g,"throw",a)}f(void 0)})}}var u=function(){var a=t(regeneratorRuntime.mark(function a(){var b;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:a.t0=f.default;a.next=3;return c.default.render("paygw_paypal/paypal_button_placeholder",{});case 3:a.t1=a.sent;a.t2={body:a.t1};a.next=7;return a.t0.create.call(a.t0,a.t2);case 7:b=a.sent;b.show();return a.abrupt("return",b);case 10:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}(),v=function(){var a=t(regeneratorRuntime.mark(function a(c,f,i,j,k){var m,n,o,p,q,r,s;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:a.next=2;return Promise.all([u(),b.getConfigForJs(c,f,i)]);case 2:m=a.sent;n=l(m,2);o=n[0];p=n[1];q=p.currency;r=p.cost;o.getRoot().on(g.default.hidden,function(){o.destroy()});s="https://www.paypal.com/sdk/js?client-id=".concat(p.clientid,"¤cy=").concat(q);w(s,function(){o.setBody("");paypal.Buttons({createOrder:function createOrder(a,b){return b.order.create({purchase_units:[{amount:{currency_code:q,value:r},description:d.default.truncate(j,{length:127,stripTags:!0})}],application_context:{shipping_preference:"NO_SHIPPING",brand_name:d.default.truncate(p.brandname,{length:127,stripTags:!0})}})},onApprove:function onApprove(a){o.getRoot().on(g.default.outsideClick,function(a){a.preventDefault()});o.setBody((0,h.get_string)("authorising","paygw_paypal"));return e.default.call([{methodname:"paygw_paypal_create_transaction_complete",args:{component:c,paymentarea:f,itemid:i,orderid:a.orderID}}])[0].then(function(a){o.hide();return k(a)})}}).render(o.getBody()[0])});case 11:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}();a.process=v;var w=function(a,b){if(w.currentlyloaded==a){b();return}if(w.currentlyloaded){var d=document.querySelector("script[src=\"".concat(w.currentlyloaded,"\"]"));if(d){d.parentNode.removeChild(d)}}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=a};w.currentlyloaded=""});
|
||||
//# sourceMappingURL=gateways_modal.min.js.map
|
||||
|
File diff suppressed because one or more lines are too long
@ -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
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.\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 <shamim@moodle.com>\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"}
|
||||
{"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 <http://www.gnu.org/licenses/>.\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 <shamim@moodle.com>\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"}
|
@ -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<void>}
|
||||
*/
|
||||
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]
|
||||
|
@ -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,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -47,7 +47,7 @@ class get_config_for_js extends external_api {
|
||||
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 @@ class get_config_for_js extends external_api {
|
||||
*
|
||||
* @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 [
|
||||
|
@ -48,7 +48,7 @@ class transaction_complete extends external_api {
|
||||
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 @@ class transaction_complete extends external_api {
|
||||
* 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 @@ class transaction_complete extends external_api {
|
||||
$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 @@ class transaction_complete extends external_api {
|
||||
|
||||
$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;
|
||||
|
@ -73,7 +73,7 @@ class core_payment_generator extends component_generator_base {
|
||||
[
|
||||
'component' => 'testcomponent',
|
||||
'paymentarea' => 'teatarea',
|
||||
'componentid' => 0,
|
||||
'itemid' => 0,
|
||||
'currency' => 'AUD',
|
||||
]);
|
||||
return $id;
|
||||
|
@ -121,7 +121,7 @@ class accounts_testcase extends advanced_testcase {
|
||||
'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')]));
|
||||
|
Loading…
x
Reference in New Issue
Block a user