MDL-69166 core_payment: add a callback for when payment is done
[moodle.git] / payment / amd / build / gateways_modal.min.js
1 function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("core_payment/gateways_modal",["exports","core/modal_factory","core/templates","core/str","core_payment/repository","./selectors","core/modal_events","core/toast","core/notification"],function(a,b,c,d,e,f,g,h,i){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.registerEventListeners=void 0;b=l(b);c=l(c);f=l(f);g=k(g);i=l(i);var r="undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:{};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){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)})}}function o(a){if("undefined"==typeof Symbol||null==a[Symbol.iterator]){if(Array.isArray(a)||(a=p(a))){var b=0,c=function(){};return{s:c,n:function n(){if(b>=a.length)return{done:!0};return{done:!1,value:a[b++]}},e:function e(a){throw a},f:c}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var d,e=!0,f=!1,g;return{s:function s(){d=a[Symbol.iterator]()},n:function n(){var a=d.next();e=a.done;return a},e:function e(a){f=!0;g=a},f:function f(){try{if(!e&&null!=d.return)d.return()}finally{if(f)throw g}}}}function p(a,b){if(!a)return;if("string"==typeof a)return q(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);if("Object"===c&&a.constructor)c=a.constructor.name;if("Map"===c||"Set"===c)return Array.from(c);if("Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c))return q(a,b)}function q(a,b){if(null==b||b>a.length)b=a.length;for(var c=0,d=Array(b);c<b;c++){d[c]=a[c]}return d}a.registerEventListeners=function registerEventListeners(a){var b=document.querySelector(a);b.addEventListener("click",function(a){a.preventDefault();s(b,{focusOnClose:a.target})})};var s=function(a){var j=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},k=j.focusOnClose,l=void 0===k?null:k;c.default.render("core_payment/gateways_modal",{}).done(function(j){b.default.create({type:b.default.types.SAVE_CANCEL,title:(0,d.get_string)("selectpaymenttype","core_payment"),body:j}).done(function(b){(0,h.addToastRegion)(b.getRoot()[0]);var j=a.dataset.currency;(0,e.getGatewaysSupportingCurrency)(j).done(function(a){var d={gateways:[]},e=o(a),g;try{for(e.s();!(g=e.n()).done;){var h=g.value;d.gateways.push(h)}}catch(a){e.e(a)}finally{e.f()}c.default.render("core_payment/gateways",d).done(function(a,d){c.default.replaceNodeContents(b.getRoot().find(f.default.regions.gatewaysContainer),a,d)})});b.getRoot().on(g.hidden,function(){b.destroy();try{l.focus()}catch(a){}});b.getRoot().on(g.save,function(c){var e=b.getRoot()[0],g=(e.querySelector(f.default.values.gateway)||{value:""}).value;if(g){t(g,a.dataset.amount,a.dataset.currency,a.dataset.component,a.dataset.componentid,a.dataset.description,function(a){var c=a.success,d=a.message,e=void 0===d?"":d;b.hide();if(c){i.default.addNotification({message:e,type:"success"});location.reload()}else{i.default.alert("",e)}})}else{(0,d.get_string)("nogatewayselected","core_payment").then(function(a){return(0,h.add)(a)})}c.preventDefault()});b.show()})})},t=function(){var a=n(regeneratorRuntime.mark(function a(b,c,d,e,f,g,h){var i;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:a.next=2;return"function"==typeof r.define&&r.define.amd?new Promise(function(a,c){r.require(["pg_".concat(b,"/gateways_modal")],a,c)}):"undefined"!=typeof module&&module.exports&&"undefined"!=typeof require||"undefined"!=typeof module&&module.component&&r.require&&"component"===r.require.loader?Promise.resolve(require(("pg_".concat(b,"/gateways_modal")))):Promise.resolve(r["pg_".concat(b,"/gateways_modal")]);case 2:i=a.sent;i.process(c,d,e,f,g,h);case 4:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}()});
2 //# sourceMappingURL=gateways_modal.min.js.map